示例#1
0
        public void CreateLvl(string outputPath, string saveFileName, string platform, bool supressPopups)
        {
            if (!outputPath.EndsWith("\\"))
            {
                outputPath += "\\";
            }

            string workspace    = outputPath + ".\\__LVLTOOL__workspace__\\";
            string munge_dir    = outputPath + ".\\__LVLTOOL__workspace__\\MUNGED\\";
            string saveFilePath = outputPath + saveFileName;

            if (Directory.Exists(workspace))
            {
                Directory.Delete(workspace, true);
            }
            Directory.CreateDirectory(workspace);
            Directory.CreateDirectory(munge_dir);
            string reqContent  = GetReqString();
            string reqFileName = mOutputFilenameTextbox.Text.ToLower().Replace(".lvl", ".req");

            File.WriteAllText(workspace + reqFileName, reqContent);

            // now copy the files over to the workspace
            foreach (MungableItem item in mListBox.Items)
            {
                if (AlreadyMunged(item.Path))
                {
                    File.Copy(item.Path, munge_dir + item.FileName);
                }
                else
                {
                    File.Copy(item.Path, workspace + item.FileName);
                }
            }
            // now munge & pack

            string configMunge  = Program.ModToolsDir + "ToolsFL\\bin\\ConfigMunge.exe";
            string textureMunge = Program.ModToolsDir + "ToolsFL\\bin\\pc_TextureMunge.exe";
            string scriptMunge  = Program.ModToolsDir + "ToolsFL\\bin\\ScriptMunge.exe";
            string lvlPack      = Program.ModToolsDir + "ToolsFL\\bin\\levelpack.exe";

            if (OverrideLevelPack != null)
            {
                lvlPack = OverrideLevelPack;
            }
            if (OverrideScriptMunge != null)
            {
                scriptMunge = OverrideScriptMunge;
            }

            string req_file_noext = reqFileName.Replace(".req", "");
            string configArgs     = string.Format(
                " -inputfile $*.mcfg -continue  -QUIET -platform {0} -sourcedir  {1} -outputdir {2} -hashstrings ",
                platform, workspace, munge_dir);
            string scriptArgs = string.Format(
                " -inputfile *.lua -continue  -QUIET -platform {0} -sourcedir  {1} -outputdir {2} ",
                platform, Path.GetFullPath(workspace), munge_dir);
            string texArgs = string.Format(
                " -inputfile $*.tga -checkdate -continue -QUIET -platform {0} -sourcedir  {1} -outputdir {2}  ",
                platform, workspace, munge_dir);
            string lvlPackArgs = string.Format(
                "-inputfile {0}.req -writefiles {1}{0}.files -continue -QUIET -platform {2} -sourcedir  {3} -inputdir {1} -outputdir {3}  ",
                req_file_noext, munge_dir, platform, Path.GetFullPath(workspace));
            //string programOutput = Program.RunCommand(program_exe, args, true);
            string programOutput = "";

            if (File.Exists(scriptMunge))
            {
                programOutput += Program.RunCommand(scriptMunge, scriptArgs, true);
            }
            if (File.Exists(configMunge))
            {
                programOutput += Program.RunCommand(configMunge, configArgs, true);
            }
            if (File.Exists(textureMunge))
            {
                programOutput += Program.RunCommand(textureMunge, texArgs, true);
            }
            programOutput += Program.RunCommand(lvlPack, lvlPackArgs, true);
            string batchFileContents = string.Format(
                "{0} {1}\n\n{2} {3}\n\n{4} {5}\n\n{6} {7}\n\n",
                textureMunge, String.Format("-inputfile $*.tga  -checkdate -continue -platform {0} -sourcedir . -outputdir MUNGED ", platform),
                scriptMunge, String.Format("-inputfile *.lua   -continue -platform {0} -sourcedir  . -outputdir MUNGED  ", platform),
                configMunge, String.Format("-inputfile $*.mcfg -continue -platform {0} -sourcedir . -outputdir MUNGED -hashstrings ", platform),
                lvlPack, String.Format("-inputfile {0}.req -writefiles MUNGED\\{0}.files -continue -platform {1} -sourcedir  . -inputdir MUNGED\\ -outputdir . ",
                                       req_file_noext, platform)
                );
            // copy output to user's choice directory
            string lvlOutput = workspace + req_file_noext + ".lvl";

            if (File.Exists(lvlOutput))
            {
                File.WriteAllText(workspace + "munge.bat", batchFileContents);
                File.WriteAllText(workspace + "munge.log", programOutput);
                File.Copy(lvlOutput, saveFilePath, true);
                if (!supressPopups)
                {
                    MessageForm.ShowMessage("Saved lvl file", "Saved to: " + saveFilePath, SystemIcons.Information, false, false);
                }
                else
                {
                    Console.WriteLine("Saved lvl file to: " + saveFilePath);
                }
                if (Directory.Exists(workspace)) // allow the user to rename in order to keep the workspace
                {
                    Directory.Delete(workspace, true);
                }
            }
            else
            {
                if (!supressPopups)
                {
                    MessageForm.ShowMessage("Error creating lvl file", "Something went wrong:\n" + programOutput);
                }
                else
                {
                    Console.WriteLine("Error creating lvl file :\n" + programOutput);
                }
            }
        }