diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs index 011b4afc..7d1d2e9f 100644 --- a/FileLiberator/DownloadDecryptBook.cs +++ b/FileLiberator/DownloadDecryptBook.cs @@ -67,9 +67,29 @@ namespace FileLiberator { validate(libraryBook); + Serilog.Log.Logger.Debug("Trying to debug mysterious null ref exception {@DebugInfo}", new { + libraryBookIsNull = libraryBook is null, + BookIsNull = libraryBook?.Book is null, + libraryBook?.Book?.Locale, + libraryBook?.Book?.AudibleProductId, + AccountLength = libraryBook?.Account?.Length + }); + var api = await InternalUtilities.AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale); + Serilog.Log.Logger.Debug("Trying to debug mysterious null ref exception {@DebugInfo}", new { apiIsNull = api is null }); + var contentLic = await api.GetDownloadLicenseAsync(libraryBook.Book.AudibleProductId); + + Serilog.Log.Logger.Debug("Trying to debug mysterious null ref exception {@DebugInfo}", new { + contentLicIsNull = contentLic is null, + contentMetadataIsNull = contentLic?.ContentMetadata is null, + voucherIsNull = contentLic?.Voucher is null, + keyIsNull = contentLic?.Voucher?.Key is null, + keyLength = contentLic?.Voucher?.Key?.Length, + ivIsNull = contentLic?.Voucher?.Iv is null, + ivLength = contentLic?.Voucher?.Iv?.Length, + }); var aaxcDecryptDlLic = new DownloadLicense ( diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 91fd3c6e..5d84fe75 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 5.3.7.1 + 5.3.8.1 diff --git a/LibationWinForms/Dialogs/Login/MfaDialog.cs b/LibationWinForms/Dialogs/Login/MfaDialog.cs index 2e12a50f..bf074692 100644 --- a/LibationWinForms/Dialogs/Login/MfaDialog.cs +++ b/LibationWinForms/Dialogs/Login/MfaDialog.cs @@ -14,49 +14,74 @@ namespace LibationWinForms.Dialogs.Login { private RadioButton[] radioButtons { get; } + AudibleApi.MfaConfig _mfaConfig { get; } + public MfaDialog(AudibleApi.MfaConfig mfaConfig) { InitializeComponent(); + _mfaConfig = mfaConfig; + radioButtons = new[] { this.radioButton1, this.radioButton2, this.radioButton3 }; // optional string settings if (!string.IsNullOrWhiteSpace(mfaConfig.Title)) this.Text = mfaConfig.Title; - setOptional(this.radioButton1, mfaConfig.Button1Text); - setOptional(this.radioButton2, mfaConfig.Button2Text); - setOptional(this.radioButton3, mfaConfig.Button3Text); - // mandatory values - radioButton1.Name = mfaConfig.Button1Name; - radioButton1.Tag = mfaConfig.Button1Value; + setRadioButton(0, this.radioButton1); + setRadioButton(1, this.radioButton2); + setRadioButton(2, this.radioButton3); - radioButton2.Name = mfaConfig.Button2Name; - radioButton2.Tag = mfaConfig.Button2Value; - - radioButton3.Name = mfaConfig.Button3Name; - radioButton3.Tag = mfaConfig.Button3Value; + Serilog.Log.Logger.Information("{@DebugInfo}", new { + paramButtonCount = mfaConfig.Buttons.Count, + visibleRadioButtonCount = radioButtons.Count(rb => rb.Visible) + }); } - private static void setOptional(RadioButton radioButton, string text) + private void setRadioButton(int pos, RadioButton rb) { - if (!string.IsNullOrWhiteSpace(text)) - radioButton.Text = text; + if (_mfaConfig.Buttons.Count <= pos) + { + rb.Checked = false; + rb.Enabled = false; + rb.Visible = false; + return; + } + + var btn = _mfaConfig.Buttons[pos]; + + // optional + if (!string.IsNullOrWhiteSpace(btn.Text)) + rb.Text = btn.Text; + + // mandatory values + rb.Name = btn.Name; + rb.Tag = btn.Value; } public string SelectedName { get; private set; } public string SelectedValue { get; private set; } private void submitBtn_Click(object sender, EventArgs e) { - Serilog.Log.Logger.Debug("RadioButton states: {@DebugInfo}", new { + Serilog.Log.Logger.Information("RadioButton states: {@DebugInfo}", new { + rb1_visible = radioButton1.Visible, rb1_checked = radioButton1.Checked, + + r21_visible = radioButton2.Visible, r21_checked = radioButton2.Checked, + + rb3_visible = radioButton3.Visible, rb3_checked = radioButton3.Checked }); - var selected = radioButtons.Single(rb => rb.Checked); + var selected = radioButtons.FirstOrDefault(rb => rb.Checked); + if (selected is null) + { + MessageBox.Show("No MFA option selected", "None selected", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } - Serilog.Log.Logger.Debug("Selected: {@DebugInfo}", new { isSelected = selected is not null, name = selected?.Name, value = selected?.Tag }); + Serilog.Log.Logger.Information("Selected: {@DebugInfo}", new { isSelected = selected is not null, name = selected?.Name, value = selected?.Tag }); SelectedName = selected.Name; SelectedValue = (string)selected.Tag; diff --git a/LibationWinForms/Dialogs/Login/WinformResponder.cs b/LibationWinForms/Dialogs/Login/WinformResponder.cs index eaeae9f7..28507f4d 100644 --- a/LibationWinForms/Dialogs/Login/WinformResponder.cs +++ b/LibationWinForms/Dialogs/Login/WinformResponder.cs @@ -17,7 +17,7 @@ namespace LibationWinForms.Login public string Get2faCode() { using var dialog = new _2faCodeDialog(); - if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + if (showDialog(dialog)) return dialog.Code; return null; } @@ -25,7 +25,7 @@ namespace LibationWinForms.Login public string GetCaptchaAnswer(byte[] captchaImage) { using var dialog = new CaptchaDialog(captchaImage); - if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + if (showDialog(dialog)) return dialog.Answer; return null; } @@ -33,7 +33,7 @@ namespace LibationWinForms.Login public (string name, string value) GetMfaChoice(MfaConfig mfaConfig) { using var dialog = new MfaDialog(mfaConfig); - if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + if (showDialog(dialog)) return (dialog.SelectedName, dialog.SelectedValue); return (null, null); } @@ -41,7 +41,7 @@ namespace LibationWinForms.Login public (string email, string password) GetLogin() { using var dialog = new AudibleLoginDialog(_account); - if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + if (showDialog(dialog)) return (dialog.Email, dialog.Password); return (null, null); } @@ -49,7 +49,15 @@ namespace LibationWinForms.Login public void ShowApprovalNeeded() { using var dialog = new ApprovalNeededDialog(); - dialog.ShowDialog(); + showDialog(dialog); + } + + /// True if ShowDialog's DialogResult == OK + private static bool showDialog(System.Windows.Forms.Form dialog) + { + var result = dialog.ShowDialog(); + Serilog.Log.Logger.Debug("{@DebugInfo}", new { DialogResult = result }); + return result == System.Windows.Forms.DialogResult.OK; } } } \ No newline at end of file