mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
[PTRun]removed obsolete Wox code based on WebRequest (#19038)
This commit is contained in:
committed by
GitHub
parent
6ccc059d7a
commit
27c52bebc7
@@ -18,7 +18,6 @@ using PowerLauncher.Plugin;
|
|||||||
using PowerLauncher.ViewModel;
|
using PowerLauncher.ViewModel;
|
||||||
using Wox;
|
using Wox;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Http;
|
|
||||||
using Wox.Infrastructure.Image;
|
using Wox.Infrastructure.Image;
|
||||||
using Wox.Infrastructure.UserSettings;
|
using Wox.Infrastructure.UserSettings;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
@@ -129,9 +128,6 @@ namespace PowerLauncher
|
|||||||
Current.MainWindow = _mainWindow;
|
Current.MainWindow = _mainWindow;
|
||||||
Current.MainWindow.Title = Constant.ExeFileName;
|
Current.MainWindow.Title = Constant.ExeFileName;
|
||||||
|
|
||||||
// main windows needs initialized before theme change because of blur settings
|
|
||||||
HttpClient.Proxy = _settings.Proxy;
|
|
||||||
|
|
||||||
RegisterExitEvents();
|
RegisterExitEvents();
|
||||||
|
|
||||||
_settingsReader.ReadSettingsOnChange();
|
_settingsReader.ReadSettingsOnChange();
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
||||||
// See the LICENSE file in the project root for more information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
|
|
||||||
namespace PowerLauncher.Helper
|
|
||||||
{
|
|
||||||
public class DataWebRequestFactory : IWebRequestCreate
|
|
||||||
{
|
|
||||||
private class DataWebRequest : WebRequest
|
|
||||||
{
|
|
||||||
private readonly Uri _uri;
|
|
||||||
|
|
||||||
#pragma warning disable SYSLIB0014 // Type or member is obsolete
|
|
||||||
|
|
||||||
// TODO: Verify if it's dead code or replace with HttpClient
|
|
||||||
public DataWebRequest(Uri uri)
|
|
||||||
{
|
|
||||||
_uri = uri;
|
|
||||||
}
|
|
||||||
#pragma warning restore SYSLIB0014 // Type or member is obsolete
|
|
||||||
|
|
||||||
public override WebResponse GetResponse()
|
|
||||||
{
|
|
||||||
return new DataWebResponse(_uri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DataWebResponse : WebResponse
|
|
||||||
{
|
|
||||||
private readonly string _contentType;
|
|
||||||
private readonly byte[] _data;
|
|
||||||
|
|
||||||
public DataWebResponse(Uri uri)
|
|
||||||
{
|
|
||||||
string uriString = uri.AbsoluteUri;
|
|
||||||
|
|
||||||
// Using Ordinal since this is internal and used with a symbol
|
|
||||||
int commaIndex = uriString.IndexOf(',', StringComparison.Ordinal);
|
|
||||||
var headers = uriString.Substring(0, commaIndex).Split(';');
|
|
||||||
_contentType = headers[0];
|
|
||||||
string dataString = uriString.Substring(commaIndex + 1);
|
|
||||||
_data = Convert.FromBase64String(dataString);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ContentType
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _contentType;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override long ContentLength
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _data.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Stream GetResponseStream()
|
|
||||||
{
|
|
||||||
return new MemoryStream(_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebRequest Create(Uri uri)
|
|
||||||
{
|
|
||||||
return new DataWebRequest(uri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,19 +5,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Common.UI;
|
using Common.UI;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
using Microsoft.Toolkit.Uwp.Notifications;
|
using Microsoft.Toolkit.Uwp.Notifications;
|
||||||
using PowerLauncher.Helper;
|
|
||||||
using PowerLauncher.Plugin;
|
using PowerLauncher.Plugin;
|
||||||
using PowerLauncher.ViewModel;
|
using PowerLauncher.ViewModel;
|
||||||
using Windows.UI.Notifications;
|
using Windows.UI.Notifications;
|
||||||
using Wox.Infrastructure.Image;
|
using Wox.Infrastructure.Image;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Plugin.Logger;
|
|
||||||
|
|
||||||
namespace Wox
|
namespace Wox
|
||||||
{
|
{
|
||||||
@@ -36,7 +32,6 @@ namespace Wox
|
|||||||
_mainVM = mainVM ?? throw new ArgumentNullException(nameof(mainVM));
|
_mainVM = mainVM ?? throw new ArgumentNullException(nameof(mainVM));
|
||||||
_themeManager = themeManager ?? throw new ArgumentNullException(nameof(themeManager));
|
_themeManager = themeManager ?? throw new ArgumentNullException(nameof(themeManager));
|
||||||
_themeManager.ThemeChanged += OnThemeChanged;
|
_themeManager.ThemeChanged += OnThemeChanged;
|
||||||
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
|
|
||||||
|
|
||||||
ToastNotificationManagerCompat.OnActivated += args =>
|
ToastNotificationManagerCompat.OnActivated += args =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
||||||
// See the LICENSE file in the project root for more information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Wox.Infrastructure.UserSettings;
|
|
||||||
using Wox.Plugin.Logger;
|
|
||||||
|
|
||||||
namespace Wox.Infrastructure.Http
|
|
||||||
{
|
|
||||||
public static class HttpClient
|
|
||||||
{
|
|
||||||
private const string UserAgent = @"Mozilla/5.0 (Trident/7.0; rv:11.0) like Gecko";
|
|
||||||
|
|
||||||
public static HttpProxy Proxy { get; set; }
|
|
||||||
|
|
||||||
public static IWebProxy WebProxy()
|
|
||||||
{
|
|
||||||
if (Proxy != null && Proxy.Enabled && !string.IsNullOrEmpty(Proxy.Server))
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(Proxy.UserName) || string.IsNullOrEmpty(Proxy.Password))
|
|
||||||
{
|
|
||||||
var webProxy = new WebProxy(Proxy.Server, Proxy.Port);
|
|
||||||
return webProxy;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var webProxy = new WebProxy(Proxy.Server, Proxy.Port)
|
|
||||||
{
|
|
||||||
Credentials = new NetworkCredential(Proxy.UserName, Proxy.Password),
|
|
||||||
};
|
|
||||||
return webProxy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return WebRequest.GetSystemWebProxy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Download([NotNull] Uri url, [NotNull] string filePath)
|
|
||||||
{
|
|
||||||
if (url == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(url));
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma warning disable SYSLIB0014 // Type or member is obsolete
|
|
||||||
|
|
||||||
// TODO: Verify if it's dead code or replace with HttpClient
|
|
||||||
var client = new WebClient { Proxy = WebProxy() };
|
|
||||||
#pragma warning restore SYSLIB0014 // Type or member is obsolete
|
|
||||||
client.Headers.Add("user-agent", UserAgent);
|
|
||||||
client.DownloadFile(url.AbsoluteUri, filePath);
|
|
||||||
client.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user