diff --git a/VideoPaper/ContentView.swift b/VideoPaper/ContentView.swift index 0c43739..bf34a13 100644 --- a/VideoPaper/ContentView.swift +++ b/VideoPaper/ContentView.swift @@ -189,8 +189,8 @@ struct ContentView: View { // Add missing Assets for sdAsset in sdAssets where !jsonWallpaperCoordinator.assets.contains(where: { $0.id == sdAsset.id }) { guard let appDir = getApplicationSupportDirectory() else { continue } - - if !FileManager.default.fileExists(atPath: sdAsset.videoURL) { + + if !storedURLStringPointsToExistingFile(sdAsset.videoURL) { do { let newUrl = appDir.appending(path: "\(UUID().uuidString).mov") try sdAsset.video.write(to: newUrl) @@ -199,7 +199,7 @@ struct ContentView: View { print("❌ Swift Data Video Recovery: \(error)") } } - if !FileManager.default.fileExists(atPath: sdAsset.previewImage) { + if !storedURLStringPointsToExistingFile(sdAsset.previewImage) { do { let newUrl = appDir.appending(path: "\(UUID().uuidString).png") try sdAsset.thumbnail.write(to: newUrl) @@ -224,6 +224,11 @@ struct ContentView: View { try? jsonWallpaperCoordinator.saveData() } } + + private func storedURLStringPointsToExistingFile(_ stored: String) -> Bool { + guard let url = URL(string: stored), url.isFileURL else { return false } + return FileManager.default.fileExists(atPath: url.path) + } }