private void UpdateRomGridImage(VDFEntry rom, string gridPicturePath) { // ############# GENERATE APP ID ################## var stringValue = $"{rom.Exe + rom.AppName}"; var byteArray = Encoding.UTF8.GetBytes(stringValue); var thing = Crc32.Crc32Algorithm.Compute(byteArray); var longThing = (ulong)thing; longThing = (longThing | 0x80000000); /* * longThing = longThing << 32; * longThing = (longThing | 0x02000000); * var finalConversion = longThing.ToString();*/ // ############# GENERATE APP ID ################## var finalNameOne = longThing.ToString() + 'p'; var extension = Path.GetExtension(gridPicturePath); var imagesFolder = Path.Combine(Path.GetDirectoryName(SteamShortcutsFile), "grid"); var steamGridImageFilePathOne = Path.Combine(imagesFolder, finalNameOne + extension); if (File.Exists(steamGridImageFilePathOne)) { File.Delete(steamGridImageFilePathOne); } File.Copy(gridPicturePath, steamGridImageFilePathOne); }
/// <summary> /// Flushes any remaining entry to the result array /// </summary> public void Flush() { if (currentEntry != null) { Console.WriteLine("Parsed " + currentEntry); entries.Add(currentEntry); } currentEntry = null; }
/// <summary> /// Feeds a given byte to the SM /// </summary> /// <param name="b">Incoming byte to be fed to the SM</param> public void Feed(byte b) { switch (mainState) { case MainSMState.IndexBeginIndicator: if (b == 0x00) { Flush(); mainState = MainSMState.IndexValue; tmpBuffer.Clear(); fieldsSM.Reset(); } break; case MainSMState.IndexValue: if (b == 0x00) // Okay, next would be IndexEndIndicator, // but the terminator is also the separator, // and things would get messy. Let's just // skip a whole SM step here and pretend // everything is fine. { int indexResult; if (int.TryParse(tmpBuffer.StringFromByteArray(), out indexResult)) { currentEntry = new VDFEntry(); currentEntry.Index = indexResult; mainState = MainSMState.Fields; } // The next is necessary to satisfy the SM pattern. fieldsSM.Feed(b); break; } tmpBuffer.Add(b); break; case MainSMState.Fields: if (fieldsSM.Feed(b)) { foreach (KeyValuePair <string, byte[]> k in fieldsSM.Fields) { FillEntry(k.Key, k.Value); } mainState = MainSMState.IndexBeginIndicator; } break; } }
public static VDFEntry[] ReadShortcuts(string userPath) { string shortcutFile = userPath + "\\config\\shortcuts.vdf"; VDFEntry[] shortcuts = new VDFEntry[0]; //Some users don't seem to have the config directory at all or the shortcut file, return a empty entry for those if (!Directory.Exists(userPath + "\\config\\") || !File.Exists(shortcutFile)) { return(shortcuts); } shortcuts = VDFParser.VDFParser.Parse(shortcutFile); return(shortcuts); }
private void gameSteamShortcut_Click(object sender, EventArgs e) { GOGGame game = (GOGGame)this.gamesList.SelectedValue; if (game == null) { return; } this.gameSteamShortcut.Enabled = false; try { string[] users = SteamUtils.GetUsers(); VDFEntry shortcut = new VDFEntry() { AppName = game.Name, Exe = $"\"{Application.ExecutablePath}\" {game.ID} -e", StartDir = $"\"{game.Path}\"", Icon = game.Icon, ShortcutPath = "", IsHidden = 0, AllowDesktopConfig = 1, OpenVR = 0, Tags = new string[] { "GOG.com" }, Index = 0 }; foreach (string user in users) { List <VDFEntry> shortcuts = new List <VDFEntry>(SteamUtils.ReadShortcuts(user)); shortcuts.Add(shortcut); SteamUtils.WriteShortcuts(shortcuts.ToArray(), user); } MessageBox.Show("You may need to restart Steam to use new shortcut", "Steam shortcut added", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Steam shortcut add failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.gameSteamShortcut.Enabled = true; }
public void TestParsedContents() { var expectations = new VDFEntry[] { new VDFEntry() { AppName = "Guitar Hero World Tour", Exe = "\"D:\\Program Files\\GH\\GHWT.exe\"", StartDir = "\"D:\\Program Files\\GH\\\"", Icon = "", ShortcutPath = "", LaunchOptions = "", IsHidden = 0, AllowDesktopConfig = 1, AllowOverlay = 1, OpenVR = 0, Devkit = 0, DevkitGameID = "", LastPlayTime = 1590640610, Tags = new string[] { "Music" }, Index = 0 } }; var entries = VDFParser.VDFParser.Parse(Helpers.GetResourceNamed("shortcuts.vdf")); for (var i = 0; i < expectations.Length; i++) { var exp = expectations[i]; var par = entries[i]; Assert.AreEqual(exp.Index, par.Index); Assert.AreEqual(exp.AppName, par.AppName); Assert.AreEqual(exp.Exe, par.Exe); Assert.AreEqual(exp.StartDir, par.StartDir); Assert.AreEqual(exp.Icon, par.Icon); Assert.AreEqual(exp.ShortcutPath, par.ShortcutPath); Assert.AreEqual(exp.LaunchOptions, par.LaunchOptions); Assert.AreEqual(exp.IsHidden, par.IsHidden); Assert.AreEqual(exp.AllowDesktopConfig, par.AllowDesktopConfig); Assert.AreEqual(exp.AllowOverlay, par.AllowOverlay); Assert.AreEqual(exp.OpenVR, par.OpenVR); Assert.AreEqual(exp.Devkit, par.Devkit); Assert.AreEqual(exp.DevkitGameID, par.DevkitGameID); Assert.AreEqual(exp.LastPlayTime, par.LastPlayTime); Assert.AreEqual(exp.Tags, par.Tags); } }
public static void ClearAllShortcuts() { Debug.WriteLine("DBG: Clearing all elements in shortcuts.vdf"); string[] tags = Settings.Default.Tags.Split(','); string steam_folder = SteamManager.GetSteamFolder(); if (Directory.Exists(steam_folder)) { var users = SteamManager.GetUsers(steam_folder); var exePath = @"""" + System.Reflection.Assembly.GetExecutingAssembly().Location + @""""; var exeDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); foreach (var user in users) { try { VDFEntry[] shortcuts = new VDFEntry[0]; try { if (!Directory.Exists(user + @"\\config\\")) { Directory.CreateDirectory(user + @"\\config\\"); } //Write the file with all the shortcuts File.WriteAllBytes(user + @"\\config\\shortcuts.vdf", VDFSerializer.Serialize(shortcuts)); } catch (Exception ex) { throw new Exception("Error: Program failed while trying to write your Steam shortcuts" + Environment.NewLine + ex.Message); } } catch (Exception ex) { MessageBox.Show("Error: Program failed while trying to clear your Steam shortcuts:" + Environment.NewLine + ex.Message + ex.StackTrace); } } MessageBox.Show("All non-Steam shortcuts has been cleared."); } }
private void BwrSave_DoWork(object sender, DoWorkEventArgs e) { string steam_folder = SteamManager.GetSteamFolder(); if (Directory.Exists(steam_folder)) { var users = SteamManager.GetUsers(steam_folder); var selected_apps = Apps.Entries.Where(app => app.Selected); //To make things faster, decide icons before looping users foreach (var app in selected_apps) { app.Icon = app.widestSquareIcon(); } foreach (var user in users) { try { VDFEntry[] shortcuts = new VDFEntry[0]; try { shortcuts = SteamManager.ReadShortcuts(user); } catch (Exception ex) { //If it's a short VDF, let's just overwrite it if (ex.GetType() != typeof(VDFTooShortException)) { throw new Exception("Error: Program failed to load existing Steam shortcuts." + Environment.NewLine + ex.Message); } } if (shortcuts != null) { var exePath = @"""" + System.Reflection.Assembly.GetExecutingAssembly().Location + @""""; var exeDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); foreach (var app in selected_apps) { VDFEntry newApp = new VDFEntry() { AppName = app.Name, Exe = exePath, StartDir = exeDir, LaunchOptions = app.Aumid, AllowDesktopConfig = 1, AllowOverlay = 1, Icon = app.Icon, Index = shortcuts.Length, IsHidden = 0, OpenVR = 0, ShortcutPath = "", Tags = new string[0], Devkit = 0, DevkitGameID = "", LastPlayTime = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds(), }; //Resize this array so it fits the new entries Array.Resize(ref shortcuts, shortcuts.Length + 1); shortcuts[shortcuts.Length - 1] = newApp; } try { if (!Directory.Exists(user + @"\\config\\")) { Directory.CreateDirectory(user + @"\\config\\"); } //Write the file with all the shortcuts File.WriteAllBytes(user + @"\\config\\shortcuts.vdf", VDFSerializer.Serialize(shortcuts)); } catch (Exception ex) { throw new Exception("Error: Program failed while trying to write your Steam shortcuts" + Environment.NewLine + ex.Message); } } } catch (Exception ex) { MessageBox.Show("Error: Program failed exporting your games:" + Environment.NewLine + ex.Message + ex.StackTrace); } } } }
private async Task ExportGames() { string steam_folder = SteamManager.GetSteamFolder(); if (Directory.Exists(steam_folder)) { var users = SteamManager.GetUsers(steam_folder); var selected_apps = Apps.Entries.Where(app => app.Selected); var exePath = @"""" + System.Reflection.Assembly.GetExecutingAssembly().Location + @""""; var exeDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); List <Task> gridImagesDownloadTasks = new List <Task>(); bool downloadGridImages = !String.IsNullOrEmpty(Properties.Settings.Default.SteamGridDbApiKey); //To make things faster, decide icons and download grid images before looping users foreach (var app in selected_apps) { app.Icon = app.widestSquareIcon(); if (downloadGridImages) { gridImagesDownloadTasks.Add(DownloadTempGridImages(app.Name, exePath)); } } foreach (var user in users) { try { VDFEntry[] shortcuts = new VDFEntry[0]; try { shortcuts = SteamManager.ReadShortcuts(user); } catch (Exception ex) { //If it's a short VDF, let's just overwrite it if (ex.GetType() != typeof(VDFTooShortException)) { throw new Exception("Error: Program failed to load existing Steam shortcuts." + Environment.NewLine + ex.Message); } } if (shortcuts != null) { foreach (var app in selected_apps) { VDFEntry newApp = new VDFEntry() { AppName = app.Name, Exe = exePath, StartDir = exeDir, LaunchOptions = app.Aumid, AllowDesktopConfig = 1, AllowOverlay = 1, Icon = app.Icon, Index = shortcuts.Length, IsHidden = 0, OpenVR = 0, ShortcutPath = "", Tags = new string[2] { "XBOX", "READY TO PLAY" }, Devkit = 0, DevkitGameID = "", LastPlayTime = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds(), }; //Resize this array so it fits the new entries Array.Resize(ref shortcuts, shortcuts.Length + 1); shortcuts[shortcuts.Length - 1] = newApp; } try { if (!Directory.Exists(user + @"\\config\\")) { Directory.CreateDirectory(user + @"\\config\\"); } //Write the file with all the shortcuts File.WriteAllBytes(user + @"\\config\\shortcuts.vdf", VDFSerializer.Serialize(shortcuts)); } catch (Exception ex) { throw new Exception("Error: Program failed while trying to write your Steam shortcuts" + Environment.NewLine + ex.Message); } } } catch (Exception ex) { MessageBox.Show("Error: Program failed exporting your games:" + Environment.NewLine + ex.Message + ex.StackTrace); } } if (gridImagesDownloadTasks.Count > 0) { await Task.WhenAll(gridImagesDownloadTasks); await Task.Run(() => { foreach (var user in users) { CopyTempGridImagesToSteamUser(user); } RemoveTempGridImages(); }); } } }
/// <summary> /// Main Task to export the selected games to steam /// </summary> /// <param name="restartSteam"></param> /// <returns></returns> private async Task <bool> ExportGames(bool restartSteam) { string[] tags = Settings.Default.Tags.Split(','); string steam_folder = SteamManager.GetSteamFolder(); if (Directory.Exists(steam_folder)) { var users = SteamManager.GetUsers(steam_folder); var selected_apps = Apps.Entries.Where(app => app.Selected); var exePath = @"""" + System.Reflection.Assembly.GetExecutingAssembly().Location + @""""; var exeDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); List <Task> gridImagesDownloadTasks = new List <Task>(); bool downloadGridImages = !String.IsNullOrEmpty(Properties.Settings.Default.SteamGridDbApiKey); //To make things faster, decide icons and download grid images before looping users Debug.WriteLine("downloadGridImages: " + (downloadGridImages)); foreach (var app in selected_apps) { app.Icon = app.widestSquareIcon(); if (downloadGridImages) { Debug.WriteLine("Downloading grid images for app " + app.Name); gridImagesDownloadTasks.Add(DownloadTempGridImages(app.Name, exePath)); } } // Export the selected apps and the downloaded images to each user // in the steam folder by modifying it's VDF file foreach (var user in users) { try { VDFEntry[] shortcuts = new VDFEntry[0]; try { shortcuts = SteamManager.ReadShortcuts(user); } catch (Exception ex) { //If it's a short VDF, let's just overwrite it if (ex.GetType() != typeof(VDFTooShortException)) { throw new Exception("Error: Program failed to load existing Steam shortcuts." + Environment.NewLine + ex.Message); } } if (shortcuts != null) { foreach (var app in selected_apps) { VDFEntry newApp = new VDFEntry() { AppName = app.Name, Exe = exePath, StartDir = exeDir, LaunchOptions = app.Aumid, AllowDesktopConfig = 1, AllowOverlay = 1, Icon = app.Icon, Index = shortcuts.Length, IsHidden = 0, OpenVR = 0, ShortcutPath = "", Tags = tags, Devkit = 0, DevkitGameID = "", LastPlayTime = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds(), }; Boolean isFound = false; for (int i = 0; i < shortcuts.Length; i++) { Debug.WriteLine(shortcuts[i].ToString()); if (shortcuts[i].AppName == app.Name) { isFound = true; Debug.WriteLine(app.Name + " already added to Steam. Updating existing shortcut."); shortcuts[i] = newApp; } } if (!isFound) { //Resize this array so it fits the new entries Array.Resize(ref shortcuts, shortcuts.Length + 1); shortcuts[shortcuts.Length - 1] = newApp; } } try { if (!Directory.Exists(user + @"\\config\\")) { Directory.CreateDirectory(user + @"\\config\\"); } //Write the file with all the shortcuts File.WriteAllBytes(user + @"\\config\\shortcuts.vdf", VDFSerializer.Serialize(shortcuts)); } catch (Exception ex) { throw new Exception("Error: Program failed while trying to write your Steam shortcuts" + Environment.NewLine + ex.Message); } } } catch (Exception ex) { MessageBox.Show("Error: Program failed exporting your games:" + Environment.NewLine + ex.Message + ex.StackTrace); } } if (gridImagesDownloadTasks.Count > 0) { await Task.WhenAll(gridImagesDownloadTasks); await Task.Run(() => { foreach (var user in users) { CopyTempGridImagesToSteamUser(user); } RemoveTempGridImages(); }); } } if (restartSteam) { Func <Process> getSteam = () => Process.GetProcessesByName("steam").SingleOrDefault(); Process steam = getSteam(); if (steam != null) { string steamExe = steam.MainModule.FileName; //we always ask politely Debug.WriteLine("Requesting Steam shutdown"); Process.Start(steamExe, "-exitsteam"); bool restarted = false; Stopwatch watch = new Stopwatch(); watch.Start(); //give it N seconds to sort itself out int waitSeconds = 8; while (watch.Elapsed.TotalSeconds < waitSeconds) { Thread.Sleep(TimeSpan.FromSeconds(0.5f)); if (getSteam() == null) { Debug.WriteLine("Restarting Steam"); Process.Start(steamExe); restarted = true; break; } } if (!restarted) { Debug.WriteLine("Steam instance not restarted"); MessageBox.Show("Failed to restart Steam, please launch it manually", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return(false); } } else { Debug.WriteLine("Steam instance not found to be restarted"); } } return(true); }
private static void smethod_7(GClass32 gclass32_0, GClass95 gclass95_0) { // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type GClass128.Class114 class114 = new GClass128.Class114(); // ISSUE: reference to a compiler-generated field class114.gclass32_0 = gclass32_0; if (GClass6.smethod_16("Steam")) { int num1 = (int)RadMessageBox.Show("Games cannot be added while Steam is running. Please close it and try again"); } else { string steamFolder = SteamManager.GetSteamFolder(); if (!System.IO.Directory.Exists(steamFolder)) { int num2 = (int)RadMessageBox.Show("Steam is not installed. Cannot proceed."); } else { string[] users = SteamManager.GetUsers(steamFolder); if (users.Length == 0) { int num3 = (int)RadMessageBox.Show("USB Helper was unable to find any registered Steam user. Make sure you have logged in at least once."); } else { string str1 = System.IO.Path.Combine(GClass128.String_0, "backup"); System.IO.Directory.CreateDirectory(GClass128.String_0); System.IO.Directory.CreateDirectory(str1); // ISSUE: reference to a compiler-generated field string str2 = System.IO.Path.Combine(GClass128.String_0, "icon" + class114.gclass32_0.TitleId.IdRaw + ".tmp"); // ISSUE: reference to a compiler-generated field string filename = System.IO.Path.Combine(GClass128.String_0, "icon" + class114.gclass32_0.TitleId.IdRaw + ".png"); // ISSUE: reference to a compiler-generated field new GClass78().method_5(class114.gclass32_0.IconUrl, str2, 0UL, GClass78.GEnum4.const_0, (WebProxy)null, 0L, (byte[])null, (byte[])null, (byte)0); Image image = Image.FromFile(str2); image.Save(filename, ImageFormat.Png); image.Dispose(); GClass6.smethod_6(str2); // ISSUE: reference to a compiler-generated field string str3 = GClass128.smethod_4(class114.gclass32_0, gclass95_0); // ISSUE: reference to a compiler-generated field VDFEntry vdfEntry = new VDFEntry() { AppName = class114.gclass32_0.Name, Exe = str3, Icon = filename, Tags = new string[1] { "Wii U USB Helper" } }; foreach (string userPath in users) { List <VDFEntry> source = new List <VDFEntry>(); try { source = new List <VDFEntry>((IEnumerable <VDFEntry>)SteamManager.ReadShortcuts(userPath)); } catch { } // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated method if (!source.Any <VDFEntry>(class114.func_0 ?? (class114.func_0 = new Func <VDFEntry, bool>(class114.method_0)))) { source.Add(vdfEntry); string str4 = userPath + "\\config\\shortcuts.vdf"; System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(str4)); if (System.IO.File.Exists(str4)) { System.IO.File.Copy(str4, System.IO.Path.Combine(str1, DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds.ToString()), true); } SteamManager.WriteShortcuts(source.ToArray(), str4); } } // ISSUE: reference to a compiler-generated field GClass128.smethod_2(class114.gclass32_0); } } } }
public void ExportToSteam() { // Step 1 - Read current Shortcuts file var currentShortcuts = ParseShortCuts(); //Step 2 - Add the ROMS to the list var romList = new List <CuratorDataSet.ROMRow>(); foreach (var console in Form1._consoleController.GetAllConsoles()) { foreach (var rom in Form1._romController.GetRomsForConsole(console)) { romList.Add(rom); } } foreach (var rom in romList) { var existingRomEntry = currentShortcuts.Where(x => x.AppName == rom.Name && x.Exe.Contains(rom.Extension)).FirstOrDefault(); if (rom.Enabled == false) { if (existingRomEntry != null) { currentShortcuts.Remove(existingRomEntry); } continue; } var RomFolder = CuratorData.RomFolder.Where(x => x.Id == rom.RomFolder_Id).First(); var console = CuratorData.Console.Where(y => y.Id == RomFolder.Console_Id).First(); var exepath = GetExePath(rom, console); var newRomEntry = new VDFEntry { AllowDesktopConfig = 1, AppName = rom.Name, Exe = exepath, StartDir = Path.GetDirectoryName(console.EmulatorPath), Index = 0, Icon = rom.GridPicture, IsHidden = 0, OpenVR = 0, ShortcutPath = "", Tags = new string[] { console.Name } }; if (!string.IsNullOrWhiteSpace(rom.LibraryPicture)) { UpdateRomGridImage(newRomEntry, rom.LibraryPicture); } if (existingRomEntry != null) { currentShortcuts[currentShortcuts.IndexOf(existingRomEntry)] = newRomEntry; } else { currentShortcuts.Add(newRomEntry); } } WriteOut(currentShortcuts); }