diff --git a/AppScaffolding/AppScaffolding.csproj b/AppScaffolding/AppScaffolding.csproj
index d69f6348..8f7f0fae 100644
--- a/AppScaffolding/AppScaffolding.csproj
+++ b/AppScaffolding/AppScaffolding.csproj
@@ -3,7 +3,7 @@
net5.0
- 6.3.2.1
+ 6.3.3.1
diff --git a/LibationFileManager/Configuration.cs b/LibationFileManager/Configuration.cs
index 56505445..c56a5576 100644
--- a/LibationFileManager/Configuration.cs
+++ b/LibationFileManager/Configuration.cs
@@ -172,7 +172,7 @@ namespace LibationFileManager
private string getTemplate(string settingName, Templates templ)
{
- var value = persistentDictionary.GetString(settingName).Trim();
+ var value = persistentDictionary.GetString(settingName)?.Trim();
return templ.IsValid(value) ? value : templ.DefaultTemplate;
}
private void setTemplate(string settingName, Templates templ, string newValue)
diff --git a/LibationFileManager/Templates.cs b/LibationFileManager/Templates.cs
index c51b27dc..481895e3 100644
--- a/LibationFileManager/Templates.cs
+++ b/LibationFileManager/Templates.cs
@@ -10,6 +10,8 @@ namespace LibationFileManager
public static Templates File { get; } = new FileTemplate();
public static Templates ChapterFile { get; } = new ChapterFileTemplate();
+ public abstract string Name { get; }
+ public abstract string Description { get; }
public abstract string DefaultTemplate { get; }
public abstract bool IsValid(string template);
@@ -47,6 +49,8 @@ namespace LibationFileManager
private class FolderTemplate : Templates
{
+ public override string Name => "Folder Template";
+ public override string Description => Configuration.GetDescription(nameof(Configuration.FolderTemplate));
public override string DefaultTemplate { get; } = " []";
public override bool IsValid(string template)
@@ -62,7 +66,9 @@ namespace LibationFileManager
private class FileTemplate : Templates
{
- public override string DefaultTemplate { get; } = " []";
+ public override string Name => "File Template";
+ public override string Description => Configuration.GetDescription(nameof(Configuration.FileTemplate));
+ public override string DefaultTemplate { get; } = " []";
public override bool IsValid(string template) => fileIsValid(template);
@@ -73,6 +79,8 @@ namespace LibationFileManager
private class ChapterFileTemplate : Templates
{
+ public override string Name => "Chapter File Template";
+ public override string Description => Configuration.GetDescription(nameof(Configuration.ChapterFileTemplate));
public override string DefaultTemplate { get; } = " [] - - ";
public override bool IsValid(string template) => fileIsValid(template);
diff --git a/LibationWinForms/Dialogs/EditTemplateDialog.Designer.cs b/LibationWinForms/Dialogs/EditTemplateDialog.Designer.cs
new file mode 100644
index 00000000..79f072d9
--- /dev/null
+++ b/LibationWinForms/Dialogs/EditTemplateDialog.Designer.cs
@@ -0,0 +1,135 @@
+namespace LibationWinForms.Dialogs
+{
+ partial class EditTemplateDialog
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.saveBtn = new System.Windows.Forms.Button();
+ this.cancelBtn = new System.Windows.Forms.Button();
+ this.templateTb = new System.Windows.Forms.TextBox();
+ this.templateLbl = new System.Windows.Forms.Label();
+ this.resetToDefaultBtn = new System.Windows.Forms.Button();
+ this.outputTb = new System.Windows.Forms.TextBox();
+ this.SuspendLayout();
+ //
+ // saveBtn
+ //
+ this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.saveBtn.Location = new System.Drawing.Point(714, 496);
+ this.saveBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+ this.saveBtn.Name = "saveBtn";
+ this.saveBtn.Size = new System.Drawing.Size(88, 27);
+ this.saveBtn.TabIndex = 98;
+ this.saveBtn.Text = "Save";
+ this.saveBtn.UseVisualStyleBackColor = true;
+ this.saveBtn.Click += new System.EventHandler(this.saveBtn_Click);
+ //
+ // cancelBtn
+ //
+ this.cancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.cancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+ this.cancelBtn.Location = new System.Drawing.Point(832, 496);
+ this.cancelBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+ this.cancelBtn.Name = "cancelBtn";
+ this.cancelBtn.Size = new System.Drawing.Size(88, 27);
+ this.cancelBtn.TabIndex = 99;
+ this.cancelBtn.Text = "Cancel";
+ this.cancelBtn.UseVisualStyleBackColor = true;
+ this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click);
+ //
+ // templateTb
+ //
+ this.templateTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.templateTb.Location = new System.Drawing.Point(12, 27);
+ this.templateTb.Name = "templateTb";
+ this.templateTb.Size = new System.Drawing.Size(779, 23);
+ this.templateTb.TabIndex = 1;
+ this.templateTb.TextChanged += new System.EventHandler(this.templateTb_TextChanged);
+ //
+ // templateLbl
+ //
+ this.templateLbl.AutoSize = true;
+ this.templateLbl.Location = new System.Drawing.Point(12, 9);
+ this.templateLbl.Name = "templateLbl";
+ this.templateLbl.Size = new System.Drawing.Size(89, 15);
+ this.templateLbl.TabIndex = 0;
+ this.templateLbl.Text = "[template desc]";
+ //
+ // resetToDefaultBtn
+ //
+ this.resetToDefaultBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.resetToDefaultBtn.Location = new System.Drawing.Point(797, 26);
+ this.resetToDefaultBtn.Name = "resetToDefaultBtn";
+ this.resetToDefaultBtn.Size = new System.Drawing.Size(124, 23);
+ this.resetToDefaultBtn.TabIndex = 2;
+ this.resetToDefaultBtn.Text = "Reset to default";
+ this.resetToDefaultBtn.UseVisualStyleBackColor = true;
+ this.resetToDefaultBtn.Click += new System.EventHandler(this.resetToDefaultBtn_Click);
+ //
+ // outputTb
+ //
+ this.outputTb.Location = new System.Drawing.Point(12, 153);
+ this.outputTb.Multiline = true;
+ this.outputTb.Name = "outputTb";
+ this.outputTb.ReadOnly = true;
+ this.outputTb.Size = new System.Drawing.Size(759, 205);
+ this.outputTb.TabIndex = 100;
+ //
+ // EditTemplateDialog
+ //
+ this.AcceptButton = this.saveBtn;
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.CancelButton = this.cancelBtn;
+ this.ClientSize = new System.Drawing.Size(933, 539);
+ this.Controls.Add(this.outputTb);
+ this.Controls.Add(this.resetToDefaultBtn);
+ this.Controls.Add(this.templateLbl);
+ this.Controls.Add(this.templateTb);
+ this.Controls.Add(this.cancelBtn);
+ this.Controls.Add(this.saveBtn);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
+ this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+ this.Name = "EditTemplateDialog";
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+ this.Text = "Edit Template";
+ this.Load += new System.EventHandler(this.EditTemplateDialog_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+ private System.Windows.Forms.Button saveBtn;
+ private System.Windows.Forms.Button cancelBtn;
+ private System.Windows.Forms.TextBox templateTb;
+ private System.Windows.Forms.Label templateLbl;
+ private System.Windows.Forms.Button resetToDefaultBtn;
+ private System.Windows.Forms.TextBox outputTb;
+ }
+}
\ No newline at end of file
diff --git a/LibationWinForms/Dialogs/EditTemplateDialog.cs b/LibationWinForms/Dialogs/EditTemplateDialog.cs
new file mode 100644
index 00000000..5eb2c22f
--- /dev/null
+++ b/LibationWinForms/Dialogs/EditTemplateDialog.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.IO;
+using System.Windows.Forms;
+using Dinah.Core;
+using LibationFileManager;
+
+namespace LibationWinForms.Dialogs
+{
+ public partial class EditTemplateDialog : Form
+ {
+ public string TemplateText { get; private set; }
+
+ private Configuration config { get; } = Configuration.Instance;
+
+ private Templates template { get; }
+ private string inputTemplateText { get; }
+
+ public EditTemplateDialog() => InitializeComponent();
+ public EditTemplateDialog(Templates template, string inputTemplateText) : this()
+ {
+ this.template = ArgumentValidator.EnsureNotNull(template, nameof(template));
+ this.inputTemplateText = inputTemplateText ?? "";
+ }
+
+ private void EditTemplateDialog_Load(object sender, EventArgs e)
+ {
+ if (this.DesignMode)
+ return;
+
+ if (template is null)
+ {
+ MessageBoxAlertAdmin.Show($"Programming error. {nameof(EditTemplateDialog)} was not created correctly", "Edit template error", new NullReferenceException($"{nameof(template)} is null"));
+ return;
+ }
+
+ this.Text = $"Edit {template.Name}";
+
+ this.templateLbl.Text = template.Description;
+ this.templateTb.Text = inputTemplateText;
+ }
+
+ private void resetToDefaultBtn_Click(object sender, EventArgs e) => templateTb.Text = template.DefaultTemplate;
+
+ private void templateTb_TextChanged(object sender, EventArgs e)
+ {
+ var books = config.Books;
+ var folderTemplate = template == Templates.Folder ? templateTb.Text : config.FolderTemplate;
+ folderTemplate = folderTemplate.Trim().Trim(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }).Trim();
+ var fileTemplate = template == Templates.Folder ? config.FileTemplate : templateTb.Text;
+ fileTemplate = fileTemplate.Trim();
+ var ext = config.DecryptToLossy ? "mp3" : "m4b";
+
+ var path = Path.Combine(books, folderTemplate, $"{fileTemplate}.{ext}");
+
+ // this logic should be external
+ path = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
+ var dbl = $"{Path.DirectorySeparatorChar}{Path.DirectorySeparatorChar}";
+ while (path.Contains(dbl))
+ path = path.Replace(dbl, $"{Path.DirectorySeparatorChar}");
+
+ outputTb.Text = @$"
+{books}
+{folderTemplate}
+{fileTemplate}
+{ext}
+{path}
+";
+ }
+
+ private void saveBtn_Click(object sender, EventArgs e)
+ {
+ if (!template.IsValid(templateTb.Text))
+ {
+ MessageBox.Show("This template text is not valid.", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ TemplateText = templateTb.Text;
+
+ this.DialogResult = DialogResult.OK;
+ this.Close();
+ }
+
+ private void cancelBtn_Click(object sender, EventArgs e)
+ {
+ this.DialogResult = DialogResult.Cancel;
+ this.Close();
+ }
+ }
+}
diff --git a/LibationWinForms/Dialogs/EditTemplateDialog.resx b/LibationWinForms/Dialogs/EditTemplateDialog.resx
new file mode 100644
index 00000000..f298a7be
--- /dev/null
+++ b/LibationWinForms/Dialogs/EditTemplateDialog.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/LibationWinForms/Dialogs/SettingsDialog.cs b/LibationWinForms/Dialogs/SettingsDialog.cs
index f8094ab6..acab607b 100644
--- a/LibationWinForms/Dialogs/SettingsDialog.cs
+++ b/LibationWinForms/Dialogs/SettingsDialog.cs
@@ -103,25 +103,20 @@ namespace LibationWinForms.Dialogs
private void logsBtn_Click(object sender, EventArgs e) => Go.To.Folder(Configuration.Instance.LibationFiles);
- private void folderTemplateBtn_Click(object sender, EventArgs e)
+ private void folderTemplateBtn_Click(object sender, EventArgs e) => editTemplate(Templates.Folder, folderTemplateTb);
+ private void fileTemplateBtn_Click(object sender, EventArgs e) => editTemplate(Templates.File, fileTemplateTb);
+ private void chapterFileTemplateBtn_Click(object sender, EventArgs e) => editTemplate(Templates.ChapterFile, chapterFileTemplateTb);
+ private static void editTemplate(Templates template, TextBox textBox)
{
TEMP_TEMP_TEMP();
+ return;
+ var form = new EditTemplateDialog(template, textBox.Text);
+ if (form.ShowDialog() == DialogResult.OK)
+ textBox.Text = form.TemplateText;
}
- private void fileTemplateBtn_Click(object sender, EventArgs e)
- {
- TEMP_TEMP_TEMP();
-
- }
-
- private void chapterFileTemplateBtn_Click(object sender, EventArgs e)
- {
- TEMP_TEMP_TEMP();
-
- }
-
- private void TEMP_TEMP_TEMP()
+ private static void TEMP_TEMP_TEMP()
=> MessageBox.Show("Sorry, not yet. Coming soon :)");
private void saveBtn_Click(object sender, EventArgs e)