public int GetHashCode(IVirtualModInfo a)
        {
            VirtualModInfo vmi = new VirtualModInfo(a);

            vmi.UpdatedDownloadId = string.Empty;
            vmi.ModName           = string.Empty;
            return(vmi.GetHashCode());
        }
 public bool Equals(VirtualModInfo other)
 {
     if (other == null)
     {
         return(false);
     }
     return(this.ModFileName.Equals(other.ModFileName, StringComparison.InvariantCultureIgnoreCase));
 }
        /// <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);
        }