Пример #1
0
        public static void RemoveLibrary(Library libraryToRemove)
        {
            if (UtilityBox.IsSteamRunning())
            {
                ErrorHandler.Instance.ShowNotificationMessage("Turn Off Steam removing steam library.");
                return;
            }
            RealSizeOnDiskTask.Instance.Cancel();
            LibraryDetector.Refresh();
            Library refreshedLibraryToRemove = null;

            foreach (Library library in BindingDataContext.Instance.LibraryList)
            {
                if (libraryToRemove.LibraryDirectory.Equals(library.LibraryDirectory, StringComparison.CurrentCultureIgnoreCase))
                {
                    refreshedLibraryToRemove = library;
                }
            }
            if (refreshedLibraryToRemove == null)
            {
                ErrorHandler.Instance.ShowErrorMessage("Library you are trying to remove is already removed.");
                return;
            }
            string newLibraryDirectory = refreshedLibraryToRemove.LibraryDirectory + "_removed";

            newLibraryDirectory = StringOperations.RenamePathWhenExists(newLibraryDirectory, "_removed");
            FileSystem.RenameDirectory(refreshedLibraryToRemove.LibraryDirectory, Path.GetFileName(newLibraryDirectory));
            BindingDataContext.Instance.LibraryList.Remove(refreshedLibraryToRemove);
            RealSizeOnDiskTask.Instance.Start();
            SteamConfigFileWriter.WriteLibraryList();
            ErrorHandler.Instance.ShowNotificationMessage("Library will still exist on harddrive. It is only removed from the list.");
            Process.Start(refreshedLibraryToRemove.LibraryDirectory + "_removed");
        }
Пример #2
0
        private static BindingList <Library> DetectSteamLibraries(string steamPath, BindingList <Library> libraryList)
        {
            SteamConfigFile steamConfigFile = SteamConfigFileReader.ReadLibraryList(steamPath + "\\steamapps\\libraryfolders.vdf");

            if (steamConfigFile.ConfigType != "LibraryFolders")
            {
                ErrorHandler.Instance.ShowCriticalErrorMessage(steamPath + "\\steamapps\\libraryfolders.vdf has wrong format or it is not supported anymore. Try running steam once to fix corrupted file.");
            }
            //Adds Main Steam Library
            Library library = new Library();

            library.LibraryDirectory = steamPath;
            libraryList.Add(library);
            //Adds Other Steam Libraries
            foreach (SteamConfigFileProperty steamConfigFileProperty in steamConfigFile.SteamConfigFilePropertyList)
            {
                if (steamConfigFileProperty.Name.Equals("TimeNextStatsReport") || steamConfigFileProperty.Name.Equals("ContentStatsID"))
                {
                    continue;
                }
                if (!Directory.Exists(steamConfigFileProperty.Value + "\\SteamApps"))
                {
                    ErrorHandler.Instance.Log(steamConfigFileProperty.Value + "\\SteamApps" + "does not exist. Removed from list of libraries.");
                    continue;
                }

                library = new Library();
                library.LibraryDirectory = steamConfigFileProperty.Value;
                libraryList.Add(library);
            }
            bool isLibraryChaged = false;

            foreach (Library libraryLoop in libraryList)
            {
                string libraryDirectory = libraryLoop.LibraryDirectory;
                if (libraryDirectory.EndsWith("_removed"))
                {
                    libraryDirectory = StringOperations.RemoveStringAtEnd(libraryDirectory, "_removed");
                    libraryDirectory = StringOperations.RenamePathWhenExists(libraryDirectory);
                    FileSystem.RenameDirectory(libraryLoop.LibraryDirectory, Path.GetFileName(libraryDirectory));
                    library.LibraryDirectory = libraryDirectory;
                    isLibraryChaged          = true;
                }
            }
            if (isLibraryChaged)
            {
                SteamConfigFileWriter.WriteLibraryList();
            }
            return(libraryList);
        }
Пример #3
0
        public static void AddLibrary()
        {
            if (UtilityBox.IsSteamRunning())
            {
                ErrorHandler.Instance.ShowNotificationMessage("Turn Off Steam removing steam library.");
                return;
            }
            RealSizeOnDiskTask.Instance.Cancel();
            LibraryDetector.Refresh();
            RealSizeOnDiskTask.Instance.Start();
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

            folderBrowserDialog.Description = "Create or select new Steam library folder:";
            bool   isSelectedPathValidated = false;
            string selectedPath;

            while (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                selectedPath            = folderBrowserDialog.SelectedPath;
                isSelectedPathValidated = ValidateSelectedPath(selectedPath);
                if (isSelectedPathValidated)
                {
                    break;
                }
            }
            if (!isSelectedPathValidated)
            {
                return;
            }
            selectedPath = folderBrowserDialog.SelectedPath;
            if (selectedPath.EndsWith("_removed"))
            {
                selectedPath = StringOperations.RemoveStringAtEnd(selectedPath, "_removed");
                selectedPath = StringOperations.RenamePathWhenExists(selectedPath);
                FileSystem.RenameDirectory(folderBrowserDialog.SelectedPath, Path.GetFileName(selectedPath));
            }
            Library library = new Library();

            library.GamesList        = new SortableBindingList <Game>();
            library.LibraryDirectory = selectedPath;
            Directory.CreateDirectory(selectedPath + "\\steamapps");
            RealSizeOnDiskTask.Instance.Cancel();
            BindingDataContext.Instance.LibraryList.Add(library);
            SteamConfigFileWriter.WriteLibraryList();
            LibraryDetector.Refresh();
            RealSizeOnDiskTask.Instance.Start();
        }