Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: base/file_version_info_mac.mm

Issue 5815001: Fixed file_version_info so that it finds Mac values correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added a file Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
Mark Mentovai 2010/12/16 22:11:47 :) Thanks!
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());
Mark Mentovai 2010/12/16 22:11:47 Ah, that’ll do.
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 NSString *identifier = [bundle bundleIdentifier];
28 if (!identifier) {
29 NOTREACHED() << "Unable to create file version for " << file_path.value();
30 return NULL;
31 } else {
32 return new FileVersionInfoMac(bundle);
33 }
44 } 34 }
45 35
46 std::wstring FileVersionInfoMac::company_name() { 36 std::wstring FileVersionInfoMac::company_name() {
47 return std::wstring(); 37 return std::wstring();
48 } 38 }
49 39
50 std::wstring FileVersionInfoMac::company_short_name() { 40 std::wstring FileVersionInfoMac::company_short_name() {
51 return std::wstring(); 41 return std::wstring();
52 } 42 }
53 43
54 std::wstring FileVersionInfoMac::internal_name() { 44 std::wstring FileVersionInfoMac::internal_name() {
55 return std::wstring(); 45 return std::wstring();
56 } 46 }
57 47
58 std::wstring FileVersionInfoMac::product_name() { 48 std::wstring FileVersionInfoMac::product_name() {
59 return GetStringValue(L"CFBundleName"); 49 return GetStringValue(kCFBundleNameKey);
60 } 50 }
61 51
62 std::wstring FileVersionInfoMac::product_short_name() { 52 std::wstring FileVersionInfoMac::product_short_name() {
63 return GetStringValue(L"CFBundleName"); 53 return GetStringValue(kCFBundleNameKey);
64 } 54 }
65 55
66 std::wstring FileVersionInfoMac::comments() { 56 std::wstring FileVersionInfoMac::comments() {
67 return std::wstring(); 57 return std::wstring();
68 } 58 }
69 59
70 std::wstring FileVersionInfoMac::legal_copyright() { 60 std::wstring FileVersionInfoMac::legal_copyright() {
71 return GetStringValue(L"CFBundleGetInfoString"); 61 return GetStringValue(CFSTR("CFBundleGetInfoString"));
72 } 62 }
73 63
74 std::wstring FileVersionInfoMac::product_version() { 64 std::wstring FileVersionInfoMac::product_version() {
75 return GetStringValue(L"CFBundleShortVersionString"); 65 return GetStringValue(CFSTR("CFBundleShortVersionString"));
76 } 66 }
77 67
78 std::wstring FileVersionInfoMac::file_description() { 68 std::wstring FileVersionInfoMac::file_description() {
79 return std::wstring(); 69 return std::wstring();
80 } 70 }
81 71
82 std::wstring FileVersionInfoMac::legal_trademarks() { 72 std::wstring FileVersionInfoMac::legal_trademarks() {
83 return std::wstring(); 73 return std::wstring();
84 } 74 }
85 75
86 std::wstring FileVersionInfoMac::private_build() { 76 std::wstring FileVersionInfoMac::private_build() {
87 return std::wstring(); 77 return std::wstring();
88 } 78 }
89 79
90 std::wstring FileVersionInfoMac::file_version() { 80 std::wstring FileVersionInfoMac::file_version() {
91 return product_version(); 81 return product_version();
92 } 82 }
93 83
94 std::wstring FileVersionInfoMac::original_filename() { 84 std::wstring FileVersionInfoMac::original_filename() {
95 return GetStringValue(L"CFBundleName"); 85 return GetStringValue(kCFBundleNameKey);
96 } 86 }
97 87
98 std::wstring FileVersionInfoMac::special_build() { 88 std::wstring FileVersionInfoMac::special_build() {
99 return std::wstring(); 89 return std::wstring();
100 } 90 }
101 91
102 std::wstring FileVersionInfoMac::last_change() { 92 std::wstring FileVersionInfoMac::last_change() {
103 return GetStringValue(L"SVNRevision"); 93 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...
104 } 94 }
105 95
106 bool FileVersionInfoMac::is_official_build() { 96 bool FileVersionInfoMac::is_official_build() {
107 #if defined (GOOGLE_CHROME_BUILD) 97 #if defined (GOOGLE_CHROME_BUILD)
108 return true; 98 return true;
109 #else 99 #else
110 return false; 100 return false;
111 #endif 101 #endif
112 } 102 }
113 103
114 bool FileVersionInfoMac::GetValue(const wchar_t* name, 104 std::wstring FileVersionInfoMac::GetStringValue(CFStringRef name) {
115 std::wstring* value_str) {
116 if (bundle_) { 105 if (bundle_) {
117 NSString* value = [bundle_ objectForInfoDictionaryKey: 106 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
118 [NSString stringWithUTF8String:WideToUTF8(name).c_str()]]; 107 NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name];
119 if (value) { 108 if (value) {
120 *value_str = reinterpret_cast<const wchar_t*>( 109 return base::SysNSStringToWide(value);
121 [value cStringUsingEncoding:NSUTF32StringEncoding]);
122 return true;
123 } 110 }
124 } 111 }
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(); 112 return std::wstring();
133 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698