|
3 | 3 | import * as errors from "./errors";
|
4 | 4 | import * as options from "./options";
|
5 | 5 | import * as utils from "./utils";
|
| 6 | +import * as fs from "fs"; |
| 7 | +import Future = require("fibers/future"); |
| 8 | +import * as path from "path"; |
6 | 9 | import * as util from "util";
|
7 | 10 | import * as os from "os";
|
8 | 11 | let $ = require("nodobjc");
|
| 12 | +let bplistParser = require("bplist-parser"); |
| 13 | +let osenv = require("osenv"); |
9 | 14 |
|
10 | 15 | import iPhoneSimulatorBaseLib = require("./iphone-interop-simulator-base");
|
11 | 16 |
|
@@ -39,6 +44,42 @@ export class XCode6Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
|
39 | 44 | return this.execute(() => this.sdks, { canRunMainLoop: false });
|
40 | 45 | }
|
41 | 46 |
|
| 47 | + public getApplicationPath(deviceId: string, applicationIdentifier: string): IFuture<string> { |
| 48 | + return (() => { |
| 49 | + let rootApplicationsPath = path.join(osenv.home(), `/Library/Developer/CoreSimulator/Devices/${deviceId}/data/Containers/Bundle/Application`); |
| 50 | + if(!fs.existsSync(rootApplicationsPath)) { |
| 51 | + rootApplicationsPath = path.join(osenv.home(), `/Library/Developer/CoreSimulator/Devices/${deviceId}/data/Applications`); |
| 52 | + } |
| 53 | + let applicationGuids = fs.readdirSync(rootApplicationsPath); |
| 54 | + let result: string = null; |
| 55 | + _.each(applicationGuids, applicationGuid => { |
| 56 | + let fullApplicationPath = path.join(rootApplicationsPath, applicationGuid); |
| 57 | + let applicationDirContents = fs.readdirSync(fullApplicationPath); |
| 58 | + let applicationName = _.find(applicationDirContents, fileName => path.extname(fileName) === ".app"); |
| 59 | + let plistFilePath = path.join(fullApplicationPath, applicationName, "Info.plist"); |
| 60 | + let applicationData = this.parseFile(plistFilePath).wait(); |
| 61 | + if(applicationData[0].CFBundleIdentifier === applicationIdentifier) { |
| 62 | + result = path.join(fullApplicationPath, applicationName); |
| 63 | + return false; |
| 64 | + } |
| 65 | + }); |
| 66 | + |
| 67 | + return result; |
| 68 | + }).future<string>()(); |
| 69 | + } |
| 70 | + |
| 71 | + private parseFile(plistFilePath: string): IFuture<any> { |
| 72 | + let future = new Future<any>(); |
| 73 | + bplistParser.parseFile(plistFilePath, (err: Error, obj: any) => { |
| 74 | + if(err) { |
| 75 | + future.throw(err); |
| 76 | + } else { |
| 77 | + future.return(obj); |
| 78 | + } |
| 79 | + }); |
| 80 | + return future; |
| 81 | + } |
| 82 | + |
42 | 83 | private get devices(): IDevice[] {
|
43 | 84 | if(!this.cachedDevices) {
|
44 | 85 | this.cachedDevices = [];
|
|
0 commit comments