Chromium Code Reviews| Index: base/file_version_info_mac.mm |
| diff --git a/base/file_version_info_mac.mm b/base/file_version_info_mac.mm |
| index 57be79ad864156d17b48f09bac0b937075a51486..71adc751085684bc90a5cce7111439b35e64d502 100644 |
| --- a/base/file_version_info_mac.mm |
| +++ b/base/file_version_info_mac.mm |
| @@ -4,43 +4,33 @@ |
| #include "base/file_version_info_mac.h" |
| -#import <Cocoa/Cocoa.h> |
| +#import <Foundation/Foundation.h> |
|
Mark Mentovai
2010/12/16 22:11:47
:) Thanks!
|
| -#include "base/basictypes.h" |
| #include "base/file_path.h" |
| -#include "base/string_util.h" |
| -#include "base/utf_string_conversions.h" |
| +#include "base/logging.h" |
| +#include "base/sys_string_conversions.h" |
| +#include "base/mac_util.h" |
| FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) : bundle_(bundle) { |
| - [bundle_ retain]; |
| -} |
| - |
| -FileVersionInfoMac::~FileVersionInfoMac() { |
| - [bundle_ release]; |
| } |
| // static |
| 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 FileVersionInfoMac(bundle); |
| -} |
| - |
| -// static |
| -FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( |
| - const std::wstring& file_path) { |
| - NSString* path = [NSString stringWithCString: |
| - reinterpret_cast<const char*>(file_path.c_str()) |
| - encoding:NSUTF32StringEncoding]; |
| - return new FileVersionInfoMac([NSBundle bundleWithPath:path]); |
| + return CreateFileVersionInfo(mac_util::MainAppBundlePath()); |
|
Mark Mentovai
2010/12/16 22:11:47
Ah, that’ll do.
|
| } |
| // static |
| FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( |
| const FilePath& file_path) { |
| - NSString* path = [NSString stringWithUTF8String:file_path.value().c_str()]; |
| - return new FileVersionInfoMac([NSBundle bundleWithPath:path]); |
| + NSString* path = base::SysUTF8ToNSString(file_path.value()); |
| + NSBundle *bundle = [NSBundle bundleWithPath:path]; |
| + NSString *identifier = [bundle bundleIdentifier]; |
| + if (!identifier) { |
| + NOTREACHED() << "Unable to create file version for " << file_path.value(); |
| + return NULL; |
| + } else { |
| + return new FileVersionInfoMac(bundle); |
| + } |
| } |
| std::wstring FileVersionInfoMac::company_name() { |
| @@ -56,11 +46,11 @@ std::wstring FileVersionInfoMac::internal_name() { |
| } |
| std::wstring FileVersionInfoMac::product_name() { |
| - return GetStringValue(L"CFBundleName"); |
| + return GetStringValue(kCFBundleNameKey); |
| } |
| std::wstring FileVersionInfoMac::product_short_name() { |
| - return GetStringValue(L"CFBundleName"); |
| + return GetStringValue(kCFBundleNameKey); |
| } |
| std::wstring FileVersionInfoMac::comments() { |
| @@ -68,11 +58,11 @@ std::wstring FileVersionInfoMac::comments() { |
| } |
| std::wstring FileVersionInfoMac::legal_copyright() { |
| - return GetStringValue(L"CFBundleGetInfoString"); |
| + return GetStringValue(CFSTR("CFBundleGetInfoString")); |
| } |
| std::wstring FileVersionInfoMac::product_version() { |
| - return GetStringValue(L"CFBundleShortVersionString"); |
| + return GetStringValue(CFSTR("CFBundleShortVersionString")); |
| } |
| std::wstring FileVersionInfoMac::file_description() { |
| @@ -92,7 +82,7 @@ std::wstring FileVersionInfoMac::file_version() { |
| } |
| std::wstring FileVersionInfoMac::original_filename() { |
| - return GetStringValue(L"CFBundleName"); |
| + return GetStringValue(kCFBundleNameKey); |
| } |
| std::wstring FileVersionInfoMac::special_build() { |
| @@ -100,7 +90,7 @@ std::wstring FileVersionInfoMac::special_build() { |
| } |
| std::wstring FileVersionInfoMac::last_change() { |
| - return GetStringValue(L"SVNRevision"); |
| + return GetStringValue(CFSTR("SVNRevision_")); |
|
Mark Mentovai
2010/12/16 22:11:47
Underscore? Eh?
dmac
2010/12/16 22:20:42
Good catch. Not sure how that got in there...
|
| } |
| bool FileVersionInfoMac::is_official_build() { |
| @@ -111,23 +101,13 @@ bool FileVersionInfoMac::is_official_build() { |
| #endif |
| } |
| -bool FileVersionInfoMac::GetValue(const wchar_t* name, |
| - std::wstring* value_str) { |
| +std::wstring FileVersionInfoMac::GetStringValue(CFStringRef name) { |
| if (bundle_) { |
| - NSString* value = [bundle_ objectForInfoDictionaryKey: |
| - [NSString stringWithUTF8String:WideToUTF8(name).c_str()]]; |
| + const NSString *ns_name = reinterpret_cast<const NSString *>(name); |
|
Mark Mentovai
2010/12/16 22:11:47
Is const really correct here?
dmac
2010/12/16 22:20:42
it's either that or
NSString *ns_name = const_cas
Mark Mentovai
2010/12/16 22:39:20
You can use a C-style cast in preference to nestin
|
| + NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name]; |
| if (value) { |
| - *value_str = reinterpret_cast<const wchar_t*>( |
| - [value cStringUsingEncoding:NSUTF32StringEncoding]); |
| - return true; |
| + return base::SysNSStringToWide(value); |
| } |
| } |
| - return false; |
| -} |
| - |
| -std::wstring FileVersionInfoMac::GetStringValue(const wchar_t* name) { |
| - std::wstring str; |
| - if (GetValue(name, &str)) |
| - return str; |
| return std::wstring(); |
| } |