CCSettings.m 44 KB

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