Esempio n. 1
0
        private static PatchList LoadPatches(IEnumerable <string> patchFolders)
        {
            PatchList patches = new PatchList();

            foreach (string patchFolder in patchFolders)
            {
                patches.Merge(PatchList.Load(patchFolder));
            }
            return(patches);
        }
Esempio n. 2
0
        public PatchList SelectPatches(string patchesRoot, ref string selectedVersion, string patchSet)
        {
            if (!Directory.Exists(patchesRoot))
            {
                return(new PatchList());
            }

            string candidateVersion      = "";
            string candidatePatchSetPath = "";

            foreach (string versionPath in Directory.EnumerateDirectories(patchesRoot, "???_???_?????_*",
                                                                          SearchOption.TopDirectoryOnly))
            {
                string directoryVersion = Path.GetFileName(versionPath);
                // ReSharper disable once AssignNullToNotNullAttribute versionPath is returned from directory enumeration and can't be null
                string patchSetPath = Path.Combine(versionPath, patchSet);
                if (!Directory.Exists(patchSetPath))
                {
                    // patch set not included in this update
                    continue;
                }

                if (string.Compare(directoryVersion, Version, StringComparison.InvariantCulture) > 0)
                {
                    // patches are only for later version of DCS
                    continue;
                }

                if (string.Compare(directoryVersion, candidateVersion, StringComparison.InvariantCulture) <= 0)
                {
                    // we already have a better match
                    continue;
                }

                if (selectedVersion != null && string.Compare(directoryVersion, selectedVersion, StringComparison.InvariantCulture) <= 0)
                {
                    // we found a better match in another location
                    continue;
                }

                candidateVersion      = directoryVersion;
                candidatePatchSetPath = patchSetPath;
            }

            if (candidatePatchSetPath == "")
            {
                if (selectedVersion != null)
                {
                    ConfigManager.LogManager.LogInfo(
                        $"no additional {patchSet} patches for DCS {DisplayVersion} from {Anonymizer.Anonymize(patchesRoot)} based on selected patch version {selectedVersion}");
                }
                else
                {
                    ConfigManager.LogManager.LogInfo(
                        $"current version of DCS {DisplayVersion} is not supported by any installed {patchSet} patch set from {Anonymizer.Anonymize(patchesRoot)}");
                }

                return(new PatchList());
            }

            ConfigManager.LogManager.LogInfo(
                $"loading {patchSet} patches for DCS {DisplayVersion} from {Anonymizer.Anonymize(patchesRoot)} using version {candidateVersion} of the patches");

            selectedVersion = candidateVersion;
            return(PatchList.Load(candidatePatchSetPath));
        }