public static async Task LaunchGameAsync(FileManager.Modpacks modpack) { try { var path = new MinecraftPath(Directory.GetCurrentDirectory() + $@"\Launcher\{modpack}"); var launcher = new CMLauncher(path); // more options : https://github.com/AlphaBs/CmlLib.Core/wiki/MLaunchOption var launchOption = new MLaunchOption { MaximumRamMb = Settings.RAM, Session = SESSION }; forgeVersion = File.ReadAllText($"Launcher/{modpack}/Forge Version.txt"); var process = await launcher.CreateProcessAsync(forgeVersion, launchOption); process.Start(); } catch (Exception) { main.GetError($"Failed Launching {modpack}!"); } }
public PathForm(MinecraftPath path) { this.MinecraftPath = path; //Sets minecraft path not works now InitializeComponent(); }
private List <MVersionMetadata> getFromLocal(MinecraftPath path) { var versionDirectory = new DirectoryInfo(path.Versions); if (!versionDirectory.Exists) { return(new List <MVersionMetadata>()); } var dirs = versionDirectory.GetDirectories(); var arr = new List <MVersionMetadata>(dirs.Length); for (int i = 0; i < dirs.Length; i++) { var dir = dirs[i]; var filepath = Path.Combine(dir.FullName, dir.Name + ".json"); if (File.Exists(filepath)) { var info = new MVersionMetadata(dir.Name); info.IsLocalVersion = true; info.Path = filepath; info.Type = "local"; info.MType = MVersionType.Custom; arr.Add(info); } } return(arr); }
public ForgeInstall(MinecraftPath path, string java) { this.javapath = java; this.Path = path; logQueue = new ConcurrentQueue <string>(); InitializeComponent(); }
/// <summary> /// Cambia la lista di mod /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ModpackCBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { modList.Text = ""; if (modpackCBox.SelectedItem != null) { if (File.Exists(Path.Combine(MinecraftPath.GetOSDefaultPath(), "Istances", (string)modpackCBox.SelectedItem, "Files.txt"))) { foreach (string str in await File.ReadAllLinesAsync(Path.Combine(MinecraftPath.GetOSDefaultPath(), "Istances", (string)modpackCBox.SelectedItem, "Files.txt"))) { modList.Text += $"{str.Replace(".jar", "")}\n"; } } else { foreach (FileInfo file in new DirectoryInfo(Path.Combine(MinecraftPath.GetOSDefaultPath(), "Istances", (string)modpackCBox.SelectedItem, "mods")).GetFiles()) { await File.AppendAllTextAsync(Path.Combine(MinecraftPath.GetOSDefaultPath(), "Istances", (string)modpackCBox.SelectedItem, "Files.txt"), file.Name + Environment.NewLine); } foreach (string str in await File.ReadAllLinesAsync(Path.Combine(MinecraftPath.GetOSDefaultPath(), "Istances", (string)modpackCBox.SelectedItem, "Files.txt"))) { modList.Text += $"{str.Replace(".jar", "")}\n"; } } } }
public static MVersion ParseAndSave(MVersionMetadata info, MinecraftPath savePath) { try { string json; if (!info.IsLocalVersion) { using (var wc = new WebClient()) { json = wc.DownloadString(info.Path); var path = savePath.GetVersionJsonPath(info.Name); Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllText(path, json); return(ParseFromJson(json)); } } else { return(ParseFromFile(info.Path)); } } catch (MVersionParseException ex) { ex.VersionName = info.Name; throw ex; } }
/// <summary> /// Verifica se il modpack era gia stato installato /// </summary> /// <param name="ModpackBaseDirectory"></param> /// <param name="ModpackModsDirectory"></param> /// <returns>Restituisce un valore booleano indicante se il modpack era gia stato installato</returns> static public bool isModpackInstalled(string ModpackBaseDirectory, string ModpackModsDirectory) { if (Directory.Exists(ModpackBaseDirectory)) { if (!Directory.Exists(ModpackModsDirectory)) { Directory.CreateDirectory(ModpackModsDirectory); } return(true); } else { if (!Directory.Exists(Path.Combine(MinecraftPath.GetOSDefaultPath(), "Istances"))) { Directory.CreateDirectory(Path.Combine(MinecraftPath.GetOSDefaultPath(), "Istances")); } if (!Directory.Exists(ModpackBaseDirectory)) { Directory.CreateDirectory(ModpackBaseDirectory); } if (!Directory.Exists(ModpackModsDirectory)) { Directory.CreateDirectory(ModpackModsDirectory); } return(false); } }
private void btnStart_Click(object sender, EventArgs e) { btnLogin.Enabled = false; btnSignout.Enabled = false; btnStart.Enabled = false; new Thread(() => { try { var path = new MinecraftPath(); var launcher = new CMLauncher(path); launcher.FileChanged += Launcher_FileChanged; launcher.ProgressChanged += Launcher_ProgressChanged; var versions = launcher.GetAllVersions(); var lastVersion = versions.LatestReleaseVersion; var process = launcher.CreateProcess(lastVersion.Name, new MLaunchOption() { Session = this.session }); process.Start(); MessageBox.Show("Success"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }).Start(); }
public static MVersionCollection LoadVersions() { var mcp = new MinecraftPath(Path.Combine(Utility.GetWorkingDir(), ".minecraft")); var launcher = new CMLauncher(mcp); return(launcher.GetAllVersions()); }
void TestStartSync(MSession session) { var path = new MinecraftPath(); var launcher = new CMLauncher(path); launcher.FileChanged += Downloader_ChangeFile; launcher.ProgressChanged += Downloader_ChangeProgress; var versions = launcher.GetAllVersions(); foreach (var item in versions) { Console.WriteLine(item.Name); } var process = launcher.CreateProcess("1.5.2", new MLaunchOption { Session = session }); var processUtil = new CmlLib.Utils.ProcessUtil(process); processUtil.OutputReceived += (s, e) => Console.WriteLine(e); processUtil.StartWithEvents(); }
async Task StartAsync(MSession session) // async version { var path = new MinecraftPath(); var launcher = new CMLauncher(path); System.Net.ServicePointManager.DefaultConnectionLimit = 256; var versions = await launcher.GetAllVersionsAsync(); foreach (var item in versions) { Console.WriteLine(item.Type + " " + item.Name); } launcher.FileChanged += Downloader_ChangeFile; launcher.ProgressChanged += Downloader_ChangeProgress; Console.WriteLine("input version (example: 1.12.2) : "); var versionName = Console.ReadLine(); var process = await launcher.CreateProcessAsync(versionName, new MLaunchOption { Session = session, MaximumRamMb = 1024 }); Console.WriteLine(process.StartInfo.Arguments); process.Start(); }
private void btnApply_Click(object sender, EventArgs e) { var mc = new MinecraftPath(txtPath.Text); mc.Runtime = MinecraftPath.Runtime; mc.SetAssetsPath(Path.Combine(MinecraftPath.GetOSDefaultPath(), "assets")); apply(mc); }
private void MainForm_Load(object sender, EventArgs e) { // Initialize launcher var defaultPath = new MinecraftPath(MinecraftPath.GetOSDefaultPath()); InitializeLauncher(defaultPath); }
async Task Start(MSession session) { var path = MinecraftPath.GetOSDefaultPath(); var game = new MinecraftPath(path); // Create CMLauncher instance var launcher = new CMLauncher(game); // if you want to download with parallel downloader, add below code : System.Net.ServicePointManager.DefaultConnectionLimit = 256; launcher.ProgressChanged += Downloader_ChangeProgress; launcher.FileChanged += Downloader_ChangeFile; Console.WriteLine($"{launcher.MinecraftPath.BasePath} adresine kuruldu."); // Get all installed profiles and load all profiles from mojang server var versions = await launcher.GetAllVersionsAsync(); foreach (var item in versions) // Display all profiles { // You can filter snapshots and old versions to add if statement : if (item.MType == CmlLib.Core.Version.MVersionType.Release || item.MType == CmlLib.Core.Version.MVersionType.Custom) { List <string> list = new List <string> { item.Type + " " + item.Name }; list.ForEach(i => Console.Write("{0}\n", i)); } } var launchOption = new MLaunchOption { MaximumRamMb = 1024, Session = session, }; Console.WriteLine("Versiyon yazın (örnek 1.12.2): "); var process = await launcher.CreateProcessAsync(Console.ReadLine(), launchOption); //var process = launcher.CreateProcess("1.16.2", "33.0.5", launchOption); Console.WriteLine(process.StartInfo.Arguments); // Below codes are print game logs in Console. var processUtil = new CmlLib.Utils.ProcessUtil(process); processUtil.OutputReceived += (s, e) => Console.WriteLine(e); processUtil.StartWithEvents(); process.WaitForExit(); // or just start it without print logs // process.Start(); Console.ReadLine(); return; }
private async void MainForm_Shown(object sender, EventArgs e) { lbLibraryVersion.Text = "CmlLib.Core " + getLibraryVersion(); // Initialize launcher var defaultPath = new MinecraftPath(MinecraftPath.GetOSDefaultPath()); await initializeLauncher(defaultPath); }
public MAsyncDownloader(MinecraftPath path, MVersion mVersion, int maxThread, bool setConnectionLimit) : base(path, mVersion) { MaxThread = maxThread; if (setConnectionLimit) { ServicePointManager.DefaultConnectionLimit = maxThread + 5; } }
async Task TestAll(MSession session) { var path = MinecraftPath.GetOSDefaultPath(); var game = new MinecraftPath(path); var launcher = new CMLauncher(game); System.Net.ServicePointManager.DefaultConnectionLimit = 256; launcher.FileDownloader = new AsyncParallelDownloader(); launcher.ProgressChanged += Downloader_ChangeProgress; launcher.FileChanged += Downloader_ChangeFile; Console.WriteLine($"Initialized in {launcher.MinecraftPath.BasePath}"); var launchOption = new MLaunchOption { MaximumRamMb = 1024, Session = session, }; var versions = await launcher.GetAllVersionsAsync(); foreach (var item in versions) { Console.WriteLine(item.Type + " " + item.Name); if (!item.IsLocalVersion) { continue; } var process = launcher.CreateProcess(item.Name, launchOption); //var process = launcher.CreateProcess("1.16.2", "33.0.5", launchOption); Console.WriteLine(process.StartInfo.Arguments); // Below codes are print game logs in Console. var processUtil = new CmlLib.Utils.ProcessUtil(process); processUtil.OutputReceived += (s, e) => Console.WriteLine(e); processUtil.StartWithEvents(); Thread.Sleep(1000 * 15); if (process.HasExited) { Console.WriteLine("FAILED!!!!!!!!!"); Console.ReadLine(); } process.Kill(); process.WaitForExit(); } return; }
private async Task initializeLauncher(MinecraftPath path) { txtPath.Text = path.BasePath; this.gamePath = path; launcher = new CMLauncher(path); launcher.FileChanged += Launcher_FileChanged; launcher.ProgressChanged += Launcher_ProgressChanged; await refreshVersions(null); }
void apply(MinecraftPath path) { this.MinecraftPath = path; txtPath.Text = path.BasePath; txtAssets.Text = path.Assets; txtLibrary.Text = path.Library; txtRuntime.Text = path.Runtime; txtVersion.Text = path.Versions; }
private void btnApply_Click(object sender, EventArgs e) { var mc = new MinecraftPath(txtPath.Text) { Runtime = MinecraftPath.Runtime, Assets = Path.Combine(MinecraftPath.GetOSDefaultPath(), "assets") //assets folder }; apply(mc); }
private void InitializeLauncher(MinecraftPath path) { txtPath.Text = path.BasePath; MinecraftPath = path; if (useMJava) { lbJavaPath.Text = path.Runtime; } refreshVersions(null); }
public DownloadFile[]? CheckFiles(MinecraftPath path, MVersion version, IProgress <DownloadFileChangedEventArgs>?progress) { if (version == null) { throw new ArgumentNullException(nameof(version)); } return(CheckFilesTaskAsync(path, version, progress) .GetAwaiter().GetResult()); }
/// <summary> /// Controlla se la cartella Minecraft esiste /// </summary> /// <returns>Restituisce un valore booleano indicante se la cartella Minecraft esiste</returns> static public bool doesMinecraftExist() { if (Directory.Exists(MinecraftPath.GetOSDefaultPath())) { return(true); } else { return(false); } }
/// <summary> /// Get All MVersionInfo from mojang server and local /// </summary> public MVersionCollection GetVersionMetadatas(MinecraftPath path) { var list = getFromLocal(path); var web = GetVersionMetadatasFromWeb(); foreach (var item in web) { if (!list.Contains(item)) { list.Add(item); } } return(new MVersionCollection(list.ToArray(), path, web.LatestReleaseVersion, web.LatestSnapshotVersion)); }
/// <summary> /// OpenFolderDialog per selezionare le mod /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public async void SelectModPath(object sender, RoutedEventArgs e) { OpenFolderDialog dialog = new OpenFolderDialog() { Directory = MinecraftPath.GetOSDefaultPath(), Title = "Selezione cartella mod" }; string path = await dialog.ShowAsync(this); if (Directory.Exists(path)) { ModU.Text = path; } }
public MVersionCollection( MVersionMetadata[] datas, MinecraftPath originalPath, MVersionMetadata latestRelease, MVersionMetadata latestSnapshot) { if (datas == null) { throw new ArgumentNullException(nameof(datas)); } versions = datas; MinecraftPath = originalPath; LatestReleaseVersion = latestRelease; LatestSnapshotVersion = latestSnapshot; }
public async Task <IActionResult> OnPostDownload() { if (LStarted == true) { HttpContext.Session.Set("LQueryProgress", true); return(RedirectToPage("/Launcher")); } HttpContext.Session.Set("DLQueryProgress", true); if (DLStarted == false) { DLStarted = true; DLFileKind = string.Empty; DLFileName = string.Empty; DLProgressedFileCnt = "0"; DLTotFileCnt = "?"; DLProgressPercentage = "0"; DLSuccess = "false"; var minecraft = new MinecraftPath(Path.Combine(Utility.GetWorkingDir(), ".minecraft")); var versionMetadatas = new MVersionLoader().GetVersionMetadatas(minecraft); var version = versionMetadatas.GetVersion("1.16.5"); MDownloader downloader = new MDownloader(minecraft, version); downloader.ChangeFile += (e) => { DLFileKind = e.FileKind.ToString(); DLFileName = e.FileName; DLProgressedFileCnt = e.ProgressedFileCount.ToString(); DLTotFileCnt = e.TotalFileCount.ToString(); }; downloader.ChangeProgress += (sender, e) => { DLProgressPercentage = e.ProgressPercentage.ToString(); }; await Task.Run(() => { try { downloader.DownloadAll(); HttpContext.Session.Set("SuccessMsg", Translation.Translate("launcher-success-dl")); } catch (Exception e) { HttpContext.Session.Set("ErrorMsg", e.Message); } HttpContext.Session.Set("DLQueryProgress", false); DLSuccess = "true"; DLStarted = false; }); } return(RedirectToPage("/Launcher")); }
/// <summary> /// Crea un nuovo profilo nel launcher di minecraft impostato con il 75% della ram del sistema e un icona personalizzata /// </summary> /// <param name="sender"></param> /// <param name="ModpackBaseDirectory">Directory del modpack</param> /// <param name="DropboxKey">token di DropBox</param> /// <param name="nome">Nome del Modpack</param> /// <param name="forgeversion">Versione di forge</param> /// <returns></returns> static public async Task ParseProfile(MainWindow sender, string ModpackBaseDirectory, string DropboxKey, string nome, string forgeversion) { sender.Message("Rilevo la quantità di ram nel sistema..."); float ram = (float)GC.GetGCMemoryInfo().TotalAvailableMemoryBytes / 1024f / 1024f / 1024f; float allocatedram = (float)Math.Ceiling(ram / 100f * 75f); sender.Message("Creo il nuovo profilo nel launcher..."); string iconPath = Path.Combine(ModpackBaseDirectory, "icon.png"); using (var dbx = new DropboxClient(DropboxKey)) { using (var response = await dbx.Files.DownloadAsync(@"/icon.png")) { using (var fileStream = File.Create(iconPath)) { (await response.GetContentAsStreamAsync()).CopyTo(fileStream); } } } byte[] imageArray = File.ReadAllBytes(iconPath); string base64ImageRepresentation = Convert.ToBase64String(imageArray); string parsedJson = await File.ReadAllTextAsync(Path.Combine(MinecraftPath.GetOSDefaultPath(), "launcher_profiles.json")); LauncherProfile root = JsonConvert.DeserializeObject <LauncherProfile>(parsedJson); if (root.profiles.ContainsKey("forge")) { root.profiles.Remove("forge"); } if (!root.profiles.ContainsKey(nome)) { root.profiles.Add(nome, new Profile { name = nome, type = "custom", lastVersionId = forgeversion, icon = "data:image/png;base64," + base64ImageRepresentation, gameDir = ModpackBaseDirectory, javaArgs = $@"-Xmx{allocatedram}G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M", }); } await File.WriteAllTextAsync(Path.Combine(MinecraftPath.GetOSDefaultPath(), "launcher_profiles.json"), JsonConvert.SerializeObject(root, Formatting.Indented)); }
public DownloadFile[]? CheckFiles(MinecraftPath path, MVersion version, IProgress <DownloadFileChangedEventArgs>?progress) { progress?.Report(new DownloadFileChangedEventArgs(MFile.Minecraft, false, version.Jar, 1, 0)); DownloadFile?result = checkClientFile(path, version); progress?.Report(new DownloadFileChangedEventArgs(MFile.Minecraft, false, version.Jar, 1, 1)); if (result == null) { return(null); } else { return new [] { result } }; }
public async Task <DownloadFile[]?> CheckFilesTaskAsync(MinecraftPath path, MVersion version, IProgress <DownloadFileChangedEventArgs>?progress) { progress?.Report(new DownloadFileChangedEventArgs(MFile.Minecraft, false, version.Jar, 1, 0)); DownloadFile?result = await Task.Run(() => checkClientFile(path, version)) .ConfigureAwait(false); progress?.Report(new DownloadFileChangedEventArgs(MFile.Minecraft, false, version.Jar, 1, 1)); if (result == null) { return(null); } else { return new [] { result } }; }