private void InstallForge(ForgeVersion forgeVersion, string installerPath) { //将installer中的forge universal提取出来 var tempDir = Path.Combine(Path.GetTempPath(), "BMCL\\ForgeInstaller"); if (Directory.Exists(tempDir)) { Directory.Delete(tempDir, true); } var archive = new ZipArchive(new FileStream(installerPath, FileMode.Open)); archive.ExtractToDirectory(tempDir); //获得universal的完整名称 var tempFolder = new DirectoryInfo(tempDir); if (!tempFolder.Exists) { tempFolder.Create(); } var tempFiles = tempFolder.GetFiles("*.jar"); if (tempFiles.Length == 0) //除非下载过来的内容错误,不然installer中一定包含universal { throw new Exception("cannot find universal.jar"); } var forge = tempFiles[0].Name; archive.Dispose(); //再从universal中提出version.json archive = new ZipArchive(new FileStream(tempDir + "\\" + forge, FileMode.Open)); archive.GetEntry("version.json").ExtractToFile(Path.Combine(tempDir, "version.json")); //从version.json中获得目标游戏版本名,并在versions文件夹中创建 var forge0 = gameinfo.Read(tempDir + "\\version.json").id; var versionFolder = BmclCore.BaseDirectory + ".minecraft\\versions\\" + forge0; Directory.CreateDirectory(versionFolder); //复制json与核心文件 File.Copy(tempDir + "\\version.json", versionFolder + "\\" + forgeVersion.GetMc() + "-" + forge0 + ".json"); File.Copy(versionFolder + "\\..\\" + forgeVersion.GetMc() + "\\" + forgeVersion.GetMc() + ".jar", versionFolder + "\\" + forge0 + ".jar"); //复制forge到libraries中 forge0 = Regex.Replace(forge0.ToLower(), forgeVersion.GetMc() + "-forge", ""); var forgeFolder = BmclCore.BaseDirectory + ".minecraft\\libraries\\net\\minecraftforge\\forge\\" + forge0; Directory.CreateDirectory(forgeFolder); File.Copy(tempDir + "\\" + forge, forgeFolder + "\\forge-" + forge0 + ".jar"); archive.Dispose(); Directory.Delete(tempDir, true); }
public bool InstallForge(ForgeVersion forgeVersion) { //将installer中的forge universal提取出来 string tempDir = Path.Combine(BmclCore.BaseDirectory, "temp"); var archive = new ZipArchive(new FileStream(Path.Combine(BmclCore.BaseDirectory, "forge.jar"), FileMode.Open)); archive.ExtractToDirectory(tempDir); //获得universal的完整名称 DirectoryInfo tempFolder = new DirectoryInfo(tempDir); FileInfo[] tempFiles = tempFolder.GetFiles("*.jar"); if (tempFiles.Length == 0)//除非下载过来的内容错误,不然installer中一定包含universal { return(false); } string forge = tempFiles[0].Name; archive.Dispose(); //再从universal中提出version.json archive = new ZipArchive(new FileStream(tempDir + "\\" + forge, FileMode.Open)); archive.GetEntry("version.json").ExtractToFile(Path.Combine(tempDir, "version.json")); //从version.json中获得目标游戏版本名,并在versions文件夹中创建 string forge0 = gameinfo.Read(tempDir + "\\version.json").id; string versionFolder = BmclCore.BaseDirectory + ".minecraft\\versions\\" + forge0; Directory.CreateDirectory(versionFolder); //复制json与核心文件 File.Copy(tempDir + "\\version.json", versionFolder + "\\" + forgeVersion.GetMc() + "-" + forge0 + ".json"); File.Copy(versionFolder + "\\..\\" + forgeVersion.GetMc() + "\\" + forgeVersion.GetMc() + ".jar", versionFolder + "\\" + forge0 + ".jar"); //复制forge到libraries中 forge0 = Regex.Replace(forge0.ToLower(), forgeVersion.GetMc() + "-forge", ""); string forgeFolder = BmclCore.BaseDirectory + ".minecraft\\libraries\\net\\minecraftforge\\forge\\" + forge0; Directory.CreateDirectory(forgeFolder); File.Copy(tempDir + "\\" + forge, forgeFolder + "\\forge-" + forge0 + ".jar"); archive.Dispose(); Directory.Delete(tempDir, true); return(true); }
public async Task DownloadForge(ForgeVersion forgeVersion) { if (!Directory.Exists(BmclCore.BaseDirectory + ".minecraft\\versions\\" + forgeVersion.GetMc())) { MessageBox.Show("请先下载原版"); return; } var url = forgeVersion.GetDownloadUrl(); var downer = new Downloader.Downloader(); var w = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\.minecraft\\launcher_profiles.json"); w.Write(Resource.NormalProfile.Profile); w.Close(); await downer.DownloadFileTaskAsync(url, Path.Combine(BmclCore.BaseDirectory, "forge.jar")); var stat = false; try { stat = InstallForge(forgeVersion); } catch (Exception ex) { Logger.Fatal("内置forge安装器出错:" + ex.Message); } if (!stat) { Logger.Info("将使用传统forge安装器"); InstallForgeInOldWay(); } else { Logger.Info("已使用内置forge安装器成功安装"); } }
public async Task DownloadForge(ForgeVersion forgeVersion) { if (!Directory.Exists(BmclCore.BaseDirectory + ".minecraft\\versions\\" + forgeVersion.GetMc())) { MessageBox.Show("请先下载原版"); return; } ProcessChange("DownloadingForge"); var url = forgeVersion.GetDownloadUrl(); var downer = new Downloader.Downloader(); var w = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\.minecraft\\launcher_profiles.json"); w.Write(NormalProfile.Profile); w.Close(); var installerPath = Path.Combine(BmclCore.TempDirectory, "forge.jar"); await downer.DownloadFileTaskAsync(url, installerPath); ProcessChange("InstallingForge"); var v = int.Parse(forgeVersion.build.version.Split('.')[0]); try { if (v >= 25) { var installer = new ForgeInstaller(Path.Combine(BmclCore.MinecraftDirectory)); installer.ProgressChange += status => ProcessChange(status); await installer.Run(installerPath); } else { try { InstallForge(forgeVersion, installerPath); } catch (Exception ex) { Logger.Fatal(ex); } } } catch (Exception ex) { Logger.Fatal("内置forge安装器出错"); Logger.Fatal(ex); Logger.Info("将使用传统forge安装器"); await InstallForgeInOldWay(installerPath); Logger.Info("已使用传统forge安装器成功安装"); } }