Пример #1
0
        /// <summary>
        /// Scrubs the config of mods that Steam got around to actually updating.
        /// </summary>
        private static void DoScrubConfig()
        {
            var settings = ModUpdateInfo.Settings;
            var existing = settings?.ModUpdates;
            var manager  = Global.Instance.modManager;

            if (existing != null && manager != null)
            {
                // Anything that is up to date gets purged
                var remove = HashSetPool <ModUpdateData, ModUpdateHandler> .Allocate();

                foreach (var info in existing)
                {
                    ulong id = info.ID;
                    if (CheckMod(manager, id))
                    {
                        remove.Add(info);
                    }
                    if (info.Status == ModUpdateStatus.PendingUpdate)
                    {
                        // Purge the temporary zip
                        ExtensionMethods.RemoveOldDownload(ModUpdateHandler.GetDownloadPath(id));
                        info.Status = ModUpdateStatus.UpdatedByThisMod;
                    }
                }
                // Remove the obsolete entries
                foreach (var info in remove)
                {
                    existing.Remove(info);
                }
                remove.Recycle();
                POptions.WriteSettingsForAssembly(settings);
            }
        }
Пример #2
0
 /// <summary>
 /// Updates the Mods button text.
 /// </summary>
 public void UpdateText()
 {
     if (modsButton != null)
     {
         var modsText = modsButton.GetComponentInChildren <LocText>();
         // How many are out of date?
         int    outdated = ModUpdateHandler.CountOutdatedMods();
         string text     = STRINGS.UI.FRONTEND.MODS.TITLE;
         var    inst     = SteamUGCServiceFixed.Instance;
         if (inst != null && inst.UpdateInProgress)
         {
             text += UISTRINGS.MAINMENU_UPDATING;
         }
         else if (outdated == 1)
         {
             text += UISTRINGS.MAINMENU_UPDATE_1;
         }
         else if (outdated > 1)
         {
             text += string.Format(UISTRINGS.MAINMENU_UPDATE, outdated);
         }
         if (modsText != null)
         {
             modsText.text = text;
         }
     }
 }
Пример #3
0
        protected override SteamAPICall_t ExecuteDownload(PublishedFileId_t id,
                                                          out bool globalEvent)
        {
            var mod = SteamUGCServiceFixed.Instance.GetInfo(id);
            var ret = SteamAPICall_t.Invalid;

            if (mod != null)
            {
                string tempPath = ModUpdateHandler.GetDownloadPath(id.m_PublishedFileId);
                // Purge any stale temporary zip
                ExtensionMethods.RemoveOldDownload(tempPath);
#if DEBUG
                PUtil.LogDebug("Downloading mod {0:D} to {1}".F(id.m_PublishedFileId,
                                                                tempPath));
#endif
                if (mod.installPath == null)
                {
                    // Newly installed mod, populate the expected path
                    globalEvent = true;
                    SteamUGC.DownloadItem(id, false);
                }
                else
                {
                    ret = SteamRemoteStorage.UGCDownloadToLocation(mod.fileId, tempPath, 0U);
                }
            }
            globalEvent = false;
            return(ret);
        }
Пример #4
0
 protected override void OnError(PublishedFileId_t id, EResult result)
 {
     PUtil.LogWarning("Unable to download mod: {0:D}, code: {1}".F(id.
                                                                   m_PublishedFileId, result));
     // Purge the dead zip
     ExtensionMethods.RemoveOldDownload(ModUpdateHandler.GetDownloadPath(id.
                                                                         m_PublishedFileId));
 }
Пример #5
0
 public ModToUpdate(Mod mod)
 {
     Mod = mod ?? throw new ArgumentNullException("mod");
     if (mod.label.distribution_platform != Label.DistributionPlatform.Steam)
     {
         throw new ArgumentException("Only Steam mods can be updated by this class");
     }
     steamFileID = mod.GetSteamModID();
     SteamID     = steamFileID.m_PublishedFileId;
     if (!steamFileID.GetGlobalLastModified(out System.DateTime steamLastUpdate))
     {
         steamLastUpdate = System.DateTime.MinValue;
     }
     LastSteamUpdate = steamLastUpdate;
     DownloadPath    = ModUpdateHandler.GetDownloadPath(SteamID);
 }
 static ModUpdateHandler()
 {
     COLOR_OUTDATED = ScriptableObject.CreateInstance <ColorStyleSetting>();
     COLOR_OUTDATED.inactiveColor = new Color(0.753f, 0.0f, 0.0f);
     COLOR_OUTDATED.activeColor   = new Color(1.0f, 0.0f, 0.0f);
     COLOR_OUTDATED.hoverColor    = new Color(1.0f, 0.0f, 0.0f);
     // Should be unreachable
     COLOR_OUTDATED.disabledColor          = COLOR_OUTDATED.disabledActiveColor =
         COLOR_OUTDATED.disabledhoverColor = new Color(0.706f, 0.549f, 0.549f);
     COLOR_UPDATED = ScriptableObject.CreateInstance <ColorStyleSetting>();
     COLOR_UPDATED.inactiveColor          = new Color(0.0f, 0.753f, 0.0f);
     COLOR_UPDATED.activeColor            = new Color(0.0f, 1.0f, 0.0f);
     COLOR_UPDATED.hoverColor             = new Color(0.0f, 1.0f, 0.0f);
     COLOR_UPDATED.disabledColor          = COLOR_UPDATED.disabledActiveColor =
         COLOR_UPDATED.disabledhoverColor = new Color(0.549f, 0.706f, 0.549f);
     Instance = new ModUpdateHandler();
 }
Пример #7
0
        protected override void OnComplete(PublishedFileId_t id, int _)
        {
            var    mod          = SteamUGCServiceFixed.Instance.GetInfo(id);
            string path         = ModUpdateHandler.GetDownloadPath(id.m_PublishedFileId);
            bool   ok           = false;
            string expectedPath = mod.installPath;

#if DEBUG
            PUtil.LogDebug("Downloaded mod: {0:D}".F(id.m_PublishedFileId));
#endif
            if (expectedPath == null)
            {
                mod.Summon();
                expectedPath = mod.installPath;
            }
            // Copy zip to the install_path and destroy it
            if (expectedPath != null)
            {
                if (File.Exists(path))
                {
                    try {
                        File.Copy(path, expectedPath, true);
                        ok = true;
                    } catch (IOException e) {
                        PUtil.LogWarning("Unable to copy file {0} to {1}:".F(path,
                                                                             expectedPath));
                        PUtil.LogExcWarn(e);
                    } catch (UnauthorizedAccessException) {
                        PUtil.LogWarning("Access to {0} is denied!".F(expectedPath));
                    }
                    ExtensionMethods.RemoveOldDownload(path);
                }
                mod.state = SteamUGCServiceFixed.SteamModState.Updated;
                if (ok && id.GetGlobalLastModified(out System.DateTime when))
                {
                    ModUpdateDetails.UpdateConfigFor(id.m_PublishedFileId, when);
                }
            }
            else
            {
                PUtil.LogWarning("Unable to find install path for {0:D}!".F(id.
                                                                            m_PublishedFileId));
            }
        }
Пример #8
0
 /// <summary>
 /// Applied after BuildDisplay runs.
 /// </summary>
 internal static void Postfix(KButton ___closeButton, System.Collections.
                              IEnumerable ___displayedMods)
 {
     // Must cast the type because ModsScreen.DisplayedMod is private
     if (___displayedMods != null)
     {
         var outdated = new List <ModToUpdate>(16);
         foreach (object displayedMod in ___displayedMods)
         {
             if (displayedMod != null)
             {
                 ModUpdateHandler.AddModUpdateButton(outdated, displayedMod);
             }
         }
         if (outdated.Count > 0 && ___closeButton != null)
         {
             ModUpdateHandler.AddUpdateAll(___closeButton.gameObject.GetParent(),
                                           outdated);
         }
         UpdateMainMenu();
     }
 }