This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
YKSystemPaths.m
73 lines (59 loc) · 2.52 KB
/
YKSystemPaths.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// YKSystemPaths.m
//
// Copyright (c) 2012 Yueks Inc. All rights reserved.
//
#import "YKSystemPaths.h"
#include <sys/xattr.h>
NSString* criticalDataPath()
{
return [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
}
NSString* cacheDataPath()
{
return [[NSHomeDirectory() stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:@"Caches"];
}
NSString* tempDataPath()
{
return [NSHomeDirectory() stringByAppendingPathComponent:@"tmp"];
}
NSString* offlineDataPath()
{
return [[NSHomeDirectory() stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:@"Private Documents"];
}
// last update: 2012 Aug 16
// reference http://developer.apple.com/library/ios/#qa/qa1719/_index.html
// reference was in 2012-04-23 version
BOOL addSkipBackupAttributeToItemAtURL(NSURL *URL)
{
NSString *versionString = [[UIDevice currentDevice] systemVersion];
NSArray *parts = [versionString componentsSeparatedByString:@"."];
NSString *majorVersionString = [parts objectAtIndex:0];
NSString *minorVersionString = [parts count] >= 2 ? [parts objectAtIndex:1] : @"0";
NSString *subMinorVersionString = [parts count] >= 3 ? [parts objectAtIndex:2] : @"0";
int majorVersion = [majorVersionString intValue];
int minorVersion = [minorVersionString intValue];
int subMinorVersion = [subMinorVersionString intValue];
if (majorVersion < 5 || (majorVersion == 5 && minorVersion == 0 && subMinorVersion == 0)) {
NSLog(@"not possible to set 'do not backup' property on older OS or 5.0.0");
return NO; // not possible to set on older OS or 5.0.0
}
else if (majorVersion == 5 && minorVersionString == 0 && subMinorVersion == 1) {
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
const char* filePath = [[URL path] fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
}
else {
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
NSError *error = nil;
BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
forKey: NSURLIsExcludedFromBackupKey error: &error];
if(!success){
NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
}
return success;
}
}