Пример #1
0
        //
        // This function tries to find version information 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);

            Interop.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);
        }
Пример #2
0
        private static Interop.VS_FIXEDFILEINFO GetFixedFileInfo(IntPtr memPtr)
        {
            IntPtr memRef = IntPtr.Zero;
            uint   memLen;

            if (Interop.mincore.VerQueryValue(memPtr, "\\", out memRef, out memLen))
            {
                Interop.VS_FIXEDFILEINFO fixedFileInfo =
                    (Interop.VS_FIXEDFILEINFO)Marshal.PtrToStructure <Interop.VS_FIXEDFILEINFO>(memRef);
                return(fixedFileInfo);
            }

            return(new Interop.VS_FIXEDFILEINFO());
        }