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