fix crash because currentPage and currentChapter were yet to be set
This commit is contained in:
@@ -251,11 +251,11 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
try String(
|
try String(
|
||||||
contentsOfFile: currentPath.appendingPathComponent("state.json").path
|
contentsOfFile: currentPath.appendingPathComponent("state.json").path
|
||||||
).utf8)
|
).utf8)
|
||||||
let l = try JSONDecoder().decode(LocalState.self, from: json)
|
let local = try JSONDecoder().decode(LocalState.self, from: json)
|
||||||
currentPage = l.page
|
currentPage = local.page
|
||||||
currentChapter = l.chapter
|
currentChapter = local.chapter
|
||||||
mode = l.turnMode
|
mode = local.turnMode
|
||||||
readerView.backgroundColor = convertStringToColor(str: l.backgroundColor)
|
readerView.backgroundColor = convertStringToColor(str: local.backgroundColor)
|
||||||
} catch {
|
} catch {
|
||||||
print("failed to load local state")
|
print("failed to load local state")
|
||||||
}
|
}
|
||||||
@@ -693,8 +693,8 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
info.text = """
|
info.text = """
|
||||||
\(metadata.title)
|
\(metadata.title)
|
||||||
\(metadata.chapters[currentChapter - 1].title)
|
\(metadata.chapters[currentChapter - 1].title)
|
||||||
Volume \(Int(metadata.chapters[currentChapter - 1].volume)) of \(Int(metadata.chapters.last!.volume))
|
Volume \(Int(metadata.chapters[currentChapter - 1].volume)) of \(Int(metadata.last_volume))
|
||||||
Chapter \(currentChapter!) of \(Int(metadata.chapters.last!.chapter))
|
Chapter \(currentChapter!) of \(Int(metadata.last_chapter))
|
||||||
Page \(currentPage!) of \(metadata.chapters[currentChapter - 1].pages)
|
Page \(currentPage!) of \(metadata.chapters[currentChapter - 1].pages)
|
||||||
Image size: \(Int(imageView.image!.size.width))x\(Int(imageView.image!.size.height))
|
Image size: \(Int(imageView.image!.size.width))x\(Int(imageView.image!.size.height))
|
||||||
"""
|
"""
|
||||||
@@ -814,7 +814,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
let ps: [String] = try fileManager.contentsOfDirectory(atPath: dir.path).sorted()
|
let ps: [String] = try fileManager.contentsOfDirectory(atPath: dir.path).sorted()
|
||||||
let current = dir.appendingPathComponent(ps[0])
|
let current = dir.appendingPathComponent(ps[0])
|
||||||
imageView.image = UIImage(contentsOfFile: current.path)
|
imageView.image = UIImage(contentsOfFile: current.path)
|
||||||
updateInfo()
|
|
||||||
|
|
||||||
let path_meta = current.lastPathComponent.components(separatedBy: "_")
|
let path_meta = current.lastPathComponent.components(separatedBy: "_")
|
||||||
assert(path_meta[0] == "chapter")
|
assert(path_meta[0] == "chapter")
|
||||||
@@ -829,6 +828,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
|||||||
assert(path_meta[2] == "image")
|
assert(path_meta[2] == "image")
|
||||||
currentPage = Int(path_meta[3].components(separatedBy: ".")[0])! + 1
|
currentPage = Int(path_meta[3].components(separatedBy: ".")[0])! + 1
|
||||||
}
|
}
|
||||||
|
updateInfo()
|
||||||
} catch {
|
} catch {
|
||||||
print("failed to set images")
|
print("failed to set images")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user