Skip to content

Commit

Permalink
新增启用日志设置项
Browse files Browse the repository at this point in the history
修复twitch反代聊天连接错误和直播视频无法观看
使httpclient更稳定
  • Loading branch information
rmbadmin committed Jan 11, 2021
1 parent 4550ff1 commit 3ab0ae4
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 128 deletions.
112 changes: 40 additions & 72 deletions source/SteamTool.Core/HttpServices.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using Ninject.Modules;
using SteamTool.Core.Common;
using System;
using System.Collections.Generic;
using System.Dynamic;
Expand All @@ -19,23 +20,47 @@ public class HttpServices

public string Accept { get; set; } = "application/json";

public async Task<string> Get(string url)
private async Task<string> SendAsync(HttpRequestMessage request)
{
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add("User-Agent", UserAgent);
request.Headers.Add("Accept", Accept);

var response = await _client.SendAsync(request).ConfigureAwait(false);
try
{
var response = await _client.SendAsync(request).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
}
catch (Exception ex)
{
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Logger.Error(ex);
}
else
return null;
}
private async Task<Stream> SendAsyncAsStream(HttpRequestMessage request)
{
try
{
return null;
var response = await _client.SendAsync(request).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
}
}
catch (Exception ex)
{
Logger.Error(ex);
}
return null;
}

public async Task<string> Get(string url)
{
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add("User-Agent", UserAgent);
request.Headers.Add("Accept", Accept);
return await SendAsync(request);
}
public async Task<string> Get(string url, Dictionary<string, string> keyValuePairs)
{
Expand All @@ -53,20 +78,7 @@ public async Task<string> Get(string url, Dictionary<string, string> keyValuePai
{
request.Headers.Add("Accept", Accept);
}


var response = await _client.SendAsync(request).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);

}
else
{
return null;
}

return await SendAsync(request);
}
public async Task<Stream> GetStream(string url, Dictionary<string, string> keyValuePairs)
{
Expand All @@ -85,18 +97,7 @@ public async Task<Stream> GetStream(string url, Dictionary<string, string> keyVa
request.Headers.Add("Accept", Accept);
}


var response = await _client.SendAsync(request).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
}
else
{
return null;
}

return await SendAsyncAsStream(request);
}

public async Task<string> Post(string url, string content)
Expand All @@ -107,18 +108,7 @@ public async Task<string> Post(string url, string content)
};
request.Headers.Add("User-Agent", UserAgent);
request.Headers.Add("Accept", Accept);

var response = await _client.SendAsync(request).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
else
{
return null;
}

return await SendAsync(request);
}
public async Task<string> Post(string url, Dictionary<string, string> keyValuePairs, string content)
{
Expand All @@ -139,18 +129,7 @@ public async Task<string> Post(string url, Dictionary<string, string> keyValuePa
request.Headers.Add("Accept", Accept);
}


var response = await _client.SendAsync(request).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
else
{
return null;
}

return await SendAsync(request);
}
public async Task<Stream> PostStream(string url, Dictionary<string, string> keyValuePairs, Stream content)
{
Expand All @@ -171,18 +150,7 @@ public async Task<Stream> PostStream(string url, Dictionary<string, string> keyV
request.Headers.Add("Accept", Accept);
}


var response = await _client.SendAsync(request).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
}
else
{
return null;
}

return await SendAsyncAsStream(request);
}
}
}
6 changes: 2 additions & 4 deletions source/SteamTool.Core/SteamToolService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ public SteamToolService()
{
var steamExePath = registryKeyService.ReadRegistryKey(Registry.CurrentUser, SteamRegistryPath, "SteamExe");
var steamPath = registryKeyService.ReadRegistryKey(Registry.CurrentUser, SteamRegistryPath, "SteamPath");
//steamExePath = Path.GetFullPath(steamExePath);
//steamPath = Path.GetFullPath(steamPath);
if (File.Exists(steamExePath))
{
SteamExePath = steamExePath;
SteamExePath = Path.GetFullPath(steamExePath);
}
if (Directory.Exists(steamPath))
{
SteamPath = steamPath;
SteamPath = Path.GetFullPath(steamPath);
}
}

Expand Down
1 change: 1 addition & 0 deletions source/SteamTool.Model/Const.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Const
public const string AUTHDATA_FILE = "authenticators.dat";
public const string SETTINGS_FILE = "settings.json";
public const string SCRIPT_DIR = "scripts";
public const string LOG_DIR = "log";
public const string HOST_TAG = "#S302";

public const string REWARDMELIST_URL = "https://gitee.com/rmbgame/steam-tools_-data/raw/master/RewardRecord.json";
Expand Down
15 changes: 10 additions & 5 deletions source/SteamTool.Proxy/HttpProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ public bool StartProxy(bool IsProxyGOG = false)
return false;
}
}
//if (PortInUse(443))
//{
// return false;
//}
if (PortInUse(443))
{
return false;
}
if (IsProxyGOG) { WirtePemCertificateToGoGSteamPlugins(); }

#region 写入Hosts
Expand Down Expand Up @@ -373,6 +373,12 @@ public bool StartProxy(bool IsProxyGOG = false)
//GenericCertificate = proxyServer.CertificateManager.RootCertificate
};
proxyServer.AddEndPoint(transparentEndPoint);

proxyServer.ExceptionFunc = ((Exception exception) =>
{
Logger.Error(exception);
});

try
{
proxyServer.Start();
Expand All @@ -385,7 +391,6 @@ public bool StartProxy(bool IsProxyGOG = false)
//proxyServer.UpStreamHttpProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 };
//proxyServer.UpStreamHttpsProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 };
#endregion

#if DEBUG
foreach (var endPoint in proxyServer.ProxyEndPoints)
Debug.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ",
Expand Down
2 changes: 2 additions & 0 deletions source/SteamTool.Proxy/Model/ProxyDomainModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,7 @@ public enum DomainTag : byte
DiscordNet = 11,
[Description("Uplay更新防劫持")]
UplayUpdate = 12,
[Description("Twitch聊天")]
TwitchChat = 13,
}
}
9 changes: 9 additions & 0 deletions source/SteamTool.Proxy/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions source/SteamTool.Proxy/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<data name="Twitch" xml:space="preserve">
<value>Twitch直播</value>
</data>
<data name="TwitchChat" xml:space="preserve">
<value>Twitch聊天</value>
</data>
<data name="UplayUpdate" xml:space="preserve">
<value>Uplay更新</value>
</data>
Expand Down
8 changes: 3 additions & 5 deletions source/SteamTool.Steam.Service/Web/SteamworksWebApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ public async Task<SteamUser> GetUserInfo(long steamId64)
var r = await httpServices.Get(string.Format(Const.STEAM_USERINFO_XML_URL, steamId64));
if (!string.IsNullOrEmpty(r))
{
using (StringReader sr = new StringReader(r))
{
var xmldes = new XmlSerializer(typeof(SteamUser));
return xmldes.Deserialize(sr) as SteamUser;
}
using StringReader sr = new StringReader(r);
var xmldes = new XmlSerializer(typeof(SteamUser));
return xmldes.Deserialize(sr) as SteamUser;
}
return new SteamUser() { SteamId64 = steamId64 };
}
Expand Down
10 changes: 5 additions & 5 deletions source/SteamTools/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected override void OnStartup(StartupEventArgs e)
App.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
DispatcherHelper.UIDispatcher = this.Dispatcher;
if (e.Args.ContainsArg("-log"))
if (e.Args.ContainsArg("-log") || GeneralSettings.IsEnableLogRecord)
{
Logger.EnableTextLog = true;
}
Expand Down Expand Up @@ -235,7 +235,7 @@ private void ProcessCommandLineParameter(string[] args)
}


#region INotifyPropertyChanged members
#region INotifyPropertyChanged members

private event PropertyChangedEventHandler PropertyChangedInternal;
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
Expand All @@ -249,9 +249,9 @@ private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
this.PropertyChangedInternal?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

#endregion
#endregion

#region IDisposable members
#region IDisposable members
private readonly LivetCompositeDisposable compositeDisposable = new LivetCompositeDisposable();
ICollection<IDisposable> IDisposableHolder.CompositeDisposable => this.compositeDisposable;

Expand All @@ -261,6 +261,6 @@ void IDisposable.Dispose()
this.compositeDisposable.Dispose();
}

#endregion
#endregion
}
}
14 changes: 14 additions & 0 deletions source/SteamTools/Models/Settings/GeneralSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MetroTrilithon.Serialization;
using SteamTool.Core;
using SteamTool.Core.Common;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,6 +14,12 @@ public static class GeneralSettings
static GeneralSettings()
{
WindowsStartupAutoRun.ValueChanged += WindowsStartupAutoRun_ValueChanged;
IsEnableLogRecord.ValueChanged += IsEnableLogRecord_ValueChanged;
}

private static void IsEnableLogRecord_ValueChanged(object sender, ValueChangedEventArgs<bool> e)
{
Logger.EnableTextLog = e.NewValue;
}

private static void WindowsStartupAutoRun_ValueChanged(object sender, ValueChangedEventArgs<bool> e)
Expand Down Expand Up @@ -69,6 +76,13 @@ private static void WindowsStartupAutoRun_ValueChanged(object sender, ValueChang
public static SerializableProperty<bool> IsAutoCheckUpdate { get; }
= new SerializableProperty<bool>(GetKey(), Providers.Roaming, true) { AutoSave = true };

/// <summary>
/// 启用错误日志记录
/// </summary>
public static SerializableProperty<bool> IsEnableLogRecord { get; }
= new SerializableProperty<bool>(GetKey(), Providers.Roaming, false) { AutoSave = true };


private static string GetKey([CallerMemberName] string propertyName = "")
{
return nameof(GeneralSettings) + "." + propertyName;
Expand Down
3 changes: 1 addition & 2 deletions source/SteamTools/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"profiles": {
"SteamTools": {
"commandName": "Project",
"commandLineArgs": "-log"
"commandName": "Project"
}
}
}
Loading

0 comments on commit 3ab0ae4

Please sign in to comment.