plist_utils.dart 1.03 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.

Devon Carew's avatar
Devon Carew committed
5 6
import 'dart:io';

7 8 9 10 11 12
import 'package:path/path.dart' as path;

import '../base/process.dart';

const String kCFBundleIdentifierKey = "CFBundleIdentifier";

13
String getValueFromFile(String plistFilePath, String key) {
Devon Carew's avatar
Devon Carew committed
14 15
  // 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.
16 17 18 19

  // 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
20 21 22 23

  if (!FileSystemEntity.isFileSync(plistFilePath))
    return null;

24 25 26
  String normalizedPlistPath = path.withoutExtension(path.absolute(plistFilePath));

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