public bool Equals(ProjectRestoreMetadata other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(ProjectStyle == other.ProjectStyle &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(ProjectPath, other.ProjectPath) &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(ProjectJsonPath, other.ProjectJsonPath) &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(OutputPath, other.OutputPath) &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(ProjectName, other.ProjectName) &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(ProjectUniqueName, other.ProjectUniqueName) &&
                   Sources.OrderedEquals(other.Sources.Distinct(), source => source.Source, StringComparer.OrdinalIgnoreCase) &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(PackagesPath, other.PackagesPath) &&
                   ConfigFilePaths.OrderedEquals(other.ConfigFilePaths, filePath => filePath, PathUtility.GetStringComparerBasedOnOS(), PathUtility.GetStringComparerBasedOnOS()) &&
                   FallbackFolders.OrderedEquals(other.FallbackFolders, fallbackFolder => fallbackFolder, PathUtility.GetStringComparerBasedOnOS(), PathUtility.GetStringComparerBasedOnOS()) &&
                   EqualityUtility.SequenceEqualWithNullCheck(TargetFrameworks, other.TargetFrameworks) &&
                   OriginalTargetFrameworks.OrderedEquals(other.OriginalTargetFrameworks, fw => fw, StringComparer.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase) &&
                   CrossTargeting == other.CrossTargeting &&
                   LegacyPackagesDirectory == other.LegacyPackagesDirectory &&
                   ValidateRuntimeAssets == other.ValidateRuntimeAssets &&
                   SkipContentFileWrite == other.SkipContentFileWrite &&
                   EqualityUtility.SequenceEqualWithNullCheck(Files, other.Files) &&
                   EqualityUtility.EqualsWithNullCheck(ProjectWideWarningProperties, other.ProjectWideWarningProperties));
        }
Esempio n. 2
0
        public override int GetHashCode()
        {
            var hashCode = new HashCodeCombiner();

            hashCode.AddStruct(ProjectStyle);

            StringComparer osStringComparer = PathUtility.GetStringComparerBasedOnOS();

            if (ProjectPath != null)
            {
                hashCode.AddObject(osStringComparer.GetHashCode(ProjectPath));
            }
            if (ProjectJsonPath != null)
            {
                hashCode.AddObject(osStringComparer.GetHashCode(ProjectJsonPath));
            }
            if (OutputPath != null)
            {
                hashCode.AddObject(osStringComparer.GetHashCode(OutputPath));
            }
            if (ProjectName != null)
            {
                hashCode.AddObject(osStringComparer.GetHashCode(ProjectName));
            }
            if (ProjectUniqueName != null)
            {
                hashCode.AddObject(osStringComparer.GetHashCode(ProjectUniqueName));
            }
            hashCode.AddSequence(Sources.OrderBy(e => e.Source, StringComparer.OrdinalIgnoreCase));
            if (PackagesPath != null)
            {
                hashCode.AddObject(osStringComparer.GetHashCode(PackagesPath));
            }
            foreach (var reference in ConfigFilePaths.OrderBy(s => s, osStringComparer))
            {
                hashCode.AddObject(osStringComparer.GetHashCode(reference));
            }
            foreach (var reference in FallbackFolders.OrderBy(s => s, osStringComparer))
            {
                hashCode.AddObject(osStringComparer.GetHashCode(reference));
            }
            hashCode.AddSequence(TargetFrameworks.OrderBy(dep => dep.TargetAlias, StringComparer.OrdinalIgnoreCase));
            foreach (var reference in OriginalTargetFrameworks.OrderBy(s => s, StringComparer.OrdinalIgnoreCase))
            {
                hashCode.AddObject(StringComparer.OrdinalIgnoreCase.GetHashCode(reference));
            }
            hashCode.AddObject(CrossTargeting);
            hashCode.AddObject(LegacyPackagesDirectory);
            hashCode.AddSequence(Files);
            hashCode.AddObject(ValidateRuntimeAssets);
            hashCode.AddObject(SkipContentFileWrite);
            hashCode.AddObject(ProjectWideWarningProperties);
            hashCode.AddObject(RestoreLockProperties);
            hashCode.AddObject(CentralPackageVersionsEnabled);
            hashCode.AddObject(CentralPackageVersionOverrideDisabled);
            hashCode.AddObject(CentralPackageTransitivePinningEnabled);

            return(hashCode.CombinedHash);
        }
        /// <summary>
        /// The method that is called to start the backgound task.
        /// </summary>
        /// <param name="args">Arguments to for the task execution.</param>
        /// <returns>Always <c>null</c>.</returns>
        protected override object DoWork(object[] args)
        {
            string strOverallRoot = "Fixing config file";

            OverallMessage          = "Parsing config file...";
            OverallProgress         = 0;
            OverallProgressStepSize = 1;
            ShowItemProgress        = false;
            int i = 0;

            ConfirmActionMethod camConfirm = (ConfirmActionMethod)args[0];

            foreach (string FilePath in ConfigFilePaths)
            {
                List <string>          lstAddedModInfo = new List <string>();
                List <IVirtualModLink> lstVirtualLinks = new List <IVirtualModLink>();
                List <IVirtualModInfo> lstVirtualMods  = new List <IVirtualModInfo>();

                if (File.Exists(FilePath))
                {
                    XDocument docVirtual;
                    using (var sr = new StreamReader(FilePath))
                    {
                        docVirtual = XDocument.Load(sr);
                    }

                    strOverallRoot = string.Format("Fixing config file {0}/{1}", ++i, ConfigFilePaths.Count());

                    try
                    {
                        XElement xelModList = docVirtual.Descendants("modList").FirstOrDefault();
                        if ((xelModList != null) && xelModList.HasElements)
                        {
                            OverallProgressMaximum = xelModList.Elements("modId").Count();

                            foreach (XElement xelMod in xelModList.Elements("modInfo"))
                            {
                                string strModId             = xelMod.Attribute("modId").Value;
                                string strDownloadId        = string.Empty;
                                string strUpdatedDownloadId = string.Empty;
                                string strNewFileName       = string.Empty;
                                string strFileVersion       = string.Empty;

                                if (OverallProgress < OverallProgressMaximum)
                                {
                                    StepOverallProgress();
                                }
                                OverallMessage = string.Format("{0} - element: {1}/{2}", strOverallRoot, OverallProgress, OverallProgressMaximum);

                                try
                                {
                                    strDownloadId = xelMod.Attribute("downloadId").Value;
                                }
                                catch { }

                                try
                                {
                                    strUpdatedDownloadId = xelMod.Attribute("updatedDownloadId").Value;
                                }
                                catch { }

                                string strModName     = xelMod.Attribute("modName").Value;
                                string strModFileName = xelMod.Attribute("modFileName").Value;

                                if (lstAddedModInfo.Contains(strModFileName, StringComparer.InvariantCultureIgnoreCase))
                                {
                                    continue;
                                }

                                try
                                {
                                    strNewFileName = xelMod.Attribute("modNewFileName").Value;
                                }
                                catch { }

                                string strModFilePath = xelMod.Attribute("modFilePath").Value;

                                try
                                {
                                    strFileVersion = xelMod.Attribute("FileVersion").Value;
                                }
                                catch
                                {
                                    IMod mod = ModManager.GetModByFilename(strModFileName);
                                    strFileVersion = mod.HumanReadableVersion;
                                }

                                VirtualModInfo vmiMod = new VirtualModInfo(strModId, strDownloadId, strUpdatedDownloadId, strModName, strModFileName, strNewFileName, strModFilePath, strFileVersion);

                                bool booNoFileLink = true;

                                foreach (XElement xelLink in xelMod.Elements("fileLink"))
                                {
                                    string strRealPath    = xelLink.Attribute("realPath").Value;
                                    string strVirtualPath = xelLink.Attribute("virtualPath").Value;
                                    Int32  intPriority    = 0;
                                    try
                                    {
                                        intPriority = Convert.ToInt32(xelLink.Element("linkPriority").Value);
                                    }
                                    catch { }
                                    bool booActive = false;
                                    try
                                    {
                                        booActive = Convert.ToBoolean(xelLink.Element("isActive").Value);
                                    }
                                    catch { }

                                    if (booNoFileLink)
                                    {
                                        booNoFileLink = false;
                                        lstVirtualMods.Add(vmiMod);
                                        lstAddedModInfo.Add(strModFileName);
                                    }

                                    lstVirtualLinks.Add(new VirtualModLink(strRealPath, strVirtualPath, intPriority, booActive, vmiMod));
                                }
                            }
                        }
                    }
                    catch { }
                }

                if ((lstVirtualLinks.Count > 0) && (lstVirtualMods.Count > 0))
                {
                    OverallMessage = "Saving fixed config file...";
                    VirtualModActivator.SaveModList(FilePath, lstVirtualMods, lstVirtualLinks);
                }
            }

            return(ModProfile);
        }