CCAdvanced.m 23 KB

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