Skip to content

Commit

Permalink
add file size column
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshaopengkael committed Apr 25, 2016
1 parent dd68f74 commit ef6874c
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 44 deletions.
6 changes: 6 additions & 0 deletions LSUnusedResources.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
114E8C711CCDC31B00434D1C /* LSFileUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 114E8C701CCDC31B00434D1C /* LSFileUtils.m */; };
B1313CAC1B942827001CD7CF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B1313CAB1B942827001CD7CF /* AppDelegate.m */; };
B1313CAE1B942827001CD7CF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B1313CAD1B942827001CD7CF /* main.m */; };
B1313CC21B942828001CD7CF /* LSUnusedResourcesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B1313CC11B942828001CD7CF /* LSUnusedResourcesTests.m */; };
Expand All @@ -29,6 +30,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
114E8C6F1CCDC31B00434D1C /* LSFileUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSFileUtils.h; sourceTree = "<group>"; };
114E8C701CCDC31B00434D1C /* LSFileUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSFileUtils.m; sourceTree = "<group>"; };
B1313CA51B942827001CD7CF /* LSUnusedResources.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LSUnusedResources.app; sourceTree = BUILT_PRODUCTS_DIR; };
B1313CA91B942827001CD7CF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B1313CAA1B942827001CD7CF /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -133,6 +136,8 @@
B19D81821B9451540097E947 /* ResourceStringSearcher.m */,
B19D81841B959BDB0097E947 /* StringUtils.h */,
B19D81851B959BDB0097E947 /* StringUtils.m */,
114E8C6F1CCDC31B00434D1C /* LSFileUtils.h */,
114E8C701CCDC31B00434D1C /* LSFileUtils.m */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -265,6 +270,7 @@
B1313CAE1B942827001CD7CF /* main.m in Sources */,
B1313CAC1B942827001CD7CF /* AppDelegate.m in Sources */,
B19D81801B9451320097E947 /* ResourceFileSearcher.m in Sources */,
114E8C711CCDC31B00434D1C /* LSFileUtils.m in Sources */,
B19D81831B9451550097E947 /* ResourceStringSearcher.m in Sources */,
B19D81861B959BDB0097E947 /* StringUtils.m in Sources */,
B1313CD51B943075001CD7CF /* MainViewController.m in Sources */,
Expand Down
20 changes: 20 additions & 0 deletions LSUnusedResources/Model/LSFileUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// LSFileUtils.h
// LSUnusedResources
//
// Created by jhgfer on 16/4/25.
// Copyright © 2016年 lessfun.com. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface LSFileUtils : NSObject
/**
* get file size, ignore directory
* @param path path
* @param isDir
*
* @return
*/
+ (uint64_t)fileSizeAtPath:(NSString *)path isDir:(BOOL *)isDir;
@end
25 changes: 25 additions & 0 deletions LSUnusedResources/Model/LSFileUtils.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// LSFileUtils.m
// LSUnusedResources
//
// Created by jhgfer on 16/4/25.
// Copyright © 2016年 lessfun.com. All rights reserved.
//

#import "LSFileUtils.h"

@implementation LSFileUtils
+ (uint64_t)fileSizeAtPath:(NSString *)path isDir:(BOOL *)isDir {
uint64_t size = 0L;
NSError *error = nil;
NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
if (!error) {
*isDir = [attr[NSFileType]isEqualToString:NSFileTypeDirectory];
if (!*isDir) {
size = [attr[NSFileSize] unsignedLongLongValue];
}
}
return size;
}

@end
3 changes: 2 additions & 1 deletion LSUnusedResources/Model/ResourceFileSearcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ extern NSString * const kNotificationResourceFileQueryDone;

@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSString *path;

@property (assign, nonatomic) BOOL isDir;
@property (assign, nonatomic) uint64_t fileSize;
- (NSImage *)image;

@end
Expand Down
4 changes: 4 additions & 0 deletions LSUnusedResources/Model/ResourceFileSearcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "ResourceFileSearcher.h"
#import "StringUtils.h"
#import "LSFileUtils.h"

NSString * const kNotificationResourceFileQueryDone = @"kNotificationResourceFileQueryDone";

Expand Down Expand Up @@ -101,9 +102,12 @@ - (void)scanResourceFile {
NSString *keyName = [StringUtils stringByRemoveResourceSuffix:name];

if (!tempResNameInfoDict[keyName]) {
BOOL isDir = NO;
ResourceFileInfo *info = [ResourceFileInfo new];
info.name = name;
info.path = path;
info.fileSize = [LSFileUtils fileSizeAtPath:path isDir:&isDir];
info.isDir = isDir;
tempResNameInfoDict[keyName] = info;
}
}
Expand Down
Loading

0 comments on commit ef6874c

Please sign in to comment.