public void DownloadAndPatch(string srg, string mcpBot, string tempDir, string oldVersion, string newVersion, DownloadUtil download) { UpdateStatus("Downloading: Patches"); download.StartDownload(mcpBot, tempDir + @"mcpbot.zip", new AsyncCompletedEventHandler(DownloadCompleted)); while (!downloadCompleted) { //Wait until download completed } downloadCompleted = false; download.StartDownload(srg, tempDir + @"srg.zip", new AsyncCompletedEventHandler(DownloadCompleted)); while (!downloadCompleted) { //Wait until download completed } downloadCompleted = false; UpdateStatus("Patching MCP"); string configDir = tempDir + @"mcp\conf\"; string mcpBotDir = tempDir + "mcpbot"; string srgDir = tempDir + "srg"; Directory.CreateDirectory(mcpBotDir); Directory.CreateDirectory(srgDir); ZipFile.ExtractToDirectory(tempDir + @"mcpbot.zip", mcpBotDir); ZipFile.ExtractToDirectory(tempDir + @"srg.zip", srgDir); Utils.CopyAndReplace(mcpBotDir, configDir); Utils.CopyAndReplace(srgDir, configDir); string configContent = File.ReadAllText(configDir + "version.cfg"); string newConfigContent = configContent.Replace(oldVersion, newVersion); File.WriteAllText(configDir + "version.cfg", newConfigContent); }
private void ButtonDecompileStart() { flatComboBox1.Invoke(new Action(() => { if (flatComboBox1.SelectedItem == null) { MessageBox.Show("Please select a mcp version.", "MCP Version Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } })); if (decompileDir == null) { if (!SelectDecompilationDirectory()) { MessageBox.Show("Please select a folder to decompile.", "Select a Folder", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (Directory.Exists(decompileDir + @"\src")) { DialogResult result = MessageBox.Show("SRC Folder already exists.", "The SRC folder already exists! Do you want to decompile again?", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.No) { return; } Directory.Delete(decompileDir + @"\src", true); } running = true; flatLabel4.Invoke(new Action(() => { flatLabel4.Show(); })); flatLabel3.Invoke(new Action(() => { flatLabel3.Show(); })); RegisteredMCP selectedMCP = RegisteredMCP.ERROR; flatComboBox1.Invoke(new Action(() => { selectedMCP = MCPUtils.GetMCPFromString(flatComboBox1.SelectedItem.ToString()); })); Patch patch = selectedMCP.GetPatchInstace(); Thread t = new Thread(() => { if (!Utils.CheckForInternetConnection()) { Utils.Error("No internet connection", "No Internet connection please connect to a valid network."); return; } if (selectedMCP == RegisteredMCP.ERROR) { return; } UpdateStatus("Creating Directories"); string tempDir = decompileDir + @"\temp\"; Directory.CreateDirectory(tempDir); Directory.CreateDirectory(decompileDir + @"\src\main\java"); Directory.CreateDirectory(decompileDir + @"\src\main\resources"); Directory.CreateDirectory(decompileDir + @"\src\test\java"); Directory.CreateDirectory(decompileDir + @"\src\test\resources"); Directory.CreateDirectory(decompileDir + @"\natives"); Directory.CreateDirectory(decompileDir + @"\.minecraft"); //Call Init in Patch patch.Init(this, selectedMCP); UpdateStatus("Downloading: MCP"); DownloadUtil download = new DownloadUtil(this, flatLabel3, flatProgressBar1); download.StartDownload(patch.mcpUrl, tempDir + @"mcp.zip", new AsyncCompletedEventHandler(DownloadCompleted)); while (!downloadCompleted) { //Wait until download completed } ZipFile.ExtractToDirectory(tempDir + @"mcp.zip", tempDir + @"mcp\"); downloadCompleted = false; //Run PrePatch string buildScript; if (checkboxClicked) { buildScript = decompileDir + @"\pom.xml"; } else { buildScript = decompileDir + @"\build.gradle"; } UpdateStatus("Running: PrePatch"); patch.RunPrePatch(this, buildScript, tempDir, download); //Update MCP to work without a button press string fixedDecompileScript = File.ReadAllText(tempDir + @"\mcp\decompile.bat").Replace("pause", ""); File.WriteAllText(tempDir + @"\mcp\decompile.bat", fixedDecompileScript); Thread decompileThread = new Thread(() => { UpdateStatus("Decompiling..."); //Decompile GC.Collect(); string strCmdText = "/C cd \"" + tempDir + "\\mcp\" && decompile.bat"; Process process = Process.Start("CMD.exe", strCmdText); Thread.Sleep(3000); process.WaitForExit(); }); decompileThread.Start(); while (decompileThread.IsAlive) { //Wait until Decompilation is finished } patch.RunPostPatch(this, tempDir); UpdateStatus("Copying: SRC"); //Copy Files to src folder string sourcePath = tempDir + @"mcp\src\"; string destinationPath = decompileDir + @"\src\main\java"; Utils.CopyAndReplace(sourcePath, destinationPath); UpdateStatus("Cleaning up"); GC.Collect(); //Delete Temp Dir Directory.Delete(tempDir, true); running = false; //Opens the BuildScriptConfigForm OpenBuildScriptConfig(buildScript, !checkboxClicked); }); t.Start(); }