Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple: Scan new Xcode Provision Directory #734

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/mac/AppleSigningIdentityController.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace Rtt
{
@private
NSString *fPath;
NSString *fNewPath;
}

+ (NSString*)defaultProvisionPath;
Expand Down
72 changes: 53 additions & 19 deletions platform/mac/AppleSigningIdentityController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,17 @@ + (NSString*)defaultProvisionPath
return provisionDir;
}

+ (NSString*)newProvisionPath
{
NSArray* paths = NSSearchPathForDirectoriesInDomains( NSLibraryDirectory, NSUserDomainMask, true );
NSString *provisionDir = [paths objectAtIndex:0];
provisionDir = [provisionDir stringByAppendingPathComponent:@"Developer/Xcode/UserData/Provisioning Profiles/"];
return provisionDir;
}




+ (BOOL)hasProvisionedDevices:(NSString*)provisionFile
{
NSDictionary *provisionProfile = [AppleSigningIdentityController loadProvisioningProfile:provisionFile];
Expand Down Expand Up @@ -499,23 +510,26 @@ + (NSString*)signingIdentity:(NSString*)provisionFile commonName:(NSString **)co

- (id)init
{
return [self initWithProvisionPath:[[self class] defaultProvisionPath]];
return [self initWithProvisionPath:[[self class] defaultProvisionPath] newPath:[[self class] newProvisionPath]];
}

- (id)initWithProvisionPath:(NSString*)path
- (id)initWithProvisionPath:(NSString*)path newPath:(NSString *)newPath
{
self = [super init];
if ( self )
{
fPath = [path copy];
fNewPath = [newPath copy]; // This new path is for Xcode 16 and later
}


return self;
}

- (void)dealloc
{
[fPath release];
[fNewPath release];
[super dealloc];
}

Expand Down Expand Up @@ -625,25 +639,45 @@ - (void)populateMenu:(NSMenu*)menu platform:(Rtt::TargetDevice::Platform)platfor
{
using namespace Rtt;

NSFileManager* fileMgr = [NSFileManager defaultManager];

NSString* provisionDir = fPath;
NSArray* dirContents = [fileMgr contentsOfDirectoryAtPath:provisionDir error:NULL];

NSMenu* identitiesMenu = menu; Rtt_ASSERT( menu );
NSMenu* iOSTeamProvisioningProfilesSubMenu = [[NSMenu alloc] init];
NSMenu* disabledSubMenu = [[NSMenu alloc] init];
NSString *extension = ExtensionForPlatform( platform );
NSFont *smallFont = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
NSFont *boldFont = [NSFont boldSystemFontOfSize:[NSFont labelFontSize]];
NSMutableArray *certIdentities = [NSMutableArray arrayWithCapacity:20];
NSString *provisionDir; // Temporary variable to hold the current directory path
NSMutableArray *allDirContents = [NSMutableArray array]; // Array to hold contents from both paths
NSMenu *identitiesMenu = menu;
Rtt_ASSERT(menu);
NSMenu *iOSTeamProvisioningProfilesSubMenu = [[NSMenu alloc] init];
NSMenu *disabledSubMenu = [[NSMenu alloc] init];
NSString *extension = ExtensionForPlatform(platform);
NSFont *smallFont = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
NSFont *boldFont = [NSFont boldSystemFontOfSize:[NSFont labelFontSize]];
NSMutableArray *certIdentities = [NSMutableArray arrayWithCapacity:20];

NSFileManager *fileMgr = [NSFileManager defaultManager];
// Get contents from both paths
for (NSString *path in @[fPath, fNewPath]) {
if ([fileMgr fileExistsAtPath:path]) {
NSArray *contents = [fileMgr contentsOfDirectoryAtPath:path error:NULL];
NSString *source = (path == fPath) ? @"old" : @"new";
for (NSString *item in contents) {
[allDirContents addObject:@{@"name": item, @"source": source}];
}
} else {
// Do nothing for right now
}
}

// Process each file in the combined contents
for (NSDictionary *fileInfo in allDirContents)
{
NSString *filename = fileInfo[@"name"];

if ([[filename pathExtension] isEqualToString:extension])
{
// Determine the source of the file and assign the correct directory
NSString *provisionDir = [fileInfo[@"source"] isEqualToString:@"old"] ? fPath : fNewPath;

for ( NSString *filename in dirContents )
{
if ( [[filename pathExtension] isEqualToString:extension] )
{
NSString *fullPath = [provisionDir stringByAppendingPathComponent:filename];
// You can now use provisionDir and filename to create the full path if needed
NSString *fullPath = [provisionDir stringByAppendingPathComponent:filename];
NSDictionary *provisionProfile = [AppleSigningIdentityController loadProvisioningProfile:fullPath];


if ( provisionProfile != nil )
{
Expand Down