-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize.cs
280 lines (238 loc) · 9.65 KB
/
initialize.cs
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Management;
using System.Windows;
using System.Globalization;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls.Interfaces;
using Wpf.Ui.Mvvm.Contracts;
namespace 光源AI绘画盒子
{
class initialize//这里负责整个启动器的初始化,也是回复默认设置
{
public static bool CheckDirectory()//首先查找启动器所在目录是否有工作目录,在启动器所在目录创建工作目录
{
if (Directory.Exists(@".AI_launther_log"))
{
return true;
}
else
{
Directory.CreateDirectory(@".AI_launther_log");
return false;
}
}
public static string 背景颜色 = "";
public static string 背景图片 = "";
public static int 背景亮度 = 0;
//下面确定SD_WebUI是否已经安装
public static bool 已下载WebUI = false;
public static bool 已解压WebUI = false;
public static bool 已安装WebUI = false;
//下面是一些启动选项的具体操作
public static bool 浏览器启动 = true;
public static bool 启动api = false;
public static bool 使用快速启动 = false;
public static bool 分享WebUI到公网 = false;
public static bool 使用CPU进行推理 = false;
public static bool 关闭模型hash计算 = false;
public static bool 无卡调试模式 = false;
public static bool XF加速模式 = true;
public static bool 自动加速模式 = true;
public static bool A卡模式 = false;
public static bool N卡模式 = false;
//下面是一些参数的字符串预设
public static string _WebUI性能优化器 = "";
public static string _显卡类型 = "";
public static string _WebUI显存压力优化设置 = "";
public static string _WebUI主题颜色 = "";
public static string _WebUI启动地址 = "";
public static string _WebUI启动端口 = "";
//下面是一些路径管理的具体实现
public static string 工作路径 = "";
public static string pythonPath = "";
public static string gitPath = "";
public static string venvPath = "";
public static string 命令列表 = "";
public static string 程序所在目录 = "";
public static string 路径状态 = "0";
//下面是全局硬件判断
public static string _cpuname = "";
public static string _GPUname = "";
public static string 相册图片数量;
public static string 参数列表 = "";//所有启动时传递的参数挂到这里,全局可编辑与访问
public static void 选择工作路径()
{
FolderBrowserDialog folder = new FolderBrowserDialog();
folder.Description = "请选择WebUI工作目录,至少保留25GB硬盘空间";
if (folder.ShowDialog() == DialogResult.OK)
{
工作路径 = folder.SelectedPath;
File.WriteAllText(@".AI_launther_log\startpath.txt", 工作路径);
}
}
public static void 选择Python路径()
{
FolderBrowserDialog folder = new FolderBrowserDialog();
folder.Description = "请选择Python所在目录,要求python版本3.10.x";
if (folder.ShowDialog() == DialogResult.OK)
{
pythonPath = folder.SelectedPath;
File.WriteAllText(@".AI_launther_log\pythonpath.txt", pythonPath);
}
}
public static void 选择Git路径()
{
FolderBrowserDialog folder = new FolderBrowserDialog();
folder.Description = "请选择Git.exe所在目录";
if (folder.ShowDialog() == DialogResult.OK)
{
gitPath = folder.SelectedPath;
File.WriteAllText(@".AI_launther_log\gitpath.txt", gitPath);
}
}
public static void 选择VENV路径()
{
FolderBrowserDialog folder = new FolderBrowserDialog();
folder.Description = "请选择虚拟环境所在目录";
if (folder.ShowDialog() == DialogResult.OK)
{
venvPath = folder.SelectedPath;
File.WriteAllText(@".AI_launther_log\venvpath.txt", venvPath);
}
}
public static void 获取程序同目录路径()
{
// 获取程序所在目录
程序所在目录 = Directory.GetCurrentDirectory();
}
public static bool CheckWebUIdownloaded() //检查WebUI是否下载
{
string instellPath = 工作路径 + @"\WebUIpack.7z";
if (File.Exists(instellPath))
{
return true;
}
else
{
return false;
}
}
public static bool CheckWebUIunzip() //检查WebUI是否解压
{
string instellPath = 工作路径 + @"\2.0.9\stable-diffusion-webui\webui-user.bat";
if (File.Exists(instellPath))
{
return true;
}
else
{
return false;
}
}
public static bool CheckWebUIinstelled() //检查WebUI是否安装
{
string instellPath = 工作路径 + @"\webui-user.bat";
if (File.Exists(instellPath))
{
return true;
}
else
{
return false;
}
}
public static void CheckCommandline()//这里在初始化后从log里读取保存的args
{
string filePath = @".AI_launther_log\argspath.txt";
if (File.Exists(filePath))
{
// 如果文件存在,读取其中的内容到startpath全局变量中
命令列表 = File.ReadAllText(filePath);
}
}
public static void CheckStartPathFile()//这里在初始化后从log里读取工作路径
{
string filePath = @".AI_launther_log\startpath.txt";
if (File.Exists(filePath))
{
// 如果文件存在,读取其中的内容到startpath全局变量中
工作路径 = File.ReadAllText(filePath);
}
else
{
// 如果文件不存在,创建文件并将默认值写入
路径状态 = "1";
}
}
public static void CheckPythonPathFile()//这里在初始化后从log里读取python路径
{
string filePath = @".AI_launther_log\pythonpath.txt";
if (File.Exists(filePath))
{
// 如果文件存在,读取其中的内容到pythonpath全局变量中
pythonPath = File.ReadAllText(filePath);
}
}
public static void CheckgitPathFile()//这里在初始化后从log里读取git路径
{
string filePath = @".AI_launther_log\gitpath.txt";
if (File.Exists(filePath))
{
// 如果文件存在,读取其中的内容到gitpath全局变量中
gitPath = File.ReadAllText(filePath);
}
}
public static void CheckVENVPathFile()//这里在初始化后从log里读取VENV的路径
{
string filePath = @".AI_launther_log\venvpath.txt";
if (File.Exists(filePath))
{
// 如果文件存在,读取其中的内容到venvpath全局变量中
venvPath = File.ReadAllText(filePath);
}
}
public static void 相册计数()
{
string 相册路径 = 工作路径 + "\\outputs";
if (!Directory.Exists(相册路径))
{
// 如果不存在,将"未找到相册"赋值给A1
相册图片数量 = "未找到相册";
}
else//相册计数功能
{
int imageFileCount = 0;
// 遍历outputs文件夹及其子文件夹
foreach (string directory in Directory.GetDirectories(相册路径, "*", SearchOption.AllDirectories))
{
// 遍历当前目录下的所有文件
foreach (string file in Directory.GetFiles(directory))
{
// 获取文件后缀名
string extension = Path.GetExtension(file);
// 判断是否为图片文件
if (extension == ".png" || extension == ".jpg" || extension == ".jpeg" || extension == ".gif")
{
// 如果是图片文件,图片文件数量加1
imageFileCount++;
}
}
}
// 将图片文件数量写入变量AI
int AI = imageFileCount;
相册图片数量 = AI.ToString();
}
}
}
}