Exemplo n.º 1
0
        public static void GenerateMain(string entryType, string entryNamespace, bool inputArgs)
        {
            StreamWriter writer = new StreamWriter(FileWritterManager.WorkingPath + "main.cpp");

            string   txt;
            Template template;

            string altTools = Environment.GetEnvironmentVariable("ALTERNATIVE_TOOLS_PATH");

            if (altTools == null)
            {
                altTools = Path.Combine(Environment.CurrentDirectory, (@"..\..\..\Tools").Replace('\\', '/'));
            }

            StreamReader sr = new StreamReader((altTools + @"\Templates\Code\main.stg").Replace('\\', '/'));

            txt      = sr.ReadToEnd();
            template = new Template(txt);

            StreamReader fs     = new StreamReader(Path.Combine(altTools, "Text/notice"));
            string       notice = fs.ReadToEnd();

            template.Add("NOTICE", notice);
            template.Add("ENTRY_TYPE", entryType);
            template.Add("ENTRY_NAMESPACE_NEEDED", !String.IsNullOrEmpty(entryNamespace));
            template.Add("ENTRY_NAMESPACE", entryNamespace);
            template.Add("INPUT_ARGS", inputArgs);

            string output = template.Render();

            writer.Write(output);
            writer.Flush();
            writer.Close();

            FileWritterManager.AddSourceFile("main.cpp");
        }
Exemplo n.º 2
0
        public int Run()
        {
            String assemblyLocation = "";

            Utils.WriteToConsole("\n");
            Utils.WriteToConsole("Executing alternative command --> " + Config.Command);

            if (System.Environment.GetEnvironmentVariable("ALTERNATIVE_TOOLS_PATH") == null)
            {
                Utils.WriteToConsole("ALTERNATIVE_TOOLS_PATH not setted, please execute alternative-init command");
            }
            else
            {
                Config.AlterNativeTools = System.Environment.GetEnvironmentVariable("ALTERNATIVE_TOOLS_PATH");
            }

            string outputDir = Utils.InitOutputPath(Config.OutputPath);

            AssemblyDefinition adef = null;

            if (Config.Command == "new")
            {
                adef             = Commands.NewTemplate(new DirectoryInfo(outputDir));
                assemblyLocation = Config.AlterNativeTools + @"/Templates/Blank";
            }
            else if (Config.Command == "make")
            {
                int           cmakeCode;
                DirectoryInfo buildDir    = Commands.RunCMake(new DirectoryInfo(outputDir), out cmakeCode);
                int           compileCode = Commands.Compile(buildDir);
                if (cmakeCode == 0 && compileCode == 0)
                {
                    return(0);
                }
                else if (cmakeCode == 0 && compileCode != 0)
                {
                    return(-1);
                }
                else
                {
                    return(-2);
                }
            }
            else
            {
                //LOAD TARGET ASSEMBLY
                adef = Commands.LoadAssembly(Config.Extra[0].Replace('\\', '/'));

                //Hakan648 - fixed: Length cannot be less than zero.
                bool isTargetInADir = Config.Extra[0].Contains('\\');

                if (isTargetInADir)
                {
                    assemblyLocation = Path.GetDirectoryName(Config.Extra[0]);
                }
                else
                {
                    assemblyLocation = Environment.CurrentDirectory;
                }
            }

            if (Config.Extra[0].EndsWith("dll"))
            {
                Config.targetType = TargetType.DynamicLinkLibrary;
            }
            else if (Config.Extra[0].EndsWith("exe"))
            {
                Config.targetType = TargetType.Executable;
            }
            //else if (Config.Extra[0].EndsWith("cs"))
            //{
            //    Commands.CompileNetCode(new FileInfo(Config.Extra[0]));
            //    Config.targetType = TargetType.DynamicLinkLibrary;
            //}
            //else
            //{
            //    DirectoryInfo di = new DirectoryInfo(Config.Extra[0]);
            //    if (di.Exists)
            //        Commands.CompileNetCode(di);
            //}

            if (!Directory.Exists(outputDir))
            {
                Utils.WriteToConsole(outputDir + " does not exists. Created");
                Directory.CreateDirectory(outputDir);
            }
            else
            {
                Utils.CleanDirectory(new DirectoryInfo(outputDir));
            }

            try
            {
                DecompileAssembly(adef, outputDir, assemblyLocation);

                if (System.Environment.GetEnvironmentVariable("ALTERNATIVE_CPP_LIB_PATH") != null)
                {
                    Config.AlterNativeLib = System.Environment.GetEnvironmentVariable("ALTERNATIVE_CPP_LIB_PATH");
                }
                else
                {
                    Config.AlterNativeLib = @"../../../Lib/src";

                    Utils.WriteToConsole("ALTERNATIVE_CPP_LIB_PATH not defined, please execute alternative-init command");
                    Utils.WriteToConsole("Trying to locate the library at: " + Config.AlterNativeLib);
                }

                // Commands.CopyLibFiles(new DirectoryInfo(outputDir));
                //TRIM END .EXE : BUG If The name is File.exe, trim end ".exe" returns Fil !!!!
                string name = adef.MainModule.Name.Substring(0, adef.MainModule.Name.Length - 4);
                CMakeGenerator.GenerateCMakeLists(name + "Proj", name, outputDir, FileWritterManager.GetSourceFiles(), Config.Release);

                return(0);
            }
            catch (Exception e)
            {
                Utils.WriteToConsole("alternative: ");
                Utils.WriteToConsole(e.Message);
                Utils.WriteToConsole(e.StackTrace);
                return(-1);
            }
        }