Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
        public ModInfo(Downloader.GetRepos.GithubRepoItem repo)
        {
            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/" + CloudName;

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

            bool   flag  = false;
            string links = "";

            try
            {
                links = client.DownloadString(linkspath + "md");
            }
            catch
            {
                try
                {
                    links = client.DownloadString(linkspath + "txt");
                }
                catch
                {
                    flag = true; // File doesn't exist
                }
            }
            FilePath = "";
            if (!flag) // Get links from LINKS.md or LINKS.txt
            {
                var linkarray = links.Split('\n', '\r');
                FilePath         = linkarray[0];
                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;
                    }
                    RequiredModNames[i + EmptySpace] = item[0] == '/' ? item.Substring(1) : item;
                }
                Array.Resize(ref RequiredModNames, linkarray.Length + EmptySpace);
            }
            else // Get link from README.md
            {
                string readmepath = "https://raw.githubusercontent.com/" + CloudName + "/master/README.md";
                string readme     = client.DownloadString(readmepath); // Get README.md
                int    linkget    = readme.IndexOf("https://github.com/" + CloudName + "/tree/");
                if (linkget == -1)
                {
                    //The repo does not have a link to the latest build folder; Skipping
                    throw new Exception("Mod is not set up properly: No path to download can be found");
                }
                FilePath         = NewMain.DigLink(ref readme, linkget);
                RequiredModNames = new string[0];
            }
        }