Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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());
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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);
            }
        }