Beispiel #1
0
        public static Mod LoadFromDirectory(string directory)
        {
            //Mod.ghClient.Credentials = Mod.basicAuth;
            DirectoryInfo di = new DirectoryInfo(directory);

            if (di.Exists)
            {
                var modFile = Path.Combine(directory, "mod.json");
                if (File.Exists(modFile))
                {
                    using (StreamReader file = File.OpenText(modFile))
                    {
                        var modjson = file.ReadToEnd();
                        Mod tempMod = JsonConvert.DeserializeObject <Mod>(modjson);
                        if (tempMod.Version != null && tempMod.Version != "")
                        {
                            if (Semver.SemVersion.TryParse(tempMod.Version, out tempMod.SemVer) == false)
                            {
                                if (Semver.SemVersion.TryParse(tempMod.Version.Substring(1), out tempMod.SemVer) == false)
                                {
                                    tempMod.SemVer = new Semver.SemVersion(0);
                                }
                            }
                        }
                        else
                        {
                            tempMod.Version = "??";
                        }
                        tempMod.ModDirectory     = di.Name;
                        tempMod.ModFullDirectory = di.FullName;
                        foreach (DirectoryInfo did in di.EnumerateDirectories())
                        {
                            tempMod.enumerateDirectoryForJson(did);
                        }
                        try
                        {
                            tempMod.fetchLatestReleaseFromWebsite();
                        }
                        catch
                        {
                            try
                            {
                                tempMod.fetchReleasesFromWebsite();
                            }
                            catch
                            {
                            }
                        }
                        if (tempMod.Name == null)
                        {
                            tempMod.Name = "??";
                        }
                        return(tempMod);
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
        public static void LoadFromServer()
        {
            var json = new WebClient().DownloadString(Utils.ghe + "modlist.json");
            Dictionary <string, Mod> temp = JsonConvert.DeserializeObject <Dictionary <string, Mod> >(json);

            foreach (string modkey in temp.Keys)
            {
                Mod modd = temp[modkey];
                modd.Name = modkey;
                modd.fetchLatestReleaseFromWebsite();
            }
            ModList = temp;
        }