public async Task <bool> Install(MCDownload download)
        {
            await Task.Factory.StartNew(() =>
            {
                System.IO.Directory.Move(download.path, Directory.GetCurrentDirectory() + @"\.minecraft\resourcepacks");
            });

            return(true);
        }
        public async Task <bool> Install(MCDownload download)
        {
            await Task.Factory.StartNew(() =>
            {
                System.IO.File.Move(download.path, Directory.GetCurrentDirectory() + @"\.minecraft\mods\" + System.IO.Path.GetFileName(download.path));
            });

            return(true);
        }
        public MCDownload download(GameVersionLatestFilesItem LatestFilesItem)
        {
            string     url      = Curseforge.download(LatestFilesItem.projectFileId, LatestFilesItem.projectFileName);
            string     path     = Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncherDownload\" + LatestFilesItem.projectFileName;
            MCDownload download = new MCDownload();

            download.Url  = url;
            download.path = path;
            return(download);
        }
示例#4
0
        private async void DownloadProgress()
        {
            List <downloader> files = new List <downloader>();

            for (int i = 0; i < 5; i++)
            {
                MCDownload download = AssignedDownload();
                if (download != null)
                {
                    downloader fileDownloader = new downloader();
                    fileDownloader.BuildDownload(download.Url, download.path);
                    fileDownloader.StartDownload();
                    files.Add(fileDownloader);
                }
            }
            if (files.Count == 0)
            {
                Progress        = 100;
                DuckEndDownload = download.Length;
                return;
            }
            await Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    int end = 0;
                    for (int i = 0; i < files.Count; i++)
                    {
                        Speed += files[i].intermation.Speed;
                        if (files[i].intermation.StatusId == -1)
                        {
                            end++;
                        }
                        if (files[i].intermation.Progress == 100)
                        {
                            end++;
                        }
                    }

                    if (end >= files.Count)
                    {
                        DuckEndDownload += files.Count;
                        EndDownload     += files.Count;
                        Speed            = 1;
                        Progress        += 50 / (double)(download.Length) * files.Count;
                        DownloadProgress();//递归

                        return;
                    }
                    Thread.Sleep(200);
                }
            });
        }
        public async Task <bool> Install(MCDownload download)
        {
            bool s = false;
            await Task.Factory.StartNew(() =>
            {
                string error = "";
                if (new Unzip().UnZipFile(download.path, Directory.GetCurrentDirectory() + Directory.GetCurrentDirectory() + @"\.minecraft\saves\", out error))
                {
                    s = true;
                }
            });

            return(s);
        }
        public async Task <bool> Install(MCDownload download)
        {
            bool s = false;
            await Task.Factory.StartNew(() =>
            {
                string error = "";
                if (new Unzip().UnZipFile(download.path, Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\Modpack", out error))
                {
                    System.IO.Directory.Move(Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\Modpack\overrides", Directory.GetCurrentDirectory() + @"\.minecraft");
                    s = true;
                }
            });

            return(s);
        }
        /// <summary>
        /// 启动游戏
        /// </summary>
        /// <param name="version">版本</param>
        /// <param name="java">java</param>
        /// <param name="RAM">虚拟内存</param>
        /// <param name="name">游戏名</param>
        /// <param name="uuid">uuid</param>
        /// <param name="token">token</param>
        /// <param name="JVMparameter">前置参数</param>
        /// <param name="RearParameter">后置参数</param>
        public async Task StartGame(string version, string java, int RAM, string name, string uuid, string token, string JVMparameter, string RearParameter)
        {
            if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(java) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(uuid) || string.IsNullOrEmpty(token) || RAM == 0)
            {
                throw new SquareMinecraftLauncherException("任何一项都不能为空");
            }
            string Game  = null;
            Tools  tools = new Tools();

            if (SLC.FileExist(System.Directory.GetCurrentDirectory() + @"\.minecraft\versions\" + version + @"\" + version + ".jar") != null)
            {
                throw new SquareMinecraftLauncherException("启动失败,未找到该版本");
            }
            //download[] MLib = tools.GetMissingLibrary(version);
            //if (MLib.Length != 0)
            //{
            //    throw new SquareMinecraftLauncherException("缺少Libraries文件");
            //}
            MCDownload[] natives1 = new MCDownload[0];
            MCDownload[] natives  = tools.GetMissingNatives(version);
            if (natives.Length == 0)
            {
                natives1 = tools.GetAllNatives(version);
                if (natives1.Length == 0)
                {
                    throw new SquareMinecraftLauncherException("Natives获取失败,请检查文件是否完整");
                }
                string nativespath = SLC.nativeszip(version);
                if (SLC.FileExist(java) != "")
                {
                    string bx = "-Dminecraft.client.jar=" + System.Directory.GetCurrentDirectory() + @"\.minecraft\versions\" + version + @"\" + version + ".jar" + " -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=16M -XX:-UseAdaptiveSizePolicy -XX:-OmitStackTraceInFastThrow -Xmn512m -Xmx" + RAM + "m -Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump ";
                    if (JVMparameter == "" || JVMparameter == null)
                    {
                        Game = bx + "-Djava.library.path=\"" + nativespath + "\" -cp ";
                    }
                    else
                    {
                        Game = bx + JVMparameter + " -Djava.library.path=\"" + nativespath + "\" -cp ";
                    }
                    MCDownload[] Lib     = tools.GetAllLibrary(version);
                    string       Libname = "\"";
                    foreach (var Libname1 in Lib)
                    {
                        Libname += Libname1.path + ";";
                    }
                    Game += Libname + System.Directory.GetCurrentDirectory() + @"\.minecraft\versions\" + version + @"\" + version + ".jar\"";
                    var      jo = SLC.versionjson <main.mainclass>(version);
                    string[] mA = null;
                    if (jo.minecraftArguments != null)
                    {
                        mA = jo.minecraftArguments.Split(' ');
                    }
                    else
                    {
                        StreamReader sr;
                        try
                        {
                            sr = new StreamReader(System.Directory.GetCurrentDirectory() + @"\.minecraft\versions\" + version + @"\" + version + ".json", Encoding.Default);
                        }
                        catch (System.IO.DirectoryNotFoundException ex)
                        {
                            throw new SquareMinecraftLauncherException("未找到该版本");
                        }
                        var           c   = (JObject)JsonConvert.DeserializeObject(sr.ReadToEnd());
                        List <string> jo3 = new List <string>();
                        for (int i = 1; c["arguments"]["game"].ToArray().Length - 1 > 0; i += 2)
                        {
                            try
                            {
                                c["arguments"]["game"][i].ToString();
                                if (c["arguments"]["game"][i - 1].ToString()[0] == '-' || c["arguments"]["game"][i].ToString()[0] == '$')
                                {
                                    jo3.Add(c["arguments"]["game"][i - 1].ToString());
                                    jo3.Add(c["arguments"]["game"][i].ToString());
                                }
                            }
                            catch (Exception ex)
                            {
                                break;
                            }
                        }
                        string[] arg = jo3.ToArray();
                        string   a   = arg[0] + " " + arg[1];
                        for (int i = 2; i < arg.Length; i += 2)
                        {
                            a += " " + arg[i] + " " + arg[i + 1];
                        }
                        mA = a.Split(' ');
                    }
                    var    jo2  = SLC.versionjson <json4.Root>(version);
                    string main = " --width 854 --height 480";
                    for (int i = 0; mA.Length > i; i += 2)
                    {
                        switch (mA[i])
                        {
                        case "--username":
                            main += " " + mA[i] + " \"" + name + "\"";
                            break;

                        case "--version":
                            main += " " + mA[i] + " \"" + jo2.id + "\"";
                            break;

                        case "--gameDir":
                            main += " " + mA[i] + " \"" + System.Directory.GetCurrentDirectory() + @"\.minecraft" + "\"";
                            break;

                        case "--assetsDir":
                            main += " " + mA[i] + " \"" + System.Directory.GetCurrentDirectory() + @"\.minecraft\assets" + "\"";
                            break;

                        case "--assetIndex":
                            main += " " + mA[i] + " " + jo2.assets;
                            break;

                        case "--uuid":
                            main += " " + mA[i] + " " + uuid;
                            break;

                        case "--accessToken":
                            main += " " + mA[i] + " " + token;
                            break;

                        case "--userType":
                            main += " " + mA[i] + " " + "Legacy";
                            break;

                        case "--versionType":
                            main += " " + mA[i] + " " + "\"SquareMinecraftLauncher - BaiBao\"";
                            break;

                        case "--userProperties":
                            main += " " + mA[i] + " " + "{}";
                            break;

                        default:
                            main += " " + mA[i] + " " + mA[i + 1];
                            break;
                        }
                    }
                    if ((RearParameter == "") || (RearParameter == null))
                    {
                        Game = Game + " " + jo.mainClass + main;
                    }
                    else
                    {
                        string[] textArray14 = new string[] { Game, " ", jo.mainClass, main, " ", RearParameter };
                        Game = string.Concat(textArray14);
                    }
                    Console.WriteLine("\n\n\n\n\n\n" + Game);
                    this.start.FileName               = java;
                    this.start.Arguments              = Game;
                    this.start.CreateNoWindow         = true;
                    this.start.RedirectStandardOutput = true;
                    this.start.RedirectStandardInput  = true;
                    this.start.UseShellExecute        = false;
                    this.start.RedirectStandardError  = true;
                    Thread thread1 = new Thread(new ThreadStart(this.monitoring))
                    {
                        IsBackground = true
                    };
                    Thread thread2 = new Thread(new ThreadStart(this.errormonitoring))
                    {
                        IsBackground = true
                    };
                    this.process = Process.Start(this.start);
                    thread2.Start();
                    thread1.Start();
                    try
                    {
                        await Task.Factory.StartNew(() =>
                        {
                            if (process.WaitForInputIdle())
                            {
                                return;
                            }
                        });
                    }
                    catch (Exception ex)
                    {
                        throw new SquareMinecraftLauncherException("等待时发生异常:" + ex.Message);
                    }
                }
            }
        }