public static int CheckMod(string modName, string singleModVersion, ModInfo modInfo, MetadataCache metadataCache)
 {
     CacheInfo ci = new CacheInfo();
     ci.version = modInfo.version;
     ci.state = "fail-install";
     CleanKSP();
     if (!InstallMod(modName, singleModVersion))
     {
         metadataCache.AddCacheData(modName, ci);
         return -1;
     }
     if (!FilesOK(modName, modInfo))
     {
         ci.state = "fail-files";
         metadataCache.AddCacheData(modName, ci);
         return -2;
     }
     ci.state = "ok";
     metadataCache.AddCacheData(modName, ci);
     if (File.Exists("errors/" + modName + ".txt"))
     {
         File.Delete("errors/" + modName + ".txt");
     }
     return 0;
 }
Exemplo n.º 2
0
 public static string GetModHash(string modName, ModInfo modInfo)
 {
     string url = Uri.UnescapeDataString(modInfo.downloadUrl);
     //Differences?
     url = url.Replace("&", "%26");
     using (var sha1 = new SHA1Managed())
     {
         byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(url));
         string retVal = BitConverter.ToString(hash).Replace("-", "").Substring(0, 8);
         return retVal;
     }
 }
Exemplo n.º 3
0
 public static string GetGameDataDir(string modName, ModInfo modInfo)
 {
     string[] dirs = Directory.GetDirectories("temp/extract", "*", SearchOption.AllDirectories);
     foreach (string dirName in dirs)
     {
         if (Path.GetFileName(dirName).ToLower() == "gamedata")
         {
             return dirName.Substring("temp/extract/".Length);
         }
     }
     return "";
 }
Exemplo n.º 4
0
        public static Dictionary<string, ModInfo> GetModInfo(string KSP_VERSION, JToken registry)
        {
            Dictionary<string, ModInfo> modInfo = new Dictionary<string, ModInfo>();
            foreach (JProperty mod in registry["available_modules"])
            {
                string currentModName = mod.Name;
                bool versionOk = false;

                foreach (JProperty versionProperty in mod.Value["module_version"])
                {
                    JObject versionKeys = (JObject)versionProperty.Value;
                    ModInfo mi = new ModInfo();
                    mi.version = (string)versionKeys["version"];
                    mi.downloadUrl = (string)versionKeys["download"];
                    JToken installs = versionKeys["install"];
                    if (installs.Type != JTokenType.Null)
                    {
                        foreach (JObject jobj in (JArray)installs)
                        {
                            string file = (string)jobj["file"];
                            string installs_to = (string)jobj["install_to"];
                            mi.installs.Add(new KeyValuePair<string,string>(file, installs_to));
                        }
                    }
                    string ksp_version = (string)versionKeys["ksp_version"];
                    string ksp_version_min = (string)versionKeys["ksp_version"];
                    string ksp_version_max = (string)versionKeys["ksp_version"];
                    versionOk = (ksp_version == KSP_VERSION) || VersionCompatible(KSP_VERSION, ksp_version_min, ksp_version_max);
                    if (versionOk)
                    {
                        modInfo.Add(currentModName, mi);
                        break;
                    }
                }
                if (versionOk)
                {
                    continue;
                }
            }
            return modInfo;
        }
        public static bool FilesOK(string modName, ModInfo modInfo)
        {
            Console.WriteLine("Checking files!");
            //string fileName = CkanUtils.GetCacheName(modName, modInfo);
            string fullName = null;
            string extractDirectoryName = "temp/extract/";
            string[] dirFiles = Directory.GetFiles("downloads");
            string fileHash = CkanUtils.GetModHash(modName, modInfo);
            foreach (string fileName in dirFiles)
            {
                if (Path.GetFileName(fileName).StartsWith(fileHash))
                {
                    fullName = fileName;
                    break;
                }
            }
            if (fullName == null)
            {
                Console.WriteLine("Checking files FAILED, No zip file!");
                return false;
            }
            if (Directory.Exists(extractDirectoryName))
            {
                Directory.Delete(extractDirectoryName, true);
            }
            Directory.CreateDirectory(extractDirectoryName);
            ZipFile.ExtractToDirectory(fullName, extractDirectoryName);
            string gamedataDir = workarounds.customRootFolders.ContainsKey(modName) ? workarounds.customRootFolders[modName] : CkanUtils.GetGameDataDir(fullName, modInfo);
            if (gamedataDir == null)
            {
                Console.WriteLine("GameData Directory was not found!");
                return false;
            }

            bool ok = CheckDirectory(modName, "temp/extract/" + gamedataDir, "/");
            Console.WriteLine("Checking done!");
            return ok;
        }
Exemplo n.º 6
0
 public static Dictionary<string, ModInfo> GetSingleModInfo(string KSP_VERSION, JToken registry, string modName, string modVersion)
 {
     Dictionary<string, ModInfo> modInfo = new Dictionary<string, ModInfo>();
     JObject mod = (JObject)registry["available_modules"][modName];
     if (mod == null)
     {
         return modInfo;
     }
     bool versionOk = false;
     foreach (JProperty versionProperty in mod["module_version"])
     {
         JObject versionKeys = (JObject)versionProperty.Value;
         ModInfo mi = new ModInfo();
         mi.version = (string)versionKeys["version"];
         mi.downloadUrl = (string)versionKeys["download"];
         JToken installs = versionKeys["install"];
         if (installs.Type != JTokenType.Null)
         {
             foreach (JObject jobj in (JArray)installs)
             {
                 string file = (string)jobj["file"];
                 string installs_to = (string)jobj["install_to"];
                 mi.installs.Add(new KeyValuePair<string,string>(file, installs_to));
             }
         }
         string ksp_version = (string)versionKeys["ksp_version"];
         string ksp_version_min = (string)versionKeys["ksp_version"];
         string ksp_version_max = (string)versionKeys["ksp_version"];
         versionOk = (ksp_version == KSP_VERSION) || VersionCompatible(KSP_VERSION, ksp_version_min, ksp_version_max);
         if (versionOk && (modVersion == null || mi.version == modVersion))
         {
             modInfo.Add(modName, mi);
             return modInfo;
         }
     }
     return modInfo;
 }