mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
fix potential uri format issue causing program crash
This commit is contained in:
parent
cc48ed54a3
commit
ff5fd5738c
1 changed files with 25 additions and 15 deletions
|
|
@ -50,25 +50,35 @@ namespace Flow.Launcher.Infrastructure.Http
|
|||
/// </summary>
|
||||
public static void UpdateProxy(ProxyProperty property)
|
||||
{
|
||||
(WebProxy.Address, WebProxy.Credentials) = property switch
|
||||
if (string.IsNullOrEmpty(Proxy.Server))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
ProxyProperty.Enabled => Proxy.Enabled switch
|
||||
(WebProxy.Address, WebProxy.Credentials) = property switch
|
||||
{
|
||||
true => Proxy.UserName switch
|
||||
ProxyProperty.Enabled => Proxy.Enabled switch
|
||||
{
|
||||
var userName when !string.IsNullOrEmpty(userName) =>
|
||||
(new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null),
|
||||
_ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"),
|
||||
new NetworkCredential(Proxy.UserName, Proxy.Password))
|
||||
true when !string.IsNullOrEmpty(Proxy.Server) => Proxy.UserName switch
|
||||
{
|
||||
var userName when string.IsNullOrEmpty(userName) =>
|
||||
(new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null),
|
||||
_ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"),
|
||||
new NetworkCredential(Proxy.UserName, Proxy.Password))
|
||||
},
|
||||
_ => (null, null)
|
||||
},
|
||||
false => (null, null)
|
||||
},
|
||||
ProxyProperty.Server => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials),
|
||||
ProxyProperty.Port => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials),
|
||||
ProxyProperty.UserName => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)),
|
||||
ProxyProperty.Password => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
ProxyProperty.Server => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials),
|
||||
ProxyProperty.Port => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials),
|
||||
ProxyProperty.UserName => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)),
|
||||
ProxyProperty.Password => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
catch(UriFormatException e)
|
||||
{
|
||||
Log.Exception("Http", "Unable to parse Uri", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task DownloadAsync([NotNull] string url, [NotNull] string filePath, CancellationToken token = default)
|
||||
|
|
|
|||
Loading…
Reference in a new issue