forked from mipstian/catch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTCFileUtils.m
39 lines (26 loc) · 1.17 KB
/
CTCFileUtils.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "CTCFileUtils.h"
static NSString * const kCTCFileUtilsTorrentExtension = @".torrent";
@implementation CTCFileUtils
+ (NSString *)computeFilenameFromURL:(NSURL*)fileURL {
// Compute destination filename
NSString *filename = fileURL.path.pathComponents.lastObject;
// Reverse urlencode
return [filename stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
+ (NSString *)addTorrentExtensionTo:(NSString*)filename {
BOOL hasExtension = [filename hasSuffix:kCTCFileUtilsTorrentExtension];
// Add .torrent extension if needed
return hasExtension ? filename : [filename stringByAppendingString:kCTCFileUtilsTorrentExtension];
}
+ (NSString *)userDownloadsDirectory {
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES);
// Might be nil!
return searchPaths.firstObject;
}
+ (NSString *)userHomeDirectory {
return NSHomeDirectory();
}
+ (NSString *)folderNameForShowWithName:(NSString *)showName {
return [[showName stringByReplacingOccurrencesOfString:@"/" withString:@""] stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
}
@end