plist_utils.dart 1.08 KB
Newer Older
1 2 3 4
// Copyright 2016 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.

5
import '../base/file_system.dart';
6 7 8
import '../base/process.dart';

const String kCFBundleIdentifierKey = "CFBundleIdentifier";
9
const String kCFBundleShortVersionStringKey = "CFBundleShortVersionString";
10

11
String getValueFromFile(String plistFilePath, String key) {
Devon Carew's avatar
Devon Carew committed
12 13
  // TODO(chinmaygarde): For now, we only need to read from plist files on a mac
  // host. If this changes, we will need our own Dart plist reader.
14 15 16 17

  // Don't use PlistBuddy since that is not guaranteed to be installed.
  // 'defaults' requires the path to be absolute and without the 'plist'
  // extension.
Devon Carew's avatar
Devon Carew committed
18

19
  if (!fs.isFileSync(plistFilePath))
Devon Carew's avatar
Devon Carew committed
20 21
    return null;

22
  final String normalizedPlistPath = fs.path.withoutExtension(fs.path.absolute(plistFilePath));
23 24

  try {
25
    final String value = runCheckedSync(<String>[
Devon Carew's avatar
Devon Carew committed
26 27
      '/usr/bin/defaults', 'read', normalizedPlistPath, key
    ]);
28
    return value.isEmpty ? null : value;
29
  } catch (error) {
30
    return null;
31 32
  }
}