CCAdvanced.m 26 KB

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