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

linux fix

parent 56ed57ec
......@@ -12,16 +12,39 @@ module Association
Win32::Registry::HKEY_CLASSES_ROOT.create('.yrp') { |reg| reg[nil] = 'mycard' }
Win32::Registry::HKEY_CLASSES_ROOT.create('.deck') { |reg| reg[nil] = 'mycard' }
else
desktop, x_ygopro_deck, x_ygopro_replay = paths
require 'fileutils'
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
[Desktop Entry]
Name=Mycard
Name[zh_CN]=Mycard - 萌卡
Comment=a card game platform
Comment[zh_CN]=卡片游戏对战客户端
Exec=/usr/bin/env ruby -KU lib/main.rb %u
Exec=ruby -KU lib/main.rb %u
Terminal=false
Icon=#{Dir.pwd}/graphics/system/icon.png
Type=Application
......@@ -30,9 +53,7 @@ Path=#{Dir.pwd}
URL=http://my-card.in/
MimeType=x-scheme-handler/mycard;application/x-ygopro-deck;application/x-ygopro-replay'
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
x_ygopro_deck = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-ygopro-deck">
......@@ -43,8 +64,7 @@ EOF
</mime-type>
</mime-info>
EOF
}
open("#{ENV['HOME']}/.local/share/mime/packages/application-x-ygopro-replay.xml", 'w') { |f| f.write <<EOF
x_ygopro_replay = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-ygopro-replay">
......@@ -55,23 +75,10 @@ EOF
</mime-type>
</mime-info>
EOF
}
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")
[desktop, x_ygopro_deck, x_ygopro_replay]
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?
return false if $config['no_assoc']
if Windows
......@@ -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('.deck') { |reg| return true unless reg[nil] == 'mycard' }
rescue
return true
true
end
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
......@@ -107,15 +122,14 @@ EOF
def start
if need?
if Windows
request do
request do
if Windows
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
else
register
end
end
end
end
\ No newline at end of file
......@@ -2,7 +2,7 @@
begin
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}'`
Dir.glob('post_update_*.rb').sort.each { |file| load file }
......@@ -124,7 +124,7 @@ end
#主循环
begin
$scene.main while $scene
rescue Exception => exception
rescue ScriptError, StandardError => exception
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") }
$game.exit if $game
......@@ -137,4 +137,4 @@ ensure
profile.close
end
$log.close rescue nil
end
\ No newline at end of file
end
......@@ -29,7 +29,7 @@ module Update
end
if @updated
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
end
@images = []
......@@ -60,7 +60,7 @@ module Update
require_relative 'widget_msgbox'
Widget_Msgbox.new('mycard', '下载更新完毕,点击确定重新运行mycard并安装更新', :ok => "确定") {
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
}
end
......@@ -183,7 +183,7 @@ module Update
$log.error('卡图下载') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
list.concat ids
end
end
end rescue $log.error('卡图下载线程出错') { $!.inspect.force_encoding("UTF-8") }
end
thread.priority = -1
thread
......
......@@ -182,12 +182,12 @@ class Ygocore < Game
def chat(chatmessage)
case chatmessage.channel
when :lobby
msg = Jabber::Message::new(nil, chatmessage.message)
@@im_room.send msg
when User
msg = Jabber::Message::new(nil, chatmessage.message)
@@im_room.send msg, chatmessage.channel.id
when :lobby
msg = Jabber::Message::new(nil, chatmessage.message)
@@im_room.send msg
when User
msg = Jabber::Message::new(nil, chatmessage.message)
@@im_room.send msg, chatmessage.channel.id
#send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time)
end
end
......@@ -265,89 +265,85 @@ class Ygocore < Game
@@config['port'] = port
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)
if !image_downloading and !Update.images.empty?
return Widget_Msgbox.new("加入房间", "卡图正在下载中,可能显示不出部分卡图", :ok => "确定") { run_ygocore(option, true) }
end
Widget_Msgbox.new("ygocore", "正在启动ygocore") rescue nil
#写入配置文件并运行ygocore
Dir.chdir(File.dirname(ygocore_path)) do
case option
when Room
room = option
room_name = if room.ot != 0 or room.lp != 8000
mode = case when room.match? then
1; when room.tag? then
2
else
0
end
room_name = "#{room.ot}#{mode}FFF#{room.lp},5,1,#{room.name}"
elsif room.tag?
"T#" + room.name
elsif room.pvp? and room.match?
"PM#" + room.name
elsif room.pvp?
"P#" + room.name
elsif room.match?
"M#" + room.name
else
room.name
end
if room.password and !room.password.empty?
room_name += "$" + room.password
end
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
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'
case option
when Room
room = option
room_name = if room.ot != 0 or room.lp != 8000
mode = case when room.match? then
1; when room.tag? then
2
else
0
end
room_name = "#{room.ot}#{mode}FFF#{room.lp},5,1,#{room.name}"
elsif room.tag?
"T#" + room.name
elsif room.pvp? and room.match?
"PM#" + room.name
elsif room.pvp?
"P#" + room.name
elsif room.match?
"M#" + room.name
else
room.name
end
if room.password and !room.password.empty?
room_name += "$" + room.password
end
options = {}
if $game.user
options['nickname'] = $game.user.name
options['nickname'] += '$' + $game.password if $game.password and !$game.password.empty? and room.server.auth
end
IO.popen("./#{File.basename(ygocore_path)} #{args}")
WM.iconify rescue nil
options['lastip'] = room.server.ip
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
spawn('./' + File.basename(ygocore_path), args, :chdir => File.dirname(ygocore_path))
WM.iconify rescue nil
Widget_Msgbox.destroy rescue nil
end
......@@ -378,24 +374,24 @@ class Ygocore < Game
end
end
#module Client
# MycardChannel = EM::Channel.new
# include EM::P::ObjectProtocol
#
# def post_init
# send_object header: :login, data: {name: $game.username, password: $game.password}
# MycardChannel.subscribe { |msg| send_object(msg) }
# end
#
# def receive_object obj
# $log.info('收到消息') { obj.inspect }
# Game_Event.push Game_Event.parse obj[:header], obj[:data]
# end
#
# def unbind
# Game_Event.push Game_Event::Error.new('ygocore', '网络连接中断', true)
# end
#end
#module Client
# MycardChannel = EM::Channel.new
# include EM::P::ObjectProtocol
#
# def post_init
# send_object header: :login, data: {name: $game.username, password: $game.password}
# MycardChannel.subscribe { |msg| send_object(msg) }
# end
#
# def receive_object obj
# $log.info('收到消息') { obj.inspect }
# Game_Event.push Game_Event.parse obj[:header], obj[:data]
# end
#
# def unbind
# Game_Event.push Game_Event::Error.new('ygocore', '网络连接中断', true)
# end
#end
get_announcements
end
......@@ -497,12 +493,12 @@ module WebSocket
def receive_data(data)
# debug "Received raw: ", data
case @state
when :connecting then
handle_connecting(data)
when :open then
handle_open(data)
when :closing then
handle_closing(data)
when :connecting then
handle_connecting(data)
when :open then
handle_open(data)
when :closing then
handle_closing(data)
end
end
......@@ -557,19 +553,19 @@ module WebSocket
@frame << data
while frame = @frame.next
case frame.type
when :close
@state = :closing
close
trigger_onclose(frame.to_s)
when :ping
pong(frame.to_s)
trigger_onping(frame.to_s)
when :pong
trigger_onpong(frame.to_s)
when :text
trigger_onmessage(frame.to_s, :text)
when :binary
trigger_onmessage(frame.to_s, :binary)
when :close
@state = :closing
close
trigger_onclose(frame.to_s)
when :ping
pong(frame.to_s)
trigger_onping(frame.to_s)
when :pong
trigger_onpong(frame.to_s)
when :text
trigger_onmessage(frame.to_s, :text)
when :binary
trigger_onmessage(frame.to_s, :binary)
end
end
unbind if @frame.error?
......
......@@ -2,16 +2,15 @@
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")"
echo "ygocore:
read -p "Username: " username
if [ $username ]; then
read -p "Password: " password
echo "ygocore:
username: '$username'
password: '$password'
" > config.yml
ruby -KU lib/main.rb
\ No newline at end of file
" > config.yml;
fi
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