begin token file migration. INCOMPLETE

This commit is contained in:
Robert McRackan 2020-08-13 17:01:06 -04:00
parent 8a54eda4a0
commit 8391e43b03
2 changed files with 68 additions and 1 deletions

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> --> <!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>3.1.12.88</Version> <Version>3.1.12.95</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -3,9 +3,11 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using FileManager; using FileManager;
using InternalUtilities;
using LibationWinForms; using LibationWinForms;
using LibationWinForms.Dialogs; using LibationWinForms.Dialogs;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Serilog; using Serilog;
@ -22,6 +24,10 @@ namespace LibationLauncher
createSettings(); createSettings();
ensureIdentityFile();
migrateIdentityFile();
updateSettingsFile();
ensureLoggingConfig(); ensureLoggingConfig();
ensureSerilogConfig(); ensureSerilogConfig();
configureLogging(); configureLogging();
@ -76,6 +82,67 @@ namespace LibationLauncher
Environment.Exit(0); Environment.Exit(0);
} }
private static void ensureIdentityFile()
{
if (File.Exists(AudibleApiStorage.AccountsSettingsFile))
return;
var jObj = new JObject {
{ "AccountsSettings", new JArray() }
};
var contents = jObj.ToString(Formatting.Indented);
File.WriteAllText(AudibleApiStorage.AccountsSettingsFile, contents);
}
private static void migrateIdentityFile()
{
if (!File.Exists(AudibleApiStorage.AccountsSettingsFileLegacy30))
return;
try
{
//
// for all in here: read directly from json file => JObject. A lot of this is legacy; don't rely on applicable POCOs
//
var legacyContents = File.ReadAllText(AudibleApiStorage.AccountsSettingsFileLegacy30);
var legacyJObj = JObject.Parse(legacyContents);
// attempt to update legacy token file with locale from settings
if (!legacyJObj.ContainsKey("LocaleName"))
{
var settings = File.ReadAllText(Configuration.Instance.SettingsFilePath);
var settingsJObj = JObject.Parse(settings);
if (settingsJObj.TryGetValue("LocaleCountryCode", out var localeName))
{
// update legacy token file with locale from settings
legacyJObj.AddFirst(new JProperty("LocaleName", localeName.Value<string>()));
// save
var newContents = legacyJObj.ToString(Formatting.Indented);
File.WriteAllText(AudibleApiStorage.AccountsSettingsFileLegacy30, newContents);
// re get contents
legacyContents = File.ReadAllText(AudibleApiStorage.AccountsSettingsFileLegacy30);
legacyJObj = JObject.Parse(legacyContents);
}
}
// more to do?
}
catch
{
// migration is a convenience. if something goes wrong: just move on
}
// more to do. prob deleting legacy token file
}
private static void updateSettingsFile()
{
//throw new NotImplementedException();
}
private static string defaultLoggingLevel { get; } = "Information"; private static string defaultLoggingLevel { get; } = "Information";
private static void ensureLoggingConfig() private static void ensureLoggingConfig()