Compare commits

..

1 commit

Author SHA1 Message Date
DHR60
fe33c0e0e6 Fix 2026-02-05 18:02:17 +08:00
12 changed files with 109 additions and 130 deletions

View file

@ -722,7 +722,7 @@ public static class ConfigHandler
SalamanderPass = profileItem.GetProtocolExtra().SalamanderPass?.TrimEx(),
UpMbps = profileItem.GetProtocolExtra().UpMbps is null or < 0 ? config.HysteriaItem.UpMbps : profileItem.GetProtocolExtra().UpMbps,
DownMbps = profileItem.GetProtocolExtra().DownMbps is null or < 0 ? config.HysteriaItem.DownMbps : profileItem.GetProtocolExtra().DownMbps,
HopInterval = profileItem.GetProtocolExtra().HopInterval?.TrimEx(),
HopInterval = profileItem.GetProtocolExtra().HopInterval is null or <= 5 ? Global.Hysteria2DefaultHopInt : profileItem.GetProtocolExtra().HopInterval,
});
await AddServerCommon(config, profileItem, toFile);
@ -745,8 +745,11 @@ public static class ConfigHandler
profileItem.CoreType = ECoreType.sing_box;
profileItem.Address = profileItem.Address.TrimEx();
profileItem.Username = profileItem.Username.TrimEx();
profileItem.Password = profileItem.Password.TrimEx();
profileItem.SetProtocolExtra(profileItem.GetProtocolExtra() with
{
Username = profileItem.GetProtocolExtra().Username?.TrimEx()
});
profileItem.Network = string.Empty;
if (!Global.TuicCongestionControls.Contains(profileItem.HeaderType))

View file

@ -33,7 +33,7 @@ public class SocksFmt : BaseFmt
remark = "#" + Utils.UrlEncode(item.Remarks);
}
//new
var pw = Utils.Base64Encode($"{item.Username}:{item.Password}", true);
var pw = Utils.Base64Encode($"{item.GetProtocolExtra().Username}:{item.Password}", true);
return ToUri(EConfigType.SOCKS, item.Address, item.Port, pw, null, remark);
}
@ -78,7 +78,7 @@ public class SocksFmt : BaseFmt
}
item.Address = arr1[1][..indexPort];
item.Port = arr1[1][(indexPort + 1)..].ToInt();
item.Username = arr21.First();
item.SetProtocolExtra(item.GetProtocolExtra() with { Username = arr21.First() });
item.Password = arr21[1];
return item;
}
@ -103,7 +103,7 @@ public class SocksFmt : BaseFmt
var userInfoParts = userInfo.Split([':'], 2);
if (userInfoParts.Length == 2)
{
item.Username = userInfoParts.First();
item.SetProtocolExtra(item.GetProtocolExtra() with { Username = userInfoParts.First() });
item.Password = userInfoParts[1];
}

View file

@ -24,7 +24,7 @@ public class TuicFmt : BaseFmt
var userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
if (userInfoParts.Length == 2)
{
item.Username = userInfoParts.First();
item.SetProtocolExtra(item.GetProtocolExtra() with { Username = userInfoParts.First() });
item.Password = userInfoParts.Last();
}
@ -53,6 +53,6 @@ public class TuicFmt : BaseFmt
dicQuery.Add("congestion_control", item.HeaderType);
return ToUri(EConfigType.TUIC, item.Address, item.Port, $"{item.Username ?? ""}:{item.Password}", dicQuery, remark);
return ToUri(EConfigType.TUIC, item.Address, item.Port, $"{item.GetProtocolExtra().Username ?? ""}:{item.Password}", dicQuery, remark);
}
}

View file

@ -96,10 +96,7 @@ public sealed class AppManager
_ = StatePort;
_ = StatePort2;
Task.Run(async () =>
{
await MigrateProfileExtra();
}).Wait();
_ = MigrateProfileExtra();
return true;
}
@ -280,95 +277,85 @@ public sealed class AppManager
break;
}
var batchSuccessCount = 0;
foreach (var item in batch)
{
try
{
var extra = item.GetProtocolExtra();
var extra = item.GetProtocolExtra();
if (item.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
if (item.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
{
extra = extra with { GroupType = nameof(item.ConfigType) };
groupItems.TryGetValue(item.IndexId, out var groupItem);
if (groupItem != null && !groupItem.NotHasChild())
{
extra = extra with { GroupType = nameof(item.ConfigType) };
groupItems.TryGetValue(item.IndexId, out var groupItem);
if (groupItem != null && !groupItem.NotHasChild())
extra = extra with
{
extra = extra with
{
ChildItems = groupItem.ChildItems,
SubChildItems = groupItem.SubChildItems,
Filter = groupItem.Filter,
MultipleLoad = groupItem.MultipleLoad,
};
}
ChildItems = groupItem.ChildItems,
SubChildItems = groupItem.SubChildItems,
Filter = groupItem.Filter,
MultipleLoad = groupItem.MultipleLoad,
};
}
switch (item.ConfigType)
{
case EConfigType.Shadowsocks:
extra = extra with { SsMethod = item.Security.NullIfEmpty() };
break;
case EConfigType.VMess:
extra = extra with
{
AlterId = item.AlterId.ToString(),
VmessSecurity = item.Security.NullIfEmpty(),
};
break;
case EConfigType.VLESS:
extra = extra with
{
Flow = item.Flow.NullIfEmpty(),
VlessEncryption = item.Security,
};
break;
case EConfigType.Hysteria2:
extra = extra with
{
SalamanderPass = item.Path.NullIfEmpty(),
Ports = item.Ports.NullIfEmpty(),
UpMbps = _config.HysteriaItem.UpMbps,
DownMbps = _config.HysteriaItem.DownMbps,
HopInterval = _config.HysteriaItem.HopInterval.ToString(),
};
break;
case EConfigType.TUIC:
item.Username = item.Id;
item.Id = item.Security;
item.Password = item.Security;
break;
case EConfigType.HTTP:
case EConfigType.SOCKS:
item.Username = item.Security;
break;
case EConfigType.WireGuard:
extra = extra with
{
WgPublicKey = item.PublicKey.NullIfEmpty(),
WgInterfaceAddress = item.RequestHost.NullIfEmpty(),
WgReserved = item.Path.NullIfEmpty(),
WgMtu = int.TryParse(item.ShortId, out var mtu) ? mtu : 1280
};
break;
}
item.SetProtocolExtra(extra);
item.Password = item.Id;
item.ConfigVersion = 3;
await SQLiteHelper.Instance.UpdateAsync(item);
batchSuccessCount++;
}
catch (Exception ex)
switch (item.ConfigType)
{
Logging.SaveLog($"MigrateProfileExtra Error: {ex}");
case EConfigType.Shadowsocks:
extra = extra with { SsMethod = item.Security.NullIfEmpty() };
break;
case EConfigType.VMess:
extra = extra with
{
AlterId = item.AlterId.ToString(),
VmessSecurity = item.Security.NullIfEmpty(),
};
break;
case EConfigType.VLESS:
extra = extra with
{
Flow = item.Flow.NullIfEmpty(),
VlessEncryption = item.Security,
};
break;
case EConfigType.Hysteria2:
extra = extra with
{
SalamanderPass = item.Path.NullIfEmpty(),
Ports = item.Ports.NullIfEmpty(),
UpMbps = _config.HysteriaItem.UpMbps,
DownMbps = _config.HysteriaItem.DownMbps,
HopInterval = _config.HysteriaItem.HopInterval
};
break;
case EConfigType.TUIC:
extra = extra with
{
Username = item.Id,
};
item.Id = item.Security;
item.Password = item.Security;
break;
case EConfigType.WireGuard:
extra = extra with
{
WgPublicKey = item.PublicKey.NullIfEmpty(),
WgInterfaceAddress = item.RequestHost.NullIfEmpty(),
WgReserved = item.Path.NullIfEmpty(),
WgMtu = int.TryParse(item.ShortId, out var mtu) ? mtu : 1280
};
break;
default:
break;
}
item.SetProtocolExtra(extra);
item.Password = item.Id;
item.ConfigVersion = 3;
await SQLiteHelper.Instance.UpdateAsync(item);
}
// Only increment offset by the number of failed items that remain in the result set
// Successfully updated items are automatically excluded from future queries due to ConfigVersion = 3
offset += batch.Count - batchSuccessCount;
offset += pageSize;
}
//await ProfileGroupItemManager.Instance.ClearAll();

View file

@ -13,7 +13,6 @@ public class ProfileItem : ReactiveObject
Address = string.Empty;
Port = 0;
Password = string.Empty;
Username = string.Empty;
Network = string.Empty;
Remarks = string.Empty;
HeaderType = string.Empty;
@ -152,7 +151,6 @@ public class ProfileItem : ReactiveObject
public string Address { get; set; }
public int Port { get; set; }
public string Password { get; set; }
public string Username { get; set; }
public string Network { get; set; }
public string Remarks { get; set; }
public string HeaderType { get; set; }

View file

@ -15,6 +15,9 @@ public record ProtocolExtraItem
//public string? PluginArgs { get; init; }
public string? SsMethod { get; init; }
// socks and http
public string? Username { get; init; }
// wireguard
public string? WgPublicKey { get; init; }
public string? WgPresharedKey { get; init; }
@ -27,7 +30,7 @@ public record ProtocolExtraItem
public int? UpMbps { get; init; }
public int? DownMbps { get; init; }
public string? Ports { get; init; }
public string? HopInterval { get; init; }
public int? HopInterval { get; init; }
// group profile
public string? GroupType { get; init; }

View file

@ -473,7 +473,7 @@ public class HysteriaSettings4Ray
public class HysteriaUdpHop4Ray
{
public string? ports { get; set; }
public string? interval { get; set; }
public int? interval { get; set; }
}
public class FinalMask4Ray

View file

@ -90,20 +90,20 @@ public partial class CoreConfigSingboxService
case EConfigType.SOCKS:
{
outbound.version = "5";
if (node.Username.IsNotEmpty()
if (protocolExtra.Username.IsNotEmpty()
&& node.Password.IsNotEmpty())
{
outbound.username = node.Username;
outbound.username = protocolExtra.Username;
outbound.password = node.Password;
}
break;
}
case EConfigType.HTTP:
{
if (node.Username.IsNotEmpty()
if (protocolExtra.Username.IsNotEmpty()
&& node.Password.IsNotEmpty())
{
outbound.username = node.Username;
outbound.username = protocolExtra.Username;
outbound.password = node.Password;
}
break;
@ -166,31 +166,16 @@ public partial class CoreConfigSingboxService
return port.Contains(':') ? port : $"{port}:{port}";
})
.ToList();
outbound.hop_interval = _config.HysteriaItem.HopInterval >= 5
? $"{_config.HysteriaItem.HopInterval}s"
: $"{Global.Hysteria2DefaultHopInt}s";
if (int.TryParse(protocolExtra.HopInterval, out var hiResult))
{
outbound.hop_interval = hiResult >= 5 ? $"{hiResult}s" : outbound.hop_interval;
}
else if (protocolExtra.HopInterval?.Contains('-') ?? false)
{
// may be a range like 5-10
var parts = protocolExtra.HopInterval.Split('-');
if (parts.Length == 2 && int.TryParse(parts[0], out var hiL) &&
int.TryParse(parts[0], out var hiH))
{
var hi = (hiL + hiH) / 2;
outbound.hop_interval = hi >= 5 ? $"{hi}s" : outbound.hop_interval;
}
}
outbound.hop_interval = protocolExtra?.HopInterval is { } hi and >= 5
? $"{hi}s"
: _config.HysteriaItem.HopInterval >= 5 ? $"{_config.HysteriaItem.HopInterval}s" : $"{Global.Hysteria2DefaultHopInt}s";
}
break;
}
case EConfigType.TUIC:
{
outbound.uuid = node.Username;
outbound.uuid = protocolExtra.Username;
outbound.password = node.Password;
outbound.congestion_control = node.HeaderType;
break;

View file

@ -97,12 +97,12 @@ public partial class CoreConfigV2rayService
serversItem.method = null;
serversItem.password = null;
if (node.Username.IsNotEmpty()
if (protocolExtra.Username.IsNotEmpty()
&& node.Password.IsNotEmpty())
{
SocksUsersItem4Ray socksUsersItem = new()
{
user = node.Username ?? "",
user = protocolExtra.Username ?? "",
pass = node.Password,
level = 1
};
@ -518,11 +518,9 @@ public partial class CoreConfigV2rayService
int? downMbps = protocolExtra?.DownMbps is { } sd and >= 0
? sd
: _config.HysteriaItem.UpMbps;
var hopInterval = !protocolExtra.HopInterval.IsNullOrEmpty()
? protocolExtra.HopInterval
: (_config.HysteriaItem.HopInterval >= 5
? _config.HysteriaItem.HopInterval
: Global.Hysteria2DefaultHopInt).ToString();
var hopInterval = protocolExtra?.HopInterval is { } hi and >= 5
? hi
: _config.HysteriaItem.HopInterval >= 5 ? _config.HysteriaItem.HopInterval : Global.Hysteria2DefaultHopInt;
HysteriaUdpHop4Ray? udpHop = null;
if (!ports.IsNullOrEmpty() &&
(ports.Contains(':') || ports.Contains('-') || ports.Contains(',')))

View file

@ -33,7 +33,7 @@ public class AddServerViewModel : MyReactiveObject
public int DownMbps { get; set; }
[Reactive]
public string HopInterval { get; set; }
public int HopInterval { get; set; }
[Reactive]
public string Flow { get; set; }
@ -47,6 +47,9 @@ public class AddServerViewModel : MyReactiveObject
[Reactive]
public string SsMethod { get; set; }
[Reactive]
public string Username { get; set; }
[Reactive]
public string WgPublicKey { get; set; }
//[Reactive]
@ -112,10 +115,11 @@ public class AddServerViewModel : MyReactiveObject
SalamanderPass = protocolExtra?.SalamanderPass ?? string.Empty;
UpMbps = protocolExtra?.UpMbps ?? _config.HysteriaItem.UpMbps;
DownMbps = protocolExtra?.DownMbps ?? _config.HysteriaItem.DownMbps;
HopInterval = protocolExtra?.HopInterval.IsNullOrEmpty() ?? true ? Global.Hysteria2DefaultHopInt.ToString() : protocolExtra.HopInterval;
HopInterval = protocolExtra?.HopInterval ?? Global.Hysteria2DefaultHopInt;
VmessSecurity = protocolExtra?.VmessSecurity?.IsNullOrEmpty() == false ? protocolExtra.VmessSecurity : Global.DefaultSecurity;
VlessEncryption = protocolExtra?.VlessEncryption.IsNullOrEmpty() == false ? protocolExtra.VlessEncryption : Global.None;
SsMethod = protocolExtra?.SsMethod ?? string.Empty;
Username = protocolExtra?.Username ?? string.Empty;
WgPublicKey = protocolExtra?.WgPublicKey ?? string.Empty;
WgInterfaceAddress = protocolExtra?.WgInterfaceAddress ?? string.Empty;
WgReserved = protocolExtra?.WgReserved ?? string.Empty;
@ -174,10 +178,11 @@ public class AddServerViewModel : MyReactiveObject
SalamanderPass = SalamanderPass.NullIfEmpty(),
UpMbps = UpMbps >= 0 ? UpMbps : null,
DownMbps = DownMbps >= 0 ? DownMbps : null,
HopInterval = HopInterval.NullIfEmpty(),
HopInterval = HopInterval >= 5 ? HopInterval : null,
VmessSecurity = VmessSecurity.NullIfEmpty(),
VlessEncryption = VlessEncryption.NullIfEmpty(),
SsMethod = SsMethod.NullIfEmpty(),
Username = Username.NullIfEmpty(),
WgPublicKey = WgPublicKey.NullIfEmpty(),
WgInterfaceAddress = WgInterfaceAddress.NullIfEmpty(),
WgReserved = WgReserved.NullIfEmpty(),

View file

@ -126,7 +126,7 @@ public partial class AddServerWindow : WindowBase<AddServerViewModel>
case EConfigType.SOCKS:
case EConfigType.HTTP:
this.Bind(ViewModel, vm => vm.SelectedSource.Password, v => v.txtId4.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Username, v => v.txtSecurity4.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Username, v => v.txtSecurity4.Text).DisposeWith(disposables);
break;
case EConfigType.VLESS:
@ -152,7 +152,7 @@ public partial class AddServerWindow : WindowBase<AddServerViewModel>
break;
case EConfigType.TUIC:
this.Bind(ViewModel, vm => vm.SelectedSource.Username, v => v.txtId8.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Username, v => v.txtId8.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Password, v => v.txtSecurity8.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.HeaderType, v => v.cmbHeaderType8.SelectedValue).DisposeWith(disposables);
break;

View file

@ -121,7 +121,7 @@ public partial class AddServerWindow
case EConfigType.SOCKS:
case EConfigType.HTTP:
this.Bind(ViewModel, vm => vm.SelectedSource.Password, v => v.txtId4.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Username, v => v.txtSecurity4.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Username, v => v.txtSecurity4.Text).DisposeWith(disposables);
break;
case EConfigType.VLESS:
@ -147,7 +147,7 @@ public partial class AddServerWindow
break;
case EConfigType.TUIC:
this.Bind(ViewModel, vm => vm.SelectedSource.Username, v => v.txtId8.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Username, v => v.txtId8.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Password, v => v.txtSecurity8.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.HeaderType, v => v.cmbHeaderType8.Text).DisposeWith(disposables);
break;