예제 #1
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);
            }
        }
예제 #2
0
        public GenerationForm(CMakeProject project, CMakeGenerator generator, bool shouldClean)
        {
            InitializeComponent( );

            m_project = project;

            Text = "Generate " + project.DisplayName;

            m_binaryDir = Path.GetFullPath(
                Path.Combine(kIntDirPrefix + generator.IntermediateDirectory,
                             project.DisplayName
                             )
                ).Replace('\\', '/');

            m_sourceDir = Path.GetDirectoryName(project.Path).Replace('\\', '/');

            if (shouldClean)
            {
                try
                {
                    Directory.Delete(m_binaryDir, true);
                }
                catch
                {
                    // ignored
                }
            }

            if (!Directory.Exists(m_binaryDir))
            {
                Directory.CreateDirectory(m_binaryDir);
            }

            var cmakeArgs = string.Format(
                "-D CMAKE_MODULE_PATH:PATH=\"{0}\" -G \"{1}\" \"{2}\"",
                CMakeProject.ModuleDirectory.Replace('\\', '/'),
                generator.Name.Replace('\\', '/'),
                m_sourceDir
                );

            try
            {
                m_cmakeProcess = new Process
                {
                    StartInfo =
                    {
                        CreateNoWindow         = true,
                        RedirectStandardError  = true,
                        RedirectStandardOutput = true,
                        FileName         = CMakeGenerator.ExecutableName,
                        Arguments        = cmakeArgs,
                        UseShellExecute  = false,
                        WorkingDirectory = m_binaryDir
                    },
                    EnableRaisingEvents = true
                };


                m_cmakeProcess.OutputDataReceived += cmakeOnData;
                m_cmakeProcess.ErrorDataReceived  += cmakeOnError;
                m_cmakeProcess.Exited             += cmakeOnExit;

                m_cmakeProcess.Start( );
                m_cmakeProcess.BeginOutputReadLine( );
                m_cmakeProcess.BeginErrorReadLine( );
            }
            catch
            {
                MessageBox.Show(
                    string.Format("Unable to execute \"{0}\".\n\nMake sure your path is correct.", CMakeGenerator.ExecutableName),
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                Close( );
            }
        }