From 2b21404ad69afb31b79f5b4e28deba7cc8de63e0 Mon Sep 17 00:00:00 2001 From: shootingstar Date: Sat, 16 May 2026 21:38:21 +0900 Subject: [PATCH] Fix loadSwiftData fileExists path / URL-string mismatch --- VideoPaper/ContentView.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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) + } }