Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/nextcloud/ios into 2399-…
Browse files Browse the repository at this point in the history
…aspect-ratio-in-media-view

Signed-off-by: Milen Pivchev <[email protected]>

# Conflicts:
#	Nextcloud.xcodeproj/project.pbxproj
#	iOSClient/Media/NCMediaCache.swift
#	iOSClient/Supporting Files/hu.lproj/Localizable.strings
  • Loading branch information
mpivchev committed Oct 30, 2023
2 parents fcbbb8a + 5aab90c commit caeaa76
Show file tree
Hide file tree
Showing 225 changed files with 1,809 additions and 2,421 deletions.
2 changes: 1 addition & 1 deletion Brand/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ import Foundation
// Database Realm
//
let databaseName = "nextcloud.realm"
let databaseSchemaVersion: UInt64 = 320
let databaseSchemaVersion: UInt64 = 321
16 changes: 7 additions & 9 deletions File Provider Extension/FileProviderData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ class fileProviderData: NSObject {
}

// LOG
if let pathDirectoryGroup = CCUtility.getDirectoryGroup()?.path {
NextcloudKit.shared.nkCommonInstance.pathLog = pathDirectoryGroup
let levelLog = CCUtility.getLogLevel()
NextcloudKit.shared.nkCommonInstance.levelLog = levelLog
let version = NSString(format: NCBrandOptions.shared.textCopyrightNextcloudiOS as NSString, NCUtility.shared.getVersionApp()) as String
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Start File Provider session with level \(levelLog) " + version + " (File Provider Extension)")
}
NextcloudKit.shared.nkCommonInstance.pathLog = NCUtilityFileSystem.shared.directoryGroup
let levelLog = NCKeychain().logLevel
NextcloudKit.shared.nkCommonInstance.levelLog = levelLog
let version = NSString(format: NCBrandOptions.shared.textCopyrightNextcloudiOS as NSString, NCUtility.shared.getVersionApp()) as String
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Start File Provider session with level \(levelLog) " + version + " (File Provider Extension)")

// NO DOMAIN -> Set default account
if domain == nil {
Expand All @@ -93,7 +91,7 @@ class fileProviderData: NSObject {

NCManageDatabase.shared.setCapabilities(account: account)

NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: NCKeychain().getPassword(account: activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
NCNetworking.shared.delegate = providerExtension as? NCNetworkingDelegate

return tableAccount.init(value: activeAccount)
Expand All @@ -117,7 +115,7 @@ class fileProviderData: NSObject {

NCManageDatabase.shared.setCapabilities(account: account)

NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: NCKeychain().getPassword(account: activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
NCNetworking.shared.delegate = providerExtension as? NCNetworkingDelegate

return tableAccount.init(value: activeAccount)
Expand Down
4 changes: 2 additions & 2 deletions File Provider Extension/FileProviderEnumerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
directoryEtag = tableDirectory.etag
}

NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "0", showHiddenFiles: CCUtility.getShowHiddenFiles()) { account, files, _, error in
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "0", showHiddenFiles: NCKeychain().showHiddenFiles) { account, files, _, error in

if directoryEtag != files.first?.etag {

NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: CCUtility.getShowHiddenFiles()) { account, files, _, error in
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: NCKeychain().showHiddenFiles) { account, files, _, error in

if error == .success {
DispatchQueue.global().async {
Expand Down
16 changes: 8 additions & 8 deletions File Provider Extension/FileProviderExtension+Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension FileProviderExtension {

if error == .success {

NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: CCUtility.getShowHiddenFiles()) { _, files, _, error in
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: NCKeychain().showHiddenFiles) { _, files, _, error in

if error == .success, let file = files.first {

Expand Down Expand Up @@ -92,16 +92,16 @@ extension FileProviderExtension {

if error == .success { // || error == kOCErrorServerPathNotFound {

let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(itemIdentifier.rawValue)!
let fileNamePath = NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(itemIdentifier.rawValue)
do {
try fileProviderUtility.shared.fileManager.removeItem(atPath: fileNamePath)
} catch let error {
print("error: \(error)")
}

if isDirectory {
let dirForDelete = CCUtility.stringAppendServerUrl(serverUrl, addFileName: fileName)
NCManageDatabase.shared.deleteDirectoryAndSubDirectory(serverUrl: dirForDelete!, account: account)
let dirForDelete = NCUtilityFileSystem.shared.stringAppendServerUrl(serverUrl, addFileName: fileName)
NCManageDatabase.shared.deleteDirectoryAndSubDirectory(serverUrl: dirForDelete, account: account)
}

NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocId))
Expand Down Expand Up @@ -201,11 +201,11 @@ extension FileProviderExtension {
let itemIdentifier = fileProviderUtility.shared.getItemIdentifier(metadata: metadata)

// rename file
_ = fileProviderUtility.shared.moveFile(CCUtility.getDirectoryProviderStorageOcId(itemIdentifier.rawValue, fileNameView: fileNameFrom), toPath: CCUtility.getDirectoryProviderStorageOcId(itemIdentifier.rawValue, fileNameView: itemName))
_ = fileProviderUtility.shared.moveFile(NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(itemIdentifier.rawValue, fileNameView: fileNameFrom), toPath: NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(itemIdentifier.rawValue, fileNameView: itemName))

_ = fileProviderUtility.shared.moveFile(CCUtility.getDirectoryProviderStoragePreviewOcId(itemIdentifier.rawValue, etag: metadata.etag), toPath: CCUtility.getDirectoryProviderStoragePreviewOcId(itemIdentifier.rawValue, etag: metadata.etag))
_ = fileProviderUtility.shared.moveFile(NCUtilityFileSystem.shared.getDirectoryProviderStoragePreviewOcId(itemIdentifier.rawValue, etag: metadata.etag), toPath: NCUtilityFileSystem.shared.getDirectoryProviderStoragePreviewOcId(itemIdentifier.rawValue, etag: metadata.etag))

_ = fileProviderUtility.shared.moveFile(CCUtility.getDirectoryProviderStorageIconOcId(itemIdentifier.rawValue, etag: metadata.etag), toPath: CCUtility.getDirectoryProviderStorageIconOcId(itemIdentifier.rawValue, etag: metadata.etag))
_ = fileProviderUtility.shared.moveFile(NCUtilityFileSystem.shared.getDirectoryProviderStorageIconOcId(itemIdentifier.rawValue, etag: metadata.etag), toPath: NCUtilityFileSystem.shared.getDirectoryProviderStorageIconOcId(itemIdentifier.rawValue, etag: metadata.etag))

NCManageDatabase.shared.setLocalFile(ocId: ocId, fileName: itemName, etag: nil)
}
Expand Down Expand Up @@ -245,7 +245,7 @@ extension FileProviderExtension {
}

if (favorite == true && metadata.favorite == false) || (favorite == false && metadata.favorite == true) {
let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId, account: metadata.account)!
let fileNamePath = NCUtilityFileSystem.shared.getFileNamePath(metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId)

NextcloudKit.shared.setFavorite(fileName: fileNamePath, favorite: favorite) { _, error in

Expand Down
4 changes: 2 additions & 2 deletions File Provider Extension/FileProviderExtension+Thumbnail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ extension FileProviderExtension {

if metadata.hasPreview {

let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId, account: metadata.account)!
let fileNameIconLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)!
let fileNamePath = NCUtilityFileSystem.shared.getFileNamePath(metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId)
let fileNameIconLocalPath = NCUtilityFileSystem.shared.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)

if let urlBase = metadata.urlBase.urlEncoded,
let fileNamePath = fileNamePath.urlEncoded,
Expand Down
30 changes: 15 additions & 15 deletions File Provider Extension/FileProviderExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
super.init()

// Create directory File Provider Storage
CCUtility.getDirectoryProviderStorage()
_ = NCUtilityFileSystem.shared.directoryProviderStorage
// Configure URLSession
_ = NCNetworking.shared.sessionManagerBackgroundExtension
}
Expand All @@ -78,9 +78,9 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
if containerItemIdentifier != NSFileProviderItemIdentifier.workingSet {
if fileProviderData.shared.setupAccount(domain: domain, providerExtension: self) == nil {
throw NSError(domain: NSFileProviderErrorDomain, code: NSFileProviderError.notAuthenticated.rawValue, userInfo: [:])
} else if let passcode = CCUtility.getPasscode(), !passcode.isEmpty, CCUtility.isPasscodeAtStartEnabled() {
} else if NCKeychain().passcode != nil, NCKeychain().requestPasscodeAtStart {
throw NSError(domain: NSFileProviderErrorDomain, code: NSFileProviderError.notAuthenticated.rawValue, userInfo: ["code": NSNumber(value: NCGlobal.shared.errorUnauthorizedFilesPasscode)])
} else if CCUtility.getDisableFilesApp() || NCBrandOptions.shared.disable_openin_file {
} else if NCKeychain().disableFilesApp || NCBrandOptions.shared.disable_openin_file {
throw NSError(domain: NSFileProviderErrorDomain, code: NSFileProviderError.notAuthenticated.rawValue, userInfo: ["code": NSNumber(value: NCGlobal.shared.errorDisableFilesApp)])
}
}
Expand Down Expand Up @@ -204,12 +204,12 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
}

let tableLocalFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
if tableLocalFile != nil && CCUtility.fileProviderStorageExists(metadata) && tableLocalFile?.etag == metadata.etag {
if tableLocalFile != nil && NCUtilityFileSystem.shared.fileProviderStorageExists(metadata) && tableLocalFile?.etag == metadata.etag {
return completionHandler(nil)
}

let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileName)!
let fileNameLocalPath = NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileName)

// Update status
NCManageDatabase.shared.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusDownloading)
Expand Down Expand Up @@ -274,9 +274,9 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
// Temp ocId ?
if outstandingOcIdTemp[ocId] != nil && outstandingOcIdTemp[ocId] != ocId {
ocId = outstandingOcIdTemp[ocId]!
let atPath = CCUtility.getDirectoryProviderStorageOcId(itemIdentifier.rawValue, fileNameView: fileName)
let toPath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)
CCUtility.copyFile(atPath: atPath, toPath: toPath)
let atPath = NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(itemIdentifier.rawValue, fileNameView: fileName)
let toPath = NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)
NCUtilityFileSystem.shared.copyFile(atPath: atPath, toPath: toPath)
}
guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return }

Expand Down Expand Up @@ -348,7 +348,7 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
let ocIdTemp = NSUUID().uuidString.lowercased()

NSFileCoordinator().coordinate(readingItemAt: fileURL, options: .withoutChanges, error: &error) { url in
_ = fileProviderUtility.shared.copyFile(url.path, toPath: CCUtility.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: fileName))
_ = fileProviderUtility.shared.copyFile(url.path, toPath: NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: fileName))
}

fileURL.stopAccessingSecurityScopedResource()
Expand All @@ -361,7 +361,7 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
NCManageDatabase.shared.addMetadata(metadata)

let serverUrlFileName = tableDirectory.serverUrl + "/" + fileName
let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: fileName)!
let fileNameLocalPath = NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: fileName)

if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: nil, dateModificationFile: nil, description: ocIdTemp, session: NCNetworking.shared.sessionManagerBackgroundExtension) {

Expand All @@ -383,7 +383,7 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
guard let metadataTemp = NCManageDatabase.shared.getMetadataFromOcId(ocIdTemp) else { return }
let metadata = tableMetadata.init(value: metadataTemp)

let url = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: fileName))
let url = URL(fileURLWithPath: NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: fileName))
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.outstandingSessionTasks.removeValue(forKey: url)
}
Expand Down Expand Up @@ -411,14 +411,14 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
NCManageDatabase.shared.addLocalFile(metadata: metadata)

// New file
if ocId != ocIdTemp {
if let ocId, ocId != ocIdTemp {

NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))

// File system
let atPath = CCUtility.getDirectoryProviderStorageOcId(ocIdTemp)
let toPath = CCUtility.getDirectoryProviderStorageOcId(ocId)
CCUtility.copyFile(atPath: atPath, toPath: toPath)
let atPath = NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(ocIdTemp)
let toPath = NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(ocId)
NCUtilityFileSystem.shared.copyFile(atPath: atPath, toPath: toPath)
}

fileProviderData.shared.signalEnumerator(ocId: metadata.ocId, update: true)
Expand Down
2 changes: 1 addition & 1 deletion File Provider Extension/FileProviderItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class FileProviderItem: NSObject, NSFileProviderItem {
if metadata.directory {
return true
}
if CCUtility.fileProviderStorageExists(metadata) {
if NCUtilityFileSystem.shared.fileProviderStorageExists(metadata) {
return true
} else {
return false
Expand Down
4 changes: 2 additions & 2 deletions File Provider Extension/FileProviderUtility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class fileProviderUtility: NSObject {
let itemIdentifier = getItemIdentifier(metadata: metadata)

if metadata.directory {
CCUtility.getDirectoryProviderStorageOcId(itemIdentifier.rawValue)
_ = NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(itemIdentifier.rawValue)
} else {
CCUtility.getDirectoryProviderStorageOcId(itemIdentifier.rawValue, fileNameView: metadata.fileNameView)
NCUtilityFileSystem.shared.getDirectoryProviderStorageOcId(itemIdentifier.rawValue, fileNameView: metadata.fileNameView)
}
}

Expand Down
Loading

0 comments on commit caeaa76

Please sign in to comment.