Skip to content

Commit

Permalink
1. Fix handle resources in .imageset; 2. Click name to copy; 3. Enhan…
Browse files Browse the repository at this point in the history
…ce ignore similar name
  • Loading branch information
tinymind committed Sep 28, 2017
1 parent 59d9623 commit 60f16f9
Show file tree
Hide file tree
Showing 47 changed files with 202 additions and 30 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>170919</string>
<string>170928</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
25 changes: 16 additions & 9 deletions LSUnusedResources/Model/ResourceFileSearcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ - (BOOL)isImageSetFolder:(NSString *)folder
return NO;
}

- (BOOL)isInImageSetFolder:(NSString *)folder
{
if (![self isImageSetFolder:folder]
&& ([folder rangeOfString:kSuffixImageSet].location != NSNotFound
|| [folder rangeOfString:kSuffixAppIcon].location != NSNotFound
|| [folder rangeOfString:kSuffixLaunchImage].location != NSNotFound)) {
return YES;
}
return NO;
}

#pragma mark - Private

- (void)scanResourceFileWithProjectPath:(NSString *)projectPath excludeFolders:(NSArray *)excludeFolders resourceSuffixs:(NSArray *)resourceSuffixs {
Expand Down Expand Up @@ -134,15 +145,11 @@ - (NSArray *)resourceFilesInDirectory:(NSString *)directoryPath excludeFolders:(
// list of path<NSString>
NSArray *pathList = [self searchDirectory:directoryPath excludeFolders:excludeFolders forFiletype:fileType];
if (pathList.count) {
if (![fileType isEqualTo:kSuffixPng]) {
[resources addObjectsFromArray:pathList];
} else {
for (NSString *path in pathList) {
// if the png file is not in xxx/xxx.imageset/; xx/LaunchImage.launchimage; xx/AppIcon.appiconset
if (![self isImageSetFolder:path]
&& [path rangeOfString:kSuffixBundle].location == NSNotFound) {
[resources addObject:path];
}
for (NSString *path in pathList) {
// ignore if the resource file is in xxx/xxx.imageset/; xx/LaunchImage.launchimage; xx/AppIcon.appiconset; xx.bundle/xx
if (![self isInImageSetFolder:path]
&& [path rangeOfString:kSuffixBundle].location == NSNotFound) {
[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 @@ -95,7 +95,7 @@ - (BOOL)containsResourceName:(NSString *)name {
}

- (BOOL)containsSimilarResourceName:(NSString *)name {
NSString *regexStr = @"(\\d+)";
NSString *regexStr = @"([-_]?\\d+)";
NSRegularExpression* regexExpression = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionCaseInsensitive error:nil];
NSArray* matchs = [regexExpression matchesInString:name options:0 range:NSMakeRange(0, name.length)];
if (matchs != nil && [matchs count] == 1) {
Expand Down
14 changes: 8 additions & 6 deletions LSUnusedResources/Resource/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,13 @@
</tableHeaderView>
</scrollView>
<button misplaced="YES" id="ty7-Lh-GkV">
<rect key="frame" x="10" y="7" width="451" height="18"/>
<rect key="frame" x="10" y="3" width="451" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Ignore similar name (eg: &quot;icon_tag_1.png&quot;, using with &quot;icon_tag_%d&quot; )" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="gdO-HM-LlZ">
<buttonCell key="cell" type="check" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="gdO-HM-LlZ">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
<string key="title">Ignore similar name (eg: tag_1.png, using with "tag_%d" or "tag"
will be considered to be used )</string>
<font key="font" metaFont="system" size="11"/>
</buttonCell>
<connections>
<action selector="onIgnoreSimilarCheckboxClicked:" target="XfG-lQ-9wD" id="HHq-fT-Fmg"/>
Expand Down Expand Up @@ -930,7 +932,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
</tableColumn>
<tableColumn identifier="FileName" editable="NO" width="200" minWidth="200" maxWidth="1000" id="60s-SD-XRC">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Name">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Name (Click to Copy)">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.33333298560000002" alpha="1" colorSpace="calibratedWhite"/>
Expand All @@ -943,7 +945,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
</tableColumn>
<tableColumn identifier="FileSize" width="64" minWidth="10" maxWidth="3.4028234663852886e+38" id="trL-iQ-pxU">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Size(KB)">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Size (KB)">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
Expand All @@ -956,7 +958,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
</tableColumn>
<tableColumn identifier="FilePath" editable="NO" width="1000" minWidth="40" maxWidth="1000" id="iry-Wq-tlB">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Full Path">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Full Path (Double Click to Open)">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.33333298560000002" alpha="1" colorSpace="calibratedWhite"/>
Expand Down
16 changes: 14 additions & 2 deletions LSUnusedResources/ViewController/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ - (void)viewDidLoad {

[self setupSettings];

// Setup double click
// Setup tableview click action
[self.resultsTableView setAction:@selector(onResultsTableViewSingleClicked)];
[self.resultsTableView setDoubleAction:@selector(onResultsTableViewDoubleClicked)];
self.resultsTableView.allowsEmptySelection = YES;
self.resultsTableView.allowsMultipleSelection = YES;
Expand Down Expand Up @@ -212,6 +213,17 @@ - (IBAction)onAddPatternButtonClicked:(id)sender {
[self.patternTableView reloadData];
}

- (void)onResultsTableViewSingleClicked {
// Copy to pasteboard
NSInteger index = [self.resultsTableView clickedRow];
if (self.unusedResults.count == 0 || index >= self.unusedResults.count) {
return;
}
ResourceFileInfo *info = [self.unusedResults objectAtIndex:index];
[[NSPasteboard generalPasteboard] clearContents];
[[NSPasteboard generalPasteboard] setString:info.name forType:NSStringPboardType];
}

- (void)onResultsTableViewDoubleClicked {
// Open finder
NSInteger index = [self.resultsTableView clickedRow];
Expand Down Expand Up @@ -378,7 +390,7 @@ - (void)updateUnusedResultsCount {
for(ResourceFileInfo *info in self.unusedResults){
totalSize += info.fileSize;
}
self.statusLabel.stringValue = [NSString stringWithFormat:@"unsued: %ld, time: %.2fs, size: %.2f KB", (long)count, time, (long)totalSize / 1024.0];
self.statusLabel.stringValue = [NSString stringWithFormat:@"Total: %ld, unsued: %ld, time: %.2fs, size: %.2f KB", [[ResourceFileSearcher sharedObject].resNameInfoDict allKeys].count, (long)count, time, (long)totalSize / 1024.0];
}

- (void)searchUnusedResourcesIfNeeded {
Expand Down
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ It's an useful utility tool to check what resources are not being used in your X

1. Click `Browse..` to select a project folder.
2. Click `Search` to start searching.
3. Wait a second, the results will be shown in the tableview.
3. Wait a few seconds, the results will be shown in the tableview.

## Feature

Expand All @@ -26,16 +26,30 @@ icon_tag_0.png
icon_tag_1.png
icon_tag_2.png
icon_tag_3.png
icon_title-0.png
icon_title-1.png
icon_title-2.png
icon_test0.png
icon_test1.png
icon_test2.png
```

And using in this way:

```
NSInteger index = random() % 4;
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"icon_tag_%d", index]];
``` objc
NSInteger index = random() % 4;
UIImage *img0 = [UIImage imageNamed:[NSString stringWithFormat:@"icon_tag_%d", index]];

// Or
UIImage *img1 = [self createImageWithPrefix:"icon_title" suffix:@"-" andIndex:index];

// Or
UIImage *img2 = [self createImageWithPrefix:"icon_test" andIndex:index];
```
`icon_tag_x.png` should not be shown as unused resource, we should ignore them.
`icon_tag_x.png`, `icon_title-x` and `icon_testx` will be considered to be used, should not be shown as unused resource.
## Installation
Expand Down
Binary file modified Release/LSUnusedResources.app.zip
Binary file not shown.
4 changes: 3 additions & 1 deletion Test/UnusedDemo/UnusedDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@
B1EB8D7F1DDC83B0008174DB /* UnusedDemo */ = {
isa = PBXGroup;
children = (
B1E27ADD1E275C0F00608ED5 /* Resource */,
B1EB8D831DDC83B0008174DB /* AppDelegate.h */,
B1EB8D841DDC83B0008174DB /* AppDelegate.m */,
B1EB8D861DDC83B0008174DB /* ViewController.h */,
B1EB8D871DDC83B0008174DB /* ViewController.m */,
B1EB8D891DDC83B0008174DB /* Main.storyboard */,
B1EB8D8E1DDC83B0008174DB /* LaunchScreen.storyboard */,
B1E27ADD1E275C0F00608ED5 /* Resource */,
B1EB8D911DDC83B0008174DB /* Info.plist */,
B1EB8D801DDC83B0008174DB /* Supporting Files */,
);
Expand Down Expand Up @@ -391,6 +391,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = 5JUDCYNX4A;
INFOPLIST_FILE = UnusedDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -403,6 +404,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = 5JUDCYNX4A;
INFOPLIST_FILE = UnusedDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "3x"
},
{
Expand All @@ -21,13 +23,15 @@
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "3x"
},
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"images" : [
{
"orientation" : "portrait",
"idiom" : "iphone",
"filename" : "Launch_Portrait_640_960.png",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "retina4",
"filename" : "Launch_Portrait_640_1136.png",
"minimum-system-version" : "7.0",
"orientation" : "portrait",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading

0 comments on commit 60f16f9

Please sign in to comment.