Commit 64a41a1a authored by 神楽坂玲奈's avatar 神楽坂玲奈

版本0.4.6 正式

parent 1674f8de
require 'open-uri' require 'open-uri'
require_relative 'card'
module Update module Update
Version = '0.4.6' Version = '0.4.6'
URL = 'http://card.touhou.cc/mycard/update.json?version=0.4.6' URL = 'http://card.touhou.cc/mycard/update.json?version=0.4.6'
...@@ -27,7 +28,7 @@ module Update ...@@ -27,7 +28,7 @@ module Update
end end
if @updated if @updated
IO.popen('./mycard') IO.popen('./mycard')
exit $scene = nil
end end
@status = '正在检查更新' @status = '正在检查更新'
Thread.new do Thread.new do
...@@ -76,36 +77,69 @@ module Update ...@@ -76,36 +77,69 @@ module Update
end end
end end
@images -= existed_images @images -= existed_images
$log.info('待下载的完整卡图'){@images.inspect} existed_images = []
threads = 5.times.collect do if !@images.empty? and File.file?("#{Card::PicPath}/1.jpg")
thread = Thread.new do db_mycard = SQLite3::Database.new( "data/data.sqlite" )
while number = @thumbnails.pop can_link = true
@status.replace "正在下载缩略卡图 (剩余#{@thumbnails.size}张)" db_mycard.execute( "select id, number from `yu-gi-oh` where number in (#{@images.collect{|number|"%08d" % number}.join(',')})" ) do |row|
open("http://card.touhou.cc/images/cards/ygocore/thumbnail/#{number}.jpg", 'rb') do |remote| id = row[0]
next if File.file? "ygocore/pics/thumbnail/#{number}.jpg" number = row[1].to_i
open("ygocore/pics/thumbnail/#{number}.jpg", 'wb') do |local| existed_images << number
local.write remote.read src = "#{Card::PicPath}/#{id}.jpg"
dest = "ygocore/pics/#{number}.jpg"
if File.file?(src) and !File.file?(dest)
@status.replace "检测到存在iDuel卡图 正在导入 #{id}.jpg"
if can_link
begin
File.link(src, dest)
rescue
can_link = false
redo
end end
end rescue nil else
end open(src, 'rb') do |src|
while number = @images.pop open(dest, 'wb') do |dest|
@status.replace "正在下载完整卡图 (剩余#{@images.size}张)" dest.write src.read
open("http://card.touhou.cc/images/cards/ygocore/#{number}.jpg", 'rb') do |remote| end
next if File.file? "ygocore/pics/#{number}.jpg"
open("ygocore/pics/#{number}.jpg", 'wb') do |local|
local.write remote.read
end end
end rescue nil end
end end
end
end
@images -= existed_images
@thumbnails = (@thumbnails & @images) + (@thumbnails - @images)
unless @thumbnails.empty? and @images.empty?
$log.info('待下载的完整卡图'){@images.inspect}
threads = 5.times.collect do
thread = Thread.new do
while number = @thumbnails.pop
@status.replace "正在下载缩略卡图 (剩余#{@thumbnails.size}张)"
open("http://card.touhou.cc/images/cards/ygocore/thumbnail/#{number}.jpg", 'rb') do |remote|
next if File.file? "ygocore/pics/thumbnail/#{number}.jpg"
open("ygocore/pics/thumbnail/#{number}.jpg", 'wb') do |local|
local.write remote.read
end
end rescue nil
end
while number = @images.pop
@status.replace "正在下载完整卡图 (剩余#{@images.size}张)"
open("http://card.touhou.cc/images/cards/ygocore/#{number}.jpg", 'rb') do |remote|
next if File.file? "ygocore/pics/#{number}.jpg"
open("ygocore/pics/#{number}.jpg", 'wb') do |local|
local.write remote.read
end
end rescue nil
end
end
thread.priority = -1
thread
end end
thread.priority = -1 threads.each{|thread|thread.join}
thread
end end
threads.each{|thread|thread.join}
end end
end rescue nil end rescue nil
@status = nil @status = nil
end end.priority = -1
end end
end end
end end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment