From 4ac7b60313bbb95924aeafb1d3d7a2f8f08b0a1e Mon Sep 17 00:00:00 2001 From: Guillaume Louel Date: Wed, 21 Nov 2018 18:35:29 +0100 Subject: [PATCH 1/2] Tentative switch to /Library/Caches --- Aerial/Source/Models/Cache/VideoCache.swift | 70 ++++++++++++--------- Resources/Info.plist | 2 +- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/Aerial/Source/Models/Cache/VideoCache.swift b/Aerial/Source/Models/Cache/VideoCache.swift index 8443de17..8178136b 100644 --- a/Aerial/Source/Models/Cache/VideoCache.swift +++ b/Aerial/Source/Models/Cache/VideoCache.swift @@ -29,53 +29,61 @@ final class VideoCache { let preferences = Preferences.sharedInstance if let customCacheDirectory = preferences.customCacheDirectory { + // We may have overriden the cache directory cacheDirectory = customCacheDirectory } else { - let cachePaths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, + let localCachePaths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, + .localDomainMask, + true) + let userCachePaths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true) - if cachePaths.isEmpty { + if localCachePaths.isEmpty || userCachePaths.isEmpty { errorLog("Couldn't find cache paths!") return nil } - var userCacheDirectory: NSString? - userCacheDirectory = cachePaths[0] as NSString - - if cachePaths.count > 1 { - // Maybe on some systems we have more than one, if so try to find one that actually exists ? - for cachePath in cachePaths { - if FileManager.default.fileExists(atPath: cachePath) { - debugLog("using this directory") - userCacheDirectory = cachePath as NSString - break + let localCacheDirectory = localCachePaths[0] as NSString + let userCacheDirectory = userCachePaths[0] as NSString + + if aerialCacheExists(at: localCacheDirectory) { + debugLog("local cache exists") + cacheDirectory = localCacheDirectory.appendingPathComponent("Aerial") + } else if aerialCacheExists(at: userCacheDirectory) { + debugLog("user cache exists") + cacheDirectory = userCacheDirectory.appendingPathComponent("Aerial") + } else { + debugLog("create local cache") + // We create in local cache directory (/Library/Caches) + cacheDirectory = localCacheDirectory.appendingPathComponent("Aerial") + + let fileManager = FileManager.default + if fileManager.fileExists(atPath: cacheDirectory!) == false { + do { + try fileManager.createDirectory(atPath: cacheDirectory!, + withIntermediateDirectories: false, attributes: nil) + } catch let error { + errorLog("Couldn't create cache directory: \(error)") + return nil } } } - - let defaultCacheDirectory = userCacheDirectory!.appendingPathComponent("Aerial") - cacheDirectory = defaultCacheDirectory } - guard let appCacheDirectory = cacheDirectory else { - return nil - } + // Cache the computed value + computedCacheDirectory = cacheDirectory + debugLog("cache to be used : \(String(describing: cacheDirectory))") + return cacheDirectory + } - let fileManager = FileManager.default - if fileManager.fileExists(atPath: appCacheDirectory as String) == false { - do { - try fileManager.createDirectory(atPath: appCacheDirectory as String, - withIntermediateDirectories: false, attributes: nil) - } catch let error { - errorLog("Couldn't create cache directory: \(error)") - return nil - } + static func aerialCacheExists(at: NSString) -> Bool { + let aerialCache = at.appendingPathComponent("Aerial") + if FileManager.default.fileExists(atPath: aerialCache as String) { + return true + } else { + return false } - - // Cache the computed value - computedCacheDirectory = appCacheDirectory - return appCacheDirectory } static func isAvailableOffline(video: AerialVideo) -> Bool { diff --git a/Resources/Info.plist b/Resources/Info.plist index 703112eb..c0f82d7d 100644 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.4.6beta5 + 1.4.6test6 CFBundleSignature ???? CFBundleVersion From 9cd2114bb058fdd9346b51ab32371c0301e1fdd2 Mon Sep 17 00:00:00 2001 From: Guillaume Louel Date: Mon, 3 Dec 2018 20:38:44 +0100 Subject: [PATCH 2/2] beta6 with tentative fix for poi crash when looking for a missing json --- Aerial/Source/Models/Cache/PoiStringProvider.swift | 2 +- Aerial/Source/Models/ManifestLoader.swift | 4 +++- Resources/Info.plist | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Aerial/Source/Models/Cache/PoiStringProvider.swift b/Aerial/Source/Models/Cache/PoiStringProvider.swift index ef349280..752dc474 100644 --- a/Aerial/Source/Models/Cache/PoiStringProvider.swift +++ b/Aerial/Source/Models/Cache/PoiStringProvider.swift @@ -160,7 +160,7 @@ final class PoiStringProvider { } } debugLog("Defaulting to bundle") - let cc = locale.countryCode!.lowercased() + let cc = "en" //locale.countryCode!.lowercased() if preferences.localizeDescriptions { let path = Bundle(for: PoiStringProvider.self).path(forResource: cc, ofType: "json") if path != nil { diff --git a/Aerial/Source/Models/ManifestLoader.swift b/Aerial/Source/Models/ManifestLoader.swift index 51bf2148..1ad08c4f 100644 --- a/Aerial/Source/Models/ManifestLoader.swift +++ b/Aerial/Source/Models/ManifestLoader.swift @@ -312,6 +312,7 @@ class ManifestLoader { dateFormatter.locale = Locale.init(identifier: "en_GB") let dateObj = dateFormatter.date(from: preferences.lastVideoCheck!) + debugLog(preferences.lastVideoCheck!) var dayCheck = 7 if preferences.newVideosMode == Preferences.NewVideosMode.monthly.rawValue { dayCheck = 30 @@ -324,6 +325,7 @@ class ManifestLoader { if #available(OSX 10.11, *) { if !cacheUrl.hasDirectoryPath { + // If there's no backup directory, we force the first check moveOldManifests() return } @@ -333,7 +335,7 @@ class ManifestLoader { debugLog("Interval : \(String(describing: dateObj?.timeIntervalSinceNow))") if Int((dateObj?.timeIntervalSinceNow)!) < -dayCheck * 86400 { - // We need to redownload + // We need to redownload then debugLog("Checking for new videos") moveOldManifests() } else { diff --git a/Resources/Info.plist b/Resources/Info.plist index c0f82d7d..74554035 100644 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.4.6test6 + 1.4.6beta6 CFBundleSignature ???? CFBundleVersion - 1.4.6beta5 + 1.4.6beta6 LSApplicationCategoryType LSMinimumSystemVersion