13
13
exit ('请在 cli 环境中运行 ' );
14
14
}
15
15
16
- require_once './loader.php ' ;
16
+ require_once __DIR__ . '/loader.php ' ;
17
+ $ __DIR__ = __DIR__ ;
17
18
18
19
//选择更新版本
19
20
echo "请选择更新分支及版本: \n 1. 发行版 \n 2. 主分支 \n 3. 开发分支 \n 0. 取消更新 \nMiraiEz > " ;
@@ -66,10 +67,10 @@ function update_releases($ver = null)
66
67
$ ver = $ resp ['tag_name ' ];
67
68
}
68
69
//覆盖检查
69
- if (file_exists (' . /update.zip ' )) {
70
+ if (file_exists (__DIR__ . ' /update.zip ' )) {
70
71
echo '发现已存在的 update.zip 是否覆盖? [Y/n] ' ;
71
72
if (!get_input_YesOrNo (null , true )) exit ("操作已取消. \n" );
72
- unlink (' . /update.zip ' );
73
+ unlink (__DIR__ . ' /update.zip ' );
73
74
}
74
75
//下载 zip 包
75
76
$ url = "https://api.github.com/repos/nkxingxh/MiraiEz/zipball/ $ ver " ;
@@ -79,15 +80,15 @@ function update_releases($ver = null)
79
80
echo "下载更新包失败! " . (isset ($ return_code ) ? "cURL 返回码: $ return_code " : '运行 cURL 命令失败 ' ) . "\n" ;
80
81
exit (-1 );
81
82
}
82
- if (!file_exists (' . /update.zip ' )) {
83
+ if (!file_exists (__DIR__ . ' /update.zip ' )) {
83
84
echo "下载文件失败! 未找到 update.zip \n" ;
84
85
exit (-1 );
85
86
}
86
87
87
88
update_zip ();
88
89
}
89
90
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 ' )
91
92
{
92
93
$ tmp_dir = strtolower ($ tmp_dir );
93
94
echo "正在解压更新包... \n" ;
@@ -112,31 +113,31 @@ function update_zip($zip_file = './update.zip', $tmp_dir = './update_tmp')
112
113
exit (-1 );
113
114
} else {
114
115
$ update_dir = $ update_dir [0 ];
116
+ echo "更新内容目录: $ update_dir \n" ;
115
117
}
116
118
117
119
//备份文件
118
120
echo "正在备份插件与数据... \n" ;
119
121
$ backups = array (
120
122
//dirname(dataDir),
121
123
'config ' ,
122
- 'plugins ' ,
123
- 'config.php '
124
+ 'plugins '
124
125
);
125
126
mkdir ("$ tmp_dir/backup " );
126
127
foreach ($ backups as $ v ) {
127
128
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" ;
129
130
continue ; //todo.完成后移除 continue
130
- if (!rename (". /$ v " , "$ tmp_dir/backup/ $ v " )) {
131
+ if (!rename ("{ $ GLOBALS [ ' __DIR__ ' ]} / $ v " , "$ tmp_dir/backup/ $ v " )) {
131
132
echo "移动文件(或目录) $ v 失败! \n" ;
132
133
exit (-1 );
133
134
}
134
135
}
135
136
//删除老文件
136
137
echo "正在移除老文件... \n" ;
137
- $ dir_arr = glob (' ./* ' );
138
+ $ dir_arr = glob ("{ $ GLOBALS [ ' __DIR__ ' ]} /* " );
138
139
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 ;
140
141
//unlink($v);
141
142
echo "[rm] $ v \n" ;
142
143
}
@@ -146,11 +147,11 @@ function update_zip($zip_file = './update.zip', $tmp_dir = './update_tmp')
146
147
$ update_dir_len = strlen ($ update_dir );
147
148
foreach ($ update_arr as $ v ) {
148
149
$ 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" ;
151
152
}
152
153
153
- unlink (' . /update.zip' );
154
+ unlink ("{ $ GLOBALS [ ' __DIR__ ' ]} /update.zip " );
154
155
unlink ($ tmp_dir );
155
156
}
156
157
0 commit comments