diff options
author | Patrick Scott <phanna@android.com> | 2010-02-04 10:37:17 -0500 |
---|---|---|
committer | Patrick Scott <phanna@android.com> | 2010-02-04 10:39:42 -0500 |
commit | c7f5f8508d98d5952d42ed7648c2a8f30a4da156 (patch) | |
tree | dd51dbfbf6670daa61279b3a19e7b1835b301dbf /base/file_version_info_mac.mm | |
parent | 139d8152182f9093f03d9089822b688e49fa7667 (diff) | |
download | external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.zip external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.tar.gz external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.tar.bz2 |
Initial source checkin.
The source files were determined by building net_unittests in chromium's source
tree. Some of the obvious libraries were left out (v8, gmock, gtest).
The Android.mk file has all the sources (minus unittests and tools) that were
used during net_unittests compilation. Nothing builds yet because of STL but
that is the next task. The .cpp files will most likely not compile anyways
because of the LOCAL_CPP_EXTENSION mod. I will have to break this into multiple
projects to get around that limitation.
Diffstat (limited to 'base/file_version_info_mac.mm')
-rw-r--r-- | base/file_version_info_mac.mm | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/base/file_version_info_mac.mm b/base/file_version_info_mac.mm new file mode 100644 index 0000000..c1395df --- /dev/null +++ b/base/file_version_info_mac.mm @@ -0,0 +1,132 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/file_version_info.h" + +#import <Cocoa/Cocoa.h> + +#include "base/file_path.h" +#include "base/logging.h" +#include "base/string_util.h" +#include "base/utf_string_conversions.h" + +FileVersionInfo::FileVersionInfo(NSBundle *bundle) : bundle_(bundle) { + [bundle_ retain]; +} + +FileVersionInfo::~FileVersionInfo() { + [bundle_ release]; +} + +// static +FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { + // TODO(erikkay): this should really use bundleForClass, but we don't have + // a class to hang onto yet. + NSBundle* bundle = [NSBundle mainBundle]; + return new FileVersionInfo(bundle); +} + +// static +FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( + const std::wstring& file_path) { + NSString* path = [NSString stringWithCString: + reinterpret_cast<const char*>(file_path.c_str()) + encoding:NSUTF32StringEncoding]; + return new FileVersionInfo([NSBundle bundleWithPath:path]); +} + +// static +FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( + const FilePath& file_path) { + NSString* path = [NSString stringWithUTF8String:file_path.value().c_str()]; + return new FileVersionInfo([NSBundle bundleWithPath:path]); +} + +std::wstring FileVersionInfo::company_name() { + return std::wstring(); +} + +std::wstring FileVersionInfo::company_short_name() { + return std::wstring(); +} + +std::wstring FileVersionInfo::internal_name() { + return std::wstring(); +} + +std::wstring FileVersionInfo::product_name() { + return GetStringValue(L"CFBundleName"); +} + +std::wstring FileVersionInfo::product_short_name() { + return GetStringValue(L"CFBundleName"); +} + +std::wstring FileVersionInfo::comments() { + return std::wstring(); +} + +std::wstring FileVersionInfo::legal_copyright() { + return GetStringValue(L"CFBundleGetInfoString"); +} + +std::wstring FileVersionInfo::product_version() { + return GetStringValue(L"CFBundleShortVersionString"); +} + +std::wstring FileVersionInfo::file_description() { + return std::wstring(); +} + +std::wstring FileVersionInfo::legal_trademarks() { + return std::wstring(); +} + +std::wstring FileVersionInfo::private_build() { + return std::wstring(); +} + +std::wstring FileVersionInfo::file_version() { + return product_version(); +} + +std::wstring FileVersionInfo::original_filename() { + return GetStringValue(L"CFBundleName"); +} + +std::wstring FileVersionInfo::special_build() { + return std::wstring(); +} + +std::wstring FileVersionInfo::last_change() { + return GetStringValue(L"SVNRevision"); +} + +bool FileVersionInfo::is_official_build() { +#if defined (GOOGLE_CHROME_BUILD) + return true; +#else + return false; +#endif +} + +bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) { + if (bundle_) { + NSString* value = [bundle_ objectForInfoDictionaryKey: + [NSString stringWithUTF8String:WideToUTF8(name).c_str()]]; + if (value) { + *value_str = reinterpret_cast<const wchar_t*>( + [value cStringUsingEncoding:NSUTF32StringEncoding]); + return true; + } + } + return false; +} + +std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) { + std::wstring str; + if (GetValue(name, &str)) + return str; + return std::wstring(); +} |