Exemple #1
0
        public void Set(ModInfoHolder Mod, DescType WindowType, string Title, string Message, string WindowTitle = null)
        {
            this.Mod = Mod;
            LocalModInfoArea.Visible  = false;
            ServerModInfoArea.Visible = false;
            UpdateInfoArea.Visible    = false;
            switch (WindowType)
            {
            case DescType.LocalModInfo: LocalModInfoArea.Visible = true; break;

            case DescType.ServerModInfo: ServerModInfoArea.Visible = true; break;

            case DescType.UpdateInfo: UpdateInfoArea.Visible = true; break;
            }
            labelTitle.Markup    = "<b>" + Title + "</b>";
            labelTextView.Text   = "";
            labelTextView.Markup = MarkdownConvert.ToPangoString(Message);
            if (string.IsNullOrWhiteSpace(labelTextView.Text))
            {
                labelTextView.Text = Message;
            }
            if (string.IsNullOrWhiteSpace(WindowTitle))
            {
                this.Title = "TTMM - " + Title;
            }
            else
            {
                this.Title = "TTMM - " + WindowTitle;
            }
        }
Exemple #2
0
        //public ModInfoHolder(JObject Value)
        //{
        //    Name = Value["Name"].ToObject;
        //    Author = Value["Author"].ToString();
        //    CloudName = Value["CloudName"].ToString();
        //    InlineDescription = Value["InlineDescription"].ToString();
        //    Description = Value["Description"].ToString();
        //    Site = Value["Site"].ToString();
        //    var dependencies = Value["RequiredModNames"];
        //    RequiredModNames = new string[dependencies.Count];
        //    for (int i = 0; i < dependencies.Count; i++)
        //    {
        //        RequiredModNames[i] = dependencies[i];
        //    }
        //    CurrentVersion = Value["CurrentVersion"];
        //}

        public static bool TryGetModInfoFromRepo(Downloader.GetRepos.GithubRepoItem repo, out ModInfoHolder result)
        {
            result = new ModInfoHolder()
            {
                State             = ModState.Server,
                Name              = repo.name,
                CloudName         = repo.full_name,
                Author            = repo.full_name.Substring(0, repo.full_name.IndexOf(repo.name) - 1),
                InlineDescription = repo.description,
                Site              = "https://github.com/" + repo.full_name,
                CurrentVersion    = repo.pushed_at
            };

            var    client    = new WebClient();
            string linkspath = "https://raw.githubusercontent.com/" + repo.full_name + "/master/LINKS.";

            string links = "";

            try
            {
                links = client.DownloadString(linkspath + "md");
            }
            catch
            {
                try
                {
                    links = client.DownloadString(linkspath + "txt");
                }
                catch
                {
                    Console.WriteLine("Mod is not set up properly: Neither LINKS.txt file present");
                    result = null;
                    return(false);
                }
            }
            result.FilePath = "";
            var linkarray = links.Split('\n', '\r');

            result.FilePath         = linkarray[0];
            result.RequiredModNames = new string[linkarray.Length - 1];
            int EmptySpace = -1;

            for (int i = 1; i < linkarray.Length; i++)
            {
                string item = linkarray[i];
                if (item == "")
                {
                    EmptySpace--;
                    continue;
                }
                result.RequiredModNames[i + EmptySpace] = item[0] == '/' ? item.Substring(1) : item;
            }
            Array.Resize(ref result.RequiredModNames, linkarray.Length + EmptySpace);
            return(true);
        }
Exemple #3
0
 public static bool GetGithubMod(Downloader.GetRepos.GithubRepoItem mod)
 {
     if (ModInfoHolder.TryGetModInfoFromRepo(mod, out var modinfo))
     {
         GithubMod(modinfo);
         //MainWindow.inst.Log("Added mod " + modinfo.CloudName);
         return(true);
     }
     Console.WriteLine(mod.html_url + " is invalid!");
     return(false);
 }
Exemple #4
0
        public static bool GetMoreGithubMods()
        {
            int count = 0, updatecount = 0;

            var mods = Downloader.GetRepos.GetNextPage();

            foreach (var mod in mods)
            {
                if (ModInfoHolder.TryGetModInfoFromRepo(mod, out var modinfo))
                {
                    updatecount += GithubMod(modinfo);
                    //MainWindow.inst.Log("Added mod " + modinfo.CloudName);
                    count++;
                }
                else
                {
                    Console.WriteLine(mod.html_url + " is invalid!");
                }
            }
            MainWindow.inst.Log($"Found {count} Github mods" + (updatecount == 0 ? "" : " (" + updatecount.ToString() + " updates)"));
            return(Downloader.GetRepos.MorePagesAvailable);
        }
Exemple #5
0
        private static int GithubMod(ModInfoHolder modinfo /*, bool IsMainThread*/)
        {
            int  result     = 0;
            bool foundOther = LocalMods.TryGetValue(modinfo.Name, out ModInfoHolder localModInfo);

            if (foundOther)
            {
                modinfo.FoundOther      = 1;
                localModInfo.FoundOther = 1;
                if (!string.IsNullOrWhiteSpace(modinfo.CurrentVersion) && localModInfo.CurrentVersion != modinfo.CurrentVersion)
                {
                    //if (IsMainThread)
                    //{
                    MainWindow.ModListStoreLocal.SetValue(localModInfo.TreeIter, (int)TreeColumnInfo.Desc, "[Update Available] " + (string)MainWindow.ModListStoreLocal.GetValue(localModInfo.TreeIter, (int)TreeColumnInfo.Desc));
                    MainWindow.ModListStoreLocal.SetValue(localModInfo.TreeIter, (int)TreeColumnInfo.Name, "<b>" + (string)MainWindow.ModListStoreLocal.GetValue(localModInfo.TreeIter, (int)TreeColumnInfo.Name) + "</b>");
                    //}
                    //else Tools.invoke.Add(delegate
                    //{
                    //    MainWindow.ModListStoreLocal.SetValue(localModInfo.TreeIter, (int)TreeColumnInfo.Desc, "[Update Available] " + (string)MainWindow.ModListStoreLocal.GetValue(localModInfo.TreeIter, (int)TreeColumnInfo.Desc));
                    //    MainWindow.ModListStoreLocal.SetValue(localModInfo.TreeIter, (int)TreeColumnInfo.Name, "<b>" + (string)MainWindow.ModListStoreLocal.GetValue(localModInfo.TreeIter, (int)TreeColumnInfo.Name) + "</b>");
                    //});
                    result = 1;
                }
            }
            lastGithubMod = modinfo;
            //if (IsMainThread)
            //{
            modinfo.TreeIter = MainWindow.ModListStoreGithub.AppendValues(foundOther, modinfo.FancyName(), modinfo.InlineDescription, modinfo.Author, modinfo);
            GithubMods.Add(modinfo.CloudName, modinfo);
            //}
            //else Tools.invoke.Add(delegate
            //{
            //    modinfo.TreeIter = MainWindow.ModListStoreGithub.AppendValues(foundOther, modinfo.FancyName(), modinfo.InlineDescription, modinfo.Author, modinfo);
            //    GithubMods.Add(modinfo.CloudName, modinfo);
            //});
            return(result);
        }
Exemple #6
0
        public static void GetLocalMod_Internal(string path /*, bool IsDisabled = false*/ /*, bool IsMainThread*/)
        {
            string modjson  = path + "/mod.json";
            string ttmmjson = path + "/ttmm.json";

            if (File.Exists(modjson))
            {
                var           json    = JsonConvert.DeserializeObject <Dictionary <string, object> >(File.ReadAllText(modjson));
                ModInfoHolder modInfo = null;
                if (File.Exists(ttmmjson))
                {
                    try
                    {
                        modInfo = JsonConvert.DeserializeObject <ModInfoHolder>(File.ReadAllText(ttmmjson), new JsonSerializerSettings()
                        {
                            MissingMemberHandling = MissingMemberHandling.Ignore
                        });
                    }
                    catch { Console.WriteLine("Reading ModInfo file from " + path + " failed!"); }
                }
                if (modInfo != null)
                {
                    modInfo.State     = /*IsDisabled ? ModInfoHolder.ModState.Disabled :*/ (Convert.ToBoolean(json["Enable"]) ? ModInfoHolder.ModState.Enabled : ModInfoHolder.ModState.Inactive);
                    modInfo.FilePath  = path;
                    modInfo.CloudName = modInfo.CloudName[0] == '/' ? modInfo.CloudName.Substring(1) : modInfo.CloudName;
                }
                else
                {
                    modInfo = new ModInfoHolder
                    {
                        Name              = json["DisplayName"] as string,
                        Author            = json["Author"] as string,
                        State             = /*IsDisabled ? ModInfoHolder.ModState.Disabled :*/ (Convert.ToBoolean(json["Enable"]) ? ModInfoHolder.ModState.Enabled : ModInfoHolder.ModState.Inactive),
                        FilePath          = path,
                        InlineDescription = json["Id"] as string
                    };
                }

                if (LocalMods.TryGetValue(modInfo.Name, out ModInfoHolder oldModInfo))
                {
                    //if (IsMainThread)               MainWindow.ModListStoreLocal.Remove(ref oldModInfo.TreeIter);
                    //else
                    Tools.invoke.Add(delegate { MainWindow.ModListStoreLocal.Remove(ref oldModInfo.TreeIter); });
                }
                //if (IsMainThread)
                //{
                //    modInfo.TreeIter = MainWindow.ModListStoreLocal.InsertWithValues(0, modInfo.State == ModInfoHolder.ModState.Enabled, modInfo.FancyName(), modInfo.InlineDescription, modInfo.Author, modInfo);
                //    LocalMods[modInfo.Name] = modInfo;
                //}
                //else
                Tools.invoke.Add(delegate
                {
                    modInfo.TreeIter        = MainWindow.ModListStoreLocal.InsertWithValues(0, modInfo.State == ModInfoHolder.ModState.Enabled, modInfo.FancyName(), modInfo.InlineDescription, modInfo.Author, modInfo);
                    LocalMods[modInfo.Name] = modInfo;
                });
                //if (modInfo.CloudName != null && modInfo.CloudName != "" && flag)
                //{
                //    string version = FindServerMod(modInfo.CloudName, ImmediatelyFromCloud);
                //    if (version != "" && version != modInfo.CurrentVersion)
                //    {
                //        Log("Update available for " + modInfo.CloudName + " (" + version + ")", Color.Turquoise);
                //        modInfo.Visible.SubItems[2].Text = "[Update Available] " + modInfo.Visible.SubItems[2].Text;
                //        modInfo.Visible.UseItemStyleForSubItems = false;
                //        modInfo.Visible.SubItems[1].Font = new Font(modInfo.Visible.SubItems[1].Font, FontStyle.Bold);
                //    }
                //}
            }
        }