mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 10:55:30 -04:00
Sort entries and titles when they needed
This commit is contained in:
parent
4e8b561f70
commit
a8f729f5c1
@ -92,6 +92,7 @@ class Title
|
|||||||
@id = id
|
@id = id
|
||||||
@mtime = File.info(@dir).modification_time
|
@mtime = File.info(@dir).modification_time
|
||||||
|
|
||||||
|
previous_titles_size = @title_ids.size
|
||||||
@title_ids.select! do |title_id|
|
@title_ids.select! do |title_id|
|
||||||
title = Library.default.get_title! title_id
|
title = Library.default.get_title! title_id
|
||||||
title.examine
|
title.examine
|
||||||
@ -101,9 +102,12 @@ class Title
|
|||||||
title.dir
|
title.dir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
previous_entries_size = @entries.size
|
||||||
@entries.select! { |entry| File.exists? entry.zip_path }
|
@entries.select! { |entry| File.exists? entry.zip_path }
|
||||||
remained_entry_zip_paths = @entries.map &.zip_path
|
remained_entry_zip_paths = @entries.map &.zip_path
|
||||||
|
|
||||||
|
is_titles_added = false
|
||||||
|
is_entries_added = false
|
||||||
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
|
||||||
@ -113,12 +117,16 @@ 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
|
||||||
|
is_titles_added = true
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
if is_supported_file path
|
if is_supported_file path
|
||||||
next if remained_entry_zip_paths.includes? path
|
next if remained_entry_zip_paths.includes? path
|
||||||
entry = Entry.new path, self
|
entry = Entry.new path, self
|
||||||
@entries << entry if entry.pages > 0 || entry.err_msg
|
if entry.pages > 0 || entry.err_msg
|
||||||
|
@entries << entry
|
||||||
|
is_entries_added = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -127,14 +135,18 @@ class Title
|
|||||||
mtimes += @entries.map &.mtime
|
mtimes += @entries.map &.mtime
|
||||||
@mtime = mtimes.max
|
@mtime = mtimes.max
|
||||||
|
|
||||||
|
if is_titles_added || previous_titles_size != @title_ids.size
|
||||||
@title_ids.sort! do |a, b|
|
@title_ids.sort! do |a, b|
|
||||||
compare_numerically Library.default.title_hash[a].title,
|
compare_numerically Library.default.title_hash[a].title,
|
||||||
Library.default.title_hash[b].title
|
Library.default.title_hash[b].title
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
if is_entries_added || previous_entries_size != @entries.size
|
||||||
sorter = ChapterSorter.new @entries.map &.title
|
sorter = ChapterSorter.new @entries.map &.title
|
||||||
@entries.sort! do |a, b|
|
@entries.sort! do |a, b|
|
||||||
sorter.compare a.title, b.title
|
sorter.compare a.title, b.title
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return true # this could be recycled
|
return true # this could be recycled
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user