Fix v3 => v4 migration bug. Improved error handing
This commit is contained in:
parent
d5cd569319
commit
cd604d03b1
@ -67,7 +67,7 @@ namespace FileLiberator
|
|||||||
: "Error downloading file";
|
: "Error downloading file";
|
||||||
|
|
||||||
var ex = new Exception(exMsg);
|
var ex = new Exception(exMsg);
|
||||||
Serilog.Log.Error(ex, "Download error {@DebugInfo}", new
|
Serilog.Log.Logger.Error(ex, "Download error {@DebugInfo}", new
|
||||||
{
|
{
|
||||||
libraryBook.Book.Title,
|
libraryBook.Book.Title,
|
||||||
libraryBook.Book.AudibleProductId,
|
libraryBook.Book.AudibleProductId,
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
|
||||||
<Version>3.1.12.316</Version>
|
<Version>3.1.12.331</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -99,9 +99,12 @@ namespace LibationLauncher
|
|||||||
{
|
{
|
||||||
updateLegacyFileWithLocale();
|
updateLegacyFileWithLocale();
|
||||||
|
|
||||||
var account = addAccountToNewAccountFile();
|
var account = createAccountFromLegacySettings();
|
||||||
|
account.DecryptKey = getDecryptKey(account);
|
||||||
|
|
||||||
importDecryptKey(account);
|
// the next few methods need persistence. to be a good citizen, dispose of persister at the end of current scope
|
||||||
|
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
||||||
|
persister.AccountsSettings.Add(account);
|
||||||
}
|
}
|
||||||
// migration is a convenience. if something goes wrong: just move on
|
// migration is a convenience. if something goes wrong: just move on
|
||||||
catch { }
|
catch { }
|
||||||
@ -133,7 +136,7 @@ namespace LibationLauncher
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Account addAccountToNewAccountFile()
|
private static Account createAccountFromLegacySettings()
|
||||||
{
|
{
|
||||||
// get required locale from settings file
|
// get required locale from settings file
|
||||||
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
|
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
|
||||||
@ -161,24 +164,22 @@ namespace LibationLauncher
|
|||||||
IdentityTokens = identity
|
IdentityTokens = identity
|
||||||
};
|
};
|
||||||
|
|
||||||
// saves to new file
|
|
||||||
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
|
||||||
persister.AccountsSettings.Add(account);
|
|
||||||
|
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void importDecryptKey(Account account)
|
private static string getDecryptKey(Account account)
|
||||||
{
|
{
|
||||||
if (account is null || !string.IsNullOrWhiteSpace(account.DecryptKey) || !File.Exists(Configuration.Instance.SettingsFilePath))
|
if (!string.IsNullOrWhiteSpace(account?.DecryptKey))
|
||||||
return;
|
return account.DecryptKey;
|
||||||
|
|
||||||
|
if (!File.Exists(Configuration.Instance.SettingsFilePath) || account is null)
|
||||||
|
return "";
|
||||||
|
|
||||||
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
|
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
|
||||||
if (JObject.Parse(settingsContents).TryGetValue("DecryptKey", out var jToken))
|
if (JObject.Parse(settingsContents).TryGetValue("DecryptKey", out var jToken))
|
||||||
{
|
return jToken.Value<string>() ?? "";
|
||||||
var decryptKey = jToken.Value<string>() ?? "";
|
|
||||||
account.DecryptKey = decryptKey;
|
return "";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateSettingsFile()
|
private static void updateSettingsFile()
|
||||||
|
|||||||
@ -36,7 +36,7 @@
|
|||||||
this.label1.AutoSize = true;
|
this.label1.AutoSize = true;
|
||||||
this.label1.Location = new System.Drawing.Point(28, 24);
|
this.label1.Location = new System.Drawing.Point(28, 24);
|
||||||
this.label1.Name = "label1";
|
this.label1.Name = "label1";
|
||||||
this.label1.Size = new System.Drawing.Size(260, 13);
|
this.label1.Size = new System.Drawing.Size(263, 13);
|
||||||
this.label1.TabIndex = 0;
|
this.label1.TabIndex = 0;
|
||||||
this.label1.Text = "Scanning Audible library. This may take a few minutes";
|
this.label1.Text = "Scanning Audible library. This may take a few minutes";
|
||||||
//
|
//
|
||||||
@ -44,7 +44,7 @@
|
|||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(319, 63);
|
this.ClientSize = new System.Drawing.Size(440, 63);
|
||||||
this.Controls.Add(this.label1);
|
this.Controls.Add(this.label1);
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
|
|||||||
@ -33,9 +33,10 @@ namespace LibationWinForms.Dialogs
|
|||||||
{
|
{
|
||||||
(TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.ImportAccountAsync((account) => new WinformResponder(account), _accounts);
|
(TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.ImportAccountAsync((account) => new WinformResponder(account), _accounts);
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = "Error importing library. Please try again. If this still happens after 2 or 3 tries, stop and contact administrator";
|
var msg = "Error importing library. Please try again. If this still happens after 2 or 3 tries, stop and contact administrator";
|
||||||
|
Serilog.Log.Logger.Error(ex, msg);
|
||||||
MessageBox.Show(msg, "Error importing library", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(msg, "Error importing library", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,15 +36,15 @@
|
|||||||
this.label1.AutoSize = true;
|
this.label1.AutoSize = true;
|
||||||
this.label1.Location = new System.Drawing.Point(28, 24);
|
this.label1.Location = new System.Drawing.Point(28, 24);
|
||||||
this.label1.Name = "label1";
|
this.label1.Name = "label1";
|
||||||
this.label1.Size = new System.Drawing.Size(260, 13);
|
this.label1.Size = new System.Drawing.Size(263, 13);
|
||||||
this.label1.TabIndex = 0;
|
this.label1.TabIndex = 0;
|
||||||
this.label1.Text = "Scanning Audible library. This may take a few minutes";
|
this.label1.Text = "Scanning Audible library. This may take a few minutes.";
|
||||||
//
|
//
|
||||||
// IndexLibraryDialog
|
// IndexLibraryDialog
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(319, 63);
|
this.ClientSize = new System.Drawing.Size(440, 63);
|
||||||
this.Controls.Add(this.label1);
|
this.Controls.Add(this.label1);
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user