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));
            }
        }
Example #2
0
            public static void GenerateLibraryList()
            {
                try
                {
                    if (File.Exists(Path.Combine(Properties.Settings.Default.steamInstallationPath, "Steam.exe")))
                    {
                        AddNew(Properties.Settings.Default.steamInstallationPath, true);
                    }

                    // Make a KeyValue reader
                    Framework.KeyValue KeyValReader = new Framework.KeyValue();

                    // If config.vdf exists
                    if (File.Exists(Definitions.Global.Steam.vdfFilePath))
                    {
                        // Read our vdf file as text
                        KeyValReader.ReadFileAsText(Definitions.Global.Steam.vdfFilePath);

                        KeyValReader = KeyValReader["Software"]["Valve"]["Steam"];
                        if (KeyValReader?.Children.Count > 0)
                        {
                            foreach (var key in KeyValReader.Children.Where(x => x.Name.StartsWith("BaseInstallFolder", StringComparison.OrdinalIgnoreCase)))
                            {
                                AddNew(key.Value);
                            }

                            Definitions.SLM.UserSteamID64 = (KeyValReader["Accounts"]?.Children.Count > 0) ? KeyValReader["Accounts"]?.Children.FirstOrDefault()?.Children.FirstOrDefault()?.Value : null;
                        }
                    }
                    else /* Could not locate LibraryFolders.vdf */ } {
            }
        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 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));
            }
        }
Example #7
0
            public static void GenerateLibraryList()
            {
                try
                {
                    if (File.Exists(Path.Combine(Properties.Settings.Default.steamInstallationPath, "Steam.exe")))
                    {
                        AddNew(Properties.Settings.Default.steamInstallationPath, true);
                    }

                    // Make a KeyValue reader
                    Framework.KeyValue KeyValReader = new Framework.KeyValue();

                    // If config.vdf exists
                    if (File.Exists(Definitions.Global.Steam.vdfFilePath))
                    {
                        // Read our vdf file as text
                        KeyValReader.ReadFileAsText(Definitions.Global.Steam.vdfFilePath);

                        KeyValReader = KeyValReader["Software"]["Valve"]["Steam"];
                        if (KeyValReader?.Children.Count > 0)
                        {
                            foreach (var key in KeyValReader.Children.Where(x => x.Name.StartsWith("BaseInstallFolder", StringComparison.OrdinalIgnoreCase)))
                            {
                                AddNew(key.Value);
                            }

                            if (KeyValReader["Accounts"]?.Children.Count > 0)
                            {
                                foreach (var account in KeyValReader["Accounts"].Children)
                                {
                                    var steamID = account.Children.SingleOrDefault(x => x.Name == "SteamID");
                                    if (steamID == null)
                                    {
                                        continue;
                                    }

                                    Definitions.List.SteamUserIDList.Add(new Tuple <string, string>(account.Name, steamID.Value));
                                }

                                Main.FormAccessor.SettingsView.SteamUserIDList.SelectedItem = Definitions.List.SteamUserIDList.Find(x => x.Item2 == Properties.Settings.Default.SteamID64);
                            }
                        }
                    }
                    else /* Could not locate LibraryFolders.vdf */ } {
            }
Example #8
0
        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 { }
        }
Example #9
0
        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());
            }
        }
Example #10
0
        public static void readGameDetailsFromZip(string zipPath, Definitions.Library targetLibrary)
        {
            try
            {
                // Open archive for read
                using (ZipArchive compressedArchive = ZipFile.OpenRead(zipPath))
                    // For each file in opened archive
                    foreach (ZipArchiveEntry acfFilePath in compressedArchive.Entries.Where(x => x.Name.Contains(".acf")))
                    {
                        // If it contains
                        // Define a KeyValue reader
                        Framework.KeyValue Key = new Framework.KeyValue();

                        // Open .acf file from archive as text
                        Key.ReadAsText(acfFilePath.Open());

                        // If acf file has no children, skip this archive
                        if (Key.Children.Count == 0)
                        {
                            continue;
                        }

                        AddNewGame(acfFilePath.FullName, Convert.ToInt32(Key["appID"].Value), !string.IsNullOrEmpty(Key["name"].Value) ? Key["name"].Value : Key["UserConfig"]["name"].Value, Key["installdir"].Value, targetLibrary, Convert.ToInt64(Key["SizeOnDisk"].Value), true);
                    }
            }
            catch (InvalidDataException iEx)
            {
                MessageBoxResult removeTheBuggenArchive = MessageBox.Show($"An error happened while parsing zip file ({zipPath})\n\nIt is still suggested to check the archive file manually to see if it is really corrupted or not!\n\nWould you like to remove the given archive file?", "An error happened while parsing zip file", MessageBoxButton.YesNo);

                if (removeTheBuggenArchive == MessageBoxResult.Yes)
                {
                    new FileInfo(zipPath).Delete();
                }

                System.Diagnostics.Debug.WriteLine(iEx);
            }
        }
        public void UpdateAppList()
        {
            try
            {
                SteamAppsFolder.Refresh();

                if (!SteamAppsFolder.Exists)
                {
                    SteamAppsFolder.Create();
                    SteamAppsFolder.Refresh();

                    if (!SteamAppsFolder.Exists)
                    {
                        MessageBox.Show(Framework.StringFormat.Format(Functions.SLM.Translate(nameof(Properties.Resources.SteamLibrary_CantCreate)), new { SteamAppsFolderFullPath = SteamAppsFolder.FullName }));
                        return;
                    }
                }

                if (Apps.Count > 0)
                {
                    Apps.Clear();
                }

                // Foreach *.acf file found in library
                foreach (FileInfo AcfFile in SteamAppsFolder.EnumerateFiles("appmanifest_*.acf", SearchOption.TopDirectoryOnly).ToList())
                {
                    // Define a new value and call KeyValue
                    Framework.KeyValue KeyValReader = new Framework.KeyValue();

                    // Read the *.acf file as text
                    KeyValReader.ReadFileAsText(AcfFile.FullName);

                    // If key doesn't contains a child (value in acf file)
                    if (KeyValReader.Children.Count == 0)
                    {
                        List.LCProgress.Report(new List.JunkInfo
                        {
                            FSInfo  = new FileInfo(AcfFile.FullName),
                            Size    = AcfFile.Length,
                            Library = Library
                        });

                        continue;
                    }

                    Functions.App.AddSteamApp(Convert.ToInt32(KeyValReader["appID"].Value), KeyValReader["name"].Value ?? KeyValReader["UserConfig"]["name"].Value, KeyValReader["installdir"].Value, Library, Convert.ToInt64(KeyValReader["SizeOnDisk"].Value), Convert.ToInt64(KeyValReader["LastUpdated"].Value), false);
                }

                // Do a loop for each *.zip file in library
                Parallel.ForEach(Directory.EnumerateFiles(SteamAppsFolder.FullName, "*.zip", SearchOption.TopDirectoryOnly).ToList(), ArchiveFile => Functions.App.ReadDetailsFromZip(ArchiveFile, Library));

                SteamBackupsFolder.Refresh();
                if (Library.Type == Enums.LibraryType.SLM && SteamBackupsFolder.Exists)
                {
                    foreach (FileInfo SkuFile in SteamBackupsFolder.EnumerateFiles("*.sis", SearchOption.AllDirectories).ToList())
                    {
                        Framework.KeyValue KeyValReader = new Framework.KeyValue();

                        KeyValReader.ReadFileAsText(SkuFile.FullName);

                        string[] AppNames = System.Text.RegularExpressions.Regex.Split(KeyValReader["name"].Value, " and ");

                        int  i       = 0;
                        long AppSize = Functions.FileSystem.GetDirectorySize(SkuFile.Directory, true);
                        foreach (Framework.KeyValue App in KeyValReader["apps"].Children)
                        {
                            if (Apps.Count(x => x.AppID == Convert.ToInt32(App.Value) && x.IsSteamBackup) > 0)
                            {
                                continue;
                            }

                            Functions.App.AddSteamApp(Convert.ToInt32(App.Value), AppNames[i], SkuFile.DirectoryName, Library, AppSize, SkuFile.LastWriteTimeUtc.ToUnixTimestamp(), false, true);

                            if (AppNames.Length > 1)
                            {
                                i++;
                            }
                        }
                    }
                }

                if (SLM.CurrentSelectedLibrary != null && SLM.CurrentSelectedLibrary == Library)
                {
                    Functions.App.UpdateAppPanel(Library);
                }
            }
            catch (UnauthorizedAccessException uaex)
            {
                Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate
                {
                    await Main.FormAccessor.ShowMessageAsync(Functions.SLM.Translate(nameof(Properties.Resources.UnauthorizedAccessException)), Framework.StringFormat.Format(Functions.SLM.Translate(nameof(Properties.Resources.UnauthorizedAccessExceptionMessage)), new { FullPath, ExceptionMessage = uaex.Message }));
                }, System.Windows.Threading.DispatcherPriority.Normal);
            }
            catch (DirectoryNotFoundException dnfex)
            {
                Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate
                {
                    await Main.FormAccessor.ShowMessageAsync(Functions.SLM.Translate(nameof(Properties.Resources.DirectoryNotFoundException)), Framework.StringFormat.Format(Functions.SLM.Translate(nameof(Properties.Resources.DirectoryNotFoundExceptionMessage)), new { FolderfullPath = FullPath, ExceptionMessage = dnfex.Message }));
                }, System.Windows.Threading.DispatcherPriority.Normal);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                logger.Fatal(ex);
            }
        }
Example #12
0
        public static void generateLibraryList()
        {
            try
            {
                // If we already have definitions in our list
                if (Definitions.List.Libraries.Count != 0)
                {
                    // Clear them so they don't conflict
                    Definitions.List.Libraries.Clear();
                }

                if (File.Exists(Path.Combine(Properties.Settings.Default.steamInstallationPath, "Steam.exe")))
                {
                    addNewLibrary(Properties.Settings.Default.steamInstallationPath, true, false);
                }

                // Make a KeyValue reader
                Framework.KeyValue Key = new Framework.KeyValue();

                // If config.vdf exists
                if (File.Exists(Definitions.Steam.vdfFilePath))
                {
                    // Read our vdf file as text
                    Key.ReadFileAsText(Definitions.Steam.vdfFilePath);

                    // Set user id from config file
                    Definitions.SLM.userSteamID64 = Key.Children[0].Children[0].Children[0].Children.Find(x => x.Name == "Accounts").Children[0].Children[0].Value;

                    foreach (Framework.KeyValue key in Key.Children[0].Children[0].Children[0].Children.FindAll(x => x.Name.Contains("BaseInstallFolder")))
                    {
                        addNewLibrary(key.Value, false, false);
                    }
                }
                else /* Could not locate LibraryFolders.vdf */ } {
                // If we have a backup library(s)
                if (Properties.Settings.Default.backupDirectories != null)
                {
                    // for each backup library we have do a loop
                    foreach (string backupDirectory in Properties.Settings.Default.backupDirectories)
                    {
                        // If directory not exists
                        if (!Directory.Exists(backupDirectory))
                        {
                            // Make a new dialog and ask user to update library path
                            MessageBoxResult askUserToUpdatePath = MessageBox.Show("Backup library couldn't be found, would you like to select a new path?", $"Backup library ({backupDirectory}) couldn't be found!", MessageBoxButton.YesNo, MessageBoxImage.Question);

                            // If user wants to update
                            if (askUserToUpdatePath == MessageBoxResult.Yes)
                            {
                                // Show another dialog to select new path
                                System.Windows.Forms.FolderBrowserDialog newBackupDirectoryPath = new System.Windows.Forms.FolderBrowserDialog();

                                // If new path selected from dialog
                                if (newBackupDirectoryPath.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                                {
                                    // define selected path to variable
                                    string newLibraryPath = newBackupDirectoryPath.SelectedPath;

                                    // Check if the selected path is exists
                                    if (!libraryExists(newLibraryPath))
                                    {
                                        // If not exists then get directory root of selected path and see if it is equals with our selected path
                                        if (Directory.GetDirectoryRoot(newLibraryPath) != newLibraryPath)
                                        {
                                            addNewLibrary(newLibraryPath, false, true);
                                        }
                                        else
                                        {
                                            // Else show an error message to user
                                            MessageBox.Show("Libraries can not be created at root");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Library exists");
                                    }
                                }
                            }
                        }
                        else
                        {
                            addNewLibrary(backupDirectory, false, true);
                        }
                    }
                }
        }
Example #13
0
        public void UpdateGameList()
        {
            try
            {
                if (!steamAppsPath.Exists)
                {
                    steamAppsPath.Create();
                }
                else if (Games.Count > 0)
                {
                    Games.Clear();
                }

                // Foreach *.acf file found in library
                //foreach (string game in Directory.EnumerateFiles(steamAppsPath.FullName, "*.acf", SearchOption.TopDirectoryOnly))
                Parallel.ForEach(steamAppsPath.EnumerateFiles("*.acf", SearchOption.TopDirectoryOnly), acfFilePath =>
                {
                    // Define a new value and call KeyValue
                    Framework.KeyValue Key = new Framework.KeyValue();

                    // Read the *.acf file as text
                    Key.ReadFileAsText(acfFilePath.FullName);

                    // If key doesn't contains a child (value in acf file)
                    if (Key.Children.Count == 0)
                    {
                        return;
                    }

                    Functions.Games.AddNewGame(acfFilePath.FullName, Convert.ToInt32(Key["appID"].Value), !string.IsNullOrEmpty(Key["name"].Value) ? Key["name"].Value : Key["UserConfig"]["name"].Value, Key["installdir"].Value, this, Convert.ToInt64(Key["SizeOnDisk"].Value), false);
                });

                // Do a loop for each *.zip file in library
                Parallel.ForEach(Directory.EnumerateFiles(steamAppsPath.FullName, "*.zip", SearchOption.TopDirectoryOnly), gameArchive =>
                {
                    Functions.Games.readGameDetailsFromZip(gameArchive, this);
                });

                // If library is backup library
                if (Backup)
                {
                    foreach (string skuFile in Directory.EnumerateFiles(fullPath, "*.sis", SearchOption.AllDirectories))
                    {
                        Framework.KeyValue Key = new Framework.KeyValue();

                        Key.ReadFileAsText(skuFile);

                        string[] name = System.Text.RegularExpressions.Regex.Split(Key["name"].Value, " and ");

                        int  i        = 0;
                        long gameSize = Functions.fileSystem.GetDirectorySize(new DirectoryInfo(skuFile).Parent.FullName, true);
                        foreach (Framework.KeyValue app in Key["apps"].Children)
                        {
                            if (Games.Count(x => x.appID == Convert.ToInt32(app.Value)) > 0)
                            {
                                continue;
                            }

                            Functions.Games.AddNewGame(skuFile, Convert.ToInt32(app.Value), name[i], Path.GetDirectoryName(skuFile), this, gameSize, false, true);

                            if (name.Count() > 1)
                            {
                                i++;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public static void UpdateLibraries()
        {
            try
            {
                // If we already have definitions in our list
                if (Definitions.List.Library.Count != 0)
                    // Clear them so they don't conflict
                    Definitions.List.Library.Clear();

                // If Steam.exe not exists in the path we set then return
                if (!File.Exists(Properties.Settings.Default.SteamInstallationPath + "Steam.exe")) return;

                // Our main library doesn't included in LibraryFolders.vdf so we have to include it manually
                Definitions.List.LibraryList Library = new Definitions.List.LibraryList();

                // Tell it is our main game library which can be handy in future
                Library.Main = true;

                // Define our library path to SteamApps
                Library.Directory = Properties.Settings.Default.SteamInstallationPath + @"SteamApps\";

                // Count how many games we have installed in our library
                Library.GameCount = Games.GetGamesCountFromLibrary(Library);

                // And add collected informations to our global list
                Definitions.List.Library.Add(Library);

                // Make a KeyValue reader
                Framework.KeyValue Key = new Framework.KeyValue();

                // Define our LibraryFolders.VDF path for easier use
                string vdfFilePath = Properties.Settings.Default.SteamInstallationPath + @"SteamApps\libraryfolders.vdf";

                // If LibraryFolders.vdf exists
                if (System.IO.File.Exists(vdfFilePath))
                {
                    // Read our vdf file as text
                    Key.ReadFileAsText(vdfFilePath);

                    // Until someone gives a better idea, try to look for 255 Keys but break at first null key
                    for (int i = 1; i < Definitions.Steam.maxLibraryCount; i++)
                    {
                        // break if key is not exists
                        if (Key[i.ToString()].Value == null)
                            break;

                        // Define a new library
                        Library = new Definitions.List.LibraryList();

                        // Define library path
                        Library.Directory = Key[i.ToString()].Value + @"\SteamApps\";

                        // Define game count in library
                        Library.GameCount = Games.GetGamesCountFromLibrary(Library);

                        // Add our new library to list
                        Definitions.List.Library.Add(Library);
                    }
                }
                else { /* Could not locate LibraryFolders.vdf */ }

                // If we have a backup library(s)
                if (Properties.Settings.Default.BackupDirectories != null)
                {
                    // for each backup library we have do a loop
                    foreach (object backupDirectory in Properties.Settings.Default.BackupDirectories)
                    {
                        // Define a new library
                        Library = new Definitions.List.LibraryList();

                        // Define it is a backup library
                        Library.Backup = true;

                        // Define library path
                        Library.Directory = backupDirectory.ToString();

                        // Define game count in library
                        Library.GameCount = Functions.Games.GetGamesCountFromLibrary(Library);

                        // Add our new library to list
                        Definitions.List.Library.Add(Library);
                    }
                }

                // Update Libraries List visually
                UpdateMainForm();
            }
            catch { }
        }
        public override async void UpdateAppList()
        {
            try
            {
                if (IsUpdatingAppList)
                {
                    return;
                }

                IsUpdatingAppList = true;

                DirectoryList["SteamApps"].Refresh();

                if (!DirectoryList["SteamApps"].Exists)
                {
                    DirectoryList["SteamApps"].Create();
                    DirectoryList["SteamApps"].Refresh();

                    if (!DirectoryList["SteamApps"].Exists)
                    {
                        MessageBox.Show(Framework.StringFormat.Format(
                                            Functions.SLM.Translate(nameof(Properties.Resources.SteamAppsFolderNotExists)),
                                            new { SteamAppsFolderFullPath = DirectoryList["SteamApps"].FullName }));
                        return;
                    }
                }

                if (Apps.Count > 0)
                {
                    Apps.Clear();
                }

                // Foreach *.acf file found in library
                await DirectoryList["SteamApps"].EnumerateFiles("appmanifest_*.acf", SearchOption.TopDirectoryOnly)
                .ParallelForEachAsync(
                    async acfFile =>
                {
                    // Define a new value and call KeyValue
                    var keyValReader = new Framework.KeyValue();

                    // Read the *.acf file as text
                    keyValReader.ReadFileAsText(acfFile.FullName);

                    // If key doesn't contains a child (value in acf file)
                    if (keyValReader.Children.Count == 0)
                    {
                        if (List.IgnoredJunkItems.Contains(acfFile.FullName))
                        {
                            return;
                        }

                        List.LcProgress.Report(new List.JunkInfo
                        {
                            FSInfo  = new FileInfo(acfFile.FullName),
                            Size    = Functions.FileSystem.FormatBytes(acfFile.Length),
                            Library = this,
                            Tag     = JunkType.CorruptedDataFile
                        });

                        return;
                    }

                    await Functions.App.AddSteamAppAsync(Convert.ToInt32(keyValReader["appid"].Value),
                                                         keyValReader["name"].Value ?? keyValReader["UserConfig"]["name"].Value,
                                                         keyValReader["installdir"].Value, Convert.ToInt32(keyValReader["StateFlags"].Value),
                                                         this, Convert.ToInt64(keyValReader["SizeOnDisk"].Value),
                                                         Convert.ToInt64(keyValReader["LastUpdated"].Value), false).ConfigureAwait(false);
                }).ConfigureAwait(false);

                // Do a loop for each *.zip file in library
                await Directory.EnumerateFiles(DirectoryList["SteamApps"].FullName, "*.zip", SearchOption.TopDirectoryOnly)
                .ParallelForEachAsync(async archive => { await Task.Run(() => Functions.App.ReadDetailsFromZip(archive, this)).ConfigureAwait(false); }).ConfigureAwait(false);

                DirectoryList["SteamBackups"].Refresh();
                if (Type == LibraryType.SLM && DirectoryList["SteamBackups"].Exists)
                {
                    await DirectoryList["SteamBackups"].EnumerateFiles("*.sis", SearchOption.AllDirectories).ParallelForEachAsync(
                        async skuFile =>
                    {
                        var keyValReader = new Framework.KeyValue();

                        keyValReader.ReadFileAsText(skuFile.FullName);

                        var appNames = System.Text.RegularExpressions.Regex.Split(keyValReader["name"].Value, " and ");

                        var i       = 0;
                        var appSize = Functions.FileSystem.GetDirectorySize(skuFile.Directory, true);
                        foreach (var app in keyValReader["apps"].Children)
                        {
                            if (Apps.Count(x => x.AppId == Convert.ToInt32(app.Value) && x.IsSteamBackup) > 0)
                            {
                                continue;
                            }

                            await Functions.App.AddSteamAppAsync(Convert.ToInt32(app.Value), appNames[i],
                                                                 skuFile.DirectoryName, 4, this, appSize, skuFile.LastWriteTimeUtc.ToUnixTimestamp(),
                                                                 false, true).ConfigureAwait(false);

                            if (appNames.Length > 1)
                            {
                                i++;
                            }
                        }
                    }).ConfigureAwait(false);
                }

                if (SLM.CurrentSelectedLibrary != null && SLM.CurrentSelectedLibrary == this)
                {
                    Functions.App.UpdateAppPanel(this);
                }

                IsUpdatingAppList = false;
            }
            catch (UnauthorizedAccessException ex)
            {
                await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(
                    async delegate
                {
                    await Main.FormAccessor.ShowMessageAsync(
                        Functions.SLM.Translate(nameof(Properties.Resources.UnauthorizedAccessException)),
                        Framework.StringFormat.Format(
                            Functions.SLM.Translate(nameof(Properties.Resources.UnauthorizedAccessExceptionMessage)),
                            new { FullPath, ExceptionMessage = ex.Message })).ConfigureAwait(true);
                }, System.Windows.Threading.DispatcherPriority.Normal).ConfigureAwait(true);

                IsUpdatingAppList = false;
            }
            catch (DirectoryNotFoundException ex)
            {
                await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(
                    async delegate
                {
                    await Main.FormAccessor.ShowMessageAsync(
                        Functions.SLM.Translate(nameof(Properties.Resources.DirectoryNotFoundException)),
                        Framework.StringFormat.Format(
                            Functions.SLM.Translate(nameof(Properties.Resources.DirectoryNotFoundExceptionMessage)),
                            new { FolderfullPath = FullPath, ExceptionMessage = ex.Message }))
                    .ConfigureAwait(true);
                }, System.Windows.Threading.DispatcherPriority.Normal).ConfigureAwait(true);

                IsUpdatingAppList = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Logger.Fatal(ex);
                IsUpdatingAppList = false;
            }
        }
Example #16
0
            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));
                }
            }
        public void UpdateAppList()
        {
            try
            {
                SteamAppsFolder.Refresh();

                if (!SteamAppsFolder.Exists)
                {
                    SteamAppsFolder.Create();
                    SteamAppsFolder.Refresh();

                    if (!SteamAppsFolder.Exists)
                    {
                        MessageBox.Show("Can not create steam apps folder at: " + SteamAppsFolder.FullName + "\n\nIf you believe this path exists and SLM can't do it's job, please contact with me.");
                        return;
                    }
                }

                if (Apps.Count > 0)
                {
                    Apps.Clear();
                }

                // Foreach *.acf file found in library
                Parallel.ForEach(SteamAppsFolder.EnumerateFiles("appmanifest_*.acf", SearchOption.TopDirectoryOnly).ToList(), AcfFile =>
                {
                    // Define a new value and call KeyValue
                    Framework.KeyValue KeyValReader = new Framework.KeyValue();

                    // Read the *.acf file as text
                    KeyValReader.ReadFileAsText(AcfFile.FullName);

                    // If key doesn't contains a child (value in acf file)
                    if (KeyValReader.Children.Count == 0)
                    {
                        List.LCItems.Add(new List.JunkInfo
                        {
                            FSInfo  = new FileInfo(AcfFile.FullName),
                            Size    = AcfFile.Length,
                            Library = Library
                        });

                        return;
                    }

                    Functions.App.AddSteamApp(Convert.ToInt32(KeyValReader["appID"].Value), KeyValReader["name"].Value ?? KeyValReader["UserConfig"]["name"].Value, KeyValReader["installdir"].Value, Library, Convert.ToInt64(KeyValReader["SizeOnDisk"].Value), Convert.ToInt64(KeyValReader["LastUpdated"].Value), false);
                });

                // Do a loop for each *.zip file in library
                Parallel.ForEach(Directory.EnumerateFiles(SteamAppsFolder.FullName, "*.zip", SearchOption.TopDirectoryOnly).ToList(), ArchiveFile => Functions.App.ReadDetailsFromZip(ArchiveFile, Library));

                SteamBackupsFolder.Refresh();
                if (Library.Type == Enums.LibraryType.SLM && SteamBackupsFolder.Exists)
                {
                    foreach (FileInfo SkuFile in SteamBackupsFolder.EnumerateFiles("*.sis", SearchOption.AllDirectories).ToList())
                    {
                        Framework.KeyValue KeyValReader = new Framework.KeyValue();

                        KeyValReader.ReadFileAsText(SkuFile.FullName);

                        string[] AppNames = System.Text.RegularExpressions.Regex.Split(KeyValReader["name"].Value, " and ");

                        int  i       = 0;
                        long AppSize = Functions.FileSystem.GetDirectorySize(SkuFile.Directory, true);
                        foreach (Framework.KeyValue App in KeyValReader["apps"].Children)
                        {
                            if (Apps.Count(x => x.AppID == Convert.ToInt32(App.Value) && x.IsSteamBackup) > 0)
                            {
                                continue;
                            }

                            Functions.App.AddSteamApp(Convert.ToInt32(App.Value), AppNames[i], SkuFile.DirectoryName, Library, AppSize, SkuFile.LastWriteTimeUtc.ToUnixTimestamp(), false, true);

                            if (AppNames.Length > 1)
                            {
                                i++;
                            }
                        }
                    }
                }

                if (SLM.CurrentSelectedLibrary != null)
                {
                    if (SLM.CurrentSelectedLibrary == Library)
                    {
                        Functions.App.UpdateAppPanel(Library);
                    }
                }
            }
            catch (UnauthorizedAccessException uaex)
            {
                Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate
                {
                    await Main.FormAccessor.ShowMessageAsync("UnauthorizedAccessException!", $"[{FullPath}] An error releated to folder permissions happened during generating library content. Running SLM as Administrator might help.\n\nError: {uaex.Message}");
                }, System.Windows.Threading.DispatcherPriority.Normal);
            }
            catch (DirectoryNotFoundException dnfex)
            {
                Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate
                {
                    await Main.FormAccessor.ShowMessageAsync("UnauthorizedAccessException!", $"[{FullPath}] Folder couldn't be created/not found. Running SLM as Administrator might help.\n\nIf you believe this path exists and SLM can't do it's job, please contact with me.\n\nError: {dnfex.Message}");
                }, System.Windows.Threading.DispatcherPriority.Normal);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                logger.Fatal(ex);
                SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex));
            }
        }
Example #18
0
            public static void GenerateLibraryList()
            {
                try
                {
                    if (!string.IsNullOrEmpty(Properties.Settings.Default.SteamID64))
                    {
                        var localConfigFilePath = Path.Combine(Properties.Settings.Default.steamInstallationPath, "userdata", Framework.SteamIDConvert.Steam64ToSteam32(Convert.ToInt64(Properties.Settings.Default.SteamID64)).Split(':').Last(), "config", "localconfig.vdf");
                        if (File.Exists(localConfigFilePath))
                        {
                            Framework.KeyValue configFile = new Framework.KeyValue();
                            configFile.ReadFileAsText(localConfigFilePath);

                            var appsPath = configFile["Software"]["Valve"]["Steam"]["apps"];

                            if (appsPath?.Children.Count > 0)
                            {
                                foreach (var app in appsPath.Children)
                                {
                                    var lastPlayed = app["LastPlayed"].Value;
                                    if (lastPlayed != null && !Definitions.List.SteamApps_LastPlayedDic.ContainsKey(Convert.ToInt32(app.Name)))
                                    {
                                        Definitions.List.SteamApps_LastPlayedDic.Add(Convert.ToInt32(app.Name), new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Convert.ToInt64(lastPlayed)));
                                    }
                                }
                            }
                        }
                    }

                    if (File.Exists(Path.Combine(Properties.Settings.Default.steamInstallationPath, "Steam.exe")))
                    {
                        AddNew(Properties.Settings.Default.steamInstallationPath, true);
                    }

                    // If config.vdf exists
                    if (File.Exists(Definitions.Global.Steam.vdfFilePath))
                    {
                        // Make a KeyValue reader
                        Framework.KeyValue KeyValReader = new Framework.KeyValue();

                        // Read our vdf file as text
                        KeyValReader.ReadFileAsText(Definitions.Global.Steam.vdfFilePath);

                        KeyValReader = KeyValReader["Software"]["Valve"]["Steam"];
                        if (KeyValReader?.Children.Count > 0)
                        {
                            foreach (var key in KeyValReader.Children.Where(x => x.Name.StartsWith("BaseInstallFolder", StringComparison.OrdinalIgnoreCase)))
                            {
                                AddNew(key.Value);
                            }

                            if (KeyValReader["Accounts"]?.Children.Count > 0)
                            {
                                foreach (var account in KeyValReader["Accounts"].Children)
                                {
                                    var steamID = account.Children.SingleOrDefault(x => x.Name == "SteamID");
                                    if (steamID == null)
                                    {
                                        continue;
                                    }

                                    Definitions.List.SteamUserIDList.Add(new Tuple <string, string>(account.Name, steamID.Value));
                                }

                                Main.FormAccessor.SettingsView.SteamUserIDList.SelectedItem = Definitions.List.SteamUserIDList.Find(x => x.Item2 == Properties.Settings.Default.SteamID64);
                            }
                        }
                    }
                    else /* Could not locate LibraryFolders.vdf */ } {
            }
Example #19
0
            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);
                }
            }
Example #20
0
        public static async void ReadDetailsFromZip(string ZipPath, Definitions.Library targetLibrary)
        {
            try
            {
                // Open archive for read
                using (ZipArchive Archive = ZipFile.OpenRead(ZipPath))
                {
                    if (Archive.Entries.Count > 0)
                    {
                        // For each file in opened archive
                        foreach (ZipArchiveEntry AcfEntry in Archive.Entries.Where(x => x.Name.Contains("appmanifest_")))
                        {
                            // If it contains
                            // Define a KeyValue reader
                            Framework.KeyValue KeyValReader = new Framework.KeyValue();

                            // Open .acf file from archive as text
                            KeyValReader.ReadAsText(AcfEntry.Open());

                            // If acf file has no children, skip this archive
                            if (KeyValReader.Children.Count == 0)
                            {
                                continue;
                            }

                            AddSteamApp(Convert.ToInt32(KeyValReader["appID"].Value), !string.IsNullOrEmpty(KeyValReader["name"].Value) ? KeyValReader["name"].Value : KeyValReader["UserConfig"]["name"].Value, KeyValReader["installdir"].Value, targetLibrary, Convert.ToInt64(KeyValReader["SizeOnDisk"].Value), Convert.ToInt64(KeyValReader["LastUpdated"].Value), true);
                        }
                    }
                }
            }
            catch (IOException IEx)
            {
                await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate
                {
                    if (await Main.FormAccessor.ShowMessageAsync("An error happened while parsing zip file", $"An error happened while parsing zip file:\n\n{ZipPath}\n\nIt is still suggested to check the archive file manually to see if it is really corrupted or not!\n\nWould you like to remove the given archive file?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings
                    {
                        NegativeButtonText = "Do NOT Remove the archive file"
                    }) == MessageDialogResult.Affirmative)
                    {
                        new FileInfo(ZipPath).Delete();
                    }
                });

                System.Diagnostics.Debug.WriteLine(IEx);
                logger.Fatal(IEx);
            }
            catch (InvalidDataException IEx)
            {
                await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate
                {
                    if (await Main.FormAccessor.ShowMessageAsync("An error happened while parsing zip file", $"An error happened while parsing zip file:\n\n{ZipPath}\n\nIt is still suggested to check the archive file manually to see if it is really corrupted or not!\n\nWould you like to remove the given archive file?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings
                    {
                        NegativeButtonText = "Do NOT Remove the archive file"
                    }) == MessageDialogResult.Affirmative)
                    {
                        new FileInfo(ZipPath).Delete();
                    }
                });

                System.Diagnostics.Debug.WriteLine(IEx);
                logger.Fatal(IEx);
            }
            catch (Exception ex)
            {
                Definitions.SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex));
                logger.Fatal(ex);
            }
        }
Example #21
0
        public static void UpdateGamesList(Definitions.List.LibraryList Library)
        {
            try
            {
                // If our list is not empty
                if (Definitions.List.Game.Count != 0)
                    // Clear the list
                    Definitions.List.Game.Clear();

                // Foreach *.acf file found in library
                foreach (Framework.FileData game in Framework.FastDirectoryEnumerator.EnumerateFiles(Library.Directory, "*.acf", SearchOption.TopDirectoryOnly))
                {
                    // Define a new value and call KeyValue
                    Framework.KeyValue Key = new Framework.KeyValue();

                    // Read the *.acf file as text
                    Key.ReadFileAsText(game.Path);

                    // If key doesn't contains a child (value in acf file)
                    if (Key.Children.Count == 0)
                        // Skip this file (game)
                        continue;

                    // Make a new definition for game
                    Definitions.List.GamesList Game = new Definitions.List.GamesList();

                    // Set game appID
                    Game.appID = Convert.ToInt32(Key["appID"].Value);

                    // Set game name
                    Game.appName = Key["name"].Value;

                    // Set installation path
                    Game.installationPath = Key["installdir"].Value;

                    // Set game library
                    Game.Library = Library;

                    // If game has a folder in "common" dir, define it as exactInstallPath
                    if (Directory.Exists(Path.Combine(Library.Directory, "common", Game.installationPath)))
                        Game.exactInstallPath = Path.Combine(Library.Directory, "common", Game.installationPath);

                    // If game has a folder in "downloading" dir, define it as downloadPath
                    if (Directory.Exists(Path.Combine(Library.Directory, "downloading", Game.appID.ToString())))
                        Game.downloadPath = Path.Combine(Library.Directory, "downloading", Game.appID.ToString());

                    // If game has a folder in "workshop" dir, define it as workShopPath
                    if (Directory.Exists(Path.Combine(Library.Directory, "workshop", "content", Game.appID.ToString())))
                        Game.workShopPath = Path.Combine(Library.Directory, "workshop", "content", Game.appID.ToString());

                    // If game do not have a folder in "common" directory and "downloading" directory then skip this game
                    if (Game.exactInstallPath == null && Game.downloadPath == null)
                        continue; // Do not add pre-loads to list

                    // If SizeOnDisk value from .ACF file is not equals to 0
                    if (Key["SizeOnDisk"].Value != "0")
                    {
                        // If game has "common" folder
                        if (Game.exactInstallPath != null)
                        {
                            // If game size calculation method NOT set as "ACF"
                            if (Properties.Settings.Default.GameSizeCalculationMethod != "ACF")
                                // Calculate game size on disk
                                Game.sizeOnDisk += Functions.FileSystem.GetDirectorySize(Game.exactInstallPath, true);
                            else
                                // Else use the game size from .ACF file
                                Game.sizeOnDisk += Convert.ToInt64(Key["SizeOnDisk"].Value);
                        }

                        // If game has downloading files
                        if (Game.downloadPath != null)
                        {
                            // If game size calculation method NOT set as "ACF"
                            if (Properties.Settings.Default.GameSizeCalculationMethod != "ACF")
                                // Calculate "downloading" folder size
                                Game.sizeOnDisk += Functions.FileSystem.GetDirectorySize(Game.downloadPath, true);
                        }

                        // If game has "workshop" files
                        if (Game.workShopPath != null)
                        {
                            // If game size calculation method NOT set as "ACF"
                            if (Properties.Settings.Default.GameSizeCalculationMethod != "ACF")
                                // Calculate "workshop" files size
                                Game.sizeOnDisk += Functions.FileSystem.GetDirectorySize(Game.workShopPath, true);
                        }

                    }
                    else
                        // Else set game size to 0
                        Game.sizeOnDisk = 0;

                    // Add our game details to global list
                    Definitions.List.Game.Add(Game);
                }

                // If library is backup library
                if (Library.Backup)
                {
                    // Do a loop for each *.zip file in library
                    foreach (Framework.FileData gameArchive in Framework.FastDirectoryEnumerator.EnumerateFiles(Library.Directory, "*.zip", SearchOption.TopDirectoryOnly))
                    {
                        // Open archive for read
                        using (ZipArchive compressedArchive = ZipFile.OpenRead(gameArchive.Path))
                        {
                            // For each file in opened archive
                            foreach (ZipArchiveEntry file in compressedArchive.Entries)
                            {
                                // Check the file if it's name contains .ACF
                                if (file.Name.Contains(".acf"))
                                {
                                    // If it contains
                                    // Define a KeyValue reader
                                    Framework.KeyValue Key = new Framework.KeyValue();

                                    // Open .acf file from archive as text
                                    Key.ReadAsText(file.Open());

                                    // If acf file has no children, skip this archive
                                    if (Key.Children.Count == 0)
                                        return;

                                    // Define a new game
                                    Definitions.List.GamesList Game = new Definitions.List.GamesList();

                                    // Define our app ID
                                    Game.appID = Convert.ToInt32(Key["appID"].Value);

                                    // Define our app name
                                    Game.appName = Key["name"].Value;

                                    // Define it is an archive
                                    Game.Compressed = true;

                                    // Define installation path for game
                                    Game.installationPath = Key["installdir"].Value;

                                    // Define our library
                                    Game.Library = Library;

                                    // If user want us to get archive size from real uncompressed size
                                    if (Properties.Settings.Default.ArchiveSizeCalculationMethod.StartsWith("Uncompressed"))
                                    {
                                        // Open archive to read
                                        using (ZipArchive zip = ZipFile.OpenRead(Path.Combine(Game.Library.Directory, Game.appID + ".zip")))
                                        {
                                            // For each file in archive
                                            foreach (ZipArchiveEntry entry in zip.Entries)
                                            {
                                                // Add file size to sizeOnDisk
                                                Game.sizeOnDisk += entry.Length;
                                            }
                                        }
                                    }
                                    // Else
                                    else
                                    {
                                        // Use FileInfo to get our archive details
                                        FileInfo zip = new FileInfo(Path.Combine(Game.Library.Directory, Game.appID + ".zip"));

                                        // And set archive size as game size
                                        Game.sizeOnDisk = zip.Length;
                                    }

                                    // Add our new game to global definiton
                                    Definitions.List.Game.Add(Game);

                                    // Update main form as visual
                                    Functions.Games.UpdateMainForm();

                                    // we found what we are looking for, return
                                    return;
                                }
                            }
                        }
                    }
                }

                // Focus to game list panel
                Definitions.Accessors.MainForm.panel_GameList.Focus();

                // Update main form as visual
                Functions.Games.UpdateMainForm();
            }
            catch (Exception ex)
            {
                // If user want us to log errors to file
                if (Properties.Settings.Default.LogErrorsToFile)
                    // Log
                    Functions.Log.ErrorsToFile("UpdateGameList", ex.ToString());

                // Show a messagebox to user
                MessageBox.Show("An error happened while updating game list!\n" + ex.ToString());
            }
        }
Example #22
0
        public static async void ReadDetailsFromZip(string ZipPath, Definitions.Library targetLibrary)
        {
            try
            {
                // Open archive for read
                using (ZipArchive Archive = ZipFile.OpenRead(ZipPath))
                {
                    if (Archive.Entries.Count > 0)
                    {
                        // For each file in opened archive
                        foreach (ZipArchiveEntry AcfEntry in Archive.Entries.Where(x => x.Name.Contains("appmanifest_")))
                        {
                            // If it contains
                            // Define a KeyValue reader
                            Framework.KeyValue KeyValReader = new Framework.KeyValue();

                            // Open .acf file from archive as text
                            KeyValReader.ReadAsText(AcfEntry.Open());

                            // If acf file has no children, skip this archive
                            if (KeyValReader.Children.Count == 0)
                            {
                                continue;
                            }

                            AddSteamApp(Convert.ToInt32(KeyValReader["appID"].Value), !string.IsNullOrEmpty(KeyValReader["name"].Value) ? KeyValReader["name"].Value : KeyValReader["UserConfig"]["name"].Value, KeyValReader["installdir"].Value, targetLibrary, Convert.ToInt64(KeyValReader["SizeOnDisk"].Value), Convert.ToInt64(KeyValReader["LastUpdated"].Value), true);
                        }
                    }
                }
            }
            catch (IOException IEx)
            {
                await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate
                {
                    if (await Main.FormAccessor.ShowMessageAsync(SLM.Translate(nameof(Properties.Resources.ReadZip_IOException)), Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.ReadZip_IOExceptionMessage)), new { ZipPath }), MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings
                    {
                        NegativeButtonText = SLM.Translate(Properties.Resources.ReadZip_DontDelete)
                    }) == MessageDialogResult.Affirmative)
                    {
                        File.Delete(ZipPath);
                    }
                });

                System.Diagnostics.Debug.WriteLine(IEx);
                logger.Fatal(IEx);
            }
            catch (InvalidDataException IEx)
            {
                await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(async delegate
                {
                    if (await Main.FormAccessor.ShowMessageAsync(SLM.Translate(nameof(Properties.Resources.ReadZip_InvalidDataException)), Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.ReadZip_InvalidDataExceptionMessage)), new { ZipPath }), MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings
                    {
                        NegativeButtonText = SLM.Translate(Properties.Resources.ReadZip_DontDelete)
                    }) == MessageDialogResult.Affirmative)
                    {
                        File.Delete(ZipPath);
                    }
                });

                System.Diagnostics.Debug.WriteLine(IEx);
                logger.Fatal(IEx);
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
            }
        }