Skip to content

Commit

Permalink
Fix singleton
Browse files Browse the repository at this point in the history
Signed-off-by: Milen Pivchev <[email protected]>
  • Loading branch information
mpivchev committed Jan 31, 2025
1 parent 2548164 commit 4ed6bf4
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Share/NCShareExtension+DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension NCShareExtension: UICollectionViewDelegate {
showAlert(title: "_info_", description: "_e2e_goto_settings_for_enable_")
}

if let fileNameError = FileNameValidator.shared.checkFileName(metadata.fileNameView, account: session.account) {
if let fileNameError = FileNameValidator.checkFileName(metadata.fileNameView, account: session.account) {
present(UIAlertController.warning(message: "\(fileNameError.errorDescription) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true)
return
}
Expand Down
4 changes: 2 additions & 2 deletions Share/NCShareExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,13 @@ extension NCShareExtension {
var invalidNameIndexes: [Int] = []

for (index, fileName) in filesName.enumerated() {
let newFileName = FileAutoRenamer.shared.rename(fileName, account: session.account)
let newFileName = FileAutoRenamer.rename(fileName, account: session.account)

if fileName != newFileName {
renameFile(oldName: fileName, newName: newFileName, account: session.account)
}

if let fileNameError = FileNameValidator.shared.checkFileName(newFileName, account: session.account) {
if let fileNameError = FileNameValidator.checkFileName(newFileName, account: session.account) {
if filesName.count == 1 {
showRenameFileDialog(named: fileName, account: account)
return
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/DeepLink/NCDeepLinkHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class NCDeepLinkHandler {
let fileFolderPath = NCUtilityFileSystem().getFileNamePath("", serverUrl: serverUrl, session: session)
let fileFolderName = (serverUrl as NSString).lastPathComponent

if !FileNameValidator.shared.checkFolderPath(fileFolderPath, account: controller.account) {
if !FileNameValidator.checkFolderPath(fileFolderPath, account: controller.account) {
controller.present(UIAlertController.warning(message: "\(String(format: NSLocalizedString("_file_name_validator_error_reserved_name_", comment: ""), fileFolderName)) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true)

return
Expand Down
10 changes: 5 additions & 5 deletions iOSClient/Extensions/UIAlertController+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ extension UIAlertController {
queue: .main) { _ in
guard let text = alertController.textFields?.first?.text else { return }
let folderName = text.trimmingCharacters(in: .whitespaces)
let isFileHidden = FileNameValidator.shared.isFileHidden(text)
let textCheck = FileNameValidator.shared.checkFileName(folderName, account: session.account)
let isFileHidden = FileNameValidator.isFileHidden(text)
let textCheck = FileNameValidator.checkFileName(folderName, account: session.account)

okAction.isEnabled = !text.isEmpty && textCheck?.error == nil

Expand Down Expand Up @@ -206,7 +206,7 @@ extension UIAlertController {
let oldExtension = fileName.fileExtension

let text = alertController.textFields?.first?.text ?? ""
let textCheck = FileNameValidator.shared.checkFileName(text, account: account)
let textCheck = FileNameValidator.checkFileName(text, account: account)
var message = textCheck?.error.localizedDescription ?? ""
var messageColor = UIColor.red

Expand Down Expand Up @@ -236,8 +236,8 @@ extension UIAlertController {
guard let text = alertController.textFields?.first?.text else { return }
let newExtension = text.fileExtension

let textCheck = FileNameValidator.shared.checkFileName(text, account: account)
let isFileHidden = FileNameValidator.shared.isFileHidden(text)
let textCheck = FileNameValidator.checkFileName(text, account: account)
let isFileHidden = FileNameValidator.isFileHidden(text)

okAction.isEnabled = !text.isEmpty && textCheck?.error == nil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct NCUploadAssetsView: View {
}
}
.onChange(of: renameFileName) { newValue in
if let error = FileNameValidator.shared.checkFileName(newValue, account: model.controller?.account) {
if let error = FileNameValidator.checkFileName(newValue, account: model.controller?.account) {
renameError = error.errorDescription
} else {
renameError = ""
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Main/NCActionCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
var listViewController = [NCSelect]()
var copyItems: [tableMetadata] = []
for item in items {
if let fileNameError = FileNameValidator.shared.checkFileName(item.fileNameView, account: controller?.account) {
if let fileNameError = FileNameValidator.checkFileName(item.fileNameView, account: controller?.account) {
controller?.present(UIAlertController.warning(message: "\(fileNameError.errorDescription) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true)
return
}
Expand Down
6 changes: 3 additions & 3 deletions iOSClient/Main/NCDragDrop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class NCDragDrop: NSObject {
let session = NCSession.shared.getSession(controller: controller)

for (index, metadata) in metadatas.enumerated() {
if let fileNameError = FileNameValidator.shared.checkFileName(metadata.fileName, account: session.account) {
if let fileNameError = FileNameValidator.checkFileName(metadata.fileName, account: session.account) {
if metadatas.count == 1 {
let alert = UIAlertController.renameFile(metadata: metadata) { newFileName in
metadatas[index].fileName = newFileName
Expand Down Expand Up @@ -125,10 +125,10 @@ class NCDragDrop: NSObject {
Task {
let ocId = NSUUID().uuidString
let session = NCSession.shared.getSession(controller: controller)
let newFileName = FileAutoRenamer.shared.rename(url.lastPathComponent, account: session.account)
let newFileName = FileAutoRenamer.rename(url.lastPathComponent, account: session.account)
let fileNamePath = utilityFileSystem.getDirectoryProviderStorageOcId(ocId, fileNameView: newFileName)

if let fileNameError = FileNameValidator.shared.checkFileName(newFileName, account: session.account) {
if let fileNameError = FileNameValidator.checkFileName(newFileName, account: session.account) {
await controller?.present(UIAlertController.warning(message: "\(fileNameError.errorDescription) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true)
return
}
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Main/NCMainTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class NCMainTabBar: UITabBar {
let fileFolderPath = NCUtilityFileSystem().getFileNamePath("", serverUrl: serverUrl, session: NCSession.shared.getSession(controller: controller))
let fileFolderName = (serverUrl as NSString).lastPathComponent

if !FileNameValidator.shared.checkFolderPath(fileFolderPath, account: controller.account) {
if !FileNameValidator.checkFolderPath(fileFolderPath, account: controller.account) {
controller.present(UIAlertController.warning(message: "\(String(format: NSLocalizedString("_file_name_validator_error_reserved_name_", comment: ""), fileFolderName)) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true)

return
Expand Down
6 changes: 3 additions & 3 deletions iOSClient/Main/NCPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate {
metadata.classFile = NKCommon.TypeClassFile.video.rawValue
}

if let fileNameError = FileNameValidator.shared.checkFileName(metadata.fileNameView, account: self.controller.account) {
if let fileNameError = FileNameValidator.checkFileName(metadata.fileNameView, account: self.controller.account) {
self.controller.present(UIAlertController.warning(message: "\(fileNameError.errorDescription) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true)
} else {
database.addMetadata(metadata)
Expand All @@ -168,7 +168,7 @@ class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate {
for urlIn in urls {
let ocId = NSUUID().uuidString
let fileName = urlIn.lastPathComponent
let newFileName = FileAutoRenamer.shared.rename(fileName, account: session.account)
let newFileName = FileAutoRenamer.rename(fileName, account: session.account)

let toPath = utilityFileSystem.getDirectoryProviderStorageOcId(ocId, fileNameView: newFileName)
let urlOut = URL(fileURLWithPath: toPath)
Expand Down Expand Up @@ -200,7 +200,7 @@ class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate {
var invalidNameIndexes: [Int] = []

for (index, metadata) in metadatas.enumerated() {
if let fileNameError = FileNameValidator.shared.checkFileName(metadata.fileName, account: session.account) {
if let fileNameError = FileNameValidator.checkFileName(metadata.fileName, account: session.account) {
if metadatas.count == 1 {
let alert = UIAlertController.renameFile(fileName: metadata.fileName, account: session.account) { newFileName in
metadatas[index].fileName = newFileName
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Menu/NCMenuAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ extension NCMenuAction {
for metadata in selectedMetadatas {
if let sceneIdentifier = metadata.sceneIdentifier,
let controller = SceneManager.shared.getController(sceneIdentifier: sceneIdentifier),
let checkError = FileNameValidator.shared.checkFileName(metadata.fileNameView, account: controller.account) {
let checkError = FileNameValidator.checkFileName(metadata.fileNameView, account: controller.account) {

fileNameError = checkError
break
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Scan document/NCUploadScanDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ struct UploadScanDocumentView: View {
.onChange(of: fileName) { _ in
let controller = (UIApplication.shared.firstWindow?.rootViewController as? NCMainTabBarController)

if let fileNameError = FileNameValidator.shared.checkFileName(fileName, account: controller?.account) {
if let fileNameError = FileNameValidator.checkFileName(fileName, account: controller?.account) {
footer = fileNameError.errorDescription
} else {
footer = ""
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Select/NCSelect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
super.viewDidAppear(animated)
let folderPath = utilityFileSystem.getFileNamePath("", serverUrl: serverUrl, session: session)

if serverUrl.isEmpty || !FileNameValidator.shared.checkFolderPath(folderPath, account: session.account) {
if serverUrl.isEmpty || !FileNameValidator.checkFolderPath(folderPath, account: session.account) {
serverUrl = utilityFileSystem.getHomeServer(session: session)
titleCurrentFolder = NCBrandOptions.shared.brand
}
Expand Down Expand Up @@ -254,7 +254,7 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
viewController.serverUrl = serverUrlPush
viewController.session = session

if let fileNameError = FileNameValidator.shared.checkFileName(metadata.fileNameView, account: session.account) {
if let fileNameError = FileNameValidator.checkFileName(metadata.fileNameView, account: session.account) {
present(UIAlertController.warning(message: "\(fileNameError.errorDescription) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true)
} else {
navigationController?.pushViewController(viewController, animated: true)
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Utility/FileAutoRenamer+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import NextcloudKit

extension FileAutoRenamer {
func rename(_ filename: String, isFolderPath: Bool = false, account: String?) -> String {
static func rename(_ filename: String, isFolderPath: Bool = false, account: String?) -> String {
let capabilities = NCCapabilities.shared.getCapabilities(account: account)
let autoRenamer = FileAutoRenamer(forbiddenFileNameCharacters: capabilities.capabilityForbiddenFileNameCharacters, forbiddenFileNameExtensions: capabilities.capabilityForbiddenFileNameExtensions)
return autoRenamer.rename(filename: filename, isFolderPath: isFolderPath)
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Utility/FileNameValidator+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import NextcloudKit

extension FileNameValidator {
func checkFileName(_ filename: String, account: String?) -> NKError? {
static func checkFileName(_ filename: String, account: String?) -> NKError? {
let capabilities = NCCapabilities.shared.getCapabilities(account: account)
let fileNameValidator = FileNameValidator(forbiddenFileNames: capabilities.capabilityForbiddenFileNames, forbiddenFileNameBasenames: capabilities.capabilityForbiddenFileNameBasenames, forbiddenFileNameCharacters: capabilities.capabilityForbiddenFileNameCharacters, forbiddenFileNameExtensions: capabilities.capabilityForbiddenFileNameExtensions)
return fileNameValidator.checkFileName(filename)
}

func checkFolderPath(_ folderPath: String, account: String?) -> Bool {
static func checkFolderPath(_ folderPath: String, account: String?) -> Bool {
let capabilities = NCCapabilities.shared.getCapabilities(account: account)
let fileNameValidator = FileNameValidator(forbiddenFileNames: capabilities.capabilityForbiddenFileNames, forbiddenFileNameBasenames: capabilities.capabilityForbiddenFileNameBasenames, forbiddenFileNameCharacters: capabilities.capabilityForbiddenFileNameCharacters, forbiddenFileNameExtensions: capabilities.capabilityForbiddenFileNameExtensions)
return fileNameValidator.checkFolderPath(folderPath)
Expand Down

0 comments on commit 4ed6bf4

Please sign in to comment.