NCCreateFormUploadAssets.swift 26 KB

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