Skip to content

Commit e5ff3df

Browse files
committed
feature: 添加脚本
1.自动生成测试环境 2.自动拷贝运行程序
1 parent 27312a9 commit e5ff3df

File tree

4 files changed

+119
-5
lines changed

4 files changed

+119
-5
lines changed

src/StartManager/Application.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.Diagnostics;
2+
3+
namespace StartManager;
4+
5+
public class Application
6+
{
7+
8+
public static void StartFileServer()
9+
{
10+
var name = "hfs.exe";
11+
}
12+
13+
public static void StartClient()
14+
{
15+
var name = "ClientSample.exe";
16+
}
17+
18+
public static void StartServer()
19+
{
20+
var name = "ServerSample.exe";
21+
}
22+
23+
public static void StartUpgrade()
24+
{
25+
var name = "UpgradeSample.exe";
26+
}
27+
28+
public static void Reset()
29+
{
30+
}
31+
32+
private static void Start(string appName, string path)
33+
{
34+
Process[] runningProcesses = Process.GetProcessesByName(appName);
35+
foreach (var process in runningProcesses)
36+
{
37+
try
38+
{
39+
process.Kill();
40+
Console.WriteLine($"已关闭进程: {process.ProcessName}");
41+
break;
42+
}
43+
catch (Exception ex)
44+
{
45+
Console.WriteLine($"关闭进程时发生错误: {ex.Message}");
46+
}
47+
}
48+
49+
try
50+
{
51+
// 启动进程
52+
var appPath = Path.Combine(path, appName);
53+
Process.Start(appPath);
54+
Console.WriteLine($"进程已启动, {appPath}.");
55+
}
56+
catch (Exception ex)
57+
{
58+
Console.WriteLine($"启动进程时发生错误: {ex.Message}");
59+
}
60+
}
61+
}

src/process.bat

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@echo off
2+
setlocal
3+
4+
set "processes=ClientSample.exe ServerSample.exe UpgradeSample.exe hfs.exe StartManager.exe"
5+
6+
for %%p in (%processes%) do (
7+
echo Checking for process %%p ...
8+
tasklist /FI "IMAGENAME eq %%p" 2>NUL | find /I "%%p" >NUL
9+
if not errorlevel 1 (
10+
echo Terminating process %%p ...
11+
taskkill /F /IM %%p
12+
) else (
13+
echo Process %%p not found.
14+
)
15+
)
16+
17+
echo Done.
18+
endlocal

src/resource.bat

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@echo off
2+
setlocal
3+
4+
REM Define the base directory
5+
set BASE_DIR=%~dp0
6+
7+
REM Check if run directory exists and delete it if it does
8+
if exist "%BASE_DIR%run" (
9+
echo Deleting existing run directory...
10+
rmdir /s /q "%BASE_DIR%run"
11+
)
12+
13+
REM Create run directory and its subdirectories
14+
mkdir "%BASE_DIR%run"
15+
mkdir "%BASE_DIR%run\app"
16+
mkdir "%BASE_DIR%run\files"
17+
mkdir "%BASE_DIR%run\files\old"
18+
mkdir "%BASE_DIR%run\files\new"
19+
mkdir "%BASE_DIR%run\files\patch"
20+
21+
REM Copy files from Client, Server, Upgrade to app directory
22+
xcopy "%BASE_DIR%Client\bin\Release\net8.0\*" "%BASE_DIR%run\app\" /s /e /y
23+
xcopy "%BASE_DIR%Server\bin\Release\net8.0\*" "%BASE_DIR%run\app\" /s /e /y
24+
xcopy "%BASE_DIR%Upgrade\bin\Release\net8.0\*" "%BASE_DIR%run\app\" /s /e /y
25+
26+
REM Create test.txt files with specified content
27+
echo 123456 > "%BASE_DIR%run\files\old\test.txt"
28+
echo 123456abcd > "%BASE_DIR%run\files\new\test.txt"
29+
echo. > "%BASE_DIR%run\files\patch\test.txt"
30+
31+
echo Operation completed successfully.
32+
33+
endlocal

src/start.cmd

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
@echo off
2+
3+
call "%~dp0process.bat"
4+
25
REM 保存初始目录
36
set InitialDir=%CD%
47

5-
echo Starting hfs.exe...
6-
start "" .\FileService\hfs.exe
7-
echo hfs.exe has been started.
8-
8+
cd /d %InitialDir%
99
echo Running Server.bat
1010
call .\Server\build.bat
1111
echo .\Server\build.bat completed
@@ -27,7 +27,9 @@ echo .\Client\build.bat completed
2727

2828
echo All scripts completed.
2929

30-
REM 使用 timeout 命令进行2秒倒计时
30+
call "%~dp0resource.bat"
31+
32+
REM 使用 timeout 命令进行3秒倒计时
3133
timeout /t 3 /nobreak >nul
3234

3335
cd /d %InitialDir%

0 commit comments

Comments
 (0)