Пример #1
0
        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安装器成功安装");
            }
        }
Пример #2
0
        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安装器成功安装");
            }
        }