Beispiel #1
0
        public void UpdateModLoadOrder(IMod p_modMod, int p_intNewPosition)
        {
            ModInfo mifNewInfo = new ModInfo(p_modMod);

            mifNewInfo.NewPlaceInModLoadOrder = p_intNewPosition;
            p_modMod.UpdateInfo(mifNewInfo, true);
        }
Beispiel #2
0
        /// <summary>
        /// Updates the mod's name.
        /// </summary>
        /// <param name="p_modMod">The mod whose name is to be updated.</param>
        /// <param name="p_strNewModName">The name to which to update the mod's name.</param>
        public void UpdateModName(IMod p_modMod, string p_strNewModName)
        {
            ModInfo mifNewInfo = new ModInfo(p_modMod);

            mifNewInfo.ModName = p_strNewModName;
            p_modMod.UpdateInfo(mifNewInfo, true);
        }
Beispiel #3
0
        /// <summary>
        /// Registers the specified mod, tagging it with the given info.
        /// </summary>
        /// <param name="p_strModPath">The path to the mod to register.</param>
        /// <param name="p_mifTagInfo">The info with which to tag the mod.</param>
        /// <returns>The mod that was registered, or <c>null</c> if the mod at the given path
        /// could not be registered.</returns>
        public IMod RegisterMod(string p_strModPath, IModInfo p_mifTagInfo, IEnvironmentInfo p_eiEnvironmentInfo)
        {
            Int32 intExistingIndex = -1;
            IMod  modMod           = null;

            for (intExistingIndex = 0; intExistingIndex < m_oclRegisteredMods.Count; intExistingIndex++)
            {
                if (p_strModPath.Equals(m_oclRegisteredMods[intExistingIndex].Filename, StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
            }
            modMod = CreateMod(p_strModPath, string.Empty, GameMode, p_eiEnvironmentInfo);
            if (p_mifTagInfo != null)
            {
                modMod.UpdateInfo(p_mifTagInfo, false);
            }
            if (modMod == null)
            {
                return(null);
            }
            if (intExistingIndex < m_oclRegisteredMods.Count)
            {
                m_oclRegisteredMods[intExistingIndex] = modMod;
            }
            else
            {
                m_oclRegisteredMods.Add(modMod);
            }
            return(modMod);
        }
Beispiel #4
0
        /// <summary>
        /// Switches the mod category.
        /// </summary>
        /// <param name="p_modMod">The mod.</param>
        /// <param name="p_intCategoryId">The new category id.</param>
        public void SwitchModCategory(IMod p_modMod, Int32 p_intCategoryId)
        {
            ModInfo mifUpdatedMod = new ModInfo(p_modMod);

            mifUpdatedMod.CustomCategoryId     = p_intCategoryId;
            mifUpdatedMod.UpdateWarningEnabled = p_modMod.UpdateWarningEnabled;
            p_modMod.UpdateInfo((IModInfo)mifUpdatedMod, false);
        }
Beispiel #5
0
        /// <summary>
        /// Toggles the endorsement for the given mod.
        /// </summary>
        /// <param name="p_modMod">The mod to endorse/unendorse.</param>
        public void ToggleModEndorsement(IMod p_modMod)
        {
            bool?   booEndorsementState = ModRepository.ToggleEndorsement(p_modMod.Id, p_modMod.IsEndorsed == true ? 1 : (p_modMod.IsEndorsed == false ? -1 : 0));
            ModInfo mifUpdatedMod       = new ModInfo(p_modMod);

            mifUpdatedMod.IsEndorsed           = booEndorsementState;
            mifUpdatedMod.HumanReadableVersion = String.IsNullOrEmpty(mifUpdatedMod.LastKnownVersion) ? mifUpdatedMod.HumanReadableVersion : mifUpdatedMod.LastKnownVersion;
            AddNewVersionNumberForMod(p_modMod, (IModInfo)mifUpdatedMod);
            p_modMod.UpdateInfo((IModInfo)mifUpdatedMod, false);
        }
		/// <summary>
		/// Registers the specified mod, tagging it with the given info.
		/// </summary>
		/// <param name="p_strModPath">The path to the mod to register.</param>
		/// <param name="p_mifTagInfo">The info with which to tag the mod.</param>
		/// <returns>The mod that was registered, or <c>null</c> if the mod at the given path
		/// could not be registered.</returns>
		public IMod RegisterMod(string p_strModPath, IModInfo p_mifTagInfo)
		{
			Int32 intExistingIndex = -1;
			IMod modMod = null;
			for (intExistingIndex = 0; intExistingIndex < m_oclRegisteredMods.Count; intExistingIndex++)
				if (p_strModPath.Equals(m_oclRegisteredMods[intExistingIndex].Filename, StringComparison.OrdinalIgnoreCase))
					break;
			modMod = CreateMod(p_strModPath, string.Empty, GameMode);
			if (p_mifTagInfo != null)
				modMod.UpdateInfo(p_mifTagInfo, false);
			if (modMod == null)
				return null;
			if (intExistingIndex < m_oclRegisteredMods.Count)
				m_oclRegisteredMods[intExistingIndex] = modMod;
			else
				m_oclRegisteredMods.Add(modMod);
			return modMod;
		}
        /// <summary>
        /// Toggles the endorsement for the given mod.
        /// </summary>
        /// <param name="mod">The mod to endorse/unendorse.</param>
        public void ToggleModEndorsement(IMod mod)
        {
            var booEndorsementState = ModRepository.ToggleEndorsement(mod.Id, mod.IsEndorsed == true ? 1 : mod.IsEndorsed == false ? -1 : 0, mod.HumanReadableVersion);

            if (booEndorsementState == null)
            {
                MessageBox.Show($"Could not change endorsement status of \"{mod.ModName}\".", "Endorsement toggle error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var mifUpdatedMod = new ModInfo(mod)
            {
                IsEndorsed = booEndorsementState
            };

            mifUpdatedMod.HumanReadableVersion = string.IsNullOrEmpty(mifUpdatedMod.LastKnownVersion) ? mifUpdatedMod.HumanReadableVersion : mifUpdatedMod.LastKnownVersion;
            AddNewVersionNumberForMod(mod, mifUpdatedMod);
            mod.UpdateInfo(mifUpdatedMod, false);
        }
Beispiel #8
0
 /// <summary>
 /// Tags the mod with the given values.
 /// </summary>
 /// <param name="p_modMod">The mod the tag.</param>
 /// <param name="p_mifModInfo">The values with which to tag the mod.</param>
 /// <param name="p_booOverwriteAllValues">Whether to overwrite the current info values,
 /// or just the empty ones.</param>
 public void Tag(IMod p_modMod, IModInfo p_mifModInfo, bool p_booOverwriteAllValues)
 {
     p_modMod.UpdateInfo(p_mifModInfo, p_booOverwriteAllValues);
 }
        /// <summary>
        /// Checks for the updated information for the given mods.
        /// </summary>
        /// <param name="p_lstModList">The mods for which to check for updates.</param>
        private string CheckForModListUpdate(List <string> p_lstModList, List <IMod> p_lstModCheck)
        {
            if (m_booMissingDownloadId != false)
            {
                OverallMessage = "Updating mods info: retrieving download ids..";
            }
            else
            {
                OverallMessage = "Updating mods info: getting online updates..";
            }
            List <IModInfo> mifInfo = new List <IModInfo>();

            IMod[] ModCheckList = p_lstModCheck.ToArray();

            try
            {
                //get mod info
                for (int i = 0; i <= m_intRetries; i++)
                {
                    mifInfo = ModRepository.GetFileListInfo(p_lstModList);

                    if (mifInfo != null)
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                }

                if (mifInfo != null)
                {
                    IModInfo[] mifModUpdates = mifInfo.ToArray();
                    ItemProgress        = 0;
                    ItemProgressMaximum = mifInfo.Count;

                    for (int i = 0; i < mifModUpdates.Count(); i++)
                    {
                        ModInfo modUpdate = (ModInfo)mifModUpdates[i];
                        if (m_booCancel)
                        {
                            break;
                        }
                        if (OverallProgress < OverallProgressMaximum)
                        {
                            StepOverallProgress();
                        }

                        if (modUpdate == null)
                        {
                            continue;
                        }

                        ItemMessage = modUpdate.ModName;

                        IMod modMod = null;
                        if (m_booMissingDownloadId != false)
                        {
                            modMod = m_lstModList.Where(x => x != null).Where(x => !string.IsNullOrEmpty(modUpdate.FileName) && (StripFileName(modUpdate.FileName, modUpdate.Id).Equals(StripFileName(Path.GetFileName(x.Filename).ToString(), x.Id), StringComparison.OrdinalIgnoreCase) || StripFileName(modUpdate.FileName, modUpdate.Id).Equals(StripFileName(Path.GetFileName(x.Filename.Replace("_", " ")).ToString(), x.Id), StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
                        }
                        else
                        {
                            modMod = m_lstModList.Where(x => x != null).Where(x => !string.IsNullOrEmpty(modUpdate.FileName) && modUpdate.FileName.Equals(Path.GetFileName(x.Filename).ToString(), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                        }

                        if (modMod == null)
                        {
                            if ((!string.IsNullOrEmpty(modUpdate.DownloadId)) && (modUpdate.DownloadId != "0") && (modUpdate.DownloadId != "-1"))
                            {
                                modMod = m_lstModList.Where(x => x != null).Where(x => !string.IsNullOrEmpty(x.DownloadId) && modUpdate.DownloadId.Equals(x.DownloadId.ToString(), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                            }
                        }

                        if (modMod == null)
                        {
                            if (m_booMissingDownloadId != false)
                            {
                                if (ModCheckList.Count() == mifModUpdates.Count())
                                {
                                    IMod modCheck = ModCheckList[i];
                                    if ((!string.IsNullOrEmpty(modUpdate.Id) && modUpdate.Id != "0") && (!string.IsNullOrEmpty(modCheck.Id) && modCheck.Id != "0"))
                                    {
                                        if (modUpdate.Id.Equals(modCheck.Id, StringComparison.OrdinalIgnoreCase))
                                        {
                                            modMod = modCheck;
                                        }
                                    }
                                }
                            }
                        }

                        if (modMod != null)
                        {
                            if (ItemProgress < ItemProgressMaximum)
                            {
                                StepItemProgress();
                            }

                            if (modUpdate.DownloadId == "-1")
                            {
                                if (m_booMissingDownloadId != false)
                                {
                                    string Filename = Path.GetFileName(modMod.Filename);
                                    if (!string.Equals(StripFileName(Filename, modMod.Id), StripFileName(modUpdate.FileName, modUpdate.Id), StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        continue;
                                    }
                                }
                            }
                            else if (!string.IsNullOrWhiteSpace(modUpdate.DownloadId) && !modUpdate.DownloadId.Equals(modMod.DownloadId))
                            {
                                if (m_booMissingDownloadId != false)
                                {
                                    string Filename = Path.GetFileName(modMod.Filename);
                                    if (string.Equals(Filename, modUpdate.FileName, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        if (!dctNewDownloadID.ContainsKey(Filename))
                                        {
                                            dctNewDownloadID.Add(Filename, modUpdate.DownloadId);
                                        }
                                    }
                                    else if (!string.IsNullOrEmpty(modMod.Id) && (modMod.Id != "0") && !string.IsNullOrEmpty(modUpdate.Id) && (modUpdate.Id != "0"))
                                    {
                                        if (string.Equals(modMod.Id, modUpdate.Id, StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            if (!dctNewDownloadID.ContainsKey(Filename))
                                            {
                                                dctNewDownloadID.Add(Filename, modUpdate.DownloadId);
                                            }
                                        }
                                    }
                                }
                            }

                            if (!string.IsNullOrEmpty(modMod.DownloadId) && string.IsNullOrWhiteSpace(modUpdate.DownloadId))
                            {
                                modUpdate.DownloadId = modMod.DownloadId;
                            }

                            if (m_booMissingDownloadId != false)
                            {
                                modUpdate.HumanReadableVersion = !string.IsNullOrEmpty(modMod.HumanReadableVersion) ? modMod.HumanReadableVersion : modUpdate.HumanReadableVersion;
                                modUpdate.MachineVersion       = modMod.MachineVersion != null ? modMod.MachineVersion : modUpdate.MachineVersion;
                            }

                            if ((modMod.CustomCategoryId != 0) && (modMod.CustomCategoryId != -1))
                            {
                                modUpdate.CustomCategoryId = modMod.CustomCategoryId;
                            }

                            modUpdate.UpdateWarningEnabled = modMod.UpdateWarningEnabled;
                            AutoUpdater.AddNewVersionNumberForMod(modMod, modUpdate);

                            if (!OverrideLocalModNames)
                            {
                                modUpdate.ModName = modMod.ModName;
                            }

                            modMod.UpdateInfo(modUpdate, null);
                            ItemProgress = 0;
                        }
                    }
                }
            }
            catch (RepositoryUnavailableException e)
            {
                return("The check failed for a server-side issue:" + Environment.NewLine + Environment.NewLine + e.Message);
            }

            return(null);
        }
		/// <summary>
		/// Updates the mod's name.
		/// </summary>
		/// <param name="p_modMod">The mod whose name is to be updated.</param>
		/// <param name="p_strNewModName">The name to which to update the mod's name.</param>
		public void UpdateModName(IMod p_modMod, string p_strNewModName)
		{
			ModInfo mifNewInfo = new ModInfo(p_modMod);
			mifNewInfo.ModName = p_strNewModName;
			p_modMod.UpdateInfo(mifNewInfo, true);
		}
		/// <summary>
		/// Tags the mod with the given values.
		/// </summary>
		/// <param name="p_modMod">The mod the tag.</param>
		/// <param name="p_mifModInfo">The values with which to tag the mod.</param>
		/// <param name="p_booOverwriteAllValues">Whether to overwrite the current info values,
		/// or just the empty ones.</param>
		public void Tag(IMod p_modMod, IModInfo p_mifModInfo, bool p_booOverwriteAllValues)
		{
			p_modMod.UpdateInfo(p_mifModInfo, p_booOverwriteAllValues);
		}
Beispiel #12
0
		/// <summary>
		/// Switches the mod category.
		/// </summary>
		/// <param name="p_modMod">The mod.</param>
		/// <param name="p_intCategoryId">The new category id.</param>
		public void SwitchModCategory(IMod p_modMod, Int32 p_intCategoryId)
		{
			ModInfo mifUpdatedMod = new ModInfo(p_modMod);
			mifUpdatedMod.CustomCategoryId = p_intCategoryId;
			mifUpdatedMod.UpdateWarningEnabled = p_modMod.UpdateWarningEnabled;
			p_modMod.UpdateInfo((IModInfo)mifUpdatedMod, false);
		}
Beispiel #13
0
		/// <summary>
		/// Toggles the endorsement for the given mod.
		/// </summary>
		/// <param name="p_modMod">The mod to endorse/unendorse.</param>
		public void ToggleModEndorsement(IMod p_modMod)
		{
			bool? booEndorsementState = ModRepository.ToggleEndorsement(p_modMod.Id, p_modMod.IsEndorsed == true ? 1 : (p_modMod.IsEndorsed == false ? -1 : 0)); 
			ModInfo mifUpdatedMod = new ModInfo(p_modMod);
			mifUpdatedMod.IsEndorsed = booEndorsementState;
			mifUpdatedMod.HumanReadableVersion = String.IsNullOrEmpty(mifUpdatedMod.LastKnownVersion) ? mifUpdatedMod.HumanReadableVersion : mifUpdatedMod.LastKnownVersion;
			AddNewVersionNumberForMod(p_modMod, (IModInfo)mifUpdatedMod);
			p_modMod.UpdateInfo((IModInfo)mifUpdatedMod, false);
		}