Repository navigation
卫月启动器添加代理设置功能 #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Errerer
wants to merge
21
commits into
AtmoOmen:CN
Choose a base branch
from
Errerer:CN
base: CN
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
卫月启动器添加代理设置功能 #45
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1e55d56
盛趣协议网络代理支持
Errerer 4e37252
代理设置窗口布局清理
Errerer a2ac76c
Merge branch 'CN' of https://github.com/Errerer/FFXIVQuickLauncherX i…
Errerer 364a11a
Merge branch 'AtmoOmen:CN' into CN
Errerer 0021966
修复代理设置窗口缺少本地组合框样式导致的打开崩溃
Errerer faf3893
代理配置支持多条目预设与激活选择
Errerer 1cc7a8b
Merge branch 'AtmoOmen:CN' into CN
Errerer 3fbc334
修复手动注入读取提权游戏进程主模块导致的拒绝访问
Errerer cab3e2f
Merge branch 'CN' of https://github.com/Errerer/FFXIVQuickLauncherX i…
Errerer 5b3dfca
代理仅对盛趣域名生效并补全大区列表代理
Errerer 2a682e7
代理配置迁移到 Roaming 目录并支持旧文件迁移
Errerer 378b867
修复代理预设增删不落盘并补充 VM 回归测试
Errerer 336edd1
Merge remote-tracking branch 'upstream/CN' into CN
Errerer 7821f01
修复代理窗口切换预设时密码框串写问题
Errerer 6ef109c
对齐上游代码风格: 字段前置、初始化器对齐与可读性拆分
Errerer 28550d6
代理配置并入启动器主配置体系, 旧配置文件启动时自动迁移
Errerer a786f3c
代理设置窗口入口移入 SettingsWindowViewModel 并统一经由 DialogService 打开
Errerer ebdf4b5
复核修正: 迁移成功后仅删除导入源文件, 清理无效 using
Errerer 7642055
按 review 二轮意见修正: 删除迁移与代理测试, 恢复重启生效语义, 支持清空密码, 端口框套深色样式, ProxyConfigSn…
Errerer 47ed010
Merge branch 'AtmoOmen:CN' into CN
Errerer 0d5c835
Merge branch 'AtmoOmen:CN' into CN
Errerer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace XIVLauncher.Common.Http; | ||
|
|
||
| /// <summary> | ||
| /// 代理配置快照, 由应用设置层提供, 避免公共库依赖 UI 层类型 | ||
| /// </summary> | ||
| public sealed record ProxyConfigSnapshot | ||
| ( | ||
| string Type, | ||
| string Host, | ||
| int Port, | ||
| string? Username = null, | ||
| string? Password = null | ||
| ) | ||
| { | ||
| public bool IsDisabled => | ||
| string.IsNullOrWhiteSpace(Host) | ||
| || Port is < 1 or > 65535 | ||
| || string.IsNullOrWhiteSpace(Type) | ||
| || string.Equals(Type, "None", StringComparison.OrdinalIgnoreCase); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| using System.Net; | ||
| using Serilog; | ||
|
|
||
| namespace XIVLauncher.Common.Http; | ||
|
|
||
| /// <summary> | ||
| /// 启动器全局代理提供者, 由启动流程根据代理配置构建一次。 | ||
| /// HTTP/HTTPS/SOCKS5 由 SocketsHttpHandler 原生支持。 | ||
| /// </summary> | ||
| public static class XLProxyProvider | ||
| { | ||
| public static IWebProxy? Current { get; private set; } | ||
|
|
||
| public static void Apply(ProxyConfigSnapshot? config) | ||
| { | ||
| var webProxy = BuildWebProxy(config); | ||
| Current = webProxy is null ? null : new SdoScopedProxy(webProxy); | ||
|
|
||
| Log.Information | ||
| ( | ||
| "[XLProxyProvider] 代理配置已应用 (仅对盛趣域名 *.sdo.com / *.jijiagames.com 生效): {Proxy}", | ||
| webProxy is WebProxy { Address: not null } proxy ? proxy.Address.ToString() : "无" | ||
| ); | ||
| } | ||
|
|
||
| public static IWebProxy? BuildWebProxy(ProxyConfigSnapshot? config) | ||
| { | ||
| if (config is null || config.IsDisabled) | ||
| return null; | ||
|
|
||
| try | ||
| { | ||
| var scheme = config.Type.Trim().ToLowerInvariant() switch | ||
| { | ||
| "http" => "http", | ||
| "https" => "https", | ||
| "socks5" => "socks5", | ||
| _ => null | ||
| }; | ||
|
|
||
| if (scheme == null) | ||
| { | ||
| Log.Warning("[XLProxyProvider] 不支持的代理类型: {ProxyType}", config.Type); | ||
| return null; | ||
| } | ||
|
|
||
| var proxy = new WebProxy($"{scheme}://{config.Host.Trim()}:{config.Port}"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(config.Username)) | ||
| proxy.Credentials = new NetworkCredential(config.Username, config.Password); | ||
|
|
||
| return proxy; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.Warning(ex, "[XLProxyProvider] 构建代理配置失败: {ProxyHost}:{ProxyPort} ({ProxyType})", config.Host, config.Port, config.Type); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 仅对盛趣域名 (*.sdo.com / *.jijiagames.com) 生效的代理包装: | ||
| /// 其余目标一律直连, 避免 GitHub / Dalamud / NuGet 等流量被错误导入代理。 | ||
| /// </summary> | ||
| private sealed class SdoScopedProxy(IWebProxy inner) : IWebProxy | ||
| { | ||
| public ICredentials? Credentials | ||
| { | ||
| get => inner.Credentials; | ||
| set => inner.Credentials = value; | ||
| } | ||
|
|
||
| public Uri? GetProxy(Uri destination) => | ||
| IsSdoHost(destination.Host) ? inner.GetProxy(destination) : destination; | ||
|
|
||
| public bool IsBypassed(Uri host) => | ||
| !IsSdoHost(host.Host); | ||
|
|
||
| private static bool IsSdoHost(string host) => | ||
| string.Equals(host, "sdo.com", StringComparison.OrdinalIgnoreCase) | ||
| || host.EndsWith(".sdo.com", StringComparison.OrdinalIgnoreCase) | ||
| || string.Equals(host, "jijiagames.com", StringComparison.OrdinalIgnoreCase) | ||
| || host.EndsWith(".jijiagames.com", StringComparison.OrdinalIgnoreCase); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.