Skip to content

Commit

Permalink
帐户切换功能增加离线模式选项
Browse files Browse the repository at this point in the history
更改了许多文本问题
  • Loading branch information
rmbadmin committed Jan 7, 2021
1 parent c01512b commit 42b11ce
Show file tree
Hide file tree
Showing 36 changed files with 543 additions and 250 deletions.
2 changes: 1 addition & 1 deletion packaging/net5.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dotnet publish ..\source\SteamTools -c Release -f net5.0-windows -r win-x86 -p:PublishSingleFile=true -p:UseAppHost=true --self-contained false -o out/result
dotnet publish ..\source\SteamTools -c Release -f net5.0-windows -r win-x86 - /p:PublishSingleFile=true /p:PublishTrimmed=true -o out/result
8 changes: 8 additions & 0 deletions resources/RewardRecord.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,13 @@
"PayType": 2,
"Remark": "感谢大佬",
"PayTime": "2021-01-05 16:22:11"
},
{
"Name": "**彬",
"Amount": 5,
"OrderNumber": "",
"PayType": 1,
"Remark": "平其心论天下之事,定其心应天下之变",
"PayTime": "2021-01-06 17:08:36"
}
]
1 change: 1 addition & 0 deletions source/SteamTool.Authenticator/SteamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;

#if NETFX_4
using System.Runtime.Serialization;
using System.Threading.Tasks;
Expand Down
14 changes: 6 additions & 8 deletions source/SteamTool.Core/Common/CertificateEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ public static string GetPrivatePemCertificateString(this X509Certificate2 @this)
RSACryptoServiceProvider pkey = (RSACryptoServiceProvider)@this.PrivateKey;

AsymmetricCipherKeyPair keyPair = DotNetUtilities.GetRsaKeyPair(pkey);
using (TextWriter tw = new StreamWriter(Path.Combine(AppContext.BaseDirectory, @this.IssuerName.Name + ".key")))
{
PemWriter pw = new PemWriter(tw);
pw.WriteObject(keyPair.Private);
tw.Flush();
return tw.ToString();
}
using TextWriter tw = new StreamWriter(Path.Combine(AppContext.BaseDirectory, @this.IssuerName.Name + ".key"));
PemWriter pw = new PemWriter(tw);
pw.WriteObject(keyPair.Private);
tw.Flush();
return tw.ToString();
}

public static List<string> GetSubjectAlternativeNames(this X509Certificate2 certificate)
Expand All @@ -56,7 +54,7 @@ public static List<string> GetSubjectAlternativeNames(this X509Certificate2 cert
//Console.WriteLine(asndata.Format(true));

return new List<string>(
asndata.Format(true).Split(new string[] { "\r\n", "DNS Name=" },
asndata.Format(true).Split(new string[] { Environment.NewLine, "DNS Name=" },
StringSplitOptions.RemoveEmptyEntries));
}

Expand Down
19 changes: 19 additions & 0 deletions source/SteamTool.Core/Common/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ namespace SteamTool.Core.Common
{
public static class Common
{
/// <summary>
/// 时间戳转DateTime(系统时区)
/// </summary>
/// <returns></returns>
public static DateTime ToDateTime(this long timestamp)
{
return TimeZoneInfo.ConvertTimeFromUtc(new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(timestamp), TimeZoneInfo.Local);
}

/// <summary>
/// 返回当前时间戳
/// </summary>
Expand Down Expand Up @@ -37,6 +46,16 @@ public static string GetCurrentPath(this string url)
}
}

/// <summary>
/// 移除字符串内所有\r \n \t
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string RemovePattern(this string inputString)
{
return inputString.Replace("\t", "").Replace("\r", "").Replace("\n", "");
}

/// <summary>
/// 获取两个字符串中间的字符串
/// </summary>
Expand Down
46 changes: 29 additions & 17 deletions source/SteamTool.Core/SteamToolService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public bool IsAdministrator

public const string UserDataDirectory = @"\userdata";

/*
Windows: ~\Steam\config\loginusers.vdf
Linux: ~/.steam/steam/config/loginusers.vdf
Mac: ~/Library/Application Support/Steam/config/loginusers.vdf
*/
public const string UserVdfPath = @"\config\loginusers.vdf";

private const string SteamRegistryPath = @"SOFTWARE\Valve\Steam";
Expand All @@ -62,7 +67,7 @@ public void KillSteamProcess()
Process[] processes = Process.GetProcesses();
foreach (Process process in processes)
{
if (process.ProcessName.Equals("steam", StringComparison.OrdinalIgnoreCase) || process.ProcessName.Equals("steamService", StringComparison.OrdinalIgnoreCase) || process.ProcessName.Equals("steamwebhelper", StringComparison.OrdinalIgnoreCase))
if (process.ProcessName.Equals("steam", StringComparison.OrdinalIgnoreCase) || process.ProcessName.Equals("steamservice", StringComparison.OrdinalIgnoreCase) || process.ProcessName.Equals("steamwebhelper", StringComparison.OrdinalIgnoreCase))
{
process.Kill();
}
Expand Down Expand Up @@ -90,38 +95,40 @@ public string GetLastLoginUserName()
/// 获取所有记住登陆steam用户信息
/// </summary>
/// <returns></returns>
public List<SteamUser> GetAllUser()
public List<SteamUser> GetRememberUserList()
{
var users = new List<SteamUser>();
if (File.Exists(SteamPath + UserVdfPath))
{
var v = vdfService.GetVdfModelByPath(SteamPath + UserVdfPath);

foreach (var item in v.Value)
{
var i = item.Value;
var user = new SteamUser
var user = new SteamUser(item.ToString())
{
SteamId64 = Convert.ToInt64(item.Key.ToString()),
AccountName = i.AccountName?.ToString(),
SteamID = i.PersonaName?.ToString(),
RememberPassword = Convert.ToBoolean(Convert.ToInt64(i.RememberPassword?.ToString())),
Timestamp = Convert.ToInt64(i.Timestamp?.ToString())
};
user.PersonaName = user.SteamID;
user.LastLoginTime = user.Timestamp.ToDateTime();

//老版本Steam数据 小写mostrecent 支持
user.MostRecent = i.mostrecent != null ?
Convert.ToBoolean(Convert.ToByte(i.mostrecent.ToString())) :
Convert.ToBoolean(Convert.ToByte(i.MostRecent.ToString()));

user.WantsOfflineMode = i.WantsOfflineMode != null ?
Convert.ToBoolean(Convert.ToByte(i.WantsOfflineMode.ToString())) : false;

// 因为警告这个东西应该都不需要所以直接默认跳过好了
user.SkipOfflineModeWarning = true;
//user.SkipOfflineModeWarning = i.SkipOfflineModeWarning != null ?
// Convert.ToBoolean(Convert.ToByte(i.SkipOfflineModeWarning.ToString())) : false;

user.LastLoginTime = TimeZoneInfo.ConvertTimeFromUtc(new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(user.Timestamp), TimeZoneInfo.Local);
if (i.mostrecent != null)//老版本Steam数据 小写mostrecent 支持
{
user.MostRecent = Convert.ToBoolean(Convert.ToInt64(i.mostrecent.ToString()));
}
else if (i.MostRecent != null)
{
user.MostRecent = Convert.ToBoolean(Convert.ToInt64(i.MostRecent.ToString()));
}
else
{
user.MostRecent = false;
}
users.Add(user);
}
}
Expand Down Expand Up @@ -214,5 +221,10 @@ public void DeleteSteamLocalUserData(SteamUser user)
Directory.Delete(temp, true);
}
}

public void UpdateSteamLocalUserData(SteamUser user)
{
vdfService.UpdateVdfValueByReplace(SteamPath + UserVdfPath, user.OriginVdfString, user.CurrentVdfString);
}
}
}
17 changes: 17 additions & 0 deletions source/SteamTool.Core/VdfService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Gameloop.Vdf;
using Gameloop.Vdf.Linq;
using SteamTool.Core.Common;

namespace SteamTool.Core
{
Expand All @@ -33,6 +34,14 @@ public dynamic GetVdfModelByPath(string path)
return GetVdfModel(text);
}

public void UpdateVdfValueByReplace(string path, string oldVaule, string newValue)
{
string text = File.ReadAllText(path, Encoding.UTF8);
text = text.RemovePattern().Replace(
oldVaule.RemovePattern().Replace(" ",string.Empty), newValue);
//Debug.WriteLine(text);
File.WriteAllText(path, text, Encoding.UTF8);
}

public void DeleteVdfValueByKey(string path, string key)
{
Expand All @@ -44,5 +53,13 @@ public void DeleteVdfValueByKey(string path, string key)
//Debug.WriteLine(text);
File.WriteAllText(path, text, Encoding.UTF8);
}

public void DeleteVdfValueByReplace(string path, string oldVaule)
{
string text = File.ReadAllText(path, Encoding.UTF8);
text = text.Replace(oldVaule, string.Empty);
//Debug.WriteLine(text);
File.WriteAllText(path, text, Encoding.UTF8);
}
}
}
52 changes: 46 additions & 6 deletions source/SteamTool.Model/SteamModel/SteamUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ namespace SteamTool.Model
{
public class SteamUser
{
public SteamUser() { }

public SteamUser(string vdfstring)
{
OriginVdfString = vdfstring;
}

public string SteamId3 { get; set; }
public long SteamId3_Int => ((SteamId64 >> (ushort)0) & 0xFFFFFFFF);

Expand Down Expand Up @@ -32,19 +39,19 @@ public class SteamUser
public string PrivacyState { get; set; }

/// <summary>
/// 头像链接
/// 头像小图标
/// </summary>
public string AvatarIcon { get; set; }

/// <summary>
/// 头像链接
/// 头像中等图片链接
/// </summary>
public string AvatarMedium { get; set; }
public string AvatarMedium { get; set; } = "/Resources/Asstes/avater.jpg";

/// <summary>
/// 头像链接
/// 头像大图链接
/// </summary>
public string AvatarFull { get; set; }
public string AvatarFull { get; set; }

/// <summary>
/// 昵称
Expand All @@ -54,7 +61,12 @@ public class SteamUser
/// <summary>
/// 昵称
/// </summary>
public string SteamNickName => string.IsNullOrEmpty(SteamID) ? "无法获取此账户昵称" : SteamID;
public string SteamNickName => string.IsNullOrEmpty(SteamID) ? PersonaName : SteamID;

/// <summary>
/// 从VDF读取到的用户名
/// </summary>
public string PersonaName { get; set; } = "No Name";

/// <summary>
/// 用户名
Expand Down Expand Up @@ -86,9 +98,37 @@ public class SteamUser
/// </summary>
public bool MostRecent { get; set; }

/// <summary>
/// 离线模式
/// </summary>
public bool WantsOfflineMode { get; set; }

/// <summary>
/// 忽略离线模式警告弹窗
/// </summary>
public bool SkipOfflineModeWarning { get; set; }

/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }

/// <summary>
/// 来源VDF字符串
/// </summary>
public string OriginVdfString { get; set; }

/// <summary>
/// 导出VDF配置字符串
/// </summary>
public string CurrentVdfString =>
"\"" + SteamId64 + "\"\n{\n" +
"\t\t\"AccountName\"\t\t\"" + AccountName + "\"\n" +
"\t\t\"PersonaName\"\t\t\"" + PersonaName + "\"\n" +
"\t\t\"RememberPassword\"\t\t\"" + Convert.ToByte(RememberPassword) + "\"\n" +
"\t\t\"MostRecent\"\t\t\"" + Convert.ToByte(MostRecent) + "\"\n" +
"\t\t\"WantsOfflineMode\"\t\t\"" + Convert.ToByte(WantsOfflineMode) + "\"\n" +
"\t\t\"SkipOfflineModeWarning\"\t\t\"" + Convert.ToByte(SkipOfflineModeWarning) + "\"\n" +
"\t\t\"Timestamp\"\t\t\"" + Timestamp + "\"\n}";
}
}
4 changes: 2 additions & 2 deletions source/SteamTool.Proxy/HttpProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public async Task OnRequest(object sender, SessionEventArgs e)
}

//没有匹配到的结果直接返回不支持,避免出现Loopback死循环内存溢出
e.Ok($"URL : {e.HttpClient.Request.RequestUri.AbsoluteUri} \r\n not support proxy");
e.Ok($"URL : {e.HttpClient.Request.RequestUri.AbsoluteUri} {Environment.NewLine} not support proxy");
return;
}
public async Task OnResponse(object sender, SessionEventArgs e)
Expand Down Expand Up @@ -427,7 +427,7 @@ public bool WirtePemCertificateToGoGSteamPlugins()
var s = file.Substring(Const.HOST_TAG, Const.HOST_TAG, true);
if (string.IsNullOrEmpty(s))
{
File.AppendAllText(certifi, "\r\n" + pem);
File.AppendAllText(certifi, Environment.NewLine + pem);
}
else if (s.Trim() != pem.Trim())
{
Expand Down
20 changes: 12 additions & 8 deletions source/SteamTools/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public partial class App : INotifyPropertyChanged, IDisposableHolder
{
public static App Instance => Current as App;

#if !NETCOREAPP
public string ProgramName => Path.GetFileName(Environment.GetCommandLineArgs()[0]);
#else
public string ProgramName => Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
#endif

public DirectoryInfo LocalAppData = new DirectoryInfo(
Path.Combine(
Expand All @@ -57,7 +61,7 @@ private void SetWebBrowserIeVersion()
{
try
{
SteamToolCore.Instance.Get<RegistryKeyService>().AddOrUpdateRegistryKey(Registry.CurrentUser, @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", ProgramName, "11001", RegistryValueKind.DWord);
SteamToolCore.Instance.Get<RegistryKeyService>().AddOrUpdateRegistryKey(Registry.CurrentUser, @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", ProgramName, "10001", RegistryValueKind.DWord);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -102,7 +106,7 @@ protected override void OnStartup(StartupEventArgs e)
AuthService.Current.Initialize();
ProxyService.Current.Initialize();
SteamConnectService.Current.Initialize();
if (GeneralSettings.IsAutoCheckUpdate)
if (GeneralSettings.IsAutoCheckUpdate.Value)
{
AutoUpdateService.Current.CheckUpdate();
}
Expand All @@ -123,12 +127,12 @@ protected override void OnStartup(StartupEventArgs e)
else
this.MainWindow.Show();

if (GeneralSettings.IsAutoRunSteam && Process.GetProcessesByName("steam").Length < 1)
if (GeneralSettings.IsAutoRunSteam.Value && Process.GetProcessesByName("steam").Length < 1)
{
var steamTool = SteamToolCore.Instance.Get<SteamToolService>();
if (!string.IsNullOrEmpty(steamTool.SteamPath))
{
steamTool.StartSteam("-silent " + GeneralSettings.SteamStratParameter);
steamTool.StartSteam("-silent " + GeneralSettings.SteamStratParameter.Value);
}
}

Expand Down Expand Up @@ -231,7 +235,7 @@ private void ProcessCommandLineParameter(string[] args)
}


#region INotifyPropertyChanged members
#region INotifyPropertyChanged members

private event PropertyChangedEventHandler PropertyChangedInternal;
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
Expand All @@ -245,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 @@ -257,6 +261,6 @@ void IDisposable.Dispose()
this.compositeDisposable.Dispose();
}

#endregion
#endregion
}
}
Loading

0 comments on commit 42b11ce

Please sign in to comment.