Skip to content

N0ine/ValveShortcuts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ValveShortcuts

ValveShortcuts is a small library that reads and writes Steam shortcuts and exports associated images (Steam grid images).

What it does

  • Reads shortcuts (the user's shortcuts file) and returns a list of all the shortcuts.
  • Writes to the shortcuts file, allowing you to add, remove, or modify shortcuts.
  • Export bundled (embedded) grid images for a given appid to a destination folder.

Usage

Add the library to your project and use the following code snippets to read, write, or export shortcuts and grid images.

Reading shortcuts

// Read shortcuts from the user's shortcuts file

using ValveShortcuts;
string filePath = @"...\shortcuts.vdf"; // Path to the shortcuts file

List<Shortcut> shortcuts = ReadFile.ReadShortcuts(filePath);

Writing shortcuts

// Write shortcuts to the user's shortcuts file

using ValveShortcuts;
string filePath = @"...\shortcuts.vdf"; // Path to the shortcuts file

// Step 1: Load existing shortcuts
List<Shortcut> shortcuts = ReadFile.ReadShortcuts(filePath);

// Step 2: Create new shortcut
var newShortcut = new Shortcut
{
    // GenerateAppID has two ways to generate an AppID:
    // AppId = GenerateId.EncodeAppID(GenerateId.GenerateAppID("My Test Game", @"""C:\Path\To\the.exe""")),
    // See Step 3 for the second version (recommended for better readability and maintainability)
    AppName = "My Test Game",          // String
    Exe = @"""C:\Path\To\the.exe""",   // String
    StartDir = @"C:\Path\To\",         // String
    Icon = "",                         // String
    ShortcutPath = "",                 // String
    LaunchOptions = "",                // String
    IsHidden = false,                  // Bool
    AllowDesktopConfig = true,         // Bool
    AllowOverlay = true,               // Bool
    OpenVR = false,                    // Bool
    Devkit = false,                    // Bool
    DevkitGameID = null,               // String
    DevkitOverrideAppID = null,        // Byte array
    LastPlayTime = null,               // Byte array
    FlatpakAppID = null,               // String
    SortAs = null,                     // String
    Tags = {}                          // List of strings
}; 

// Step 3: Generate AppID and add the new shortcut to the list
newShortcut.AppId = GenerateId.EncodeAppID(GenerateId.GenerateAppID(newShortcut));

shortcuts.Add(newShortcut);

// Step 4: Write the updated shortcuts list back to the file
WriteFile.WriteShortcuts(filePath, shortcuts);

Exporting embedded grid images

// Extract embedded image files and replace a temporary id (eg. "#APPID#") with the App ID
uint app_id = GenerateId.GenerateAppID(newShortcut);

CreateGrid.CreateSteamGrid(app_id, "#APPID#", @"C:\Path\to\config\grid");

Generating App ID, encoding and decoding app ID

// Generate App ID without being encoded
uint app_id = GenerateId.GenerateAppID(newShortcut);

// Encode App ID
byte[] encodedAppId = GenerateId.EncodeAppID(app_id);

// Decode the App ID; Useful when creating steam grids
uint decodedAppId = GenerateId.DecodeAppID(encodedAppId);

About

A C# Library that reads and writes steam shortcuts

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages