Beispiel #1
0
        ProjectFile TryCreateSatelliteFile(ModuleDef module, string rsrcName, FilenameCreator filenameCreator, ProjectFile nonSatFile)
        {
            if (!Options.CreateResX)
            {
                return(null);
            }
            var asm = module.Assembly;

            Debug.Assert(asm != null && !UTF8String.IsNullOrEmpty(asm.Culture));
            if (asm == null || UTF8String.IsNullOrEmpty(asm.Culture))
            {
                return(null);
            }
            var name    = FileUtils.RemoveExtension(rsrcName);
            var ext     = FileUtils.GetExtension(rsrcName);
            var locName = name + "." + asm.Culture + ext;
            var er      = module.Resources.OfType <EmbeddedResource>().FirstOrDefault(a => StringComparer.Ordinal.Equals(a.Name, locName));
            var set     = TryCreateResourceElementSet(module, er);

            if (set == null)
            {
                return(null);
            }

            var dir = Path.GetDirectoryName(nonSatFile.Filename).Substring(Directory.Length + 1);

            name = Path.GetFileNameWithoutExtension(nonSatFile.Filename);
            ext  = Path.GetExtension(nonSatFile.Filename);
            var filename = filenameCreator.CreateFromRelativePath(Path.Combine(dir, name) + "." + asm.Culture, ext);

            return(CreateResXFile(module, er, set, filename, string.Empty, true));
        }
Beispiel #2
0
        string GetBamlResourceName(string resourceName)
        {
            if (namespaces == null)
            {
                Initialize();
            }

            var ext       = FileUtils.GetExtension(resourceName);
            var nameNoExt = resourceName.Substring(0, resourceName.Length - ext.Length);
            var ns        = GetNamespace(resourceName);

            string fixedNs;

            if (partialNamespaceMap.TryGetValue(ns, out fixedNs))
            {
                nameNoExt = fixedNs.Replace('.', '/') + "/" + nameNoExt.Substring(ns.Length + 1);
            }

            return(filenameCreator.CreateFromRelativePath(nameNoExt, ext));
        }
Beispiel #3
0
		ProjectFile TryCreateSatelliteFile(ModuleDef module, string rsrcName, FilenameCreator filenameCreator, ProjectFile nonSatFile) {
			if (!options.CreateResX)
				return null;
			var asm = module.Assembly;
			Debug.Assert(asm != null && !UTF8String.IsNullOrEmpty(asm.Culture));
			if (asm == null || UTF8String.IsNullOrEmpty(asm.Culture))
				return null;
			var name = FileUtils.RemoveExtension(rsrcName);
			var ext = FileUtils.GetExtension(rsrcName);
			var locName = name + "." + asm.Culture + ext;
			var er = module.Resources.OfType<EmbeddedResource>().FirstOrDefault(a => StringComparer.Ordinal.Equals(a.Name, locName));
			var set = TryCreateResourceElementSet(module, er);
			if (set == null)
				return null;

			var dir = Path.GetDirectoryName(nonSatFile.Filename).Substring(projDir.Length + 1);
			name = Path.GetFileNameWithoutExtension(nonSatFile.Filename);
			ext = Path.GetExtension(nonSatFile.Filename);
			var filename = filenameCreator.CreateFromRelativePath(Path.Combine(dir, name) + "." + asm.Culture, ext);
			return CreateResXFile(module, er, set, filename, string.Empty, true);
		}
Beispiel #4
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));
				}
			}
		}
Beispiel #5
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));
                    }
                }
            }
        }