CCSettings.m 43 KB

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