blob: 3813cc6fb99601bb294a48ade8a369473aaec82d [file] [log] [blame]
[email protected]49df6022008-08-27 19:03:431// 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.
[email protected]6723f832008-08-11 15:38:274
[email protected]6723f832008-08-11 15:38:275#include "base/file_version_info.h"
6
[email protected]1265917f2008-08-12 17:33:527#import <Cocoa/Cocoa.h>
8
[email protected]6723f832008-08-11 15:38:279#include "base/logging.h"
10#include "base/string_util.h"
11
[email protected]1265917f2008-08-12 17:33:5212FileVersionInfo::FileVersionInfo(NSBundle *bundle) : bundle_(bundle) {
[email protected]09562232008-12-23 16:57:3613 [bundle_ retain];
[email protected]6723f832008-08-11 15:38:2714}
15
16FileVersionInfo::~FileVersionInfo() {
[email protected]1265917f2008-08-12 17:33:5217 [bundle_ release];
[email protected]6723f832008-08-11 15:38:2718}
19
20// static
21FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
[email protected]1265917f2008-08-12 17:33:5222 // TODO(erikkay): this should really use bundleForClass, but we don't have
23 // a class to hang onto yet.
[email protected]6723f832008-08-11 15:38:2724 NSBundle* bundle = [NSBundle mainBundle];
[email protected]1265917f2008-08-12 17:33:5225 return new FileVersionInfo(bundle);
[email protected]6723f832008-08-11 15:38:2726}
27
28// static
29FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
30 const std::wstring& file_path) {
[email protected]09562232008-12-23 16:57:3631 NSString* path = [NSString stringWithCString:
32 reinterpret_cast<const char*>(file_path.c_str())
33 encoding:NSUTF32StringEncoding];
34 return new FileVersionInfo([NSBundle bundleWithPath:path]);
35}
36
37// static
38FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
39 const FilePath& file_path) {
40 NSString* path = [NSString stringWithUTF8String:file_path.value().c_str()];
41 return new FileVersionInfo([NSBundle bundleWithPath:path]);
[email protected]6723f832008-08-11 15:38:2742}
43
44std::wstring FileVersionInfo::company_name() {
45 return L"";
46}
47
48std::wstring FileVersionInfo::company_short_name() {
49 return L"";
50}
51
52std::wstring FileVersionInfo::internal_name() {
53 return L"";
54}
55
56std::wstring FileVersionInfo::product_name() {
57 return GetStringValue(L"CFBundleName");
58}
59
60std::wstring FileVersionInfo::product_short_name() {
61 return GetStringValue(L"CFBundleName");
62}
63
64std::wstring FileVersionInfo::comments() {
65 return L"";
66}
67
68std::wstring FileVersionInfo::legal_copyright() {
69 return GetStringValue(L"CFBundleGetInfoString");
70}
71
72std::wstring FileVersionInfo::product_version() {
73 return GetStringValue(L"CFBundleShortVersionString");
74}
75
76std::wstring FileVersionInfo::file_description() {
77 return L"";
78}
79
80std::wstring FileVersionInfo::legal_trademarks() {
81 return L"";
82}
83
84std::wstring FileVersionInfo::private_build() {
85 return L"";
86}
87
88std::wstring FileVersionInfo::file_version() {
89 return GetStringValue(L"CFBundleVersion");
90}
91
92std::wstring FileVersionInfo::original_filename() {
93 return GetStringValue(L"CFBundleName");
94}
95
96std::wstring FileVersionInfo::special_build() {
97 return L"";
98}
99
100std::wstring FileVersionInfo::last_change() {
101 return L"";
102}
103
104bool FileVersionInfo::is_official_build() {
105 return false;
106}
107
108bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) {
[email protected]6723f832008-08-11 15:38:27109 if (bundle_) {
110 NSString* value = [bundle_ objectForInfoDictionaryKey:
111 [NSString stringWithUTF8String:WideToUTF8(name).c_str()]];
112 if (value) {
113 *value_str = reinterpret_cast<const wchar_t*>(
114 [value cStringUsingEncoding:NSUTF32StringEncoding]);
115 return true;
116 }
117 }
118 return false;
119}
120
121std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) {
122 std::wstring str;
123 if (GetValue(name, &str))
124 return str;
125 return L"";
126}