|
@@ -42,19 +42,6 @@
|
|
|
#pragma mark ===== Various =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
|
|
|
-+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
|
|
|
-{
|
|
|
- NSError *error = nil;
|
|
|
- BOOL success = [URL setResourceValue:[NSNumber numberWithBool: YES] forKey: NSURLIsExcludedFromBackupKey error: &error];
|
|
|
- if(success) {
|
|
|
- NSLog(@"Excluding %@ from backup", [URL lastPathComponent]);
|
|
|
- } else {
|
|
|
- NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
|
|
|
- }
|
|
|
-
|
|
|
- return success;
|
|
|
-}
|
|
|
-
|
|
|
+ (NSString *)dateDiff:(NSDate *) convertedDate
|
|
|
{
|
|
|
NSDate *todayDate = [NSDate date];
|
|
@@ -251,233 +238,6 @@
|
|
|
return fileName;
|
|
|
}
|
|
|
|
|
|
-+ (void)createDirectoryStandard
|
|
|
-{
|
|
|
- NSString *path;
|
|
|
- NSURL *dirGroup = [CCUtility getDirectoryGroup];
|
|
|
-
|
|
|
- NSLog(@"[LOG] Dir Group");
|
|
|
- NSLog(@"%@", [dirGroup path]);
|
|
|
- NSLog(@"[LOG] Program application ");
|
|
|
- NSLog(@"%@", [[CCUtility getDirectoryDocuments] stringByDeletingLastPathComponent]);
|
|
|
-
|
|
|
- // create Directory Documents
|
|
|
- path = [CCUtility getDirectoryDocuments];
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath: path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- // create Directory audio => Library, Application Support, audio
|
|
|
- path = [CCUtility getDirectoryAudio];
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath: path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- // create Directory database Nextcloud
|
|
|
- path = [[dirGroup URLByAppendingPathComponent:[[NCGlobal shared] appDatabaseNextcloud]] path];
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath:path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- // create Directory User Data
|
|
|
- path = [[dirGroup URLByAppendingPathComponent:NCGlobal.shared.appUserData] path];
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath:path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- // create Directory Provider Storage
|
|
|
- path = [CCUtility getDirectoryProviderStorage];
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath: path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- // create Directory Scan
|
|
|
- path = [[dirGroup URLByAppendingPathComponent:NCGlobal.shared.appScan] path];
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath:path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- // create Directory Temp
|
|
|
- path = NSTemporaryDirectory();
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath:path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- // Directory Excluded From Backup
|
|
|
- [CCUtility addSkipBackupAttributeToItemAtURL:[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]];
|
|
|
- [CCUtility addSkipBackupAttributeToItemAtURL:[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:NCGlobal.shared.directoryProviderStorage]];
|
|
|
- [CCUtility addSkipBackupAttributeToItemAtURL:[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:NCGlobal.shared.appApplicationSupport]];
|
|
|
-
|
|
|
- [CCUtility addSkipBackupAttributeToItemAtURL:[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:NCGlobal.shared.appCertificates]];
|
|
|
- [CCUtility addSkipBackupAttributeToItemAtURL:[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:NCGlobal.shared.appDatabaseNextcloud]];
|
|
|
- [CCUtility addSkipBackupAttributeToItemAtURL:[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:NCGlobal.shared.appScan]];
|
|
|
- [CCUtility addSkipBackupAttributeToItemAtURL:[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:NCGlobal.shared.appUserData]];
|
|
|
-}
|
|
|
-
|
|
|
-+ (NSURL *)getDirectoryGroup
|
|
|
-{
|
|
|
- NSURL *path = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:[NCBrandOptions shared].capabilitiesGroups];
|
|
|
- return path;
|
|
|
-}
|
|
|
-
|
|
|
-// Return the path of directory Documents -> NSDocumentDirectory
|
|
|
-+ (NSString *)getDirectoryDocuments
|
|
|
-{
|
|
|
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
-
|
|
|
- return [paths objectAtIndex:0];
|
|
|
-}
|
|
|
-
|
|
|
-+ (NSString *)getDirectoryReaderMetadata
|
|
|
-{
|
|
|
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
|
|
-
|
|
|
- return [NSString stringWithFormat:@"%@/Reader Metadata", [paths objectAtIndex:0]];
|
|
|
-}
|
|
|
-
|
|
|
-// Return the path of directory Audio
|
|
|
-+ (NSString *)getDirectoryAudio
|
|
|
-{
|
|
|
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
|
|
-
|
|
|
- return [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0], @"audio"];
|
|
|
-}
|
|
|
-
|
|
|
-// Return the path of directory Cetificates
|
|
|
-+ (NSString *)getDirectoryCerificates
|
|
|
-{
|
|
|
- NSString *path = [[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:NCGlobal.shared.appCertificates] path];
|
|
|
-
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath:path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- return path;
|
|
|
-}
|
|
|
-
|
|
|
-+ (NSString *)getDirectoryUserData
|
|
|
-{
|
|
|
- NSString *path = [[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:NCGlobal.shared.appUserData] path];
|
|
|
-
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath:path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- return path;
|
|
|
-}
|
|
|
-
|
|
|
-+ (NSString *)getDirectoryProviderStorage
|
|
|
-{
|
|
|
- NSString *path = [[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:NCGlobal.shared.directoryProviderStorage] path];
|
|
|
-
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath:path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- return path;
|
|
|
-}
|
|
|
-
|
|
|
-+ (NSString *)getDirectoryProviderStorageOcId:(NSString *)ocId
|
|
|
-{
|
|
|
- NSString *path = [NSString stringWithFormat:@"%@/%@", [self getDirectoryProviderStorage], ocId];
|
|
|
-
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath:path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- return path;
|
|
|
-}
|
|
|
-
|
|
|
-+ (NSString *)getDirectoryProviderStorageOcId:(NSString *)ocId fileNameView:(NSString *)fileNameView
|
|
|
-{
|
|
|
- NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", [self getDirectoryProviderStorageOcId:ocId], fileNameView];
|
|
|
-
|
|
|
- // if do not exists create file 0 length
|
|
|
- // causes files with lenth 0 to never be downloaded, because already exist
|
|
|
- // also makes it impossible to delete any file with length 0 (from cache)
|
|
|
- if ([[NSFileManager defaultManager] fileExistsAtPath:fileNamePath] == NO) {
|
|
|
- [[NSFileManager defaultManager] createFileAtPath:fileNamePath contents:nil attributes:nil];
|
|
|
- }
|
|
|
-
|
|
|
- return fileNamePath;
|
|
|
-}
|
|
|
-
|
|
|
-+ (NSString *)getDirectoryProviderStorageIconOcId:(NSString *)ocId etag:(NSString *)etag
|
|
|
-{
|
|
|
- return [NSString stringWithFormat:@"%@/%@.small.%@", [self getDirectoryProviderStorageOcId:ocId], etag, [NCGlobal shared].extensionPreview];
|
|
|
-}
|
|
|
-
|
|
|
-+ (NSString *)getDirectoryProviderStoragePreviewOcId:(NSString *)ocId etag:(NSString *)etag
|
|
|
-{
|
|
|
- return [NSString stringWithFormat:@"%@/%@.preview.%@", [self getDirectoryProviderStorageOcId:ocId], etag, [NCGlobal shared].extensionPreview];
|
|
|
-}
|
|
|
-
|
|
|
-+ (BOOL)fileProviderStorageExists:(tableMetadata *)metadata
|
|
|
-{
|
|
|
- NSString *fileNameViewPath = [self getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView];
|
|
|
- NSString *fileNamePath = [self getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileName];
|
|
|
-
|
|
|
- unsigned long long fileNameViewSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileNameViewPath error:nil] fileSize];
|
|
|
- unsigned long long fileNameSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileNamePath error:nil] fileSize];
|
|
|
-
|
|
|
- if (metadata.isDirectoryE2EE == true) {
|
|
|
- if ((fileNameSize == metadata.size || fileNameViewSize == metadata.size) && fileNameViewSize > 0) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- } else {
|
|
|
- return fileNameViewSize == metadata.size;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-+ (int64_t)fileProviderStorageSize:(NSString *)ocId fileNameView:(NSString *)fileNameView
|
|
|
-{
|
|
|
- NSString *fileNamePath = [self getDirectoryProviderStorageOcId:ocId fileNameView:fileNameView];
|
|
|
-
|
|
|
- int64_t fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileNamePath error:nil] fileSize];
|
|
|
-
|
|
|
- return fileSize;
|
|
|
-}
|
|
|
-
|
|
|
-+ (BOOL)fileProviderStoragePreviewIconExists:(NSString *)ocId etag:(NSString *)etag
|
|
|
-{
|
|
|
- NSString *fileNamePathPreview = [self getDirectoryProviderStoragePreviewOcId:ocId etag:etag];
|
|
|
- NSString *fileNamePathIcon = [self getDirectoryProviderStorageIconOcId:ocId etag:etag];
|
|
|
-
|
|
|
- unsigned long long fileSizePreview = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileNamePathPreview error:nil] fileSize];
|
|
|
- unsigned long long fileSizeIcon = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileNamePathIcon error:nil] fileSize];
|
|
|
-
|
|
|
- if (fileSizePreview > 0 && fileSizeIcon > 0) return true;
|
|
|
- else return false;
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)removeGroupApplicationSupport
|
|
|
-{
|
|
|
- NSURL *dirGroup = [CCUtility getDirectoryGroup];
|
|
|
- NSString *path = [[dirGroup URLByAppendingPathComponent:NCGlobal.shared.appApplicationSupport] path];
|
|
|
-
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)removeGroupLibraryDirectory
|
|
|
-{
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryScan] error:nil];
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryUserData] error:nil];
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)removeGroupDirectoryProviderStorage
|
|
|
-{
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorage] error:nil];
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)removeDocumentsDirectory
|
|
|
-{
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryDocuments] error:nil];
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)removeTemporaryDirectory
|
|
|
-{
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:NSTemporaryDirectory() error:nil];
|
|
|
-}
|
|
|
-
|
|
|
-+ (void)emptyTemporaryDirectory
|
|
|
-{
|
|
|
- NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
|
|
|
- for (NSString *file in tmpDirectory) {
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
+ (NSString *)getTitleSectionDate:(NSDate *)date
|
|
|
{
|
|
|
NSString *title;
|
|
@@ -570,15 +330,6 @@
|
|
|
return returnFileUTI;
|
|
|
}
|
|
|
|
|
|
-+ (NSString *)getDirectoryScan
|
|
|
-{
|
|
|
- NSString *path = [[[CCUtility getDirectoryGroup] URLByAppendingPathComponent:NCGlobal.shared.appScan] path];
|
|
|
-
|
|
|
- if (![[NSFileManager defaultManager] fileExistsAtPath:path])
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
-
|
|
|
- return path;
|
|
|
-}
|
|
|
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
#pragma mark ===== Share Permissions =====
|