DXR will be turned off on Tuesday, December 29th. It will redirect to Searchfox.
See the announcement on Discourse.

DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b66b287a2650)

VCS Links

Line Code
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
// 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/logging.h"
#include "base/string_util.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 L"";
}

std::wstring FileVersionInfo::company_short_name() {
  return L"";
}

std::wstring FileVersionInfo::internal_name() {
  return L"";
}

std::wstring FileVersionInfo::product_name() {
  return GetStringValue(L"CFBundleName");
}

std::wstring FileVersionInfo::product_short_name() {
  return GetStringValue(L"CFBundleName");
}

std::wstring FileVersionInfo::comments() {
  return L"";
}

std::wstring FileVersionInfo::legal_copyright() {
  return GetStringValue(L"CFBundleGetInfoString");
}

std::wstring FileVersionInfo::product_version() {
  return GetStringValue(L"CFBundleShortVersionString");
}

std::wstring FileVersionInfo::file_description() {
  return L"";
}

std::wstring FileVersionInfo::legal_trademarks() {
  return L"";
}

std::wstring FileVersionInfo::private_build() {
  return L"";
}

std::wstring FileVersionInfo::file_version() {
  // CFBundleVersion has limitations that may not be honored by a
  // proper Chromium version number, so try KSVersion first.
  std::wstring version = GetStringValue(L"KSVersion");
  if (version == L"")
    version = GetStringValue(L"CFBundleVersion");
  return version;
}

std::wstring FileVersionInfo::original_filename() {
  return GetStringValue(L"CFBundleName");
}

std::wstring FileVersionInfo::special_build() {
  return L"";
}

std::wstring FileVersionInfo::last_change() {
  return L"";
}

bool FileVersionInfo::is_official_build() {
  return false;
}

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 L"";
}