CCAdvanced.m 24 KB

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