blob: a3e3e0c5bc4f4195e42da72a24a8284a978b31d4 [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
31#import <Cocoa/Cocoa.h>
32
33#include "base/file_version_info.h"
34
35#include "base/logging.h"
36#include "base/string_util.h"
37
38FileVersionInfo::FileVersionInfo(const std::wstring& file_path, NSBundle *bundle)
39 : file_path_(file_path), bundle_(bundle) {
40 if (!bundle_) {
41 NSString* path = [[NSString alloc]
42 initWithCString:reinterpret_cast<const char*>(file_path_.c_str())
43 encoding:NSUTF32StringEncoding];
44 bundle_ = [NSBundle bundleWithPath: path];
45 }
46}
47
48FileVersionInfo::~FileVersionInfo() {
49
50}
51
52// static
53FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
54 NSBundle* bundle = [NSBundle mainBundle];
55 return new FileVersionInfo(L"", bundle);
56}
57
58// static
59FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
60 const std::wstring& file_path) {
61 return new FileVersionInfo(file_path, nil);
62}
63
64std::wstring FileVersionInfo::company_name() {
65 return L"";
66}
67
68std::wstring FileVersionInfo::company_short_name() {
69 return L"";
70}
71
72std::wstring FileVersionInfo::internal_name() {
73 return L"";
74}
75
76std::wstring FileVersionInfo::product_name() {
77 return GetStringValue(L"CFBundleName");
78}
79
80std::wstring FileVersionInfo::product_short_name() {
81 return GetStringValue(L"CFBundleName");
82}
83
84std::wstring FileVersionInfo::comments() {
85 return L"";
86}
87
88std::wstring FileVersionInfo::legal_copyright() {
89 return GetStringValue(L"CFBundleGetInfoString");
90}
91
92std::wstring FileVersionInfo::product_version() {
93 return GetStringValue(L"CFBundleShortVersionString");
94}
95
96std::wstring FileVersionInfo::file_description() {
97 return L"";
98}
99
100std::wstring FileVersionInfo::legal_trademarks() {
101 return L"";
102}
103
104std::wstring FileVersionInfo::private_build() {
105 return L"";
106}
107
108std::wstring FileVersionInfo::file_version() {
109 return GetStringValue(L"CFBundleVersion");
110}
111
112std::wstring FileVersionInfo::original_filename() {
113 return GetStringValue(L"CFBundleName");
114}
115
116std::wstring FileVersionInfo::special_build() {
117 return L"";
118}
119
120std::wstring FileVersionInfo::last_change() {
121 return L"";
122}
123
124bool FileVersionInfo::is_official_build() {
125 return false;
126}
127
128bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) {
129 std::wstring str;
130 if (bundle_) {
131 NSString* value = [bundle_ objectForInfoDictionaryKey:
132 [NSString stringWithUTF8String:WideToUTF8(name).c_str()]];
133 if (value) {
134 *value_str = reinterpret_cast<const wchar_t*>(
135 [value cStringUsingEncoding:NSUTF32StringEncoding]);
136 return true;
137 }
138 }
139 return false;
140}
141
142std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) {
143 std::wstring str;
144 if (GetValue(name, &str))
145 return str;
146 return L"";
147}
148