コード例 #1
0
            public static async void AddNew(string LibraryPath, bool IsMainLibrary = false)
            {
                try
                {
                    if (!LibraryPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
                    {
                        LibraryPath += Path.DirectorySeparatorChar;
                    }

                    var newLibrary = new Definitions.Library
                    {
                        Type          = Definitions.Enums.LibraryType.Steam,
                        DirectoryInfo = new DirectoryInfo(LibraryPath)
                    };

                    newLibrary.Steam = new Definitions.SteamLibrary(LibraryPath, newLibrary, IsMainLibrary);

                    Definitions.List.LibraryProgress.Report(newLibrary);

                    await Task.Run(() => newLibrary.Steam.UpdateAppListAsync()).ConfigureAwait(true);

                    await Task.Run(() => newLibrary.Steam.UpdateJunks()).ConfigureAwait(true);
                }
                catch (Exception ex)
                {
                    logger.Fatal(ex);
                }
            }
コード例 #2
0
            public static async void AddNewAsync(string LibraryPath)
            {
                try
                {
                    if (string.IsNullOrEmpty(LibraryPath))
                    {
                        return;
                    }

                    Definitions.Library Library = new Definitions.Library
                    {
                        Type          = Definitions.Enums.LibraryType.SLM,
                        DirectoryInfo = new DirectoryInfo(LibraryPath),
                        Steam         = (Directory.Exists(LibraryPath)) ? new Definitions.SteamLibrary(LibraryPath) : null,
                    };

                    Definitions.List.Libraries.Add(Library);

                    if (Library.Steam != null)
                    {
                        await Task.Run(() => Library.Steam.UpdateAppList());

                        await Task.Run(() => Library.Steam.UpdateJunks());
                    }
                }
                catch (Exception ex)
                {
                    logger.Fatal(ex);
                    MessageBox.Show(ex.ToString());
                }
            }
コード例 #3
0
        public static void UpdateMainForm(Definitions.Library Library, string Search = null)
        {
            try
            {
                Func <Definitions.Game, object> Sort = SLM.Settings.getSortingMethod();

                if (MainWindow.Accessor.gamePanel.Dispatcher.CheckAccess())
                {
                    MainWindow.Accessor.gamePanel.ItemsSource = ((string.IsNullOrEmpty(Search)) ? Library.Games.OrderBy(Sort) : Library.Games.Where(
                                                                     y => y.appName.ToLowerInvariant().Contains(Search.ToLowerInvariant()) || // Search by appName
                                                                     y.appID.ToString().Contains(Search) // Search by app ID
                                                                     ).OrderBy(Sort)
                                                                 );
                }
                else
                {
                    MainWindow.Accessor.gamePanel.Dispatcher.Invoke(delegate
                    {
                        UpdateMainForm(Library, Search);
                    }, System.Windows.Threading.DispatcherPriority.Normal);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #4
0
            public static Func <dynamic, object> GetSortingMethod(Definitions.Library Library)
            {
                System.Diagnostics.Debug.WriteLine(Properties.Settings.Default.defaultGameSortingMethod);
                switch (Properties.Settings.Default.defaultGameSortingMethod)
                {
                case "appName":
                default:
                    return(x => x.AppName);

                case "appID":
                    return(x => x.AppId);

                case "sizeOnDisk":
                    return(x => x.SizeOnDisk);

                case "backupType":
                    return(x => (Library.Type == Definitions.Enums.LibraryType.Origin) ? x.AppName : x.IsCompressed);

                case "LastUpdated":
                    return(x => x.LastUpdated);

                case "LastPlayed":

                    return(x => (Library.Type == Definitions.Enums.LibraryType.Origin) ? x.AppName : x.LastPlayed);
                }
            }
コード例 #5
0
        public MoveGameForm(Definitions.Game gameToMove, Definitions.Library libraryToMove)
        {
            InitializeComponent();

            Game          = gameToMove;
            targetLibrary = libraryToMove;

            textBox.ItemsSource = formLogs;
        }
コード例 #6
0
 public static void deleteOldLibrary(Definitions.Library Library)
 {
     try
     {
         if (Library.steamAppsPath.Exists)
         {
             Library.steamAppsPath.Delete(true);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
コード例 #7
0
            public static async void UpdateLibrary(Definitions.Library Library)
            {
                try
                {
                    Library.DirectoryInfo.Refresh();

                    await Task.Run(Library.UpdateAppListAsync).ConfigureAwait(true);

                    Library.UpdateDiskDetails();
                }
                catch (Exception ex)
                {
                    logger.Fatal(ex);
                }
            }
コード例 #8
0
            public static async void UpdateBackupLibrary(Definitions.Library Library)
            {
                try
                {
                    if (Library.Steam != null)
                    {
                        await Task.Run(() => Library.Steam.UpdateAppList());

                        await Task.Run(() => Library.Steam.UpdateJunks());
                    }
                }
                catch (Exception ex)
                {
                    logger.Fatal(ex);
                }
            }
コード例 #9
0
        public static async void addNewLibrary(string libraryPath, bool mainLibrary, bool backupLibrary)
        {
            try
            {
                Definitions.Library Library = new Definitions.Library();

                // Define if library is main library
                Library.Main = mainLibrary;

                // Define if library is a backup dir
                Library.Backup = backupLibrary;

                // Define full path of library
                Library.fullPath = libraryPath;

                // Define our library path to SteamApps
                Library.steamAppsPath = new DirectoryInfo(Path.Combine(libraryPath, "SteamApps"));

                // Define common folder path for future use
                Library.commonPath = new DirectoryInfo(Path.Combine(Library.steamAppsPath.FullName, "common"));

                // Define download folder path
                Library.downloadPath = new DirectoryInfo(Path.Combine(Library.steamAppsPath.FullName, "downloading"));

                // Define workshop folder path
                Library.workshopPath = new DirectoryInfo(Path.Combine(Library.steamAppsPath.FullName, "workshop"));

                Library.freeSpace       = fileSystem.getAvailableFreeSpace(Library.fullPath);
                Library.prettyFreeSpace = fileSystem.FormatBytes(Library.freeSpace);
                Library.freeSpacePerc   = 100 - ((int)Math.Round((double)(100 * Library.freeSpace) / fileSystem.getUsedSpace(Library.fullPath)));

                Library.contextMenu = Library.generateRightClickMenuItems();

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

                await Task.Run(() => Library.UpdateGameList());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #10
0
            public static async void AddNew(string LibraryPath, bool IsMainLibrary = false)
            {
                try
                {
                    var newLibrary = new Definitions.Library
                    {
                        Type          = Definitions.Enums.LibraryType.Steam,
                        DirectoryInfo = new DirectoryInfo(LibraryPath)
                    };

                    newLibrary.Steam = new Definitions.SteamLibrary(LibraryPath, newLibrary, IsMainLibrary);

                    Definitions.List.Libraries.Add(newLibrary);

                    await Task.Run(() => newLibrary.Steam.UpdateAppList());

                    await Task.Run(() => newLibrary.Steam.UpdateJunks());
                }
                catch (Exception ex)
                {
                    logger.Fatal(ex);
                }
            }
コード例 #11
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);
            }
        }
コード例 #12
0
        private async void LibraryGrid_Drop(object sender, DragEventArgs e)
        {
            try
            {
                Definitions.Library Library = ((Grid)sender).DataContext as Definitions.Library;

                if (Main.FormAccessor.AppView.AppPanel.SelectedItems.Count == 0 || Library == null)
                {
                    return;
                }

                Library.DirectoryInfo.Refresh();
                if (!Library.DirectoryInfo.Exists)
                {
                    return;
                }

                foreach (dynamic App in Main.FormAccessor.AppView.AppPanel.SelectedItems.Cast <dynamic>().ToList())
                {
                    if (App is Definitions.SteamAppInfo)
                    {
                        if (App.IsSteamBackup)
                        {
                            Process.Start(Path.Combine(Properties.Settings.Default.steamInstallationPath, "Steam.exe"), $"-install \"{App.InstallationDirectory}\"");
                        }
                        else
                        {
                            if (Library == App.Library || Library.Type == Definitions.Enums.LibraryType.Origin)
                            {
                                continue;
                            }

                            if (Functions.TaskManager.TaskList.ToList().Count(x => x.SteamApp == App && x.TargetLibrary == Library) == 0)
                            {
                                Functions.TaskManager.AddTask(new Definitions.List.TaskInfo
                                {
                                    SteamApp      = App,
                                    TargetLibrary = Library,
                                    TaskType      = Definitions.Enums.TaskType.Copy
                                });
                            }
                            else
                            {
                                await Main.FormAccessor.ShowMessageAsync(Functions.SLM.Translate(nameof(Properties.Resources.TaskManager_AlreadyTasked)), Framework.StringFormat.Format(Functions.SLM.Translate(nameof(Properties.Resources.TaskManager_AlreadyTaskedMessage)), new { App.AppName, LibraryFullPath = Library.DirectoryInfo.FullName }));
                            }
                        }
                    }
                    else if (App is Definitions.OriginAppInfo)
                    {
                        if (Library == App.Library || Library.Type != Definitions.Enums.LibraryType.Origin)
                        {
                            continue;
                        }

                        if (Functions.TaskManager.TaskList.ToList().Count(x => x.OriginApp == App && x.TargetLibrary == Library) == 0)
                        {
                            Functions.TaskManager.AddTask(new Definitions.List.TaskInfo
                            {
                                OriginApp     = App,
                                TargetLibrary = Library,
                                TaskType      = Definitions.Enums.TaskType.Copy
                            });
                        }
                        else
                        {
                            await Main.FormAccessor.ShowMessageAsync(Functions.SLM.Translate(nameof(Properties.Resources.TaskManager_AlreadyTasked)), Framework.StringFormat.Format(Functions.SLM.Translate(nameof(Properties.Resources.TaskManager_AlreadyTaskedMessage)), new { App.AppName, LibraryFullPath = Library.DirectoryInfo.FullName }));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
            }
        }
コード例 #13
0
        public static void UpdateAppPanel(Definitions.Library Library)
        {
            try
            {
                if (Library == null)
                {
                    return;
                }

                string Search = (Properties.Settings.Default.includeSearchResults) ? Properties.Settings.Default.SearchText : null;

                if (Main.FormAccessor.AppView.AppPanel.Dispatcher.CheckAccess())
                {
                    if (Definitions.List.Libraries.Count(x => x == Library) == 0 || !Library.DirectoryInfo.Exists)
                    {
                        Main.FormAccessor.AppView.AppPanel.ItemsSource = null;
                        return;
                    }

                    Func <dynamic, object> Sort = SLM.Settings.GetSortingMethod();

                    switch (Library.Type)
                    {
                    case Definitions.Enums.LibraryType.Steam:
                    case Definitions.Enums.LibraryType.SLM:
                        Main.FormAccessor.AppView.AppPanel.ItemsSource = (Properties.Settings.Default.defaultGameSortingMethod == "sizeOnDisk" || Properties.Settings.Default.defaultGameSortingMethod == "LastUpdated") ?
                                                                         ((string.IsNullOrEmpty(Search)) ?
                                                                          Library.Steam.Apps.OrderByDescending(Sort).ToList() : Library.Steam.Apps.Where(
                                                                              y => y.AppName.IndexOf(Search, StringComparison.InvariantCultureIgnoreCase) >= 0 || y.AppID.ToString().Contains(Search) // Search by app ID
                                                                              ).OrderByDescending(Sort).ToList()
                                                                         ) :
                                                                         ((string.IsNullOrEmpty(Search)) ? Library.Steam.Apps.OrderBy(Sort).ToList() : Library.Steam.Apps.Where(
                                                                              y => y.AppName.IndexOf(Search, StringComparison.InvariantCultureIgnoreCase) >= 0 || y.AppID.ToString().Contains(Search) // Search by app ID
                                                                              ).OrderBy(Sort).ToList()
                                                                         );
                        break;

                    case Definitions.Enums.LibraryType.Origin:
                        Main.FormAccessor.AppView.AppPanel.ItemsSource = (Properties.Settings.Default.defaultGameSortingMethod == "sizeOnDisk" || Properties.Settings.Default.defaultGameSortingMethod == "LastUpdated") ?
                                                                         ((string.IsNullOrEmpty(Search)) ?
                                                                          Library.Origin.Apps.OrderByDescending(Sort).ToList() : Library.Origin.Apps.Where(
                                                                              y => y.AppName.IndexOf(Search, StringComparison.InvariantCultureIgnoreCase) >= 0 || y.AppID.ToString().Contains(Search) // Search by app ID
                                                                              ).OrderByDescending(Sort).ToList()
                                                                         ) :
                                                                         ((string.IsNullOrEmpty(Search)) ? Library.Origin.Apps.OrderBy(Sort).ToList() : Library.Origin.Apps.Where(
                                                                              y => y.AppName.IndexOf(Search, StringComparison.InvariantCultureIgnoreCase) >= 0 || y.AppID.ToString().Contains(Search) // Search by app ID
                                                                              ).OrderBy(Sort).ToList()
                                                                         );
                        break;
                    }
                }
                else
                {
                    Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke(delegate
                    {
                        UpdateAppPanel(Library);
                    }, System.Windows.Threading.DispatcherPriority.Normal);
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
                Definitions.SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex));
            }
        }
コード例 #14
0
        public static async System.Threading.Tasks.Task AddSteamAppAsync(int AppID, string AppName, string InstallationPath, int StateFlag, Definitions.Library Library, long SizeOnDisk, long LastUpdated, bool IsCompressed, bool IsSteamBackup = false)
        {
            try
            {
                // Make a new definition for app
                var appInfo = new Definitions.SteamAppInfo(AppID, Library, new DirectoryInfo(Path.Combine(Library.DirectoryList["Common"].FullName, InstallationPath)))
                {
                    // Set game name
                    AppName = AppName,

                    // Define it is an archive
                    IsCompressed  = IsCompressed,
                    IsSteamBackup = IsSteamBackup,
                    LastUpdated   = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(LastUpdated)
                };

                if (Definitions.List.SteamAppsLastPlayedDic.ContainsKey(AppID))
                {
                    appInfo.LastPlayed = Definitions.List.SteamAppsLastPlayedDic[AppID];
                }

                // If app doesn't have a folder in "common" directory and "downloading" directory then skip
                if (!appInfo.InstallationDirectory.Exists && StateFlag == 4 && !appInfo.IsCompressed && !appInfo.IsSteamBackup)
                {
                    var acfFile = new FileInfo(Path.Combine(Library.DirectoryList["SteamApps"].FullName, $"appmanifest_{appInfo.AppId}.acf"));

                    if (Definitions.List.IgnoredJunkItems.Contains(acfFile.FullName))
                    {
                        return;
                    }

                    Definitions.List.LcProgress.Report(new Definitions.List.JunkInfo
                    {
                        FSInfo  = acfFile,
                        Size    = FileSystem.FormatBytes(acfFile.Length),
                        Library = Library,
                        Tag     = JunkType.HeadlessDataFile
                    });

                    return; // Do not add pre-loads to list
                }

                if (IsCompressed)
                {
                    // If user want us to get archive size from real uncompressed size
                    if (Properties.Settings.Default.archiveSizeCalculationMethod.StartsWith("Uncompressed"))
                    {
                        // Open archive to read
                        using (var archive = ZipFile.OpenRead(appInfo.CompressedArchivePath.FullName))
                        {
                            // For each file in archive
                            foreach (var entry in archive.Entries)
                            {
                                // Add file size to sizeOnDisk
                                appInfo.SizeOnDisk += entry.Length;
                            }
                        }
                    }
                    else
                    {
                        appInfo.CompressedArchivePath.Refresh();

                        // And set archive size as game size
                        appInfo.SizeOnDisk = appInfo.CompressedArchivePath?.Length ?? 0;
                    }
                }
                else
                {
                    // If SizeOnDisk value from .ACF file is not equals to 0
                    if (Properties.Settings.Default.gameSizeCalculationMethod != "ACF")
                    {
                        var  gameFiles = appInfo.GetFileList();
                        long gameSize  = 0;

                        System.Threading.Tasks.Parallel.ForEach(gameFiles, file => Interlocked.Add(ref gameSize, file.Length));

                        appInfo.SizeOnDisk = gameSize;
                    }
                    else
                    {
                        // Else set game size to size in acf
                        appInfo.SizeOnDisk = SizeOnDisk;
                    }
                }

                appInfo.IsCompacted = await appInfo.CompactStatus().ConfigureAwait(false);

                // Add our game details to global list
                Library.Apps.Add(appInfo);

                if (Definitions.SLM.CurrentSelectedLibrary == Library)
                {
                    UpdateAppPanel(Library);
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex);
            }
        }
コード例 #15
0
        private async void LibraryGrid_Drop(object sender, DragEventArgs e)
        {
            try
            {
                Definitions.Library Library = ((Grid)sender).DataContext as Definitions.Library;

                if (Main.FormAccessor.AppView.AppPanel.SelectedItems.Count == 0 || Library == null)
                {
                    return;
                }

                Library.DirectoryInfo.Refresh();
                if (!Library.DirectoryInfo.Exists)
                {
                    return;
                }

                foreach (dynamic App in Main.FormAccessor.AppView.AppPanel.SelectedItems)
                {
                    if (App is Definitions.SteamAppInfo)
                    {
                        if (App.IsSteamBackup)
                        {
                            Process.Start(Path.Combine(Properties.Settings.Default.steamInstallationPath, "Steam.exe"), $"-install \"{App.InstallationDirectory}\"");
                        }
                        else
                        {
                            if (Library == App.Library || Library.Type == Definitions.Enums.LibraryType.Origin)
                            {
                                continue;
                            }

                            if (Framework.TaskManager.TaskList.ToList().Count(x => x.SteamApp == App && x.TargetLibrary == Library) == 0)
                            {
                                Framework.TaskManager.AddTask(new Definitions.List.TaskInfo
                                {
                                    SteamApp      = App,
                                    TargetLibrary = Library,
                                    TaskType      = Definitions.Enums.TaskType.Copy
                                });
                            }
                            else
                            {
                                await Main.FormAccessor.ShowMessageAsync("Steam Library Manager", $"This item is already tasked.\n\nGame: {App.AppName}\nTarget Library: {Library.DirectoryInfo.FullName}");
                            }
                        }
                    }
                    else if (App is Definitions.OriginAppInfo)
                    {
                        if (Library == App.Library || Library.Type != Definitions.Enums.LibraryType.Origin)
                        {
                            continue;
                        }

                        if (Framework.TaskManager.TaskList.ToList().Count(x => x.OriginApp == App && x.TargetLibrary == Library) == 0)
                        {
                            Framework.TaskManager.AddTask(new Definitions.List.TaskInfo
                            {
                                OriginApp     = App,
                                TargetLibrary = Library,
                                TaskType      = Definitions.Enums.TaskType.Copy
                            });
                        }
                        else
                        {
                            await Main.FormAccessor.ShowMessageAsync("Steam Library Manager", $"This item is already tasked.\n\nGame: {App.AppName}\nTarget Library: {Library.DirectoryInfo.FullName}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
                Definitions.SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex));
            }
        }
コード例 #16
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);
            }
        }
コード例 #17
0
        public static void AddNewGame(string acfPath, int appID, string appName, string installationPath, Definitions.Library Library, long sizeOnDisk, bool isCompressed, bool isSteamBackup = false)
        {
            try
            {
                // Make a new definition for game
                Definitions.Game Game = new Definitions.Game();

                // Set game appID
                Game.appID = appID;

                // Set game name
                Game.appName = appName;

                Game.gameHeaderImage = $"http://cdn.akamai.steamstatic.com/steam/apps/{appID}/header.jpg";

                // Set acf name, appmanifest_107410.acf as example
                Game.acfName = $"appmanifest_{appID}.acf";

                // Set game acf path
                Game.fullAcfPath = new FileInfo(acfPath);

                // Set workshop acf name
                Game.workShopAcfName = $"appworkshop_{appID}.acf";

                Game.workShopAcfPath = new FileInfo(Path.Combine(Library.workshopPath.FullName, Game.workShopAcfName));

                // Set installation path
                DirectoryInfo testOldInstallations = new DirectoryInfo(installationPath);

                Game.installationPath = (testOldInstallations.Exists && !isCompressed && !isSteamBackup) ? testOldInstallations : new DirectoryInfo(installationPath);

                Game.installedLibrary = Library;

                // Define it is an archive
                Game.IsCompressed = isCompressed;

                Game.IsSteamBackup = isSteamBackup;

                Game.compressedName = new FileInfo(Path.Combine(Game.installedLibrary.steamAppsPath.FullName, Game.appID + ".zip"));

                Game.commonPath   = new DirectoryInfo(Path.Combine(Library.commonPath.FullName, installationPath));
                Game.downloadPath = new DirectoryInfo(Path.Combine(Library.downloadPath.FullName, installationPath));
                Game.workShopPath = new DirectoryInfo(Path.Combine(Library.workshopPath.FullName, "content", appID.ToString()));

                // If game do not have a folder in "common" directory and "downloading" directory then skip this game
                if (!Game.commonPath.Exists && !Game.downloadPath.Exists && !Game.IsCompressed)
                {
                    return; // Do not add pre-loads to list
                }
                // If SizeOnDisk value from .ACF file is not equals to 0
                if (Properties.Settings.Default.gameSizeCalculationMethod != "ACF" && !isCompressed)
                {
                    List <FileSystemInfo> gameFiles = Game.getFileList();

                    Parallel.ForEach(gameFiles, file =>
                    {
                        Game.sizeOnDisk += (file as FileInfo).Length;
                    });
                }
                else if (isCompressed)
                {
                    // 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(Game.compressedName.FullName))
                        {
                            // For each file in archive
                            foreach (ZipArchiveEntry entry in zip.Entries)
                            {
                                // Add file size to sizeOnDisk
                                Game.sizeOnDisk += entry.Length;
                            }
                        }
                    }
                    else
                    {
                        // And set archive size as game size
                        Game.sizeOnDisk = fileSystem.getFileSize(Path.Combine(Game.installedLibrary.steamAppsPath.FullName, Game.appID + ".zip"));
                    }
                }
                else
                {
                    // Else set game size to size in acf
                    Game.sizeOnDisk = sizeOnDisk;
                }

                Game.prettyGameSize = fileSystem.FormatBytes(Game.sizeOnDisk);

                Application.Current.Dispatcher.Invoke(delegate
                {
                    Game.contextMenuItems = Game.generateRightClickMenuItems();
                }, System.Windows.Threading.DispatcherPriority.Normal);

                // Add our game details to global list
                Library.Games.Add(Game);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #18
0
ファイル: App.cs プロジェクト: viko1002/Steam-Library-Manager
 public static void UpdateAppPanel(Definitions.Library Library) => Main.FormAccessor.LibraryChange.Report(Library);
コード例 #19
0
ファイル: App.cs プロジェクト: viko1002/Steam-Library-Manager
        public static void AddSteamApp(int AppID, string AppName, string InstallationPath, Definitions.Library Library, long SizeOnDisk, long LastUpdated, bool IsCompressed, bool IsSteamBackup = false)
        {
            try
            {
                // Make a new definition for app
                var App = new Definitions.SteamAppInfo(AppID, Library, new DirectoryInfo(InstallationPath))
                {
                    // Set game name
                    AppName = AppName,

                    // Define it is an archive
                    IsCompressed  = IsCompressed,
                    IsSteamBackup = IsSteamBackup,
                    LastUpdated   = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(LastUpdated)
                };

                if (Definitions.List.SteamApps_LastPlayedDic.ContainsKey(AppID))
                {
                    App.LastPlayed = Definitions.List.SteamApps_LastPlayedDic[AppID];
                }

                // If app doesn't have a folder in "common" directory and "downloading" directory then skip
                if (!App.CommonFolder.Exists && !App.DownloadFolder.Exists && !App.IsCompressed && !App.IsSteamBackup)
                {
                    Definitions.List.LCProgress.Report(new Definitions.List.JunkInfo
                    {
                        FSInfo  = new FileInfo(App.FullAcfPath.FullName),
                        Size    = App.FullAcfPath.Length,
                        Library = Library
                    });

                    return; // Do not add pre-loads to list
                }

                if (IsCompressed)
                {
                    // 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 Archive = ZipFile.OpenRead(App.CompressedArchiveName.FullName))
                        {
                            // For each file in archive
                            foreach (ZipArchiveEntry Entry in Archive.Entries)
                            {
                                // Add file size to sizeOnDisk
                                App.SizeOnDisk += Entry.Length;
                            }
                        }
                    }
                    else
                    {
                        App.CompressedArchiveName.Refresh();

                        // And set archive size as game size
                        App.SizeOnDisk = App.CompressedArchiveName?.Length ?? 0;
                    }
                }
                else
                {
                    // If SizeOnDisk value from .ACF file is not equals to 0
                    if (Properties.Settings.Default.gameSizeCalculationMethod != "ACF")
                    {
                        List <FileInfo> GameFiles = App.GetFileList();
                        long            GameSize  = 0;

                        System.Threading.Tasks.Parallel.ForEach(GameFiles, File => Interlocked.Add(ref GameSize, File.Length));

                        App.SizeOnDisk = GameSize;
                    }
                    else
                    {
                        // Else set game size to size in acf
                        App.SizeOnDisk = SizeOnDisk;
                    }
                }

                // Add our game details to global list
                Library.Steam.Apps.Add(App);

                if (Definitions.SLM.CurrentSelectedLibrary == Library)
                {
                    UpdateAppPanel(Library);
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
            }
        }
コード例 #20
0
ファイル: App.cs プロジェクト: viko1002/Steam-Library-Manager
        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);
            }
        }