CCAdvanced.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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.tableView.backgroundColor = [NCBrandColor 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)changeTheming
  116. {
  117. if (self.isViewLoaded && self.view.window)
  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 errorCode: error.code];
  156. break;
  157. case MFMailComposeResultSaved:
  158. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  159. break;
  160. case MFMailComposeResultSent:
  161. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  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 errorCode: error.code];
  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 errorCode:0];
  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. // fix CCAdvanced.m line 276 2.17.2 (00005)
  207. if ([fileAttachment writeToFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"] atomically:YES encoding:NSUTF8StringEncoding error:&error] && [MFMailComposeViewController canSendMail]) {
  208. toRecipents = [NSArray arrayWithObject:k_mailMe];
  209. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  210. mc.mailComposeDelegate = self;
  211. [mc setSubject:emailTitle];
  212. [mc setMessageBody:messageBody isHTML:NO];
  213. [mc setToRecipients:toRecipents];
  214. NSData *noteData = [NSData dataWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"]];
  215. [mc addAttachmentData:noteData mimeType:@"text/plain" fileName:@"activity.txt"];
  216. // Present mail view controller on screen
  217. [self presentViewController:mc animated:YES completion:NULL];
  218. } else {
  219. [app messageNotification:@"_error_" description:@"Impossible create file body" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  220. }
  221. }
  222. #pragma --------------------------------------------------------------------------------------------
  223. #pragma mark === Clear Activity ===
  224. #pragma --------------------------------------------------------------------------------------------
  225. - (void)clearActivity:(XLFormRowDescriptor *)sender
  226. {
  227. [self deselectFormRow:sender];
  228. [CCCoreData flushTableActivityAccount:app.activeAccount];
  229. [app.activeActivity reloadDatasource];
  230. }
  231. #pragma --------------------------------------------------------------------------------------------
  232. #pragma mark === Clear Cache ===
  233. #pragma --------------------------------------------------------------------------------------------
  234. - (void)clearCache:(XLFormRowDescriptor *)sender
  235. {
  236. [self deselectFormRow:sender];
  237. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  238. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  239. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  240. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  241. [app cancelAllOperations];
  242. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  243. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  244. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  245. [CCCoreData flushTableActivityAccount:app.activeAccount];
  246. [CCCoreData flushTableAutomaticUploadAccount:app.activeAccount selector:nil];
  247. [CCCoreData flushTableCapabilitiesAccount:app.activeAccount];
  248. [CCCoreData flushTableDirectoryAccount:app.activeAccount];
  249. [CCCoreData flushTableExternalSitesAccount:app.activeAccount];
  250. [CCCoreData flushTableGPS];
  251. [CCCoreData flushTableLocalFileAccount:app.activeAccount];
  252. [CCCoreData flushTableMetadataAccount:app.activeAccount];
  253. [CCCoreData flushTableShareAccount:app.activeAccount];
  254. [self emptyUserDirectoryUser:app.activeUser url:app.activeUrl];
  255. [self emptyLocalDirectory];
  256. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  257. for (NSString *file in tmpDirectory)
  258. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  259. [self recalculateSize];
  260. // Inizialized home
  261. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  262. [self.hud hideHud];
  263. });
  264. }]];
  265. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  266. }]];
  267. //if iPhone
  268. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  269. [self presentViewController:alertController animated:YES completion:nil];
  270. }
  271. //if iPad
  272. else {
  273. // Change Rect to position Popover
  274. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  275. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  276. }
  277. }
  278. - (void)recalculateSize
  279. {
  280. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  281. self.form.delegate = nil;
  282. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  283. NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  284. rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  285. //rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  286. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  287. self.form.delegate = self;
  288. });
  289. }
  290. #pragma --------------------------------------------------------------------------------------------
  291. #pragma mark == Exit Nextcloud ==
  292. #pragma --------------------------------------------------------------------------------------------
  293. - (void)exitNextcloud:(XLFormRowDescriptor *)sender
  294. {
  295. [self deselectFormRow:sender];
  296. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:[CCUtility localizableBrand:@"_want_exit_" table:nil] preferredStyle:UIAlertControllerStyleActionSheet];
  297. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  298. [self.hud visibleIndeterminateHud];
  299. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  300. [app cancelAllOperations];
  301. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  302. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  303. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  304. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  305. [CCCoreData flushAllDatabase];
  306. [CCUtility deleteAllChainStore];
  307. [self emptyDocumentsDirectory];
  308. [self emptyLibraryDirectory];
  309. [self emptyGroupApplicationSupport];
  310. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  311. for (NSString *file in tmpDirectory)
  312. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  313. [self.hud hideHud];
  314. exit(0);
  315. });
  316. }]];
  317. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  318. }]];
  319. //if iPhone
  320. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  321. [self presentViewController:alertController animated:YES completion:nil];
  322. }
  323. //if iPad
  324. else {
  325. // Change Rect to position Popover
  326. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  327. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:sender]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  328. }
  329. }
  330. #pragma --------------------------------------------------------------------------------------------
  331. #pragma mark == Utility ==
  332. #pragma --------------------------------------------------------------------------------------------
  333. - (void)emptyGroupApplicationSupport
  334. {
  335. NSString *file;
  336. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  337. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  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)emptyLibraryDirectory
  343. {
  344. NSString *file;
  345. NSString *dirIniziale;
  346. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, 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)emptyDocumentsDirectory
  353. {
  354. NSString *file;
  355. NSString *dirIniziale;
  356. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  357. dirIniziale = [paths objectAtIndex:0];
  358. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  359. while (file = [enumerator nextObject])
  360. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  361. }
  362. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url
  363. {
  364. NSString *file;
  365. NSString *dirIniziale;
  366. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  367. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  368. while (file = [enumerator nextObject]) {
  369. NSString *ext = [[file pathExtension] lowercaseString];
  370. // Do not remove ICO
  371. if ([ext isEqualToString:@"ico"])
  372. continue;
  373. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  374. }
  375. }
  376. - (void)emptyLocalDirectory
  377. {
  378. NSString *file;
  379. NSString *dirIniziale;
  380. dirIniziale = [CCUtility getDirectoryLocal];
  381. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  382. while (file = [enumerator nextObject])
  383. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  384. }
  385. - (NSNumber *)getUserDirectorySize
  386. {
  387. NSString *directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  388. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  389. unsigned long long count = 0;
  390. NSNumber *value = nil;
  391. if (! directoryURL) return 0;
  392. // Get dimension Document
  393. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  394. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  395. count += [value longLongValue];
  396. } else {
  397. return nil;
  398. }
  399. }
  400. return @(count);
  401. }
  402. @end