コード例 #1
0
 internal ModUpdateTask(ModToUpdate toUpdate)
 {
     if (toUpdate == null)
     {
         throw new ArgumentNullException("toUpdate");
     }
     Mods = new Queue <ModToUpdate>(1);
     Mods.Enqueue(toUpdate);
     Results = new List <ModUpdateResult>(1);
 }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <summary>
        /// Adds the mod update date to the mods menu.
        /// </summary>
        /// <param name="modEntry">The entry in the mod menu.</param>
        /// <param name="outdated">The mods which are out of date.</param>
        internal static void AddModUpdateButton(ICollection <ModToUpdate> outdated,
                                                Traverse modEntry)
        {
            int index       = modEntry.GetField <int>("mod_index");
            var rowInstance = modEntry.GetField <RectTransform>("rect_transform")?.gameObject;
            var mods        = Global.Instance.modManager?.mods;

            if (rowInstance != null && mods != null && index >= 0 && index < mods.Count)
            {
                var mod       = mods[index];
                var tooltip   = new StringBuilder(128);
                var localDate = mod.GetLocalLastModified();
                var updated   = ModStatus.Disabled;
                // A nice colorful button with a warning or checkmark icon
                var updButton = new PButton("UpdateMod")
                {
                    Margin = BUTTON_MARGIN, SpriteSize = ICON_SIZE,
                    MaintainSpriteAspect = true
                };
                if (mod.label.distribution_platform == Label.DistributionPlatform.Steam)
                {
                    var modUpdate = new ModToUpdate(mod);
                    updated = AddSteamUpdate(tooltip, modUpdate, localDate, updButton);
                    if (updated == ModStatus.Outdated)
                    {
                        outdated.Add(modUpdate);
                    }
                }
                else
                {
                    tooltip.AppendFormat(UISTRINGS.LOCAL_UPDATE, localDate.ToLocalTime());
                }
                // Icon, color, and tooltip
                updButton.Sprite = (updated == ModStatus.UpToDate || updated == ModStatus.
                                    Disabled) ? PUITuning.Images.Checked : PUITuning.Images.GetSpriteByName(
                    "iconWarning");
                updButton.Color = (updated == ModStatus.Outdated) ? COLOR_OUTDATED :
                                  COLOR_UPDATED;
                updButton.ToolTip = tooltip.ToString();
                // Just before subscription button, and after the Options button
                PButton.SetButtonEnabled(updButton.AddTo(rowInstance, 3), updated != ModStatus.
                                         Disabled);
            }
        }
コード例 #4
0
        /// <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>
        /// <param name="autoUpdate">Whether automatic updates are enabled.</param>
        /// <returns>The status of the Steam mod.</returns>
        private static ModStatus AddSteamUpdate(StringBuilder tooltip, ModToUpdate modUpdate,
                                                System.DateTime localDate, PButton updButton, bool autoUpdate)
        {
            var steamDate = modUpdate.LastSteamUpdate;
            var updated   = GetModStatus(modUpdate, ref localDate);

            // Generate tooltip for mod's current date and last Steam update
            switch (updated)
            {
            case ModStatus.UpToDate:
                tooltip.Append(UISTRINGS.MOD_UPDATED);
                break;

            case ModStatus.UpToDateLocal:
                tooltip.Append(UISTRINGS.MOD_UPDATED_BYUS);
                break;

            case ModStatus.Outdated:
                tooltip.Append(autoUpdate ? UISTRINGS.MOD_ERR_UPDATE : UISTRINGS.MOD_OUTDATED);
                break;

            default:
                break;
            }
            // AppendLine appends platform specific separator
            tooltip.Append("\n");
            tooltip.AppendFormat(cultureInfo, UISTRINGS.LOCAL_UPDATE, localDate.ToLocalTime());
            tooltip.Append("\n");
            if (updated == ModStatus.Disabled)
            {
                tooltip.AppendFormat(UISTRINGS.STEAM_UPDATE_UNKNOWN);
            }
            else
            {
                tooltip.AppendFormat(cultureInfo, UISTRINGS.STEAM_UPDATE, steamDate.
                                     ToLocalTime());
                updButton.OnClick = new ModUpdateTask(modUpdate).TryUpdateMods;
            }
            return(updated);
        }
コード例 #5
0
        /// <summary>
        /// Adds the mod update date to the mods menu.
        /// </summary>
        /// <param name="outdated">The mods which are out of date.</param>
        /// <param name="modEntry">The entry in the mod menu.</param>
        internal static void AddModUpdateButton(ICollection <ModToUpdate> outdated,
                                                object modEntry)
        {
            int index    = -1;
            var type     = modEntry.GetType();
            var indexVal = type.GetFieldSafe("mod_index", false)?.GetValue(modEntry);

            if (indexVal is int intVal)
            {
                index = intVal;
            }
            var rowInstance = (type.GetFieldSafe("rect_transform", false)?.GetValue(
                                   modEntry) as RectTransform)?.gameObject;
            var mods = Global.Instance.modManager?.mods;

            if (rowInstance != null && mods != null && index >= 0 && index < mods.Count)
            {
                var mod       = mods[index];
                var tooltip   = new StringBuilder(128);
                var localDate = mod.GetLocalLastModified();
                var updated   = ModStatus.Disabled;
                // A nice colorful button with a warning or checkmark icon
                var updButton = new PButton("UpdateMod")
                {
                    Margin = BUTTON_MARGIN, SpriteSize = ICON_SIZE,
                    MaintainSpriteAspect = true
                };
                // Format DateTime to the current Klei culture (otherwise it uses
                // CurrentCulture which defaults to the Steam culture)
                if (cultureInfo == null)
                {
                    var langCode = Localization.GetLocale()?.Code;
                    if (string.IsNullOrEmpty(langCode))
                    {
                        langCode = Localization.GetCurrentLanguageCode();
                    }
                    if (string.IsNullOrEmpty(langCode))
                    {
                        cultureInfo = CultureInfo.CurrentCulture;
                    }
                    else
                    {
                        cultureInfo = new CultureInfo(langCode);
                    }
                }
                if (mod.label.distribution_platform == Label.DistributionPlatform.Steam)
                {
                    var modUpdate = new ModToUpdate(mod);
                    updated = AddSteamUpdate(tooltip, modUpdate, localDate, updButton);
                    if (updated == ModStatus.Outdated)
                    {
                        outdated.Add(modUpdate);
                    }
                }
                else
                {
                    tooltip.AppendFormat(cultureInfo, UISTRINGS.LOCAL_UPDATE, localDate.
                                         ToLocalTime());
                }
                // Icon, color, and tooltip
                updButton.Sprite = (updated == ModStatus.UpToDate || updated == ModStatus.
                                    Disabled) ? PUITuning.Images.Checked : PUITuning.Images.GetSpriteByName(
                    "iconWarning");
                updButton.Color = (updated == ModStatus.Outdated) ? COLOR_OUTDATED :
                                  COLOR_UPDATED;
                updButton.ToolTip = tooltip.ToString();
                // Just before subscription button, and after the Options button
                PButton.SetButtonEnabled(updButton.AddTo(rowInstance, 4), updated != ModStatus.
                                         Disabled);
            }
        }