Example #1
0
        //
        // This function tries to find version informaiton for a specific codepage.
        // Returns true when version information is found.
        //
        private bool GetVersionInfoForCodePage(IntPtr memIntPtr, string codepage)
        {
            string template = "\\\\StringFileInfo\\\\{0}\\\\{1}";

            companyName      = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "CompanyName"));
            fileDescription  = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "FileDescription"));
            fileVersion      = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "FileVersion"));
            internalName     = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "InternalName"));
            legalCopyright   = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "LegalCopyright"));
            originalFilename = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "OriginalFilename"));
            productName      = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "ProductName"));
            productVersion   = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "ProductVersion"));
            comments         = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "Comments"));
            legalTrademarks  = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "LegalTrademarks"));
            privateBuild     = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "PrivateBuild"));
            specialBuild     = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, template, codepage, "SpecialBuild"));

            language = GetFileVersionLanguage(memIntPtr);

            NativeMethods.VS_FIXEDFILEINFO ffi = GetFixedFileInfo(memIntPtr);
            fileMajor      = HIWORD(ffi.dwFileVersionMS);
            fileMinor      = LOWORD(ffi.dwFileVersionMS);
            fileBuild      = HIWORD(ffi.dwFileVersionLS);
            filePrivate    = LOWORD(ffi.dwFileVersionLS);
            productMajor   = HIWORD(ffi.dwProductVersionMS);
            productMinor   = LOWORD(ffi.dwProductVersionMS);
            productBuild   = HIWORD(ffi.dwProductVersionLS);
            productPrivate = LOWORD(ffi.dwProductVersionLS);
            fileFlags      = ffi.dwFileFlags;

            // fileVersion is chosen based on best guess. Other fields can be used if appropriate.
            return(fileVersion != string.Empty);
        }
Example #2
0
        private static NativeMethods.VS_FIXEDFILEINFO GetFixedFileInfo(IntPtr memPtr)
        {
            IntPtr memRef = IntPtr.Zero;
            int    memLen;

            if (UnsafeNativeMethods.VerQueryValue(new HandleRef(null, memPtr), "\\", ref memRef, out memLen))
            {
                NativeMethods.VS_FIXEDFILEINFO fixedFileInfo = new NativeMethods.VS_FIXEDFILEINFO();
                Marshal.PtrToStructure(memRef, fixedFileInfo);
                return(fixedFileInfo);
            }

            return(new NativeMethods.VS_FIXEDFILEINFO());
        }
        private static NativeMethods.VS_FIXEDFILEINFO GetFixedFileInfo(IntPtr memPtr) {
            IntPtr memRef = IntPtr.Zero;
            int memLen;

            if (UnsafeNativeMethods.VerQueryValue(new HandleRef(null, memPtr), "\\", ref memRef, out memLen)) {
                NativeMethods.VS_FIXEDFILEINFO fixedFileInfo = new NativeMethods.VS_FIXEDFILEINFO();
                Marshal.PtrToStructure(memRef, fixedFileInfo);
                return fixedFileInfo;
            }

            return new NativeMethods.VS_FIXEDFILEINFO();
        }