public override void OnLoad(Harmony harmony)
 {
     try {
         var method = typeof(Mod).GetMethodSafe(nameof(Mod.SetCrashed), false);
         if (method != null)
         {
             harmony.Patch(method, prefix: new HarmonyMethod(typeof(
                                                                 ModUpdateDatePatches), nameof(OnModCrash)));
         }
         SafeMode = false;
         PUtil.InitLibrary();
         new PPatchManager(harmony).RegisterPatchClass(typeof(ModUpdateDatePatches));
         new POptions().RegisterOptions(this, typeof(ModUpdateInfo));
         new PLocalization().Register();
         ModUpdateInfo.LoadSettings();
         base.OnLoad(harmony);
         ThisMod = mod;
         // Shut off AVC
         PRegistry.PutData("PLib.VersionCheck.ModUpdaterActive", true);
         if (ModUpdateInfo.Settings?.AutoUpdate == true)
         {
             PRegistry.PutData("PLib.VersionCheck.PassiveSteamUpdate", true);
         }
     } catch (Exception e) {
         // AAAAAAAAH!
         PUtil.LogWarning("Mod Updater failed to load! Entering safe mode...");
         PUtil.LogExcWarn(e);
         SafeMode = true;
     }
 }
Exemple #2
0
        /// <summary>
        /// Loads the settings for this mod.
        /// </summary>
        internal static void LoadSettings()
        {
            var s = POptions.ReadSettings <ModUpdateInfo>();

            if (s == null || string.IsNullOrEmpty(s.VersionSavedOn))
            {
                s = new ModUpdateInfo();
            }
            s.VersionSavedOn = ModVersion.FILE_VERSION;
            Settings         = s;
        }
        /// <summary>
        /// Adds a tooltip to a Steam mod showing its update status.
        /// </summary>
        /// <param name="tooltip">The tooltip under construction.</param>
        /// <param name="modUpdate">The mod update executor which can update this mod.</param>
        /// <param name="localDate">The local last update date.</param>
        /// <param name="updButton">The button to be used for updating this mod.</param>
        /// <returns>The status of the Steam mod.</returns>
        private static ModStatus AddSteamUpdate(StringBuilder tooltip, ModToUpdate modUpdate,
                                                System.DateTime localDate, PButton updButton)
        {
            var steamDate = modUpdate.LastSteamUpdate;
            var updated   = ModStatus.Disabled;

            if (steamDate > System.DateTime.MinValue)
            {
                // Generate tooltip for mod's current date and last Steam update
                var ours       = ModUpdateInfo.FindModInConfig(modUpdate.SteamID.m_PublishedFileId);
                var ourDate    = System.DateTime.MinValue;
                var globalDate = modUpdate.LastSteamUpdate;
                // Do we have a better estimate?
                if (ours != null)
                {
                    ourDate = new System.DateTime(ours.LastUpdated, DateTimeKind.Utc);
                }
                // Allow some time for download delays etc
                if (localDate.AddMinutes(UPDATE_JITTER) >= globalDate)
                {
                    tooltip.Append(ModUpdateDateStrings.MOD_UPDATED);
                    updated = ModStatus.UpToDate;
                }
                else if (ourDate.AddMinutes(UPDATE_JITTER) >= globalDate)
                {
                    tooltip.Append(ModUpdateDateStrings.MOD_UPDATED_BYUS);
                    localDate = ourDate;
                    updated   = ModStatus.UpToDateLocal;
                }
                else
                {
                    tooltip.Append(ModUpdateDateStrings.MOD_OUTDATED);
                    updated = ModStatus.Outdated;
                }
                // AppendLine appends platform specific separator
                tooltip.Append("\n");
                tooltip.AppendFormat(ModUpdateDateStrings.LOCAL_UPDATE, localDate.
                                     ToLocalTime());
                tooltip.Append("\n");
                tooltip.AppendFormat(ModUpdateDateStrings.STEAM_UPDATE, globalDate.
                                     ToLocalTime());
                updButton.OnClick = new ModUpdateTask(modUpdate).TryUpdateMods;
            }
            else
            {
                // Steam update could not be determined
                tooltip.AppendFormat(ModUpdateDateStrings.LOCAL_UPDATE, localDate.
                                     ToLocalTime());
                tooltip.Append("\n");
                tooltip.AppendFormat(ModUpdateDateStrings.STEAM_UPDATE_UNKNOWN);
            }
            return(updated);
        }
Exemple #4
0
 /// <summary>
 /// Updates the settings for the specified mod ID.
 /// </summary>
 /// <param name="id">The Steam mod ID to update.</param>
 /// <param name="lastUpdated">The new last updated date.</param>
 internal static void UpdateConfigFor(ulong id, System.DateTime lastUpdated)
 {
     lock (DETAILS) {
         var settings = ModUpdateInfo.Settings;
         if (settings.ModUpdates == null)
         {
             settings = new ModUpdateInfo();
         }
         var info = ModUpdateInfo.FindModInConfig(id);
         // Now tracked by this mod
         if (info == null)
         {
             info = new ModUpdateData(id, lastUpdated);
             settings.ModUpdates.Add(info);
         }
         else
         {
             info.LastUpdated = lastUpdated.Ticks;
         }
         info.Status = ModUpdateStatus.PendingUpdate;
         POptions.WriteSettingsForAssembly(settings);
     }
 }
Exemple #5
0
            /// <summary>
            /// Updates the mod local update time and archive path.
            /// </summary>
            internal void Summon()
            {
                var id = ugcMod.fileId;

                if (SteamUGC.GetItemInstallInfo(id, out _, out installPath, 260U,
                                                out uint ts))
                {
                    updateTimestamp = SteamVersionChecker.UnixEpochToDateTime(ts);
                }
                else
                {
                    installPath     = null;
                    updateTimestamp = System.DateTime.MinValue;
                }
                // But reuse the local timestamp if we updated it
                var ourData = ModUpdateInfo.FindModInConfig(id.m_PublishedFileId);

                if (ourData != null)
                {
                    updateTimestamp = new System.DateTime(ourData.LastUpdated, DateTimeKind.
                                                          Utc);
                }
            }
Exemple #6
0
        public override void OnLoad(Harmony harmony)
        {
            var method = typeof(Mod).GetMethodSafe(nameof(Mod.SetCrashed), false);

            if (method != null)
            {
                harmony.Patch(method, prefix: new HarmonyMethod(typeof(ModUpdateDatePatches),
                                                                nameof(OnModCrash)));
            }
            PUtil.InitLibrary();
            new PPatchManager(harmony).RegisterPatchClass(typeof(ModUpdateDatePatches));
            new POptions().RegisterOptions(this, typeof(ModUpdateInfo));
            new PLocalization().Register();
            ModUpdateInfo.LoadSettings();
            base.OnLoad(harmony);
            ThisMod = mod;
            // Shut off AVC
            PRegistry.PutData("PLib.VersionCheck.ModUpdaterActive", true);
            if (ModUpdateInfo.Settings?.PassiveMode == true)
            {
                PRegistry.PutData("PLib.VersionCheck.PassiveSteamUpdate", true);
            }
        }
Exemple #7
0
 /// <summary>
 /// Loads the settings for this mod.
 /// </summary>
 internal static void LoadSettings()
 {
     Settings = POptions.ReadSettingsForAssembly <ModUpdateInfo>() ??
                new ModUpdateInfo();
 }