CCSettings.m 44 KB

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