diff --git a/InternalUtilities/UNTESTED/AudibleApiActions.cs b/InternalUtilities/UNTESTED/AudibleApiActions.cs index 30951160..8c873482 100644 --- a/InternalUtilities/UNTESTED/AudibleApiActions.cs +++ b/InternalUtilities/UNTESTED/AudibleApiActions.cs @@ -17,7 +17,7 @@ namespace InternalUtilities { Localization.SetLocale(Configuration.Instance.LocaleCountryCode); - return await EzApiCreator.GetApiAsync(AudibleApiStorage.AccountsSettingsFile, AudibleApiStorage.GetIdentityTokensJsonPath(), loginCallback); + return await EzApiCreator.GetApiAsync(AudibleApiStorage.AccountsSettingsFile, AudibleApiStorage.TEST_GetFirstIdentityTokensJsonPath(), loginCallback); } private static AsyncRetryPolicy policy { get; } diff --git a/InternalUtilities/UNTESTED/AudibleApiStorage.cs b/InternalUtilities/UNTESTED/AudibleApiStorage.cs index 66a8620c..e8758f99 100644 --- a/InternalUtilities/UNTESTED/AudibleApiStorage.cs +++ b/InternalUtilities/UNTESTED/AudibleApiStorage.cs @@ -19,25 +19,33 @@ namespace InternalUtilities _ = new AccountsPersister(new Accounts(), AccountsSettingsFile); } - // convenience for for tests and demos. don't use in production Libation - public static Account TEST_GetFirstAccount() - => new AccountsPersister(AccountsSettingsFile).Accounts.GetAll().FirstOrDefault(); // convenience for for tests and demos. don't use in production Libation public static string TEST_GetFirstIdentityTokensJsonPath() => TEST_GetFirstAccount().GetIdentityTokensJsonPath(); - - // TEMP - public static string GetIdentityTokensJsonPath() => null; + // convenience for for tests and demos. don't use in production Libation + public static Account TEST_GetFirstAccount() + => new AccountsPersister(AccountsSettingsFile).Accounts.GetAll().FirstOrDefault(); public static string GetIdentityTokensJsonPath(this Account account) - => GetIdentityTokensJsonPath(account.AccountId, account?.IdentityTokens?.Locale.Name); - + => GetIdentityTokensJsonPath(account.AccountId, account.Locale?.Name); public static string GetIdentityTokensJsonPath(string username, string locale) { - var usernameSanitized = JsonConvert.ToString(username); - var localeSanitized = JsonConvert.ToString(locale); + var usernameSanitized = trimSurroundingQuotes(JsonConvert.ToString(username)); + var localeSanitized = trimSurroundingQuotes(JsonConvert.ToString(locale)); - return $"$.AccountsSettings[?(@.Username == '{usernameSanitized}' && @.IdentityTokens.Locale == '{localeSanitized}')].IdentityTokens"; + return $"$.AccountsSettings[?(@.AccountId == '{usernameSanitized}' && @.IdentityTokens.LocaleName == '{localeSanitized}')].IdentityTokens"; } + // SubString algo is better than .Trim("\"") + // orig string " + // json string "\"" + // Eg: + // => str.Trim("\"") + // output \ + // vs + // => str.Substring(1, str.Length - 2) + // output \" + // also works with surrounding single quotes + private static string trimSurroundingQuotes(string str) + => str.Substring(1, str.Length - 2); } } diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 26eb85b7..ca737a9c 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 3.1.12.127 + 3.1.12.136 diff --git a/LibationLauncher/UNTESTED/Program.cs b/LibationLauncher/UNTESTED/Program.cs index e7834a34..39db7676 100644 --- a/LibationLauncher/UNTESTED/Program.cs +++ b/LibationLauncher/UNTESTED/Program.cs @@ -86,6 +86,13 @@ namespace LibationLauncher static string AccountsSettingsFileLegacy30 => Path.Combine(Configuration.Instance.LibationFiles, "IdentityTokens.json"); private static void migrate_v3_to_v4() + { + migrateLegacyIdentityFile(); + + updateSettingsFile(); + } + + private static void migrateLegacyIdentityFile() { if (File.Exists(AccountsSettingsFileLegacy30)) { @@ -104,8 +111,6 @@ namespace LibationLauncher // delete legacy token file File.Delete(AccountsSettingsFileLegacy30); } - - updateSettingsFile(); } private static void updateLegacyFileWithLocale() @@ -178,7 +183,7 @@ namespace LibationLauncher // don't delete old settings until new values are used // remember to remove these from Configuration.cs -throw new NotImplementedException(); +return; // use JObject to remove decrypt key and locale from Settings.json var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);