OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_version_info_mac.h" | 5 #include "base/file_version_info_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include "base/basictypes.h" | |
10 #include "base/file_path.h" | 9 #include "base/file_path.h" |
11 #include "base/string_util.h" | 10 #include "base/logging.h" |
12 #include "base/utf_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
| 12 #include "base/mac_util.h" |
13 | 13 |
14 FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) : bundle_(bundle) { | 14 FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) : bundle_(bundle) { |
15 [bundle_ retain]; | |
16 } | |
17 | |
18 FileVersionInfoMac::~FileVersionInfoMac() { | |
19 [bundle_ release]; | |
20 } | 15 } |
21 | 16 |
22 // static | 17 // static |
23 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { | 18 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { |
24 // TODO(erikkay): this should really use bundleForClass, but we don't have | 19 return CreateFileVersionInfo(mac_util::MainAppBundlePath()); |
25 // a class to hang onto yet. | |
26 NSBundle* bundle = [NSBundle mainBundle]; | |
27 return new FileVersionInfoMac(bundle); | |
28 } | |
29 | |
30 // static | |
31 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( | |
32 const std::wstring& file_path) { | |
33 NSString* path = [NSString stringWithCString: | |
34 reinterpret_cast<const char*>(file_path.c_str()) | |
35 encoding:NSUTF32StringEncoding]; | |
36 return new FileVersionInfoMac([NSBundle bundleWithPath:path]); | |
37 } | 20 } |
38 | 21 |
39 // static | 22 // static |
40 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( | 23 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( |
41 const FilePath& file_path) { | 24 const FilePath& file_path) { |
42 NSString* path = [NSString stringWithUTF8String:file_path.value().c_str()]; | 25 NSString* path = base::SysUTF8ToNSString(file_path.value()); |
43 return new FileVersionInfoMac([NSBundle bundleWithPath:path]); | 26 NSBundle* bundle = [NSBundle bundleWithPath:path]; |
| 27 return new FileVersionInfoMac(bundle); |
44 } | 28 } |
45 | 29 |
46 std::wstring FileVersionInfoMac::company_name() { | 30 std::wstring FileVersionInfoMac::company_name() { |
47 return std::wstring(); | 31 return std::wstring(); |
48 } | 32 } |
49 | 33 |
50 std::wstring FileVersionInfoMac::company_short_name() { | 34 std::wstring FileVersionInfoMac::company_short_name() { |
51 return std::wstring(); | 35 return std::wstring(); |
52 } | 36 } |
53 | 37 |
54 std::wstring FileVersionInfoMac::internal_name() { | 38 std::wstring FileVersionInfoMac::internal_name() { |
55 return std::wstring(); | 39 return std::wstring(); |
56 } | 40 } |
57 | 41 |
58 std::wstring FileVersionInfoMac::product_name() { | 42 std::wstring FileVersionInfoMac::product_name() { |
59 return GetStringValue(L"CFBundleName"); | 43 return GetWStringValue(kCFBundleNameKey); |
60 } | 44 } |
61 | 45 |
62 std::wstring FileVersionInfoMac::product_short_name() { | 46 std::wstring FileVersionInfoMac::product_short_name() { |
63 return GetStringValue(L"CFBundleName"); | 47 return GetWStringValue(kCFBundleNameKey); |
64 } | 48 } |
65 | 49 |
66 std::wstring FileVersionInfoMac::comments() { | 50 std::wstring FileVersionInfoMac::comments() { |
67 return std::wstring(); | 51 return std::wstring(); |
68 } | 52 } |
69 | 53 |
70 std::wstring FileVersionInfoMac::legal_copyright() { | 54 std::wstring FileVersionInfoMac::legal_copyright() { |
71 return GetStringValue(L"CFBundleGetInfoString"); | 55 return GetWStringValue(CFSTR("CFBundleGetInfoString")); |
72 } | 56 } |
73 | 57 |
74 std::wstring FileVersionInfoMac::product_version() { | 58 std::wstring FileVersionInfoMac::product_version() { |
75 return GetStringValue(L"CFBundleShortVersionString"); | 59 return GetWStringValue(CFSTR("CFBundleShortVersionString")); |
76 } | 60 } |
77 | 61 |
78 std::wstring FileVersionInfoMac::file_description() { | 62 std::wstring FileVersionInfoMac::file_description() { |
79 return std::wstring(); | 63 return std::wstring(); |
80 } | 64 } |
81 | 65 |
82 std::wstring FileVersionInfoMac::legal_trademarks() { | 66 std::wstring FileVersionInfoMac::legal_trademarks() { |
83 return std::wstring(); | 67 return std::wstring(); |
84 } | 68 } |
85 | 69 |
86 std::wstring FileVersionInfoMac::private_build() { | 70 std::wstring FileVersionInfoMac::private_build() { |
87 return std::wstring(); | 71 return std::wstring(); |
88 } | 72 } |
89 | 73 |
90 std::wstring FileVersionInfoMac::file_version() { | 74 std::wstring FileVersionInfoMac::file_version() { |
91 return product_version(); | 75 return product_version(); |
92 } | 76 } |
93 | 77 |
94 std::wstring FileVersionInfoMac::original_filename() { | 78 std::wstring FileVersionInfoMac::original_filename() { |
95 return GetStringValue(L"CFBundleName"); | 79 return GetWStringValue(kCFBundleNameKey); |
96 } | 80 } |
97 | 81 |
98 std::wstring FileVersionInfoMac::special_build() { | 82 std::wstring FileVersionInfoMac::special_build() { |
99 return std::wstring(); | 83 return std::wstring(); |
100 } | 84 } |
101 | 85 |
102 std::wstring FileVersionInfoMac::last_change() { | 86 std::wstring FileVersionInfoMac::last_change() { |
103 return GetStringValue(L"SVNRevision"); | 87 return GetWStringValue(CFSTR("SVNRevision")); |
104 } | 88 } |
105 | 89 |
106 bool FileVersionInfoMac::is_official_build() { | 90 bool FileVersionInfoMac::is_official_build() { |
107 #if defined (GOOGLE_CHROME_BUILD) | 91 #if defined (GOOGLE_CHROME_BUILD) |
108 return true; | 92 return true; |
109 #else | 93 #else |
110 return false; | 94 return false; |
111 #endif | 95 #endif |
112 } | 96 } |
113 | 97 |
114 bool FileVersionInfoMac::GetValue(const wchar_t* name, | 98 std::wstring FileVersionInfoMac::GetWStringValue(CFStringRef name) { |
115 std::wstring* value_str) { | |
116 if (bundle_) { | 99 if (bundle_) { |
117 NSString* value = [bundle_ objectForInfoDictionaryKey: | 100 NSString *ns_name = mac_util::CFToNSCast(name); |
118 [NSString stringWithUTF8String:WideToUTF8(name).c_str()]]; | 101 NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name]; |
119 if (value) { | 102 if (value) { |
120 *value_str = reinterpret_cast<const wchar_t*>( | 103 return base::SysNSStringToWide(value); |
121 [value cStringUsingEncoding:NSUTF32StringEncoding]); | |
122 return true; | |
123 } | 104 } |
124 } | 105 } |
125 return false; | |
126 } | |
127 | |
128 std::wstring FileVersionInfoMac::GetStringValue(const wchar_t* name) { | |
129 std::wstring str; | |
130 if (GetValue(name, &str)) | |
131 return str; | |
132 return std::wstring(); | 106 return std::wstring(); |
133 } | 107 } |
OLD | NEW |