NCCreateFormUploadAssets.swift 26 KB

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