no message
This commit is contained in:
1 parent
de5bd21a43
commit
568ad5c409
262 files changed
+23226
-78
No files matched your search
+20
@@ -0,0 +1,20 @@
|
||||
Copyright (c) <2015> Hiroki Umatani PEAR
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// PEARFileManager.h
|
||||
// FileManager
|
||||
//
|
||||
// Created by hirokiumatani on 2015/10/31.
|
||||
// Copyright (c) 2015年 hirokiumatani. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface PEARFileManager : NSObject
|
||||
|
||||
typedef NS_ENUM(NSInteger,ROOT_DIR_TYPE)
|
||||
{
|
||||
k_ROOT_DIR_DOCUMENTS,
|
||||
k_ROOT_DIR_LIBRARY,
|
||||
k_ROOT_DIR_TMP,
|
||||
};
|
||||
|
||||
|
||||
@property (nonatomic,assign)ROOT_DIR_TYPE rootDir;
|
||||
/**
|
||||
initial with root directory
|
||||
*/
|
||||
- (id)initWithRootPath:(ROOT_DIR_TYPE)rootType;
|
||||
|
||||
/**
|
||||
singletone instance
|
||||
*/
|
||||
+ (PEARFileManager *)sharedInstatnce;
|
||||
|
||||
/**
|
||||
set root directory
|
||||
*/
|
||||
- (void)setRootDirectory:(ROOT_DIR_TYPE)rootType;
|
||||
|
||||
/**
|
||||
get root directory path
|
||||
*/
|
||||
- (NSString *)getRootDirectoryPath;
|
||||
|
||||
/**
|
||||
join file name in dir path
|
||||
*/
|
||||
- (NSString *)joinFileName:(NSString *)fileName
|
||||
inDirPath:(NSString *)dirPath;
|
||||
|
||||
/**
|
||||
create directory
|
||||
*/
|
||||
- (BOOL)createDirectory:(NSString *)dirPath
|
||||
permisson:(NSNumber *)permission;
|
||||
|
||||
/**
|
||||
create file
|
||||
*/
|
||||
- (BOOL)createFileWithData:(NSData *)fileData
|
||||
filePath:(NSString *)filePath
|
||||
permisson:(NSNumber *)permission;
|
||||
|
||||
/**
|
||||
fetch data
|
||||
*/
|
||||
- (NSData *)fetchFileDataWithPath:(NSString *)path;
|
||||
|
||||
/**
|
||||
fetch file Names
|
||||
*/
|
||||
- (NSArray *)fetchFileNameListsWithDirPath:(NSString *)dirPath;
|
||||
|
||||
/**
|
||||
check file or directory
|
||||
*/
|
||||
- (BOOL)checkPath:(NSString *)path;
|
||||
|
||||
/**
|
||||
delete file or directory
|
||||
*/
|
||||
- (BOOL)deletePath:(NSString *)Path;
|
||||
|
||||
/**
|
||||
update directory
|
||||
*/
|
||||
- (BOOL)updateDirectory:(NSString *)dirPath
|
||||
permisson:(NSNumber *)permission;
|
||||
|
||||
/**
|
||||
update file
|
||||
*/
|
||||
- (BOOL)updateFileWithData:(NSData *)fileData
|
||||
filePath:(NSString *)filePath
|
||||
permisson:(NSNumber *)permission;
|
||||
|
||||
/**
|
||||
move file or directory
|
||||
*/
|
||||
- (BOOL)moveFromPath:(NSString *)fromPath toPath:(NSString *)toPath;
|
||||
|
||||
/**
|
||||
copy file or directory
|
||||
*/
|
||||
- (BOOL)copyFrompath:(NSString *)fromPath toPath:(NSString *)toPath;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,219 @@
|
||||
//
|
||||
// PEARFileManager.m
|
||||
// FileManager
|
||||
//
|
||||
// Created by hirokiumatani on 2015/10/31.
|
||||
// Copyright (c) 2015年 hirokiumatani. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PEARFileManager.h"
|
||||
|
||||
@interface PEARFileManager ()
|
||||
|
||||
@property (nonatomic,strong) NSString *rootPath;
|
||||
|
||||
@end
|
||||
|
||||
@implementation PEARFileManager
|
||||
|
||||
static PEARFileManager *_sharedInstatnce = nil;
|
||||
|
||||
#pragma mark - initial
|
||||
+ (PEARFileManager*)sharedInstatnce
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^
|
||||
{
|
||||
_sharedInstatnce = [[PEARFileManager alloc] init];
|
||||
[_sharedInstatnce setRootDirectory:k_ROOT_DIR_LIBRARY];
|
||||
});
|
||||
return _sharedInstatnce;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self == [super init])
|
||||
{
|
||||
[self setRootDir:k_ROOT_DIR_LIBRARY];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithRootPath:(ROOT_DIR_TYPE)rootType
|
||||
{
|
||||
if (self == [super init])
|
||||
{
|
||||
[self setRootDir:rootType];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - root directory
|
||||
- (void)setRootDirectory:(ROOT_DIR_TYPE)rootType
|
||||
{
|
||||
switch (rootType)
|
||||
{
|
||||
case k_ROOT_DIR_DOCUMENTS:
|
||||
{
|
||||
_rootPath = [NSString stringWithFormat:@"%@/Documents",NSHomeDirectory()];
|
||||
break;
|
||||
}
|
||||
case k_ROOT_DIR_LIBRARY:
|
||||
{
|
||||
_rootPath = [NSString stringWithFormat:@"%@/Library",NSHomeDirectory()];
|
||||
break;
|
||||
}
|
||||
case k_ROOT_DIR_TMP:
|
||||
{
|
||||
_rootPath = [NSString stringWithFormat:@"%@/tmp",NSHomeDirectory()];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)getRootDirectoryPath
|
||||
{
|
||||
return _rootPath;
|
||||
}
|
||||
|
||||
#pragma mark - create
|
||||
- (BOOL)createDirectory:(NSString *)dirPath
|
||||
permisson:(NSNumber *)permission
|
||||
{
|
||||
if ([self checkPath:dirPath])
|
||||
{
|
||||
NSLog(@"The path already exists");
|
||||
return NO;
|
||||
}
|
||||
|
||||
return [[NSFileManager new] createDirectoryAtPath:[self joinFileName:dirPath inDirPath:_rootPath]
|
||||
withIntermediateDirectories:YES
|
||||
attributes:@{NSFilePosixPermissions: permission}
|
||||
error:nil];
|
||||
}
|
||||
|
||||
- (BOOL)createFileWithData:(NSData *)fileData
|
||||
filePath:(NSString *)filePath
|
||||
permisson:(NSNumber *)permission
|
||||
{
|
||||
if ([self checkPath:filePath])
|
||||
{
|
||||
NSLog(@"The path already exists");
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSString *filesPath = [self joinFileName:filePath inDirPath:_rootPath];
|
||||
|
||||
return [[NSFileManager new] createFileAtPath:filesPath
|
||||
contents:fileData
|
||||
attributes:@{NSFilePosixPermissions:permission}];
|
||||
}
|
||||
|
||||
#pragma mark - update
|
||||
- (BOOL)updateDirectory:(NSString *)dirPath
|
||||
permisson:(NSNumber *)permission
|
||||
{
|
||||
if (![self checkPath:dirPath])
|
||||
{
|
||||
NSLog(@"The path dose not exists");
|
||||
return NO;
|
||||
}
|
||||
|
||||
return [[NSFileManager new] createDirectoryAtPath:[self joinFileName:dirPath inDirPath:_rootPath]
|
||||
withIntermediateDirectories:YES
|
||||
attributes:@{NSFilePosixPermissions: permission}
|
||||
error:nil];
|
||||
}
|
||||
|
||||
- (BOOL)updateFileWithData:(NSData *)fileData
|
||||
filePath:(NSString *)filePath
|
||||
permisson:(NSNumber *)permission
|
||||
{
|
||||
if (![self checkPath:filePath])
|
||||
{
|
||||
NSLog(@"The path dose not exists");
|
||||
return NO;
|
||||
}
|
||||
|
||||
return [[NSFileManager new] createFileAtPath:[self joinFileName:filePath inDirPath:_rootPath]
|
||||
contents:fileData
|
||||
attributes:@{NSFilePosixPermissions:permission}];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - fetch
|
||||
- (NSData *)fetchFileDataWithPath:(NSString *)path
|
||||
{
|
||||
if (![self checkPath:path])
|
||||
{
|
||||
NSLog(@"The path dose not exists");
|
||||
return nil;
|
||||
}
|
||||
return [[NSFileManager new] contentsAtPath:[self joinFileName:path inDirPath:_rootPath]];
|
||||
}
|
||||
|
||||
- (NSArray *)fetchFileNameListsWithDirPath:(NSString *)dirPath
|
||||
{
|
||||
return [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dirPath error:nil];
|
||||
}
|
||||
|
||||
#pragma mark - check
|
||||
- (BOOL)checkPath:(NSString *)path
|
||||
{
|
||||
return [[NSFileManager new] fileExistsAtPath:[self joinFileName:path inDirPath:_rootPath]];
|
||||
}
|
||||
|
||||
#pragma mark - delete
|
||||
- (BOOL)deletePath:(NSString *)path
|
||||
{
|
||||
if (![self checkPath:path])
|
||||
{
|
||||
NSLog(@"The path dose not exists");
|
||||
return NO;
|
||||
}
|
||||
return [[NSFileManager new] removeItemAtPath:[self joinFileName:path inDirPath:_rootPath] error:nil];
|
||||
}
|
||||
|
||||
#pragma mark - move
|
||||
- (BOOL)moveFromPath:(NSString *)fromPath toPath:(NSString *)toPath
|
||||
{
|
||||
if (![self checkPath:fromPath])
|
||||
{
|
||||
NSLog(@"The path dose not exists");
|
||||
return NO;
|
||||
}
|
||||
if ([self checkPath:toPath])
|
||||
{
|
||||
NSLog(@"The path already exists");
|
||||
return NO;
|
||||
}
|
||||
|
||||
return [[NSFileManager new] moveItemAtPath:[self joinFileName:fromPath inDirPath:_rootPath]
|
||||
toPath:[self joinFileName:toPath inDirPath:_rootPath] error:nil];
|
||||
}
|
||||
|
||||
#pragma mark - copy
|
||||
- (BOOL)copyFrompath:(NSString *)fromPath toPath:(NSString *)toPath
|
||||
{
|
||||
if (![self checkPath:fromPath])
|
||||
{
|
||||
NSLog(@"The path dose not exists");
|
||||
return NO;
|
||||
}
|
||||
if ([self checkPath:toPath])
|
||||
{
|
||||
NSLog(@"The path already exists");
|
||||
return NO;
|
||||
}
|
||||
|
||||
return [[NSFileManager new] copyItemAtPath:[self joinFileName:fromPath inDirPath:_rootPath]
|
||||
toPath:[self joinFileName:toPath inDirPath:_rootPath] error:nil];
|
||||
}
|
||||
|
||||
#pragma mark - join
|
||||
- (NSString *)joinFileName:(NSString *)fileName
|
||||
inDirPath:(NSString *)dirPath
|
||||
{
|
||||
return [NSString stringWithFormat:@"%@/%@",dirPath,fileName];
|
||||
}
|
||||
@end
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
### PEAR-FileManager-iOS [](https://github.com/HirokiUmatani/PEAR-FileManager-iOS/LICENSE) [](https://cocoapods.org/pods/PEAR-FileManager-iOS) [](https://cocoapods.org/pods/PEAR-FileManager-iOS)
|
||||
|
||||
====
|
||||
### Overview
|
||||
This is the ios library to manipulate directories and files in application.
|
||||
|
||||
### Installation
|
||||
<code>
|
||||
pod 'PEAR-FileManager-iOS'
|
||||
</code>
|
||||
|
||||
### Usage
|
||||
|
||||
##### initial
|
||||
```
|
||||
PEARFileManager *fileManager = [PEARFileManager sharedInstatnce];
|
||||
fileManager.rootDir = k_ROOT_DIR_LIBRARY;
|
||||
|
||||
```
|
||||
##### Create
|
||||
```
|
||||
[fileManager createDirectory:DIR_PATH permisson:PERMISSION];
|
||||
|
||||
```
|
||||
```
|
||||
[fileManager createFileWithData:pearImageData
|
||||
filePath:[fileManager joinFileName:FILE_NAME inDirPath:DIR_PATH]
|
||||
permisson:PERMISSION];
|
||||
|
||||
|
||||
```
|
||||
##### Copy
|
||||
```
|
||||
[fileManager copyFrompath:[fileManager joinFileName:FILE_NAME inDirPath:DIR_PATH]
|
||||
toPath:[fileManager joinFileName:COPY_FILE_NAME inDirPath:DIR_PATH]];
|
||||
|
||||
```
|
||||
##### Move
|
||||
```
|
||||
[fileManager moveFromPath:DIR_PATH
|
||||
toPath:MOVE_DIR_PATH];
|
||||
|
||||
```
|
||||
##### Delete
|
||||
```
|
||||
[fileManager deletePath:[fileManager joinFileName:FILE_NAME inDirPath:DIR_PATH]];
|
||||
|
||||
```
|
||||
|
||||
### Documents
|
||||
[library document](http://cocoadocs.org/docsets/PEAR-FileManager-iOS)
|
||||
|
||||
### Licence
|
||||
[MIT](https://github.com/HirokiUmatani/PEAR-FileManager-iOS/blob/master/LICENSE)
|
||||
|
||||
### Author
|
||||
[Hiroki Umatani](https://github.com/HirokiUmatani)
|
||||
Reference in new issue
Block a user