CCActions.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // CCActions.swift
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 06/02/17.
  6. // Copyright (c) 2017 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 Foundation
  24. @objc protocol CCActionsDelegate {
  25. func deleteFileOrFolderSuccess(_ metadataNet : CCMetadataNet)
  26. func deleteFileOrFolderFailure(_ metadataNet : CCMetadataNet, message : NSString, errorCode : NSInteger)
  27. }
  28. class CCActions: NSObject {
  29. //MARK: Shared Instance
  30. /*
  31. static let sharedInstance : CCActions = {
  32. let instance = CCActions()
  33. return instance
  34. }()
  35. */
  36. //MARK: Local Variable
  37. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  38. var metadataNet : CCMetadataNet = CCMetadataNet.init()
  39. var delegate : CCActionsDelegate?
  40. //MARK: Init
  41. override init() {
  42. }
  43. // BARK: Delete
  44. func deleteFileOrFolder(_ metadata : CCMetadata, serverUrl : String, delegate : AnyObject) {
  45. let metadataNet : CCMetadataNet = CCMetadataNet.init()
  46. if metadata.cryptated == true {
  47. metadataNet.action = actionDeleteFileDirectory
  48. metadataNet.delegate = delegate
  49. metadataNet.fileID = metadata.fileID
  50. metadataNet.fileNamePrint = metadata.fileNamePrint
  51. metadataNet.metadata = metadata
  52. metadataNet.serverUrl = serverUrl
  53. // data crypto
  54. metadataNet.fileName = metadata.fileNameData
  55. metadataNet.selector = selectorDeleteCrypto
  56. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  57. // plist
  58. metadataNet.fileName = metadata.fileName;
  59. metadataNet.selector = selectorDeletePlist
  60. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  61. } else {
  62. metadataNet.action = actionDeleteFileDirectory
  63. metadataNet.delegate = self
  64. metadataNet.fileID = metadata.fileID
  65. metadataNet.fileName = metadata.fileName
  66. metadataNet.fileNamePrint = metadata.fileNamePrint
  67. metadataNet.metadata = metadata
  68. metadataNet.selector = selectorDelete
  69. metadataNet.serverUrl = serverUrl
  70. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  71. }
  72. }
  73. func deleteFileOrFolderSuccess(_ metadataNet : CCMetadataNet) {
  74. CCCoreData.deleteFile(metadataNet.metadata, serverUrl: metadataNet.serverUrl, directoryUser: appDelegate.directoryUser, typeCloud: appDelegate.typeCloud, activeAccount: appDelegate.activeAccount)
  75. delegate?.deleteFileOrFolderSuccess(metadataNet)
  76. }
  77. func deleteFileOrFolderFailure(_ metadataNet : CCMetadataNet, message : NSString, errorCode : NSInteger) {
  78. if errorCode == 404 {
  79. CCCoreData.deleteFile(metadataNet.metadata, serverUrl: metadataNet.serverUrl, directoryUser: appDelegate.directoryUser, typeCloud: appDelegate.typeCloud, activeAccount: appDelegate.activeAccount)
  80. }
  81. delegate?.deleteFileOrFolderFailure(metadataNet, message: message, errorCode: errorCode)
  82. }
  83. }