Ferrite-backup/Ferrite/Extensions/URL.swift
kingbri e3e8924547 Ferrite: Add backups and massive cleanup
Backups in Ferrite archive a user's bookmarks, history, source lists,
and source names. Sources are not archived due to the size of the backup
increasing exponentially.

These files use the .feb format to avoid JSON conflicts when opening
the file in Ferrite. The backup file can be renamed to JSON for editing
at any time.

Add the Backport namespace to be used for ported features rather
than making a file for every iOS 14 adaptation.

Move history and bookmark creation to the PersistenceController rather
than individual functions.

Signed-off-by: kingbri <bdashore3@proton.me>
2022-11-06 20:54:45 -05:00

29 lines
918 B
Swift

//
// URL.swift
// Ferrite
//
// Created by Brian Dashore on 9/20/22.
//
import Foundation
extension URL {
// From https://github.com/Aidoku/Aidoku/blob/main/Shared/Extensions/FileManager.swift
// Used for FileManager
var contentsByDateAdded: [URL] {
if let urls = try? FileManager.default.contentsOfDirectory(
at: self,
includingPropertiesForKeys: [.contentModificationDateKey]
) {
return urls.sorted {
((try? $0.resourceValues(forKeys: [.addedToDirectoryDateKey]))?.addedToDirectoryDate ?? Date.distantPast)
>
((try? $1.resourceValues(forKeys: [.addedToDirectoryDateKey]))?.addedToDirectoryDate ?? Date.distantPast)
}
}
let contents = try? FileManager.default.contentsOfDirectory(at: self, includingPropertiesForKeys: nil)
return contents ?? []
}
}