CCAdvanced.m 26 KB

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