[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 1 | // Copyright 2008, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | // Copied from base/basictypes.h with some modifications |
| 30 | |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 31 | #include "base/file_version_info.h" |
| 32 | |
[email protected] | 1265917f | 2008-08-12 17:33:52 | [diff] [blame^] | 33 | #import <Cocoa/Cocoa.h> |
| 34 | |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 35 | #include "base/logging.h" |
| 36 | #include "base/string_util.h" |
| 37 | |
[email protected] | 1265917f | 2008-08-12 17:33:52 | [diff] [blame^] | 38 | FileVersionInfo::FileVersionInfo(const std::wstring& file_path) { |
| 39 | NSString* path = [[NSString alloc] |
| 40 | initWithCString:reinterpret_cast<const char*>(file_path.c_str()) |
| 41 | encoding:NSUTF32StringEncoding]; |
| 42 | bundle_ = [NSBundle bundleWithPath: path]; |
| 43 | } |
| 44 | |
| 45 | FileVersionInfo::FileVersionInfo(NSBundle *bundle) : bundle_(bundle) { |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | FileVersionInfo::~FileVersionInfo() { |
[email protected] | 1265917f | 2008-08-12 17:33:52 | [diff] [blame^] | 49 | [bundle_ release]; |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | // static |
| 53 | FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { |
[email protected] | 1265917f | 2008-08-12 17:33:52 | [diff] [blame^] | 54 | // TODO(erikkay): this should really use bundleForClass, but we don't have |
| 55 | // a class to hang onto yet. |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 56 | NSBundle* bundle = [NSBundle mainBundle]; |
[email protected] | 1265917f | 2008-08-12 17:33:52 | [diff] [blame^] | 57 | return new FileVersionInfo(bundle); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | // static |
| 61 | FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( |
| 62 | const std::wstring& file_path) { |
[email protected] | 1265917f | 2008-08-12 17:33:52 | [diff] [blame^] | 63 | return new FileVersionInfo(file_path); |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | std::wstring FileVersionInfo::company_name() { |
| 67 | return L""; |
| 68 | } |
| 69 | |
| 70 | std::wstring FileVersionInfo::company_short_name() { |
| 71 | return L""; |
| 72 | } |
| 73 | |
| 74 | std::wstring FileVersionInfo::internal_name() { |
| 75 | return L""; |
| 76 | } |
| 77 | |
| 78 | std::wstring FileVersionInfo::product_name() { |
| 79 | return GetStringValue(L"CFBundleName"); |
| 80 | } |
| 81 | |
| 82 | std::wstring FileVersionInfo::product_short_name() { |
| 83 | return GetStringValue(L"CFBundleName"); |
| 84 | } |
| 85 | |
| 86 | std::wstring FileVersionInfo::comments() { |
| 87 | return L""; |
| 88 | } |
| 89 | |
| 90 | std::wstring FileVersionInfo::legal_copyright() { |
| 91 | return GetStringValue(L"CFBundleGetInfoString"); |
| 92 | } |
| 93 | |
| 94 | std::wstring FileVersionInfo::product_version() { |
| 95 | return GetStringValue(L"CFBundleShortVersionString"); |
| 96 | } |
| 97 | |
| 98 | std::wstring FileVersionInfo::file_description() { |
| 99 | return L""; |
| 100 | } |
| 101 | |
| 102 | std::wstring FileVersionInfo::legal_trademarks() { |
| 103 | return L""; |
| 104 | } |
| 105 | |
| 106 | std::wstring FileVersionInfo::private_build() { |
| 107 | return L""; |
| 108 | } |
| 109 | |
| 110 | std::wstring FileVersionInfo::file_version() { |
| 111 | return GetStringValue(L"CFBundleVersion"); |
| 112 | } |
| 113 | |
| 114 | std::wstring FileVersionInfo::original_filename() { |
| 115 | return GetStringValue(L"CFBundleName"); |
| 116 | } |
| 117 | |
| 118 | std::wstring FileVersionInfo::special_build() { |
| 119 | return L""; |
| 120 | } |
| 121 | |
| 122 | std::wstring FileVersionInfo::last_change() { |
| 123 | return L""; |
| 124 | } |
| 125 | |
| 126 | bool FileVersionInfo::is_official_build() { |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) { |
[email protected] | 6723f83 | 2008-08-11 15:38:27 | [diff] [blame] | 131 | if (bundle_) { |
| 132 | NSString* value = [bundle_ objectForInfoDictionaryKey: |
| 133 | [NSString stringWithUTF8String:WideToUTF8(name).c_str()]]; |
| 134 | if (value) { |
| 135 | *value_str = reinterpret_cast<const wchar_t*>( |
| 136 | [value cStringUsingEncoding:NSUTF32StringEncoding]); |
| 137 | return true; |
| 138 | } |
| 139 | } |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) { |
| 144 | std::wstring str; |
| 145 | if (GetValue(name, &str)) |
| 146 | return str; |
| 147 | return L""; |
| 148 | } |
| 149 | |