Skip to content

Commit

Permalink
Apple: Scan new Xcode Provision Directory (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrules44 authored Oct 25, 2024
1 parent f9b30a5 commit b1cd06b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
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

0 comments on commit b1cd06b

Please sign in to comment.