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