西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴(lài)的軟件下載站!
西西首頁(yè) 電腦軟件 安卓軟件 電腦游戲 安卓游戲 排行榜 專(zhuān)題合集

高速iDuel卡圖下載工具

  • 高速iDuel卡圖下載工具
  • 軟件大小:422KB
  • 更新時(shí)間:2013-11-01 15:30
  • 軟件語(yǔ)言:中文
  • 軟件廠商:
  • 軟件類(lèi)別:國(guó)產(chǎn)軟件 / 免費(fèi)軟件 / 下載工具
  • 軟件等級(jí):4級(jí)
  • 應(yīng)用平臺(tái):WinAll, WinXP
  • 官方網(wǎng)站:http://www.innovatechautomation.com
  • 應(yīng)用備案:
好評(píng):50%
壞評(píng):50%

軟件介紹

iDuel自帶的卡圖下載工具慢到不能忍...于是自己寫(xiě)了個(gè)
只有一個(gè)功能 就是下載/更新卡圖
下載速度應(yīng)該能占滿(mǎn)帶寬

需要放到 OCG聯(lián)網(wǎng)決斗模擬軟件(iDuel) 目錄下。

http://www.innovatechautomation.com/soft/71354.html

實(shí)現(xiàn)代碼:

#encoding: UTF-8
if !File.file? 'data/allcards.dll'
puts "請(qǐng)放到iDuel目錄下運(yùn)行"
exit
end

cards = IO.readlines('data/allcards.dll').size / 2
puts "卡片總計(jì) #{cards} 張"

if File.file? 'data/config.ini'
require 'inifile'
config = IniFile.new IO.read('data/config.ini', mode: 'rb:BOM|UTF-16LE:UTF-8')
path = config['Config'] && config['Config']['CardImagePath']
end

if !path or !File.directory? path
require 'win32/registry'
path = Win32::Registry::HKEY_CURRENT_USER.open('Software\OCGSOFT\Cards') { |reg| reg['Path'] } rescue ''
path.force_encoding(Encoding::GBK).encode!(Encoding::UTF_8)
end

if !path or !File.directory? path
Dir.mkdir 'data' unless File.directory? 'data'
path = 'data/image'
end

puts "本地卡圖路徑 #{path}"
Dir.mkdir path unless File.directory? path

def batch_download(main_url, files, content_type=nil)
connections = {}
count = {total: files.size, error: 0}
[10*100, files.size].min.times { do_download(main_url, files, content_type, count, connections) }
end

def do_download(main_url, files, content_type, count, connections)
if connections.size < 10
connection = EventMachine::HttpRequest.new(main_url)
connections[connection] = 0
else
connection = connections.min_by { |key, value| value }
if connection[1] >= 100
return
else
connection = connection[0]
end
end
remote_path, local_path = files.shift
connections[connection] += 1
connection.get(path: remote_path, keepalive: connections[connection] != 100).callback { |http|
puts File.basename local_path
count[:error] = 0
count[:total] -= 1
if http.response_header['CONNECTION'] != 'keep-alive'
connection.close
connections.delete(connection)
do_download(main_url, files, content_type, count, connections) while !files.empty? and (connections.size < 10 or connections.values.min < 100)
end

if http.response_header.status == 200 and (!content_type or http.response_header['CONTENT_TYPE'] == content_type)
IO.binwrite local_path, http.response
else
puts http.response_header.http_status
end

if count[:total].zero?
connections.each_key { |connection| connection.close }
connections.clear
puts 'all done'
EM.stop
end
}.errback { |http|
puts http.error
connection.close
connections.delete(connection)
files[remote_path] = local_path
count[:error] += 1
if count[:error] <= 10*100
do_download(main_url, files, content_type, count, connections) while !files.empty? and (connections.size < 10 or connections.values.min < 100)
else
connections.each_key { |connection| connection.close }
connections.clear
puts 'network error'
EM.stop
end
}
end

cards_to_download = (1..cards).to_a - Dir.glob(File.expand_path '*.jpg', path).collect { |file| File.basename(file, '.jpg').to_i }


puts "需要下載 #{cards_to_download.size} 張"

exit if cards_to_download.empty?

#monkey patch for exerb & addressable
if defined? ExerbRuntime
require 'stringio'
module Addressable
module IDNA
module File
class <<self
def join(*args)
end
def expand_path(*args)
end
def dirname(*args)
end
def open(*args)
result = ExerbRuntime.open('unicode.data')
if block_given?
begin
yield result
ensure
result.close
end
end
end
end
end
end
end
end

require 'em-http-request'
EventMachine.run do
http = EventMachine::HttpRequest.new('http://p.ocgsoft.cn/:osid.jpg').get redirects: 10
http.callback { |http|
main_url = http.last_effective_url
puts "獲取卡圖下載地址: #{main_url}"
files = {}
cards_to_download.each { |card_id| files[main_url.path.gsub(':osid', card_id.to_s)] = File.join(path, card_id.to_s + '.jpg') }
batch_download(main_url.to_s, files, 'image/jpeg')
}
end

軟件標(biāo)簽: iDuel

其他版本下載

最新評(píng)論查看所有(1)條評(píng)論 >

第 1 樓 西班牙 網(wǎng)友 客人 2013/9/4 18:18:23
這個(gè)是iDuel下載卡圖的嗎,用過(guò)了確實(shí)比自帶的快多了。

支持( 0 ) 蓋樓(回復(fù))

發(fā)表評(píng)論

昵稱(chēng):
表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
查看所有(1)條評(píng)論 > 字?jǐn)?shù): 0/500

TOP
軟件下載