CCSettings.m 43 KB

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