1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_FILE_VERSION_INFO_H__ 6 #define BASE_FILE_VERSION_INFO_H__ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/scoped_ptr.h" 12 13 #if defined(OS_WIN) 14 struct tagVS_FIXEDFILEINFO; 15 typedef tagVS_FIXEDFILEINFO VS_FIXEDFILEINFO; 16 #elif defined(OS_MACOSX) 17 #ifdef __OBJC__ 18 @class NSBundle; 19 #else 20 class NSBundle; 21 #endif 22 #endif 23 24 class FilePath; 25 26 // Provides a way to access the version information for a file. 27 // This is the information you access when you select a file in the Windows 28 // explorer, right-click select Properties, then click the Version tab. 29 30 class FileVersionInfo { 31 public: 32 // Creates a FileVersionInfo for the specified path. Returns NULL if something 33 // goes wrong (typically the file does not exit or cannot be opened). The 34 // returned object should be deleted when you are done with it. 35 static FileVersionInfo* CreateFileVersionInfo(const FilePath& file_path); 36 // This version, taking a wstring, is deprecated and only kept around 37 // until we can fix all callers. 38 static FileVersionInfo* CreateFileVersionInfo(const std::wstring& file_path); 39 40 // Creates a FileVersionInfo for the current module. Returns NULL in case 41 // of error. The returned object should be deleted when you are done with it. 42 static FileVersionInfo* CreateFileVersionInfoForCurrentModule(); 43 44 ~FileVersionInfo(); 45 46 // Accessors to the different version properties. 47 // Returns an empty string if the property is not found. 48 std::wstring company_name(); 49 std::wstring company_short_name(); 50 std::wstring product_name(); 51 std::wstring product_short_name(); 52 std::wstring internal_name(); 53 std::wstring product_version(); 54 std::wstring private_build(); 55 std::wstring special_build(); 56 std::wstring comments(); 57 std::wstring original_filename(); 58 std::wstring file_description(); 59 std::wstring file_version(); 60 std::wstring legal_copyright(); 61 std::wstring legal_trademarks(); 62 std::wstring last_change(); 63 bool is_official_build(); 64 65 // Lets you access other properties not covered above. 66 bool GetValue(const wchar_t* name, std::wstring* value); 67 68 // Similar to GetValue but returns a wstring (empty string if the property 69 // does not exist). 70 std::wstring GetStringValue(const wchar_t* name); 71 72 #ifdef OS_WIN 73 // Get the fixed file info if it exists. Otherwise NULL fixed_file_info()74 VS_FIXEDFILEINFO* fixed_file_info() { return fixed_file_info_; } 75 #endif 76 77 private: 78 #if defined(OS_WIN) 79 FileVersionInfo(void* data, int language, int code_page); 80 81 scoped_ptr_malloc<char> data_; 82 int language_; 83 int code_page_; 84 // This is a pointer into the data_ if it exists. Otherwise NULL. 85 VS_FIXEDFILEINFO* fixed_file_info_; 86 #elif defined(OS_MACOSX) 87 explicit FileVersionInfo(NSBundle *bundle); 88 89 NSBundle *bundle_; 90 #elif defined(OS_POSIX) 91 FileVersionInfo(); 92 #endif 93 94 DISALLOW_EVIL_CONSTRUCTORS(FileVersionInfo); 95 }; 96 97 #endif // BASE_FILE_VERSION_INFO_H__ 98