Shadowsocks Windows 中的配置系统负责存储、加载和管理所有应用程序设置,包括代理服务器配置、应用程序偏好设置和运行时选项。这个中心系统确保设置在应用程序会话之间保持持久性,并为所有组件提供一个一致的接口来与配置数据进行交互。
有关使用配置的 ShadowsocksController 的信息,请参见核心组件:ShadowsocksController。有关服务器管理详情,请参见服务器管理。
来源:shadowsocks-csharp/Model/Configuration.cs shadowsocks-csharp/Model/Server.cs
配置系统围绕两个主要类构建
Configuration 类:包含应用程序所有设置的中心类。
Model/Configuration.csServer 对象列表Server 类:表示单个代理服务器配置。
Model/Server.cs| 属性 | 类型 | 描述 |
|---|---|---|
configs | List<Server> | 配置的代理服务器列表 |
index | int | 当前选中服务器的索引(如果使用策略则为 -1) |
strategy | 字符串 | 服务器选择策略名称(如果未使用策略则为 null) |
enabled | bool | 代理是否启用 |
global | bool | 是否使用全局代理模式(而非 PAC 模式) |
localPort | int | 代理监听的本地端口 |
portableMode | bool | 应用程序是否以便携模式运行 |
shareOverLan | bool | 是否允许其他设备使用此代理 |
pacUrl | 字符串 | PAC 文件的 URL |
onlineConfigSource | List<string> | 在线服务器配置源的 URL 列表 |
配置存储在名为 gui-config.json 的 JSON 文件中。在便携模式下,此文件位于应用程序目录中。在非便携模式下,它存储在用户的 AppData 文件夹中。
当应用程序首次启动或配置文件缺失时,将创建具有以下默认值的配置
来源:shadowsocks-csharp/Model/Configuration.cs63-110
来源:shadowsocks-csharp/Model/Configuration.cs161-276
加载:应用程序启动时,ShadowsocksController 使用静态方法 Configuration.Load() 加载配置,该方法会
Configuration 对象处理:加载后,会调用 Configuration.Process() 来
保存:当设置更改时,Configuration.Save() 方法会
来源:shadowsocks-csharp/Controller/ShadowsocksController.cs shadowsocks-csharp/View/ConfigForm.cs shadowsocks-csharp/View/MenuViewController.cs
配置系统与几个关键组件交互
ShadowsocksController:中心控制器,它
UI 组件:
事件系统:当配置更改时,控制器会触发以下事件,例如
ConfigChanged:通用配置更改EnableStatusChanged:代理启用/禁用状态更改EnableGlobalChanged:全局模式状态更改ShareOverLANStatusChanged:局域网共享状态更改来源:shadowsocks-csharp/View/ConfigForm.cs138-212 shadowsocks-csharp/Controller/ShadowsocksController.cs287-292
ConfigForm 提供了一个用于管理服务器配置的用户界面,包含以下关键操作
添加服务器:向列表中添加一个新的默认服务器
编辑服务器:通过用户界面表单更新服务器属性
删除服务器:从列表中删除一个服务器
验证服务器:保存前,验证服务器属性,包括
保存服务器:使用修改后的服务器更新配置
Shadowsocks 支持通过 URL 字符串导入和导出服务器配置,支持两种格式
旧版格式(正在逐步淘汰)
ss://BASE64(method:password@server:port)#remarks
SIP002 格式(当前标准)
ss://BASE64(method:password)@server:port/?plugin=plugin;plugin_opts#remarks
Server.GetURL() 方法生成这些用于共享的 URL,而 Server.ParseURL() 在导入时解析它们。
来源:shadowsocks-csharp/Model/Server.cs75-119 shadowsocks-csharp/Model/Server.cs183-249
来源:shadowsocks-csharp/Controller/Service/OnlineConfigResolver.cs
应用程序可以从在线源检索服务器配置
在线源:URL 存储在配置中的 onlineConfigSource 列表中
更新过程:
UpdateOnlineConfig(url):从特定 URL 更新服务器UpdateAllOnlineConfig():从源列表中的所有 URL 更新服务器实现:
OnlineConfigResolver.GetOnline(url):从 URL 检索并解析服务器列表group 属性中标记了源 URL配置系统包含对各种设置的验证
服务器验证:在 Configuration.CheckServer() 中
CheckServer())CheckPort())CheckPassword())CheckTimeout())本地端口验证:在 Configuration.CheckLocalPort() 中
Geosite 分组验证:在 Configuration.ValidateGeositeGroupList() 中
来源:shadowsocks-csharp/Model/Configuration.cs145-155 shadowsocks-csharp/Model/Configuration.cs351-382
Configuration 类提供了几个关键方法
| 方法 | 目的 |
|---|---|
Configuration.Load() | 从文件加载配置或创建默认配置 |
Configuration.Process() | 验证并处理加载的配置 |
Configuration.Save() | 将配置保存到文件 |
GetCurrentServer() | 返回当前选中的服务器 |
CheckServer() | 验证服务器配置 |
AddDefaultServerOrServer() | 向配置中添加一个新服务器 |
来源:shadowsocks-csharp/Model/Configuration.cs128-134 shadowsocks-csharp/Model/Configuration.cs161-183 shadowsocks-csharp/Model/Configuration.cs189-241 shadowsocks-csharp/Model/Configuration.cs247-276
配置系统通过以下方式与用户界面紧密集成
ConfigForm:提供用于编辑服务器配置和应用程序设置的用户界面
MenuViewController:使用配置更新系统托盘菜单
当配置更改时,用户界面通过 ShadowsocksController 的事件进行更新。
来源:shadowsocks-csharp/View/ConfigForm.cs418-437 shadowsocks-csharp/View/MenuViewController.cs350-366
配置系统支持在便携模式下运行应用程序
便携模式设置通过 ConfigForm 中的用户界面进行控制。
来源:shadowsocks-csharp/View/ConfigForm.cs433-434 shadowsocks-csharp/View/ConfigForm.Designer.cs504-507