CCSettings.m 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. //
  2. // CCSettings.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/11/14.
  6. // Copyright (c) 2014 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 "CCSettings.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #define alertViewEsci 1
  27. #define alertViewAzzeraCache 2
  28. @implementation CCSettings
  29. - (id)initWithCoder:(NSCoder *)aDecoder
  30. {
  31. self = [super initWithCoder:aDecoder];
  32. if (self) {
  33. [self initializeForm];
  34. app.activeSettings = self;
  35. }
  36. return self;
  37. }
  38. - (void)initializeForm
  39. {
  40. XLFormDescriptor *form;
  41. XLFormSectionDescriptor *section;
  42. XLFormRowDescriptor *row;
  43. // Section : Settings
  44. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_settings_", nil)];
  45. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  46. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_passcode_", nil)];
  47. [form addFormSection:section];
  48. // Passcode
  49. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
  50. [row.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeNO] forKey:@"imageView.image"];
  51. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  52. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  53. [row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  54. row.action.formSelector = @selector(bloccoPassword);
  55. [section addFormRow:row];
  56. // Passcode simply
  57. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"simplypasscode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_simply_", nil)];
  58. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  59. [section addFormRow:row];
  60. // Passcode only directory
  61. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"onlylockdir" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_folder_", nil)];
  62. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  63. [section addFormRow:row];
  64. // Send aes-256 password via mail
  65. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendmailencryptpass" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_encryptpass_by_email_", nil)];
  66. [row.cellConfig setObject:@(NSTextAlignmentCenter) forKey:@"textLabel.textAlignment"];
  67. [row.cellConfig setObject:COLOR_ENCRYPTED forKey:@"textLabel.textColor"];
  68. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  69. [row.cellConfig setObject:[UIImage imageNamed:image_settingsKeyMail] forKey:@"imageView.image"];
  70. row.action.formSelector = @selector(checkEncryptPass:);
  71. [section addFormRow:row];
  72. // Section : data Cloud
  73. section = [XLFormSectionDescriptor formSectionWithTitle:@"Cloud account"];
  74. [form addFormSection:section];
  75. // version
  76. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"versionserver" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_version_server_", nil)];
  77. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  78. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  79. [section addFormRow:row];
  80. // Url
  81. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"urlcloud" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_url_", nil)];
  82. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  83. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  84. [section addFormRow:row];
  85. // username
  86. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usernamecloud" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_username_", nil)];
  87. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  88. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  89. [section addFormRow:row];
  90. // quota
  91. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"quota" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_quota_", nil)];
  92. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  93. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  94. [section addFormRow:row];
  95. // Change Account
  96. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"changecredentials" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_change_credentials_", nil)];
  97. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  98. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCredentials] forKey:@"imageView.image"];
  99. row.action.formSegueIdentifier = @"CCManageAccountSegue";
  100. [section addFormRow:row];
  101. // Section : Camera Upload
  102. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_uploading_from_camera_", nil)];
  103. [form addFormSection:section];
  104. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"cameraupload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_uploading_from_camera_", nil)];
  105. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  106. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCameraUpload] forKey:@"imageView.image"];
  107. row.action.formSegueIdentifier = @"CCManageCameraUploadSegue";
  108. [section addFormRow:row];
  109. // Section : Photos
  110. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_photo_camera_", nil)];
  111. [form addFormSection:section];
  112. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"managephotos" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_photo_camera_", nil)];
  113. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  114. [row.cellConfig setObject:[UIImage imageNamed:image_settingsManagePhotos] forKey:@"imageView.image"];
  115. row.action.formSegueIdentifier = @"CCManagePhotosSegue";
  116. [section addFormRow:row];
  117. // Section : Optimizations
  118. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_optimizations_", nil)];
  119. [form addFormSection:section];
  120. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"optimizations" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_optimizations_", nil)];
  121. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  122. [row.cellConfig setObject:[UIImage imageNamed:image_settingsOptimizations] forKey:@"imageView.image"];
  123. row.action.formSegueIdentifier = @"CCManageOptimizationsSegue";
  124. [section addFormRow:row];
  125. // Section : Acknowledgements
  126. section = [XLFormSectionDescriptor formSection];
  127. [form addFormSection:section];
  128. section.footerTitle = @"Nextcloud © 2016 T.W.S. Inc.";
  129. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
  130. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  131. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  132. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAcknowledgements] forKey:@"imageView.image"];
  133. [row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  134. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  135. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  136. [self deselectFormRow:sender];
  137. };
  138. [section addFormRow:row];
  139. // Version
  140. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"versioneapplicazione" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_app_version_", nil)];
  141. row.value = [NSString stringWithFormat:@"%@ (%@)", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  142. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  143. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  144. [section addFormRow:row];
  145. // Section : help
  146. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_help_", nil)];
  147. [form addFormSection:section];
  148. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"help" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_", nil)];
  149. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  150. [row.cellConfig setObject:[UIImage imageNamed:image_settingsHelp] forKey:@"imageView.image"];
  151. row.action.formSegueIdentifier = @"CCManageHelpSegue";
  152. [section addFormRow:row];
  153. // Section : mail
  154. section = [XLFormSectionDescriptor formSection];
  155. [form addFormSection:section];
  156. // Contact us mail
  157. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendmail" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_contact_by_email_", nil)];
  158. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  159. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  160. [row.cellConfig setObject:[UIImage imageNamed:image_settingsMail] forKey:@"imageView.image"];
  161. row.action.formSelector = @selector(sendMail:);
  162. [section addFormRow:row];
  163. // Section : cache
  164. section = [XLFormSectionDescriptor formSection];
  165. [form addFormSection:section];
  166. // Clear cache
  167. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:@""];
  168. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  169. [row.cellConfig setObject:[UIImage imageNamed:image_settingsClearCache] forKey:@"imageView.image"];
  170. row.action.formSelector = @selector(azzeraCache:);
  171. [section addFormRow:row];
  172. // Section : debug
  173. #ifdef DEBUG
  174. section = [XLFormSectionDescriptor formSectionWithTitle:@"Debug"];
  175. [form addFormSection:section];
  176. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"adminRemoveVersionIntro" rowType:XLFormRowDescriptorTypeButton title:@"Remove self-Version Intro"];
  177. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  178. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  179. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  180. row.action.formSelector = @selector(adminRemoveVersionIntro:);
  181. [section addFormRow:row];
  182. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"adminRemovePasscode" rowType:XLFormRowDescriptorTypeButton title:@"Remove Passcode"];
  183. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  184. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  185. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  186. row.action.formSelector = @selector(adminRemovePasscode:);
  187. [section addFormRow:row];
  188. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"adminRemoveVersion" rowType:XLFormRowDescriptorTypeButton title:@"Remove Version"];
  189. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  190. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  191. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  192. row.action.formSelector = @selector(adminRemoveVersion:);
  193. [section addFormRow:row];
  194. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"copyGroupLocal" rowType:XLFormRowDescriptorTypeButton title:@"Copy Group to Local"];
  195. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  196. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  197. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  198. row.action.formSelector = @selector(copyDirGroupToLocal:);
  199. [section addFormRow:row];
  200. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"quickActionOffline" rowType:XLFormRowDescriptorTypeButton title:@"Quick Action Offline"];
  201. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  202. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  203. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  204. row.action.formSelector = @selector(quickActionOffline:);
  205. [section addFormRow:row];
  206. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"quickActionPhotos" rowType:XLFormRowDescriptorTypeButton title:@"Quick Action Photos"];
  207. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  208. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  209. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  210. row.action.formSelector = @selector(quickActionPhotos:);
  211. [section addFormRow:row];
  212. #endif
  213. // Section : quit
  214. section = [XLFormSectionDescriptor formSection];
  215. [form addFormSection:section];
  216. // Exit
  217. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:[CCUtility localizableBrand:@"_exit_" table:nil]];
  218. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  219. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  220. [row.cellConfig setObject:[UIImage imageNamed:image_settingsExit] forKey:@"imageView.image"];
  221. row.action.formSelector = @selector(esci:);
  222. [section addFormRow:row];
  223. section = [XLFormSectionDescriptor formSection];
  224. [form addFormSection:section];
  225. self.form = form;
  226. }
  227. - (void)viewDidLoad
  228. {
  229. [super viewDidLoad];
  230. self.hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  231. self.title = NSLocalizedString(@"_settings_", nil);
  232. // Color
  233. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  234. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  235. }
  236. // Apparirà
  237. - (void)viewWillAppear:(BOOL)animated
  238. {
  239. [super viewWillAppear:animated];
  240. // Color
  241. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  242. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  243. [self reloadForm];
  244. [self recalculateSize];
  245. }
  246. // E' apparsa
  247. - (void)viewDidAppear:(BOOL)animated
  248. {
  249. [super viewDidAppear:animated];
  250. }
  251. #pragma --------------------------------------------------------------------------------------------
  252. #pragma mark === Admin ===
  253. #pragma --------------------------------------------------------------------------------------------
  254. - (void)adminRemoveVersionIntro:(XLFormRowDescriptor *)sender
  255. {
  256. [self deselectFormRow:sender];
  257. [CCUtility adminRemoveIntro];
  258. exit(0);
  259. }
  260. - (void)adminRemovePasscode:(XLFormRowDescriptor *)sender
  261. {
  262. [self deselectFormRow:sender];
  263. [CCUtility adminRemovePasscode];
  264. exit(0);
  265. }
  266. - (void)adminRemoveVersion:(XLFormRowDescriptor *)sender
  267. {
  268. [self deselectFormRow:sender];
  269. [CCUtility adminRemoveVersion];
  270. exit(0);
  271. }
  272. - (void)quickActionOffline:(XLFormRowDescriptor *)sender
  273. {
  274. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  275. UIApplicationShortcutItem *shortcutOffline = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.offline", bundleId] localizedTitle:@"" localizedSubtitle:nil icon:nil userInfo:nil];
  276. [app handleShortCutItem:shortcutOffline];
  277. }
  278. - (void)quickActionPhotos:(XLFormRowDescriptor *)sender
  279. {
  280. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  281. UIApplicationShortcutItem *shortcutPhotos = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.photos", bundleId] localizedTitle:@"" localizedSubtitle:nil icon:nil userInfo:nil];
  282. [app handleShortCutItem:shortcutPhotos];
  283. }
  284. #pragma --------------------------------------------------------------------------------------------
  285. #pragma mark === Chiamate dal Form ===
  286. #pragma --------------------------------------------------------------------------------------------
  287. - (void)reloadForm
  288. {
  289. self.form.delegate = nil;
  290. // ----------------------
  291. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  292. XLFormRowDescriptor *rowSimplyPasscode = [self.form formRowWithTag:@"simplypasscode"];
  293. XLFormRowDescriptor *rowOnlyLockDir = [self.form formRowWithTag:@"onlylockdir"];
  294. XLFormRowDescriptor *rowVersionServer = [self.form formRowWithTag:@"versionserver"];
  295. XLFormRowDescriptor *rowUrlCloud = [self.form formRowWithTag:@"urlcloud"];
  296. XLFormRowDescriptor *rowUserNameCloud = [self.form formRowWithTag:@"usernamecloud"];
  297. XLFormRowDescriptor *rowQuota = [self.form formRowWithTag:@"quota"];
  298. // ------------------------------------------------------------------
  299. if ([[CCUtility getBlockCode] length]) {
  300. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  301. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeYES] forKey:@"imageView.image"];
  302. } else {
  303. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  304. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeNO] forKey:@"imageView.image"];
  305. }
  306. if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
  307. if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
  308. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud])
  309. rowVersionServer.value = [CCNetworking sharedNetworking].sharedOCCommunication.getCurrentServerVersion;
  310. rowUrlCloud.value = app.activeUrl;
  311. rowUserNameCloud.value = app.activeUser;
  312. NSString *quota = [CCUtility transformedSize:(app.quotaAvailable + app.quotaUsed)];
  313. NSString *quotaAvailable = [CCUtility transformedSize:(app.quotaAvailable)];
  314. rowQuota.value = [NSString stringWithFormat:@"%@ / %@ %@", quota, quotaAvailable, NSLocalizedString(@"_available_", nil)];
  315. // -----------------------------------------------------------------
  316. [self.tableView reloadData];
  317. self.form.delegate = self;
  318. }
  319. - (void)recalculateSize
  320. {
  321. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  322. self.form.delegate = nil;
  323. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  324. NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  325. rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  326. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  327. self.form.delegate = self;
  328. });
  329. }
  330. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  331. {
  332. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  333. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  334. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  335. [CCUtility setOnlyLockDir:true];
  336. } else {
  337. [CCUtility setOnlyLockDir:false];
  338. }
  339. }
  340. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  341. if ([[CCUtility getBlockCode] length] == 0)
  342. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  343. else
  344. [self changeSimplyPassword];
  345. }
  346. }
  347. - (void)checkEncryptPass:(XLFormRowDescriptor *)sender
  348. {
  349. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  350. viewController.delegate = self;
  351. viewController.fromType = CCBKPasscodeFromCheckCryptoKey;
  352. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  353. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  354. viewController.passcodeInputView.maximumLength = 64;
  355. viewController.title = NSLocalizedString(@"_check_key_aes_256_", nil);
  356. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  357. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  358. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  359. [self presentViewController:navigationController animated:YES completion:nil];
  360. }
  361. - (void)changeSimplyPassword
  362. {
  363. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  364. viewController.delegate = self;
  365. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  366. viewController.fromType = CCBKPasscodeFromSimply;
  367. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  368. viewController.inputViewTitlePassword = YES;
  369. if ([CCUtility getSimplyBlockCode]) {
  370. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  371. viewController.passcodeInputView.maximumLength = 6;
  372. } else {
  373. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  374. viewController.passcodeInputView.maximumLength = 64;
  375. }
  376. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  377. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  378. viewController.touchIDManager = touchIDManager;
  379. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  380. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  381. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  382. [self presentViewController:navigationController animated:YES completion:nil];
  383. }
  384. - (void)bloccoPassword
  385. {
  386. // ATTIVAZIONE LOCK PASSWORD
  387. if ([[CCUtility getBlockCode] length] == 0) {
  388. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  389. viewController.delegate = self;
  390. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  391. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  392. viewController.inputViewTitlePassword = YES;
  393. if ([CCUtility getSimplyBlockCode]) {
  394. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  395. viewController.passcodeInputView.maximumLength = 6;
  396. } else {
  397. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  398. viewController.passcodeInputView.maximumLength = 64;
  399. }
  400. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  401. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  402. viewController.touchIDManager = touchIDManager;
  403. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  404. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  405. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  406. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  407. [self presentViewController:navigationController animated:YES completion:nil];
  408. } else {
  409. // OFF LOCK PASSWORD
  410. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  411. viewController.delegate = self;
  412. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  413. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  414. viewController.inputViewTitlePassword = YES;
  415. if ([CCUtility getSimplyBlockCode]) {
  416. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  417. viewController.passcodeInputView.maximumLength = 6;
  418. } else {
  419. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  420. viewController.passcodeInputView.maximumLength = 64;
  421. }
  422. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  423. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  424. viewController.touchIDManager = touchIDManager;
  425. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  426. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  427. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  428. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  429. [self presentViewController:navigationController animated:YES completion:nil];
  430. }
  431. }
  432. - (void)esci:(XLFormRowDescriptor *)sender
  433. {
  434. [self deselectFormRow:sender];
  435. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:[CCUtility localizableBrand:@"_exit_" table:nil]
  436. message:[CCUtility localizableBrand:@"_want_exit_" table:nil]
  437. delegate:self
  438. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  439. otherButtonTitles: nil];
  440. alertView.tag = alertViewEsci;
  441. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  442. [alertView show];
  443. }
  444. - (void)azzeraCache:(XLFormRowDescriptor *)sender
  445. {
  446. [self deselectFormRow:sender];
  447. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:NSLocalizedString(@"_delete_cache_",nil)
  448. message:NSLocalizedString(@"_want_delete_cache_", nil)
  449. delegate:self
  450. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  451. otherButtonTitles: nil];
  452. alertView.tag = alertViewAzzeraCache;
  453. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  454. [alertView show];
  455. }
  456. #pragma --------------------------------------------------------------------------------------------
  457. #pragma mark === Mail ===
  458. #pragma --------------------------------------------------------------------------------------------
  459. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  460. {
  461. switch (result)
  462. {
  463. case MFMailComposeResultCancelled:
  464. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  465. break;
  466. case MFMailComposeResultSaved:
  467. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  468. break;
  469. case MFMailComposeResultSent:
  470. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  471. break;
  472. case MFMailComposeResultFailed: {
  473. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  474. [app messageNotification:@"_error_" description:msg visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  475. }
  476. break;
  477. default:
  478. break;
  479. }
  480. // Close the Mail Interface
  481. [self dismissViewControllerAnimated:YES completion:NULL];
  482. }
  483. - (void)sendMail:(XLFormRowDescriptor *)sender
  484. {
  485. // Email Subject
  486. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  487. // Email Content
  488. NSString *messageBody;
  489. // Email Recipents
  490. NSArray *toRecipents;
  491. messageBody = [NSString stringWithFormat:@"\n\n\nNextcloud Version %@ (%@)", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  492. toRecipents = [NSArray arrayWithObject:_mail_me_];
  493. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  494. mc.mailComposeDelegate = self;
  495. [mc setSubject:emailTitle];
  496. [mc setMessageBody:messageBody isHTML:NO];
  497. [mc setToRecipients:toRecipents];
  498. // Present mail view controller on screen
  499. [self presentViewController:mc animated:YES completion:NULL];
  500. }
  501. - (void)sendMailEncryptPass
  502. {
  503. [CCUtility sendMailEncryptPass:[CCUtility getEmail] validateEmail:NO form:self];
  504. }
  505. #pragma --------------------------------------------------------------------------------------------
  506. #pragma mark === AlertView ===
  507. #pragma --------------------------------------------------------------------------------------------
  508. - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
  509. {
  510. // Remove ALL
  511. if (buttonIndex == 1 && alertView.tag == alertViewEsci)
  512. {
  513. [self.hud visibleIndeterminateHud];
  514. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  515. [app cancelAllOperations];
  516. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  517. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  518. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  519. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  520. [CCCoreData flushAllDatabase];
  521. [CCUtility deleteAllChainStore];
  522. [self emptyDocumentsDirectory];
  523. [self emptyLibraryDirectory];
  524. [self emptyGroupApplicationSupport];
  525. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  526. for (NSString *file in tmpDirectory)
  527. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  528. [self.hud hideHud];
  529. exit(0);
  530. });
  531. }
  532. // Clear Cache
  533. if (buttonIndex == 1 && alertView.tag == alertViewAzzeraCache)
  534. {
  535. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  536. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  537. [app cancelAllOperations];
  538. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  539. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  540. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  541. [CCCoreData flushTableAutomaticUploadAccount:app.activeAccount selector:nil];
  542. [CCCoreData flushTableDirectoryAccount:app.activeAccount];
  543. [CCCoreData flushTableLocalFileAccount:app.activeAccount];
  544. [CCCoreData flushTableMetadataAccount:app.activeAccount];
  545. [self emptyUserDirectoryUser:app.activeUser url:app.activeUrl];
  546. [self emptyLocalDirectory];
  547. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  548. for (NSString *file in tmpDirectory)
  549. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  550. [self recalculateSize];
  551. // Inizialized home
  552. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  553. [self.hud hideHud];
  554. });
  555. }
  556. }
  557. #pragma --------------------------------------------------------------------------------------------
  558. #pragma mark === BKPasscodeViewController ===
  559. #pragma --------------------------------------------------------------------------------------------
  560. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  561. {
  562. [aViewController dismissViewControllerAnimated:YES completion:nil];
  563. switch (aViewController.type) {
  564. case BKPasscodeViewControllerNewPasscodeType: {
  565. // enable passcode
  566. [CCUtility setBlockCode:aPasscode];
  567. }
  568. break;
  569. case BKPasscodeViewControllerCheckPasscodeType: {
  570. // disable passcode
  571. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  572. [CCUtility setBlockCode:@""];
  573. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  574. CCMain *mainVC = [app.listMainVC objectForKey:app.serverUrl];
  575. if (mainVC)
  576. [mainVC.tableView reloadData];
  577. }
  578. // email Key EAS-256
  579. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey)
  580. [self sendMailEncryptPass];
  581. // change simply
  582. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  583. // disable passcode
  584. [CCUtility setBlockCode:@""];
  585. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  586. CCMain *mainVC = [app.listMainVC objectForKey:app.serverUrl];
  587. if (mainVC)
  588. [mainVC.tableView reloadData];
  589. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  590. // Call new passcode
  591. [self bloccoPassword];
  592. }
  593. }
  594. break;
  595. default:
  596. break;
  597. }
  598. [self reloadForm];
  599. }
  600. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  601. {
  602. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey) {
  603. NSString *key = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
  604. if ([aPasscode isEqualToString:key]) {
  605. self.lockUntilDate = nil;
  606. self.failedAttempts = 0;
  607. aResultHandler(YES);
  608. } else aResultHandler(NO);
  609. }
  610. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  611. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  612. self.lockUntilDate = nil;
  613. self.failedAttempts = 0;
  614. aResultHandler(YES);
  615. } else aResultHandler(NO);
  616. }
  617. }
  618. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  619. {
  620. self.failedAttempts++;
  621. if (self.failedAttempts > 5) {
  622. NSTimeInterval timeInterval = 60;
  623. if (self.failedAttempts > 6) {
  624. NSUInteger multiplier = self.failedAttempts - 6;
  625. timeInterval = (5 * 60) * multiplier;
  626. if (timeInterval > 3600 * 24) {
  627. timeInterval = 3600 * 24;
  628. }
  629. }
  630. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  631. }
  632. }
  633. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  634. {
  635. return self.failedAttempts;
  636. }
  637. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  638. {
  639. return self.lockUntilDate;
  640. }
  641. - (void)passcodeViewCloseButtonPressed:(id)sender
  642. {
  643. [self dismissViewControllerAnimated:YES completion:nil];
  644. }
  645. #pragma --------------------------------------------------------------------------------------------
  646. #pragma mark == Utility ==
  647. #pragma --------------------------------------------------------------------------------------------
  648. - (void)emptyGroupApplicationSupport
  649. {
  650. NSString *file;
  651. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:capabilitiesGroups];
  652. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  653. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  654. while (file = [enumerator nextObject])
  655. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  656. }
  657. - (void)emptyLibraryDirectory
  658. {
  659. NSString *file;
  660. NSString *dirIniziale;
  661. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  662. dirIniziale = [paths objectAtIndex:0];
  663. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  664. while (file = [enumerator nextObject])
  665. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  666. }
  667. - (void)emptyDocumentsDirectory
  668. {
  669. NSString *file;
  670. NSString *dirIniziale;
  671. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  672. dirIniziale = [paths objectAtIndex:0];
  673. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  674. while (file = [enumerator nextObject])
  675. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  676. }
  677. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url
  678. {
  679. NSString *file;
  680. NSString *dirIniziale;
  681. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  682. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  683. while (file = [enumerator nextObject]) {
  684. /*
  685. if (removeICO == NO) {
  686. NSString *ext = [[file pathExtension] lowercaseString];
  687. if ([ext isEqualToString:@"ico"] && [file rangeOfString:@"ID_UPLOAD_"].location == NSNotFound) continue;
  688. }
  689. */
  690. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  691. }
  692. }
  693. - (void)emptyLocalDirectory
  694. {
  695. NSString *file;
  696. NSString *dirIniziale;
  697. dirIniziale = [CCUtility getDirectoryLocal];
  698. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  699. while (file = [enumerator nextObject])
  700. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  701. }
  702. - (NSNumber *)getUserDirectorySize
  703. {
  704. NSString *directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  705. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  706. unsigned long long count = 0;
  707. NSNumber *value = nil;
  708. if (! directoryURL) return 0;
  709. // Get dimension Document
  710. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  711. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  712. count += [value longLongValue];
  713. } else {
  714. return nil;
  715. }
  716. }
  717. return @(count);
  718. }
  719. - (void)copyDirGroupToLocal:(XLFormRowDescriptor *)sender
  720. {
  721. [self deselectFormRow:sender];
  722. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:capabilitiesGroups];
  723. dirGroup = [dirGroup URLByAppendingPathComponent:@"Library"];
  724. dirGroup = [dirGroup URLByAppendingPathComponent:@"Application Support"];
  725. dirGroup = [dirGroup URLByAppendingPathComponent:@"Crypto Cloud"];
  726. NSArray *paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
  727. NSURL *destination = [[paths lastObject] URLByAppendingPathComponent:@"group"];
  728. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  729. dateFormatter.dateFormat = @"hh:mm:ss";
  730. [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
  731. NSLog(@"[LOG] Open HUD %@",[dateFormatter stringFromDate:[NSDate date]]);
  732. [self.hud visibleIndeterminateHud];
  733. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
  734. NSLog(@"[LOG] Init copy %@",[dateFormatter stringFromDate:[NSDate date]]);
  735. [[NSFileManager defaultManager] removeItemAtURL:destination error:nil];
  736. NSError *copyError = nil;
  737. if (![[NSFileManager defaultManager] copyItemAtURL:dirGroup toURL:destination error:&copyError]) {
  738. NSLog(@"[LOG] Error copying files: %@", [copyError localizedDescription]);
  739. }
  740. NSLog(@"[LOG] Fine copy %@",[dateFormatter stringFromDate:[NSDate date]]);
  741. [self.hud hideHud];
  742. });
  743. }
  744. @end