public static void CreateNewLibrary(string newLibraryPath, bool Backup) { try { // If we are not creating a backup library if (!Backup) { // Copy Steam.dll as steam needs it File.Copy(Properties.Settings.Default.SteamInstallationPath + "Steam.dll", newLibraryPath + @"\Steam.dll", true); // create SteamApps directory at requested directory Directory.CreateDirectory(newLibraryPath + @"\SteamApps"); // If Steam.dll moved succesfully if (File.Exists(newLibraryPath + @"\Steam.dll")) // in case of permissions denied { // Set libraryFolders.vdf path string vdfPath = Properties.Settings.Default.SteamInstallationPath + @"SteamApps\libraryfolders.vdf"; // Call KeyValue in act Framework.KeyValue Key = new Framework.KeyValue(); // Read vdf file as text Key.ReadFileAsText(vdfPath); // Add our new library to vdf file so steam will know we have a new library Key.Children.Add(new Framework.KeyValue((Key.Children.Count - 1).ToString(), newLibraryPath)); // Save vdf file Key.SaveToFile(vdfPath, false); // Show a messagebox to user about process System.Windows.Forms.MessageBox.Show("New Steam Library added, Please Restart Steam to see it in work."); // to-do: edit text // Update game libraries UpdateLibraries(); } else // Show an error to user and cancel the process because we couldn't get Steam.dll in new library dir System.Windows.Forms.MessageBox.Show("Failed to create new Steam Library, Try to run SLM as Administrator?"); } else { // If backup directories in settings null if (Properties.Settings.Default.BackupDirectories == null) // make a new definition Properties.Settings.Default.BackupDirectories = new System.Collections.Specialized.StringCollection(); // Add our newest backup library to settings Properties.Settings.Default.BackupDirectories.Add(newLibraryPath + @"\"); // Update game libraries UpdateLibraries(); // Save our settings Functions.Settings.Save(); } } catch { } }
public async void UpdateLibraryPathAsync(string NewLibraryPath) { try { await Functions.Steam.CloseSteamAsync(); // Make a KeyValue reader Framework.KeyValue Key = new Framework.KeyValue(); // Read vdf file Key.ReadFileAsText(Global.Steam.vdfFilePath); // Change old library path with new one Key["Software"]["Valve"]["Steam"].Children.Find(key => key.Value.Contains(FullPath)).Value = NewLibraryPath; // Update config.vdf file with changes Key.SaveToFile(Global.Steam.vdfFilePath, false); // Since this file started to interrupt us? // No need to bother with it since config.vdf is the real deal, just remove it and Steam client will handle with some magic. if (File.Exists(Path.Combine(Properties.Settings.Default.steamInstallationPath, "steamapps", "libraryfolders.vdf"))) { File.Delete(Path.Combine(Properties.Settings.Default.steamInstallationPath, "steamapps", "libraryfolders.vdf")); } Functions.Steam.RestartSteamAsync(); } catch (Exception ex) { logger.Fatal(ex); SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex)); } }
public static void createNewLibrary(string newLibraryPath, bool Backup) { try { // If we are not creating a backup library if (!Backup) { // Define steam dll paths for better looking string currentSteamDLLPath = Path.Combine(Properties.Settings.Default.steamInstallationPath, "Steam.dll"); string newSteamDLLPath = Path.Combine(newLibraryPath, "Steam.dll"); if (!File.Exists(newSteamDLLPath)) { // Copy Steam.dll as steam needs it File.Copy(currentSteamDLLPath, newSteamDLLPath, true); } if (!Directory.Exists(Path.Combine(newLibraryPath, "SteamApps"))) { // create SteamApps directory at requested directory Directory.CreateDirectory(Path.Combine(newLibraryPath, "SteamApps")); } // If Steam.dll moved succesfully if (File.Exists(newSteamDLLPath)) // in case of permissions denied { // Call KeyValue in act Framework.KeyValue Key = new Framework.KeyValue(); // Read vdf file as text Key.ReadFileAsText(Definitions.Steam.vdfFilePath); // Add our new library to vdf file so steam will know we have a new library Key.Children[0].Children[0].Children[0].Children.Add(new Framework.KeyValue(string.Format("BaseInstallFolder_{0}", Definitions.List.Libraries.Select(x => !x.Backup).Count()), newLibraryPath)); // Save vdf file Key.SaveToFile(Definitions.Steam.vdfFilePath, false); // Show a messagebox to user about process MessageBox.Show("new library created"); } else { // Show an error to user and cancel the process because we couldn't get Steam.dll in new library dir MessageBox.Show("failed to create new library"); } } // Add library to list addNewLibrary(newLibraryPath, false, Backup); // Save our settings SLM.Settings.saveSettings(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public override async void RemoveLibraryAsync(bool withFiles) { try { if (withFiles) { DeleteFilesAsync(); } List.Libraries.Remove(this); if (Type != LibraryType.Steam) { return; } await Functions.Steam.CloseSteamAsync().ConfigureAwait(true); // Make a KeyValue reader var keyValReader = new Framework.KeyValue(); // Read vdf file keyValReader.ReadFileAsText(Global.Steam.VdfFilePath); // Remove old library keyValReader["Software"]["Valve"]["Steam"].Children.RemoveAll(x => x.Value == FullPath); var i = 1; foreach (var key in keyValReader["Software"]["Valve"]["Steam"].Children.FindAll(x => x.Name.Contains("BaseInstallFolder"))) { key.Name = $"BaseInstallFolder_{i}"; i++; } // Update libraryFolders.vdf file with changes keyValReader.SaveToFile(Global.Steam.VdfFilePath, false); // Since this file started to interrupt us? // No need to bother with it since config.vdf is the real deal, just remove it and Steam client will handle with some magic. if (File.Exists(Path.Combine(Properties.Settings.Default.steamInstallationPath, "steamapps", "libraryfolders.vdf"))) { File.Delete(Path.Combine(Properties.Settings.Default.steamInstallationPath, "steamapps", "libraryfolders.vdf")); } Functions.Steam.RestartSteamAsync(); } catch (Exception ex) { Logger.Fatal(ex); } }
public async void RemoveLibraryAsync(bool ShouldDeleteFiles) { try { if (ShouldDeleteFiles) { DeleteFilesAsync(); } List.Libraries.Remove(List.Libraries.First(x => x == Library)); await Functions.Steam.CloseSteamAsync(); // Make a KeyValue reader Framework.KeyValue KeyValReader = new Framework.KeyValue(); // Read vdf file KeyValReader.ReadFileAsText(Global.Steam.vdfFilePath); // Remove old library KeyValReader["Software"]["Valve"]["Steam"].Children.RemoveAll(x => x.Value == FullPath); int i = 1; foreach (Framework.KeyValue Key in KeyValReader["Software"]["Valve"]["Steam"].Children.FindAll(x => x.Name.Contains("BaseInstallFolder"))) { Key.Name = $"BaseInstallFolder_{i}"; i++; } // Update libraryFolders.vdf file with changes KeyValReader.SaveToFile(Global.Steam.vdfFilePath, false); // Since this file started to interrupt us? // No need to bother with it since config.vdf is the real deal, just remove it and Steam client will handle with some magic. if (File.Exists(Path.Combine(Properties.Settings.Default.steamInstallationPath, "steamapps", "libraryfolders.vdf"))) { File.Delete(Path.Combine(Properties.Settings.Default.steamInstallationPath, "steamapps", "libraryfolders.vdf")); } Functions.Steam.RestartSteamAsync(); } catch (Exception ex) { logger.Fatal(ex); SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex)); } }
public void updateLibraryPath(string newLibraryPath) { try { // Make a KeyValue reader Framework.KeyValue Key = new Framework.KeyValue(); // Read vdf file Key.ReadFileAsText(Steam.vdfFilePath); // Change old library path with new one Key.Children[0].Children[0].Children[0].Children.Find(key => key.Value.Contains(fullPath)).Value = newLibraryPath; // Update config.vdf file with changes Key.SaveToFile(Steam.vdfFilePath, false); } catch { } }
public void removeLibrary(bool deleteFiles) { try { if (deleteFiles) { Functions.fileSystem.deleteOldLibrary(this); } List.Libraries.Remove(this); if (Backup) { Functions.SLM.Settings.updateBackupDirs(); Functions.SLM.Settings.saveSettings(); } else { // Make a KeyValue reader Framework.KeyValue Key = new Framework.KeyValue(); // Read vdf file Key.ReadFileAsText(Definitions.Steam.vdfFilePath); // Remove old library Key.Children[0].Children[0].Children[0].Children.RemoveAll(x => x.Value == fullPath); int i = 1; foreach (Framework.KeyValue key in Key.Children[0].Children[0].Children[0].Children.FindAll(x => x.Name.Contains("BaseInstallFolder"))) { key.Name = string.Format("BaseInstallFolder_{0}", i); i++; } // Update libraryFolders.vdf file with changes Key.SaveToFile(Definitions.Steam.vdfFilePath, false); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public static async void CreateNew(string NewLibraryPath, bool Backup) { try { if (string.IsNullOrEmpty(NewLibraryPath)) { return; } // If we are not creating a backup library if (!Backup) { await CloseSteamAsync(); // Define steam dll paths for better looking string SteamDLLPath = Path.Combine(NewLibraryPath, "Steam.dll"); if (!File.Exists(SteamDLLPath)) { // Copy Steam.dll as steam needs it File.Copy(Path.Combine(Properties.Settings.Default.steamInstallationPath, "Steam.dll"), SteamDLLPath, true); } if (!Directory.Exists(Path.Combine(NewLibraryPath, "SteamApps"))) { // create SteamApps directory at requested directory Directory.CreateDirectory(Path.Combine(NewLibraryPath, "SteamApps")); } // If Steam.dll moved succesfully if (File.Exists(SteamDLLPath)) // in case of permissions denied { // Call KeyValue in act Framework.KeyValue Key = new Framework.KeyValue(); // Read vdf file as text Key.ReadFileAsText(Definitions.Global.Steam.vdfFilePath); // Add our new library to vdf file so steam will know we have a new library Key["Software"]["Valve"]["Steam"].Children.Add(new Framework.KeyValue(string.Format("BaseInstallFolder_{0}", Definitions.List.Libraries.Select(x => x.Type == Definitions.Enums.LibraryType.Steam).Count()), NewLibraryPath)); // Save vdf file Key.SaveToFile(Definitions.Global.Steam.vdfFilePath, false); // Show a messagebox to user about process MessageBox.Show(SLM.Translate(nameof(Properties.Resources.CreateSteamLibrary_Created))); // Since this file started to interrupt us? // No need to bother with it since config.vdf is the real deal, just remove it and Steam client will handle. if (File.Exists(Path.Combine(Properties.Settings.Default.steamInstallationPath, "steamapps", "libraryfolders.vdf"))) { File.Delete(Path.Combine(Properties.Settings.Default.steamInstallationPath, "steamapps", "libraryfolders.vdf")); } RestartSteamAsync(); } else { // Show an error to user and cancel the process because we couldn't get Steam.dll in new library dir MessageBox.Show(SLM.Translate(nameof(Properties.Resources.CreateSteamLibrary_UnknownError))); } } // Add library to list AddNew(NewLibraryPath); // Save our settings SLM.Settings.SaveSettings(); } catch (UnauthorizedAccessException ex) { await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate { await Main.FormAccessor.ShowMessageAsync(SLM.Translate(nameof(Properties.Resources.CreateSteamLibrary_UnauthorizedAccessException)), Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.CreateSteamLibrary_UnauthorizedAccessExceptionMessage)), new { NewLibraryPath, ExceptionMessage = ex.Message }), MessageDialogStyle.AffirmativeAndNegative); }, System.Windows.Threading.DispatcherPriority.Normal); logger.Fatal(ex); } catch (Exception ex) { logger.Fatal(ex); } }
public static async void CreateNew(string NewLibraryPath, bool Backup) { try { if (string.IsNullOrEmpty(NewLibraryPath)) { return; } // If we are not creating a backup library if (!Backup) { await CloseSteamAsync(); // Define steam dll paths for better looking string SteamDLLPath = Path.Combine(NewLibraryPath, "Steam.dll"); if (!File.Exists(SteamDLLPath)) { // Copy Steam.dll as steam needs it File.Copy(Path.Combine(Properties.Settings.Default.steamInstallationPath, "Steam.dll"), SteamDLLPath, true); } if (!Directory.Exists(Path.Combine(NewLibraryPath, "SteamApps"))) { // create SteamApps directory at requested directory Directory.CreateDirectory(Path.Combine(NewLibraryPath, "SteamApps")); } // If Steam.dll moved succesfully if (File.Exists(SteamDLLPath)) // in case of permissions denied { // Call KeyValue in act Framework.KeyValue Key = new Framework.KeyValue(); // Read vdf file as text Key.ReadFileAsText(Definitions.Global.Steam.vdfFilePath); // Add our new library to vdf file so steam will know we have a new library Key["Software"]["Valve"]["Steam"].Children.Add(new Framework.KeyValue(string.Format("BaseInstallFolder_{0}", Definitions.List.Libraries.Select(x => x.Type == Definitions.Enums.LibraryType.Steam).Count()), NewLibraryPath)); // Save vdf file Key.SaveToFile(Definitions.Global.Steam.vdfFilePath, false); // Show a messagebox to user about process MessageBox.Show("New Steam library created"); // Since this file started to interrupt us? // No need to bother with it since config.vdf is the real deal, just remove it and Steam client will handle. if (File.Exists(Path.Combine(Properties.Settings.Default.steamInstallationPath, "steamapps", "libraryfolders.vdf"))) { File.Delete(Path.Combine(Properties.Settings.Default.steamInstallationPath, "steamapps", "libraryfolders.vdf")); } RestartSteamAsync(); } else { // Show an error to user and cancel the process because we couldn't get Steam.dll in new library dir MessageBox.Show("Failed to copy Steam.dll into new library directory. Permission error, maybe?"); } } // Add library to list AddNew(NewLibraryPath); // Save our settings SLM.Settings.SaveSettings(); } catch (Exception ex) { logger.Fatal(ex); Definitions.SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex)); } }