public Dictionary<string, string> AddModPack(ZipFile ModPack, WischisLauncherCore.LauncherProfile Profil) { Dictionary<string, string> ModListe = new Dictionary<string, string>(); string ModName = Path.GetFileName(ModPack.Name); if (ModPack.EntryFileNames.Contains("modindex.txt")) { string index = new StreamReader(ModPack["modindex.txt"].OpenReader()).ReadToEnd(); char[] splitchars = {'\r','\n'}; string[] zeilen = index.Split(splitchars); foreach (string zzz in zeilen) { string zeile = zzz.Trim(); if (zeile == "" || zeile.Substring(0, 1) == "#" || zeile.Substring(0, 1) == ";") continue; string[] cmd = zeile.Split('\t'); if (cmd.Length <= 0) continue; switch(cmd[0]) { case "copy": //falls nicht genau 1 befehl und 2 argumente, brich ab. if (cmd.Length != 3) break; foreach (ZipEntry ent in ModPack) { if (!Regex.IsMatch(ent.FileName, cmd[1]) || ent.FileName.Substring(ent.FileName.Length-1,1)=="/") continue; string location = Regex.Replace(ent.FileName, cmd[1], cmd[2], RegexOptions.None); location = LauncherFolderStructure.GetSpecificMinecraftFolder(Profil) + Path.DirectorySeparatorChar + location; if (File.Exists(location)) continue; string dir = Path.GetDirectoryName(location); string fname = dir + Path.DirectorySeparatorChar + Path.GetFileName(location); ModListe.Add(("file|" + fname).ToLower(), ModName.ToLower()); if(Directory.Exists(dir))Directory.CreateDirectory(dir); FileStream fs = File.Open(location,FileMode.OpenOrCreate,FileAccess.Write); ent.Extract(fs); fs.Close(); } break; case "patch": //falls nicht genau 1 befehl und 2 argumente, brich ab. if (cmd.Length != 3) break; foreach (ZipEntry ent in ModPack) { if (!Regex.IsMatch(ent.FileName, cmd[1]) || ent.FileName.Substring(ent.FileName.Length - 1, 1) == "/") continue; string location = Regex.Replace(ent.FileName, cmd[1], cmd[2], RegexOptions.None); ModListe.Add(("patch|" + ent.FileName).ToLower(), ModName.ToLower()); AddModFile(ent.OpenReader(),location); } break; default: //was ist das für ein befehl? break; } } } else { foreach (ZipEntry ent in ModPack) { if(!ent.IsDirectory)ModListe.Add(("patch|" + ent.FileName).ToLower(), ModName.ToLower()); AddModFile(ent); } } return ModListe; }
public bool StartMinecraft(WischisLauncherCore.LauncherProfile Profil) { ClearConsole(); SwitchToConsoleScreen(); #region Check running Processes foreach (Process proc in Process.GetProcesses()) { if (proc.ProcessName.Contains("java")) { ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + proc.Id); foreach (ManagementObject mo in mos.Get()) { object abc = mo["CommandLine"]; if (!(abc is string)) continue; string cmd = (string)abc; Regex mineEx = new Regex("-cp[ ]+[\"]?([a-zA-Z]:\\\\([^|/:*\\\\?<>]+\\\\)+).minecraft\\\\[^|/:*\\\\?<>]+.jar[\"]? net.minecraft.LauncherFrame"); Match MineMatch = mineEx.Match(cmd); //checke ob der aktuelle Start im gleichen Profil passiert. if (MineMatch.Groups.Count > 2) { string a = MineMatch.Groups[1].Value; string b = Path.GetDirectoryName(a); //TODO: schau dir das mal an /* if (b.ToLower() == CurrentAppPath.ToLower()) { AddLogLine("> Minecraft läuft bereits im Verzeichnis: " + b + ". Bitte beende die offene Instanz."); //proc. this.Show(); return false; }*/ } } } } #endregion #region Check Java Path if (Profil.Settings.JavaExecutable == "") { AddLogLine("$WMCL> JavaPfad nicht eingetragen!"); this.Show(); return false; } #endregion Application.DoEvents(); minecraft = new Process(); minecraft.StartInfo.FileName = Profil.Settings.JavaExecutable; //TODO: Pfad verbiegen minecraft.StartInfo.EnvironmentVariables["appdata"] = LauncherFolderStructure.GetSpecificProfilePath(Profil); if (!MinecraftLocations.ContainsKey(Profil.Settings.MinecraftBinJarHash)) { AddLogLine("$WMCL> FEHLER: Es ist keine gültige Minecraft-Version gewählt"); return false; } AddConsoleLine("Login: http://login.minecraft.net"); Application.DoEvents(); while (RebuildJarList.Count > 0 || ModCompatibilityChecker.IsBusy) Application.DoEvents(); if (!File.Exists(Profil.Settings.MinecraftBinJarCache)) { AddModInfo("Keine Jar im Cache gefunden -> neu bilden.", Profil); BuildJarInBackground(Profil, true); Thread.Sleep(200); } while (RebuildJarList.Count > 0 || ModCompatibilityChecker.IsBusy) Application.DoEvents(); if (!File.Exists(Profil.Settings.MinecraftBinJarCache)) { label22.Text = "minecraft.jar nicht gefunden."; label22.Visible = true; return false; #region Weg damit /*AddConsoleLine("Erstelle MinecraftBinJar"); while (ModCompatibilityChecker.IsBusy || RebuildJarList.Count > 0) Application.DoEvents(); CookieContainer cc = null; MinecraftBinJarLocation loc = MinecraftLocations[Profil.Settings.MinecraftBinJarHash]; AddConsoleLine("Lade Jar: " + loc.Name); if (loc.NeedAuth) { AddConsoleLine("Verbinde zu http://dev.wischenbart.org/minecraft"); AddLogLine("$WMCL> Verbinde zu http://dev.wischenbart.org/minecraft"); string Hinweis; cc = MinecraftAuth.WischiAuth(sid, Profil.Settings.MinecraftLoginUser,out Hinweis); AddLogLine("$WMCL> AuthResp.: " + Hinweis); AddLogLine("$WMCL> Rückmeldung: " + MinecraftAuth.CheckWischiAuth(cc)); } AddConsoleLine("> " + loc.DownloadLocation); Application.DoEvents(); MinecraftBinJar mjar = null; try { mjar = loc.GetMinecraftBinJar(cc); } catch (Exception ex) { AddLogLine("$WMCL> MinecraftJar konnte nicht geladen werden: " + ex.Message); return false; } if (Profil.Settings.MinecraftServerAutoConnect) { string WischiPatch = Assembly.GetExecutingAssembly().GetName().Name + ".Resources." + "WMLPatch.class"; Stream WischiPatchStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(WischiPatch); mjar.AddModFile(WischiPatchStream, "net/minecraft/client/WMLPatch.class"); } Application.DoEvents(); AddConsoleLine("Patche Mods in Binjar"); foreach (ListViewItem it in ModListe.Items) { if (!it.Checked) continue; AddConsoleLine("Mod: " + it.Text); string mod = LauncherFolderStructure.ModFolder + Path.DirectorySeparatorChar + it.Text; if (File.Exists(mod) && ZipFile.CheckZip(mod)) { ZipFile modfile = new ZipFile(mod); mjar.AddModPack(modfile,Profil); } else { AddLogLine("$WMCL> Der Mod konnte nicht geladen werden: '" + mod + "'"); } } Application.DoEvents(); string tempString = Guid.NewGuid().ToString().ToUpper(); Profil.Settings.MinecraftBinJarCache = LauncherFolderStructure.GetSpecificBinFolder(Profil) + Path.DirectorySeparatorChar + tempString; mjar.Save(Profil.Settings.MinecraftBinJarCache);*/ #endregion } else { AddConsoleLine("MinecraftBinJar Cache gefunden."); } string sid; string mcuser; if (!MinecraftAuth.ProfileAuth(Profil, out sid, out mcuser, textBox11.Text)) { label22.Text = "Can't connect to minecraft.net"; label22.Visible = true; AddLogLine("Error minecraft.net: " + sid); return false; } if (AllowOffline) { Random rnd = new Random(); sid = rnd.Next().ToString(); mcuser = FakePlayerName.Text.Replace(" ", ""); } AddConsoleLine("Lade Resourcen"); MinecraftRessourceDownloader.DownloadBins(LauncherFolderStructure.GetSpecificBinFolder(Profil), this); string arguments = ""; //RAM Einstellungen if (checkBox3.Checked) arguments += " -Xmx" + regler_max.Value + "M -Xms" + regler_init.Value + "M"; //Set Proxy if (checkBox4.Checked) { arguments += " -DsocksproxyHost=" + textBox1.Text + " -DsocksproxyPort=" + textBox2.Text; arguments += " -Dhttp.proxyHost=" + textBox1.Text + " -Dhttp.proxyPort=" + textBox2.Text; arguments += " -Dhttps.proxyHost=" + textBox1.Text + " -Dhttps.proxyPort=" + textBox2.Text; arguments += " -Dhttp.proxyUser="******" -Dhttp.proxyPassword="******" -Djava.library.path=\"" + LauncherFolderStructure.GetSpecificBinFolder(Profil) + Path.DirectorySeparatorChar + "natives\""; string Classes = ""; Classes += "\"" + Profil.Settings.MinecraftBinJarCache + "\";"; Classes += "\"" + LauncherFolderStructure.GetSpecificBinFolder(Profil) + Path.DirectorySeparatorChar + "lwjgl.jar\";"; Classes += "\"" + LauncherFolderStructure.GetSpecificBinFolder(Profil) + Path.DirectorySeparatorChar + "lwjgl_util.jar\";"; Classes += "\"" + LauncherFolderStructure.GetSpecificBinFolder(Profil) + Path.DirectorySeparatorChar + "jinput.jar\";"; if (Profil.Settings.MinecraftServerAutoConnect) arguments += " -cp " + Classes + " net.minecraft.client.WMLPatch"; else arguments += " -cp " + Classes + " net.minecraft.client.Minecraft"; arguments += " \"" + mcuser + "\" \"" + sid + "\""; if (Profil.Settings.MinecraftServerAutoConnect) arguments += " " + Profil.Settings.MinecraftServerAutoconnectHost; minecraft.StartInfo.Arguments = arguments; minecraft.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; AddLogLine("$WMCL> Java: " + minecraft.StartInfo.FileName); AddLogLine("$WMCL> Attrib: " + arguments); minecraft.StartInfo.CreateNoWindow = true; minecraft.StartInfo.RedirectStandardOutput = true; minecraft.StartInfo.RedirectStandardError = true; minecraft.StartInfo.UseShellExecute = false; minecraft.EnableRaisingEvents = true; minecraft.OutputDataReceived += new DataReceivedEventHandler(minecraft_OutputDataReceived); minecraft.ErrorDataReceived += new DataReceivedEventHandler(minecraft_ErrorDataReceived); AddLogLine("$WMCL> Starte Minecraft."); MCstart = DateTime.Now; LastWindowTime = DateTime.Now; AddConsoleLine("Starte Minecraft..."); RunningProfile = Profil; minecraft.Exited += new EventHandler(minecraft_Exited); minecraft.Start(); object Prio = Enum.Parse(typeof(ProcessPriorityClass), Profil.Settings.MinecraftPrio); if (Prio is ProcessPriorityClass && Profil.Settings.JavaMemoryUse) { minecraft.PriorityClass = (ProcessPriorityClass)Prio; } else { minecraft.PriorityClass = ProcessPriorityClass.Normal; Profil.Settings.MinecraftPrio = ProcessPriorityClass.Normal.ToString(); } button10.Enabled = false; SetSize = true; timer1.Enabled = true; minecraft.BeginErrorReadLine(); minecraft.BeginOutputReadLine(); return true; }