diff --git a/ProfilesManager.xcodeproj/project.pbxproj b/ProfilesManager.xcodeproj/project.pbxproj index 8a3ade9..cc4b868 100755 --- a/ProfilesManager.xcodeproj/project.pbxproj +++ b/ProfilesManager.xcodeproj/project.pbxproj @@ -369,7 +369,7 @@ }; buildConfigurationList = A21193141AF1CA5B0064CA7D /* Build configuration list for PBXProject "ProfilesManager" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, diff --git a/ProfilesManager/Controller/ProfilesManagerViewController.m b/ProfilesManager/Controller/ProfilesManagerViewController.m index 39f91f5..463b1d4 100755 --- a/ProfilesManager/Controller/ProfilesManagerViewController.m +++ b/ProfilesManager/Controller/ProfilesManagerViewController.m @@ -25,6 +25,7 @@ // static NSString *kColumnIdentifierUUID = @"uuid"; static NSString *kColumnIdentifierExpirationDate = @"expirationDate"; static NSString *kColumnIdentifierCreateDate = @"creationDate"; +static NSString *kColumnIdentifierCreateDays = @"days"; @implementation ProfilesManagerViewController @@ -83,12 +84,15 @@ - (void)loadProfileFilesWithSearchWord:(NSString *)searchWord { NSArray *profileNames = [[[NSFileManager defaultManager] subpathsAtPath:_profileDir] pathsMatchingExtensions:@[@"mobileprovision", @"MOBILEPROVISION", @"provisionprofile", @"PROVISIONPROFILE"]]; NSMutableDictionary *provisions = [NSMutableDictionary dictionary]; - for (NSString *fileName in profileNames) { + for (NSUInteger i=0;i<[profileNames count];i++) { + NSString *fileName = [profileNames objectAtIndex:i]; + NSString *plistString; - NSMutableDictionary *dic = (NSMutableDictionary *)[PlistManager readPlist:[_profileDir stringByAppendingString:fileName ? : @""] plistString:&plistString]; - dic[@"filePath"] = [_profileDir stringByAppendingString:fileName ? : @""]; + NSMutableDictionary *dic = (NSMutableDictionary *)[PlistManager readPlist:[_profileDir stringByAppendingString:fileName?:@""] plistString:&plistString]; + dic[@"filePath"] = [_profileDir stringByAppendingString:fileName?:@""]; - if (dic && fileName) { + + if (dic && fileName) { if ([searchWord lowercaseString] && searchWord.length > 0) { if ([[plistString lowercaseString] rangeOfString:[searchWord lowercaseString]].location != NSNotFound) { provisions[fileName] = dic; @@ -139,9 +143,11 @@ - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTabl } else if ([[tableColumn identifier] isEqualToString:kColumnIdentifierDetal]) { return realItem.detail; } else if ([[tableColumn identifier] isEqualToString:kColumnIdentifierExpirationDate]) { - return realItem.expirationDate; + return [[DateManager sharedManager] stringConvert_YMDHM_FromDate:realItem.expirationDate]; } else if ([[tableColumn identifier] isEqualToString:kColumnIdentifierCreateDate]) { - return realItem.creationDate; + return [[DateManager sharedManager] stringConvert_YMDHM_FromDate:realItem.creationDate]; + }else if ([[tableColumn identifier] isEqualToString:kColumnIdentifierCreateDays]) { + return realItem.days; } return @""; } @@ -199,20 +205,6 @@ - (void)outlineView:(NSOutlineView *)outlineView sortDescriptorsDidChange:(NSArr sortedArray = [currChildren sortedArrayUsingDescriptors:@[sortDescriptor]]; _rootNode.childrenNodes = sortedArray; [outlineView reloadData]; - // NSSortDescriptor *sortDescriptor; - // - // NSString *key=[[[outlineView sortDescriptors] objectAtIndex:0] key]; - // BOOL isAscending=[[[outlineView sortDescriptors] objectAtIndex:0] ascending]; - // - // sortDescriptor = [[NSSortDescriptor alloc] initWithKey:key ascending:isAscending] ; - // NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; - // NSArray *sortedArray; - // - // NSMutableArray *currChildren= [_rootNode.childrenNodes mutableCopy]; - // sortedArray = [currChildren sortedArrayUsingDescriptors:sortDescriptors]; - // _rootNode.childrenNodes = sortedArray; - // [outlineView reloadData]; - //} } - (void)outlineViewSelectionDidChange:(NSNotification *)notification { diff --git a/ProfilesManager/Controller/ProfilesManagerViewController.xib b/ProfilesManager/Controller/ProfilesManagerViewController.xib index decb4df..0d89b76 100755 --- a/ProfilesManager/Controller/ProfilesManagerViewController.xib +++ b/ProfilesManager/Controller/ProfilesManagerViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -16,25 +16,25 @@ - + - + - + - - + + - - - + + + @@ -45,9 +45,9 @@ - + - + @@ -60,7 +60,7 @@ - + @@ -73,7 +73,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -97,6 +97,19 @@ + + + + + + + + + + + + + @@ -107,7 +120,7 @@ - + - + - + @@ -140,7 +153,7 @@ - + diff --git a/ProfilesManager/Model/ProfilesNode.h b/ProfilesManager/Model/ProfilesNode.h index 0168b5b..c08d25a 100755 --- a/ProfilesManager/Model/ProfilesNode.h +++ b/ProfilesManager/Model/ProfilesNode.h @@ -22,9 +22,10 @@ @property (nonatomic, copy)NSString *uuid; @property (nonatomic, copy)NSString *filePath; @property (nonatomic, strong)NSDictionary *extra; -@property (nonatomic, copy)NSString *expirationDate; -@property (nonatomic, copy)NSString *creationDate; - +@property (nonatomic, strong)NSDate *expirationDate; +@property (nonatomic, strong)NSDate *creationDate; + +@property (nonatomic, copy)NSString *days; - (id)initWithRootNode:(ProfilesNode *)rootNote originInfo:(id)info key:(NSString*)key; @end diff --git a/ProfilesManager/Model/ProfilesNode.m b/ProfilesManager/Model/ProfilesNode.m index 9056173..2b1ddfe 100755 --- a/ProfilesManager/Model/ProfilesNode.m +++ b/ProfilesManager/Model/ProfilesNode.m @@ -67,7 +67,7 @@ - (id)initWithRootNode:(ProfilesNode *)rootNode originInfo:(id)info key:(NSStrin } } info = [dict copy]; - + } if ([info isKindOfClass:[NSDictionary class]]) { _type = @"Dictionary"; @@ -78,20 +78,38 @@ - (id)initWithRootNode:(ProfilesNode *)rootNode originInfo:(id)info key:(NSStrin _detail = [NSString stringWithFormat:@"%lu items", (unsigned long)[dict count]]; _uuid = [dict objectForKey:@"UUID"]; _filePath = [dict objectForKey:@"filePath"]; - _expirationDate = [[DateManager sharedManager] stringConvert_YMDHM_FromDate:[dict objectForKey:@"ExpirationDate"]]; - _expirationDate = [[DateManager sharedManager] stringConvert_YMDHM_FromDate:[dict objectForKey:@"ExpirationDate"]]; - _creationDate= [[DateManager sharedManager] stringConvert_YMDHM_FromDate:[dict objectForKey:@"CreationDate"]]; if(_uuid){ NSDate *expiration = [dict objectForKey:@"ExpirationDate"]; _detail = [[NSDate date] compare:expiration] == NSOrderedDescending ?JKLocalizedString(@"Expired",nil):JKLocalizedString(@"Valid",nil); _type = [dict objectForKey:@"Name"]; } - - for (NSString *key in dict) { - ProfilesNode *child = [[ProfilesNode alloc]initWithRootNode:self originInfo:dict[key] key:key]; - [children addObject:child]; + if(rootNode){ + //root + + _expirationDate = [dict objectForKey:@"ExpirationDate"]; + _creationDate= [dict objectForKey:@"CreationDate"]; + NSInteger days = [self getDaysFrom:[NSDate date] endDate:_expirationDate]; + _days = [@(days) stringValue]; + for (NSString *key in dict) { + ProfilesNode *child = [[ProfilesNode alloc]initWithRootNode:self originInfo:dict[key] key:key]; + [children addObject:child]; + } + + }else{ + NSArray *keys = [dict allKeys]; + for (int i=0;i<[keys count];i++) { + NSString *key = [keys objectAtIndex:i]; + NSString *bundleID = [[[dict objectForKey:key] objectForKey:@"Entitlements"] objectForKey:@"application-identifier"]; + + ProfilesNode *child = [[ProfilesNode alloc]initWithRootNode:self originInfo:dict[key] key:bundleID]; + [children addObject:child]; + } + [children sortUsingComparator:^NSComparisonResult(ProfilesNode *obj1, ProfilesNode *obj2) { + return [obj2.expirationDate compare:obj1.expirationDate]; + }]; } + _childrenNodes = [NSArray arrayWithArray:children]; } else if([info isKindOfClass:[NSArray class]]) { @@ -124,16 +142,16 @@ - (id)initWithRootNode:(ProfilesNode *)rootNode originInfo:(id)info key:(NSStrin _type = @"Data"; _detail = [info jk_base64EncodedString]; if ([self.rootNode.key isEqualToString:@"DeveloperCertificates"]) { - NSDictionary *cerInfo = [self parseCertificate:info]; + NSDictionary *cerInfo = [self parseCertificate:info]; _extra = cerInfo; _key = [NSString stringWithFormat:@"%@",[cerInfo objectForKey:@"summary"]]; -// _name = [cerInfo objectForKey:@"invalidity"]; + // _name = [cerInfo objectForKey:@"invalidity"]; _type = @".cer"; } -// [info writeToFile:[@"/Users/Jakey/Downloads/" stringByAppendingPathComponent:@"info.cer"] atomically:YES]; -// -----BEGIN CERTIFICATE----- -// _detail -// -----END CERTIFICATE----- + // [info writeToFile:[@"/Users/Jakey/Downloads/" stringByAppendingPathComponent:@"info.cer"] atomically:YES]; + // -----BEGIN CERTIFICATE----- + // _detail + // -----END CERTIFICATE----- } } @@ -191,7 +209,7 @@ -(NSDictionary*)parseCertificate:(NSData*)data { else { NSLog(@"No invalidity values in '%@' certificate, dictionary = %@", summary, valuesDict); [detailsDict setObject:@"No invalidity values" forKey:devCertInvalidityDateKey]; - + } CFRelease(valuesDict); @@ -208,7 +226,26 @@ -(NSDictionary*)parseCertificate:(NSData*)data { CFRelease(certificateRef); } return detailsDict; - + } +-(NSInteger)getDaysFrom:(NSDate *)date endDate:(NSDate *)endDate +{ + if(!date || !endDate){ + return 0; + } + NSCalendar *gregorian = [[NSCalendar alloc] + initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; + [gregorian setFirstWeekday:2]; + NSDate *fromDate; + NSDate *toDate; + [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&fromDate interval:NULL forDate:date]; + [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&toDate interval:NULL forDate:endDate]; + NSDateComponents *dayComponents = [gregorian components:NSCalendarUnitDay fromDate:fromDate toDate:toDate options:0]; + if(dayComponents.day<0){ + return 0; + } + return dayComponents.day; +} + @end