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);
            }
        }
Exemple #2
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);
            }
        }