CCAdvanced.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. // Color
  104. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  105. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  106. [self recalculateSize];
  107. }
  108. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  109. {
  110. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  111. if ([rowDescriptor.tag isEqualToString:@"activityVerboseHigh"]) {
  112. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  113. [CCUtility setActivityVerboseHigh:true];
  114. } else {
  115. [CCUtility setActivityVerboseHigh:false];
  116. }
  117. // Clear Date read Activity for force reload datasource
  118. app.activeActivity.storeDateFirstActivity = nil;
  119. }
  120. if ([rowDescriptor.tag isEqualToString:@"optimizedphoto"]) {
  121. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  122. [CCUtility setOptimizedPhoto:YES];
  123. } else {
  124. [CCUtility setOptimizedPhoto:NO];
  125. }
  126. }
  127. if ([rowDescriptor.tag isEqualToString:@"uploadremovephoto"]) {
  128. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  129. [CCUtility setUploadAndRemovePhoto:YES];
  130. } else {
  131. [CCUtility setUploadAndRemovePhoto:NO];
  132. }
  133. }
  134. }
  135. #pragma --------------------------------------------------------------------------------------------
  136. #pragma mark === Mail ===
  137. #pragma --------------------------------------------------------------------------------------------
  138. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  139. {
  140. switch (result)
  141. {
  142. case MFMailComposeResultCancelled:
  143. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  144. break;
  145. case MFMailComposeResultSaved:
  146. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  147. break;
  148. case MFMailComposeResultSent:
  149. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  150. break;
  151. case MFMailComposeResultFailed: {
  152. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  153. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  154. }
  155. break;
  156. default:
  157. break;
  158. }
  159. // Close the Mail Interface
  160. [self dismissViewControllerAnimated:YES completion:NULL];
  161. }
  162. - (void)sendMail:(XLFormRowDescriptor *)sender
  163. {
  164. [self deselectFormRow:sender];
  165. // Email Subject
  166. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  167. // Email Content
  168. NSString *messageBody;
  169. // File Attachment
  170. NSString *fileAttachment = @"";
  171. // Email Recipents
  172. NSArray *toRecipents;
  173. NSArray *activities = [CCCoreData getAllTableActivityWithPredicate:[NSPredicate predicateWithFormat:@"((account == %@) || (account == ''))", app.activeAccount]];
  174. if ([activities count] == 0) {
  175. [app messageNotification:@"_info_" description:@"No activity found" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  176. return;
  177. }
  178. for (TableActivity *activity in activities) {
  179. NSString *date, *type, *actionFile, *note;
  180. date = [[NSDateFormatter localizedStringFromDate:activity.date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterMediumStyle] stringByPaddingToLength:22 withString:@" " startingAtIndex:0];
  181. if ([activity.type isEqual: k_activityTypeInfo]) type = @"Info ";
  182. if ([activity.type isEqual: k_activityTypeSuccess]) type = @"Success";
  183. if ([activity.type isEqual: k_activityTypeFailure]) type = @"Failure";
  184. actionFile = [[NSString stringWithFormat:@"%@ %@", activity.action, activity.file] stringByPaddingToLength:100 withString:@" " startingAtIndex:0];
  185. if (activity.idActivity == 0) note = [NSString stringWithFormat:@"%@ Selector: %@", activity.note, activity.selector];
  186. else note = activity.note;
  187. note = [note stringByPaddingToLength:200 withString:@" " startingAtIndex:0];
  188. fileAttachment = [fileAttachment stringByAppendingString:[NSString stringWithFormat:@"| %@ | %@ | %@ | %@ |\n", date, type, actionFile, note]];
  189. }
  190. messageBody = [NSString stringWithFormat:@"\n\n\n%@ Version %@ (%@)", k_brand,[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  191. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  192. NSString *documentsDirectory = [paths objectAtIndex:0];
  193. NSError *error;
  194. if ([fileAttachment writeToFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"] atomically:YES encoding:NSUTF8StringEncoding error:&error]) {
  195. toRecipents = [NSArray arrayWithObject:k_mailMe];
  196. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  197. mc.mailComposeDelegate = self;
  198. [mc setSubject:emailTitle];
  199. [mc setMessageBody:messageBody isHTML:NO];
  200. [mc setToRecipients:toRecipents];
  201. NSData *noteData = [NSData dataWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"]];
  202. [mc addAttachmentData:noteData mimeType:@"text/plain" fileName:@"activity.txt"];
  203. // Present mail view controller on screen
  204. [self presentViewController:mc animated:YES completion:NULL];
  205. } else {
  206. [app messageNotification:@"_error_" description:@"Impossible create file body" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  207. }
  208. }
  209. #pragma --------------------------------------------------------------------------------------------
  210. #pragma mark === Clear Activity ===
  211. #pragma --------------------------------------------------------------------------------------------
  212. - (void)clearActivity:(XLFormRowDescriptor *)sender
  213. {
  214. [self deselectFormRow:sender];
  215. [CCCoreData flushTableActivityAccount:app.activeAccount];
  216. [app.activeActivity reloadDatasource];
  217. }
  218. #pragma --------------------------------------------------------------------------------------------
  219. #pragma mark === Clear Cache ===
  220. #pragma --------------------------------------------------------------------------------------------
  221. - (void)clearCache:(XLFormRowDescriptor *)sender
  222. {
  223. [self deselectFormRow:sender];
  224. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  225. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  226. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  227. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  228. [app cancelAllOperations];
  229. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  230. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  231. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  232. [CCCoreData flushTableAutomaticUploadAccount:app.activeAccount selector:nil];
  233. [CCCoreData flushTableDirectoryAccount:app.activeAccount];
  234. [CCCoreData flushTableLocalFileAccount:app.activeAccount];
  235. [CCCoreData flushTableMetadataAccount:app.activeAccount];
  236. [CCCoreData flushTableActivityAccount:app.activeAccount];
  237. [self emptyUserDirectoryUser:app.activeUser url:app.activeUrl];
  238. [self emptyLocalDirectory];
  239. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  240. for (NSString *file in tmpDirectory)
  241. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  242. [self recalculateSize];
  243. // Inizialized home
  244. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  245. [self.hud hideHud];
  246. });
  247. }]];
  248. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  249. }]];
  250. //if iPhone
  251. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  252. [self presentViewController:alertController animated:YES completion:nil];
  253. }
  254. //if iPad
  255. else {
  256. // Change Rect to position Popover
  257. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  258. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  259. }
  260. }
  261. - (void)recalculateSize
  262. {
  263. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  264. self.form.delegate = nil;
  265. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  266. NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  267. rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  268. //rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  269. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  270. self.form.delegate = self;
  271. });
  272. }
  273. #pragma --------------------------------------------------------------------------------------------
  274. #pragma mark == Exit Nextcloud ==
  275. #pragma --------------------------------------------------------------------------------------------
  276. - (void)exitNextcloud:(XLFormRowDescriptor *)sender
  277. {
  278. [self deselectFormRow:sender];
  279. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:[CCUtility localizableBrand:@"_want_exit_" table:nil] preferredStyle:UIAlertControllerStyleActionSheet];
  280. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  281. [self.hud visibleIndeterminateHud];
  282. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  283. [app cancelAllOperations];
  284. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  285. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  286. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  287. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  288. [CCCoreData flushAllDatabase];
  289. [CCUtility deleteAllChainStore];
  290. [self emptyDocumentsDirectory];
  291. [self emptyLibraryDirectory];
  292. [self emptyGroupApplicationSupport];
  293. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  294. for (NSString *file in tmpDirectory)
  295. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  296. [self.hud hideHud];
  297. exit(0);
  298. });
  299. }]];
  300. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  301. }]];
  302. //if iPhone
  303. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  304. [self presentViewController:alertController animated:YES completion:nil];
  305. }
  306. //if iPad
  307. else {
  308. // Change Rect to position Popover
  309. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  310. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  311. }
  312. }
  313. #pragma --------------------------------------------------------------------------------------------
  314. #pragma mark == Utility ==
  315. #pragma --------------------------------------------------------------------------------------------
  316. - (void)emptyGroupApplicationSupport
  317. {
  318. NSString *file;
  319. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  320. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  321. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  322. while (file = [enumerator nextObject])
  323. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  324. }
  325. - (void)emptyLibraryDirectory
  326. {
  327. NSString *file;
  328. NSString *dirIniziale;
  329. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  330. dirIniziale = [paths objectAtIndex:0];
  331. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  332. while (file = [enumerator nextObject])
  333. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  334. }
  335. - (void)emptyDocumentsDirectory
  336. {
  337. NSString *file;
  338. NSString *dirIniziale;
  339. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  340. dirIniziale = [paths objectAtIndex:0];
  341. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  342. while (file = [enumerator nextObject])
  343. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  344. }
  345. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url
  346. {
  347. NSString *file;
  348. NSString *dirIniziale;
  349. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  350. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  351. while (file = [enumerator nextObject]) {
  352. NSString *ext = [[file pathExtension] lowercaseString];
  353. // Do not remove ICO
  354. if ([ext isEqualToString:@"ico"])
  355. continue;
  356. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  357. }
  358. }
  359. - (void)emptyLocalDirectory
  360. {
  361. NSString *file;
  362. NSString *dirIniziale;
  363. dirIniziale = [CCUtility getDirectoryLocal];
  364. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  365. while (file = [enumerator nextObject])
  366. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  367. }
  368. - (NSNumber *)getUserDirectorySize
  369. {
  370. NSString *directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  371. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  372. unsigned long long count = 0;
  373. NSNumber *value = nil;
  374. if (! directoryURL) return 0;
  375. // Get dimension Document
  376. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  377. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  378. count += [value longLongValue];
  379. } else {
  380. return nil;
  381. }
  382. }
  383. return @(count);
  384. }
  385. @end