summaryrefslogtreecommitdiffstats
path: root/base/file_version_info_mac.mm
blob: 293d904a31084d7b77b9ae73075dfefd48d03359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) 2011 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_mac.h"

#import <Foundation/Foundation.h>

#include "base/file_path.h"
#include "base/logging.h"
#include "base/mac/mac_util.h"
#include "base/sys_string_conversions.h"

FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle)
    : bundle_([bundle retain]) {
}

FileVersionInfoMac::~FileVersionInfoMac() {}

// static
FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
  return CreateFileVersionInfo(base::mac::MainAppBundlePath());
}

// static
FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
    const FilePath& file_path) {
  NSString* path = base::SysUTF8ToNSString(file_path.value());
  NSBundle* bundle = [NSBundle bundleWithPath:path];
  return new FileVersionInfoMac(bundle);
}

string16 FileVersionInfoMac::company_name() {
  return string16();
}

string16 FileVersionInfoMac::company_short_name() {
  return string16();
}

string16 FileVersionInfoMac::internal_name() {
  return string16();
}

string16 FileVersionInfoMac::product_name() {
  return GetString16Value(kCFBundleNameKey);
}

string16 FileVersionInfoMac::product_short_name() {
  return GetString16Value(kCFBundleNameKey);
}

string16 FileVersionInfoMac::comments() {
  return string16();
}

string16 FileVersionInfoMac::legal_copyright() {
  return GetString16Value(CFSTR("CFBundleGetInfoString"));
}

string16 FileVersionInfoMac::product_version() {
  return GetString16Value(CFSTR("CFBundleShortVersionString"));
}

string16 FileVersionInfoMac::file_description() {
  return string16();
}

string16 FileVersionInfoMac::legal_trademarks() {
  return string16();
}

string16 FileVersionInfoMac::private_build() {
  return string16();
}

string16 FileVersionInfoMac::file_version() {
  return product_version();
}

string16 FileVersionInfoMac::original_filename() {
  return GetString16Value(kCFBundleNameKey);
}

string16 FileVersionInfoMac::special_build() {
  return string16();
}

string16 FileVersionInfoMac::last_change() {
  return GetString16Value(CFSTR("SVNRevision"));
}

bool FileVersionInfoMac::is_official_build() {
#if defined (GOOGLE_CHROME_BUILD)
  return true;
#else
  return false;
#endif
}

string16 FileVersionInfoMac::GetString16Value(CFStringRef name) {
  if (bundle_) {
    NSString *ns_name = base::mac::CFToNSCast(name);
    NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name];
    if (value) {
      return base::SysNSStringToUTF16(value);
    }
  }
  return string16();
}