Esempio n. 1
0
        public override bool Compile(out string scriptFilePath, params string[] additionalSourceFiles)
        {
            var inputScript = Path.Combine(Options.OutputDirectory, "files.j");

            using (var inputScriptStream = FileProvider.OpenNewWrite(inputScript))
            {
                using (var streamWriter = new StreamWriter(inputScriptStream))
                {
                    foreach (var file in Directory.EnumerateFiles(Options.SourceDirectory, "*.j", SearchOption.AllDirectories))
                    {
                        streamWriter.WriteLine($"//! import \"{file}\"");
                    }

                    /*foreach (var reference in references)
                     * {
                     *  foreach (var file in reference.EnumerateFiles("*.j", SearchOption.AllDirectories, null))
                     *  {
                     *      streamWriter.WriteLine($"//! import \"{file}\"");
                     *  }
                     * }*/

                    foreach (var file in additionalSourceFiles)
                    {
                        streamWriter.WriteLine($"//! import \"{file}\"");
                    }
                }
            }

            var outputScript = "war3map.j";

            scriptFilePath = Path.Combine(Options.OutputDirectory, outputScript);
            var jasshelperOutputScript = Path.Combine(Options.OutputDirectory, Options.Obfuscate ? "war3map.original.j" : outputScript);
            var jasshelperOptions      = Options.Debug ? "--debug" : Options.Optimize ? string.Empty : "--nooptimize";
            var jasshelper             = Process.Start(_jasshelperPath, $"{jasshelperOptions} --scriptonly \"{_commonPath}\" \"{_blizzardPath}\" \"{inputScript}\" \"{jasshelperOutputScript}\"");

            jasshelper.WaitForExit();

            var success = jasshelper.ExitCode == 0;

            if (success && Options.Obfuscate)
            {
                JassObfuscator.Obfuscate(jasshelperOutputScript, scriptFilePath, _commonPath, _blizzardPath);
            }

            return(success);
        }
Esempio n. 2
0
        public override CompileResult Compile(out string scriptFilePath, params string[] additionalSourceFiles)
        {
            var outputScript = "war3map.j";

            scriptFilePath = Path.Combine(Options.OutputDirectory, outputScript);

            var jasshelperPath = Options.JasshelperCliPath;

            if (string.IsNullOrEmpty(jasshelperPath) || !File.Exists(jasshelperPath))
            {
                return(new CompileResult(false, new[] { Microsoft.CodeAnalysis.Diagnostic.Create(DiagnosticProvider.MissingPathJasshelper, null, jasshelperPath) }));
            }

            var commonPath = Options.CommonJPath;

            if (string.IsNullOrEmpty(commonPath) || !File.Exists(commonPath))
            {
                return(new CompileResult(false, new[] { Microsoft.CodeAnalysis.Diagnostic.Create(DiagnosticProvider.MissingPathCommonJ, null, commonPath) }));
            }

            var blizzardPath = Options.BlizzardJPath;

            if (string.IsNullOrEmpty(blizzardPath) || !File.Exists(blizzardPath))
            {
                return(new CompileResult(false, new[] { Microsoft.CodeAnalysis.Diagnostic.Create(DiagnosticProvider.MissingPathBlizzardJ, null, blizzardPath) }));
            }

            var inputScript = Path.Combine(Options.OutputDirectory, "files.j");

            using (var inputScriptStream = FileProvider.CreateFileAndFolder(inputScript))
            {
                using (var streamWriter = new StreamWriter(inputScriptStream))
                {
                    foreach (var file in Directory.EnumerateFiles(Options.SourceDirectory, "*.j", SearchOption.AllDirectories))
                    {
                        streamWriter.WriteLine($"//! import \"{file}\"");
                    }

                    /*foreach (var reference in references)
                     * {
                     *  foreach (var file in reference.EnumerateFiles("*.j", SearchOption.AllDirectories, null))
                     *  {
                     *      streamWriter.WriteLine($"//! import \"{file}\"");
                     *  }
                     * }*/

                    foreach (var file in additionalSourceFiles)
                    {
                        streamWriter.WriteLine($"//! import \"{file}\"");
                    }
                }
            }

            var jasshelperOutputScript = Path.Combine(Options.OutputDirectory, Options.Obfuscate ? "war3map.original.j" : outputScript);
            var jasshelperOptions      = Options.Debug ? "--debug" : Options.Optimize ? string.Empty : "--nooptimize";
            var jasshelper             = Process.Start(Options.JasshelperCliPath, $"{jasshelperOptions} --scriptonly \"{commonPath}\" \"{blizzardPath}\" \"{inputScript}\" \"{jasshelperOutputScript}\"");

            jasshelper.WaitForExit();

            var success     = jasshelper.ExitCode == 0;
            var diagnostics = new List <Microsoft.CodeAnalysis.Diagnostic>();

            if (success)
            {
                if (Options.Obfuscate)
                {
                    JassObfuscator.Obfuscate(jasshelperOutputScript, scriptFilePath, commonPath, blizzardPath);
                }
            }
            else
            {
                while (!jasshelper.StandardOutput.EndOfStream)
                {
                    // TODO: parse stdout
                    // diagnostics.Add(Diagnostic.Create())
                    jasshelper.StandardOutput.ReadLine();
                }
            }

            return(new CompileResult(success, diagnostics));
        }