private async void LauncherOnGameStart(object sender, VersionInfo versionInfo) { _assetManager = new AssetManager(versionInfo); await _assetManager.Sync(); //TODO 弹窗 BmclCore.Notify("资源文件同步完成"); }
protected void OnLoginFinishEvent(LoginInfo logininfo) { LoginFinishEventHandler handler = LoginFinishEvent; if (handler != null) { BmclCore.Invoke(new Action(() => handler(logininfo))); } }
private void OnStateChangeEvent(string state) { var handler = StateChangeEvent; if (handler != null) { BmclCore.Invoke(new Action(() => handler(state))); } }
private void OnGameStartUp(bool success) { GameStartUpEventHandler handler = GameStartUp; if (handler != null) { BmclCore.Invoke(new Action(() => handler(success))); } }
private static void OnImportProgressChangeEvent(string status) { ImportProgressChangeEventHandler handler = ImportProgressChangeEvent; if (handler != null) { BmclCore.Invoke(handler, new[] { status }); } }
private static void OnImportFinish() { ImportFinishEventHandler handler = ImportFinish; if (handler != null) { BmclCore.Invoke(handler); } }
public FrmMain() { BmclCore.NIcon.MainWindow = this; BmclCore.MainWindow = this; InitializeComponent(); Title = "BMCL Ver." + BmclCore.BmclVersion; LoadConfig(); GridGame.ReFlushlistver(); GridGame.listVer.SelectedItem = BmclCore.Config.LastPlayVer; BmclCore.SingleInstance(this); }
private void btnClose_Click(object sender, RoutedEventArgs e) { if (BmclCore.GameManager.IsGameRunning) { btnMiniSize_Click(null, null); } else { Logger.Log($"BMCL V2 Ver.{BmclCore.BmclVersion} 正在退出"); BmclCore.Halt(); } }
private void btnClose_Click(object sender, RoutedEventArgs e) { if (BmclCore.Game != null) { if (BmclCore.Game.IsRunning()) { this.btnMiniSize_Click(null, null); return; } } Logger.Log($"BMCL V2 Ver.{BmclCore.BmclVersion} 正在退出"); BmclCore.Halt(); }
private void DownloadForge(string ver) { if (!_forgeVer.ForgeDownloadUrl.ContainsKey(ver)) { MessageBox.Show(LangManager.GetLangFromResource("ForgeDoNotSupportInstaller")); return; } BmclCore.Invoke(new Action(() => BmclCore.MainWindow.SwitchDownloadGrid(Visibility.Visible))); var url = new Uri(_forgeVer.ForgeDownloadUrl[ver]); var downer = new WebClient(); downer.Headers.Add("User-Agent", "BMCL" + BmclCore.BmclVersion); downer.DownloadProgressChanged += downer_DownloadProgressChanged; downer.DownloadFileCompleted += downer_DownloadForgeCompleted; _downedtime = Environment.TickCount - 1; _downed = 0; var w = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\.minecraft\\launcher_profiles.json"); w.Write(Resource.NormalProfile.Profile); w.Close(); downer.DownloadFileAsync(url, "forge.jar"); }
private void Run() { _game.StartInfo.UseShellExecute = false; OnStateChangeEvent(LangManager.GetLangFromResource("LauncherSettingupEnvoriement")); var arg = new StringBuilder("-Xincgc -Xmx"); arg.Append(_javaxmx); arg.Append("M "); arg.Append(Extarg); arg.Append(" "); arg.Append("-Djava.library.path=\""); arg.Append(Environment.CurrentDirectory).Append(@"\.minecraft\versions\"); arg.Append(_name).Append("\\").Append(_version).Append("-natives-").Append(_timestamp.ToString(CultureInfo.InvariantCulture)); arg.Append("\" -cp \""); foreach (Libraryies lib in _info.libraries) { if (lib.natives != null) { continue; } if (lib.rules != null) { bool goflag = false; foreach (rules rule in lib.rules) { if (rule.action == "disallow") { if (rule.os == null) { goflag = false; break; } if (rule.os.name.ToLower().Trim() == "windows") { goflag = false; break; } } { if (rule.os == null) { goflag = true; break; } if (rule.os.name.ToLower().Trim() == "windows") { goflag = true; break; } } } if (!goflag) { continue; } } OnStateChangeEvent(LangManager.GetLangFromResource("LauncherSolveLib") + lib.name); string libp = BuildLibPath(lib); if (GetFileLength(libp) == 0) { BMCLV4.Logger.Log("未找到依赖" + lib.name + "开始下载", BMCLV4.Logger.LogType.Error); try { if (lib.url == null) { OnStateChangeEvent(LangManager.GetLangFromResource("LauncherDownloadLib") + lib.name); Downloading++; if (!Directory.Exists(Path.GetDirectoryName(libp))) { Directory.CreateDirectory(Path.GetDirectoryName(libp)); } #if DEBUG System.Windows.MessageBox.Show(_urlLib + libp.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("\\", "/")); #endif BMCLV4.Logger.Log(_urlLib + libp.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("\\", "/")); _downer.DownloadFile( _urlLib + libp.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("/", "\\"), libp); } else { string urlLib = lib.url; OnStateChangeEvent(LangManager.GetLangFromResource("LauncherDownloadLib") + lib.name); Downloading++; /* * DownLib downer = new DownLib(lib); * downLibEvent(lib); * downer.DownFinEvent += downfin; * downer.startdownload(); */ if (!Directory.Exists(Path.GetDirectoryName(libp))) { Directory.CreateDirectory(Path.GetDirectoryName(libp)); } #if DEBUG System.Windows.MessageBox.Show(urlLib + libp.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("\\", "/")); #endif BMCLV4.Logger.Log(urlLib + libp.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("\\", "/")); _downer.DownloadFile(urlLib + libp.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("\\", "/"), libp); } } catch (WebException ex) { BMCLV4.Logger.Log(ex); BMCLV4.Logger.Log("原地址下载失败,尝试作者源" + lib.name); try { _downer.DownloadFile(DownloadSource.DownloadSourceManage.GetUrlFromResource("UrlDownloadBase") + "libraries/" + libp.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("/", "\\"), libp); } catch (WebException exception) { Libraryies lib1 = lib; BmclCore.Invoke(new Action(() => MessageBox.Show(BmclCore.MainWindow, "下载" + lib1.name + "遇到错误:" + exception.Message))); return; } } } arg.Append(BuildLibPath(lib) + ";"); } OnStateChangeEvent(LangManager.GetLangFromResource("LauncherBuildMCArg")); var mcpath = new StringBuilder(Environment.CurrentDirectory + @"\.minecraft\versions\"); mcpath.Append(_name).Append("\\").Append(_version).Append(".jar\" "); mcpath.Append(_info.mainClass); arg.Append(mcpath); //" --username ${auth_player_name} --session ${auth_session} --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}" var mcarg = new StringBuilder(_info.minecraftArguments); mcarg.Replace("${auth_player_name}", _username); mcarg.Replace("${version_name}", _version); mcarg.Replace("${game_directory}", @"."); mcarg.Replace("${game_assets}", @"assets"); mcarg.Replace("${assets_root}", @"assets"); mcarg.Replace("${user_type}", "Legacy"); mcarg.Replace("${assets_index_name}", _info.assets); if (!string.IsNullOrEmpty(_li.OutInfo)) { string[] replace = _li.OutInfo.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string str in replace) { int sp = str.IndexOf(":", System.StringComparison.Ordinal); mcarg.Replace(str.Substring(0, sp), str.Substring(sp + 1)); mcarg = new StringBuilder(Microsoft.VisualBasic.Strings.Replace(mcarg.ToString(), str.Split(':')[0], str.Split(':')[1], 1, -1, Microsoft.VisualBasic.CompareMethod.Text)); } } else { mcarg.Replace("{auth_session}", _li.SID); } mcarg.Replace("${auth_uuid}", "{}"); mcarg.Replace("${auth_access_token}", "{}"); mcarg.Replace("${user_properties}", "{}"); arg.Append(" "); arg.Append(mcarg); _game.StartInfo.Arguments = arg.ToString(); #if DEBUG System.Windows.MessageBox.Show(_game.StartInfo.Arguments); #endif BMCLV4.Logger.Log(_game.StartInfo.Arguments); OnStateChangeEvent(LangManager.GetLangFromResource("LauncherCreateNativeDir")); var nativePath = new StringBuilder(Environment.CurrentDirectory + @"\.minecraft\versions\"); nativePath.Append(_name).Append("\\"); var oldnative = new DirectoryInfo(nativePath.ToString()); foreach (DirectoryInfo dir in oldnative.GetDirectories()) { if (dir.FullName.Contains("-natives-")) { Directory.Delete(dir.FullName, true); } } nativePath.Append(_version).Append("-natives-").Append(_timestamp); if (!Directory.Exists(nativePath.ToString())) { Directory.CreateDirectory(nativePath.ToString()); } foreach (Libraries.Libraryies lib in _info.libraries) { if (lib.natives == null) { continue; } if (lib.rules != null) { bool goflag = false; foreach (rules rule in lib.rules) { if (rule.action == "disallow") { if (rule.os == null) { goflag = false; break; } if (rule.os.name.ToLower().Trim() == "windows") { goflag = false; break; } } { if (rule.os == null) { goflag = true; break; } if (rule.os.name.ToLower().Trim() == "windows") { goflag = true; break; } } } if (!goflag) { continue; } } OnStateChangeEvent(LangManager.GetLangFromResource("LauncherUnpackNative") + lib.name); string[] split = lib.name.Split(':');//0 包;1 名字;2 版本 if (split.Count() != 3) { throw new UnSupportVersionException(); } string libp = BuildNativePath(lib); if (GetFileLength(libp) == 0) { { BMCLV4.Logger.Log("未找到依赖" + lib.name + "开始下载", BMCLV4.Logger.LogType.Error); if (lib.url == null) { try { OnStateChangeEvent(LangManager.GetLangFromResource("LauncherDownloadLib") + lib.name); string nativep = BuildNativePath(lib); if (!Directory.Exists(Path.GetDirectoryName(nativep))) { Directory.CreateDirectory(Path.GetDirectoryName(nativep)); } #if DEBUG System.Windows.MessageBox.Show(_urlLib + nativep.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("\\", "/")); BMCLV4.Logger.Log(_urlLib + nativep.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("\\", "/")); #endif _downer.DownloadFile(_urlLib + nativep.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("\\", "/"), nativep); } catch (WebException ex) { BMCLV4.Logger.Log(ex); BMCLV4.Logger.Log("原地址下载失败,尝试作者源" + lib.name); string nativep = BuildLibPath(lib); try { _downer.DownloadFile( DownloadSource.DownloadSourceManage.GetUrlFromResource("UrlDownloadBase") + "libraries/" + nativep.Remove(0, Environment.CurrentDirectory.Length + 22).Replace("/", "\\"), nativep); } catch (WebException exception) { Libraryies lib1 = lib; BmclCore.Invoke(new Action(() => MessageBox.Show(BmclCore.MainWindow, "下载" + lib1.name + "遇到错误:" + exception.Message))); return; } } } else { try { string urlLib = lib.url; OnStateChangeEvent(LangManager.GetLangFromResource("LauncherDownloadLib") + lib.name); /* * DownNative downer = new DownNative(lib); * downNativeEvent(lib); * downer.startdownload(); */ string nativep = BuildNativePath(lib); if (!Directory.Exists(Path.GetDirectoryName(nativep))) { Directory.CreateDirectory(Path.GetDirectoryName(nativep)); } #if DEBUG System.Windows.MessageBox.Show(urlLib.Replace("\\", "/")); BMCLV4.Logger.Log(urlLib.Replace("\\", "/")); #endif _downer.DownloadFile(urlLib + nativep.Replace("/", "\\"), nativep); } catch (WebException ex) { BMCLV4.Logger.Log(ex); BMCLV4.Logger.Log("原地址下载失败,尝试作者源" + lib.name); string nativep = BuildLibPath(lib); _downer.DownloadFile(DownloadSource.DownloadSourceManage.GetUrlFromResource("UrlDownloadBase") + "libraries/" + nativep.Replace("/", "\\"), nativep); } } } } BMCLV4.Logger.Log("解压native"); var zipfile = new ZipInputStream(System.IO.File.OpenRead(libp)); ZipEntry theEntry; while ((theEntry = zipfile.GetNextEntry()) != null) { bool exc = false; if (lib.extract.exclude != null) { if (lib.extract.exclude.Any(excfile => theEntry.Name.Contains(excfile))) { exc = true; } } if (exc) { continue; } var filepath = new StringBuilder(nativePath.ToString()); filepath.Append("\\").Append(theEntry.Name); BMCLV4.Logger.Log(filepath.ToString()); FileStream fileWriter = File.Create(filepath.ToString()); var data = new byte[2048]; while (true) { int size = zipfile.Read(data, 0, data.Length); if (size > 0) { fileWriter.Write(data, 0, size); } else { break; } } fileWriter.Close(); } } OnStateChangeEvent(LangManager.GetLangFromResource("LauncherSolveMod")); BMCLV4.Logger.Log("处理Mods"); if (Directory.Exists(@".minecraft\versions\" + _name + @"\mods")) { if (Directory.Exists(@".minecraft\Config")) { BMCLV4.Logger.Log("找到旧的配置文件,备份并应用新配置文件"); Directory.Move(@".minecraft\Config", @".minecraft\Config" + _timestamp); if (Directory.Exists(@".minecraft\versions\" + _name + @"\Config")) { FileHelper.Dircopy(@".minecraft\versions\" + _name + @"\Config", @".minecraft\Config"); } } else { BMCLV4.Logger.Log("应用新配置文件"); if (Directory.Exists(@".minecraft\versions\" + _name + @"\Config")) { FileHelper.Dircopy(@".minecraft\versions\" + _name + @"\Config", @".minecraft\Config"); } } if (Directory.Exists(@".minecraft\mods")) { BMCLV4.Logger.Log("找到旧的mod文件,备份并应用新mod文件"); Directory.Move(@".minecraft\mods", @".minecraft\mods" + _timestamp); if (Directory.Exists(@".minecraft\versions\" + _name + @"\mods")) { FileHelper.Dircopy(@".minecraft\versions\" + _name + @"\mods", @".minecraft\mods"); } } else { BMCLV4.Logger.Log("应用新mod文件"); if (Directory.Exists(@".minecraft\versions\" + _name + @"\mods")) { FileHelper.Dircopy(@".minecraft\versions\" + _name + @"\mods", @".minecraft\mods"); } } if (Directory.Exists(@".minecraft\coremods")) { BMCLV4.Logger.Log("找到旧的coremod文件,备份并应用新coremod文件"); Directory.Move(@".minecraft\coremods", @".minecraft\coremods" + _timestamp); if (Directory.Exists(@".minecraft\versions\" + _name + @"\coremods")) { FileHelper.Dircopy(@".minecraft\versions\" + _name + @"\coremods", @".minecraft\coremods"); } } else { BMCLV4.Logger.Log("应用新coremod文件"); if (Directory.Exists(@".minecraft\versions\" + _name + @"\coremods")) { FileHelper.Dircopy(@".minecraft\versions\" + _name + @"\coremods", @".minecraft\coremods"); } } if (Directory.Exists(@".minecraft\versions\" + _name + @"\moddir")) { var moddirs = new DirectoryInfo(@".minecraft\versions\" + _name + @"\moddir"); foreach (DirectoryInfo moddir in moddirs.GetDirectories()) { BMCLV4.Logger.Log("复制ModDir " + moddir.Name); FileHelper.Dircopy(moddir.FullName, ".minecraft\\" + moddir.Name); } foreach (FileInfo modfile in moddirs.GetFiles()) { BMCLV4.Logger.Log("复制ModDir " + modfile.Name); File.Copy(modfile.FullName, ".minecraft\\" + modfile.Name, true); } } } OnStateChangeEvent(LangManager.GetLangFromResource("LauncherGo")); //game.StartInfo.WorkingDirectory = Environment.CurrentDirectory + "\\.minecraft\\versions\\" + version; Environment.SetEnvironmentVariable("APPDATA", Environment.CurrentDirectory); _game.EnableRaisingEvents = true; _game.Exited += game_Exited; _game.StartInfo.WorkingDirectory = Environment.CurrentDirectory + "\\.minecraft"; try { _game.Start(); if (BMCLV4.Logger.Debug) { _gameoutput = _game.StandardOutput; _gameerror = _game.StandardError; _logthread = new Thread(Logger); _logthread.Start(); } OnGameStartUp(true); } catch { OnGameStartUp(false); } }
public static void ImportOldMc(string importName, string importFrom, Delegate callback = null) { var thread = new Thread(() => { OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportMain")); Directory.CreateDirectory(".minecraft\\versions\\" + importName); File.Copy(importFrom + "\\bin\\minecraft.jar", ".minecraft\\versions\\" + importName + "\\" + importName + ".jar"); OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportCreateJson")); var info = new gameinfo { id = importName }; string timezone = DateTimeOffset.Now.Offset.ToString(); if (timezone[0] != '-') { timezone = "+" + timezone; } info.time = DateTime.Now.GetDateTimeFormats('s')[0] + timezone; info.releaseTime = DateTime.Now.GetDateTimeFormats('s')[0] + timezone; info.type = "Port By BMCL"; info.minecraftArguments = "${auth_player_name}"; info.mainClass = "net.minecraft.client.Minecraft"; OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportSolveNative")); var libs = new ArrayList(); var bin = new DirectoryInfo(importFrom + "\\bin"); foreach (FileInfo file in bin.GetFiles("*.jar")) { var libfile = new libraries.libraryies(); if (file.Name == "minecraft.jar") { continue; } if ( !Directory.Exists(".minecraft\\libraries\\" + importName + "\\" + file.Name.Substring(0, file.Name.Length - 4) + "\\BMCL\\")) { Directory.CreateDirectory(".minecraft\\libraries\\" + importName + "\\" + file.Name.Substring(0, file.Name.Length - 4) + "\\BMCL\\"); } File.Copy(file.FullName, ".minecraft\\libraries\\" + importName + "\\" + file.Name.Substring(0, file.Name.Length - 4) + "\\BMCL\\" + file.Name.Substring(0, file.Name.Length - 4) + "-BMCL.jar"); libfile.name = importName + ":" + file.Name.Substring(0, file.Name.Length - 4) + ":BMCL"; libs.Add(libfile); } FileHelper.CreateDirectoryIfNotExist(".minecraft\\libraries\\" + importName + "\\BMCL\\"); var nativejar = new ZipArchive( new FileStream( ".minecraft\\libraries\\" + importName + "\\native\\BMCL\\native-BMCL-natives-windows.jar", FileMode.OpenOrCreate)); var nativeInfo = new DirectoryInfo(importFrom + "\\bin\\natives").GetFiles("\\.dll$"); foreach (var fileInfo in nativeInfo) { nativejar.CreateEntryFromFile(fileInfo.FullName, fileInfo.Name); } var nativefile = new libraries.libraryies { name = importName + ":native:BMCL" }; var nativeos = new libraries.OS { windows = "natives-windows" }; nativefile.natives = nativeos; nativefile.extract = new libraries.extract(); libs.Add(nativefile); info.libraries = (libraries.libraryies[])libs.ToArray(typeof(libraries.libraryies)); OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportWriteJson")); var wcfg = new FileStream(".minecraft\\versions\\" + importName + "\\" + importName + ".json", FileMode.Create); var infojson = new DataContractJsonSerializer(typeof(gameinfo)); infojson.WriteObject(wcfg, info); wcfg.Close(); OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportSolveLib")); if (Directory.Exists(importFrom + "\\lib")) { if (!Directory.Exists(".minecraft\\lib")) { Directory.CreateDirectory(".minecraft\\lib"); } foreach ( string libfile in Directory.GetFiles(importFrom + "\\lib", "*", SearchOption.AllDirectories)) { if (!File.Exists(".minecraft\\lib\\" + System.IO.Path.GetFileName(libfile))) { File.Copy(libfile, ".minecraft\\lib\\" + System.IO.Path.GetFileName(libfile)); } } } OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportSolveMod")); if (Directory.Exists(importFrom + "\\mods")) { util.FileHelper.Dircopy(importFrom + "\\mods", ".minecraft\\versions\\" + importName + "\\mods"); } else { Directory.CreateDirectory(".minecraft\\versions\\" + importName + "\\mods"); } if (Directory.Exists(importFrom + "\\coremods")) { util.FileHelper.Dircopy(importFrom + "\\coremods", ".minecraft\\versions\\" + importName + "\\coremods"); } else { Directory.CreateDirectory(".minecraft\\versions\\" + importName + "\\coremods"); } if (Directory.Exists(importFrom + "\\config")) { util.FileHelper.Dircopy(importFrom + "\\config", ".minecraft\\versions\\" + importName + "\\config"); } else { Directory.CreateDirectory(".minecraft\\versions\\" + importName + "\\configmods"); } OnImportFinish(); if (callback != null) { BmclCore.Invoke(callback); } }); thread.Start(); }
public void ChangeLanguage() { GridConfig.listDownSource.Items[1] = LangManager.GetLangFromResource("listOfficalSource"); GridConfig.listDownSource.Items[0] = LangManager.GetLangFromResource("listAuthorSource"); BmclCore.LoadPlugin(LangManager.GetLangFromResource("LangName")); }
public void ReFlushlistver() { BmclCore.GameManager.ReloadList(); BmclCore.Invoke(new Action(() => listVer.ItemsSource = BmclCore.GameManager.GetVersions().Keys.ToList())); }