Skip to content

Commit

Permalink
Bug fix: should ignore Contents.json in x.imageset
Browse files Browse the repository at this point in the history
  • Loading branch information
tinymind committed Sep 19, 2017
1 parent 799f53d commit 59d9623
Show file tree
Hide file tree
Showing 55 changed files with 873 additions and 17 deletions.
2 changes: 1 addition & 1 deletion LSUnusedResources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>170919</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 2 additions & 0 deletions LSUnusedResources/Model/ResourceFileSearcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ extern NSString * const kNotificationResourceFileQueryDone;

- (void)reset;

- (BOOL)isImageSetFolder:(NSString *)folder;

@end
34 changes: 20 additions & 14 deletions LSUnusedResources/Model/ResourceFileSearcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

NSString * const kNotificationResourceFileQueryDone = @"kNotificationResourceFileQueryDone";

static NSString * const kSuffixImageSet = @"imageset";
static NSString * const kSuffixLaunchImage = @"launchimage";
static NSString * const kSuffixAppIcon = @"appiconset";
static NSString * const kSuffixBundle = @"bundle";
static NSString * const kSuffixPng = @"png";
static NSString * const kSuffixImageSet = @".imageset";
static NSString * const kSuffixLaunchImage = @".launchimage";
static NSString * const kSuffixAppIcon = @".appiconset";
static NSString * const kSuffixBundle = @".bundle";
static NSString * const kSuffixPng = @".png";


@implementation ResourceFileInfo
Expand All @@ -26,7 +26,7 @@ - (NSImage *)image {
return [[NSImage alloc] initByReferencingFile:self.path];
}

if ([self.name hasSuffix:kSuffixImageSet]) {
if ([[ResourceFileSearcher sharedObject] isImageSetFolder:self.name]) {
NSError *error = nil;
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.path error:&error];
if (files.count == 0) {
Expand Down Expand Up @@ -82,6 +82,16 @@ - (void)reset {
[self.resNameInfoDict removeAllObjects];
}

- (BOOL)isImageSetFolder:(NSString *)folder
{
if ([folder hasSuffix:kSuffixImageSet]
|| [folder hasSuffix:kSuffixAppIcon]
|| [folder hasSuffix:kSuffixLaunchImage]) {
return YES;
}
return NO;
}

#pragma mark - Private

- (void)scanResourceFileWithProjectPath:(NSString *)projectPath excludeFolders:(NSArray *)excludeFolders resourceSuffixs:(NSArray *)resourceSuffixs {
Expand Down Expand Up @@ -129,10 +139,8 @@ - (NSArray *)resourceFilesInDirectory:(NSString *)directoryPath excludeFolders:(
} else {
for (NSString *path in pathList) {
// if the png file is not in xxx/xxx.imageset/; xx/LaunchImage.launchimage; xx/AppIcon.appiconset
if ([path rangeOfString:kSuffixImageSet].location == NSNotFound
&& [path rangeOfString:kSuffixBundle].location == NSNotFound
&& [path rangeOfString:kSuffixAppIcon].location == NSNotFound
&& [path rangeOfString:kSuffixLaunchImage].location == NSNotFound) {
if (![self isImageSetFolder:path]
&& [path rangeOfString:kSuffixBundle].location == NSNotFound) {
[resources addObject:path];
}
}
Expand All @@ -147,10 +155,8 @@ - (NSArray *)resourceFilesInDirectory:(NSString *)directoryPath excludeFolders:(
// // if the resource file is not in xxx/xxx.imageset/; xx/LaunchImage.launchimage; xx/AppIcon.appiconset
// if (![path hasPrefix:kSuffixPng]) {
// [resources addObjectsFromArray:pathList];
// } else if ([path rangeOfString:kSuffixImageSet].location == NSNotFound
// && [path rangeOfString:kSuffixBundle].location == NSNotFound
// && [path rangeOfString:kSuffixAppIcon].location == NSNotFound
// && [path rangeOfString:kSuffixLaunchImage].location == NSNotFound) {
// } else if (![self isImageSetFolder:path]
// && [path rangeOfString:kSuffixBundle].location == NSNotFound) {
// [resources addObject:path];
// }
// }
Expand Down
5 changes: 5 additions & 0 deletions LSUnusedResources/Model/ResourceStringSearcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "ResourceStringSearcher.h"
#import "ResourceFileSearcher.h"
#import "StringUtils.h"

NSString * const kNotificationResourceStringQueryDone = @"kNotificationResourceStringQueryDone";
Expand Down Expand Up @@ -263,6 +264,10 @@ - (NSArray *)getMatchStringWithContent:(NSString *)content pattern:(NSString*)pa
}

- (BOOL)isDirectory:(NSString *)path {
// Ignore x.imageset/Contents.json
if ([[ResourceFileSearcher sharedObject] isImageSetFolder:path]) {
return NO;
}
BOOL isDirectory;
return [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory;
}
Expand Down
4 changes: 2 additions & 2 deletions LSUnusedResources/Resource/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12118"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down
Binary file modified Release/LSUnusedResources.app.zip
Binary file not shown.
Loading

0 comments on commit 59d9623

Please sign in to comment.