Exemple #1
0
        public VersionStatus(ModMetaData mod)
        {
            version = mod.TargetVersion;
            if (!VersionControl.IsWellFormattedVersionString(mod.TargetVersion))
            {
                match = VersionMatch.InvalidVersion;
                tip   = I18n.InvalidVersion(version);
                return;
            }

            var _version = VersionControl.VersionFromString(version);

            if (_version.Major != VersionControl.CurrentMajor || _version.Minor != VersionControl.CurrentMinor)
            {
                match = VersionMatch.DifferentVersion;
                tip   = I18n.DifferentVersion(mod);
                return;
            }
            if (_version.Build != VersionControl.CurrentBuild)
            {
                match = VersionMatch.DifferentBuild;
                tip   = I18n.DifferentBuild(mod);
                return;
            }
            match = VersionMatch.CurrentVersion;
            tip   = I18n.CurrentVersion;
        }
Exemple #2
0
 public static void Upload(ModMetaData mod)
 {
     if (!VersionControl.IsWellFormattedVersionString(mod.TargetVersion))
     {
         Messages.Message(I18n.NeedsWellFormattedTargetVersion, MessageTypeDefOf.RejectInput, false);
     }
     else
     {
         Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(I18n.ConfirmSteamWorkshopUpload, delegate
         {
             SoundDefOf.Tick_High.PlayOneShotOnCamera();
             Dialog_MessageBox dialog_MessageBox = Dialog_MessageBox.CreateConfirmation(
                 I18n.ConfirmContentAuthor, delegate
             {
                 SoundDefOf.Tick_High.PlayOneShotOnCamera();
                 AccessTools.Method(typeof(Verse.Steam.Workshop), "Upload")
                 .Invoke(null, new object[] { mod });
             }, true);
             dialog_MessageBox.buttonAText      = I18n.Yes;
             dialog_MessageBox.buttonBText      = I18n.No;
             dialog_MessageBox.interactionDelay = 6f;
             Find.WindowStack.Add(dialog_MessageBox);
         }, true));
     }
 }
Exemple #3
0
 public static VersionMatch Match(string version)
 {
     if (!VersionControl.IsWellFormattedVersionString(version))
     {
         return(VersionMatch.InvalidVersion);
     }
     return(Match(Manifest.ParseVersion(version, null)));
 }
Exemple #4
0
        private void Init()
        {
            this.meta = DirectXmlLoader.ItemFromXmlFile <ModMetaData.ModMetaDataInternal>(string.Concat(new object[]
            {
                this.RootDir.FullName,
                Path.DirectorySeparatorChar,
                "About",
                Path.DirectorySeparatorChar,
                "About.xml"
            }), true);
            if (this.meta.name.NullOrEmpty())
            {
                if (this.OnSteamWorkshop)
                {
                    this.meta.name = "Workshop mod " + this.Identifier;
                }
                else
                {
                    this.meta.name = this.Identifier;
                }
            }
            if (!this.IsCoreMod && !this.OnSteamWorkshop && !VersionControl.IsWellFormattedVersionString(this.meta.targetVersion))
            {
                Log.ErrorOnce(string.Concat(new string[]
                {
                    "Mod ",
                    this.meta.name,
                    " has incorrectly formatted target version '",
                    this.meta.targetVersion,
                    "'. For the current version, write: <targetVersion>",
                    VersionControl.CurrentVersionString,
                    "</targetVersion>"
                }), this.Identifier.GetHashCode(), false);
            }
            LongEventHandler.ExecuteWhenFinished(delegate
            {
                string url = GenFilePaths.SafeURIForUnityWWWFromPath(this.PreviewImagePath);
                using (WWW www = new WWW(url))
                {
                    www.threadPriority = UnityEngine.ThreadPriority.High;
                    while (!www.isDone)
                    {
                        Thread.Sleep(1);
                    }
                    if (www.error == null)
                    {
                        this.previewImage = www.textureNonReadable;
                    }
                }
            });
            string publishedFileIdPath = this.PublishedFileIdPath;

            if (File.Exists(this.PublishedFileIdPath))
            {
                string s = File.ReadAllText(publishedFileIdPath);
                this.publishedFileIdInt = new PublishedFileId_t(ulong.Parse(s));
            }
        }
Exemple #5
0
        public List <string> GetIssueList(ModMetaData mod)
        {
            List <string> list = new List <string>();

            if (foldersForVersion.Count > 0)
            {
                string text = null;
                {
                    foreach (string key in foldersForVersion.Keys)
                    {
                        if (foldersForVersion[key].Count == 0)
                        {
                            list.Add("ModLoadFolderListEmpty".Translate(key));
                        }
                        foreach (LoadFolder item in from f in foldersForVersion[key]
                                 group f by f into g
                                 where g.Count() > 1
                                 select g.Key)
                        {
                            list.Add("ModLoadFolderRepeatingFolder".Translate(key, item.folderName));
                        }
                        if (!VersionControl.IsWellFormattedVersionString(key) && !key.Equals("default", StringComparison.InvariantCultureIgnoreCase))
                        {
                            list.Add("ModLoadFolderMalformedVersion".Translate(key));
                        }
                        if (key.Equals("default") && text != null)
                        {
                            list.Add("ModLoadFolderOutOfOrderDefault".Translate());
                        }
                        if (text != null && VersionControl.TryParseVersionString(key, out Version version) && VersionControl.TryParseVersionString(text, out Version version2) && version < version2)
                        {
                            list.Add("ModLoadFolderOutOfOrder".Translate(key, text));
                        }
                        for (int i = 0; i < foldersForVersion[key].Count; i++)
                        {
                            LoadFolder loadFolder = foldersForVersion[key][i];
                            if (!Directory.Exists(Path.Combine(mod.RootDir.FullName, loadFolder.folderName)))
                            {
                                list.Add("ModLoadFolderDoesntExist".Translate(loadFolder.folderName, key));
                            }
                        }
                        if (VersionControl.TryParseVersionString(key, out Version version3) && !mod.SupportedVersionsReadOnly.Contains(version3))
                        {
                            list.Add("ModLoadFolderDefinesUnsupportedGameVersion".Translate(key));
                        }
                        text = key;
                    }
                    return(list);
                }
            }
            return(list);
        }
Exemple #6
0
 protected Version getVersion(string versionString, string exceptionType)
 {
     if (versionString.NullOrEmpty() || !VersionControl.IsWellFormattedVersionString(versionString))
     {
         throw new ArgumentException(exceptionType);
     }
     try
     {
         return(VersionControl.VersionFromString(versionString));
     }
     catch
     {
         throw new ArgumentException(exceptionType);
     }
 }
Exemple #7
0
        private void Init()
        {
            meta = DirectXmlLoader.ItemFromXmlFile <ModMetaDataInternal>(RootDir.FullName + Path.DirectorySeparatorChar + "About" + Path.DirectorySeparatorChar + "About.xml");
            if (meta.name.NullOrEmpty())
            {
                if (OnSteamWorkshop)
                {
                    meta.name = "Workshop mod " + Identifier;
                }
                else
                {
                    meta.name = Identifier;
                }
            }
            if (!IsCoreMod && !OnSteamWorkshop && !VersionControl.IsWellFormattedVersionString(meta.targetVersion))
            {
                Log.ErrorOnce("Mod " + meta.name + " has incorrectly formatted target version '" + meta.targetVersion + "'. For the current version, write: <targetVersion>" + VersionControl.CurrentVersionString + "</targetVersion>", Identifier.GetHashCode());
            }
            LongEventHandler.ExecuteWhenFinished(delegate
            {
                string url = GenFilePaths.SafeURIForUnityWWWFromPath(PreviewImagePath);
                using (WWW wWW = new WWW(url))
                {
                    wWW.threadPriority = UnityEngine.ThreadPriority.High;
                    while (!wWW.isDone)
                    {
                        Thread.Sleep(1);
                    }
                    if (wWW.error == null)
                    {
                        previewImage = wWW.textureNonReadable;
                    }
                }
            });
            string publishedFileIdPath = PublishedFileIdPath;

            if (File.Exists(PublishedFileIdPath))
            {
                string s = File.ReadAllText(publishedFileIdPath);
                publishedFileIdInt = new PublishedFileId_t(ulong.Parse(s));
            }
        }
 private bool TryParseVersion(string str, bool logIssues = true)
 {
     if (!VersionControl.TryParseVersionString(str, out var version))
     {
         if (logIssues)
         {
             Log.Error("Unable to parse version string on mod " + name + " from " + author + " \"" + str + "\"");
         }
         return(false);
     }
     SupportedVersions.Add(version);
     if (!VersionControl.IsWellFormattedVersionString(str))
     {
         if (logIssues)
         {
             Log.Warning("Malformed (correct format is Major.Minor) version string on mod " + name + " from " + author + " \"" + str + "\" - parsed as \"" + version.Major + "." + version.Minor + "\"");
         }
         return(false);
     }
     return(true);
 }
Exemple #9
0
 static List <System.Version> GetTaggedVersions(string rootDir)
 {
     if (cachedVersions.TryGetValue(rootDir, out var cached))
     {
         return(cached);
     }
     try
     {
         var xml = new XmlDocument();
         xml.Load(rootDir + Path.DirectorySeparatorChar + "About" + Path.DirectorySeparatorChar + "Manifest.xml");
         var tags   = xml.SelectNodes("/Manifest/targetVersions/li").Cast <XmlNode>().Select(node => node.InnerText);
         var result = tags
                      .Where(tag => VersionControl.IsWellFormattedVersionString(tag))
                      .Select(tag => VersionControl.VersionFromString(tag)).ToList();
         cachedVersions[rootDir] = result;
         return(result);
     }
     catch (System.Exception)
     {
         cachedVersions[rootDir] = null;
         return(null);
     }
 }
        internal static void DoWindowContents(this Page_ModsConfig instance, Rect rect)
        {
            Rect mainRect = (Rect)AccessTools.Method(typeof(Page_ModsConfig), "GetMainRect").Invoke(instance, new object[] { rect, 0f, true });

            GUI.BeginGroup(mainRect);
            Text.Font = GameFont.Small;
            float num   = 0f;
            Rect  rect2 = new Rect(17f, num, 316f, 30f);

            if (Widgets.ButtonText(rect2, "OpenSteamWorkshop".Translate(), true, false, true))
            {
                SteamUtility.OpenSteamWorkshopPage();
            }
            num += 30f;
            Rect rect3 = new Rect(17f, num, 316f, 30f);

            if (Widgets.ButtonText(rect3, "GetModsFromForum".Translate(), true, false, true))
            {
                Application.OpenURL("http://rimworldgame.com/getmods");
            }
            num += 30f;
            num += 17f;

            // Modlist

            Rect rect4 = new Rect(0f, num, 350f, mainRect.height - num);

            Widgets.DrawMenuSection(rect4, true);

            float height = (float)(ModLister.AllInstalledMods.Count <ModMetaData>() * 34 + 300);
            Rect  rect5  = new Rect(0f, 26f, rect4.width - 16f, height);

            Widgets.BeginScrollView(rect4, ref modListScrollPosition, rect5, true);
            Rect             rect6            = rect5.ContractedBy(4f);
            Listing_Standard listing_Standard = new Listing_Standard();

            listing_Standard.ColumnWidth = rect6.width;
            listing_Standard.Begin(rect6);

            Rect searchBox = listing_Standard.GetRect(26f);

            searchString = TextEntryWidgets.TextEntryWithPlaceHolder(searchBox, searchString, "SearchPlaceHolder".Translate());

            int reorderableGroup = -1;

            if (!SearchInProgress)
            {
                reorderableGroup = ReorderableWidget.NewGroup(delegate(int from, int to) {
                    AccessTools.Method(typeof(ModsConfig), "Reorder").Invoke(null, new object[] { from, to });
                    SoundDefOf.TickHigh.PlayOneShotOnCamera(null);
                });
            }
            int num2 = 0;

            foreach (ModMetaDataEnhanced current in ModsInListOrder())
            {
                DoModRow(listing_Standard, current, num2, reorderableGroup);
                num2++;
            }
            for (int i = 0; i < WorkshopItems.DownloadingItemsCount; i++)
            {
                DoModRowDownloading(listing_Standard, num2);
                num2++;
            }
            listing_Standard.End();
            Widgets.EndScrollView();

            // selected mod details
            Rect position = new Rect(rect4.xMax + 17f, 0f, mainRect.width - rect4.width - 17f, mainRect.height);

            GUI.BeginGroup(position);
            if (selectedMod != null)
            {
                Text.Font = GameFont.Medium;
                Rect rect7 = new Rect(0f, 0f, position.width, 40f);
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect7, selectedMod.OriginalMetaData.Name.Truncate(rect7.width, null));
                Text.Anchor = TextAnchor.UpperLeft;
                if (!selectedMod.OriginalMetaData.IsCoreMod)
                {
                    Rect rect8 = rect7;
                    Text.Font   = GameFont.Tiny;
                    Text.Anchor = TextAnchor.LowerRight;
                    if (!selectedMod.OriginalMetaData.VersionCompatible)
                    {
                        GUI.color = Color.red;
                    }
                    Widgets.Label(rect8, "ModTargetVersion".Translate(new object[]
                    {
                        selectedMod.OriginalMetaData.TargetVersion
                    }));
                    GUI.color   = Color.white;
                    Text.Anchor = TextAnchor.UpperLeft;
                    Text.Font   = GameFont.Small;
                }
                Rect position2 = new Rect(0f, rect7.yMax, 0f, 20f);
                if (selectedMod.OriginalMetaData.previewImage != null)
                {
                    position2.width  = Mathf.Min((float)selectedMod.OriginalMetaData.previewImage.width, position.width);
                    position2.height = (float)selectedMod.OriginalMetaData.previewImage.height * (position2.width / (float)selectedMod.OriginalMetaData.previewImage.width);
                    if (position2.height > 300f)
                    {
                        position2.width *= 300f / position2.height;
                        position2.height = 300f;
                    }
                    position2.x = position.width / 2f - position2.width / 2f;
                    GUI.DrawTexture(position2, selectedMod.OriginalMetaData.previewImage, ScaleMode.ScaleToFit);
                }
                Text.Font = GameFont.Small;
                float num3 = position2.yMax + 10f;
                if (!selectedMod.OriginalMetaData.Author.NullOrEmpty())
                {
                    Rect rect9 = new Rect(0f, num3, position.width / 2f, 25f);
                    Widgets.Label(rect9, "Author".Translate() + ": " + selectedMod.OriginalMetaData.Author);
                }
                if (!selectedMod.OriginalMetaData.Url.NullOrEmpty())
                {
                    float num4   = Mathf.Min(position.width / 2f, Text.CalcSize(selectedMod.OriginalMetaData.Url).x);
                    Rect  rect10 = new Rect(position.width - num4, num3, num4, 25f);
                    Text.WordWrap = false;
                    if (Widgets.ButtonText(rect10, selectedMod.OriginalMetaData.Url, false, false, true))
                    {
                        Application.OpenURL(selectedMod.OriginalMetaData.Url);
                    }
                    Text.WordWrap = true;
                }
                WidgetRow widgetRow = new WidgetRow(position.width, num3 + 25f, UIDirection.LeftThenUp, 99999f, 4f);
                if (SteamManager.Initialized && selectedMod.OriginalMetaData.OnSteamWorkshop)
                {
                    if (widgetRow.ButtonText("Unsubscribe", null, true, false))
                    {
                        Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmUnsubscribe".Translate(new object[]
                        {
                            selectedMod.OriginalMetaData.Name
                        }), delegate {
                            selectedMod.OriginalMetaData.enabled = false;
                            AccessTools.Method(typeof(Workshop), "Unsubscribe").Invoke(null, new object[] { selectedMod.OriginalMetaData });
                            AccessTools.Method(typeof(Page_ModsConfig), "Notify_SteamItemUnsubscribed").Invoke(instance, new object[] { selectedMod.OriginalMetaData.GetPublishedFileId() });
                        }, true, null));
                    }
                    if (widgetRow.ButtonText("WorkshopPage".Translate(), null, true, false))
                    {
                        SteamUtility.OpenWorkshopPage(selectedMod.OriginalMetaData.GetPublishedFileId());
                    }
                }
                float num5    = num3 + 25f + 24f;
                Rect  outRect = new Rect(0f, num5, position.width, position.height - num5 - 40f);
                float width   = outRect.width - 16f;
                Rect  rect11  = new Rect(0f, 0f, width, Text.CalcHeight(selectedMod.OriginalMetaData.Description, width));
                Widgets.BeginScrollView(outRect, ref modDescriptionScrollPosition, rect11, true);
                Widgets.Label(rect11, selectedMod.OriginalMetaData.Description);
                Widgets.EndScrollView();
                if (Prefs.DevMode && SteamManager.Initialized && selectedMod.OriginalMetaData.CanToUploadToWorkshop())
                {
                    Rect rect12 = new Rect(0f, position.yMax - 40f, 200f, 40f);
                    if (Widgets.ButtonText(rect12, Workshop.UploadButtonLabel(selectedMod.OriginalMetaData.GetPublishedFileId()), true, false, true))
                    {
                        if (!VersionControl.IsWellFormattedVersionString(selectedMod.OriginalMetaData.TargetVersion))
                        {
                            Messages.Message("MessageModNeedsWellFormattedTargetVersion".Translate(new object[]
                            {
                                VersionControl.CurrentVersionString
                            }), MessageSound.RejectInput);
                        }
                        else
                        {
                            Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmSteamWorkshopUpload".Translate(), delegate {
                                SoundDefOf.TickHigh.PlayOneShotOnCamera(null);
                                Dialog_MessageBox dialog_MessageBox = Dialog_MessageBox.CreateConfirmation("ConfirmContentAuthor".Translate(), delegate {
                                    SoundDefOf.TickHigh.PlayOneShotOnCamera(null);
                                    AccessTools.Method(typeof(Workshop), "Upload").Invoke(null, new object[] { selectedMod.OriginalMetaData });
                                }, true, null);
                                dialog_MessageBox.buttonAText      = "Yes".Translate();
                                dialog_MessageBox.buttonBText      = "No".Translate();
                                dialog_MessageBox.interactionDelay = 6f;
                                Find.WindowStack.Add(dialog_MessageBox);
                            }, true, null));
                        }
                    }
                }
            }
            GUI.EndGroup();
            GUI.EndGroup();

            DoBottomLeftWindowContents(rect);
            DoBottomRightWindowContents(rect);
        }