| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
| 6 #include <asl.h> | 6 #include <asl.h> |
| 7 #include <libgen.h> | 7 #include <libgen.h> |
| 8 #include <stdarg.h> | 8 #include <stdarg.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 | 10 |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 // Creates the necessary directory structure under the given user home directory | 484 // Creates the necessary directory structure under the given user home directory |
| 485 // path, then sets the path in the appropriate environment variable. | 485 // path, then sets the path in the appropriate environment variable. |
| 486 // Returns YES if successful, NO if unable to create or initialize the given | 486 // Returns YES if successful, NO if unable to create or initialize the given |
| 487 // directory. | 487 // directory. |
| 488 BOOL InitializeSimulatorUserHome(NSString* userHomePath, NSString* deviceName) { | 488 BOOL InitializeSimulatorUserHome(NSString* userHomePath, NSString* deviceName) { |
| 489 if (!CreateHomeDirSubDirs(userHomePath)) | 489 if (!CreateHomeDirSubDirs(userHomePath)) |
| 490 return NO; | 490 return NO; |
| 491 | 491 |
| 492 // Set the device to simulate. Note that the iOS Simulator must not be running | 492 // Set the device to simulate. Note that the iOS Simulator must not be running |
| 493 // for this setting to take effect. | 493 // for this setting to take effect. |
| 494 NSMutableDictionary* plistDict = | 494 CFStringRef iPhoneSimulatorAppID = CFSTR("com.apple.iphonesimulator"); |
| 495 [NSMutableDictionary dictionaryWithObject:deviceName | 495 CFPreferencesSetAppValue(CFSTR("SimulateDevice"), |
| 496 forKey:@"SimulateDevice"]; | 496 deviceName, |
| 497 NSString* plistPath = @"Library/Preferences/com.apple.iphonesimulator.plist"; | 497 iPhoneSimulatorAppID); |
| 498 [plistDict writeToFile:[userHomePath stringByAppendingPathComponent:plistPath] | 498 CFPreferencesAppSynchronize(iPhoneSimulatorAppID); |
| 499 atomically:YES]; | |
| 500 | 499 |
| 501 // Update the environment to use the specified directory as the user home | 500 // Update the environment to use the specified directory as the user home |
| 502 // directory. | 501 // directory. |
| 503 // Note: the third param of setenv specifies whether or not to overwrite the | 502 // Note: the third param of setenv specifies whether or not to overwrite the |
| 504 // variable's value if it has already been set. | 503 // variable's value if it has already been set. |
| 505 if ((setenv(kUserHomeEnvVariable, [userHomePath UTF8String], YES) == -1) || | 504 if ((setenv(kUserHomeEnvVariable, [userHomePath UTF8String], YES) == -1) || |
| 506 (setenv(kHomeEnvVariable, [userHomePath UTF8String], YES) == -1)) { | 505 (setenv(kHomeEnvVariable, [userHomePath UTF8String], YES) == -1)) { |
| 507 LogError(@"Unable to set environment variables for home directory."); | 506 LogError(@"Unable to set environment variables for home directory."); |
| 508 return NO; | 507 return NO; |
| 509 } | 508 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 [error localizedDescription], | 718 [error localizedDescription], |
| 720 [error domain], static_cast<long int>([error code])); | 719 [error domain], static_cast<long int>([error code])); |
| 721 } | 720 } |
| 722 | 721 |
| 723 // Note that this code is only executed if the simulator fails to start | 722 // Note that this code is only executed if the simulator fails to start |
| 724 // because once the main run loop is started, only the delegate calling | 723 // because once the main run loop is started, only the delegate calling |
| 725 // exit() will end the program. | 724 // exit() will end the program. |
| 726 [pool drain]; | 725 [pool drain]; |
| 727 return kExitFailure; | 726 return kExitFailure; |
| 728 } | 727 } |
| OLD | NEW |