Commit 85a31944 authored by 神楽坂玲奈's avatar 神楽坂玲奈

fix

parent 6a8fd953
......@@ -3,6 +3,11 @@
#################
/error.txt
/main.exe
/Gemfile.lock
/main.exa
/main.exy
/main.upx
/upx.exe
#################
## Jetbrains
......
source 'https://rubygems.org'
gem 'websocket-eventmachine-server'
gem 'rb-notifu'
gem 'i18n'
gem 'locale'
gem 'mail'
\ No newline at end of file
mkexy --encoding=utf-8 main.rb
exerb -c gui -k utf8 main.exy
upx main.exe
\ No newline at end of file
# = Building
if defined?(Ocra) or defined?(Exerb)
require 'json'
require 'pathname'
require 'fileutils'
require 'uri'
require 'open-uri'
require 'win32api'
require 'win32ole'
require 'win32/registry'
require 'websocket-eventmachine-server'
exit
end
# = Runtime
begin
# == initialize
Version = "0.1.0"
Platform = (RUBY_PLATFORM['mswin'] || RUBY_PLATFORM['mingw']) ? :win32 : :linux
System_Encoding = Encoding.find("locale") rescue Encoding.find(Encoding.locale_charmap)
Dir.chdir File.dirname(defined?(ExerbRuntime) ? ExerbRuntime.filepath.dup.force_encoding(System_Encoding).encode!(Encoding::UTF_8) : ENV["OCRA_EXECUTABLE"] || __FILE__)
# == config
Config = {
'port' => 9998,
'ygopro' => {
'path' => ['ygocore/ygopro_vs.exe', 'ygopro_vs.exe'],
'textfont' => ['fonts/wqy-microhei.ttc', '/usr/share/fonts/wqy-microhei/wqy-microhei.ttc', '/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 'c:/windows/fonts/simsun.ttc'],
'path' => ['ygocore/ygopro_vs.exe', 'ygopro_vs.exe', 'ygocore/ygopro', 'ygopro', 'ygocore/gframe', 'gframe'],
'textfont' => ['fonts/wqy-microhei.ttc', '/usr/share/fonts/wqy-microhei/wqy-microhei.ttc', '/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', '/Library/Fonts/Hiragino Sans GB W3.otf', 'c:/windows/fonts/simsun.ttc'],
'numfont' => ['/usr/share/fonts/gnu-free/FreeSansBold.ttf', 'c:/windows/fonts/arialbd.ttf']
},
"url" => 'http://my-card.in/rooms'
}
Dir.chdir File.dirname(ENV["OCRA_EXECUTABLE"] || __FILE__)
require 'json'
if File.file? 'config.json'
config = open('config.json') { |f| JSON.load(f) }
......@@ -21,6 +37,10 @@ begin
end
Config['ygopro']['path'] = Config['ygopro']['path'].find { |path| File.file? path } if Config['ygopro']['path'].is_a? Enumerable
Config['ygopro']['textfont'] = Config['ygopro']['textfont'].find { |path| File.file? path } if Config['ygopro']['textfont'].is_a? Enumerable
Config['ygopro']['numfont'] = Config['ygopro']['numfont'].find { |path| File.file? path } if Config['ygopro']['numfont'].is_a? Enumerable
if !Config['ygopro']['path']
require 'win32api'
GetOpenFileName = Win32API.new("comdlg32.dll", "GetOpenFileNameW", "p", "i")
......@@ -65,7 +85,7 @@ begin
0 # lpTemplateName L
].pack("LLLPLLLPLPLPPLS2L4")
Dir.chdir('.') {
p GetOpenFileName.call(ofn)
GetOpenFileName.call(ofn)
}
szFile.delete!("\0".encode("UTF-16LE"))
result = szFile.encode("UTF-8")
......@@ -76,8 +96,7 @@ begin
exit
end
end
Config['ygopro']['textfont'] = Config['ygopro']['textfont'].find { |path| File.file? path } if Config['ygopro']['textfont'].is_a? Enumerable
Config['ygopro']['numfont'] = Config['ygopro']['numfont'].find { |path| File.file? path } if Config['ygopro']['numfont'].is_a? Enumerable
def save_config(config=Config)
require 'json'
......@@ -101,7 +120,7 @@ begin
end
def register_paths
path = File.expand_path(ENV["OCRA_EXECUTABLE"] || $0)
path = defined?(ExerbRuntime) ? ExerbRuntime.filepath : ENV["OCRA_EXECUTABLE"] || File.expand_path($0).gsub('/', '\\')
command = "\"#{path}\" \"%1\""
icon = "\"#{path}\" ,0"
[path, command, icon]
......@@ -111,15 +130,17 @@ begin
require 'win32/registry'
path, command, icon = register_paths
begin
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard') { |reg| reg['URL Protocol'] = path.ljust path.bytesize }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\shell\open\command') { |reg| reg[nil] = command.ljust command.bytesize }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\DefaultIcon') { |reg| reg[nil] = icon.ljust icon.bytesize }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard') { |reg| reg['URL Protocol'] = path }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\shell\open\command') { |reg| reg[nil] = command }
Win32::Registry::HKEY_CLASSES_ROOT.create('mycard\DefaultIcon') { |reg| reg[nil] = icon }
Win32::Registry::HKEY_CLASSES_ROOT.create('.ydk') { |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' }
true
rescue Win32::Registry::Error #Access Denied, need elevation
if ENV["OCRA_EXECUTABLE"]
if defined?(ExerbRuntime)
System.elevate ExerbRuntime.filepath, ['register']
elsif ENV["OCRA_EXECUTABLE"]
System.elevate ENV["OCRA_EXECUTABLE"], ['register']
else
System.elevate Gem.ruby, [$0, 'register']
......@@ -152,13 +173,11 @@ begin
def load_system_conf
system_conf = {}
conf_path = File.join(File.dirname(Config['ygopro']['path']), 'system.conf')
IO.readlines(conf_path, 'r:UTF-8').each do |line|
IO.readlines(conf_path, encoding: Encoding::UTF_8).each do |line|
next if line[0, 1] == '#'
field, contents = line.chomp.split(' = ', 2)
system_conf[field] = contents
end if File.file? conf_path
system_conf
end
......@@ -182,21 +201,31 @@ begin
end
module System
BUTTONS_OK = 0
def message_box(txt, title=nil, buttons=BUTTONS_OK)
require 'dl'
user32 = DL.dlopen('user32')
msgbox = user32['MessageBoxA', 'ILSSI']
r, rs = msgbox.call(0, txt, title, buttons)
return r
end
module_function
def open(path=Config['url'], *args)
def web(path=Config['url'], *args)
require 'win32ole'
$shell ||= WIN32OLE.new('Shell.Application')
$shell.ShellExecute(path, *args)
end
def elevate(path, args, pwd = Dir.pwd)
open path, args.join(' '), Dir.pwd, 'runas'
web path, args.join(' '), Dir.pwd, 'runas'
end
end
def run_ygopro(parameter)
System.open(Config['ygopro']['path'], parameter, File.dirname(Config['ygopro']['path']))
spawn File.basename(Config['ygopro']['path']), parameter, chdir: File.dirname(Config['ygopro']['path'])
end
def join(room)
......@@ -225,13 +254,14 @@ begin
def replay(replay)
require 'fileutils'
moved_replay_directory = File.expand_path(File.dirname(Config['ygopro']['path'])) == Dir.pwd ? 'replay_moved' : 'replay'
files = Dir.glob(File.join(File.dirname(Config['ygopro']['path']), 'replay', '*.yrp')) - File.join(File.dirname(Config['ygopro']['path']), 'replay', replay+'.yrp')
files = Dir.glob(File.join(File.dirname(Config['ygopro']['path']), 'replay', '*.yrp'))
files.delete File.join(File.dirname(Config['ygopro']['path']), 'replay', replay+'.yrp')
FileUtils.mv files, moved_replay_directory
run_ygopro('-r')
end
def local_user(system_conf=load_system_conf)
nickname, password = system_conf['nickname'].split('$')
nickname, password = system_conf['nickname'] ? system_conf['nickname'].split('$') : []
{'nickname' => nickname, 'password' => password}
end
......@@ -255,8 +285,10 @@ begin
case File.extname(path)
when '.ydk'
deck_directory = File.join(File.dirname(Config['ygopro']['path']), 'deck')
if file.dirname(path) != deck_directory
Dir.mkdir(deck_directory) unless File.directory?(deck_directory)
FileUtils.copy(path, deck_directory)
end
deck(File.basename(path, '.ydk'))
when '.yrp'
replay_directory = File.expand_path(File.dirname(Config['ygopro']['path']))
......@@ -269,14 +301,10 @@ begin
end
def parse_uri(uri)
file = uri.dup.force_encoding("UTF-8")
file.force_encoding("GBK") unless file.valid_encoding?
file.encode!("UTF-8")
require 'uri'
if uri[0, 9] == 'mycard://'
file = URI.unescape file[9, file.size-9]
file = URI.unescape uri[9, uri.size-9]
uri = "http://" + URI.escape(file)
else
uri = file
......@@ -315,23 +343,23 @@ begin
end
save_config
if ARGV.first
puts parse(ARGV.first).to_json
parse ARGV.first.dup.force_encoding(System_Encoding).encode!(Encoding::UTF_8)
else
register if !registed?
System.open(Config['url'])
if File.file? 'ruby\bin\rubyw.exe'
spawn 'ruby\bin\rubyw.exe', '-KU', 'lib/main.rb'
else
System.web(Config['url'])
end
#service
#require all, for ocra
require 'open-uri'
require 'pathname'
require 'win32api'
end
rescue => exception
open('error.txt', 'w') { |f| f.write ([exception] + exception.backtrace).join("\r\n") }
exec 'notepad error.txt'
end
error = "程序出现了错误,请把你的操作及以下信息发送至zh99998@gmail.com来帮助我们完善程序
an error occurs, please send your operation and message below to zh99998@gmail.com
#{exception.inspect}
#{exception.backtrace.join("\n")}"
open('error.txt', 'w') { |f| f.write error }
spawn 'notepad', 'error.txt'
end
\ 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