NCCreateFormUploadAssets.swift 25 KB

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