Commit baa7c338 authored by 神楽坂玲奈's avatar 神楽坂玲奈

linux fix

parent 56ed57ec
...@@ -12,16 +12,39 @@ module Association ...@@ -12,16 +12,39 @@ module Association
Win32::Registry::HKEY_CLASSES_ROOT.create('.yrp') { |reg| reg[nil] = 'mycard' } Win32::Registry::HKEY_CLASSES_ROOT.create('.yrp') { |reg| reg[nil] = 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.create('.deck') { |reg| reg[nil] = 'mycard' } Win32::Registry::HKEY_CLASSES_ROOT.create('.deck') { |reg| reg[nil] = 'mycard' }
else else
desktop, x_ygopro_deck, x_ygopro_replay = paths
require 'fileutils' require 'fileutils'
FileUtils.mkdir_p("#{ENV['HOME']}/.local/share/applications") unless File.directory?("#{ENV['HOME']}/.local/share/applications") FileUtils.mkdir_p("#{ENV['HOME']}/.local/share/applications") unless File.directory?("#{ENV['HOME']}/.local/share/applications")
open("#{ENV['HOME']}/.local/share/applications/mycard.desktop", 'w') { |f| f.write <<EOF open("#{ENV['HOME']}/.local/share/applications/mycard.desktop", 'w') { |f| f.write desktop }
FileUtils.mkdir_p("#{ENV['HOME']}/.local/share/mime/packages") unless File.directory?("#{ENV['HOME']}/.local/share/mime/packages")
open("#{ENV['HOME']}/.local/share/mime/packages/application-x-ygopro-deck.xml", 'w') { |f| f.write x_ygopro_deck }
open("#{ENV['HOME']}/.local/share/mime/packages/application-x-ygopro-replay.xml", 'w') { |f| f.write x_ygopro_replay }
system("install -D #{Dir.pwd}/graphics/system/icon.png ~/.icons/application-x-ygopro-deck.png")
system("install -D #{Dir.pwd}/graphics/system/icon.png ~/.icons/application-x-ygopro-replay.png")
system("xdg-mime default mycard.desktop application/x-ygopro-deck application/x-ygopro-replay x-scheme-handler/mycard")
system("update-mime-database #{ENV['HOME']}/.local/share/mime")
system("update-desktop-database #{ENV['HOME']}/.local/share/applications")
end
end
def paths
if Windows
pwd = Dir.pwd.gsub('/', '\\')
path = '"' + pwd + '\ruby\bin\rubyw.exe" -C"' + pwd + '" -KU lib/main.rb'
command = path + ' "%1"'
icon = '"' + pwd + '\mycard.exe", 0'
[path, command, icon]
else
desktop = <<EOF
#!/usr/bin/env xdg-open #!/usr/bin/env xdg-open
[Desktop Entry] [Desktop Entry]
Name=Mycard Name=Mycard
Name[zh_CN]=Mycard - 萌卡 Name[zh_CN]=Mycard - 萌卡
Comment=a card game platform Comment=a card game platform
Comment[zh_CN]=卡片游戏对战客户端 Comment[zh_CN]=卡片游戏对战客户端
Exec=/usr/bin/env ruby -KU lib/main.rb %u Exec=ruby -KU lib/main.rb %u
Terminal=false Terminal=false
Icon=#{Dir.pwd}/graphics/system/icon.png Icon=#{Dir.pwd}/graphics/system/icon.png
Type=Application Type=Application
...@@ -30,9 +53,7 @@ Path=#{Dir.pwd} ...@@ -30,9 +53,7 @@ Path=#{Dir.pwd}
URL=http://my-card.in/ URL=http://my-card.in/
MimeType=x-scheme-handler/mycard;application/x-ygopro-deck;application/x-ygopro-replay' MimeType=x-scheme-handler/mycard;application/x-ygopro-deck;application/x-ygopro-replay'
EOF EOF
} x_ygopro_deck = <<EOF
FileUtils.mkdir_p("#{ENV['HOME']}/.local/share/mime/packages") unless File.directory?("#{ENV['HOME']}/.local/share/mime/packages")
open("#{ENV['HOME']}/.local/share/mime/packages/application-x-ygopro-deck.xml", 'w') { |f| f.write <<EOF
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-ygopro-deck"> <mime-type type="application/x-ygopro-deck">
...@@ -43,8 +64,7 @@ EOF ...@@ -43,8 +64,7 @@ EOF
</mime-type> </mime-type>
</mime-info> </mime-info>
EOF EOF
} x_ygopro_replay = <<EOF
open("#{ENV['HOME']}/.local/share/mime/packages/application-x-ygopro-replay.xml", 'w') { |f| f.write <<EOF
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-ygopro-replay"> <mime-type type="application/x-ygopro-replay">
...@@ -55,23 +75,10 @@ EOF ...@@ -55,23 +75,10 @@ EOF
</mime-type> </mime-type>
</mime-info> </mime-info>
EOF EOF
} [desktop, x_ygopro_deck, x_ygopro_replay]
system("install -D #{Dir.pwd}/graphics/system/icon.png ~/.icons/application-x-ygopro-deck.png")
system("install -D #{Dir.pwd}/graphics/system/icon.png ~/.icons/application-x-ygopro-replay.png")
system("xdg-mime default mycard.desktop application/x-ygopro-deck application/x-ygopro-replay x-scheme-handler/mycard")
system("update-mime-database #{ENV['HOME']}/.local/share/mime")
system("update-desktop-database #{ENV['HOME']}/.local/share/applications")
end end
end end
def paths
pwd = Dir.pwd.gsub('/', '\\')
path = '"' + pwd + '\ruby\bin\rubyw.exe" -C"' + pwd + '" -KU lib/main.rb'
command = path + ' "%1"'
icon = '"' + pwd + '\mycard.exe", 0'
[path, command, icon]
end
def need? def need?
return false if $config['no_assoc'] return false if $config['no_assoc']
if Windows if Windows
...@@ -85,10 +92,18 @@ EOF ...@@ -85,10 +92,18 @@ EOF
Win32::Registry::HKEY_CLASSES_ROOT.open('.yrp') { |reg| return true unless reg[nil] == 'mycard' } Win32::Registry::HKEY_CLASSES_ROOT.open('.yrp') { |reg| return true unless reg[nil] == 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.open('.deck') { |reg| return true unless reg[nil] == 'mycard' } Win32::Registry::HKEY_CLASSES_ROOT.open('.deck') { |reg| return true unless reg[nil] == 'mycard' }
rescue rescue
return true true
end end
else else
true #how to detect? begin
(([IO.read("#{ENV['HOME']}/.local/share/applications/mycard.desktop"),
IO.read("#{ENV['HOME']}/.local/share/mime/packages/application-x-ygopro-deck.xml"),
IO.read("#{ENV['HOME']}/.local/share/mime/packages/application-x-ygopro-replay.xml")] != paths) or !(
File.file?("#{ENV['HOME']}/.icons/application-x-ygopro-deck.png") and
File.file?("#{ENV['HOME']}/.icons/application-x-ygopro-replay.png")))
rescue
true
end
end end
end end
...@@ -107,15 +122,14 @@ EOF ...@@ -107,15 +122,14 @@ EOF
def start def start
if need? if need?
if Windows request do
request do if Windows
require 'rbconfig' require 'rbconfig'
register rescue Dialog.uac(File.join(RbConfig::CONFIG["bindir"],RbConfig::CONFIG["RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"]), "-KU lib/main.rb register_association") register rescue Dialog.uac(File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"]), "-KU lib/main.rb register_association")
else
register
end end
else
register
end end
end end
end end
end end
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
begin begin
Windows = RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"] Windows = RUBY_PLATFORM["win"] || RUBY_PLATFORM["ming"]
Font = Windows ? File.expand_path('fonts/wqy-microhei.ttc') : '/usr/share/fonts/wqy-microhei/wqy-microhei.ttc' Font = Windows ? 'fonts/wqy-microhei.ttc' : '/usr/share/fonts/wqy-microhei/wqy-microhei.ttc'
#System_Encoding = Windows ? "CP#{`chcp`.scan(/\d+$/)}" : `locale |grep LANG |awk -F '=' '{print $2}'` #System_Encoding = Windows ? "CP#{`chcp`.scan(/\d+$/)}" : `locale |grep LANG |awk -F '=' '{print $2}'`
Dir.glob('post_update_*.rb').sort.each { |file| load file } Dir.glob('post_update_*.rb').sort.each { |file| load file }
...@@ -124,7 +124,7 @@ end ...@@ -124,7 +124,7 @@ end
#主循环 #主循环
begin begin
$scene.main while $scene $scene.main while $scene
rescue Exception => exception rescue ScriptError, StandardError => exception
exception.backtrace.each { |backtrace| break if backtrace =~ /^(.*)\.rb:\d+:in `.*'"$/ } #由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件 exception.backtrace.each { |backtrace| break if backtrace =~ /^(.*)\.rb:\d+:in `.*'"$/ } #由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件
$log.fatal($1) { [exception.inspect, *exception.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") } $log.fatal($1) { [exception.inspect, *exception.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
$game.exit if $game $game.exit if $game
...@@ -137,4 +137,4 @@ ensure ...@@ -137,4 +137,4 @@ ensure
profile.close profile.close
end end
$log.close rescue nil $log.close rescue nil
end end
\ No newline at end of file
...@@ -29,7 +29,7 @@ module Update ...@@ -29,7 +29,7 @@ module Update
end end
if @updated if @updated
require 'rbconfig' require 'rbconfig'
IO.popen(File.join(RbConfig::CONFIG["bindir"],RbConfig::CONFIG[Windows ? "RUBYW_INSTALL_NAME" : "RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"]) + " -KU lib/main.rb") spawn(File.join(RbConfig::CONFIG["bindir"],RbConfig::CONFIG[Windows ? "RUBYW_INSTALL_NAME" : "RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"]) + " -KU lib/main.rb")
$scene = nil $scene = nil
end end
@images = [] @images = []
...@@ -60,7 +60,7 @@ module Update ...@@ -60,7 +60,7 @@ module Update
require_relative 'widget_msgbox' require_relative 'widget_msgbox'
Widget_Msgbox.new('mycard', '下载更新完毕,点击确定重新运行mycard并安装更新', :ok => "确定") { Widget_Msgbox.new('mycard', '下载更新完毕,点击确定重新运行mycard并安装更新', :ok => "确定") {
require 'rbconfig' require 'rbconfig'
IO.popen(File.join(RbConfig::CONFIG["bindir"],RbConfig::CONFIG[Windows ? "RUBYW_INSTALL_NAME" : "RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"]) + " -KU lib/main.rb") spawn(File.join(RbConfig::CONFIG["bindir"],RbConfig::CONFIG[Windows ? "RUBYW_INSTALL_NAME" : "RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"]) + " -KU lib/main.rb")
$scene = nil $scene = nil
} }
end end
...@@ -183,7 +183,7 @@ module Update ...@@ -183,7 +183,7 @@ module Update
$log.error('卡图下载') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") } $log.error('卡图下载') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
list.concat ids list.concat ids
end end
end end rescue $log.error('卡图下载线程出错') { $!.inspect.force_encoding("UTF-8") }
end end
thread.priority = -1 thread.priority = -1
thread thread
......
...@@ -182,12 +182,12 @@ class Ygocore < Game ...@@ -182,12 +182,12 @@ class Ygocore < Game
def chat(chatmessage) def chat(chatmessage)
case chatmessage.channel case chatmessage.channel
when :lobby when :lobby
msg = Jabber::Message::new(nil, chatmessage.message) msg = Jabber::Message::new(nil, chatmessage.message)
@@im_room.send msg @@im_room.send msg
when User when User
msg = Jabber::Message::new(nil, chatmessage.message) msg = Jabber::Message::new(nil, chatmessage.message)
@@im_room.send msg, chatmessage.channel.id @@im_room.send msg, chatmessage.channel.id
#send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time) #send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time)
end end
end end
...@@ -265,89 +265,85 @@ class Ygocore < Game ...@@ -265,89 +265,85 @@ class Ygocore < Game
@@config['port'] = port @@config['port'] = port
end end
def self.write_system_conf(options)
system_conf = {}
begin
IO.readlines(File.join(File.dirname(ygocore_path), 'system.conf')).each do |line|
line.force_encoding "UTF-8"
next if line[0, 1] == '#'
field, contents = line.chomp.split(' = ', 2)
system_conf[field] = contents
end
rescue
end
font, size = system_conf['textfont'].split(' ')
if !File.file?(font) or size.to_i.to_s != size
require 'pathname'
font_path = Pathname.new(Font)
font_path = font_path.relative_path_from(Pathname.new(File.dirname(ygocore_path))) if font_path.relative?
system_conf['textfont'] = font_path + ' 14'
end
if !File.file?(system_conf['numfont'])
system_conf['textfont'] = Windows ? 'c:/windows/fonts/arialbd.ttf' : '/usr/share/fonts/gnu-free/FreeSansBold.ttf'
end
options.each do |key, value|
system_conf[key] = value
end
open(File.join(File.dirname(ygocore_path), 'system.conf'), 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") }
end
def self.run_ygocore(option, image_downloading=false) def self.run_ygocore(option, image_downloading=false)
if !image_downloading and !Update.images.empty? if !image_downloading and !Update.images.empty?
return Widget_Msgbox.new("加入房间", "卡图正在下载中,可能显示不出部分卡图", :ok => "确定") { run_ygocore(option, true) } return Widget_Msgbox.new("加入房间", "卡图正在下载中,可能显示不出部分卡图", :ok => "确定") { run_ygocore(option, true) }
end end
Widget_Msgbox.new("ygocore", "正在启动ygocore") rescue nil Widget_Msgbox.new("ygocore", "正在启动ygocore") rescue nil
#写入配置文件并运行ygocore #写入配置文件并运行ygocore
Dir.chdir(File.dirname(ygocore_path)) do case option
case option when Room
when Room room = option
room = option room_name = if room.ot != 0 or room.lp != 8000
room_name = if room.ot != 0 or room.lp != 8000 mode = case when room.match? then
mode = case when room.match? then 1; when room.tag? then
1; when room.tag? then 2
2 else
else 0
0 end
end room_name = "#{room.ot}#{mode}FFF#{room.lp},5,1,#{room.name}"
room_name = "#{room.ot}#{mode}FFF#{room.lp},5,1,#{room.name}" elsif room.tag?
elsif room.tag? "T#" + room.name
"T#" + room.name elsif room.pvp? and room.match?
elsif room.pvp? and room.match? "PM#" + room.name
"PM#" + room.name elsif room.pvp?
elsif room.pvp? "P#" + room.name
"P#" + room.name elsif room.match?
elsif room.match? "M#" + room.name
"M#" + room.name else
else room.name
room.name end
end if room.password and !room.password.empty?
if room.password and !room.password.empty? room_name += "$" + room.password
room_name += "$" + room.password end
end options = {}
system_conf = {} if $game.user
begin options['nickname'] = $game.user.name
IO.readlines('system.conf').each do |line| options['nickname'] += '$' + $game.password if $game.password and !$game.password.empty? and room.server.auth
line.force_encoding "UTF-8"
next if line[0, 1] == '#'
field, contents = line.chomp.split(' = ', 2)
system_conf[field] = contents
end
rescue
end
if $game.user
system_conf['nickname'] = $game.user.name
system_conf['nickname'] += '$' + $game.password if $game.password and !$game.password.empty? and room.server.auth
end
font, size = system_conf['textfont'].split(' ')
if !File.file?(font) or size.to_i.to_s != size
system_conf['textfont'] = Font + ' 14'
end
if !File.file?(system_conf['numfont'])
system_conf['textfont'] = Windows ? 'c:/windows/fonts/arialbd.ttf' : '/usr/share/fonts/gnu-free/FreeSansBold.ttf'
end
system_conf['lastip'] = room.server.ip
system_conf['lastport'] = room.server.port.to_s
system_conf['roompass'] = room_name if room_name and !room_name.empty?
open('system.conf', 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") }
args = '-j'
when :replay
args = '-r'
when :deck
args = '-d'
when String
system_conf = {}
begin
IO.readlines('system.conf').each do |line|
line.force_encoding "UTF-8"
next if line[0, 1] == '#'
field, contents = line.chomp.split(' = ', 2)
system_conf[field] = contents
end
rescue
system_conf['antialias'] = 2
system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14'
system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf'
end
system_conf['lastdeck'] = option
open('system.conf', 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") }
args = '-d'
end end
IO.popen("./#{File.basename(ygocore_path)} #{args}") options['lastip'] = room.server.ip
WM.iconify rescue nil options['lastport'] = room.server.port.to_s
options['roompass'] = room_name if room_name and !room_name.empty?
write_system_conf options
args = '-j'
when :replay
args = '-r'
when :deck
args = '-d'
when String
write_system_conf 'lastdeck' => option
args = '-d'
end end
spawn('./' + File.basename(ygocore_path), args, :chdir => File.dirname(ygocore_path))
WM.iconify rescue nil
Widget_Msgbox.destroy rescue nil Widget_Msgbox.destroy rescue nil
end end
...@@ -378,24 +374,24 @@ class Ygocore < Game ...@@ -378,24 +374,24 @@ class Ygocore < Game
end end
end end
#module Client #module Client
# MycardChannel = EM::Channel.new # MycardChannel = EM::Channel.new
# include EM::P::ObjectProtocol # include EM::P::ObjectProtocol
# #
# def post_init # def post_init
# send_object header: :login, data: {name: $game.username, password: $game.password} # send_object header: :login, data: {name: $game.username, password: $game.password}
# MycardChannel.subscribe { |msg| send_object(msg) } # MycardChannel.subscribe { |msg| send_object(msg) }
# end # end
# #
# def receive_object obj # def receive_object obj
# $log.info('收到消息') { obj.inspect } # $log.info('收到消息') { obj.inspect }
# Game_Event.push Game_Event.parse obj[:header], obj[:data] # Game_Event.push Game_Event.parse obj[:header], obj[:data]
# end # end
# #
# def unbind # def unbind
# Game_Event.push Game_Event::Error.new('ygocore', '网络连接中断', true) # Game_Event.push Game_Event::Error.new('ygocore', '网络连接中断', true)
# end # end
#end #end
get_announcements get_announcements
end end
...@@ -497,12 +493,12 @@ module WebSocket ...@@ -497,12 +493,12 @@ module WebSocket
def receive_data(data) def receive_data(data)
# debug "Received raw: ", data # debug "Received raw: ", data
case @state case @state
when :connecting then when :connecting then
handle_connecting(data) handle_connecting(data)
when :open then when :open then
handle_open(data) handle_open(data)
when :closing then when :closing then
handle_closing(data) handle_closing(data)
end end
end end
...@@ -557,19 +553,19 @@ module WebSocket ...@@ -557,19 +553,19 @@ module WebSocket
@frame << data @frame << data
while frame = @frame.next while frame = @frame.next
case frame.type case frame.type
when :close when :close
@state = :closing @state = :closing
close close
trigger_onclose(frame.to_s) trigger_onclose(frame.to_s)
when :ping when :ping
pong(frame.to_s) pong(frame.to_s)
trigger_onping(frame.to_s) trigger_onping(frame.to_s)
when :pong when :pong
trigger_onpong(frame.to_s) trigger_onpong(frame.to_s)
when :text when :text
trigger_onmessage(frame.to_s, :text) trigger_onmessage(frame.to_s, :text)
when :binary when :binary
trigger_onmessage(frame.to_s, :binary) trigger_onmessage(frame.to_s, :binary)
end end
end end
unbind if @frame.error? unbind if @frame.error?
......
...@@ -2,16 +2,15 @@ ...@@ -2,16 +2,15 @@
echo 'you only need to run from this script once, it will create desktop shortcut automatically after first run.' echo 'you only need to run from this script once, it will create desktop shortcut automatically after first run.'
echo -n "Username: "
read username
echo -n "Password: "
read password
cd "$(dirname "$0")" cd "$(dirname "$0")"
echo "ygocore:
read -p "Username: " username
if [ $username ]; then
read -p "Password: " password
echo "ygocore:
username: '$username' username: '$username'
password: '$password' password: '$password'
" > config.yml " > config.yml;
fi
ruby -KU lib/main.rb ruby -KU lib/main.rb
\ 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