CCAdvanced.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. //
  2. // CCManageHelp.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 06/11/15.
  6. // Copyright (c) 2015 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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 "NSNotificationCenter+MainThread.h"
  26. #import "NCBridgeSwift.h"
  27. @interface CCAdvanced ()
  28. {
  29. AppDelegate *appDelegate;
  30. XLFormSectionDescriptor *sectionSize;
  31. }
  32. @end
  33. @implementation CCAdvanced
  34. - (void)initializeForm
  35. {
  36. XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
  37. XLFormSectionDescriptor *section;
  38. XLFormRowDescriptor *row;
  39. // Section HIDDEN FILES -------------------------------------------------
  40. section = [XLFormSectionDescriptor formSection];
  41. [form addFormSection:section];
  42. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"showHiddenFiles" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_show_hidden_files_", nil)];
  43. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  44. if ([CCUtility getShowHiddenFiles]) row.value = @"1";
  45. else row.value = @"0";
  46. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  47. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  48. [section addFormRow:row];
  49. // Format Compatibility + Live Photo + Delete asset
  50. section = [XLFormSectionDescriptor formSection];
  51. [form addFormSection:section];
  52. section.footerTitle = [NSString stringWithFormat:@"%@\n%@\n%@", NSLocalizedString(@"_format_compatibility_footer_", nil), NSLocalizedString(@"_upload_mov_livephoto_footer_", nil), NSLocalizedString(@"_remove_photo_CameraRoll_desc_", nil)];
  53. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"formatCompatibility" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_format_compatibility_", nil)];
  54. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  55. if ([CCUtility getFormatCompatibility]) row.value = @"1";
  56. else row.value = @"0";
  57. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  58. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  59. [section addFormRow:row];
  60. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"livePhoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_upload_mov_livephoto_", nil)];
  61. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  62. if ([CCUtility getLivePhoto]) row.value = @"1";
  63. else row.value = @"0";
  64. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  65. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  66. [section addFormRow:row];
  67. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"removePhotoCameraRoll" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_remove_photo_CameraRoll_", nil)];
  68. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  69. if ([CCUtility getRemovePhotoCameraRoll]) row.value = @"1";
  70. else row.value = @0;
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  72. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  73. [section addFormRow:row];
  74. // Section : Files App --------------------------------------------------------------
  75. if (![NCBrandOptions shared].disable_openin_file) {
  76. section = [XLFormSectionDescriptor formSection];
  77. [form addFormSection:section];
  78. section.footerTitle = NSLocalizedString(@"_disable_files_app_footer_", nil);
  79. // Disable Files App
  80. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"disablefilesapp" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_disable_files_app_", nil)];
  81. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  82. if ([CCUtility getDisableFilesApp]) row.value = @"1";
  83. else row.value = @"0";
  84. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  85. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  86. [section addFormRow:row];
  87. }
  88. // Section : Privacy --------------------------------------------------------------
  89. if (!NCBrandOptions.shared.disable_crash_service) {
  90. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_privacy_", nil)];
  91. [form addFormSection:section];
  92. section.footerTitle = NSLocalizedString(@"_privacy_footer_", nil);
  93. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"crashservice" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_crashservice_title_", nil)];
  94. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  95. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  96. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  97. [row.cellConfig setObject:[[UIImage imageNamed:@"crashservice"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  98. if ([CCUtility getDisableCrashservice]) row.value = @"1";
  99. else row.value = @"0";
  100. [section addFormRow:row];
  101. }
  102. // Section DIAGNOSTICS -------------------------------------------------
  103. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_diagnostics_", nil)];
  104. [form addFormSection:section];
  105. if ([[NSFileManager defaultManager] fileExistsAtPath:NextcloudKit.shared.nkCommonInstance.filenamePathLog] && NCBrandOptions.shared.disable_log == false) {
  106. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"log" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_view_log_", nil)];
  107. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  108. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  109. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  110. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  111. [row.cellConfig setObject:[[UIImage imageNamed:@"log"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  112. row.action.formBlock = ^(XLFormRowDescriptor * sender) {
  113. [self deselectFormRow:sender];
  114. NCViewerQuickLook *viewerQuickLook = [[NCViewerQuickLook alloc] initWith:[NSURL fileURLWithPath:NextcloudKit.shared.nkCommonInstance.filenamePathLog] isEditingEnabled:false metadata:nil];
  115. [self presentViewController:viewerQuickLook animated:YES completion:nil];
  116. };
  117. [section addFormRow:row];
  118. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"clearlog" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_log_", nil)];
  119. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  120. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  121. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  122. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  123. [row.cellConfig setObject:[[UIImage imageNamed:@"clear"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  124. row.action.formBlock = ^(XLFormRowDescriptor * sender) {
  125. [self deselectFormRow:sender];
  126. [[[NextcloudKit shared] nkCommonInstance] clearFileLog];
  127. NSInteger logLevel = [CCUtility getLogLevel];
  128. BOOL isSimulatorOrTestFlight = [[NCUtility shared] isSimulatorOrTestFlight];
  129. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions shared].textCopyrightNextcloudiOS, [[NCUtility shared] getVersionAppWithBuild:true]];
  130. if (isSimulatorOrTestFlight) {
  131. [[[NextcloudKit shared] nkCommonInstance] writeLog:[NSString stringWithFormat:@"[INFO] Clear log with level %lu %@ (Simulator / TestFlight)", (unsigned long)logLevel, versionNextcloudiOS]];
  132. } else {
  133. [[[NextcloudKit shared] nkCommonInstance] writeLog:[NSString stringWithFormat:@"[INFO] Clear log with level %lu %@", (unsigned long)logLevel, versionNextcloudiOS]];
  134. }
  135. [[NCMediaCache shared] createCacheWithAccount:appDelegate.account];
  136. };
  137. [section addFormRow:row];
  138. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"logLevel" rowType:XLFormRowDescriptorTypeSlider title:NSLocalizedString(@"_level_log_", nil)];
  139. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  140. [row.cellConfig setObject:@(NSTextAlignmentCenter) forKey:@"textLabel.textAlignment"];
  141. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  142. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  143. NSInteger logLevel = [CCUtility getLogLevel];
  144. row.value = @(logLevel);
  145. [row.cellConfigAtConfigure setObject:@(2) forKey:@"slider.maximumValue"];
  146. [row.cellConfigAtConfigure setObject:@(0) forKey:@"slider.minimumValue"];
  147. [row.cellConfigAtConfigure setObject:@(2) forKey:@"steps"];
  148. [section addFormRow:row];
  149. }
  150. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"capabilities" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_capabilities_", nil)];
  151. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  152. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  153. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  154. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  155. [row.cellConfig setObject:[[UIImage imageNamed:@"capabilities"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  156. row.action.formBlock = ^(XLFormRowDescriptor * sender) {
  157. [self deselectFormRow:sender];
  158. UIViewController *vc = [[NCHostingCapabilitiesView alloc] makeShipDetailsUI];
  159. [self.navigationController pushViewController:vc animated:YES];
  160. };
  161. [section addFormRow:row];
  162. // Section : Delete files / Clear cache --------------------------------------------------------------
  163. sectionSize = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_delete_files_desc_", nil)];
  164. [form addFormSection:sectionSize];
  165. sectionSize.footerTitle = NSLocalizedString(@"_clear_cache_footer_", nil);
  166. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deleteoldfiles" rowType:XLFormRowDescriptorTypeSelectorPush title:NSLocalizedString(@"_delete_old_files_", nil)];
  167. switch (CCUtility.getCleanUpDay) {
  168. case 0:
  169. row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(0) displayText:NSLocalizedString(@"_never_", nil)];
  170. break;
  171. case 365:
  172. row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(365) displayText:NSLocalizedString(@"_1_year_", nil)];
  173. break;
  174. case 180:
  175. row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(180) displayText:NSLocalizedString(@"_6_months_", nil)];
  176. break;
  177. case 90:
  178. row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(90) displayText:NSLocalizedString(@"_3_months_", nil)];
  179. break;
  180. case 30:
  181. row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(30) displayText:NSLocalizedString(@"_1_month_", nil)];
  182. break;
  183. case 7:
  184. row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(7) displayText:NSLocalizedString(@"_1_week_", nil)];
  185. break;
  186. case 1:
  187. row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(1) displayText:NSLocalizedString(@"_1_day_", nil)];
  188. break;
  189. default:
  190. row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(0) displayText:NSLocalizedString(@"_never_", nil)];
  191. break;
  192. }
  193. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  194. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  195. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  196. row.selectorTitle = NSLocalizedString(@"_delete_old_files_", nil);
  197. row.selectorOptions = @[[XLFormOptionsObject formOptionsObjectWithValue:@(0) displayText:NSLocalizedString(@"_never_", nil)],
  198. [XLFormOptionsObject formOptionsObjectWithValue:@(365) displayText:NSLocalizedString(@"_1_year_", nil)],
  199. [XLFormOptionsObject formOptionsObjectWithValue:@(180) displayText:NSLocalizedString(@"_6_months_", nil)],
  200. [XLFormOptionsObject formOptionsObjectWithValue:@(90) displayText:NSLocalizedString(@"_3_months_", nil)],
  201. [XLFormOptionsObject formOptionsObjectWithValue:@(30) displayText:NSLocalizedString(@"_1_month_", nil)],
  202. [XLFormOptionsObject formOptionsObjectWithValue:@(7) displayText:NSLocalizedString(@"_1_week_", nil)],
  203. ];
  204. [sectionSize addFormRow:row];
  205. // Clear cache
  206. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_cache_", nil)];
  207. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  208. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  209. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  210. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  211. [row.cellConfig setObject:[[UIImage imageNamed:@"trash"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  212. row.action.formSelector = @selector(clearCacheRequest:);
  213. [sectionSize addFormRow:row];
  214. #ifdef DEBUG
  215. // Clear all cache
  216. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeraallcache" rowType:XLFormRowDescriptorTypeButton title:@"Clear all cache"];
  217. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  218. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  219. [row.cellConfig setObject:[UIColor blueColor] forKey:@"textLabel.textColor"];
  220. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  221. [row.cellConfig setObject:[[UIImage imageNamed:@"trash"] imageWithColor:[UIColor blueColor] size:25] forKey:@"imageView.image"];
  222. row.action.formSelector = @selector(clearAllCacheRequest:);
  223. [sectionSize addFormRow:row];
  224. #endif
  225. // Section EXIT --------------------------------------------------------
  226. section = [XLFormSectionDescriptor formSection];
  227. [form addFormSection:section];
  228. section.footerTitle = NSLocalizedString(@"_exit_footer_", nil);
  229. // Exit
  230. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_exit_", nil)];
  231. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  232. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  233. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  234. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  235. [row.cellConfig setObject:[[UIImage imageNamed:@"xmark"] imageWithColor:[UIColor redColor] size:25] forKey:@"imageView.image"];
  236. row.action.formSelector = @selector(exitNextcloud:);
  237. [section addFormRow:row];
  238. self.tableView.showsVerticalScrollIndicator = NO;
  239. self.form = form;
  240. }
  241. // MARK: - View Life Cycle
  242. - (void)viewDidLoad
  243. {
  244. [super viewDidLoad];
  245. self.title = NSLocalizedString(@"_advanced_", nil);
  246. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  247. self.view.backgroundColor = UIColor.systemGroupedBackgroundColor;
  248. self.tableView.backgroundColor = UIColor.systemGroupedBackgroundColor;
  249. [self initializeForm];
  250. [self calculateSize];
  251. }
  252. - (void)viewWillAppear:(BOOL)animated
  253. {
  254. [super viewWillAppear:animated];
  255. appDelegate.activeViewController = self;
  256. }
  257. #pragma mark -
  258. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  259. {
  260. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  261. if ([rowDescriptor.tag isEqualToString:@"showHiddenFiles"]) {
  262. [CCUtility setShowHiddenFiles:[[rowDescriptor.value valueData] boolValue]];
  263. }
  264. if ([rowDescriptor.tag isEqualToString:@"formatCompatibility"]) {
  265. [CCUtility setFormatCompatibility:[[rowDescriptor.value valueData] boolValue]];
  266. }
  267. if ([rowDescriptor.tag isEqualToString:@"livePhoto"]) {
  268. [CCUtility setLivePhoto:[[rowDescriptor.value valueData] boolValue]];
  269. }
  270. if ([rowDescriptor.tag isEqualToString:@"removePhotoCameraRoll"]) {
  271. [CCUtility setRemovePhotoCameraRoll:[[rowDescriptor.value valueData] boolValue]];
  272. }
  273. if ([rowDescriptor.tag isEqualToString:@"disablefilesapp"]) {
  274. [CCUtility setDisableFilesApp:[[rowDescriptor.value valueData] boolValue]];
  275. }
  276. if ([rowDescriptor.tag isEqualToString:@"crashservice"]) {
  277. [CCUtility setDisableCrashservice:[[rowDescriptor.value valueData] boolValue]];
  278. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_crashservice_title_", nil) message:NSLocalizedString(@"_crashservice_alert_", nil) preferredStyle:UIAlertControllerStyleAlert];
  279. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  280. exit(0);
  281. }];
  282. [alertController addAction:okAction];
  283. [self presentViewController:alertController animated:YES completion:nil];
  284. }
  285. if ([rowDescriptor.tag isEqualToString:@"logLevel"]) {
  286. NSInteger levelLog = [[rowDescriptor.value valueData] intValue];
  287. [CCUtility setLogLevel:levelLog];
  288. [[[NextcloudKit shared] nkCommonInstance] setLevelLog:levelLog];
  289. }
  290. if ([rowDescriptor.tag isEqualToString:@"deleteoldfiles"]) {
  291. NSInteger days = [[rowDescriptor.value valueData] intValue];
  292. [CCUtility setCleanUpDay:days];
  293. }
  294. }
  295. #pragma mark - Clear Cache
  296. - (void)clearCache:(NSString *)account
  297. {
  298. [[NCNetworking shared] cancelSessionsInBackground:true];
  299. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  300. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  301. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  302. [[NCManageDatabase shared] clearDatabaseWithAccount:account removeAccount:false];
  303. [CCUtility removeGroupDirectoryProviderStorage];
  304. [CCUtility removeGroupLibraryDirectory];
  305. [CCUtility removeDocumentsDirectory];
  306. [CCUtility removeTemporaryDirectory];
  307. [CCUtility createDirectoryStandard];
  308. [[NCAutoUpload shared] alignPhotoLibraryWithViewController:self];
  309. [[NCMediaCache shared] clearCache];
  310. [[NCActivityIndicator shared] stop];
  311. [self calculateSize];
  312. });
  313. }
  314. - (void)clearCacheRequest:(XLFormRowDescriptor *)sender
  315. {
  316. [self deselectFormRow:sender];
  317. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  318. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  319. [[NCActivityIndicator shared] startActivityWithBackgroundView:nil style: UIActivityIndicatorViewStyleLarge blurEffect:true];
  320. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  321. [self clearCache:appDelegate.account];
  322. });
  323. }]];
  324. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  325. }]];
  326. alertController.popoverPresentationController.sourceView = self.view;
  327. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  328. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  329. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  330. [self presentViewController:alertController animated:YES completion:nil];
  331. }
  332. - (void)clearAllCacheRequest:(XLFormRowDescriptor *)sender
  333. {
  334. [self deselectFormRow:sender];
  335. [[NCActivityIndicator shared] startActivityWithBackgroundView:nil style: UIActivityIndicatorViewStyleLarge blurEffect:true];
  336. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  337. [self clearCache:nil];
  338. });
  339. }
  340. - (void)calculateSize
  341. {
  342. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  343. NSString *directory = CCUtility.getDirectoryProviderStorage;
  344. int64_t totalSize = [[NCUtilityFileSystem shared] getDirectorySizeWithDirectory:directory];
  345. sectionSize.footerTitle = [NSString stringWithFormat:@"%@. (%@ %@)", NSLocalizedString(@"_clear_cache_footer_", nil), NSLocalizedString(@"_used_space_", nil), [CCUtility transformedSize:totalSize]];
  346. dispatch_async(dispatch_get_main_queue(), ^{
  347. [self.tableView reloadData];
  348. });
  349. });
  350. }
  351. #pragma mark - Exit Nextcloud
  352. - (void)exitNextcloud:(XLFormRowDescriptor *)sender
  353. {
  354. [self deselectFormRow:sender];
  355. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_exit_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  356. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  357. [[NCNetworking shared] cancelSessionsInBackground:true];
  358. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  359. [[NCManageDatabase shared] removeDB];
  360. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  361. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  362. [CCUtility removeGroupDirectoryProviderStorage];
  363. [CCUtility removeGroupApplicationSupport];
  364. [CCUtility removeDocumentsDirectory];
  365. [CCUtility removeTemporaryDirectory];
  366. [CCUtility deleteAllChainStore];
  367. exit(0);
  368. });
  369. }]];
  370. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  371. }]];
  372. alertController.popoverPresentationController.sourceView = self.view;
  373. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  374. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  375. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  376. [self presentViewController:alertController animated:YES completion:nil];
  377. }
  378. #pragma mark -
  379. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  380. if (indexPath.section == 4 && indexPath.row == 2) {
  381. return 80;
  382. } else {
  383. return NCGlobal.shared.heightCellSettings;
  384. }
  385. }
  386. @end