Beispiel #1
0
        public static void Init(IEnumerable <string> fileNames)
        {
            if (m_firstRun)
            {
                MyVSCompiler.DependencyCollector.CollectReferences(MyPlugins.GameAssembly);
                m_firstRun = false;
            }

            m_defaultPreprocessor.Clear();

            foreach (var fileName in fileNames)
            {
                m_defaultPreprocessor.AddFile(fileName);
            }

            var tempFiles      = new List <string>();
            var filesToCompile = m_defaultPreprocessor.FileSet;
            var scriptBuilder  = new MyVisualScriptBuilder();

            foreach (var absoluteFilePath in filesToCompile)
            {
                scriptBuilder.ScriptFilePath = absoluteFilePath;
                if (!scriptBuilder.Load() || !scriptBuilder.Build())
                {
                    Debug.Fail("One of dependencies of " + scriptBuilder.ScriptName + " failed to build. Script wont be built.");
                    continue;
                }

                tempFiles.Add(Path.Combine(Path.GetTempPath(), scriptBuilder.ScriptName + ".cs"));
                File.WriteAllText(tempFiles[tempFiles.Count - 1], scriptBuilder.Syntax);
            }

            m_defaultCompiler = new MyVSCompiler("MyVSDefaultAssembly", tempFiles);

            if (filesToCompile.Length > 0)
            {
                if (!m_defaultCompiler.Compile() || !m_defaultCompiler.LoadAssembly())
                {
                    Debug.Fail("Default Compiler failed to compile or load VS assembly.");
                }
            }

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (!MyFinalBuildConstants.IS_DEBUG)
            {
                foreach (var tempFile in tempFiles)
                {
                    File.Delete(tempFile);
                }
            }
        }
        public static void Init(IEnumerable<string> fileNames)
        {
            if (m_firstRun)
            {
                MyVSCompiler.DependencyCollector.CollectReferences(MyPlugins.GameAssembly);
                m_firstRun = false;
            }

            m_defaultPreprocessor.Clear();

            foreach (var fileName in fileNames)
                m_defaultPreprocessor.AddFile(fileName);
            
            var tempFiles = new List<string>();
            var filesToCompile = m_defaultPreprocessor.FileSet;
            var scriptBuilder = new MyVisualScriptBuilder();

            foreach (var absoluteFilePath in filesToCompile)
            {
                scriptBuilder.ScriptFilePath = absoluteFilePath;
                if(!scriptBuilder.Load() || !scriptBuilder.Build())
                {
                    Debug.Fail("One of dependencies of " + scriptBuilder.ScriptName + " failed to build. Script wont be built.");
                    continue;
                }

                tempFiles.Add(Path.Combine(Path.GetTempPath(), scriptBuilder.ScriptName + ".cs"));
                File.WriteAllText(tempFiles[tempFiles.Count - 1], scriptBuilder.Syntax);
            }

            m_defaultCompiler = new MyVSCompiler("MyVSDefaultAssembly", tempFiles);

            if (filesToCompile.Length > 0)
                if(!m_defaultCompiler.Compile() || !m_defaultCompiler.LoadAssembly())
                {
                    Debug.Fail("Default Compiler failed to compile or load VS assembly.");
                }

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if(!MyFinalBuildConstants.IS_DEBUG)
                foreach (var tempFile in tempFiles)
                    File.Delete(tempFile);
        }