|
@@ -43,97 +43,74 @@ class NCUtilityFileSystem: NSObject {
|
|
}
|
|
}
|
|
|
|
|
|
var directoryCertificates: String {
|
|
var directoryCertificates: String {
|
|
- if let directoryGroup = fileManager.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroups) {
|
|
|
|
- let path = directoryGroup.appendingPathComponent(NCGlobal.shared.appCertificates).path
|
|
|
|
- if !fileManager.fileExists(atPath: path) {
|
|
|
|
- do {
|
|
|
|
- try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
|
|
- } catch {
|
|
|
|
- return ""
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return path
|
|
|
|
|
|
+ guard let directoryGroup = fileManager.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroups) else { return "" }
|
|
|
|
+ let path = directoryGroup.appendingPathComponent(NCGlobal.shared.appCertificates).path
|
|
|
|
+ if !fileManager.fileExists(atPath: path) {
|
|
|
|
+ do {
|
|
|
|
+ try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
|
|
+ } catch { print("Error: \(error)") }
|
|
}
|
|
}
|
|
- return ""
|
|
|
|
|
|
+ return path
|
|
}
|
|
}
|
|
|
|
|
|
var directoryUserData: String {
|
|
var directoryUserData: String {
|
|
- if let directoryGroup = fileManager.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroups) {
|
|
|
|
- let path = directoryGroup.appendingPathComponent(NCGlobal.shared.appUserData).path
|
|
|
|
- if !fileManager.fileExists(atPath: path) {
|
|
|
|
- do {
|
|
|
|
- try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
|
|
- } catch {
|
|
|
|
- return ""
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return path
|
|
|
|
|
|
+ guard let directoryGroup = fileManager.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroups) else { return "" }
|
|
|
|
+ let path = directoryGroup.appendingPathComponent(NCGlobal.shared.appUserData).path
|
|
|
|
+ if !fileManager.fileExists(atPath: path) {
|
|
|
|
+ do {
|
|
|
|
+ try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
|
|
+ } catch { print("Error: \(error)") }
|
|
}
|
|
}
|
|
- return ""
|
|
|
|
|
|
+ return path
|
|
}
|
|
}
|
|
|
|
|
|
@objc var directoryProviderStorage: String {
|
|
@objc var directoryProviderStorage: String {
|
|
- if let directoryGroup = fileManager.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroups) {
|
|
|
|
- let path = directoryGroup.appendingPathComponent(NCGlobal.shared.directoryProviderStorage).path
|
|
|
|
- if !fileManager.fileExists(atPath: path) {
|
|
|
|
- do {
|
|
|
|
- try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
|
|
- } catch {
|
|
|
|
- return ""
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return path
|
|
|
|
|
|
+ guard let directoryGroup = fileManager.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroups) else { return "" }
|
|
|
|
+ let path = directoryGroup.appendingPathComponent(NCGlobal.shared.directoryProviderStorage).path
|
|
|
|
+ if !fileManager.fileExists(atPath: path) {
|
|
|
|
+ do {
|
|
|
|
+ try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
|
|
+ } catch { print("Error: \(error)") }
|
|
}
|
|
}
|
|
- return ""
|
|
|
|
|
|
+ return path
|
|
}
|
|
}
|
|
|
|
|
|
@objc func getDirectoryProviderStorageOcId(_ ocId: String) -> String {
|
|
@objc func getDirectoryProviderStorageOcId(_ ocId: String) -> String {
|
|
-
|
|
|
|
let path = directoryProviderStorage + "/" + ocId
|
|
let path = directoryProviderStorage + "/" + ocId
|
|
if !fileManager.fileExists(atPath: path) {
|
|
if !fileManager.fileExists(atPath: path) {
|
|
do {
|
|
do {
|
|
try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
- } catch {
|
|
|
|
- return ""
|
|
|
|
- }
|
|
|
|
|
|
+ } catch { print("Error: \(error)") }
|
|
}
|
|
}
|
|
return path
|
|
return path
|
|
}
|
|
}
|
|
|
|
|
|
@objc func getDirectoryProviderStorageOcId(_ ocId: String, fileNameView: String) -> String {
|
|
@objc func getDirectoryProviderStorageOcId(_ ocId: String, fileNameView: String) -> String {
|
|
-
|
|
|
|
let path = directoryProviderStorage + "/" + ocId + "/" + fileNameView
|
|
let path = directoryProviderStorage + "/" + ocId + "/" + fileNameView
|
|
if !fileManager.fileExists(atPath: path) {
|
|
if !fileManager.fileExists(atPath: path) {
|
|
do {
|
|
do {
|
|
try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true)
|
|
- } catch {
|
|
|
|
- return ""
|
|
|
|
- }
|
|
|
|
|
|
+ } catch { print("Error: \(error)") }
|
|
}
|
|
}
|
|
return path
|
|
return path
|
|
}
|
|
}
|
|
|
|
|
|
func getDirectoryProviderStorageIconOcId(_ ocId: String, etag: String) -> String {
|
|
func getDirectoryProviderStorageIconOcId(_ ocId: String, etag: String) -> String {
|
|
-
|
|
|
|
return directoryProviderStorage + "/" + ocId + "/" + etag + ".small." + NCGlobal.shared.extensionPreview
|
|
return directoryProviderStorage + "/" + ocId + "/" + etag + ".small." + NCGlobal.shared.extensionPreview
|
|
}
|
|
}
|
|
|
|
|
|
func getDirectoryProviderStoragePreviewOcId(_ ocId: String, etag: String) -> String {
|
|
func getDirectoryProviderStoragePreviewOcId(_ ocId: String, etag: String) -> String {
|
|
-
|
|
|
|
return directoryProviderStorage + "/" + ocId + "/" + etag + ".preview." + NCGlobal.shared.extensionPreview
|
|
return directoryProviderStorage + "/" + ocId + "/" + etag + ".preview." + NCGlobal.shared.extensionPreview
|
|
}
|
|
}
|
|
|
|
|
|
func fileProviderStorageExists(_ metadata: tableMetadata) -> Bool {
|
|
func fileProviderStorageExists(_ metadata: tableMetadata) -> Bool {
|
|
-
|
|
|
|
let fileNamePath = getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileName)
|
|
let fileNamePath = getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileName)
|
|
let fileNameViewPath = getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)
|
|
let fileNameViewPath = getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)
|
|
-
|
|
|
|
do {
|
|
do {
|
|
let fileNameAttribute = try fileManager.attributesOfItem(atPath: fileNamePath)
|
|
let fileNameAttribute = try fileManager.attributesOfItem(atPath: fileNamePath)
|
|
let fileNameSize: UInt64 = fileNameAttribute[FileAttributeKey.size] as? UInt64 ?? 0
|
|
let fileNameSize: UInt64 = fileNameAttribute[FileAttributeKey.size] as? UInt64 ?? 0
|
|
let fileNameViewAttribute = try fileManager.attributesOfItem(atPath: fileNameViewPath)
|
|
let fileNameViewAttribute = try fileManager.attributesOfItem(atPath: fileNameViewPath)
|
|
let fileNameViewSize: UInt64 = fileNameViewAttribute[FileAttributeKey.size] as? UInt64 ?? 0
|
|
let fileNameViewSize: UInt64 = fileNameViewAttribute[FileAttributeKey.size] as? UInt64 ?? 0
|
|
-
|
|
|
|
if metadata.isDirectoryE2EE == true {
|
|
if metadata.isDirectoryE2EE == true {
|
|
if (fileNameSize == metadata.size || fileNameViewSize == metadata.size) && fileNameViewSize > 0 {
|
|
if (fileNameSize == metadata.size || fileNameViewSize == metadata.size) && fileNameViewSize > 0 {
|
|
return true
|
|
return true
|
|
@@ -144,28 +121,22 @@ class NCUtilityFileSystem: NSObject {
|
|
return fileNameViewSize == metadata.size
|
|
return fileNameViewSize == metadata.size
|
|
}
|
|
}
|
|
} catch { print("Error: \(error)") }
|
|
} catch { print("Error: \(error)") }
|
|
-
|
|
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
|
|
func fileProviderStorageSize(_ ocId: String, fileNameView: String) -> UInt64 {
|
|
func fileProviderStorageSize(_ ocId: String, fileNameView: String) -> UInt64 {
|
|
-
|
|
|
|
let fileNamePath = getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView)
|
|
let fileNamePath = getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView)
|
|
-
|
|
|
|
do {
|
|
do {
|
|
let fileNameAttribute = try fileManager.attributesOfItem(atPath: fileNamePath)
|
|
let fileNameAttribute = try fileManager.attributesOfItem(atPath: fileNamePath)
|
|
let fileNameSize: UInt64 = fileNameAttribute[FileAttributeKey.size] as? UInt64 ?? 0
|
|
let fileNameSize: UInt64 = fileNameAttribute[FileAttributeKey.size] as? UInt64 ?? 0
|
|
return fileNameSize
|
|
return fileNameSize
|
|
} catch { print("Error: \(error)") }
|
|
} catch { print("Error: \(error)") }
|
|
-
|
|
|
|
return 0
|
|
return 0
|
|
}
|
|
}
|
|
|
|
|
|
func fileProviderStoragePreviewIconExists(_ ocId: String, etag: String) -> Bool {
|
|
func fileProviderStoragePreviewIconExists(_ ocId: String, etag: String) -> Bool {
|
|
-
|
|
|
|
let fileNamePathPreview = getDirectoryProviderStoragePreviewOcId(ocId, etag: etag)
|
|
let fileNamePathPreview = getDirectoryProviderStoragePreviewOcId(ocId, etag: etag)
|
|
let fileNamePathIcon = getDirectoryProviderStorageIconOcId(ocId, etag: etag)
|
|
let fileNamePathIcon = getDirectoryProviderStorageIconOcId(ocId, etag: etag)
|
|
-
|
|
|
|
do {
|
|
do {
|
|
let fileNamePathPreviewAttribute = try fileManager.attributesOfItem(atPath: fileNamePathPreview)
|
|
let fileNamePathPreviewAttribute = try fileManager.attributesOfItem(atPath: fileNamePathPreview)
|
|
let fileSizePreview: UInt64 = fileNamePathPreviewAttribute[FileAttributeKey.size] as? UInt64 ?? 0
|
|
let fileSizePreview: UInt64 = fileNamePathPreviewAttribute[FileAttributeKey.size] as? UInt64 ?? 0
|
|
@@ -177,10 +148,14 @@ class NCUtilityFileSystem: NSObject {
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
} catch { print("Error: \(error)") }
|
|
} catch { print("Error: \(error)") }
|
|
-
|
|
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ func createDirectoryStandard() {
|
|
|
|
+
|
|
|
|
+ guard let directoryGroup = fileManager.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroups) else { return }
|
|
|
|
+ }
|
|
|
|
+
|
|
// MARK: -
|
|
// MARK: -
|
|
|
|
|
|
@objc func getFileSize(filePath: String) -> Int64 {
|
|
@objc func getFileSize(filePath: String) -> Int64 {
|