Exemplo n.º 1
0
        private void BuildForgeClientJar()
        {
            ForgeProcessor MCForge = ForgeProcessor.FromJson(File.ReadAllText(LibraryDir + _sForgeTree.Replace('/', '\\') + sForgeVersion + @"\install_profile.json").Trim());

            // download needes Libraries
            DownloadForgeProcessorLibraries(MCForge);

            // (re-)create Temp-Dir
            sForgeTempDir = LibraryDir + _sForgeTree.Replace('/', '\\') + sForgeVersion + @"\temp";
            if (!Directory.Exists(sForgeTempDir))
            {
                Directory.CreateDirectory(sForgeTempDir);
            }

            // extract data/client.lzma
            List <string> extractList = new List <string>
            {
                "data/client.lzma"
            };

            dhelper.ExtractZipFiles(sForgeInstallerFile, sForgeTempDir, extractList, true);

            if (!File.Exists(LibraryDir + _sForgeTree.Replace('/', '\\') + sForgeVersion + @"\forge-" + sForgeVersion + "-client.jar"))
            {
                // Processors
                foreach (Processor processor in MCForge.Processors)
                {
                    RunProccessor(MCForge, processor);
                }
            }
        }
Exemplo n.º 2
0
        private void DownloadForgeProcessorLibraries(ForgeProcessor Forge)
        {
            foreach (Json.GameVersion.Library lib in Forge.Libraries)
            {
                string[]            sLibName = lib.Name.Split(':');
                VersionJsonDownload download;

                // dont download Forge itself
                if (sLibName[0].Equals("net.minecraftforge") && sLibName[1].Equals("forge"))
                {
                    List <string> extractList = new List <string>
                    {
                        "maven/" + lib.Downloads.Artifact.Path
                    };
                    dhelper.ExtractZipFiles(sForgeInstallerFile, sForgeVersionDir, extractList, false);
                    continue;
                }

                download      = lib.Downloads.Artifact;
                download.Path = LibraryDir + @"\" + download.Path.Replace("/", @"\");

                // fix for typesafe libraries
                if (sLibName[0].Contains("org.apache.logging.log4j"))
                {
                    download.Url = new Uri("http://central.maven.org/maven2/" + sLibName[0].Replace('.', '/') + "/" + sLibName[1] + "/" + sLibName[2] + "/" + sLibName[1] + "-" + sLibName[2] + ".jar");
                }
                dhelper.DownloadFileTo(download.Url, download.Path);
            }
        }
Exemplo n.º 3
0
        private void RunProccessor(ForgeProcessor Forge, Processor processor)
        {
            Debug.WriteLine("******************************************************");
            Configuration C = new Configuration();

            // get path to jar file
            string jarFile = MavenStringToFilePath(processor.Jar);

            // file exists
            if (!File.Exists(LibraryDir + "/" + jarFile))
            {
                Debug.WriteLine("file: " + jarFile + " not exists");
                return;
            }

            // get main class of Jar file
            string mainClass = GetMainClass(LibraryDir + "/" + jarFile);

            if (mainClass == null)
            {
                Debug.WriteLine("file: " + jarFile + " has no main class");
                return;
            }
            Debug.WriteLine("MainClass: " + mainClass);

            string args = "-cp " + BuildProcessClassPath(processor);

            args += " " + mainClass + " ";
            args += BuildProcArgs(Forge, processor);

            Process proc = new Process();

            proc.StartInfo.FileName               = C.GetJavaPath();
            proc.StartInfo.WorkingDirectory       = sForgeTempDir;
            proc.StartInfo.Arguments              = args;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError  = true;
            proc.StartInfo.UseShellExecute        = false;
            proc.StartInfo.CreateNoWindow         = true;
            proc.OutputDataReceived              += new DataReceivedEventHandler(Proc_OutputDataReceived);
            proc.ErrorDataReceived  += new DataReceivedEventHandler(Proc_OutputDataReceived);
            proc.EnableRaisingEvents = true;
            proc.Start();
            proc.BeginOutputReadLine();
            proc.BeginErrorReadLine();
            proc.WaitForExit();
            proc.Close();
            proc.Dispose();
        }
Exemplo n.º 4
0
        private string BuildProcArgs(ForgeProcessor Forge, Processor processor)
        {
            string args = null;

            foreach (string arg in processor.Args)
            {
                string newarg = arg;

                if (arg.Equals("{MINECRAFT_JAR}"))
                {
                    args += " " + VersionDir + @"\" + Forge.Minecraft + @"\" + Forge.Minecraft + ".jar";
                    continue;
                }

                // contains var?
                if (newarg.StartsWith("{") && newarg.EndsWith("}"))
                {
                    // remove chars
                    newarg = newarg.Replace("{", "").Replace("}", "");
                    newarg = Forge.Data[newarg].Client;
                }

                // remove leading slash
                if (newarg.StartsWith("/"))
                {
                    newarg = newarg.Remove(0, 1);
                }

                // contains maven string?
                if (newarg.StartsWith("[") && newarg.EndsWith("]"))
                {
                    newarg = LibraryDir + @"\" + MavenStringToFilePath(newarg.Replace("[", "").Replace("]", "")).Replace('/', '\\');
                }
                args += " " + newarg;
            }

            Debug.WriteLine("Args: " + args);
            return(args);
        }