Skip to content

Commit b3a6cf9

Browse files
committed
Update update.php
1 parent ba23d23 commit b3a6cf9

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

update.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
exit('请在 cli 环境中运行');
1414
}
1515

16-
require_once './loader.php';
16+
require_once __DIR__ . '/loader.php';
17+
$__DIR__ = __DIR__;
1718

1819
//选择更新版本
1920
echo "请选择更新分支及版本:\n 1. 发行版\n 2. 主分支\n 3. 开发分支\n 0. 取消更新\nMiraiEz > ";
@@ -66,10 +67,10 @@ function update_releases($ver = null)
6667
$ver = $resp['tag_name'];
6768
}
6869
//覆盖检查
69-
if (file_exists('./update.zip')) {
70+
if (file_exists(__DIR__ . '/update.zip')) {
7071
echo '发现已存在的 update.zip 是否覆盖? [Y/n]';
7172
if (!get_input_YesOrNo(null, true)) exit("操作已取消.\n");
72-
unlink('./update.zip');
73+
unlink(__DIR__ . '/update.zip');
7374
}
7475
//下载 zip 包
7576
$url = "https://api.github.com/repos/nkxingxh/MiraiEz/zipball/$ver";
@@ -79,15 +80,15 @@ function update_releases($ver = null)
7980
echo "下载更新包失败! " . (isset($return_code) ? "cURL 返回码: $return_code" : '运行 cURL 命令失败') . "\n";
8081
exit(-1);
8182
}
82-
if (!file_exists('./update.zip')) {
83+
if (!file_exists(__DIR__ . '/update.zip')) {
8384
echo "下载文件失败! 未找到 update.zip\n";
8485
exit(-1);
8586
}
8687

8788
update_zip();
8889
}
8990

90-
function update_zip($zip_file = './update.zip', $tmp_dir = './update_tmp')
91+
function update_zip($zip_file = __DIR__ . '/update.zip', $tmp_dir = __DIR__ . '/update_tmp')
9192
{
9293
$tmp_dir = strtolower($tmp_dir);
9394
echo "正在解压更新包...\n";
@@ -112,31 +113,31 @@ function update_zip($zip_file = './update.zip', $tmp_dir = './update_tmp')
112113
exit(-1);
113114
} else {
114115
$update_dir = $update_dir[0];
116+
echo "更新内容目录: $update_dir\n";
115117
}
116118

117119
//备份文件
118120
echo "正在备份插件与数据...\n";
119121
$backups = array(
120122
//dirname(dataDir),
121123
'config',
122-
'plugins',
123-
'config.php'
124+
'plugins'
124125
);
125126
mkdir("$tmp_dir/backup");
126127
foreach ($backups as $v) {
127128
if (!file_exists($v)) continue;
128-
echo "[mv] ./$v $tmp_dir/backup/$v\n";
129+
echo "[mv] {$GLOBALS['__DIR__']}/$v -> $tmp_dir/backup/$v\n";
129130
continue; //todo.完成后移除 continue
130-
if (!rename("./$v", "$tmp_dir/backup/$v")) {
131+
if (!rename("{$GLOBALS['__DIR__']}/$v", "$tmp_dir/backup/$v")) {
131132
echo "移动文件(或目录) $v 失败!\n";
132133
exit(-1);
133134
}
134135
}
135136
//删除老文件
136137
echo "正在移除老文件...\n";
137-
$dir_arr = glob('./*');
138+
$dir_arr = glob("{$GLOBALS['__DIR__']}/*");
138139
foreach ($dir_arr as $v) {
139-
if ($v == $tmp_dir || strtolower(substr($v, 0, 7)) == './data_') continue;
140+
if ($v == $tmp_dir || strtolower(substr($v, 0, 7)) == "{$GLOBALS['__DIR__']}/data_") continue;
140141
//unlink($v);
141142
echo "[rm] $v\n";
142143
}
@@ -146,11 +147,11 @@ function update_zip($zip_file = './update.zip', $tmp_dir = './update_tmp')
146147
$update_dir_len = strlen($update_dir);
147148
foreach ($update_arr as $v) {
148149
$fn = substr($v, -(strlen($v) - $update_dir_len - 1));
149-
//rename($v, "./$fn");
150-
echo "[mv] $v ./$fn\n";
150+
//rename($v, "{$GLOBALS['__DIR__']}/$fn");
151+
echo "[mv] $v -> {$GLOBALS['__DIR__']}/$fn\n";
151152
}
152153

153-
unlink('./update.zip');
154+
unlink("{$GLOBALS['__DIR__']}/update.zip");
154155
unlink($tmp_dir);
155156
}
156157

0 commit comments

Comments
 (0)