blob: 23d84db010b155dc87376b9b85eba5a08450ddf5 [file] [log] [blame]
[email protected]6723f832008-08-11 15:38:271// 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]6723f832008-08-11 15:38:2731#include "base/file_version_info.h"
32
[email protected]1265917f2008-08-12 17:33:5233#import <Cocoa/Cocoa.h>
34
[email protected]6723f832008-08-11 15:38:2735#include "base/logging.h"
36#include "base/string_util.h"
37
[email protected]1265917f2008-08-12 17:33:5238FileVersionInfo::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
45FileVersionInfo::FileVersionInfo(NSBundle *bundle) : bundle_(bundle) {
[email protected]6723f832008-08-11 15:38:2746}
47
48FileVersionInfo::~FileVersionInfo() {
[email protected]1265917f2008-08-12 17:33:5249 [bundle_ release];
[email protected]6723f832008-08-11 15:38:2750}
51
52// static
53FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
[email protected]1265917f2008-08-12 17:33:5254 // TODO(erikkay): this should really use bundleForClass, but we don't have
55 // a class to hang onto yet.
[email protected]6723f832008-08-11 15:38:2756 NSBundle* bundle = [NSBundle mainBundle];
[email protected]1265917f2008-08-12 17:33:5257 return new FileVersionInfo(bundle);
[email protected]6723f832008-08-11 15:38:2758}
59
60// static
61FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
62 const std::wstring& file_path) {
[email protected]1265917f2008-08-12 17:33:5263 return new FileVersionInfo(file_path);
[email protected]6723f832008-08-11 15:38:2764}
65
66std::wstring FileVersionInfo::company_name() {
67 return L"";
68}
69
70std::wstring FileVersionInfo::company_short_name() {
71 return L"";
72}
73
74std::wstring FileVersionInfo::internal_name() {
75 return L"";
76}
77
78std::wstring FileVersionInfo::product_name() {
79 return GetStringValue(L"CFBundleName");
80}
81
82std::wstring FileVersionInfo::product_short_name() {
83 return GetStringValue(L"CFBundleName");
84}
85
86std::wstring FileVersionInfo::comments() {
87 return L"";
88}
89
90std::wstring FileVersionInfo::legal_copyright() {
91 return GetStringValue(L"CFBundleGetInfoString");
92}
93
94std::wstring FileVersionInfo::product_version() {
95 return GetStringValue(L"CFBundleShortVersionString");
96}
97
98std::wstring FileVersionInfo::file_description() {
99 return L"";
100}
101
102std::wstring FileVersionInfo::legal_trademarks() {
103 return L"";
104}
105
106std::wstring FileVersionInfo::private_build() {
107 return L"";
108}
109
110std::wstring FileVersionInfo::file_version() {
111 return GetStringValue(L"CFBundleVersion");
112}
113
114std::wstring FileVersionInfo::original_filename() {
115 return GetStringValue(L"CFBundleName");
116}
117
118std::wstring FileVersionInfo::special_build() {
119 return L"";
120}
121
122std::wstring FileVersionInfo::last_change() {
123 return L"";
124}
125
126bool FileVersionInfo::is_official_build() {
127 return false;
128}
129
130bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) {
[email protected]6723f832008-08-11 15:38:27131 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
143std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) {
144 std::wstring str;
145 if (GetValue(name, &str))
146 return str;
147 return L"";
148}
149