Skip to content

Commit

Permalink
Fix search result; ignore if using diffrent image name from imageset …
Browse files Browse the repository at this point in the history
…folder name
  • Loading branch information
tinymind committed Nov 16, 2016
1 parent aa20de3 commit 620b539
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
4 changes: 2 additions & 2 deletions LSUnusedResources/Model/ResourceFileSearcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ - (NSArray *)resourceFilesInDirectory:(NSString *)directoryPath excludeFolders:(
[resources addObjectsFromArray:pathList];
} else {
for (NSString *path in pathList) {
// if the resource file is not in xxx/xxx.imageset/; xx/LaunchImage.launchimage; xx/AppIcon.appiconset
// 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) {
[resources addObject:path];
[resources addObject:path];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion LSUnusedResources/Model/ResourceStringSearcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ - (NSArray *)getMatchStringWithContent:(NSString *)content pattern:(NSString*)pa
for (NSTextCheckingResult *checkingResult in matchs) {
NSString *res = [content substringWithRange:[checkingResult rangeAtIndex:index]];
res = [res lastPathComponent];
// res = [StringUtils stringByRemoveResourceSuffix:res];
res = [StringUtils stringByRemoveResourceSuffix:res];
[list addObject:res];
}
return list;
Expand Down
2 changes: 1 addition & 1 deletion LSUnusedResources/Recourse/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@
<button verticalHuggingPriority="750" id="K2U-Ys-vXw">
<rect key="frame" x="440" y="25" width="94" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Browse.." bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="PMh-w7-GaI">
<buttonCell key="cell" type="push" title="Browse..." bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="PMh-w7-GaI">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
Expand Down
38 changes: 32 additions & 6 deletions LSUnusedResources/ViewController/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "MainViewController.h"
#import "ResourceFileSearcher.h"
#import "ResourceStringSearcher.h"
#import "StringUtils.h"

// Constant strings
static NSString * const kDefaultResourceSuffixs = @"imageset;jpg;gif;png";
Expand Down Expand Up @@ -55,11 +56,6 @@ @interface MainViewController () <NSTableViewDelegate, NSTableViewDataSource>
@property (assign, nonatomic) BOOL isStringDone;
@property (strong, nonatomic) NSDate *startTime;

- (IBAction)onBrowseButtonClicked:(id)sender;
- (IBAction)onSearchButtonClicked:(id)sender;
- (IBAction)onExportButtonClicked:(id)sender;
- (IBAction)onDeleteButtonClicked:(id)sender;

@end

@implementation MainViewController
Expand Down Expand Up @@ -361,7 +357,13 @@ - (void)searchUnusedResourcesIfNeeded {
if (![[ResourceStringSearcher sharedObject] containsResourceName:name]) {
if (!self.ignoreSimilarCheckbox.state
|| ![[ResourceStringSearcher sharedObject] containsSimilarResourceName:name]) {
[self.unusedResults addObject:[ResourceFileSearcher sharedObject].resNameInfoDict[name]];
//TODO: if imageset name is A but contains png with name B, and using as B, should ignore A.imageset

ResourceFileInfo *resInfo = [ResourceFileSearcher sharedObject].resNameInfoDict[name];
if (!resInfo.isDir
|| ![self usingResWithDiffrentDirName:resInfo]) {
[self.unusedResults addObject:resInfo];
}
}
}
}
Expand All @@ -372,4 +374,28 @@ - (void)searchUnusedResourcesIfNeeded {
}
}

- (BOOL)usingResWithDiffrentDirName:(ResourceFileInfo *)resInfo
{
if (!resInfo.isDir) {
return NO;
}
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:resInfo.path];
for (NSString *fileName in fileEnumerator) {
if (![StringUtils isImageTypeWithName:fileName]) {
continue;
}

NSString *fileNameWithoutExt = [StringUtils stringByRemoveResourceSuffix:fileName];

if ([fileNameWithoutExt isEqualToString:resInfo.name]) {
return NO;
}

if ([[ResourceStringSearcher sharedObject] containsResourceName:fileNameWithoutExt]) {
return YES;
}
}
return NO;
}

@end
Binary file modified Release/LSUnusedResources.app.zip
Binary file not shown.

0 comments on commit 620b539

Please sign in to comment.