Ejemplo n.º 1
0
 public Project(ProjectModuleOptions options, string projDir, SatelliteAssemblyFinder satelliteAssemblyFinder, Func <TextWriter, IDecompilerOutput> createDecompilerOutput)
 {
     Options   = options ?? throw new ArgumentNullException(nameof(options));
     Directory = projDir;
     this.satelliteAssemblyFinder = satelliteAssemblyFinder;
     this.createDecompilerOutput  = createDecompilerOutput;
     Files                   = new List <ProjectFile>();
     DefaultNamespace        = new DefaultNamespaceFinder(options.Module).Find();
     Filename                = Path.Combine(projDir, Path.GetFileName(projDir) + options.Decompiler.ProjectFileExtension);
     AssemblyName            = options.Module.Assembly is null ? string.Empty : options.Module.Assembly.Name.String;
     ProjectTypeGuids        = new HashSet <Guid>();
     PropertiesFolder        = CalculatePropertiesFolder();
     ExtraAssemblyReferences = new HashSet <string>();
     LanguageGuid            = CalculateLanguageGuid(options.Decompiler);
 }
Ejemplo n.º 2
0
		public Project(ProjectModuleOptions options, string projDir, SatelliteAssemblyFinder satelliteAssemblyFinder, Func<TextWriter, IDecompilerOutput> createDecompilerOutput) {
			if (options == null)
				throw new ArgumentNullException(nameof(options));
			Options = options;
			Directory = projDir;
			this.satelliteAssemblyFinder = satelliteAssemblyFinder;
			this.createDecompilerOutput = createDecompilerOutput;
			Files = new List<ProjectFile>();
			DefaultNamespace = new DefaultNamespaceFinder(options.Module).Find();
			Filename = Path.Combine(projDir, Path.GetFileName(projDir) + options.Decompiler.ProjectFileExtension);
			AssemblyName = options.Module.Assembly == null ? string.Empty : options.Module.Assembly.Name.String;
			ProjectTypeGuids = new HashSet<Guid>();
			PropertiesFolder = CalculatePropertiesFolder();
			ExtraAssemblyReferences = new HashSet<string>();
			LanguageGuid = CalculateLanguageGuid(options.Decompiler);
		}
Ejemplo n.º 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);
							var outputOptions = xamlOutputOptionsProvider?.Default ?? new XamlOutputOptions();
							projOpts.DecompileBaml = (a, b, c, d) => bamlDecompiler.Decompile(a, b, c, o, d, outputOptions);
						}
						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());
			}