Skip to content

Commit f4fbee2

Browse files
committed
Initital commit: Release 1.0.0
0 parents  commit f4fbee2

File tree

12 files changed

+1885
-0
lines changed

12 files changed

+1885
-0
lines changed

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 编译输出
2+
[Bb]in/
3+
[Oo]bj/
4+
out/
5+
6+
# Visual Studio 目录和文件
7+
*.user
8+
*.userosscache
9+
*.sln.docstates
10+
.vs/
11+
*.suo
12+
*.cache
13+
*.ilk
14+
*.pdb
15+
*.log
16+
17+
# NuGet 包目录
18+
packages/
19+
[Nn]u[Gg]et/
20+
*.nupkg
21+
*.snupkg
22+
23+
# IDE 文件
24+
.idea/
25+
*.swp
26+
*.swo
27+
28+
# 操作系统文件
29+
.DS_Store
30+
Thumbs.db
31+
32+
# 项目特定文件
33+
appsettings.Development.json
34+
appsettings.Local.json
35+
*.db

ArgHandler.cs

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace EasingPathPositionCalculator;
8+
public class ArgHandler
9+
{
10+
// 子命令处理
11+
public static void HandleGroupCommand(string[] args)
12+
{
13+
string subCommand = args[1].ToLower();
14+
15+
switch (subCommand)
16+
{
17+
case "create":
18+
HandleGroupCreate(args);
19+
break;
20+
21+
case "list":
22+
Program.GroupList();
23+
break;
24+
25+
case "remove":
26+
HandleGroupRemove(args);
27+
break;
28+
29+
case "export":
30+
HandleGroupExport(args);
31+
break;
32+
33+
default:
34+
Console.WriteLine($"未知的 group 子命令: {subCommand}");
35+
Console.WriteLine("输入\"help\"以获取帮助。");
36+
break;
37+
}
38+
}
39+
40+
private static void HandleGroupCreate(string[] args)
41+
{
42+
string name = "";
43+
bool withOpen = false;
44+
45+
for (int i = 2; i < args.Length; i++)
46+
{
47+
if (args[i] == "-o")
48+
{
49+
withOpen = true;
50+
break;
51+
}
52+
else if (!args[i].StartsWith("-"))
53+
name += args[i] + "_";
54+
}
55+
56+
Program.GroupCreate(name, withOpen);
57+
}
58+
59+
private static void HandleGroupRemove(string[] args)
60+
{
61+
if (args.Length < 3)
62+
{
63+
Console.WriteLine("错误:remove 命令需要指定 UID 或 使用'all'");
64+
return;
65+
}
66+
67+
string target = args[2].ToLower();
68+
69+
if (target == "all")
70+
{
71+
Console.Write("确定要删除所有路径组吗?(y/N): ");
72+
string? confirm = Console.ReadLine()?.Trim().ToLower();
73+
if (confirm == "y" || confirm == "yes")
74+
{
75+
Program.GroupRemoveAll();
76+
Console.WriteLine("已删除所有路径组!");
77+
}
78+
else
79+
{
80+
Console.WriteLine("取消删除操作!");
81+
}
82+
return;
83+
}
84+
85+
// 解析 UID 和选项
86+
bool quite = false;
87+
short uid = Utils.ParseInput<short>(Console.ReadLine(), "整数", x => x > 0, "UID必然大于0!");
88+
89+
for (int i = 3; i < args.Length; i++)
90+
{
91+
if (args[i] == "-q")
92+
quite = true;
93+
}
94+
95+
if(!Program.GroupRemove(uid, quite))
96+
Console.WriteLine($"UID{uid} 不存在!");
97+
}
98+
99+
private static void HandleGroupExport(string[] args)
100+
{
101+
if (args.Length < 3)
102+
{
103+
Console.WriteLine("错误:export 命令需要指定 UID 或 使用'all'");
104+
return;
105+
}
106+
107+
string target = args[2].ToLower();
108+
109+
if (target == "all")
110+
{
111+
bool divided = false;
112+
113+
for (int i = 3; i < args.Length; i++)
114+
{
115+
if (args[i] == "-d")
116+
divided = true;
117+
}
118+
119+
Program.ExportGroupAll(divided);
120+
}
121+
else
122+
{
123+
short uid = Utils.ParseInput<short>(Console.ReadLine(), "整数", x => x > 0, "UID必然大于0!");
124+
Program.ExportGroup(uid);
125+
}
126+
}
127+
128+
public static void HandleLogCommand(string[] args)
129+
{
130+
if (args.Length < 2)
131+
{
132+
Console.WriteLine(Log.GetCurrentStatus());
133+
return;
134+
}
135+
136+
string subCommand = args[1].ToLower();
137+
bool realtime = args.Length > 2 && args[2].ToLower() == "intime";
138+
139+
switch (subCommand)
140+
{
141+
case "normal":
142+
Log.SetLevel(LogLevel.NORMAL);
143+
break;
144+
case "warning":
145+
Log.SetLevel(LogLevel.WARNING);
146+
break;
147+
case "fatal":
148+
Log.SetLevel(LogLevel.FATAL);
149+
break;
150+
case "debug":
151+
Log.SetLevel(LogLevel.DEBUG, realtime);
152+
break;
153+
case "show":
154+
Utils.OpenExplorer(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log"));
155+
break;
156+
case "status":
157+
Console.WriteLine(Log.GetCurrentStatus());
158+
break;
159+
default:
160+
Console.WriteLine("未知的日志级别。可用选项: normal, warning, fatal, debug [intime]");
161+
break;
162+
}
163+
}
164+
public static void HandleClearCommand(string[] args)
165+
{
166+
if (args.Length < 2)
167+
{
168+
Console.WriteLine("参数数量不足,请指定要删除的目标");
169+
return;
170+
}
171+
172+
string target = args[1].ToLower();
173+
174+
switch (target)
175+
{
176+
case "log":
177+
ClearDirectory("log", "日志");
178+
break;
179+
180+
case "tmp":
181+
ClearDirectory("tmp", "临时");
182+
break;
183+
184+
default:
185+
Console.WriteLine($"未知的目标 '{target}'");
186+
break;
187+
}
188+
}
189+
190+
private static void ClearDirectory(string directoryName, string displayName)
191+
{
192+
try
193+
{
194+
string programDirectory = AppDomain.CurrentDomain.BaseDirectory;
195+
string targetDirectory = Path.Combine(programDirectory, directoryName);
196+
197+
// 检查目录是否存在,如果不存在则创建并返回
198+
if (!Directory.Exists(targetDirectory))
199+
{
200+
Directory.CreateDirectory(targetDirectory);
201+
Console.WriteLine($"{displayName}目录不存在,已创建新目录: {targetDirectory}");
202+
return;
203+
}
204+
205+
// 获取目录中的所有文件
206+
string[] files = Directory.GetFiles(targetDirectory);
207+
208+
if (files.Length == 0)
209+
{
210+
Console.WriteLine($"{displayName}目录中没有任何文件");
211+
return;
212+
}
213+
214+
// 显示将要删除的文件列表
215+
Console.WriteLine($"找到 {files.Length}{displayName}文件:");
216+
foreach (string file in files)
217+
{
218+
FileInfo fileInfo = new FileInfo(file);
219+
Console.WriteLine($" {Path.GetFileName(file)} ({fileInfo.Length} bytes, 修改时间: {fileInfo.LastWriteTime})");
220+
}
221+
222+
// 确认操作
223+
Console.Write($"确定要删除所有{displayName}文件吗?(y/N): ");
224+
string confirmation = Console.ReadLine()?.Trim().ToLower() ?? "N";
225+
226+
if (confirmation != "y" && confirmation != "yes")
227+
{
228+
Console.WriteLine("操作已取消");
229+
return;
230+
}
231+
232+
// 删除文件
233+
int deletedCount = 0;
234+
foreach (string file in files)
235+
{
236+
try
237+
{
238+
File.Delete(file);
239+
deletedCount++;
240+
Console.WriteLine($"已删除: {Path.GetFileName(file)}");
241+
}
242+
catch (Exception ex)
243+
{
244+
Console.WriteLine($"删除文件失败 {Path.GetFileName(file)}: {ex.Message}");
245+
}
246+
}
247+
248+
Console.WriteLine($"成功删除 {deletedCount}{displayName}文件");
249+
}
250+
catch (Exception ex)
251+
{
252+
Console.WriteLine($"清除{displayName}目录时发生错误: {ex.Message}");
253+
}
254+
}
255+
}

0 commit comments

Comments
 (0)