Skip to content

Commit

Permalink
Merge pull request #682 from glouel/master
Browse files Browse the repository at this point in the history
Tentative fix for poi crash
  • Loading branch information
glouel authored Dec 3, 2018
2 parents 2bbe5e2 + 9cd2114 commit 3327fe4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Aerial/Source/Models/Cache/PoiStringProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
70 changes: 39 additions & 31 deletions Aerial/Source/Models/Cache/VideoCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion Aerial/Source/Models/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.6beta5</string>
<string>1.4.6beta6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.4.6beta5</string>
<string>1.4.6beta6</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit 3327fe4

Please sign in to comment.