CCAdvanced.m 23 KB

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