internal void libraries(ForgeJson.Root json)
        {
            int num = 0;
            List <Minecraft.MCDownload> download = new List <Minecraft.MCDownload>();

            foreach (ForgeJson.LibrariesItem item in json.libraries)
            {
                if (!(item.downloads.artifact.url == "") && (this.SLC.FileExist(System.Directory.GetCurrentDirectory() + @"\.minecraft\libraries\" + item.downloads.artifact.path.Replace('/', '\\')) != null))
                {
                    num++;
                    Minecraft.MCDownload download1 = new Minecraft.MCDownload();
                    download1.path = System.Directory.GetCurrentDirectory() + @"\.minecraft\libraries\" + item.downloads.artifact.path.Replace('/', '\\');
                    download1.Url  = item.downloads.artifact.url.Replace("https://files.minecraftforge.net/maven/", "https://bmclapi2.bangbang93.com/maven/");
                    download.Add(download1);
                }
            }

            ForgeDownload forgedownload = new ForgeDownload(5, download.ToArray());

            forgedownload.StartDownload();
            bool flag = true;

            while (flag)
            {
                if (forgedownload.error > 0)
                {
                    throw new SquareMinecraftLauncherException("安装失败");
                }
                else if (forgedownload.GetEndDownload())
                {
                    flag = false;
                }
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 2
0
        internal async Task <string> liteloaderJsonY(ForgeY.Root versionText, string type, string patch, string version, string filename, string javaPath)
        {
            string[] textArray1 = new string[] { "\"assetIndex\": {\"id\": \"", versionText.assetIndex.id, "\",\"size\":", versionText.assetIndex.size, ",\"url\": \"", versionText.assetIndex.url, "\"},\"assets\": \"", versionText.assets, "\",\"downloads\": {\"client\": {\"url\":\"", versionText.downloads.client.url, "\"}},\"id\": \"", versionText.id, "\",\"libraries\": [" };
            string   str        = string.Concat(textArray1);

            ForgeY.Artifact  artifact  = new ForgeY.Artifact();
            ForgeY.Downloads downloads = new ForgeY.Downloads();
            var DO = Minecraft.DownloadOptifine(version, filename);

            ForgeY.LibrariesItem item = new ForgeY.LibrariesItem();
            item.name          = DO.name;
            artifact.url       = DO.Url;
            downloads.artifact = artifact;
            item.downloads     = downloads;
            versionText.libraries.Add(item);
            ForgeDownload forgeDownload = new ForgeDownload(new MCDownload[] { new MCDownload()
                                                                               {
                                                                                   Url = DO.Url, path = DO.path
                                                                               } });

            forgeDownload.StartDownload();
            await Task.Run(() =>
            {
                while (!forgeDownload.GetEndDownload())
                {
                    Thread.Sleep(2000);
                }
            });

            if (forgeDownload.error != 0)
            {
                throw new SquareMinecraftLauncherException("安装失败,下载optifine失败");
            }
            Unzip  unzip = new Unzip();
            string err;

            unzip.UnZipFile(DO.path, System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\OptiFine\", out err);
            if (File.Exists(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\OptiFine\launchwrapper-of.txt"))
            {
                string launch = File.ReadAllText(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\OptiFine\launchwrapper-of.txt");
                SLC.path(System.Directory.GetCurrentDirectory() + @"\.minecraft\libraries\optifine\launchwrapper-of\" + launch);
                File.Copy(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\OptiFine\launchwrapper-of-" + launch + ".jar", System.Directory.GetCurrentDirectory() + @"\.minecraft\libraries\optifine\launchwrapper-of\" + launch + @"\launchwrapper-of-" + launch + ".jar");
                ForgeY.LibrariesItem item2      = new ForgeY.LibrariesItem();
                ForgeY.Artifact      artifact2  = new ForgeY.Artifact();
                ForgeY.Downloads     downloads2 = new ForgeY.Downloads();
                item2.name          = "optifine:launchwrapper-of:" + launch;
                artifact2.url       = DO.Url;
                downloads2.artifact = artifact2;
                item2.downloads     = downloads2;
                versionText.libraries.Add(item2);
            }
            else
            {
                if (!tools.ForgeExist(version))
                {
                    ForgeY.LibrariesItem item2      = new ForgeY.LibrariesItem();
                    ForgeY.Artifact      artifact2  = new ForgeY.Artifact();
                    ForgeY.Downloads     downloads2 = new ForgeY.Downloads();
                    item2.name          = "net.minecraft:launchwrapper:1.12";
                    artifact2.url       = "http://files.minecraftforge.net/maven/";
                    downloads2.artifact = artifact2;
                    item2.downloads     = downloads2;
                    versionText.libraries.Add(item2);
                }
            }
            if (File.Exists(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\OptiFine\optifine\Patcher.class"))
            {
                SLC.path(System.Directory.GetCurrentDirectory() + @"\.minecraft\libraries\optifine\OptiFine\" + DO.name.Split(':')[2]);
                string  arg     = "-cp \"" + DO.path + "\" optifine.Patcher " + System.Directory.GetCurrentDirectory() + @"\.minecraft\versions\" + version + @"\" + version + ".jar " + DO.path + " " + System.Directory.GetCurrentDirectory() + @"\.minecraft\libraries\optifine\OptiFine\" + DO.name.Split(':')[2] + @"\" + DO.name.Split(':')[2] + ".jar";
                Process process = Process.Start(javaPath, arg);
                await Task.Run(() => { process.WaitForExit(); });

                process.Close();
            }
            else
            {
                throw new SquareMinecraftLauncherException("安装失败,OptiFine存在问题");
            }
            SLC.DelPathOrFile(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\OptiFine\");
            for (int i = 0; versionText.libraries.ToArray().Length > i; i++)
            {
                str = str + "{\"name\":\"" + versionText.libraries[i].name + "\",";
                if ((versionText.libraries[i].downloads == null) || (versionText.libraries[i].downloads.artifact == null))
                {
                    str = str.Substring(0, str.Length - 1);
                }
                else
                {
                    str = str + "\"downloads\":{\"artifact\":{\"url\":\"" + versionText.libraries[i].downloads.artifact.url + "\"}}";
                }
                if (versionText.libraries[i].natives != null)
                {
                    str = str + ",\"natives\": {";
                    string str2 = null;
                    if (versionText.libraries[i].natives.linux != null)
                    {
                        if (str2 != null)
                        {
                            str2 = str2 + ",";
                        }
                        str2 = str2 + "\"linux\": \"natives - linux\"";
                    }
                    if (versionText.libraries[i].natives.osx != null)
                    {
                        if (str2 != null)
                        {
                            str2 = str2 + ",";
                        }
                        str2 = str2 + "\"osx\": \"natives - osx\"";
                    }
                    if (versionText.libraries[i].natives.windows != null)
                    {
                        if (str2 != null)
                        {
                            str2 = str2 + ",";
                        }
                        str2 = str2 + "\"windows\": \"" + versionText.libraries[i].natives.windows + "\"";
                    }
                    str = str + str2 + "}},";
                }
                else
                {
                    str = str + "},";
                }
                if (i == (versionText.libraries.ToArray().Length - 1))
                {
                    char[] chArray1 = str.ToCharArray();
                    chArray1[chArray1.Length - 1] = ']';
                    str = null;
                    foreach (char ch in chArray1)
                    {
                        str = str + ch.ToString();
                    }
                }
            }
            return(str + ",\"mainClass\": \"net.minecraft.launchwrapper.Launch\"");
        }