Skip to content

Commit ce64851

Browse files
committed
Start searching for artwork from system root instead of system library
1 parent 696a5de commit ce64851

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

Classes/ArtworkViewController.m

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
int unknown2;
2525
};
2626

27-
static NSString *systemLibraryPath()
27+
static NSString *systemRoot()
2828
{
29-
static NSString *systemLibraryPath = nil;
30-
if (systemLibraryPath)
31-
return systemLibraryPath;
29+
static NSString *systemRoot = nil;
30+
if (systemRoot)
31+
return systemRoot;
3232

3333
// Extract images from actual firmware if mounted instead of simulator
3434
// Use https://github.com/kennytm/Miscellaneous/blob/master/ipsw_decrypt.py
@@ -46,26 +46,13 @@
4646
NSString *model = [wallpapers count] == 1 ? [wallpapers lastObject] : @"iPhone";
4747
if ([[UIDevice currentDevice].model hasPrefix:model])
4848
{
49-
systemLibraryPath = [volumePath retain];
50-
return systemLibraryPath;
49+
systemRoot = [volumePath retain];
50+
return systemRoot;
5151
}
5252
}
5353
}
5454

55-
NSString *systemFrameworksPath = @"/System/Library/Frameworks";
56-
for (NSBundle *framework in [NSBundle allFrameworks])
57-
{
58-
// So that it works on both simulator and device
59-
NSString *frameworkName = [[framework bundlePath] lastPathComponent];
60-
if ([frameworkName isEqualToString:@"Foundation.framework"])
61-
{
62-
systemFrameworksPath = [[framework bundlePath] stringByDeletingLastPathComponent];
63-
break;
64-
}
65-
}
66-
67-
systemLibraryPath = [[systemFrameworksPath stringByDeletingLastPathComponent] retain];
68-
return systemLibraryPath;
55+
return [[[NSProcessInfo processInfo] environment] objectForKey:@"IPHONE_SIMULATOR_ROOT"] ?: @"/";
6956
}
7057

7158
static NSString *pathWithScale(NSString *path, CGFloat scale)
@@ -427,18 +414,18 @@ - (void) loadImages
427414

428415
if ([self isArtwork])
429416
{
430-
for (NSString *relativePath in [[NSFileManager defaultManager] enumeratorAtPath:systemLibraryPath()])
417+
for (NSString *relativePath in [[NSFileManager defaultManager] enumeratorAtPath:systemRoot()])
431418
{
432419
BOOL scale1 = [UIScreen mainScreen].scale == 1 && [[relativePath lowercaseString] rangeOfString:@"@2x"].location == NSNotFound;
433420
BOOL scale2 = [UIScreen mainScreen].scale == 2 && [[relativePath lowercaseString] rangeOfString:@"@2x"].location != NSNotFound;
434421
if ([relativePath hasSuffix:@"png"] && (scale1 || scale2))
435422
{
436-
NSString *filePath = [systemLibraryPath() stringByAppendingPathComponent:relativePath];
423+
NSString *filePath = [systemRoot() stringByAppendingPathComponent:relativePath];
437424
[self addImage:imageWithContentsOfFile(filePath) filePath:filePath];
438425
}
439426
else if ([[relativePath pathExtension] isEqualToString:@"artwork"])
440427
{
441-
NSString *artworkPath = [systemLibraryPath() stringByAppendingPathComponent:relativePath];
428+
NSString *artworkPath = [systemRoot() stringByAppendingPathComponent:relativePath];
442429
NSBundle *bundle = [NSBundle bundleWithPath:[artworkPath stringByDeletingLastPathComponent]];
443430
NSString *artworkName = [[relativePath lastPathComponent] stringByDeletingPathExtension];
444431
NSRange atRange = [artworkName rangeOfString:@"@"];

0 commit comments

Comments
 (0)