CCSettings.m 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  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 flushTableDirectoryAccount:app.activeAccount];
  558. [CCCoreData flushTableLocalFileAccount:app.activeAccount];
  559. [CCCoreData flushTableMetadataAccount:app.activeAccount];
  560. [self emptyUserDirectoryUser:app.activeUser url:app.activeUrl];
  561. [self emptyLocalDirectory];
  562. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  563. for (NSString *file in tmpDirectory)
  564. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  565. [self recalculateSize];
  566. // Inizialized home
  567. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  568. [self.hud hideHud];
  569. });
  570. }
  571. }
  572. #pragma --------------------------------------------------------------------------------------------
  573. #pragma mark === BKPasscodeViewController ===
  574. #pragma --------------------------------------------------------------------------------------------
  575. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  576. {
  577. [aViewController dismissViewControllerAnimated:YES completion:nil];
  578. switch (aViewController.type) {
  579. case BKPasscodeViewControllerNewPasscodeType: {
  580. // enable passcode
  581. [CCUtility setBlockCode:aPasscode];
  582. }
  583. break;
  584. case BKPasscodeViewControllerCheckPasscodeType: {
  585. // disable passcode
  586. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  587. [CCUtility setBlockCode:@""];
  588. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  589. CCMain *mainVC = [app.listMainVC objectForKey:app.serverUrl];
  590. if (mainVC)
  591. [mainVC.tableView reloadData];
  592. }
  593. // email Key EAS-256
  594. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey)
  595. [self sendMailEncryptPass];
  596. // change simply
  597. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  598. // disable passcode
  599. [CCUtility setBlockCode:@""];
  600. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  601. CCMain *mainVC = [app.listMainVC objectForKey:app.serverUrl];
  602. if (mainVC)
  603. [mainVC.tableView reloadData];
  604. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  605. // Call new passcode
  606. [self bloccoPassword];
  607. }
  608. }
  609. break;
  610. default:
  611. break;
  612. }
  613. [self reloadForm];
  614. }
  615. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  616. {
  617. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey) {
  618. NSString *key = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
  619. if ([aPasscode isEqualToString:key]) {
  620. self.lockUntilDate = nil;
  621. self.failedAttempts = 0;
  622. aResultHandler(YES);
  623. } else aResultHandler(NO);
  624. }
  625. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  626. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  627. self.lockUntilDate = nil;
  628. self.failedAttempts = 0;
  629. aResultHandler(YES);
  630. } else aResultHandler(NO);
  631. }
  632. }
  633. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  634. {
  635. self.failedAttempts++;
  636. if (self.failedAttempts > 5) {
  637. NSTimeInterval timeInterval = 60;
  638. if (self.failedAttempts > 6) {
  639. NSUInteger multiplier = self.failedAttempts - 6;
  640. timeInterval = (5 * 60) * multiplier;
  641. if (timeInterval > 3600 * 24) {
  642. timeInterval = 3600 * 24;
  643. }
  644. }
  645. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  646. }
  647. }
  648. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  649. {
  650. return self.failedAttempts;
  651. }
  652. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  653. {
  654. return self.lockUntilDate;
  655. }
  656. - (void)passcodeViewCloseButtonPressed:(id)sender
  657. {
  658. [self dismissViewControllerAnimated:YES completion:nil];
  659. }
  660. #pragma --------------------------------------------------------------------------------------------
  661. #pragma mark == Utility ==
  662. #pragma --------------------------------------------------------------------------------------------
  663. - (void)emptyGroupApplicationSupport
  664. {
  665. NSString *file;
  666. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:capabilitiesGroups];
  667. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  668. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  669. while (file = [enumerator nextObject])
  670. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  671. }
  672. - (void)emptyLibraryDirectory
  673. {
  674. NSString *file;
  675. NSString *dirIniziale;
  676. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  677. dirIniziale = [paths objectAtIndex:0];
  678. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  679. while (file = [enumerator nextObject])
  680. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  681. }
  682. - (void)emptyDocumentsDirectory
  683. {
  684. NSString *file;
  685. NSString *dirIniziale;
  686. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  687. dirIniziale = [paths objectAtIndex:0];
  688. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  689. while (file = [enumerator nextObject])
  690. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  691. }
  692. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url
  693. {
  694. NSString *file;
  695. NSString *dirIniziale;
  696. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  697. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  698. while (file = [enumerator nextObject]) {
  699. /*
  700. if (removeICO == NO) {
  701. NSString *ext = [[file pathExtension] lowercaseString];
  702. if ([ext isEqualToString:@"ico"] && [file rangeOfString:@"ID_UPLOAD_"].location == NSNotFound) continue;
  703. }
  704. */
  705. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  706. }
  707. }
  708. - (void)emptyLocalDirectory
  709. {
  710. NSString *file;
  711. NSString *dirIniziale;
  712. dirIniziale = [CCUtility getDirectoryLocal];
  713. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  714. while (file = [enumerator nextObject])
  715. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  716. }
  717. - (NSNumber *)getUserDirectorySize
  718. {
  719. NSString *directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  720. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  721. unsigned long long count = 0;
  722. NSNumber *value = nil;
  723. if (! directoryURL) return 0;
  724. // Get dimension Document
  725. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  726. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  727. count += [value longLongValue];
  728. } else {
  729. return nil;
  730. }
  731. }
  732. return @(count);
  733. }
  734. - (void)copyDirGroupToLocal:(XLFormRowDescriptor *)sender
  735. {
  736. [self deselectFormRow:sender];
  737. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:capabilitiesGroups];
  738. dirGroup = [dirGroup URLByAppendingPathComponent:@"Library"];
  739. dirGroup = [dirGroup URLByAppendingPathComponent:@"Application Support"];
  740. dirGroup = [dirGroup URLByAppendingPathComponent:@"Crypto Cloud"];
  741. NSArray *paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
  742. NSURL *destination = [[paths lastObject] URLByAppendingPathComponent:@"group"];
  743. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  744. dateFormatter.dateFormat = @"hh:mm:ss";
  745. [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
  746. NSLog(@"[LOG] Open HUD %@",[dateFormatter stringFromDate:[NSDate date]]);
  747. [self.hud visibleIndeterminateHud];
  748. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
  749. NSLog(@"[LOG] Init copy %@",[dateFormatter stringFromDate:[NSDate date]]);
  750. [[NSFileManager defaultManager] removeItemAtURL:destination error:nil];
  751. NSError *copyError = nil;
  752. if (![[NSFileManager defaultManager] copyItemAtURL:dirGroup toURL:destination error:&copyError]) {
  753. NSLog(@"[LOG] Error copying files: %@", [copyError localizedDescription]);
  754. }
  755. NSLog(@"[LOG] Fine copy %@",[dateFormatter stringFromDate:[NSDate date]]);
  756. [self.hud hideHud];
  757. });
  758. }
  759. @end