Esempio n. 1
0
            public static Process LaunchWithoutDebugger(string exe, string args, bool ShowConsole)
            {
                StopExecution();

                if (!File.Exists(exe))
                {
                    ErrorLogger.Log(exe + " not found", ErrorType.Error, ErrorOrigin.Program);
                    return(null);
                }

                IDEManager.Instance.MainWindow.LeftStatusText = "Launch " + Path.GetFileName(exe) + " without debugger";

                // Make all documents read-only
                WorkbenchLogic.Instance.AllDocumentsReadOnly = true;

                try
                {
                    if (ShowConsole)
                    {
                        CurrentProcess = FileExecution.ExecuteAsync(exe, args, Path.GetDirectoryName(exe), CurrentProcess_Exited);
                    }
                    else
                    {
                        CurrentProcess = FileExecution.ExecuteSilentlyAsync(exe, args, Path.GetDirectoryName(exe),
                                                                            CurrentProcess_OutputDataReceived, CurrentProcess_ErrorDataReceived, CurrentProcess_Exited);
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex, ErrorType.Error, ErrorOrigin.Program);
                }

                Instance.UpdateGUI();
                return(CurrentProcess);
            }
Esempio n. 2
0
 public Processor(ProcessorArgs processorArgs)
 {
     ProcessorArgs = processorArgs;
     //
     ExternalTools   = new ExternalTools(ProcessorArgs.ConfigurationMain.Paths);
     FileExecution   = new FileExecution(ExternalTools);
     FilePreparation = new FilePreparation(ExternalTools);
     FileInformation = new FileInformation();
 }
Esempio n. 3
0
        public static void DoUpdate()
        {
            if (!File.Exists(UpdaterExe))
            {
                ErrorLogger.Log(UpdaterExe + " not found! Cannot proceed with update!", ErrorType.Error, ErrorOrigin.System);
                return;
            }

            // Start the updater
            var upt = FileExecution.ExecuteAsync(UpdaterExe, "-a -o \"" + ApplicationStartUpPath + "\"", ApplicationStartUpPath, null);

            // Close main window - the D-IDE.exe will be overwritten!
            IDEManager.Instance.MainWindow.Dispatcher.Invoke(new Action(() =>
                                                                        IDEManager.Instance.MainWindow.Close()));
        }
Esempio n. 4
0
        public BuildResult CompileSource(SourceModule Module, DMDConfig dmd, bool DebugCompile, string objFile, string execDirectory)
        {
            var obj = Path.ChangeExtension(objFile, ".obj");
            var br  = new BuildResult()
            {
                SourceFile = Module.AbsoluteFileName, TargetFile = obj, Successful = true
            };

            ErrorLogger.Log("Compile " + (Module.Project != null?Module.Project.ToRelativeFileName(Module.FileName):Module.FileName), ErrorType.Information, ErrorOrigin.Build);

            var dmd_exe = dmd.SoureCompiler;

            // Always enable it to use environment paths to find dmd.exe
            if (!Path.IsPathRooted(dmd_exe) && Directory.Exists(dmd.BaseDirectory))
            {
                dmd_exe = Path.Combine(dmd.BaseDirectory, dmd.SoureCompiler);
            }

            TempPrc = FileExecution.ExecuteSilentlyAsync(dmd_exe,
                                                         BuildDSourceCompileArgumentString(dmd.BuildArguments(DebugCompile).SoureCompiler, Module.AbsoluteFileName, obj, dmd.ImportDirectories), // Compile our program always in debug mode
                                                         execDirectory,
                                                         OnOutput, delegate(string s) {
                var err = ParseErrorMessage(s);
                if (Module.Project != null && Module.Project.ContainsFile(err.FileName))
                {
                    err.Project = Module.Project;
                }
                if (err.Type == GenericError.ErrorType.Error)
                {
                    br.Successful = false;
                }
                br.BuildErrors.Add(err);
            }, OnExit);

            if (TempPrc != null && !TempPrc.HasExited)
            {
                TempPrc.WaitForExit(MaxCompilationTime);
            }

            br.Successful = br.Successful && TempPrc != null && TempPrc.ExitCode == 0 && File.Exists(obj);
            return(br);
        }
Esempio n. 5
0
        private void StartProcess3(object o)
        {
            try
            {
                ProcessorArgs     processorArgs = (ProcessorArgs)o;
                ConfigurationMain mainCfg       = processorArgs.ConfigurationMain;
                //
                FileExecution.ExecuteTreat(processorArgs.Orders, mainCfg, false);
                //
                if (mainCfg.PassBsa.Enabled)
                {
                    if (mainCfg.PassBsa.MustRepack())
                    {
                        FileExecution.RepackBsa(processorArgs.BsaOrders, mainCfg.PassBsa.GameParameter, mainCfg.IsUseMultithreading, mainCfg.IsVerbose);
                    }
                    if (mainCfg.PassBsa.MustClean())
                    {
                        FileExecution.CleanBsa(processorArgs.BsaOrders, mainCfg.IsVerbose);
                    }
                }
                //
                if (mainCfg.IsMergeActivated)
                {
                    if (mainCfg.IsUnmergeActivated)
                    {
                        FileExecution.DeleteFiles(mainCfg, processorArgs.DeleteOrders);
                    }
                    else
                    {
                        FileExecution.Merge(mainCfg, processorArgs.CopyOrders);
                    }
                }
                //
                if (mainCfg.PassBsa.Enabled && mainCfg.PassBsa.IsRepackLooseFilesInBsa)
                {
                    var bsaToProcess = mainCfg.PassBsa.IsIntelligentPacking ?
                                       FileUtils.GetIntelligentPacking(mainCfg.Selection, mainCfg.PathSource, mainCfg.PassBsa.GameParameter, mainCfg.PassBsa.IsRepackCreateDummy, mainCfg.IsVerbose) :
                                       FileUtils.PrepareForPacking(mainCfg.PassBsa.Repacks, mainCfg.PathSource, mainCfg.PassBsa.GameParameter, true, mainCfg.IsVerbose);



                    List <DirectoryInfo> dirToDeleteIfFail = new List <DirectoryInfo>();
                    foreach (InformationRepackBsa informationRepackBsa in bsaToProcess)
                    {
                        ExternalTools.CallBsaPack(Path.Combine(informationRepackBsa.Source.FullName, informationRepackBsa.CurrentBsaName),
                                                  informationRepackBsa.CurrentTarget.FullName, informationRepackBsa.IsCompressed, informationRepackBsa.GameParameter, mainCfg.IsUseMultithreading, mainCfg.IsVerbose);
                        //
                        informationRepackBsa.CurrentTarget.Refresh();
                        if (informationRepackBsa.CurrentTarget.Exists)
                        {
                            try
                            {
                                FileUtils.DeleteCompleteDirectory(informationRepackBsa.CurrentTarget);
                            }
                            catch
                            {
                                dirToDeleteIfFail.Add(informationRepackBsa.CurrentTarget);
                            }
                        }
                    }
                    //
                    foreach (DirectoryInfo directoryInfo in dirToDeleteIfFail)
                    {
                        FileUtils.DeleteCompleteDirectory(directoryInfo);
                    }
                }
                //Cleaning empty subdir
                if (mainCfg.IsBackupActivated && mainCfg.IsRefreshBackup)
                {
                    FileInformation.CleanEmptySubdir(mainCfg.PathBackup);
                }
                //Cleaning no present source subdir
                if (mainCfg.IsBackupActivated && mainCfg.IsCleanBackup)
                {
                    FileInformation.CleanBackupFromSource(mainCfg.PathSource, mainCfg.PathBackup);
                }
                //
                if (mainCfg.IsShowResults)
                {
                    var infoTextures = new DirectoryInfo(mainCfg.PathSource);
                    //
                    foreach (var directoryInfo in infoTextures.GetDirectories())
                    {
                        processorArgs.Folders[directoryInfo.Name].NewSize = FileUtils.CalculateDirectorySizeMo(directoryInfo, mainCfg.PassBsa.Enabled);
                    }
                    processorArgs.Folders[infoTextures.Name].NewSize = FileUtils.CalculateDirectorySizeMo(infoTextures, mainCfg.PassBsa.Enabled);
                    // Show sizes before/after resizes
                    Logger.Log("Results: (Size before resize in Mo => current size in Mo)");
                    foreach (var keyValuePair in processorArgs.Folders.OrderBy(e => e.Value.Size))
                    {
                        Logger.Log("{0,15:F2} Mo => {1,15:F2} Mo {2}",
                                   keyValuePair.Value.Size,
                                   keyValuePair.Value.NewSize,
                                   keyValuePair.Key);
                    }
                }

                OnProcessorEnded(-1);
            }
            catch (AggregateException e)
            {
                Logger.Log(e);
                foreach (Exception innerException in e.InnerExceptions)
                {
                    Logger.Log(innerException);
                }
                OnProcessorEnded(-1);
            }
            catch (Exception e)
            {
                Logger.Log(e);
                OnProcessorEnded(-1);
            }
        }
Esempio n. 6
0
 private void StartProcess1(object o)
 {
     try
     {
         ProcessorArgs     processorArgs = (ProcessorArgs)o;
         ConfigurationMain mainCfg       = processorArgs.ConfigurationMain;
         //
         if (mainCfg.IsShowResults)
         {
             Logger.Log("Preparing futur results data");
             var infoTextures = new DirectoryInfo(mainCfg.PathSource);
             //
             foreach (var directoryInfo in infoTextures.GetDirectories())
             {
                 processorArgs.Folders.Add(directoryInfo.Name,
                                           new InformationDirectory {
                     Size = FileUtils.CalculateDirectorySizeMo(directoryInfo, mainCfg.PassBsa.Enabled)
                 });
             }
             processorArgs.Folders.Add(infoTextures.Name,
                                       new InformationDirectory {
                 Size = FileUtils.CalculateDirectorySizeMo(infoTextures, mainCfg.PassBsa.Enabled)
             });
         }
         //
         if (mainCfg.PassBsa.Enabled)
         {
             FileInformation.GetFileInfos(mainCfg.PathSource, mainCfg.PathBackup, processorArgs.FilesBsa, true, mainCfg);
             FilePreparation.PrepareTreat(processorArgs.FilesBsa, mainCfg, processorArgs.BsaOrders, null, null, true);
             FileExecution.ExecuteTreat(processorArgs.BsaOrders, mainCfg, true);
             if (mainCfg.PassBsa.MustUnpack())
             {
                 FileExecution.UnpackBsa(processorArgs.BsaOrders, mainCfg);
             }
             if (mainCfg.PassBsa.IsCopyAsLoose)
             {
                 if (mainCfg.PassBsa.IsCopyAsLooseIfDummy)
                 {
                     List <InformationOrder> confirmedBsaUnpack = new List <InformationOrder>();
                     List <InformationCopy>  confirmedDeletes   = new List <InformationCopy>();
                     foreach (InformationOrder bsaOrder in processorArgs.BsaOrders)
                     {
                         var      bsaName = Path.GetFileNameWithoutExtension(bsaOrder.FileSource.FullName);
                         var      espName = bsaName.ToUpper().Replace(" - TEXTURES", "").Replace("- TEXTURES", "");
                         var      espFile = Path.Combine(bsaOrder.FileSource.Directory.FullName, string.Format("{0}.esp", espName));
                         FileInfo dummy   = new FileInfo("dummy.esp");
                         if (!dummy.Exists)
                         {
                             throw new Exception("No dummy esp to compare from. A dummy.esp file must be present in Octagon directory.");
                         }
                         FileInfo esp = new FileInfo(espFile);
                         if (esp.Exists && dummy.Length == esp.Length)
                         {
                             confirmedBsaUnpack.Add(bsaOrder);
                             if (!confirmedDeletes.Any(e => string.Equals(e.Target, espFile, StringComparison.OrdinalIgnoreCase)))
                             {
                                 confirmedDeletes.Add(new InformationCopy(null, espFile, false, false));
                             }
                         }
                     }
                     FileExecution.CopyBsaAsLooseSimplified(confirmedBsaUnpack, mainCfg);
                     foreach (InformationCopy confirmedDelete in confirmedDeletes)
                     {
                         FileUtils.ExecuteCopyOrDelete(confirmedDelete);
                     }
                 }
                 else
                 {
                     FileExecution.CopyBsaAsLooseSimplified(processorArgs.BsaOrders, mainCfg);
                 }
             }
         }
         //
         if (mainCfg.HasTextureOperation() || (mainCfg.IsBackupActivated && mainCfg.IsRecopyOriginal))
         {
             FileInformation.GetFileInfos(mainCfg.PathSource, mainCfg.PathBackup, processorArgs.FilesDds, false, mainCfg);
         }
         OnProcessorEnded(2);
     }
     catch (AggregateException e)
     {
         Logger.Log(e);
         foreach (Exception innerException in e.InnerExceptions)
         {
             Logger.Log(innerException);
         }
         OnProcessorEnded(-1);
     }
     catch (Exception e)
     {
         Logger.Log(e);
         OnProcessorEnded(-1);
     }
 }
Esempio n. 7
0
            /// <summary>
            /// Launch the debugger asynchronously
            /// </summary>
            public static void LaunchWithDebugger(string exe, string args, string sourcePath, bool showConsole)
            {
                StopExecution();

                // Make all documents read-only
                WorkbenchLogic.Instance.AllDocumentsReadOnly = true;

                // If there's an external debugger specified and if it's wanted to launch it, start that one
                if (GlobalProperties.Instance.UseExternalDebugger)
                {
                    IDEManager.Instance.MainWindow.LeftStatusText = "Launch external debugger";
                    CurrentProcess = FileExecution.ExecuteAsync(GlobalProperties.Instance.ExternalDebugger_Bin,
                                                                AbstractBuildSupport.BuildArgumentString(GlobalProperties.Instance.ExternalDebugger_Arguments, new Dictionary <string, string> {
                        { "$sourcePath", sourcePath },
                        { "$targetDir", Path.GetDirectoryName(exe) },
                        { "$target", exe },
                        { "$exe", Path.ChangeExtension(exe, ".exe") },
                        { "$dll", Path.ChangeExtension(exe, ".dll") },
                        { "$args", args }
                    }),                             // %WINDBG_ARGS% Program.exe Arg1 Arg2
                                                                Path.GetDirectoryName(exe), CurrentProcess_Exited);

                    Instance.UpdateGUI();

                    return;
                }

                IDEManager.Instance.MainWindow.LeftStatusText = "Start debugging " + Path.GetFileName(exe);

                if (!dbgEngineInited)
                {
                    InitDebugger();
                }

                IsDebugging = true;
                Instance.UpdateGUI();
                EngineStarting       = true;
                StopWaitingForEvents = false;

                DebugCreateProcessOptions opt = new DebugCreateProcessOptions();

                opt.CreateFlags    = CreateFlags.DebugOnlyThisProcess | (showConsole ? CreateFlags.CreateNewConsole : 0);
                opt.EngCreateFlags = EngCreateFlags.Default;

                Engine.CreateProcessAndAttach(0, exe + (string.IsNullOrWhiteSpace(args) ? "" : (" " + args)), opt, Path.GetDirectoryName(exe), "", 0, 0);


                Engine.Symbols.SourcePath           = string.IsNullOrWhiteSpace(sourcePath) ? sourcePath : Path.GetDirectoryName(exe);
                Engine.IsSourceCodeOrientedStepping = true;

                Engine.WaitForEvent();
                Engine.Execute("bc");                 // Clear breakpoint list
                Engine.WaitForEvent();

                CoreManager.DebugManagement.CurrentDebugSupport.PostlaunchInit(Engine);
                BreakpointManagement.SetupBreakpoints();

                EngineStarting = false;

                WaitForDebugEvent();                 // Wait for the first breakpoint/exception/program exit to occur
            }
Esempio n. 8
0
        public override void BuildModule(SourceModule Module,
                                         string OutputDirectory,
                                         string ExecDirectory,
                                         bool DebugCompile,
                                         bool LinkToStandAlone)
        {
            var src = Module.AbsoluteFileName;

            var outputDir = Path.IsPathRooted(OutputDirectory) ? OutputDirectory : Path.Combine(Path.GetDirectoryName(src), OutputDirectory);

            // Ensure that target directory exists
            Util.CreateDirectoryRecursively(outputDir);

            // Compile .rc source file to res
            var res = Path.Combine(outputDir, Path.GetFileNameWithoutExtension(src) + ".res");

            // Check if creation can be skipped
            if (GlobalProperties.Instance.EnableIncrementalBuild && !Module.Modified && File.Exists(res))
            {
                Module.LastBuildResult = new BuildResult()
                {
                    SourceFile = src, TargetFile = res, Successful = true, NoBuildNeeded = true
                };
                return;
            }

            // Init returned BuildResult-object
            var br = new BuildResult()
            {
                SourceFile = src, TargetFile = res, Successful = true
            };

            // Print verbose information message
            ErrorLogger.Log("Compile " + (Module.Project != null ? Module.Project.ToRelativeFileName(Module.FileName) : Module.FileName), ErrorType.Information, ErrorOrigin.Build);

            var resourceCompiler = ResConfig.Instance.ResourceCompilerPath;

            // Prefer the resource compiler located in D-IDE's bin root
            // Otherwise let the system search along the %PATH% environment variable to find the resource compiler
            if (!Path.IsPathRooted(resourceCompiler) &&
                File.Exists(Path.Combine(Util.ApplicationStartUpPath, resourceCompiler)))
            {
                resourceCompiler = Path.Combine(Util.ApplicationStartUpPath, resourceCompiler);
            }

            TempPrc = FileExecution.ExecuteSilentlyAsync(resourceCompiler,
                                                         BuildResArgumentString(
                                                             ResConfig.Instance.ResourceCompilerArguments,
                                                             src, res, outputDir),
                                                         ExecDirectory,
                                                         // Output handling
                                                         delegate(string s)
            {
                var err = ParseErrorMessage(s);
                if (Module.Project != null && Module.Project.ContainsFile(err.FileName))
                {
                    err.Project = Module.Project;
                }
                br.BuildErrors.Add(err);
                br.Successful = false;

                if (!GlobalProperties.Instance.VerboseBuildOutput)
                {
                    ErrorLogger.Log(s, ErrorType.Message, ErrorOrigin.Build);
                }
            },
                                                         // Error handling
                                                         delegate(string s)
            {
                br.Successful = false;

                ErrorLogger.Log(s, ErrorType.Error, ErrorOrigin.Build);
            },
                                                         OnExit);

            if (TempPrc != null && !TempPrc.HasExited)
            {
                TempPrc.WaitForExit(MaxCompilationTime);
            }

            br.Successful = br.Successful && TempPrc != null && TempPrc.ExitCode == 0 && File.Exists(res);

            if (br.Successful)
            {
                Module.ResetModifiedTime();
            }

            Module.LastBuildResult = br;
        }
Esempio n. 9
0
        /// <summary>
        /// Calls the cv2pdb program
        /// </summary>
        public BuildResult CreatePDBFromExe(string Executable)
        {
            var pdb = Path.ChangeExtension(Executable, ".pdb");
            var br  = new BuildResult()
            {
                SourceFile = Executable, TargetFile = pdb
            };

            if (!File.Exists(Executable))
            {
                br.BuildErrors.Add(new GenericError()
                {
                    Message = "Debug information database creation failed - " + Executable + " does not exist"
                });
                return(br);
            }

            if (File.Exists(pdb))
            {
                File.Delete(pdb);                 // Enforce recreation of the database
            }
            string cv2pdb = DSettings.Instance.cv2pdb_exe;

            // By default, check if there's a cv2pdb.exe at the program's main directory
            if (!Path.IsPathRooted(cv2pdb) && File.Exists(Util.ApplicationStartUpPath + "\\" + cv2pdb))
            {
                cv2pdb = Util.ApplicationStartUpPath + "\\" + cv2pdb;
            }

            ErrorLogger.Log("Create debug information database " + Path.GetFileName(pdb), ErrorType.Information, ErrorOrigin.Build);
            try
            {
                var prc = FileExecution.ExecuteSilentlyAsync(cv2pdb, "\"" + Executable + "\"", Path.GetDirectoryName(Executable),
                                                             OnOutput, delegate(string s){
                    br.BuildErrors.Add(new GenericError()
                    {
                        Message = s
                    });
                }, delegate()
                {
                    if (File.Exists(pdb))
                    {
                        if (GlobalProperties.Instance.VerboseBuildOutput)
                        {
                            ErrorLogger.Log("Debug information database created successfully", ErrorType.Information, ErrorOrigin.Build);
                        }
                        br.Successful = true;
                    }
                    else
                    {
                        br.BuildErrors.Add(new GenericError()
                        {
                            Message = "Debug information database creation failed",
                            Type    = GenericError.ErrorType.Warning
                        });
                    }
                });

                if (prc != null && !prc.HasExited)
                {
                    prc.WaitForExit(10000);                     // A time out of 10 seconds should be enough
                }
            }
            catch (Exception ex) { ErrorLogger.Log(ex); }

            return(br);
        }
Esempio n. 10
0
        /// <summary>
        /// Links several object files to an executable, dynamic or static library
        /// </summary>
        public BuildResult LinkFiles(DMDConfig dmd, string linkerExe, string linkerArgs, string startDirectory, string targetFile, bool CreatePDB, params string[] files)
        {
            var errList = new List <GenericError>();
            var br      = new BuildResult()
            {
                TargetFile = targetFile, Successful = true
            };

            ErrorLogger.Log("Link files to " + Path.GetFileName(targetFile), ErrorType.Information, ErrorOrigin.Build);

            if (File.Exists(targetFile))
            {
                try
                {
                    File.Delete(targetFile);
                }
                catch (Exception ex)                 // Perhaps our targetFile is still in use
                {
                    br.BuildErrors.Add(new GenericError()
                    {
                        Message = ex.Message
                    });
                    return(br);
                }
            }

            // Ensure that target directory exists
            var tarDir = Path.GetDirectoryName(targetFile);

            try
            {
                Util.CreateDirectoryRecursively(tarDir);
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex, ErrorType.Error, ErrorOrigin.Build);
                br.Successful = false;
                return(br);
            }

            // Always enable it to use environment paths to find dmd.exe
            if (!Path.IsPathRooted(linkerExe) && Directory.Exists(dmd.BaseDirectory))
            {
                linkerExe = Path.Combine(dmd.BaseDirectory, linkerExe);
            }

            //CRITICAL: Execute linker exe
            TempPrc = FileExecution.ExecuteSilentlyAsync(
                linkerExe, BuildDLinkerArgumentString(linkerArgs, startDirectory, targetFile, dmd.ImportDirectories, files), startDirectory,
                OnOutput, delegate(string s)
            {
                var err = ParseErrorMessage(s);
                if (err.Type == GenericError.ErrorType.Error)
                {
                    br.Successful = false;
                }
                br.BuildErrors.Add(err);
            }, OnExit);

            if (TempPrc != null && !TempPrc.HasExited)
            {
                TempPrc.WaitForExit(MaxCompilationTime);
            }

            br.Successful = br.Successful && TempPrc.ExitCode == 0 && File.Exists(targetFile);

            // If targetFile is executable or dynamic linked library, create PDB
            if (br.Successful && CreatePDB && (targetFile.EndsWith(".exe") || targetFile.EndsWith(".dll")))
            {
                var br_ = CreatePDBFromExe(targetFile);
                br.BuildErrors.AddRange(br_.BuildErrors);

                br.AdditionalFiles = new[] { br_.TargetFile };
            }

            return(br);
        }