-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_game.ps1
More file actions
69 lines (58 loc) · 1.87 KB
/
Copy pathstart_game.ps1
File metadata and controls
69 lines (58 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 确认执行策略允许脚本执行
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
# 设置端口
$Port = 8000
function Start-HttpServer {
param ($Port, $currentDir)
Write-Host "Starting HTTP server on port $Port"
# 启动Python的HTTP服务器作为后台任务
$job = Start-Job -ScriptBlock {
param ($Port, $currentDir)
try {
Set-Location $currentDir
python -m http.server $Port
} catch {
$_ | Write-Host
}
} -ArgumentList $Port, $currentDir
Start-Sleep -Seconds 1 # 等待服务器启动
# 打开默认浏览器并跳转到本地服务器网址
Start-Process "http://localhost:$Port"
return $job
}
# 切换到当前目录
try {
$currentDir = Get-Location
Write-Host "Current Directory: $currentDir"
} catch {
Write-Host "Failed to get current directory"
exit
}
# 启动初始的HTTP服务器
$job = Start-HttpServer -Port $Port -currentDir $currentDir
# 使用用户输入来停止或重启服务器
Write-Host "Press 'q' to stop the server or 'r' to restart the server..."
while ($true) {
$input = Read-Host
if ($input -eq 'q') {
Write-Host "Stopping HTTP server..."
Stop-Job -Id $job.Id
Remove-Job -Id $job.Id
Write-Host "HTTP server stopped."
break
} elseif ($input -eq 'r') {
Write-Host "Executing encrypt_files.ps1 script..."
try {
# 执行加密文件的脚本
.\dev-tool\encrypt_files.ps1
Write-Host "Script executed successfully."
} catch {
Write-Host "Failed to execute script."
continue
}
Write-Host "Restarting HTTP server..."
Stop-Job -Id $job.Id
Remove-Job -Id $job.Id
$job = Start-HttpServer -Port $Port -currentDir $currentDir
}
}