Exemple #1
0
        /// <summary>
        /// This gets executed right before downloading the MCP
        /// </summary>
        public virtual void Init(MainForm form, RegisteredMCP mcp)
        {
            this.mcp = mcp;
            string buildScriptName = "script " + mcp.GetVersionString();

            if (form.checkboxClicked)
            {
                buildScriptName = buildScriptName.Replace("script", "Maven");
            }
            else
            {
                buildScriptName = buildScriptName.Replace("script", "Gradle");
            }
            buildScriptBytes = GetResourceBytes(buildScriptName);
        }
Exemple #2
0
 public static Patch GetPatchInstace(this RegisteredMCP mcp)
 {
     if (patchInstances.ContainsKey(mcp))
     {
         patchInstances.TryGetValue(mcp, out Patch returnVal);
         return(returnVal);
     }
     try
     {
         Type  t         = Type.GetType("MCP_Creater.Patches." + "_" + GetVersionString(mcp).Replace(".", "_"));
         Patch returnVal = (Patch)Activator.CreateInstance(t);
         patchInstances.Add(mcp, returnVal);
         return(returnVal);
     }
     catch (Exception)
     {
         return(new Patch());
     }
 }
Exemple #3
0
 public override void Init(MainForm form, RegisteredMCP mcp)
 {
     base.Init(form, mcp);
     mcpUrl = "http://www.modcoderpack.com/files/mcp918.zip";
 }
Exemple #4
0
 public static string GetMinecraftName(this RegisteredMCP mcp)
 {
     return("Minecraft " + GetVersionString(mcp));
 }
Exemple #5
0
 public static string GetVersionString(this RegisteredMCP mcp)
 {
     return(Enum.GetName(mcp.GetType(), mcp).Replace("MC", "").Replace("_", ".").Trim());
 }
Exemple #6
0
        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();
        }