CCAdvanced.m 26 KB

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