NCCreateFormUploadAssets.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. //
  2. // NCCreateFormUploadAssets.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 14/11/2018.
  6. // Copyright © 2018 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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 UIKit
  24. import Queuer
  25. protocol createFormUploadAssetsDelegate {
  26. func dismissFormUploadAssets()
  27. }
  28. class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
  29. var serverUrl: String = ""
  30. var titleServerUrl: String?
  31. var assets: [PHAsset] = []
  32. var cryptated: Bool = false
  33. var session: String = ""
  34. var delegate: createFormUploadAssetsDelegate?
  35. let requestOptions = PHImageRequestOptions()
  36. var imagePreview: UIImage?
  37. let targetSizeImagePreview = CGSize(width:100, height: 100)
  38. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  39. var cellBackgoundColor = NCBrandColor.shared.secondarySystemGroupedBackground
  40. // MARK: - View Life Cycle
  41. convenience init(serverUrl: String, assets: [PHAsset], cryptated: Bool, session: String, delegate: createFormUploadAssetsDelegate?) {
  42. self.init()
  43. if serverUrl == NCUtilityFileSystem.shared.getHomeServer(urlBase: appDelegate.urlBase, account: appDelegate.account) {
  44. titleServerUrl = "/"
  45. } else {
  46. if let tableDirectory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl)) {
  47. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(tableDirectory.ocId) {
  48. titleServerUrl = metadata.fileNameView
  49. } else { titleServerUrl = (serverUrl as NSString).lastPathComponent }
  50. } else { titleServerUrl = (serverUrl as NSString).lastPathComponent }
  51. }
  52. self.serverUrl = serverUrl
  53. self.assets = assets
  54. self.cryptated = cryptated
  55. self.session = session
  56. self.delegate = delegate
  57. requestOptions.resizeMode = PHImageRequestOptionsResizeMode.exact
  58. requestOptions.deliveryMode = PHImageRequestOptionsDeliveryMode.highQualityFormat
  59. requestOptions.isSynchronous = true
  60. }
  61. override func viewDidLoad() {
  62. super.viewDidLoad()
  63. self.title = NSLocalizedString("_upload_photos_videos_", comment: "")
  64. self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(cancel))
  65. self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_save_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(save))
  66. self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
  67. if assets.count == 1 && assets[0].mediaType == PHAssetMediaType.image {
  68. PHImageManager.default().requestImage(for: assets[0], targetSize: targetSizeImagePreview, contentMode: PHImageContentMode.aspectFill, options: requestOptions, resultHandler: { (image, info) in
  69. self.imagePreview = image
  70. })
  71. }
  72. setColors(userInterfaceStyle: nil)
  73. initializeForm()
  74. reloadForm()
  75. }
  76. override func viewWillDisappear(_ animated: Bool)
  77. {
  78. super.viewWillDisappear(animated)
  79. self.delegate?.dismissFormUploadAssets()
  80. }
  81. override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
  82. super.traitCollectionDidChange(previousTraitCollection)
  83. setColors(userInterfaceStyle: traitCollection.userInterfaceStyle)
  84. }
  85. // MARK: - Colors
  86. func setColors(userInterfaceStyle: UIUserInterfaceStyle?) {
  87. if userInterfaceStyle == .dark {
  88. // personalized
  89. } else {
  90. // personalized
  91. }
  92. view.backgroundColor = NCBrandColor.shared.systemGroupedBackground
  93. tableView.backgroundColor = NCBrandColor.shared.systemGroupedBackground
  94. cellBackgoundColor = NCBrandColor.shared.secondarySystemGroupedBackground
  95. tableView.reloadData()
  96. }
  97. //MARK: XLForm
  98. func initializeForm() {
  99. let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor
  100. form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow
  101. var section : XLFormSectionDescriptor
  102. var row : XLFormRowDescriptor
  103. // Section: Destination Folder
  104. section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_save_path_", comment: ""))
  105. form.addFormSection(section)
  106. row = XLFormRowDescriptor(tag: "ButtonDestinationFolder", rowType: XLFormRowDescriptorTypeButton, title: self.titleServerUrl)
  107. row.action.formSelector = #selector(changeDestinationFolder(_:))
  108. row.cellConfig["backgroundColor"] = cellBackgoundColor
  109. row.cellConfig["imageView.image"] = UIImage(named: "folder")!.image(color: NCBrandColor.shared.brandElement, size: 25)
  110. row.cellConfig["textLabel.textAlignment"] = NSTextAlignment.right.rawValue
  111. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  112. row.cellConfig["textLabel.textColor"] = NCBrandColor.shared.label
  113. section.addFormRow(row)
  114. // User folder Autoupload
  115. row = XLFormRowDescriptor(tag: "useFolderAutoUpload", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_use_folder_auto_upload_", comment: ""))
  116. row.value = 0
  117. row.cellConfig["backgroundColor"] = cellBackgoundColor
  118. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  119. row.cellConfig["textLabel.textColor"] = NCBrandColor.shared.label
  120. section.addFormRow(row)
  121. // Use Sub folder
  122. row = XLFormRowDescriptor(tag: "useSubFolder", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_autoupload_create_subfolder_", comment: ""))
  123. let activeAccount = NCManageDatabase.shared.getActiveAccount()
  124. if activeAccount?.autoUploadCreateSubfolder == true {
  125. row.value = 1
  126. } else {
  127. row.value = 0
  128. }
  129. row.hidden = "$\("useFolderAutoUpload") == 0"
  130. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  131. row.cellConfig["textLabel.textColor"] = NCBrandColor.shared.label
  132. section.addFormRow(row)
  133. // Section Mode filename
  134. section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_mode_filename_", comment: ""))
  135. form.addFormSection(section)
  136. // Maintain the original fileName
  137. row = XLFormRowDescriptor(tag: "maintainOriginalFileName", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_maintain_original_filename_", comment: ""))
  138. row.value = CCUtility.getOriginalFileName(NCGlobal.shared.keyFileNameOriginal)
  139. row.cellConfig["backgroundColor"] = cellBackgoundColor
  140. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  141. row.cellConfig["textLabel.textColor"] = NCBrandColor.shared.label
  142. section.addFormRow(row)
  143. // Add File Name Type
  144. row = XLFormRowDescriptor(tag: "addFileNameType", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_add_filenametype_", comment: ""))
  145. row.value = CCUtility.getFileNameType(NCGlobal.shared.keyFileNameType)
  146. row.hidden = "$\("maintainOriginalFileName") == 1"
  147. row.cellConfig["backgroundColor"] = cellBackgoundColor
  148. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  149. row.cellConfig["textLabel.textColor"] = NCBrandColor.shared.label
  150. section.addFormRow(row)
  151. // Section: Rename File Name
  152. section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_filename_", comment: ""))
  153. form.addFormSection(section)
  154. row = XLFormRowDescriptor(tag: "maskFileName", rowType: XLFormRowDescriptorTypeAccount, title: (NSLocalizedString("_filename_", comment: "")))
  155. let fileNameMask : String = CCUtility.getFileNameMask(NCGlobal.shared.keyFileNameMask)
  156. if fileNameMask.count > 0 {
  157. row.value = fileNameMask
  158. }
  159. row.hidden = "$\("maintainOriginalFileName") == 1"
  160. row.cellConfig["backgroundColor"] = cellBackgoundColor
  161. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  162. row.cellConfig["textLabel.textColor"] = NCBrandColor.shared.label
  163. row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
  164. row.cellConfig["textField.font"] = UIFont.systemFont(ofSize: 15.0)
  165. row.cellConfig["textField.textColor"] = NCBrandColor.shared.label
  166. section.addFormRow(row)
  167. // Section: Preview File Name
  168. row = XLFormRowDescriptor(tag: "previewFileName", rowType: XLFormRowDescriptorTypeTextView, title: "")
  169. row.height = 180
  170. row.disabled = true
  171. row.cellConfig["backgroundColor"] = cellBackgoundColor
  172. row.cellConfig["textView.backgroundColor"] = cellBackgoundColor
  173. row.cellConfig["textView.font"] = UIFont.systemFont(ofSize: 14.0)
  174. row.cellConfig["textView.textColor"] = NCBrandColor.shared.label
  175. section.addFormRow(row)
  176. self.form = form
  177. }
  178. override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
  179. super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
  180. if formRow.tag == "useFolderAutoUpload" {
  181. if (formRow.value! as AnyObject).boolValue == true {
  182. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  183. buttonDestinationFolder.hidden = true
  184. } else{
  185. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  186. buttonDestinationFolder.hidden = false
  187. }
  188. }
  189. else if formRow.tag == "useSubFolder" {
  190. if (formRow.value! as AnyObject).boolValue == true {
  191. } else{
  192. }
  193. }
  194. else if formRow.tag == "maintainOriginalFileName" {
  195. CCUtility.setOriginalFileName((formRow.value! as AnyObject).boolValue, key: NCGlobal.shared.keyFileNameOriginal)
  196. self.reloadForm()
  197. }
  198. else if formRow.tag == "addFileNameType" {
  199. CCUtility.setFileNameType((formRow.value! as AnyObject).boolValue, key: NCGlobal.shared.keyFileNameType)
  200. self.reloadForm()
  201. }
  202. else if formRow.tag == "maskFileName" {
  203. let fileName = formRow.value as? String
  204. self.form.delegate = nil
  205. if let fileName = fileName {
  206. formRow.value = CCUtility.removeForbiddenCharactersServer(fileName)
  207. }
  208. self.form.delegate = self
  209. let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
  210. previewFileName.value = self.previewFileName(valueRename: formRow.value as? String)
  211. // reload cell
  212. if fileName != nil {
  213. if newValue as! String != formRow.value as! String {
  214. self.reloadFormRow(formRow)
  215. NCContentPresenter.shared.messageNotification("_info_", description: "_forbidden_characters_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.errorCharactersForbidden, forced: true)
  216. }
  217. }
  218. self.reloadFormRow(previewFileName)
  219. }
  220. }
  221. func reloadForm() {
  222. self.form.delegate = nil
  223. let buttonDestinationFolder : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  224. buttonDestinationFolder.title = self.titleServerUrl
  225. let maskFileName : XLFormRowDescriptor = self.form.formRow(withTag: "maskFileName")!
  226. let previewFileName : XLFormRowDescriptor = self.form.formRow(withTag: "previewFileName")!
  227. previewFileName.value = self.previewFileName(valueRename: maskFileName.value as? String)
  228. self.tableView.reloadData()
  229. self.form.delegate = self
  230. }
  231. // MARK: - Action
  232. func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], overwrite: Bool, copy: Bool, move: Bool) {
  233. if serverUrl != nil {
  234. self.serverUrl = serverUrl!
  235. if serverUrl == NCUtilityFileSystem.shared.getHomeServer(urlBase: appDelegate.urlBase, account: appDelegate.account) {
  236. self.titleServerUrl = "/"
  237. } else {
  238. if let tableDirectory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account
  239. , self.serverUrl)) {
  240. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(tableDirectory.ocId) {
  241. titleServerUrl = metadata.fileNameView
  242. } else { titleServerUrl = (self.serverUrl as NSString).lastPathComponent }
  243. } else { titleServerUrl = (self.serverUrl as NSString).lastPathComponent }
  244. }
  245. // Update
  246. let row : XLFormRowDescriptor = self.form.formRow(withTag: "ButtonDestinationFolder")!
  247. row.title = self.titleServerUrl
  248. self.updateFormRow(row)
  249. }
  250. }
  251. /*
  252. func save() {
  253. self.dismiss(animated: true, completion: {
  254. let useFolderPhotoRow : XLFormRowDescriptor = self.form.formRow(withTag: "useFolderAutoUpload")!
  255. let useSubFolderRow : XLFormRowDescriptor = self.form.formRow(withTag: "useSubFolder")!
  256. var useSubFolder : Bool = false
  257. if (useFolderPhotoRow.value! as AnyObject).boolValue == true {
  258. self.serverUrl = NCManageDatabase.shared.getAccountAutoUploadPath(urlBase: self.appDelegate.urlBase, account: self.appDelegate.account)
  259. useSubFolder = (useSubFolderRow.value! as AnyObject).boolValue
  260. }
  261. self.appDelegate.activeMain.uploadFileAsset(self.assets, serverUrl: self.serverUrl, useSubFolder: useSubFolder, session: self.session)
  262. })
  263. }
  264. */
  265. @objc func save() {
  266. DispatchQueue.global().async {
  267. let useFolderPhotoRow: XLFormRowDescriptor = self.form.formRow(withTag: "useFolderAutoUpload")!
  268. let useSubFolderRow: XLFormRowDescriptor = self.form.formRow(withTag: "useSubFolder")!
  269. var useSubFolder: Bool = false
  270. var metadatasMOV: [tableMetadata] = []
  271. var metadatasNOConflict: [tableMetadata] = []
  272. var metadatasUploadInConflict: [tableMetadata] = []
  273. if (useFolderPhotoRow.value! as AnyObject).boolValue == true {
  274. self.serverUrl = NCManageDatabase.shared.getAccountAutoUploadPath(urlBase: self.appDelegate.urlBase, account: self.appDelegate.account)
  275. useSubFolder = (useSubFolderRow.value! as AnyObject).boolValue
  276. }
  277. let autoUploadPath = NCManageDatabase.shared.getAccountAutoUploadPath(urlBase: self.appDelegate.urlBase, account: self.appDelegate.account)
  278. if autoUploadPath == self.serverUrl {
  279. if !NCNetworking.shared.createFolder(assets: self.assets, selector: NCGlobal.shared.selectorUploadFile, useSubFolder: useSubFolder, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase) {
  280. NCContentPresenter.shared.messageNotification("_error_", description: "_error_createsubfolders_upload_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorInternalError, forced: true)
  281. return
  282. }
  283. }
  284. for asset in self.assets {
  285. var serverUrl = self.serverUrl
  286. var livePhoto: Bool = false
  287. let fileName = CCUtility.createFileName(asset.value(forKey: "filename") as? String, fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: NCGlobal.shared.keyFileNameMask, keyFileNameType: NCGlobal.shared.keyFileNameType, keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal, forcedNewFileName: false)!
  288. let assetDate = asset.creationDate ?? Date()
  289. let dateFormatter = DateFormatter()
  290. // Detect LivePhoto Upload
  291. if asset.mediaSubtypes.contains(.photoLive) && CCUtility.getLivePhoto() {
  292. livePhoto = true
  293. }
  294. // Create serverUrl if use sub folder
  295. if useSubFolder {
  296. dateFormatter.dateFormat = "yyyy"
  297. let yearString = dateFormatter.string(from: assetDate)
  298. dateFormatter.dateFormat = "MM"
  299. let monthString = dateFormatter.string(from: assetDate)
  300. serverUrl = autoUploadPath + "/" + yearString + "/" + monthString
  301. }
  302. // Check if is in upload
  303. let isRecordInSessions = NCManageDatabase.shared.getAdvancedMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@ AND session != ''", self.appDelegate.account, serverUrl, fileName), sorted: "fileName", ascending: false)
  304. if isRecordInSessions.count > 0 {
  305. continue
  306. }
  307. let metadataForUpload = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, fileName: fileName, fileNameView: fileName, ocId: NSUUID().uuidString, serverUrl: serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", livePhoto: livePhoto, chunk: false)
  308. metadataForUpload.assetLocalIdentifier = asset.localIdentifier
  309. metadataForUpload.session = self.session
  310. metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
  311. metadataForUpload.size = NCUtilityFileSystem.shared.getFileSize(asset: asset)
  312. metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
  313. if livePhoto {
  314. let fileNameMove = (fileName as NSString).deletingPathExtension + ".mov"
  315. let ocId = NSUUID().uuidString
  316. let filePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameMove)!
  317. let semaphore = Semaphore()
  318. CCUtility.extractLivePhotoAsset(asset, filePath: filePath) { (url) in
  319. if let url = url {
  320. let fileSize = NCUtilityFileSystem.shared.getFileSize(filePath: url.path)
  321. let metadataMOVForUpload = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, fileName: fileNameMove, fileNameView: fileNameMove, ocId:ocId, serverUrl: serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", livePhoto: livePhoto, chunk: false)
  322. metadataForUpload.livePhoto = true
  323. metadataMOVForUpload.livePhoto = true
  324. metadataMOVForUpload.session = self.session
  325. metadataMOVForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
  326. metadataMOVForUpload.size = fileSize
  327. metadataMOVForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
  328. metadataMOVForUpload.typeFile = NCGlobal.shared.metadataTypeFileVideo
  329. metadatasMOV.append(metadataMOVForUpload)
  330. }
  331. semaphore.continue()
  332. }
  333. semaphore.wait()
  334. }
  335. if NCManageDatabase.shared.getMetadataConflict(account: self.appDelegate.account, serverUrl: serverUrl, fileName: fileName) != nil {
  336. metadatasUploadInConflict.append(metadataForUpload)
  337. } else {
  338. metadatasNOConflict.append(metadataForUpload)
  339. }
  340. }
  341. // Verify if file(s) exists
  342. if metadatasUploadInConflict.count > 0 {
  343. DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
  344. if let conflict = UIStoryboard.init(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict {
  345. conflict.serverUrl = self.serverUrl
  346. conflict.metadatasNOConflict = metadatasNOConflict
  347. conflict.metadatasMOV = metadatasMOV
  348. conflict.metadatasUploadInConflict = metadatasUploadInConflict
  349. self.appDelegate.window?.rootViewController?.present(conflict, animated: true, completion: nil)
  350. }
  351. }
  352. } else {
  353. self.appDelegate.networkingProcessUpload?.createProcessUploads(metadatas: metadatasNOConflict)
  354. self.appDelegate.networkingProcessUpload?.createProcessUploads(metadatas: metadatasMOV)
  355. }
  356. DispatchQueue.main.async {self.dismiss(animated: true, completion: nil) }
  357. }
  358. }
  359. @objc func cancel() {
  360. self.dismiss(animated: true, completion: nil)
  361. }
  362. // MARK: - Utility
  363. func previewFileName(valueRename : String?) -> String {
  364. var returnString: String = ""
  365. let asset = assets[0]
  366. if (CCUtility.getOriginalFileName(NCGlobal.shared.keyFileNameOriginal)) {
  367. return (NSLocalizedString("_filename_", comment: "") + ": " + (asset.value(forKey: "filename") as! String))
  368. } else if let valueRename = valueRename {
  369. let valueRenameTrimming = valueRename.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
  370. if valueRenameTrimming.count > 0 {
  371. self.form.delegate = nil
  372. CCUtility.setFileNameMask(valueRename, key: NCGlobal.shared.keyFileNameMask)
  373. self.form.delegate = self
  374. returnString = CCUtility.createFileName(asset.value(forKey: "filename") as! String?, fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: NCGlobal.shared.keyFileNameMask, keyFileNameType: NCGlobal.shared.keyFileNameType, keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal, forcedNewFileName: false)
  375. } else {
  376. CCUtility.setFileNameMask("", key: NCGlobal.shared.keyFileNameMask)
  377. returnString = CCUtility.createFileName(asset.value(forKey: "filename") as! String?, fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: nil, keyFileNameType: NCGlobal.shared.keyFileNameType, keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal, forcedNewFileName: false)
  378. }
  379. } else {
  380. CCUtility.setFileNameMask("", key: NCGlobal.shared.keyFileNameMask)
  381. returnString = CCUtility.createFileName(asset.value(forKey: "filename") as! String?, fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: nil, keyFileNameType: NCGlobal.shared.keyFileNameType, keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal, forcedNewFileName: false)
  382. }
  383. return String(format: NSLocalizedString("_preview_filename_", comment: ""), "MM, MMM, DD, YY, YYYY, HH, hh, mm, ss, ampm") + ":" + "\n\n" + returnString
  384. }
  385. @objc func changeDestinationFolder(_ sender: XLFormRowDescriptor) {
  386. self.deselectFormRow(sender)
  387. let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
  388. let navigationController = storyboard.instantiateInitialViewController() as! UINavigationController
  389. let viewController = navigationController.topViewController as! NCSelect
  390. viewController.delegate = self
  391. viewController.typeOfCommandView = .selectCreateFolder
  392. viewController.includeDirectoryE2EEncryption = true
  393. self.present(navigationController, animated: true, completion: nil)
  394. }
  395. }