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,21 +75,8 @@ EOF ...@@ -55,21 +75,8 @@ 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
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 end
def need? def need?
...@@ -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")
end
else else
register register
end 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
......
...@@ -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
......
...@@ -265,13 +265,40 @@ class Ygocore < Game ...@@ -265,13 +265,40 @@ 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
...@@ -297,57 +324,26 @@ class Ygocore < Game ...@@ -297,57 +324,26 @@ class Ygocore < Game
if room.password and !room.password.empty? if room.password and !room.password.empty?
room_name += "$" + room.password room_name += "$" + room.password
end end
system_conf = {} options = {}
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
end
if $game.user if $game.user
system_conf['nickname'] = $game.user.name options['nickname'] = $game.user.name
system_conf['nickname'] += '$' + $game.password if $game.password and !$game.password.empty? and room.server.auth options['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 end
system_conf['lastip'] = room.server.ip options['lastip'] = room.server.ip
system_conf['lastport'] = room.server.port.to_s options['lastport'] = room.server.port.to_s
system_conf['roompass'] = room_name if room_name and !room_name.empty? options['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") } write_system_conf options
args = '-j' args = '-j'
when :replay when :replay
args = '-r' args = '-r'
when :deck when :deck
args = '-d' args = '-d'
when String when String
system_conf = {} write_system_conf 'lastdeck' => option
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' args = '-d'
end end
IO.popen("./#{File.basename(ygocore_path)} #{args}") spawn('./' + File.basename(ygocore_path), args, :chdir => File.dirname(ygocore_path))
WM.iconify rescue nil WM.iconify rescue nil
end
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
......
...@@ -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
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