Exemple #1
0
        private async void DownloadProgressPlus()
        {
            this.download = tools.GetMissingAsset(Version);
            if (download.Length > 900)
            {
                assetDownloadPlus.StartDownload();
                await Task.Factory.StartNew(() =>
                {
                    while (!assetDownloadPlus.GetEndDownload())
                    {
                        Speed    = assetDownloadPlus.Speed;
                        Progress = assetDownloadPlus.Progress / 2;
                        Thread.Sleep(2000);
                    }
                });

                Unzip  unzip = new Unzip();
                string Out   = "";
                unzip.UnZipFile(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncherDownload\Asset\Assets.zip", System.Directory.GetCurrentDirectory() + @"\.minecraft\assets\", out Out);
                Thread.Sleep(4000);
            }
            Console.WriteLine("pass");
            tools.DownloadSourceInitialization(DownloadSource.MCBBSSource);
            Progress        = 50;
            DuckEndDownload = 0;
            download        = tools.GetMissingAsset(Version);
            EndDownload     = tools.GetAllTheAsset(Version).Length - download.Length;
            for (int i = 0; i < Threads.Length; i++)
            {
                Threads[i] = Task.Run(DownloadProgress);
                // Threads[i].Start();//启动线程
            }
        }
        public async Task BeginInstall(ProgressCallback monitor, CancellationToken cancellationToken)
        {
            CommonInstaller.IsInstal = true;
            string installerName = Path.GetFileNameWithoutExtension(InstallerPath);
            string tempPath      = string.Format("{0}\\{1}Temp", PathManager.TempDirectory, installerName);

            if (Directory.Exists(tempPath))
            {
                Directory.Delete(tempPath, true);
            }
            Directory.CreateDirectory(tempPath);
            Unzip.UnZipFile(InstallerPath, tempPath);
            string  mainJson = File.ReadAllText(tempPath + "\\install_profile.json");
            JObject jObject  = JObject.Parse(mainJson);

            if (jObject.ContainsKey("install") && jObject.ContainsKey("versionInfo"))
            {
                CommonInstaller commonInstaller = new CommonInstaller(InstallerPath, Options);
                await commonInstaller.BeginInstallFromJObject(monitor, cancellationToken, jObject, tempPath);
            }
            else if (jObject.ContainsKey("data") && jObject.ContainsKey("processors") && jObject.ContainsKey("libraries"))
            {
                DataProcessorsForgeInstaller forgeInstaller = new DataProcessorsForgeInstaller(InstallerPath, Options);
                await forgeInstaller.BeginInstallFromJObject(monitor, cancellationToken, jObject, tempPath);
            }
            else
            {
                throw new JsonException("JSON has no matching format");
            }

            Directory.Delete(tempPath, true);
            File.Delete(InstallerPath);
            CommonInstaller.IsInstal = false;
        }
Exemple #3
0
        public async Task BuildAssetDownload(int NumThreads, string version)
        {
            _NumThreads = NumThreads;
            _version    = version;
            if (!_disposed)
            {
                AllFile   = new Tools().GetAllTheAsset(version).Length;
                _disposed = true;
            }
            if (FinishFile == AllFile)
            {
                return;
            }
            string Path = System.IO.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\Asset\";

            if (File.Exists(Path + @"\ConsoleApp15.exe"))
            {
                process.StartInfo.FileName = "cmd.exe";
                string Arguments = Path + @"ConsoleApp15.exe " + string.Format("{0} {1} {2}", version, NumThreads, System.Directory.GetCurrentDirectory());
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.RedirectStandardInput  = true;
                process.StartInfo.CreateNoWindow         = false;
                process.Start();
                process.StandardInput.WriteLine(Arguments + "&exit");
                process.StandardInput.AutoFlush = true;
                process.StandardInput.Close();
                Thread thread = new Thread(Process_OutputDataReceived);
                thread.Start();
                await Task.Run(() =>
                {
                    while (true)
                    {
                        if (FinishFile == AllFile)
                        {
                            return;
                        }
                        Thread.Sleep(2000);
                    }
                });
            }

            GacDownload gac = new GacDownload();

            gac.Download(Path + "yq.zip", "http://www.baibaoblog.cn:81/Asset/Asset.zip");
            while (gac.Complete != 1)
            {
                Thread.Sleep(500);
            }
            if (File.Exists(Path + "yq.zip"))
            {
                Unzip  unzip = new Unzip();
                string a     = "";
                unzip.UnZipFile(Path + "yq.zip", Path, out a);
                BuildAssetDownload(NumThreads, version);
            }
        }
Exemple #4
0
        public void BeginInstall()
        {
            string gameRootPath = ((CommonInstallOptions)Options).GameRootPath;
            string tempPath     = PathManager.TempDirectory + "\\CommonInstallerTemp";

            if (Directory.Exists(tempPath))
            {
                Directory.Delete(tempPath, true);
            }
            Directory.CreateDirectory(tempPath);
            Unzip.UnZipFile(InstallerPath, tempPath);
            string mainJson = File.ReadAllText(tempPath + "\\install_profile.json");
            var    jsonObj  = JsonConvert.DeserializeObject <CommonJsonObj>(mainJson);

            var    t          = jsonObj.Install.Path.Split(':');
            var    libPackage = t[0];
            var    libName    = t[1];
            var    libVersion = t[2];
            string libPath    = string.Format(@"{0}\libraries\{1}\{2}\{3}\{2}-{3}.jar",
                                              gameRootPath, libPackage.Replace(".", @"\"), libName, libVersion);

            string libDir = Path.GetDirectoryName(libPath);

            if (!Directory.Exists(libDir))
            {
                Directory.CreateDirectory(libDir);
            }
            File.Copy(tempPath + '\\' + jsonObj.Install.FilePath, libPath, true);


            string newPath = PathManager.GetJsonPath(gameRootPath, jsonObj.Install.Target);
            string newDir  = Path.GetDirectoryName(newPath);
            string jarPath = PathManager.GetJarPath(gameRootPath, jsonObj.Install.Target);

            if (!Directory.Exists(newDir))
            {
                Directory.CreateDirectory(newDir);
            }
            File.WriteAllText(newPath, jsonObj.VersionInfo.ToString());
            File.Copy(tempPath + '\\' + jsonObj.Install.FilePath, jarPath, true);

            Directory.Delete(tempPath, true);
            File.Delete(InstallerPath);
        }
        public async Task BeginInstall(ProgressCallback callback, CancellationToken cancellationToken)
        {
            IsInstal = true;
            string installerName = Path.GetFileNameWithoutExtension(InstallerPath);
            string tempPath      = string.Format("{0}\\{1}Temp", PathManager.TempDirectory, installerName);

            if (Directory.Exists(tempPath))
            {
                Directory.Delete(tempPath, true);
            }
            Directory.CreateDirectory(tempPath);
            Unzip.UnZipFile(InstallerPath, tempPath);
            string  mainJson = File.ReadAllText(tempPath + "\\install_profile.json");
            JObject jObject  = JObject.Parse(mainJson);

            await BeginInstallFromJObject(callback, cancellationToken, jObject, tempPath);

            Directory.Delete(tempPath, true);
            File.Delete(InstallerPath);
            IsInstal = false;
        }
Exemple #6
0
        private LaunchResult Launch(LaunchSetting setting)
        {
            try
            {
                if (setting.AuthenticateAccessToken == null || setting.AuthenticateUUID == null)
                {
                    return(new LaunchResult(new ArgumentException("启动所需必要的验证参数为空")));
                }
                if (setting.Version == null)
                {
                    return(new LaunchResult(new ArgumentException("启动所需必要的版本参数为空")));
                }

                if (setting.MaxMemory == 0)
                {
                    setting.MaxMemory = SystemTools.GetBestMemory(this.Java);
                }

                Stopwatch sw = new Stopwatch();
                sw.Start();

                string arg = argumentsParser.Parse(setting);

                #region 处理库文件
                foreach (var item in setting.Version.Natives)
                {
                    string nativePath = GetNativePath(item);
                    if (File.Exists(nativePath))
                    {
                        App.logHandler.AppendDebug(string.Format("检查并解压不存在的库文件:{0}", nativePath));
                        Unzip.UnZipFile(nativePath, GetGameVersionRootDir(setting.Version) + @"\$natives", item.Exclude);
                    }
                    else
                    {
                        return(new LaunchResult(new NativeNotFoundException(item, nativePath)));
                    }
                }
                #endregion

                ProcessStartInfo startInfo = new ProcessStartInfo(Java.Path, arg)
                {
                    RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false, WorkingDirectory = GetGameVersionRootDir(setting.Version)
                };
                var process = Process.Start(startInfo);
                sw.Stop();
                App.logHandler.AppendInfo(string.Format("成功启动游戏进程,总共用时:{0}ms", sw.ElapsedMilliseconds));

                Task.Factory.StartNew(() =>
                {
                    process.WaitForExit();
                    App.logHandler.AppendInfo("游戏进程退出,代码:" + process.ExitCode);
                    GameExit?.Invoke(this, process.ExitCode);
                });

                process.OutputDataReceived += Process_OutputDataReceived;
                process.ErrorDataReceived  += Process_ErrorDataReceived;
                process.BeginErrorReadLine();
                process.BeginOutputReadLine();

                #region 配置文件
                App.config.MainConfig.History.LastLaunchUsingMs = sw.ElapsedMilliseconds;
                App.config.MainConfig.History.LastLaunchTime    = DateTime.Now;
                App.config.MainConfig.History.LastLaunchVersion = setting.Version.ID;
                App.config.Save();
                #endregion

                return(new LaunchResult()
                {
                    Process = process, IsSuccess = true, LaunchArguments = arg
                });
            }
            catch (LaunchException.LaunchException ex)
            {
                return(new LaunchResult(ex));
            }
            catch (Exception ex)
            {
                return(new LaunchResult(ex));
            }
        }
Exemple #7
0
        public Exception Process(string temp, string gamerootPath, string minecraft, Java java)
        {
            try
            {
                int progress = 1;
                Dictionary <string, string> originalData = Profile.GetData(IsClient);
                if (originalData.Count != 0)
                {
                    Monitor.SetTotalSize(originalData.Count);

                    foreach (var item in originalData)
                    {
                        Monitor.IncreaseDoneSize(progress++);

                        if (item.Value[0] == '[' && item.Value[item.Value.Length - 1] == ']')
                        { //Artifact
                            Data.Add(item.Key, GetArtifactPath(gamerootPath, item.Value.Substring(1, item.Value.Length - 2)));
                        }
                        else if (item.Value[0] == '\'' && item.Value[item.Value.Length - 1] == '\'')
                        { //Literal
                            Data.Add(item.Key, item.Value.Substring(1, item.Value.Length - 2));
                        }
                        else
                        {
                            string target = temp + item.Value;
                            Monitor.SetState(string.Format("Extracting:{0}", item.Value));
                            Data.Add(item.Key, target);
                        }
                    }
                }
                Data.Add("SIDE", IsClient ? "client" : "server");
                Data.Add("MINECRAFT_JAR", minecraft);

                Monitor.SetTotalSize(Processors.Count);
                Monitor.SetDoneSize(0);
                Monitor.SetState("Building Processors");

                foreach (var proc in Processors)
                {
                    string jarPath = GetArtifactPath(gamerootPath, proc.Jar);
                    if (!File.Exists(jarPath))
                    {
                        return(new FileNotFoundException("Jar file can not found", jarPath));
                    }

                    string jarTemp = Path.GetDirectoryName(jarPath);
                    Unzip.UnZipFile(jarPath, jarTemp);

                    string MetaPath = jarTemp + @"\META-INF\MANIFEST.MF";
                    if (!File.Exists(MetaPath))
                    {
                        return(new FileNotFoundException("META-INF file can not found", MetaPath));
                    }

                    string metaContent = File.ReadAllText(MetaPath);
                    string mainClass   = Regex.Match(metaContent, @"(?M)^Main-Class: (.*)$").Groups[1].Value.Trim();

                    StringBuilder argBuilder = new StringBuilder();

                    argBuilder.Append("-cp \"");
                    foreach (var item in proc.ClassPath)
                    {
                        argBuilder.Append(GetArtifactPath(gamerootPath, item)).Append(';');
                    }
                    argBuilder.Append(jarPath).Append("\" ");

                    argBuilder.Append(mainClass).Append(' ');

                    foreach (var item in proc.Args)
                    {
                        char start = item[0];
                        char end   = item[item.Length - 1];

                        if (start == '[' && end == ']') //Library
                        {
                            argBuilder.Append("\"").Append(GetArtifactPath(gamerootPath, item.Substring(1, item.Length - 2))).Append("\" ");
                        }
                        else if (start == '{' && end == '}')
                        { // Data
                            string key   = item.Substring(1, item.Length - 2);
                            string value = Data[key];
                            if (value != null)
                            {
                                argBuilder.Append("\"").Append(value).Append("\" ");
                            }
                        }
                        else
                        {
                            argBuilder.Append(item).Append(' ');
                        }
                    }

                    ProcessStartInfo processStartInfo = new ProcessStartInfo(java.Path, argBuilder.ToString())
                    {
                        RedirectStandardOutput = true,
                        UseShellExecute        = false
                    };
                    Monitor.SetState(string.Format("执行安装器{0}", proc.Jar.Name));
                    var result = System.Diagnostics.Process.Start(processStartInfo);
                    result.BeginOutputReadLine();
                    result.OutputDataReceived += Result_OutputDataReceived;
                    result.WaitForExit();

                    Monitor.IncreaseDoneSize(1);
                }
                Monitor.SetDone();
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(e);
            }
        }
Exemple #8
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\"");
        }