CCSettings.m 44 KB

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