Skip to content

Commit fa412cc

Browse files
committed
2023-07-05 - Multiple fixes
- Info prompt when changing account and closing method is different to suggested. TaskKill for BattleNet does not close games, whereas Close or Combined may (as BattleNet has time to close games before itself). - Fixed crash when saving accounts and folder does not exist. - Fixed rare corruption of Steam's loginusers.vdf on forget account
1 parent df726a8 commit fa412cc

File tree

7 files changed

+42
-12
lines changed

7 files changed

+42
-12
lines changed

TcNo-Acc-Switcher-Globals/Globals.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class Globals
2727
#pragma warning disable CA2211 // Non-constant fields should not be visible - This is necessary due to it being a launch parameter.
2828
public static bool VerboseMode;
2929
#pragma warning restore CA2211 // Non-constant fields should not be visible
30-
public static readonly string Version = "2023-06-27_01";
30+
public static readonly string Version = "2023-07-05_00";
3131

3232
#region INITIALISATION
3333

TcNo-Acc-Switcher-Server/Pages/Basic/BasicSwitcherBase.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Runtime.Versioning;
22
using Microsoft.JSInterop;
33
using TcNo_Acc_Switcher_Globals;
4+
using TcNo_Acc_Switcher_Server.Data;
5+
using TcNo_Acc_Switcher_Server.Pages.General;
46

57
namespace TcNo_Acc_Switcher_Server.Pages.Basic
68
{
@@ -34,7 +36,15 @@ public static void NewLogin_Basic()
3436
public static void BasicAddCurrent(string accName)
3537
{
3638
Globals.DebugWriteLine(@"[JSInvoke:Basic\BasicSwitcherBase.BasicAddCurrent] accName:hidden");
37-
_ = BasicSwitcherFuncs.BasicAddCurrent(accName);
39+
try
40+
{
41+
_ = BasicSwitcherFuncs.BasicAddCurrent(accName);
42+
}
43+
catch (System.IO.DirectoryNotFoundException io)
44+
{
45+
_ = GeneralInvocableFuncs.ShowToast("error", Lang.Instance["Toast_RestartAsAdmin"], Lang.Instance["Failed"], "toastarea");
46+
Globals.WriteToLog($"Failed to BasicAddCurrent. DirectoryNotFoundException", io);
47+
}
3848
}
3949
}
4050
}

TcNo-Acc-Switcher-Server/Pages/Basic/BasicSwitcherFuncs.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
using System.Runtime.Versioning;
66
using System.Text.RegularExpressions;
77
using System.Threading.Tasks;
8+
using Microsoft.AspNetCore.Components.RenderTree;
89
using Microsoft.JSInterop;
910
using Newtonsoft.Json;
1011
using Newtonsoft.Json.Linq;
1112
using TcNo_Acc_Switcher_Globals;
1213
using TcNo_Acc_Switcher_Server.Data;
1314
using TcNo_Acc_Switcher_Server.Pages.General;
15+
using static SteamKit2.Internal.CMsgClientAMGetPersonaNameHistory;
1416
using BasicSettings = TcNo_Acc_Switcher_Server.Data.Settings.Basic;
1517

1618
namespace TcNo_Acc_Switcher_Server.Pages.Basic
@@ -481,6 +483,12 @@ private static bool BasicCopyInAccount(string accId)
481483
private static bool KillGameProcesses()
482484
{
483485
// Kill game processes
486+
if (BasicSettings.ClosingMethod != CurrentPlatform.ClosingMethod)
487+
{
488+
_ = GeneralInvocableFuncs.ShowToast("info", Lang["Toast_DifferentClosingMethod",
489+
new { defaultMethod = CurrentPlatform.ClosingMethod, currentMethod = BasicSettings.ClosingMethod }], renderTo: "toastarea", duration: 15000);
490+
}
491+
484492
_ = AppData.InvokeVoidAsync("updateStatus", Lang["Status_ClosingPlatform", new { platform = CurrentPlatform.FullName }]);
485493
if (!GeneralFuncs.CloseProcesses(CurrentPlatform.ExesToEnd, BasicSettings.ClosingMethod))
486494
{
@@ -535,6 +543,13 @@ public static bool BasicAddCurrent(string accName)
535543
// Unique ID file, and does not already exist: Therefore create!
536544
var uniqueIdFile = CurrentPlatform.GetUniqueFilePath();
537545
uniqueId = Globals.RandomString(16);
546+
547+
var uniqueIdDir = Path.GetDirectoryName(uniqueIdFile);
548+
if (!Directory.Exists(uniqueIdDir))
549+
{
550+
Directory.CreateDirectory(uniqueIdDir);
551+
}
552+
538553
File.WriteAllText(uniqueIdFile, uniqueId);
539554
}
540555

TcNo-Acc-Switcher-Server/Pages/Steam/Index.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Steamuser
3030
[JsonProperty("mostrecent", Order = 3)] public string MostRec = "0";
3131
[JsonProperty("Timestamp", Order = 4)] public string LastLogin { get; set; }
3232
[JsonProperty("WantsOfflineMode", Order = 5)] public string OfflineMode = "0";
33-
[JsonProperty("SkipOfflineModeWarning", Order = 6)] public string SkipOfflineModeWarning { get; set; }
33+
[JsonProperty("SkipOfflineModeWarning", Order = 6)] public string SkipOfflineModeWarning { get; set; } = "0";
3434

3535
[JsonIgnore] public string ImageDownloadUrl { get; set; }
3636
[JsonIgnore] public string ImgUrl { get; set; }

TcNo-Acc-Switcher-Server/Pages/Steam/SteamSwitcherFuncs.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,18 @@ public static string GetCurrentAccountId()
163163
Index.Steamuser mostRecent = null;
164164
foreach (var su in AppData.SteamUsers)
165165
{
166-
int.TryParse(su.LastLogin, out var last);
166+
_ = int.TryParse(su.LastLogin, out int last);
167167

168-
int.TryParse(mostRecent?.LastLogin, out var recent);
168+
_ = int.TryParse(mostRecent?.LastLogin, out int recent);
169169

170170
if (mostRecent == null || last > recent)
171171
mostRecent = su;
172172
}
173173

174-
int.TryParse(mostRecent.LastLogin, out var mrTimestamp);
174+
if (mostRecent is null) return "";
175175

176-
if (SteamSettings.LastAccTimestamp > mrTimestamp)
177-
{
176+
if (int.TryParse(mostRecent?.LastLogin, out var mrTimestamp) && SteamSettings.LastAccTimestamp > mrTimestamp)
178177
return SteamSettings.LastAccName;
179-
}
180178

181179
return mostRecent.SteamId ?? "";
182180
}
@@ -434,8 +432,11 @@ private static string VerifyVdfText(string loginUserPath)
434432
{
435433
var original = Globals.ReadAllText(loginUserPath);
436434
var vdf = original;
437-
// Replaces double quotes, sometimes added by mistake (?) with single, as they should be.
438-
vdf = vdf.Replace("\"\"", "\"");
435+
//// Replaces double quotes, sometimes added by mistake (?) with single, as they should be.
436+
//vdf = vdf.Replace("\"\"", "\"");
437+
438+
// Logic can be improved here. Currently the above causes issues, whereas before this was nessecary... Very flaky.
439+
439440
if (original == vdf) return vdf;
440441

441442
// Save original file if different.

TcNo-Acc-Switcher-Server/Platforms.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,10 @@
421421
},
422422
"ExitBeforeInteract": true,
423423
"UniqueIdFile": "%AppData%\\Battle.net\\Battle.net.config::$.Client.SavedAccountNames",
424-
"UniqueIdMethod": "JSON_SELECT_FIRST,"
424+
"UniqueIdMethod": "JSON_SELECT_FIRST,",
425+
"Extras": {
426+
"ClosingMethod": "TaskKill"
427+
}
425428
}
426429
},
427430
"Platform-WIP": {

TcNo-Acc-Switcher-Server/Resources/en-US.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ Toast_SteamWebKeyInvalid: Steam Web API key seems to be invalid. Please set a ne
241241
Toast_DownloadingProfileData: Downloading profile data
242242
Toast_PasswordChanged: Password changed
243243
Toast_JsonFailModify: Failed to modify JSON file. See log.
244+
Toast_DifferentClosingMethod: "'Closing Method' is different to the default. If games are closing and more check if changing this option helps. Default: {defaultMethod}, Current: {currentMethod}"
244245
Modal_Crowdin_Header: Crowdin translators
245246
Modal_Crowdin_Info: "Here's everyone who helped translate this software.<br>Users with languages next to them helped a lot in translation (proofreader role)."
246247
Modal_Info_Creator: Created by TechNobo [Wesley Pyburn]

0 commit comments

Comments
 (0)