CCAdvanced.m 26 KB

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