示例#1
0
        public override void Execute(IMenuItemContext context)
        {
            var modules = GetModules();

            if (modules.Length == 0)
            {
                return;
            }

            var decompiler = decompilerService.Decompiler;

            if (decompiler.ProjectFileExtension == null)
            {
                decompiler = decompilerService.AllDecompilers.FirstOrDefault(a => a.ProjectFileExtension != null);
                Debug.Assert(decompiler != null);
                if (decompiler == null)
                {
                    return;
                }
            }

            var task = new ExportTask(this, modules);
            var vm   = new ExportToProjectVM(new PickDirectory(), decompilerService, task, bamlDecompiler != null);

            task.vm                 = vm;
            vm.ProjectVersion       = exportToProjectSettings.ProjectVersion;
            vm.CreateResX           = documentTreeViewSettings.DeserializeResources;
            vm.DontReferenceStdLib  = modules.Any(a => a.Assembly.IsCorLib());
            vm.Decompiler           = decompiler;
            vm.SolutionFilename     = GetSolutionFilename(modules);
            vm.FilesToExportMessage = CreateFilesToExportMessage(modules);

            var win = new ExportToProjectDlg();

            task.dlg        = win;
            win.DataContext = vm;
            win.Owner       = appWindow.MainWindow;
            using (documentTreeView.DocumentService.DisableAssemblyLoad())
                win.ShowDialog();
            if (vm.IsComplete)
            {
                exportToProjectSettings.ProjectVersion = vm.ProjectVersion;
            }
            task.Dispose();
        }
示例#2
0
        public override void Execute(IMenuItemContext context)
        {
            var modules = GetModules();

            if (modules.Length == 0)
            {
                return;
            }

            var lang = languageManager.SelectedLanguage;

            if (lang.ProjectFileExtension == null)
            {
                lang = languageManager.Languages.FirstOrDefault(a => a.ProjectFileExtension != null);
                Debug.Assert(lang != null);
                if (lang == null)
                {
                    return;
                }
            }

            var task = new ExportTask(this, modules);
            var vm   = new ExportToProjectVM(new PickDirectory(), languageManager, task, bamlDecompiler != null);

            task.vm                 = vm;
            vm.CreateResX           = fileTreeViewSettings.DeserializeResources;
            vm.DontReferenceStdLib  = modules.Any(a => a.Assembly.IsCorLib());
            vm.Language             = lang;
            vm.SolutionFilename     = GetSolutionFilename(modules);
            vm.FilesToExportMessage = CreateFilesToExportMessage(modules);

            var win = new ExportToProjectDlg();

            task.dlg        = win;
            win.DataContext = vm;
            win.Owner       = appWindow.MainWindow;
            using (fileTreeView.FileManager.DisableAssemblyLoad())
                win.ShowDialog();
        }
示例#3
0
            public void Execute(ExportToProjectVM vm)
            {
                vm.ProgressMinimum = 0;
                vm.ProgressMaximum = 1;
                vm.TotalProgress   = 0;
                vm.IsIndeterminate = false;
                Task.Factory.StartNew(() => {
                    var decompilationContext = new DecompilationContext {
                        CancellationToken      = cancellationToken,
                        GetDisableAssemblyLoad = () => owner.documentTreeView.DocumentService.DisableAssemblyLoad(),
                    };
                    var options            = new ProjectCreatorOptions(vm.Directory, cancellationToken);
                    options.ProjectVersion = vm.ProjectVersion;
                    if (vm.CreateSolution)
                    {
                        options.SolutionFilename = vm.SolutionFilename;
                    }
                    options.Logger           = this;
                    options.ProgressListener = this;

                    bool hasProjectGuid = vm.ProjectGuid.Value != null;
                    string guidFormat   = null;
                    int guidNum         = 0;
                    if (hasProjectGuid)
                    {
                        string guidStr = vm.ProjectGuid.Value.ToString();
                        guidNum        = int.Parse(guidStr.Substring(36 - 8, 8), NumberStyles.HexNumber);
                        guidFormat     = guidStr.Substring(0, 36 - 8) + "{0:X8}";
                    }
                    foreach (var module in modules.OrderBy(a => a.Location, StringComparer.InvariantCultureIgnoreCase))
                    {
                        var projOpts = new ProjectModuleOptions(module, vm.Decompiler, decompilationContext)
                        {
                            DontReferenceStdLib = vm.DontReferenceStdLib,
                            UnpackResources     = vm.UnpackResources,
                            CreateResX          = vm.CreateResX,
                            DecompileXaml       = vm.DecompileXaml,
                            ProjectGuid         = hasProjectGuid ? new Guid(string.Format(guidFormat, guidNum++)) : Guid.NewGuid(),
                        };
                        if (bamlDecompiler != null)
                        {
                            var o = BamlDecompilerOptions.Create(vm.Decompiler);
                            projOpts.DecompileBaml = (a, b, c, d) => bamlDecompiler.Decompile(a, b, c, o, d);
                        }
                        options.ProjectModules.Add(projOpts);
                    }
                    var creator = new MSBuildProjectCreator(options);

                    creator.Create();
                    if (vm.CreateSolution)
                    {
                        fileToOpen = creator.SolutionFilename;
                    }
                    else
                    {
                        fileToOpen = creator.ProjectFilenames.FirstOrDefault();
                    }
                }, cancellationToken)
                .ContinueWith(t => {
                    var ex = t.Exception;
                    if (ex != null)
                    {
                        Error(string.Format(dnSpy_Resources.ErrorExceptionOccurred, ex));
                    }
                    EmtpyErrorList();
                    vm.OnExportComplete();
                    if (!vm.ExportErrors)
                    {
                        dlg.Close();
                        if (vm.OpenProject)
                        {
                            OpenProject();
                        }
                    }
                }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
            }
示例#4
0
 public void Cancel(ExportToProjectVM vm)
 {
     cancellationTokenSource.Cancel();
     dlg.Close();
 }
示例#5
0
            public void Execute(ExportToProjectVM vm)
            {
                vm.ProgressMinimum = 0;
                vm.ProgressMaximum = 1;
                vm.TotalProgress   = 0;
                vm.IsIndeterminate = false;
                Task.Factory.StartNew(() => {
                    AppCulture.InitializeCulture();
                    var decompilationContext = new DecompilationContext {
                        CancellationToken      = cancellationTokenSource.Token,
                        GetDisableAssemblyLoad = () => owner.fileTreeView.FileManager.DisableAssemblyLoad(),
                    };
                    var options            = new ProjectCreatorOptions(vm.Directory, cancellationTokenSource.Token);
                    options.ProjectVersion = vm.ProjectVersion;
                    if (vm.CreateSolution)
                    {
                        options.SolutionFilename = vm.SolutionFilename;
                    }
                    options.Logger           = this;
                    options.ProgressListener = this;
                    foreach (var module in modules)
                    {
                        var projOpts = new ProjectModuleOptions(module, vm.Language, decompilationContext)
                        {
                            DontReferenceStdLib = vm.DontReferenceStdLib,
                            UnpackResources     = vm.UnpackResources,
                            CreateResX          = vm.CreateResX,
                            DecompileXaml       = vm.DecompileXaml,
                        };
                        if (owner.bamlDecompiler != null)
                        {
                            var o = BamlDecompilerOptions.Create(vm.Language);
                            projOpts.DecompileBaml = (a, b, c, d) => owner.bamlDecompiler.Value.Decompile(a, b, c, o, d);
                        }
                        options.ProjectModules.Add(projOpts);
                    }
                    var creator = new MSBuildProjectCreator(options);

                    creator.Create();
                    if (vm.CreateSolution)
                    {
                        fileToOpen = creator.SolutionFilename;
                    }
                    else
                    {
                        fileToOpen = creator.ProjectFilenames.FirstOrDefault();
                    }
                }, cancellationTokenSource.Token)
                .ContinueWith(t => {
                    var ex = t.Exception;
                    if (ex != null)
                    {
                        Error(string.Format(dnSpy_Resources.ErrorExceptionOccurred, ex));
                    }
                    EmtpyErrorList();
                    vm.OnExportComplete();
                    if (!vm.ExportErrors)
                    {
                        dlg.Close();
                        if (vm.OpenProject)
                        {
                            OpenProject();
                        }
                    }
                }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
            }