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 // Set the device to simulate. Note that the iOS Simulator must not be running |
495 [NSMutableDictionary dictionaryWithObject:deviceName | 495 // for this setting to take effect. |
TVL
2013/04/16 20:05:45
duplicate comment?
lliabraa
2013/04/17 13:15:37
Done.
TVL
2013/04/17 13:42:04
New upload?
| |
496 forKey:@"SimulateDevice"]; | 496 CFStringRef iPhoneSimulatorAppID = CFSTR("com.apple.iphonesimulator"); |
497 NSString* plistPath = @"Library/Preferences/com.apple.iphonesimulator.plist"; | 497 CFPreferencesSetAppValue(CFSTR("SimulateDevice"), |
498 [plistDict writeToFile:[userHomePath stringByAppendingPathComponent:plistPath] | 498 deviceName, |
499 atomically:YES]; | 499 iPhoneSimulatorAppID); |
500 CFPreferencesAppSynchronize(iPhoneSimulatorAppID); | |
500 | 501 |
501 // Update the environment to use the specified directory as the user home | 502 // Update the environment to use the specified directory as the user home |
502 // directory. | 503 // directory. |
503 // Note: the third param of setenv specifies whether or not to overwrite the | 504 // Note: the third param of setenv specifies whether or not to overwrite the |
504 // variable's value if it has already been set. | 505 // variable's value if it has already been set. |
505 if ((setenv(kUserHomeEnvVariable, [userHomePath UTF8String], YES) == -1) || | 506 if ((setenv(kUserHomeEnvVariable, [userHomePath UTF8String], YES) == -1) || |
506 (setenv(kHomeEnvVariable, [userHomePath UTF8String], YES) == -1)) { | 507 (setenv(kHomeEnvVariable, [userHomePath UTF8String], YES) == -1)) { |
507 LogError(@"Unable to set environment variables for home directory."); | 508 LogError(@"Unable to set environment variables for home directory."); |
508 return NO; | 509 return NO; |
509 } | 510 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 int c; | 573 int c; |
573 while ((c = getopt(argc, argv, "hs:d:u:e:t:")) != -1) { | 574 while ((c = getopt(argc, argv, "hs:d:u:e:t:")) != -1) { |
574 switch (c) { | 575 switch (c) { |
575 case 's': | 576 case 's': |
576 sdkVersion = [NSString stringWithUTF8String:optarg]; | 577 sdkVersion = [NSString stringWithUTF8String:optarg]; |
577 break; | 578 break; |
578 case 'd': | 579 case 'd': |
579 deviceName = [NSString stringWithUTF8String:optarg]; | 580 deviceName = [NSString stringWithUTF8String:optarg]; |
580 break; | 581 break; |
581 case 'u': | 582 case 'u': |
582 simHomePath = [[NSFileManager defaultManager] | 583 simHomePath = [[NSFileManager defaultManager] |
TVL
2013/04/16 20:05:45
is it even worth having this option any more and t
lliabraa
2013/04/17 13:15:37
Can you remind me what the issue is here? It seems
TVL
2013/04/17 13:42:04
So the problem is what defaults the app (and simul
lliabraa
2013/04/17 16:52:03
I see. So if we were to set up a dir for the simul
| |
583 stringWithFileSystemRepresentation:optarg length:strlen(optarg)]; | 584 stringWithFileSystemRepresentation:optarg length:strlen(optarg)]; |
584 break; | 585 break; |
585 case 'e': { | 586 case 'e': { |
586 NSString* envLine = [NSString stringWithUTF8String:optarg]; | 587 NSString* envLine = [NSString stringWithUTF8String:optarg]; |
587 NSRange range = [envLine rangeOfString:@"="]; | 588 NSRange range = [envLine rangeOfString:@"="]; |
588 if (range.location == NSNotFound) { | 589 if (range.location == NSNotFound) { |
589 LogError(@"Invalid key=value argument for -e."); | 590 LogError(@"Invalid key=value argument for -e."); |
590 PrintUsage(); | 591 PrintUsage(); |
591 exit(kExitInvalidArguments); | 592 exit(kExitInvalidArguments); |
592 } | 593 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 [error localizedDescription], | 720 [error localizedDescription], |
720 [error domain], static_cast<long int>([error code])); | 721 [error domain], static_cast<long int>([error code])); |
721 } | 722 } |
722 | 723 |
723 // Note that this code is only executed if the simulator fails to start | 724 // 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 | 725 // because once the main run loop is started, only the delegate calling |
725 // exit() will end the program. | 726 // exit() will end the program. |
726 [pool drain]; | 727 [pool drain]; |
727 return kExitFailure; | 728 return kExitFailure; |
728 } | 729 } |
OLD | NEW |