Ejemplo n.º 1
0
		public void CreateProjectFiles(DecompileContext ctx) {
			var filenameCreator = new FilenameCreator(projDir, defaultNamespace);
			var resourceNameCreator = new ResourceNameCreator(options.Module, filenameCreator);

			AllowUnsafeBlocks = DotNetUtils.IsUnsafe(options.Module);
			InitializeSplashScreen();
			if (options.Language.CanDecompile(DecompilationType.AssemblyInfo)) {
				var filename = filenameCreator.CreateFromRelativePath(Path.Combine(PropertiesFolder, "AssemblyInfo"), options.Language.FileExtension);
				files.Add(new AssemblyInfoProjectFile(options.Module, filename, options.DecompilationContext, options.Language));
			}

			var ep = options.Module.EntryPoint;
			if (ep != null && ep.DeclaringType != null)
				StartupObject = ep.DeclaringType.ReflectionFullName;

			applicationManifest = ApplicationManifest.TryCreate(options.Module.Win32Resources, filenameCreator);
			if (applicationManifest != null)
				files.Add(new ApplicationManifestProjectFile(applicationManifest.Filename));

			foreach (var rsrc in options.Module.Resources) {
				ctx.CancellationToken.ThrowIfCancellationRequested();
				switch (rsrc.ResourceType) {
				case ResourceType.Embedded:
					foreach (var file in CreateEmbeddedResourceFiles(options.Module, resourceNameCreator, (EmbeddedResource)rsrc)) {
						files.Add(file);
						files.AddRange(CreateSatelliteFiles(rsrc.Name, filenameCreator, file));
					}
					break;

				case ResourceType.AssemblyLinked:
					//TODO: What should be created here?
					break;

				case ResourceType.Linked:
					//TODO: What should be created here?
					break;

				default:
					break;
				}
			}
			InitializeXaml();
			InitializeResX();
			foreach (var type in options.Module.Types) {
				ctx.CancellationToken.ThrowIfCancellationRequested();
				if (!DecompileType(type))
					continue;
				files.Add(CreateTypeProjectFile(type, filenameCreator));
			}
			CreateEmptyAppXamlFile();

			var existingAppConfig = options.Module.Location + ".config";
			if (File.Exists(existingAppConfig))
				files.Add(new AppConfigProjectFile(filenameCreator.CreateName("App.config"), existingAppConfig));

			applicationIcon = ApplicationIcon.TryCreate(options.Module.Win32Resources, Path.GetFileName(Directory), filenameCreator);

			var dirs = new HashSet<string>(files.Select(a => Path.GetDirectoryName(a.Filename)), StringComparer.OrdinalIgnoreCase);
			foreach (var dir in dirs) {
				ctx.CancellationToken.ThrowIfCancellationRequested();
				try {
					System.IO.Directory.CreateDirectory(dir);
				}
				catch (Exception ex) {
					ctx.Logger.Error(string.Format(Languages_Resources.MSBuild_CouldNotCreateDirectory2, dir, ex.Message));
				}
			}
		}
Ejemplo n.º 2
0
        public void CreateProjectFiles(DecompileContext ctx)
        {
            var filenameCreator     = new FilenameCreator(Directory, DefaultNamespace);
            var resourceNameCreator = new ResourceNameCreator(Options.Module, filenameCreator);

            AllowUnsafeBlocks = DotNetUtils.IsUnsafe(Options.Module);
            InitializeSplashScreen();
            if (Options.Language.CanDecompile(DecompilationType.AssemblyInfo))
            {
                var filename = filenameCreator.CreateFromRelativePath(Path.Combine(PropertiesFolder, "AssemblyInfo"), Options.Language.FileExtension);
                Files.Add(new AssemblyInfoProjectFile(Options.Module, filename, Options.DecompilationContext, Options.Language, createDecompilerOutput));
            }

            var ep = Options.Module.EntryPoint;

            if (ep != null && ep.DeclaringType != null)
            {
                StartupObject = ep.DeclaringType.ReflectionFullName;
            }

            applicationManifest = ApplicationManifest.TryCreate(Options.Module.Win32Resources, filenameCreator);
            if (ApplicationManifest != null)
            {
                Files.Add(new ApplicationManifestProjectFile(ApplicationManifest.Filename));
            }

            foreach (var rsrc in Options.Module.Resources)
            {
                ctx.CancellationToken.ThrowIfCancellationRequested();
                switch (rsrc.ResourceType)
                {
                case ResourceType.Embedded:
                    foreach (var file in CreateEmbeddedResourceFiles(Options.Module, resourceNameCreator, (EmbeddedResource)rsrc))
                    {
                        Files.Add(file);
                        Files.AddRange(CreateSatelliteFiles(rsrc.Name, filenameCreator, file));
                    }
                    break;

                case ResourceType.AssemblyLinked:
                    //TODO: What should be created here?
                    break;

                case ResourceType.Linked:
                    //TODO: What should be created here?
                    break;

                default:
                    break;
                }
            }
            InitializeXaml();
            InitializeResX();
            foreach (var type in Options.Module.Types)
            {
                ctx.CancellationToken.ThrowIfCancellationRequested();
                if (!DecompileType(type))
                {
                    continue;
                }
                Files.Add(CreateTypeProjectFile(type, filenameCreator));
            }
            CreateEmptyAppXamlFile();

            var existingAppConfig = Options.Module.Location + ".config";

            if (File.Exists(existingAppConfig))
            {
                Files.Add(new AppConfigProjectFile(filenameCreator.CreateName("App.config"), existingAppConfig));
            }

            applicationIcon = ApplicationIcon.TryCreate(Options.Module.Win32Resources, Path.GetFileName(Directory), filenameCreator);

            var dirs   = new HashSet <string>(Files.Select(a => GetDirectoryName(a.Filename)).Where(a => a != null), StringComparer.OrdinalIgnoreCase);
            int errors = 0;

            foreach (var dir in dirs)
            {
                ctx.CancellationToken.ThrowIfCancellationRequested();
                try {
                    System.IO.Directory.CreateDirectory(dir);
                }
                catch (Exception ex) {
                    if (errors++ < 20)
                    {
                        ctx.Logger.Error(string.Format(dnSpy_Languages_Resources.MSBuild_CouldNotCreateDirectory2, dir, ex.Message));
                    }
                }
            }
        }