CCSettings.m 42 KB

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