mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -04:00
Initial work on title signature
This commit is contained in:
parent
44336c546a
commit
18e8e88c66
@ -3,7 +3,7 @@ require "../archive"
|
|||||||
class Title
|
class Title
|
||||||
getter dir : String, parent_id : String, title_ids : Array(String),
|
getter dir : String, parent_id : String, title_ids : Array(String),
|
||||||
entries : Array(Entry), title : String, id : String,
|
entries : Array(Entry), title : String, id : String,
|
||||||
encoded_title : String, mtime : Time
|
encoded_title : String, mtime : Time, signature : UInt64 = 0
|
||||||
|
|
||||||
@entry_display_name_cache : Hash(String, String)?
|
@entry_display_name_cache : Hash(String, String)?
|
||||||
|
|
||||||
@ -25,6 +25,8 @@ class Title
|
|||||||
@entries = [] of Entry
|
@entries = [] of Entry
|
||||||
@mtime = File.info(dir).modification_time
|
@mtime = File.info(dir).modification_time
|
||||||
|
|
||||||
|
signatures = [] of UInt64
|
||||||
|
|
||||||
Dir.entries(dir).each do |fn|
|
Dir.entries(dir).each do |fn|
|
||||||
next if fn.starts_with? "."
|
next if fn.starts_with? "."
|
||||||
path = File.join dir, fn
|
path = File.join dir, fn
|
||||||
@ -33,14 +35,18 @@ class Title
|
|||||||
next if title.entries.size == 0 && title.titles.size == 0
|
next if title.entries.size == 0 && title.titles.size == 0
|
||||||
Library.default.title_hash[title.id] = title
|
Library.default.title_hash[title.id] = title
|
||||||
@title_ids << title.id
|
@title_ids << title.id
|
||||||
|
signatures << title.signature
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
if [".zip", ".cbz", ".rar", ".cbr"].includes? File.extname path
|
if [".zip", ".cbz", ".rar", ".cbr"].includes? File.extname path
|
||||||
entry = Entry.new path, self
|
entry = Entry.new path, self
|
||||||
@entries << entry if entry.pages > 0 || entry.err_msg
|
@entries << entry if entry.pages > 0 || entry.err_msg
|
||||||
|
signatures << File.size entry.zip_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@signature = Digest::CRC32.checksum(signatures.sort.join "").to_u64
|
||||||
|
|
||||||
mtimes = [@mtime]
|
mtimes = [@mtime]
|
||||||
mtimes += @title_ids.map { |e| Library.default.title_hash[e].mtime }
|
mtimes += @title_ids.map { |e| Library.default.title_hash[e].mtime }
|
||||||
mtimes += @entries.map { |e| e.mtime }
|
mtimes += @entries.map { |e| e.mtime }
|
||||||
@ -61,6 +67,7 @@ class Title
|
|||||||
{% for str in ["dir", "title", "id"] %}
|
{% for str in ["dir", "title", "id"] %}
|
||||||
json.field {{str}}, @{{str.id}}
|
json.field {{str}}, @{{str.id}}
|
||||||
{% end %}
|
{% end %}
|
||||||
|
json.field "signature" { json.number @signature }
|
||||||
json.field "display_name", display_name
|
json.field "display_name", display_name
|
||||||
json.field "cover_url", cover_url
|
json.field "cover_url", cover_url
|
||||||
json.field "mtime" { json.number @mtime.to_unix }
|
json.field "mtime" { json.number @mtime.to_unix }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user