Skip to content

Commit

Permalink
适配window下 run.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
huahua132 committed Nov 18, 2024
1 parent 4a5463e commit 9a6f915
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 26 deletions.
6 changes: 3 additions & 3 deletions binbat/make_encrycode.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ set key=%2
set targetpath=%3

if "%skynet_fly_path%" == "" (
echo "please format make_encrycode.bat skynet_fly_path key targetpath"
echo please format make_encrycode.bat skynet_fly_path key targetpath
exit /b 1
)

if "%key%" == "" (
echo "please format make_encrycode.bat skynet_fly_path key targetpath"
echo please format make_encrycode.bat skynet_fly_path key targetpath
exit /b 1
)

if "%targetpath%" == "" (
echo "please format make_encrycode.bat skynet_fly_path key targetpath"
echo please format make_encrycode.bat skynet_fly_path key targetpath
exit /b 1
)

Expand Down
11 changes: 10 additions & 1 deletion lualib/skynet-fly/utils/file_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ function M.convert_linux_to_windows_relative(linux_path)
return windows_path
end

function M.convert_windows_to_linux_relative(window_path)
local linux_path = window_path:gsub("\\", "/")
return linux_path
end

function M.is_window()
return package.config:sub(1, 1) == '\\'
end
Expand All @@ -175,7 +180,11 @@ function M.new_copy_file(is_dir)
return {
set_source_target = function(source, target)
if is_window then
table.insert(list, cmd .. M.convert_linux_to_windows_relative(source) .. ' ' .. M.convert_linux_to_windows_relative(target) .. ' /E /I /Y')
if is_dir then
table.insert(list, cmd .. M.convert_linux_to_windows_relative(source) .. ' ' .. M.convert_linux_to_windows_relative(target) .. ' /E /I /Y')
else
table.insert(list, cmd .. M.convert_linux_to_windows_relative(source) .. ' ' .. M.convert_linux_to_windows_relative(target) .. ' /Y')
end
else
table.insert(list, cmd .. source .. ' ' .. target)
end
Expand Down
3 changes: 2 additions & 1 deletion script/bat/make_server.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ if not exist "%lua%" (
exit /b 1
)

%lua% "%script_path%\write_config.lua" %skynet_fly_path% %load_mods_name%
%lua% "%script_path%\write_config.lua" %skynet_fly_path% %load_mods_name%
%lua% "%script_path%\write_runsh.lua" %skynet_fly_path%
2 changes: 2 additions & 0 deletions script/lua/write_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ else
is_daemon = false
end

skynet_fly_path = file_util.convert_windows_to_linux_relative(skynet_fly_path)

local skynet_path = file_util.path_join(skynet_fly_path, '/skynet/')
local server_path = "./"
local common_path = "../../commonlualib/"
Expand Down
82 changes: 61 additions & 21 deletions script/lua/write_runsh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ local server_path = "./"
local lua_path = skynet_path .. '/3rd/lua/lua'
local script_path = file_util.path_join(skynet_fly_path, '/script/lua')

local shell_str = "#!/bin/bash\n"
shell_str = shell_str .. [[
if not file_util.is_window() then
local shell_str = "#!/bin/bash\n"
shell_str = shell_str .. [[
if [ "$#" -lt 1 ]; then
echo "arg1 [load_mods] 启动的load_mods配置"
echo "arg2 [is_daemon] 是否守护进程运行 1是0不是 默认1"
Expand All @@ -23,22 +24,61 @@ if [ "$#" -lt 1 ]; then
exit 1
fi
]]
shell_str = shell_str .. string.format("echo run %s $1 $2 $3\n",svr_name)
shell_str = shell_str .. string.format("%s %s/write_config.lua %s $1 $2 $3\n",lua_path,script_path,skynet_fly_path)
shell_str = shell_str .. string.format("%s %s/console.lua %s %s $1 create_running_config\n",lua_path,script_path,skynet_fly_path,svr_name)
shell_str = shell_str .. string.format("%s %s/console.lua %s %s $1 create_load_mods_old\n",lua_path,script_path,skynet_fly_path,svr_name)
shell_str = shell_str .. string.format("%s/skynet make/%s_config.lua $1\n",skynet_path,svr_name)
local shell_path = server_path .. 'make/script/'

local isok, err = file_util.mkdir(shell_path)
if not isok then
error("create shell_path err " .. err)
end

local file_path = shell_path .. 'run.sh'

local file = io.open(file_path,'w+')
assert(file)
file:write(shell_str)
file:close()
print("make " .. file_path)
shell_str = shell_str .. string.format("echo run %s $1 $2 $3\n",svr_name)
shell_str = shell_str .. string.format("%s %s/write_config.lua %s $1 $2 $3\n",lua_path,script_path,skynet_fly_path)
shell_str = shell_str .. string.format("%s %s/console.lua %s %s $1 create_running_config\n",lua_path,script_path,skynet_fly_path,svr_name)
shell_str = shell_str .. string.format("%s %s/console.lua %s %s $1 create_load_mods_old\n",lua_path,script_path,skynet_fly_path,svr_name)
shell_str = shell_str .. string.format("%s/skynet make/%s_config.lua $1\n",skynet_path,svr_name)
local shell_path = server_path .. 'make/script/'

local isok, err = file_util.mkdir(shell_path)
if not isok then
error("create shell_path err " .. err)
end

local file_path = shell_path .. 'run.sh'

local file = io.open(file_path,'w+')
assert(file)
file:write(shell_str)
file:close()
print("make " .. file_path)
else
--window
local bat_str = [[
@echo off
set load_mods=%1
set is_daemon=%2
set recordfile=%3
if "%load_mods%" == "" (
echo arg1 [load_mods] 启动的load_mods配置
echo arg2 [is_daemon] 是否守护进程运行 1是0不是 默认1
echo arg3 [recordfile] 播放录像文件路径 可选
echo please format make/script/run.bat load_mods.lua is_daemon
exit /b 1
)
]]

lua_path = file_util.convert_linux_to_windows_relative(lua_path) .. ".exe"
script_path = file_util.convert_linux_to_windows_relative(script_path)
skynet_fly_path = file_util.convert_linux_to_windows_relative(skynet_fly_path)
skynet_path = file_util.convert_linux_to_windows_relative(skynet_path)
bat_str = bat_str .. string.format("echo run %s %%load_mods%% %%is_daemon%% %%recordfile%%\n", svr_name)
bat_str = bat_str .. string.format("%s %s\\write_config.lua %s %%load_mods%% %%is_daemon%% %%recordfile%%\n",lua_path,script_path,skynet_fly_path)
bat_str = bat_str .. string.format("%s %s\\console.lua %s %s %%load_mods%% create_running_config\n",lua_path,script_path,skynet_fly_path,svr_name)
bat_str = bat_str .. string.format("%s %s\\console.lua %s %s %%load_mods%% create_load_mods_old\n",lua_path,script_path,skynet_fly_path,svr_name)
bat_str = bat_str .. string.format('start "skynet make\\AB_question_config.lua %%load_mods%%" %s\\skynet.exe make\\%s_config.lua %%load_mods%%\n',skynet_path,svr_name)

local bat_path = server_path .. 'make\\script\\'
local isok, err = file_util.mkdir(bat_path)
if not isok then
error("create bat_path err " .. err)
end
local file_path = bat_path .. 'run.bat'

local file = io.open(file_path,'w+')
assert(file)
file:write(bat_str)
file:close()
print("make " .. file_path)
end

0 comments on commit 9a6f915

Please sign in to comment.