summaryrefslogtreecommitdiffstats
path: root/base/file_version_info_mac.mm
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-18 00:40:17 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-18 00:40:17 +0000
commit30c918084bac874b6cfaabb93f0bb2545c5354e2 (patch)
tree45bd81ec93407433426c0a6d1421bc189a96c2c4 /base/file_version_info_mac.mm
parentd9cb161850584e5d277b141aadb68abec0af28bb (diff)
downloadchromium_src-30c918084bac874b6cfaabb93f0bb2545c5354e2.zip
chromium_src-30c918084bac874b6cfaabb93f0bb2545c5354e2.tar.gz
chromium_src-30c918084bac874b6cfaabb93f0bb2545c5354e2.tar.bz2
Revert 69592 - file_version_info was not finding Mac values correctly.
Changed file_version_info to find Mac values, and changed version_info to fail if values can't be found. BUG=NONE TEST=BUILD Review URL: http://codereview.chromium.org/5815001 TBR=dmaclach@chromium.org Review URL: http://codereview.chromium.org/6017003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69601 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_version_info_mac.mm')
-rw-r--r--base/file_version_info_mac.mm68
1 files changed, 44 insertions, 24 deletions
diff --git a/base/file_version_info_mac.mm b/base/file_version_info_mac.mm
index 7b1ac54..57be79a 100644
--- a/base/file_version_info_mac.mm
+++ b/base/file_version_info_mac.mm
@@ -4,33 +4,43 @@
#include "base/file_version_info_mac.h"
-#import <Foundation/Foundation.h>
+#import <Cocoa/Cocoa.h>
+#include "base/basictypes.h"
#include "base/file_path.h"
-#include "base/logging.h"
-#include "base/sys_string_conversions.h"
-#include "base/mac_util.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) : bundle_(bundle) {
+ [bundle_ retain];
+}
+
+FileVersionInfoMac::~FileVersionInfoMac() {
+ [bundle_ release];
}
// static
FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
- return CreateFileVersionInfo(mac_util::MainAppBundlePath());
+ // 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]);
}
// static
FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
const FilePath& file_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);
- }
+ NSString* path = [NSString stringWithUTF8String:file_path.value().c_str()];
+ return new FileVersionInfoMac([NSBundle bundleWithPath:path]);
}
std::wstring FileVersionInfoMac::company_name() {
@@ -46,11 +56,11 @@ std::wstring FileVersionInfoMac::internal_name() {
}
std::wstring FileVersionInfoMac::product_name() {
- return GetWStringValue(kCFBundleNameKey);
+ return GetStringValue(L"CFBundleName");
}
std::wstring FileVersionInfoMac::product_short_name() {
- return GetWStringValue(kCFBundleNameKey);
+ return GetStringValue(L"CFBundleName");
}
std::wstring FileVersionInfoMac::comments() {
@@ -58,11 +68,11 @@ std::wstring FileVersionInfoMac::comments() {
}
std::wstring FileVersionInfoMac::legal_copyright() {
- return GetWStringValue(CFSTR("CFBundleGetInfoString"));
+ return GetStringValue(L"CFBundleGetInfoString");
}
std::wstring FileVersionInfoMac::product_version() {
- return GetWStringValue(CFSTR("CFBundleShortVersionString"));
+ return GetStringValue(L"CFBundleShortVersionString");
}
std::wstring FileVersionInfoMac::file_description() {
@@ -82,7 +92,7 @@ std::wstring FileVersionInfoMac::file_version() {
}
std::wstring FileVersionInfoMac::original_filename() {
- return GetWStringValue(kCFBundleNameKey);
+ return GetStringValue(L"CFBundleName");
}
std::wstring FileVersionInfoMac::special_build() {
@@ -90,7 +100,7 @@ std::wstring FileVersionInfoMac::special_build() {
}
std::wstring FileVersionInfoMac::last_change() {
- return GetWStringValue(CFSTR("SVNRevision"));
+ return GetStringValue(L"SVNRevision");
}
bool FileVersionInfoMac::is_official_build() {
@@ -101,13 +111,23 @@ bool FileVersionInfoMac::is_official_build() {
#endif
}
-std::wstring FileVersionInfoMac::GetWStringValue(CFStringRef name) {
+bool FileVersionInfoMac::GetValue(const wchar_t* name,
+ std::wstring* value_str) {
if (bundle_) {
- NSString *ns_name = mac_util::CFToNSCast(name);
- NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name];
+ NSString* value = [bundle_ objectForInfoDictionaryKey:
+ [NSString stringWithUTF8String:WideToUTF8(name).c_str()]];
if (value) {
- return base::SysNSStringToWide(value);
+ *value_str = reinterpret_cast<const wchar_t*>(
+ [value cStringUsingEncoding:NSUTF32StringEncoding]);
+ return true;
}
}
+ return false;
+}
+
+std::wstring FileVersionInfoMac::GetStringValue(const wchar_t* name) {
+ std::wstring str;
+ if (GetValue(name, &str))
+ return str;
return std::wstring();
}