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" |
13 | 12 |
14 FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) : bundle_(bundle) { | 13 FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) : bundle_(bundle) { |
15 [bundle_ retain]; | |
16 } | |
17 | |
18 FileVersionInfoMac::~FileVersionInfoMac() { | |
19 [bundle_ release]; | |
20 } | 14 } |
21 | 15 |
22 // static | 16 // static |
23 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { | 17 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { |
24 // TODO(erikkay): this should really use bundleForClass, but we don't have | 18 // TODO(erikkay): this should really use bundleForClass, but we don't have |
25 // a class to hang onto yet. | 19 // a class to hang onto yet. |
26 NSBundle* bundle = [NSBundle mainBundle]; | 20 NSBundle* bundle = [NSBundle mainBundle]; |
27 return new FileVersionInfoMac(bundle); | 21 if (![bundle bundleIdentifier]) { |
Erik does not do reviews
2010/12/14 19:16:32
if mainBundle is bogus, don't we have a big proble
| |
22 VLOG(1) << "Unable to create file version for " | |
23 << base::SysNSStringToUTF8([bundle description]); | |
24 return NULL; | |
25 } else { | |
26 return new FileVersionInfoMac(bundle); | |
27 } | |
28 } | 28 } |
29 | 29 |
30 // static | 30 // static |
31 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( | 31 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( |
32 const std::wstring& file_path) { | 32 const std::wstring& file_path) { |
33 NSString* path = [NSString stringWithCString: | 33 NSString* path = base::SysWideToNSString(file_path); |
34 reinterpret_cast<const char*>(file_path.c_str()) | 34 NSBundle *bundle = [NSBundle bundleWithPath:path]; |
35 encoding:NSUTF32StringEncoding]; | 35 if (![bundle bundleIdentifier]) { |
36 return new FileVersionInfoMac([NSBundle bundleWithPath:path]); | 36 VLOG(1) << "Unable to create file version for " |
37 << base::SysNSStringToUTF8([bundle description]); | |
38 return NULL; | |
39 } else { | |
40 return new FileVersionInfoMac(bundle); | |
41 } | |
37 } | 42 } |
38 | 43 |
39 // static | 44 // static |
40 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( | 45 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( |
41 const FilePath& file_path) { | 46 const FilePath& file_path) { |
42 NSString* path = [NSString stringWithUTF8String:file_path.value().c_str()]; | 47 NSString* path = base::SysUTF8ToNSString(file_path.value()); |
43 return new FileVersionInfoMac([NSBundle bundleWithPath:path]); | 48 return new FileVersionInfoMac([NSBundle bundleWithPath:path]); |
44 } | 49 } |
45 | 50 |
46 std::wstring FileVersionInfoMac::company_name() { | 51 std::wstring FileVersionInfoMac::company_name() { |
47 return std::wstring(); | 52 return std::wstring(); |
48 } | 53 } |
49 | 54 |
50 std::wstring FileVersionInfoMac::company_short_name() { | 55 std::wstring FileVersionInfoMac::company_short_name() { |
51 return std::wstring(); | 56 return std::wstring(); |
52 } | 57 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 #if defined (GOOGLE_CHROME_BUILD) | 112 #if defined (GOOGLE_CHROME_BUILD) |
108 return true; | 113 return true; |
109 #else | 114 #else |
110 return false; | 115 return false; |
111 #endif | 116 #endif |
112 } | 117 } |
113 | 118 |
114 bool FileVersionInfoMac::GetValue(const wchar_t* name, | 119 bool FileVersionInfoMac::GetValue(const wchar_t* name, |
115 std::wstring* value_str) { | 120 std::wstring* value_str) { |
116 if (bundle_) { | 121 if (bundle_) { |
117 NSString* value = [bundle_ objectForInfoDictionaryKey: | 122 NSString* ns_name = base::SysWideToNSString(name); |
118 [NSString stringWithUTF8String:WideToUTF8(name).c_str()]]; | 123 NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name]; |
119 if (value) { | 124 if (value) { |
120 *value_str = reinterpret_cast<const wchar_t*>( | 125 *value_str = base::SysNSStringToWide(value); |
121 [value cStringUsingEncoding:NSUTF32StringEncoding]); | |
122 return true; | 126 return true; |
123 } | 127 } |
124 } | 128 } |
125 return false; | 129 return false; |
126 } | 130 } |
127 | 131 |
128 std::wstring FileVersionInfoMac::GetStringValue(const wchar_t* name) { | 132 std::wstring FileVersionInfoMac::GetStringValue(const wchar_t* name) { |
129 std::wstring str; | 133 std::wstring str; |
130 if (GetValue(name, &str)) | 134 if (GetValue(name, &str)) |
131 return str; | 135 return str; |
132 return std::wstring(); | 136 return std::wstring(); |
133 } | 137 } |
OLD | NEW |