Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 46 additions and 3 deletions.
  1. +6 −1 QSFileManager.h
  2. +40 −2 QSFileManager.m
View
7 QSFileManager.h
@@ -31,10 +31,15 @@
}
+ (NSString *)documentsFilePathForFile:(NSString *)strFile;
-
+ (bool)writeDocumentsFile:(NSString *)strFileName WithData:(NSData *)objData;
+ (NSData *)readDocumentsFile:(NSString *)strFileName;
++ (NSString *)offlineContentFilePathForFile:(NSString *)strFile;
++ (bool)writeOfflineContentFile:(NSString *)strFileName WithData:(NSData *)objData;
++ (NSData *)readOfflineContentFile:(NSString *)strFileName;
+
++ (bool)markFileAsDoNotBackup:(NSString *)strFileName;
+
+ (bool)writeFile:(NSString *)strFilePath WithData:(NSData *)objData;
+ (NSData *)readFile:(NSString *)strFilePath;
+ (NSInteger)fileSize:(NSString *)strFilePath;
View
42 QSFileManager.m
@@ -24,8 +24,10 @@
*/
#import "QSFileManager.h"
+#include <sys/xattr.h>
static NSString * _strDocumentsPath = nil;
+static NSString * _strOfflineContentPath = nil;
@implementation QSFileManager
@@ -35,10 +37,21 @@ + (NSString *)documentsFilePathForFile:(NSString *)strFile {
_strDocumentsPath = [objPaths objectAtIndex:0];
[_strDocumentsPath retain];
}
-
+
return [_strDocumentsPath stringByAppendingPathComponent:strFile];
}
+
++ (NSString *)offlineContentFilePathForFile:(NSString *)strFile {
+ if (_strOfflineContentPath == nil) {
+ NSArray * objPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, true);
+ _strOfflineContentPath = [[objPaths objectAtIndex:0] stringByAppendingPathComponent:@"Offline Content"];
+ [_strOfflineContentPath retain];
+ }
+
+ return [_strOfflineContentPath stringByAppendingPathComponent:strFile];
+}
+
+ (bool)writeFile:(NSString *)strFilePath WithData:(NSData *)objData {
return [[NSFileManager defaultManager] createFileAtPath:strFilePath contents:objData attributes:nil];
}
@@ -48,13 +61,38 @@ + (NSData *)readFile:(NSString *)strFilePath {
}
+ (bool)writeDocumentsFile:(NSString *)strFileName WithData:(NSData *)objData {
- return [QSFileManager writeFile:[QSFileManager documentsFilePathForFile:@"qcodo_large.tif"] WithData:objData];
+ return [QSFileManager writeFile:[QSFileManager documentsFilePathForFile:strFileName] WithData:objData];
}
+ (NSData *)readDocumentsFile:(NSString *)strFileName {
return [QSFileManager readFile:[QSFileManager documentsFilePathForFile:strFileName]];
}
++ (bool)writeOfflineContentFile:(NSString *)strFileName WithData:(NSData *)objData {
+ bool blnToReturn;
+ blnToReturn = [QSFileManager writeFile:[QSFileManager offlineContentFilePathForFile:strFileName] WithData:objData];
+
+ // Since we're dealing with Offline Content, we are required to set the "Do Not Back up" Extended Attribute
+ if (blnToReturn) {
+ blnToReturn = [QSFileManager markFileAsDoNotBackup:[QSFileManager offlineContentFilePathForFile:strFileName]];
+ }
+
+ return blnToReturn;
+}
+
++ (bool)markFileAsDoNotBackup:(NSString *)strFileName {
+ const char * strFilePath = [strFileName fileSystemRepresentation];
+ const char * strAttributeName = "com.apple.MobileBackup";
+ u_int8_t attrValue = 1;
+
+ int result = setxattr(strFilePath, strAttributeName, &attrValue, sizeof(attrValue), 0, 0);
+ return (result == 0);
+}
+
++ (NSData *)readOfflineContentFile:(NSString *)strFileName {
+ return [QSFileManager readFile:[QSFileManager offlineContentFilePathForFile:strFileName]];
+}
+
+ (NSInteger)fileSize:(NSString *)strFilePath {
NSDictionary * dctFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:strFilePath error:NULL];
return [dctFileAttributes fileSize];

No commit comments for this range

Something went wrong with that request. Please try again.