Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaoye
mycard
Commits
baa7c338
Commit
baa7c338
authored
Mar 06, 2013
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
linux fix
parent
56ed57ec
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
171 additions
and
162 deletions
+171
-162
lib/association.rb
lib/association.rb
+43
-29
lib/main.rb
lib/main.rb
+3
-3
lib/update.rb
lib/update.rb
+3
-3
lib/ygocore/game.rb
lib/ygocore/game.rb
+114
-118
mycard.sh
mycard.sh
+8
-9
No files found.
lib/association.rb
View file @
baa7c338
...
...
@@ -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,21 +75,8 @@ 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"
)
end
[
desktop
,
x_ygopro_deck
,
x_ygopro_replay
]
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?
...
...
@@ -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
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"
)
end
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
end
end
end
\ No newline at end of file
lib/main.rb
View file @
baa7c338
...
...
@@ -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
...
...
lib/update.rb
View file @
baa7c338
...
...
@@ -29,7 +29,7 @@ module Update
end
if
@updated
require
'rbconfig'
IO
.
pope
n
(
File
.
join
(
RbConfig
::
CONFIG
[
"bindir"
],
RbConfig
::
CONFIG
[
Windows
?
"RUBYW_INSTALL_NAME"
:
"RUBY_INSTALL_NAME"
]
+
RbConfig
::
CONFIG
[
"EXEEXT"
])
+
" -KU lib/main.rb"
)
spaw
n
(
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
.
pope
n
(
File
.
join
(
RbConfig
::
CONFIG
[
"bindir"
],
RbConfig
::
CONFIG
[
Windows
?
"RUBYW_INSTALL_NAME"
:
"RUBY_INSTALL_NAME"
]
+
RbConfig
::
CONFIG
[
"EXEEXT"
])
+
" -KU lib/main.rb"
)
spaw
n
(
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
...
...
lib/ygocore/game.rb
View file @
baa7c338
...
...
@@ -265,13 +265,40 @@ 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
...
...
@@ -297,57 +324,26 @@ class Ygocore < Game
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
options
=
{}
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'
options
[
'nickname'
]
=
$game
.
user
.
name
options
[
'nickname'
]
+=
'$'
+
$game
.
password
if
$game
.
password
and
!
$game
.
password
.
empty?
and
room
.
server
.
auth
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
"
)
}
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
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
"
)
}
write_system_conf
'lastdeck'
=>
option
args
=
'-d'
end
IO
.
popen
(
"./
#{
File
.
basename
(
ygocore_path
)
}
#{
args
}
"
)
spawn
(
'./'
+
File
.
basename
(
ygocore_path
),
args
,
:chdir
=>
File
.
dirname
(
ygocore_path
)
)
WM
.
iconify
rescue
nil
end
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
...
...
mycard.sh
View file @
baa7c338
...
...
@@ -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
"
>
config.yml
;
fi
ruby
-KU
lib/main.rb
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment