Exemplo n.º 1
0
        private static bool InternalSwitchVersion(
            string currentVersion,
            string newVersion,
            Depot currentDLC,
            Depot newDLC,
            string bl3Path,
            string ddPath,
            string username,
            Action <int> setBarMax,
            Action <int> setBarValue,
            Action incrementBar
            )
        {
            /*
             * How switching versions works
             * ============================
             * Switching versions will upgrade/downgrade through every version between the current and the target.
             * This will be combined into one operation, no need to replace the same files multiple times.
             *
             * We use the fields from `VersionInfo` as follows.
             * Note that upgrading refers to upgrading *to* the relevant version, while downgrading refers to downgrading *from* it.
             *
             * FilesToAdd:
             *  When upgrading, all these files get added.
             *  When downgrading, all these files get deleted.
             * FilesToDelete:
             *  When upgrading, all these files get deleted.
             *  When downgrading, all these files get added again, from the version before this one.
             * FilesToReplace:
             *  Behaves like `FilesToAdd` when upgrading.
             *  Behaves like `FilesToDelete` when downgrading.
             *
             * Because we want to cache downloads, we store the manifest of the version we discovered a file alongside it.
             * Future calls will discover it at the same version, and can find it in the same place in our cache.
             * We make sure to validate files every download though incase some corrupted.
             *
             * While iterating, if a file is added then deleted (or vice versa) only the latest state is saved.
             * We also update manifests when this happens, as the file might have changed inbetween.
             *
             * DLCs and the base game work mostly the same, only difference is DLCs need to specify all their files as `FilesToAdd` on
             * their lowest version, so that we have a full list to delete when uninstalling.
             */

            currentDLC |= Depot.Base;
            newDLC      = (newDLC & GetSupportedDepots(newVersion)) | Depot.Base;

            int currentIdx = AllVersionInfo.FindIndex(x => x.ProductVersion == currentVersion);
            int newIdx     = AllVersionInfo.FindIndex(x => x.ProductVersion == newVersion);

            bool upgrading = currentIdx < newIdx;

            // Also store the depot/manifest to get each file from
            Dictionary <string, (Depot dep, VersionInfo info)> filesToAdd = new Dictionary <string, (Depot dep, VersionInfo info)>();
            HashSet <string> filesToDelete = new HashSet <string>();

            Action <Dictionary <Depot, HashSet <string> >, VersionInfo> addFiles = (dict, info) => {
                foreach (KeyValuePair <Depot, HashSet <string> > entry in dict)
                {
                    if (!newDLC.HasFlag(entry.Key))
                    {
                        continue; // We'll deal with uninstalled dlc files later
                    }
                    foreach (string file in entry.Value)
                    {
                        filesToAdd[file] = (entry.Key, info);
                        filesToDelete.Remove(file);
                    }
Exemplo n.º 2
0
 public static Depot GetSupportedDepots(string version)
 {
     return(AllVersionInfo.Find(x => x.ProductVersion == version).Manifests.Keys.Aggregate((a, b) => a | b));
 }
Exemplo n.º 3
0
 public static string GetVersionName(string version) => AllVersionInfo.Find(x => x.ProductVersion == version)?.Name;
Exemplo n.º 4
0
 public static bool IsValidVersion(string version) => AllVersionInfo.Any(x => x.ProductVersion == version);
Exemplo n.º 5
0
 public static IEnumerable <string> GetAllVersions() => AllVersionInfo.Select(x => x.ProductVersion);