CCAdvanced.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. //
  2. // CCManageHelp.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 06/11/15.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCAdvanced.h"
  24. #import "CCUtility.h"
  25. #import "AppDelegate.h"
  26. @interface CCAdvanced ()
  27. @end
  28. @implementation CCAdvanced
  29. -(id)init
  30. {
  31. XLFormDescriptor *form ;
  32. XLFormSectionDescriptor *section;
  33. XLFormRowDescriptor *row;
  34. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_advanced_", nil)];
  35. // Section ACTIVITY -------------------------------------------------
  36. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_activity_", nil)];
  37. [form addFormSection:section];
  38. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"activityVerboseHigh" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_help_activity_verbose_", nil)];
  39. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  40. [row.cellConfig setObject:[UIImage imageNamed:image_settingsActivityHigh] forKey:@"imageView.image"];
  41. if ([CCUtility getActivityVerboseHigh]) row.value = @"1";
  42. else row.value = @"0";
  43. [section addFormRow:row];
  44. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendMailActivity" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_activity_mail_", nil)];
  45. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  46. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  47. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  48. [row.cellConfig setObject:[UIImage imageNamed:image_settingsSendActivity] forKey:@"imageView.image"];
  49. row.action.formSelector = @selector(sendMail:);
  50. [section addFormRow:row];
  51. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"clearActivityLog" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_activity_clear_", nil)];
  52. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  53. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  54. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  55. [row.cellConfig setObject:[UIImage imageNamed:image_settingsClearActivity] forKey:@"imageView.image"];
  56. row.action.formSelector = @selector(clearActivity:);
  57. [section addFormRow:row];
  58. // Section OTTIMIZATIONS -------------------------------------------------
  59. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_optimized_photos_", nil)];
  60. [form addFormSection:section];
  61. section.footerTitle = NSLocalizedString(@"_optimized_photos_how_", nil);
  62. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"optimizedphoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_optimized_photos_", nil)];
  63. if ([CCUtility getOptimizedPhoto]) row.value = @"1";
  64. else row.value = @"0";
  65. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  66. [section addFormRow:row];
  67. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_upload_del_photos_", nil)];
  68. [form addFormSection:section];
  69. section.footerTitle = [CCUtility localizableBrand:@"_upload_del_photos_how_" table:nil];
  70. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"uploadremovephoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_upload_del_photos_", nil)];
  71. if ([CCUtility getUploadAndRemovePhoto]) row.value = @"1";
  72. else row.value = @"0";
  73. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  74. [section addFormRow:row];
  75. // Section CLEAR CACHE -------------------------------------------------
  76. section = [XLFormSectionDescriptor formSection];
  77. [form addFormSection:section];
  78. // Clear cache
  79. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_cache_no_size_", nil)];
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  81. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  82. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  83. [row.cellConfig setObject:[UIImage imageNamed:image_settingsClearCache] forKey:@"imageView.image"];
  84. row.action.formSelector = @selector(clearCache:);
  85. [section addFormRow:row];
  86. // Section EXIT --------------------------------------------------------
  87. section = [XLFormSectionDescriptor formSection];
  88. [form addFormSection:section];
  89. // Exit
  90. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:[CCUtility localizableBrand:@"_exit_" table:nil]];
  91. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  92. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  93. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  94. [row.cellConfig setObject:[UIImage imageNamed:image_settingsExit] forKey:@"imageView.image"];
  95. row.action.formSelector = @selector(exitNextcloud:);
  96. [section addFormRow:row];
  97. return [super initWithForm:form];
  98. }
  99. // Apparirà
  100. - (void)viewWillAppear:(BOOL)animated
  101. {
  102. [super viewWillAppear:animated];
  103. self.tableView.backgroundColor = [UIColor whiteColor];
  104. // Color
  105. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  106. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  107. [self recalculateSize];
  108. }
  109. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  110. {
  111. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  112. if ([rowDescriptor.tag isEqualToString:@"activityVerboseHigh"]) {
  113. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  114. [CCUtility setActivityVerboseHigh:true];
  115. } else {
  116. [CCUtility setActivityVerboseHigh:false];
  117. }
  118. // Clear Date read Activity for force reload datasource
  119. app.activeActivity.storeDateFirstActivity = nil;
  120. }
  121. if ([rowDescriptor.tag isEqualToString:@"optimizedphoto"]) {
  122. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  123. [CCUtility setOptimizedPhoto:YES];
  124. } else {
  125. [CCUtility setOptimizedPhoto:NO];
  126. }
  127. }
  128. if ([rowDescriptor.tag isEqualToString:@"uploadremovephoto"]) {
  129. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  130. [CCUtility setUploadAndRemovePhoto:YES];
  131. } else {
  132. [CCUtility setUploadAndRemovePhoto:NO];
  133. }
  134. }
  135. }
  136. #pragma --------------------------------------------------------------------------------------------
  137. #pragma mark === Mail ===
  138. #pragma --------------------------------------------------------------------------------------------
  139. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  140. {
  141. switch (result)
  142. {
  143. case MFMailComposeResultCancelled:
  144. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  145. break;
  146. case MFMailComposeResultSaved:
  147. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  148. break;
  149. case MFMailComposeResultSent:
  150. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  151. break;
  152. case MFMailComposeResultFailed: {
  153. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  154. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  155. }
  156. break;
  157. default:
  158. break;
  159. }
  160. // Close the Mail Interface
  161. [self dismissViewControllerAnimated:YES completion:NULL];
  162. }
  163. - (void)sendMail:(XLFormRowDescriptor *)sender
  164. {
  165. [self deselectFormRow:sender];
  166. // Email Subject
  167. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  168. // Email Content
  169. NSString *messageBody;
  170. // File Attachment
  171. NSString *fileAttachment = @"";
  172. // Email Recipents
  173. NSArray *toRecipents;
  174. NSArray *activities = [CCCoreData getAllTableActivityWithPredicate:[NSPredicate predicateWithFormat:@"((account == %@) || (account == ''))", app.activeAccount]];
  175. if ([activities count] == 0) {
  176. [app messageNotification:@"_info_" description:@"No activity found" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  177. return;
  178. }
  179. for (TableActivity *activity in activities) {
  180. NSString *date, *type, *actionFile, *note;
  181. date = [[NSDateFormatter localizedStringFromDate:activity.date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterMediumStyle] stringByPaddingToLength:22 withString:@" " startingAtIndex:0];
  182. if ([activity.type isEqual: k_activityTypeInfo]) type = @"Info ";
  183. if ([activity.type isEqual: k_activityTypeSuccess]) type = @"Success";
  184. if ([activity.type isEqual: k_activityTypeFailure]) type = @"Failure";
  185. actionFile = [[NSString stringWithFormat:@"%@ %@", activity.action, activity.file] stringByPaddingToLength:100 withString:@" " startingAtIndex:0];
  186. if (activity.idActivity == 0) note = [NSString stringWithFormat:@"%@ Selector: %@", activity.note, activity.selector];
  187. else note = activity.note;
  188. note = [note stringByPaddingToLength:200 withString:@" " startingAtIndex:0];
  189. fileAttachment = [fileAttachment stringByAppendingString:[NSString stringWithFormat:@"| %@ | %@ | %@ | %@ |\n", date, type, actionFile, note]];
  190. }
  191. messageBody = [NSString stringWithFormat:@"\n\n\n%@ Version %@ (%@)", k_brand,[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  192. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  193. NSString *documentsDirectory = [paths objectAtIndex:0];
  194. NSError *error;
  195. if ([fileAttachment writeToFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"] atomically:YES encoding:NSUTF8StringEncoding error:&error]) {
  196. toRecipents = [NSArray arrayWithObject:k_mailMe];
  197. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  198. mc.mailComposeDelegate = self;
  199. [mc setSubject:emailTitle];
  200. [mc setMessageBody:messageBody isHTML:NO];
  201. [mc setToRecipients:toRecipents];
  202. NSData *noteData = [NSData dataWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"]];
  203. [mc addAttachmentData:noteData mimeType:@"text/plain" fileName:@"activity.txt"];
  204. // Present mail view controller on screen
  205. [self presentViewController:mc animated:YES completion:NULL];
  206. } else {
  207. [app messageNotification:@"_error_" description:@"Impossible create file body" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  208. }
  209. }
  210. #pragma --------------------------------------------------------------------------------------------
  211. #pragma mark === Clear Activity ===
  212. #pragma --------------------------------------------------------------------------------------------
  213. - (void)clearActivity:(XLFormRowDescriptor *)sender
  214. {
  215. [self deselectFormRow:sender];
  216. [CCCoreData flushTableActivityAccount:app.activeAccount];
  217. [app.activeActivity reloadDatasource];
  218. }
  219. #pragma --------------------------------------------------------------------------------------------
  220. #pragma mark === Clear Cache ===
  221. #pragma --------------------------------------------------------------------------------------------
  222. - (void)clearCache:(XLFormRowDescriptor *)sender
  223. {
  224. [self deselectFormRow:sender];
  225. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  226. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  227. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  228. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  229. [app cancelAllOperations];
  230. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  231. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  232. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  233. [CCCoreData flushTableAutomaticUploadAccount:app.activeAccount selector:nil];
  234. [CCCoreData flushTableDirectoryAccount:app.activeAccount];
  235. [CCCoreData flushTableLocalFileAccount:app.activeAccount];
  236. [CCCoreData flushTableMetadataAccount:app.activeAccount];
  237. [CCCoreData flushTableActivityAccount:app.activeAccount];
  238. [self emptyUserDirectoryUser:app.activeUser url:app.activeUrl];
  239. [self emptyLocalDirectory];
  240. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  241. for (NSString *file in tmpDirectory)
  242. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  243. [self recalculateSize];
  244. // Inizialized home
  245. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  246. [self.hud hideHud];
  247. });
  248. }]];
  249. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  250. }]];
  251. //if iPhone
  252. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  253. [self presentViewController:alertController animated:YES completion:nil];
  254. }
  255. //if iPad
  256. else {
  257. // Change Rect to position Popover
  258. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  259. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  260. }
  261. }
  262. - (void)recalculateSize
  263. {
  264. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  265. self.form.delegate = nil;
  266. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  267. NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  268. rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  269. //rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  270. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  271. self.form.delegate = self;
  272. });
  273. }
  274. #pragma --------------------------------------------------------------------------------------------
  275. #pragma mark == Exit Nextcloud ==
  276. #pragma --------------------------------------------------------------------------------------------
  277. - (void)exitNextcloud:(XLFormRowDescriptor *)sender
  278. {
  279. [self deselectFormRow:sender];
  280. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:[CCUtility localizableBrand:@"_want_exit_" table:nil] preferredStyle:UIAlertControllerStyleActionSheet];
  281. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  282. [self.hud visibleIndeterminateHud];
  283. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  284. [app cancelAllOperations];
  285. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  286. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  287. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  288. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  289. [CCCoreData flushAllDatabase];
  290. [CCUtility deleteAllChainStore];
  291. [self emptyDocumentsDirectory];
  292. [self emptyLibraryDirectory];
  293. [self emptyGroupApplicationSupport];
  294. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  295. for (NSString *file in tmpDirectory)
  296. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  297. [self.hud hideHud];
  298. exit(0);
  299. });
  300. }]];
  301. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  302. }]];
  303. //if iPhone
  304. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  305. [self presentViewController:alertController animated:YES completion:nil];
  306. }
  307. //if iPad
  308. else {
  309. // Change Rect to position Popover
  310. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  311. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  312. }
  313. }
  314. #pragma --------------------------------------------------------------------------------------------
  315. #pragma mark == Utility ==
  316. #pragma --------------------------------------------------------------------------------------------
  317. - (void)emptyGroupApplicationSupport
  318. {
  319. NSString *file;
  320. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  321. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  322. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  323. while (file = [enumerator nextObject])
  324. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  325. }
  326. - (void)emptyLibraryDirectory
  327. {
  328. NSString *file;
  329. NSString *dirIniziale;
  330. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  331. dirIniziale = [paths objectAtIndex:0];
  332. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  333. while (file = [enumerator nextObject])
  334. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  335. }
  336. - (void)emptyDocumentsDirectory
  337. {
  338. NSString *file;
  339. NSString *dirIniziale;
  340. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  341. dirIniziale = [paths objectAtIndex:0];
  342. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  343. while (file = [enumerator nextObject])
  344. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  345. }
  346. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url
  347. {
  348. NSString *file;
  349. NSString *dirIniziale;
  350. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  351. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  352. while (file = [enumerator nextObject]) {
  353. NSString *ext = [[file pathExtension] lowercaseString];
  354. // Do not remove ICO
  355. if ([ext isEqualToString:@"ico"])
  356. continue;
  357. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  358. }
  359. }
  360. - (void)emptyLocalDirectory
  361. {
  362. NSString *file;
  363. NSString *dirIniziale;
  364. dirIniziale = [CCUtility getDirectoryLocal];
  365. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  366. while (file = [enumerator nextObject])
  367. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  368. }
  369. - (NSNumber *)getUserDirectorySize
  370. {
  371. NSString *directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  372. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  373. unsigned long long count = 0;
  374. NSNumber *value = nil;
  375. if (! directoryURL) return 0;
  376. // Get dimension Document
  377. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  378. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  379. count += [value longLongValue];
  380. } else {
  381. return nil;
  382. }
  383. }
  384. return @(count);
  385. }
  386. @end