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