Beispiel #1
0
        // -----------------------------------------------------
        void ReplaceIcon(Options options)
        {
            // Find version info resources
            ResourceInfo ri = new ResourceInfo();

            ri.Load(options.outputExeFile);
            List <Resource> iconResources      = ri.Resources[new ResourceId(Kernel32.ResourceTypes.RT_ICON)];
            List <Resource> iconGroupResources = ri.Resources[new ResourceId(Kernel32.ResourceTypes.RT_GROUP_ICON)];

            ri.Dispose();

            // Delete old icons from file
            foreach (Resource resource in iconResources)
            {
                resource.DeleteFrom(options.outputExeFile);
            }

            // Delete old icon groups from file
            foreach (Resource resource in iconGroupResources)
            {
                resource.DeleteFrom(options.outputExeFile);
            }

            // Add the new icon and iconGroup
            IconFile iconFile = new IconFile(options.inputIcoFile);
            IconDirectoryResource iconDirectoryResource = new IconDirectoryResource(iconFile);

            iconDirectoryResource.SaveTo(options.outputExeFile);
        }
Beispiel #2
0
        // -----------------------------------------------------
        void ReplaceVersionInfo(Options options)
        {
            // Find version info resources
            ResourceInfo ri = new ResourceInfo();

            ri.Load(options.outputExeFile);
            List <Resource> resources = ri.Resources[new ResourceId(Kernel32.ResourceTypes.RT_VERSION)];

            ri.Dispose();

            // Delete old version resource(s) from file
            foreach (Resource resource in resources)
            {
                resource.DeleteFrom(options.outputExeFile);
            }

            // Create new version info resource
            VersionResource versionResource = new VersionResource();

            versionResource.FileVersion    = options.versionInfo.fileVersion;
            versionResource.ProductVersion = options.versionInfo.productVersion;

            // Set all the info / strings
            StringFileInfo stringFileInfo = new StringFileInfo();

            versionResource[stringFileInfo.Key] = stringFileInfo;
            StringTable stringFileInfoStrings = new StringTable();

            stringFileInfoStrings.LanguageID = ResourceUtil.USENGLISHLANGID;
            stringFileInfoStrings.CodePage   = 1200;
            stringFileInfo.Strings.Add(stringFileInfoStrings.Key, stringFileInfoStrings);
//          stringFileInfoStrings["ProductName"] = "not used";
            stringFileInfoStrings["FileVersion"]     = options.versionInfo.fileVersion;
            stringFileInfoStrings["FileDescription"] = options.versionInfo.productName;
            stringFileInfoStrings["LegalCopyright"]  = options.versionInfo.legalCopyright;
            stringFileInfoStrings["CompanyName"]     = options.versionInfo.companyName;
//          stringFileInfoStrings["Comments"] = "not used";
            stringFileInfoStrings["ProductVersion"] = options.versionInfo.productVersion;

            // Don't really understand what this chunk does, but leaving it in anyway
            VarFileInfo varFileInfo = new VarFileInfo();

            versionResource[varFileInfo.Key] = varFileInfo;
            VarTable varFileInfoTranslation = new VarTable("Translation");

            varFileInfo.Vars.Add(varFileInfoTranslation.Key, varFileInfoTranslation);
            varFileInfoTranslation[ResourceUtil.USENGLISHLANGID] = 1300;

            // Save to file
            versionResource.SaveTo(options.outputExeFile);
        }
Beispiel #3
0
        /// <summary>
        ///     A
        /// </summary>
        /// <param name="target"></param>
        /// <param name="source"></param>
        public static void CopyResources(this FileInfo target, FileInfo source) {
            if (File.Exists(target.FullName) == false) throw new FileNotFoundException("Couldnt find the given file", target.FullName);
            if (File.Exists(source.FullName) == false) throw new FileNotFoundException("Couldnt find the given file", source.FullName);

            var ri = new ResourceInfo();
            ri.Load(source.FullName);
            foreach (var res in ri) {
                try {
                    res.SaveTo(target.FullName);
                } catch { //copy what ever it can. skip errory ones.
                }
            }
            ri.Dispose();
            
        }
Beispiel #4
0
        public override bool Execute()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Log.LogWarning("Skipping task on non-Windows platform");
                return(true);
            }

            string       outputPath     = OutputFile.GetMetadata("FullPath");
            ResourceInfo inputResources = new ResourceInfo();

            inputResources.Load(InputFile.GetMetadata("FullPath"));

            // ResourceInfo.Save() is not implemented, so I must save each resource one at a time.
            foreach (var rsrc in inputResources)
            {
                rsrc.SaveTo(outputPath);
            }

            inputResources.Dispose();
            return(true);
        }
Beispiel #5
0
        /// <summary>
        ///     A
        /// </summary>
        /// <param name="target"></param>
        /// <param name="source"></param>
        public static void CopyResources(this FileInfo target, FileInfo source)
        {
            if (File.Exists(target.FullName) == false)
            {
                throw new FileNotFoundException("Couldnt find the given file", target.FullName);
            }
            if (File.Exists(source.FullName) == false)
            {
                throw new FileNotFoundException("Couldnt find the given file", source.FullName);
            }

            var ri = new ResourceInfo();

            ri.Load(source.FullName);
            foreach (var res in ri)
            {
                try {
                    res.SaveTo(target.FullName);
                } catch { //copy what ever it can. skip errory ones.
                }
            }
            ri.Dispose();
        }