Bug fix: #143
This commit is contained in:
parent
2478c61df6
commit
904665da7f
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<Version>6.3.2.1</Version>
|
<Version>6.3.3.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -172,7 +172,7 @@ namespace LibationFileManager
|
|||||||
|
|
||||||
private string getTemplate(string settingName, Templates templ)
|
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;
|
return templ.IsValid(value) ? value : templ.DefaultTemplate;
|
||||||
}
|
}
|
||||||
private void setTemplate(string settingName, Templates templ, string newValue)
|
private void setTemplate(string settingName, Templates templ, string newValue)
|
||||||
|
|||||||
@ -10,6 +10,8 @@ namespace LibationFileManager
|
|||||||
public static Templates File { get; } = new FileTemplate();
|
public static Templates File { get; } = new FileTemplate();
|
||||||
public static Templates ChapterFile { get; } = new ChapterFileTemplate();
|
public static Templates ChapterFile { get; } = new ChapterFileTemplate();
|
||||||
|
|
||||||
|
public abstract string Name { get; }
|
||||||
|
public abstract string Description { get; }
|
||||||
public abstract string DefaultTemplate { get; }
|
public abstract string DefaultTemplate { get; }
|
||||||
|
|
||||||
public abstract bool IsValid(string template);
|
public abstract bool IsValid(string template);
|
||||||
@ -47,6 +49,8 @@ namespace LibationFileManager
|
|||||||
|
|
||||||
private class FolderTemplate : Templates
|
private class FolderTemplate : Templates
|
||||||
{
|
{
|
||||||
|
public override string Name => "Folder Template";
|
||||||
|
public override string Description => Configuration.GetDescription(nameof(Configuration.FolderTemplate));
|
||||||
public override string DefaultTemplate { get; } = "<title short> [<id>]";
|
public override string DefaultTemplate { get; } = "<title short> [<id>]";
|
||||||
|
|
||||||
public override bool IsValid(string template)
|
public override bool IsValid(string template)
|
||||||
@ -62,6 +66,8 @@ namespace LibationFileManager
|
|||||||
|
|
||||||
private class FileTemplate : Templates
|
private class FileTemplate : Templates
|
||||||
{
|
{
|
||||||
|
public override string Name => "File Template";
|
||||||
|
public override string Description => Configuration.GetDescription(nameof(Configuration.FileTemplate));
|
||||||
public override string DefaultTemplate { get; } = "<title> [<id>]";
|
public override string DefaultTemplate { get; } = "<title> [<id>]";
|
||||||
|
|
||||||
public override bool IsValid(string template) => fileIsValid(template);
|
public override bool IsValid(string template) => fileIsValid(template);
|
||||||
@ -73,6 +79,8 @@ namespace LibationFileManager
|
|||||||
|
|
||||||
private class ChapterFileTemplate : Templates
|
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; } = "<title> [<id>] - <ch# 0> - <ch title>";
|
public override string DefaultTemplate { get; } = "<title> [<id>] - <ch# 0> - <ch title>";
|
||||||
|
|
||||||
public override bool IsValid(string template) => fileIsValid(template);
|
public override bool IsValid(string template) => fileIsValid(template);
|
||||||
|
|||||||
135
LibationWinForms/Dialogs/EditTemplateDialog.Designer.cs
generated
Normal file
135
LibationWinForms/Dialogs/EditTemplateDialog.Designer.cs
generated
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
namespace LibationWinForms.Dialogs
|
||||||
|
{
|
||||||
|
partial class EditTemplateDialog
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
92
LibationWinForms/Dialogs/EditTemplateDialog.cs
Normal file
92
LibationWinForms/Dialogs/EditTemplateDialog.cs
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
60
LibationWinForms/Dialogs/EditTemplateDialog.resx
Normal file
60
LibationWinForms/Dialogs/EditTemplateDialog.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
||||||
@ -103,25 +103,20 @@ namespace LibationWinForms.Dialogs
|
|||||||
|
|
||||||
private void logsBtn_Click(object sender, EventArgs e) => Go.To.Folder(Configuration.Instance.LibationFiles);
|
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();
|
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)
|
private static void TEMP_TEMP_TEMP()
|
||||||
{
|
|
||||||
TEMP_TEMP_TEMP();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void chapterFileTemplateBtn_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
TEMP_TEMP_TEMP();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TEMP_TEMP_TEMP()
|
|
||||||
=> MessageBox.Show("Sorry, not yet. Coming soon :)");
|
=> MessageBox.Show("Sorry, not yet. Coming soon :)");
|
||||||
|
|
||||||
private void saveBtn_Click(object sender, EventArgs e)
|
private void saveBtn_Click(object sender, EventArgs e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user