diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 01:46:43 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 01:46:43 +0000 |
commit | bcff05af3d60df10a21e07751a14b95ce9e7f3d4 (patch) | |
tree | 76d8d3ec6c6c0d9564c675d423907e29607bf253 /base | |
parent | 474b2ab8c3b32c07692480aa234f3b2921fe5dd6 (diff) | |
download | chromium_src-bcff05af3d60df10a21e07751a14b95ce9e7f3d4.zip chromium_src-bcff05af3d60df10a21e07751a14b95ce9e7f3d4.tar.gz chromium_src-bcff05af3d60df10a21e07751a14b95ce9e7f3d4.tar.bz2 |
Refactor FileVersionInfo into an interface with platform implementations.
This allows us to move the chrome specific version informaton used by
Linux into src/chrome.
Add a GetChromeVersionInfo() for Linux in src/chrome/app/ and make sure to use this in src/chrome.
In src/webkit/glue, add a new glue method for getting the product version. When compiling chrome, use an implementation in src/chrome/renderer (which uses GetChromeVersionInfo()) and a stub implementation for test_shell.
Review URL: http://codereview.chromium.org/1560027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44435 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gyp | 59 | ||||
-rw-r--r-- | base/base.gypi | 6 | ||||
-rw-r--r-- | base/file_version_info.h | 83 | ||||
-rw-r--r-- | base/file_version_info_linux.cc | 86 | ||||
-rw-r--r-- | base/file_version_info_linux.h.version | 26 | ||||
-rw-r--r-- | base/file_version_info_mac.h | 63 | ||||
-rw-r--r-- | base/file_version_info_mac.mm | 49 | ||||
-rw-r--r-- | base/file_version_info_unittest.cc | 30 | ||||
-rw-r--r-- | base/file_version_info_win.cc (renamed from base/file_version_info.cc) | 50 | ||||
-rw-r--r-- | base/file_version_info_win.h | 67 |
10 files changed, 223 insertions, 296 deletions
diff --git a/base/base.gyp b/base/base.gyp index 05f8a0f..bccac47 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -268,65 +268,6 @@ }, ], }], - [ 'OS == "linux" or OS == "freebsd" or OS == "openbsd" or OS == "solaris"', { - 'targets': [ - { - 'target_name': 'linux_versioninfo', - 'type': '<(library)', - 'sources': [ - 'file_version_info_linux.cc', - ], - 'include_dirs': [ - '..', - '<(SHARED_INTERMEDIATE_DIR)', - ], - 'actions': [ - { - 'action_name': 'linux_version', - 'variables': { - 'lastchange_path': - '<(SHARED_INTERMEDIATE_DIR)/build/LASTCHANGE', - 'version_py_path': '../chrome/tools/build/version.py', - 'version_path': '../chrome/VERSION', - 'template_input_path': 'file_version_info_linux.h.version', - }, - 'conditions': [ - [ 'branding == "Chrome"', { - 'variables': { - 'branding_path': - '../chrome/app/theme/google_chrome/BRANDING', - }, - }, { # else branding!="Chrome" - 'variables': { - 'branding_path': - '../chrome/app/theme/chromium/BRANDING', - }, - }], - ], - 'inputs': [ - '<(template_input_path)', - '<(version_path)', - '<(branding_path)', - '<(lastchange_path)', - ], - 'outputs': [ - '<(SHARED_INTERMEDIATE_DIR)/base/file_version_info_linux.h', - ], - 'action': [ - 'python', - '<(version_py_path)', - '-f', '<(version_path)', - '-f', '<(branding_path)', - '-f', '<(lastchange_path)', - '<(template_input_path)', - '<@(_outputs)', - ], - 'message': 'Generating version information', - }, - ], - }, - ], - }], ], } diff --git a/base/base.gypi b/base/base.gypi index df96e51..abdb161 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -80,9 +80,11 @@ 'file_util_mac.mm', 'file_util_posix.cc', 'file_util_win.cc', - 'file_version_info.cc', 'file_version_info.h', + 'file_version_info_mac.h', 'file_version_info_mac.mm', + 'file_version_info_win.cc', + 'file_version_info_win.h', 'fix_wp64.h', 'float_util.h', 'foundation_utils_mac.h', @@ -301,7 +303,7 @@ 'linux_util.cc', 'message_pump_glib.cc', ], - },], + }], [ 'OS != "linux"', { 'sources!': [ # Not automatically excluded by the *linux.cc rules. diff --git a/base/file_version_info.h b/base/file_version_info.h index 561c324..def2ea5 100644 --- a/base/file_version_info.h +++ b/base/file_version_info.h @@ -7,28 +7,17 @@ #include <string> -#include "base/basictypes.h" -#include "base/scoped_ptr.h" - -#if defined(OS_WIN) -struct tagVS_FIXEDFILEINFO; -typedef tagVS_FIXEDFILEINFO VS_FIXEDFILEINFO; -#elif defined(OS_MACOSX) -#ifdef __OBJC__ -@class NSBundle; -#else -class NSBundle; -#endif -#endif +#include "build/build_config.h" class FilePath; -// Provides a way to access the version information for a file. +// Provides an interface for accessing the version information for a file. // This is the information you access when you select a file in the Windows // explorer, right-click select Properties, then click the Version tab. class FileVersionInfo { public: +#if defined(OS_WIN) || defined(OS_MACOSX) // Creates a FileVersionInfo for the specified path. Returns NULL if something // goes wrong (typically the file does not exit or cannot be opened). The // returned object should be deleted when you are done with it. @@ -36,62 +25,30 @@ class FileVersionInfo { // This version, taking a wstring, is deprecated and only kept around // until we can fix all callers. static FileVersionInfo* CreateFileVersionInfo(const std::wstring& file_path); +#endif // Creates a FileVersionInfo for the current module. Returns NULL in case // of error. The returned object should be deleted when you are done with it. static FileVersionInfo* CreateFileVersionInfoForCurrentModule(); - ~FileVersionInfo(); - // Accessors to the different version properties. // Returns an empty string if the property is not found. - std::wstring company_name(); - std::wstring company_short_name(); - std::wstring product_name(); - std::wstring product_short_name(); - std::wstring internal_name(); - std::wstring product_version(); - std::wstring private_build(); - std::wstring special_build(); - std::wstring comments(); - std::wstring original_filename(); - std::wstring file_description(); - std::wstring file_version(); - std::wstring legal_copyright(); - std::wstring legal_trademarks(); - std::wstring last_change(); - bool is_official_build(); - - // Lets you access other properties not covered above. - bool GetValue(const wchar_t* name, std::wstring* value); - - // Similar to GetValue but returns a wstring (empty string if the property - // does not exist). - std::wstring GetStringValue(const wchar_t* name); - -#ifdef OS_WIN - // Get the fixed file info if it exists. Otherwise NULL - VS_FIXEDFILEINFO* fixed_file_info() { return fixed_file_info_; } -#endif - - private: -#if defined(OS_WIN) - FileVersionInfo(void* data, int language, int code_page); - - scoped_ptr_malloc<char> data_; - int language_; - int code_page_; - // This is a pointer into the data_ if it exists. Otherwise NULL. - VS_FIXEDFILEINFO* fixed_file_info_; -#elif defined(OS_MACOSX) - explicit FileVersionInfo(NSBundle *bundle); - - NSBundle *bundle_; -#elif defined(OS_POSIX) - FileVersionInfo(); -#endif - - DISALLOW_EVIL_CONSTRUCTORS(FileVersionInfo); + virtual std::wstring company_name() = 0; + virtual std::wstring company_short_name() = 0; + virtual std::wstring product_name() = 0; + virtual std::wstring product_short_name() = 0; + virtual std::wstring internal_name() = 0; + virtual std::wstring product_version() = 0; + virtual std::wstring private_build() = 0; + virtual std::wstring special_build() = 0; + virtual std::wstring comments() = 0; + virtual std::wstring original_filename() = 0; + virtual std::wstring file_description() = 0; + virtual std::wstring file_version() = 0; + virtual std::wstring legal_copyright() = 0; + virtual std::wstring legal_trademarks() = 0; + virtual std::wstring last_change() = 0; + virtual bool is_official_build() = 0; }; #endif // BASE_FILE_VERSION_INFO_H__ diff --git a/base/file_version_info_linux.cc b/base/file_version_info_linux.cc deleted file mode 100644 index 55e1bd2..0000000 --- a/base/file_version_info_linux.cc +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/file_version_info.h" -#include "base/file_version_info_linux.h" - -#include <string> - -// TODO(mmoss) This only provides version info for the current binary, but it's -// also called for arbitrary files (e.g. plugins). -// See http://code.google.com/p/chromium/issues/detail?id=8132 for a discussion -// on what we should do with this module. - -FileVersionInfo::FileVersionInfo() {} - -FileVersionInfo::~FileVersionInfo() {} - -// static -FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { - return new FileVersionInfo(); -} - -std::wstring FileVersionInfo::company_name() { - return COMPANY_NAME; -} - -std::wstring FileVersionInfo::company_short_name() { - return COMPANY_SHORT_NAME; -} - -std::wstring FileVersionInfo::product_name() { - return PRODUCT_NAME; -} - -std::wstring FileVersionInfo::product_short_name() { - return PRODUCT_SHORT_NAME; -} - -std::wstring FileVersionInfo::internal_name() { - return INTERNAL_NAME; -} - -std::wstring FileVersionInfo::product_version() { - return PRODUCT_VERSION; -} - -std::wstring FileVersionInfo::private_build() { - return PRIVATE_BUILD; -} - -std::wstring FileVersionInfo::special_build() { - return SPECIAL_BUILD; -} - -std::wstring FileVersionInfo::comments() { - return COMMENTS; -} - -std::wstring FileVersionInfo::original_filename() { - return ORIGINAL_FILENAME; -} - -std::wstring FileVersionInfo::file_description() { - return FILE_DESCRIPTION; -} - -std::wstring FileVersionInfo::file_version() { - return FILE_VERSION; -} - -std::wstring FileVersionInfo::legal_copyright() { - return LEGAL_COPYRIGHT; -} - -std::wstring FileVersionInfo::legal_trademarks() { - return LEGAL_TRADEMARKS; -} - -std::wstring FileVersionInfo::last_change() { - return LAST_CHANGE; -} - -bool FileVersionInfo::is_official_build() { - return OFFICIAL_BUILD; -} diff --git a/base/file_version_info_linux.h.version b/base/file_version_info_linux.h.version deleted file mode 100644 index 88bf234..0000000 --- a/base/file_version_info_linux.h.version +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_FILE_VERSION_INFO_LINUX_H_ -#define BASE_FILE_VERSION_INFO_LINUX_H_ - -#define COMPANY_NAME L"@COMPANY_FULLNAME@" -#define FILE_DESCRIPTION L"@PRODUCT_FULLNAME@" -#define FILE_VERSION L"@MAJOR@.@MINOR@.@BUILD@.@PATCH@" -#define LEGAL_COPYRIGHT L"@COPYRIGHT@" -#define PRODUCT_NAME L"@PRODUCT_FULLNAME@" -#define PRODUCT_VERSION L"@MAJOR@.@MINOR@.@BUILD@.@PATCH@" -#define COMPANY_SHORT_NAME L"@COMPANY_SHORTNAME@" -#define PRODUCT_SHORT_NAME L"@PRODUCT_SHORTNAME@" -#define LAST_CHANGE L"@LASTCHANGE@" -#define OFFICIAL_BUILD @OFFICIAL_BUILD@ -// TODO(mmoss) Do these have values for Linux? -#define INTERNAL_NAME L"" -#define ORIGINAL_FILENAME L"" -#define PRIVATE_BUILD L"" -#define SPECIAL_BUILD L"" -#define COMMENTS L"" -#define LEGAL_TRADEMARKS L"" - -#endif // BASE_FILE_VERSION_INFO_LINUX_H_ diff --git a/base/file_version_info_mac.h b/base/file_version_info_mac.h new file mode 100644 index 0000000..a523f54 --- /dev/null +++ b/base/file_version_info_mac.h @@ -0,0 +1,63 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_FILE_VERSION_INFO_MAC_H_ +#define BASE_FILE_VERSION_INFO_MAC_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/file_version_info.h" +#include "base/scoped_ptr.h" + +#ifdef __OBJC__ +@class NSBundle; +#else +class NSBundle; +#endif + +class FilePath; + +// Provides a way to access the version information for a file. +// This is the information you access when you select a file in the Windows +// explorer, right-click select Properties, then click the Version tab. + +class FileVersionInfoMac : public FileVersionInfo { + public: + explicit FileVersionInfoMac(NSBundle *bundle); + ~FileVersionInfoMac(); + + // Accessors to the different version properties. + // Returns an empty string if the property is not found. + virtual std::wstring company_name(); + virtual std::wstring company_short_name(); + virtual std::wstring product_name(); + virtual std::wstring product_short_name(); + virtual std::wstring internal_name(); + virtual std::wstring product_version(); + virtual std::wstring private_build(); + virtual std::wstring special_build(); + virtual std::wstring comments(); + virtual std::wstring original_filename(); + virtual std::wstring file_description(); + virtual std::wstring file_version(); + virtual std::wstring legal_copyright(); + virtual std::wstring legal_trademarks(); + virtual std::wstring last_change(); + virtual bool is_official_build(); + + private: + // Lets you access other properties not covered above. + bool GetValue(const wchar_t* name, std::wstring* value); + + // Similar to GetValue but returns a wstring (empty string if the property + // does not exist). + std::wstring GetStringValue(const wchar_t* name); + + NSBundle *bundle_; + + DISALLOW_COPY_AND_ASSIGN(FileVersionInfoMac); +}; + +#endif // BASE_FILE_VERSION_INFO_MAC_H_ diff --git a/base/file_version_info_mac.mm b/base/file_version_info_mac.mm index c1395df..2218226 100644 --- a/base/file_version_info_mac.mm +++ b/base/file_version_info_mac.mm @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/file_version_info.h" +#include "base/file_version_info_mac.h" #import <Cocoa/Cocoa.h> @@ -11,11 +11,11 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" -FileVersionInfo::FileVersionInfo(NSBundle *bundle) : bundle_(bundle) { +FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) : bundle_(bundle) { [bundle_ retain]; } -FileVersionInfo::~FileVersionInfo() { +FileVersionInfoMac::~FileVersionInfoMac() { [bundle_ release]; } @@ -24,7 +24,7 @@ FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { // TODO(erikkay): this should really use bundleForClass, but we don't have // a class to hang onto yet. NSBundle* bundle = [NSBundle mainBundle]; - return new FileVersionInfo(bundle); + return new FileVersionInfoMac(bundle); } // static @@ -33,77 +33,77 @@ FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( NSString* path = [NSString stringWithCString: reinterpret_cast<const char*>(file_path.c_str()) encoding:NSUTF32StringEncoding]; - return new FileVersionInfo([NSBundle bundleWithPath:path]); + return new FileVersionInfoMac([NSBundle bundleWithPath:path]); } // static FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( const FilePath& file_path) { NSString* path = [NSString stringWithUTF8String:file_path.value().c_str()]; - return new FileVersionInfo([NSBundle bundleWithPath:path]); + return new FileVersionInfoMac([NSBundle bundleWithPath:path]); } -std::wstring FileVersionInfo::company_name() { +std::wstring FileVersionInfoMac::company_name() { return std::wstring(); } -std::wstring FileVersionInfo::company_short_name() { +std::wstring FileVersionInfoMac::company_short_name() { return std::wstring(); } -std::wstring FileVersionInfo::internal_name() { +std::wstring FileVersionInfoMac::internal_name() { return std::wstring(); } -std::wstring FileVersionInfo::product_name() { +std::wstring FileVersionInfoMac::product_name() { return GetStringValue(L"CFBundleName"); } -std::wstring FileVersionInfo::product_short_name() { +std::wstring FileVersionInfoMac::product_short_name() { return GetStringValue(L"CFBundleName"); } -std::wstring FileVersionInfo::comments() { +std::wstring FileVersionInfoMac::comments() { return std::wstring(); } -std::wstring FileVersionInfo::legal_copyright() { +std::wstring FileVersionInfoMac::legal_copyright() { return GetStringValue(L"CFBundleGetInfoString"); } -std::wstring FileVersionInfo::product_version() { +std::wstring FileVersionInfoMac::product_version() { return GetStringValue(L"CFBundleShortVersionString"); } -std::wstring FileVersionInfo::file_description() { +std::wstring FileVersionInfoMac::file_description() { return std::wstring(); } -std::wstring FileVersionInfo::legal_trademarks() { +std::wstring FileVersionInfoMac::legal_trademarks() { return std::wstring(); } -std::wstring FileVersionInfo::private_build() { +std::wstring FileVersionInfoMac::private_build() { return std::wstring(); } -std::wstring FileVersionInfo::file_version() { +std::wstring FileVersionInfoMac::file_version() { return product_version(); } -std::wstring FileVersionInfo::original_filename() { +std::wstring FileVersionInfoMac::original_filename() { return GetStringValue(L"CFBundleName"); } -std::wstring FileVersionInfo::special_build() { +std::wstring FileVersionInfoMac::special_build() { return std::wstring(); } -std::wstring FileVersionInfo::last_change() { +std::wstring FileVersionInfoMac::last_change() { return GetStringValue(L"SVNRevision"); } -bool FileVersionInfo::is_official_build() { +bool FileVersionInfoMac::is_official_build() { #if defined (GOOGLE_CHROME_BUILD) return true; #else @@ -111,7 +111,8 @@ bool FileVersionInfo::is_official_build() { #endif } -bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) { +bool FileVersionInfoMac::GetValue(const wchar_t* name, + std::wstring* value_str) { if (bundle_) { NSString* value = [bundle_ objectForInfoDictionaryKey: [NSString stringWithUTF8String:WideToUTF8(name).c_str()]]; @@ -124,7 +125,7 @@ bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) { return false; } -std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) { +std::wstring FileVersionInfoMac::GetStringValue(const wchar_t* name) { std::wstring str; if (GetValue(name, &str)) return str; diff --git a/base/file_version_info_unittest.cc b/base/file_version_info_unittest.cc index 676e950..4e058f4 100644 --- a/base/file_version_info_unittest.cc +++ b/base/file_version_info_unittest.cc @@ -8,6 +8,10 @@ #include "base/file_version_info.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_WIN) +#include "base/file_version_info_win.h" +#endif + namespace { class FileVersionInfoTest : public testing::Test { @@ -24,7 +28,7 @@ FilePath GetTestDataPath() { } -#ifdef OS_WIN +#if defined(OS_WIN) TEST(FileVersionInfoTest, HardCodedProperties) { const wchar_t* kDLLNames[] = { L"FileVersionInfoTest1.dll" @@ -76,7 +80,7 @@ TEST(FileVersionInfoTest, HardCodedProperties) { } #endif -#ifdef OS_WIN +#if defined(OS_WIN) TEST(FileVersionInfoTest, IsOfficialBuild) { const wchar_t* kDLLNames[] = { L"FileVersionInfoTest1.dll", @@ -103,6 +107,7 @@ TEST(FileVersionInfoTest, IsOfficialBuild) { } #endif +#if defined(OS_WIN) TEST(FileVersionInfoTest, CustomProperties) { FilePath dll_path = GetTestDataPath(); dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll"); @@ -112,22 +117,23 @@ TEST(FileVersionInfoTest, CustomProperties) { // Test few existing properties. std::wstring str; -#ifdef OS_WIN - EXPECT_TRUE(version_info->GetValue(L"Custom prop 1", &str)); + FileVersionInfoWin* version_info_win = + static_cast<FileVersionInfoWin*>(version_info.get()); + EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 1", &str)); EXPECT_EQ(L"Un", str); - EXPECT_EQ(L"Un", version_info->GetStringValue(L"Custom prop 1")); + EXPECT_EQ(L"Un", version_info_win->GetStringValue(L"Custom prop 1")); - EXPECT_TRUE(version_info->GetValue(L"Custom prop 2", &str)); + EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 2", &str)); EXPECT_EQ(L"Deux", str); - EXPECT_EQ(L"Deux", version_info->GetStringValue(L"Custom prop 2")); + EXPECT_EQ(L"Deux", version_info_win->GetStringValue(L"Custom prop 2")); - EXPECT_TRUE(version_info->GetValue(L"Custom prop 3", &str)); + EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 3", &str)); EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", str); EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", - version_info->GetStringValue(L"Custom prop 3")); -#endif + version_info_win->GetStringValue(L"Custom prop 3")); // Test an non-existing property. - EXPECT_FALSE(version_info->GetValue(L"Unknown property", &str)); - EXPECT_EQ(L"", version_info->GetStringValue(L"Unknown property")); + EXPECT_FALSE(version_info_win->GetValue(L"Unknown property", &str)); + EXPECT_EQ(L"", version_info_win->GetStringValue(L"Unknown property")); } +#endif diff --git a/base/file_version_info.cc b/base/file_version_info_win.cc index f9bee21..d1049b8 100644 --- a/base/file_version_info.cc +++ b/base/file_version_info_win.cc @@ -2,18 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/file_version_info.h" +#include "base/file_version_info_win.h" #include <windows.h> #include "base/file_path.h" +#include "base/file_version_info.h" #include "base/logging.h" #include "base/path_service.h" // This has to be last. #include <strsafe.h> -FileVersionInfo::FileVersionInfo(void* data, int language, int code_page) +FileVersionInfoWin::FileVersionInfoWin(void* data, int language, int code_page) : language_(language), code_page_(code_page) { data_.reset((char*) data); fixed_file_info_ = NULL; @@ -21,7 +22,7 @@ FileVersionInfo::FileVersionInfo(void* data, int language, int code_page) ::VerQueryValue(data_.get(), L"\\", (LPVOID*)&fixed_file_info_, &size); } -FileVersionInfo::~FileVersionInfo() { +FileVersionInfoWin::~FileVersionInfoWin() { DCHECK(data_.get()); } @@ -63,8 +64,8 @@ FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( (void**) &translate, &page_count); if (query_result && translate) { - return new FileVersionInfo(data, translate->language, - translate->code_page); + return new FileVersionInfoWin(data, translate->language, + translate->code_page); } else { free(data); @@ -72,78 +73,79 @@ FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( } } +// static FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( const std::wstring& file_path) { FilePath file_path_fp = FilePath::FromWStringHack(file_path); return CreateFileVersionInfo(file_path_fp); } -std::wstring FileVersionInfo::company_name() { +std::wstring FileVersionInfoWin::company_name() { return GetStringValue(L"CompanyName"); } -std::wstring FileVersionInfo::company_short_name() { +std::wstring FileVersionInfoWin::company_short_name() { return GetStringValue(L"CompanyShortName"); } -std::wstring FileVersionInfo::internal_name() { +std::wstring FileVersionInfoWin::internal_name() { return GetStringValue(L"InternalName"); } -std::wstring FileVersionInfo::product_name() { +std::wstring FileVersionInfoWin::product_name() { return GetStringValue(L"ProductName"); } -std::wstring FileVersionInfo::product_short_name() { +std::wstring FileVersionInfoWin::product_short_name() { return GetStringValue(L"ProductShortName"); } -std::wstring FileVersionInfo::comments() { +std::wstring FileVersionInfoWin::comments() { return GetStringValue(L"Comments"); } -std::wstring FileVersionInfo::legal_copyright() { +std::wstring FileVersionInfoWin::legal_copyright() { return GetStringValue(L"LegalCopyright"); } -std::wstring FileVersionInfo::product_version() { +std::wstring FileVersionInfoWin::product_version() { return GetStringValue(L"ProductVersion"); } -std::wstring FileVersionInfo::file_description() { +std::wstring FileVersionInfoWin::file_description() { return GetStringValue(L"FileDescription"); } -std::wstring FileVersionInfo::legal_trademarks() { +std::wstring FileVersionInfoWin::legal_trademarks() { return GetStringValue(L"LegalTrademarks"); } -std::wstring FileVersionInfo::private_build() { +std::wstring FileVersionInfoWin::private_build() { return GetStringValue(L"PrivateBuild"); } -std::wstring FileVersionInfo::file_version() { +std::wstring FileVersionInfoWin::file_version() { return GetStringValue(L"FileVersion"); } -std::wstring FileVersionInfo::original_filename() { +std::wstring FileVersionInfoWin::original_filename() { return GetStringValue(L"OriginalFilename"); } -std::wstring FileVersionInfo::special_build() { +std::wstring FileVersionInfoWin::special_build() { return GetStringValue(L"SpecialBuild"); } -std::wstring FileVersionInfo::last_change() { +std::wstring FileVersionInfoWin::last_change() { return GetStringValue(L"LastChange"); } -bool FileVersionInfo::is_official_build() { +bool FileVersionInfoWin::is_official_build() { return (GetStringValue(L"Official Build").compare(L"1") == 0); } -bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) { - +bool FileVersionInfoWin::GetValue(const wchar_t* name, + std::wstring* value_str) { WORD lang_codepage[8]; int i = 0; // Use the language and codepage from the DLL. @@ -177,7 +179,7 @@ bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) { return false; } -std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) { +std::wstring FileVersionInfoWin::GetStringValue(const wchar_t* name) { std::wstring str; if (GetValue(name, &str)) return str; diff --git a/base/file_version_info_win.h b/base/file_version_info_win.h new file mode 100644 index 0000000..ce173fe --- /dev/null +++ b/base/file_version_info_win.h @@ -0,0 +1,67 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_FILE_VERSION_INFO_WIN_H_ +#define BASE_FILE_VERSION_INFO_WIN_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/file_version_info.h" +#include "base/scoped_ptr.h" + +struct tagVS_FIXEDFILEINFO; +typedef tagVS_FIXEDFILEINFO VS_FIXEDFILEINFO; + +class FilePath; + +// Provides a way to access the version information for a file. +// This is the information you access when you select a file in the Windows +// explorer, right-click select Properties, then click the Version tab. + +class FileVersionInfoWin : public FileVersionInfo { + public: + FileVersionInfoWin(void* data, int language, int code_page); + ~FileVersionInfoWin(); + + // Accessors to the different version properties. + // Returns an empty string if the property is not found. + virtual std::wstring company_name(); + virtual std::wstring company_short_name(); + virtual std::wstring product_name(); + virtual std::wstring product_short_name(); + virtual std::wstring internal_name(); + virtual std::wstring product_version(); + virtual std::wstring private_build(); + virtual std::wstring special_build(); + virtual std::wstring comments(); + virtual std::wstring original_filename(); + virtual std::wstring file_description(); + virtual std::wstring file_version(); + virtual std::wstring legal_copyright(); + virtual std::wstring legal_trademarks(); + virtual std::wstring last_change(); + virtual bool is_official_build(); + + // Lets you access other properties not covered above. + bool GetValue(const wchar_t* name, std::wstring* value); + + // Similar to GetValue but returns a wstring (empty string if the property + // does not exist). + std::wstring GetStringValue(const wchar_t* name); + + // Get the fixed file info if it exists. Otherwise NULL + VS_FIXEDFILEINFO* fixed_file_info() { return fixed_file_info_; } + + private: + scoped_ptr_malloc<char> data_; + int language_; + int code_page_; + // This is a pointer into the data_ if it exists. Otherwise NULL. + VS_FIXEDFILEINFO* fixed_file_info_; + + DISALLOW_COPY_AND_ASSIGN(FileVersionInfoWin); +}; + +#endif // BASE_FILE_VERSION_INFO_WIN_H_ |