2018-01-20 16:57:29 -02:00
|
|
|
//
|
|
|
|
// RNFileSystem.m
|
|
|
|
// RCTCamera
|
|
|
|
//
|
|
|
|
// Created by Joao Guilherme Daros Fidelis on 19/01/18.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "RNFileSystem.h"
|
|
|
|
|
|
|
|
@implementation RNFileSystem
|
|
|
|
|
|
|
|
+ (BOOL)ensureDirExistsWithPath:(NSString *)path
|
|
|
|
{
|
|
|
|
BOOL isDir = NO;
|
|
|
|
NSError *error;
|
|
|
|
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];
|
|
|
|
if (!(exists && isDir)) {
|
|
|
|
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
|
if (error) {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString *)generatePathInDirectory:(NSString *)directory withExtension:(NSString *)extension
|
|
|
|
{
|
|
|
|
NSString *fileName = [[[NSUUID UUID] UUIDString] stringByAppendingString:extension];
|
|
|
|
[RNFileSystem ensureDirExistsWithPath:directory];
|
|
|
|
return [directory stringByAppendingPathComponent:fileName];
|
|
|
|
}
|
|
|
|
|
2018-01-23 10:36:00 -02:00
|
|
|
+ (NSString *)cacheDirectoryPath
|
|
|
|
{
|
|
|
|
NSArray *array = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
return [array objectAtIndex:0];
|
|
|
|
}
|
|
|
|
|
2018-01-20 16:57:29 -02:00
|
|
|
@end
|
|
|
|
|