CCAdvanced.m 23 KB

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