CCAdvanced.m 28 KB

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