Overhaul of installation workflow per issue #36

This commit is contained in:
Robert McRackan 2021-07-19 14:52:34 -04:00
parent 730484c28c
commit c9b434daed
14 changed files with 543 additions and 516 deletions

View File

@ -37,7 +37,7 @@ namespace FileManager
get
{
if (string.IsNullOrWhiteSpace(Configuration.Instance.Books))
Configuration.Instance.Books = Path.Combine(Configuration.Instance.LibationFiles, "Books");
Configuration.Instance.Books = Path.Combine(Configuration.UserProfile, "Books");
return Directory.CreateDirectory(Configuration.Instance.Books).FullName;
}
}

View File

@ -11,11 +11,28 @@ namespace FileManager
{
public class Configuration
{
// settings will be persisted when all are true
// - property (not field)
// - string
// - public getter
// - public setter
public bool LibationSettingsAreValid
=> File.Exists(APPSETTINGS_JSON)
&& SettingsFileIsValid(SettingsFilePath);
public static bool SettingsFileIsValid(string settingsFile)
{
if (!Directory.Exists(Path.GetDirectoryName(settingsFile)) || !File.Exists(settingsFile))
return false;
var pDic = new PersistentDictionary(settingsFile, isReadOnly: true);
var booksDir = pDic.GetString(nameof(Books));
if (booksDir is null || !Directory.Exists(booksDir))
return false;
if (string.IsNullOrWhiteSpace(pDic.GetString(nameof(InProgress))))
return false;
return true;
}
#region persistent configuration settings/values
#region // properties to test reflection
/*
@ -33,16 +50,39 @@ namespace FileManager
*/
#endregion
// settings will be persisted when all are true
// - property (not field)
// - string
// - public getter
// - public setter
// note: any potential file manager static ctors can't compensate if storage dir is changed at run time via settings. this is partly bad architecture. but the side effect is desirable. if changing LibationFiles location: restart app
// default setting and directory creation occur in class responsible for files.
// config class is only responsible for path. not responsible for setting defaults, dir validation, or dir creation
// exceptions: appsettings.json, LibationFiles dir, Settings.json
private PersistentDictionary persistentDictionary;
public bool FilesExist
=> File.Exists(APPSETTINGS_JSON)
&& File.Exists(SettingsFilePath)
&& Directory.Exists(LibationFiles)
&& Directory.Exists(Books);
public object GetObject(string propertyName) => persistentDictionary.GetObject(propertyName);
public void SetObject(string propertyName, object newValue) => persistentDictionary.Set(propertyName, newValue);
public void SetWithJsonPath(string jsonPath, string propertyName, string newValue) => persistentDictionary.SetWithJsonPath(jsonPath, propertyName, newValue);
public string SettingsFilePath => Path.Combine(LibationFiles, "Settings.json");
public static string GetDescription(string propertyName)
{
var attribute = typeof(Configuration)
.GetProperty(propertyName)
?.GetCustomAttributes(typeof(DescriptionAttribute), true)
.SingleOrDefault()
as DescriptionAttribute;
return attribute?.Description;
}
public bool Exists(string propertyName) => persistentDictionary.Exists(propertyName);
[Description("Location for book storage. Includes destination of newly liberated books")]
public string Books
{
@ -50,10 +90,34 @@ namespace FileManager
set => persistentDictionary.Set(nameof(Books), value);
}
#region known directories
public static string AppDir_Relative => @".\LibationFiles";
// temp/working dir(s) should be outside of dropbox
[Description("Temporary location of files while they're in process of being downloaded and decrypted.\r\nWhen decryption is complete, the final file will be in Books location\r\nRecommend not using a folder which is backed up real time. Eg: Dropbox, iCloud, Google Drive")]
public string InProgress
{
get => persistentDictionary.GetString(nameof(InProgress));
set => persistentDictionary.Set(nameof(InProgress), value);
}
[Description("Allow Libation for fix up audiobook metadata?")]
public bool AllowLibationFixup
{
get => persistentDictionary.Get<bool>(nameof(AllowLibationFixup));
set => persistentDictionary.Set(nameof(AllowLibationFixup), value);
}
[Description("Decrypt to lossy format?")]
public bool DecryptToLossy
{
get => persistentDictionary.Get<bool>(nameof(DecryptToLossy));
set => persistentDictionary.Set(nameof(DecryptToLossy), value);
}
#endregion
#region known directories
public static string AppDir_Relative => $@".\{LIBATION_FILES_KEY}";
public static string AppDir_Absolute => Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Exe.FileLocationOnDisk), LIBATION_FILES_KEY));
public static string MyDocs => Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "LibationFiles"));
public static string MyDocs => Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Libation"));
public static string WinTemp => Path.GetFullPath(Path.Combine(Path.GetTempPath(), "Libation"));
public static string UserProfile => Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Libation"));
@ -84,7 +148,8 @@ namespace FileManager
(KnownDirectories.AppDir, () => AppDir_Relative),
(KnownDirectories.WinTemp, () => WinTemp),
(KnownDirectories.MyDocs, () => MyDocs),
// this is important to not let very early calls try to accidentally load LibationFiles too early
// this is important to not let very early calls try to accidentally load LibationFiles too early.
// also, keep this at bottom of this list
(KnownDirectories.LibationFiles, () => libationFilesPathCache)
};
public static string GetKnownDirectoryPath(KnownDirectories directory)
@ -98,43 +163,21 @@ namespace FileManager
if (string.IsNullOrWhiteSpace(directory))
return KnownDirectories.None;
var dirFunc = directoryOptionsPaths.SingleOrDefault(dirFunc => dirFunc.getPathFunc() == directory);
// 'First' instead of 'Single' because LibationFiles could match other directories. eg: default value of LibationFiles == UserProfile.
// since it's a list, order matters and non-LibationFiles will be returned first
var dirFunc = directoryOptionsPaths.FirstOrDefault(dirFunc => dirFunc.getPathFunc() == directory);
return dirFunc == default ? KnownDirectories.None : dirFunc.directory;
}
#endregion
#endregion
// default setting and directory creation occur in class responsible for files.
// config class is only responsible for path. not responsible for setting defaults, dir validation, or dir creation
// exceptions: appsettings.json, LibationFiles dir, Settings.json
// temp/working dir(s) should be outside of dropbox
[Description("Temporary location of files while they're in process of being downloaded and decrypted.\r\nWhen decryption is complete, the final file will be in Books location\r\nRecommend not using a folder which is backed up real time. Eg: Dropbox, iCloud, Google Drive")]
public string InProgress
{
get => persistentDictionary.GetString(nameof(InProgress));
set => persistentDictionary.Set(nameof(InProgress), value);
}
[Description("Allow Libation for fix up audiobook metadata?")]
public bool AllowLibationFixup
{
get => persistentDictionary.Get<bool>(nameof(AllowLibationFixup));
set => persistentDictionary.Set(nameof(AllowLibationFixup), value);
}
[Description("Decrypt to lossy format?")]
public bool DecryptToLossy
{
get => persistentDictionary.Get<bool>(nameof(DecryptToLossy));
set => persistentDictionary.Set(nameof(DecryptToLossy), value);
}
// note: any potential file manager static ctors can't compensate if storage dir is changed at run time via settings. this is partly bad architecture. but the side effect is desirable. if changing LibationFiles location: restart app
// singleton stuff
public static Configuration Instance { get; } = new Configuration();
#region singleton stuff
public static Configuration Instance { get; } = new Configuration();
private Configuration() { }
#endregion
private const string APPSETTINGS_JSON = "appsettings.json";
#region LibationFiles
private const string APPSETTINGS_JSON = "appsettings.json";
private const string LIBATION_FILES_KEY = "LibationFiles";
[Description("Location for storage of program-created files")]
@ -192,21 +235,6 @@ namespace FileManager
return valueFinal;
}
public object GetObject(string propertyName) => persistentDictionary.GetObject(propertyName);
public void SetObject(string propertyName, object newValue) => persistentDictionary.Set(propertyName, newValue);
public void SetWithJsonPath(string jsonPath, string propertyName, string newValue) => persistentDictionary.SetWithJsonPath(jsonPath, propertyName, newValue);
public static string GetDescription(string propertyName)
{
var attribute = typeof(Configuration)
.GetProperty(propertyName)
?.GetCustomAttributes(typeof(DescriptionAttribute), true)
.SingleOrDefault()
as DescriptionAttribute;
return attribute?.Description;
}
public bool TrySetLibationFiles(string directory)
{
// this is WRONG. need to MOVE settings; not DELETE them
@ -236,5 +264,6 @@ namespace FileManager
return true;
}
#endregion
}
}

View File

@ -10,14 +10,16 @@ namespace FileManager
public class PersistentDictionary
{
public string Filepath { get; }
public bool IsReadOnly { get; }
// optimize for strings. expectation is most settings will be strings and a rare exception will be something else
private Dictionary<string, string> stringCache { get; } = new Dictionary<string, string>();
private Dictionary<string, object> objectCache { get; } = new Dictionary<string, object>();
public PersistentDictionary(string filepath)
public PersistentDictionary(string filepath, bool isReadOnly = false)
{
Filepath = filepath;
IsReadOnly = isReadOnly;
if (File.Exists(Filepath))
return;
@ -25,6 +27,9 @@ namespace FileManager
// will create any missing directories, incl subdirectories. if all already exist: no action
Directory.CreateDirectory(Path.GetDirectoryName(filepath));
if (IsReadOnly)
return;
File.WriteAllText(Filepath, "{}");
System.Threading.Thread.Sleep(100);
}
@ -34,7 +39,9 @@ namespace FileManager
if (!stringCache.ContainsKey(propertyName))
{
var jObject = readFile();
stringCache[propertyName] = jObject.ContainsKey(propertyName) ? jObject[propertyName].Value<string>() : null;
if (!jObject.ContainsKey(propertyName))
return null;
stringCache[propertyName] = jObject[propertyName].Value<string>();
}
return stringCache[propertyName];
@ -42,10 +49,10 @@ namespace FileManager
public T Get<T>(string propertyName)
{
var o = GetObject(propertyName);
if (o is null) return default;
if (o is JToken jt) return jt.Value<T>();
return (T)o;
var obj = GetObject(propertyName);
if (obj is null) return default;
if (obj is JToken jToken) return jToken.Value<T>();
return (T)obj;
}
public object GetObject(string propertyName)
@ -53,17 +60,21 @@ namespace FileManager
if (!objectCache.ContainsKey(propertyName))
{
var jObject = readFile();
objectCache[propertyName] = jObject.ContainsKey(propertyName) ? jObject[propertyName].Value<object>() : null;
if (!jObject.ContainsKey(propertyName))
return null;
objectCache[propertyName] = jObject[propertyName].Value<object>();
}
return objectCache[propertyName];
}
public bool Exists(string propertyName) => readFile().ContainsKey(propertyName);
private object locker { get; } = new object();
public void Set(string propertyName, string newValue)
{
// only do this check in string cache, NOT object cache
if (stringCache[propertyName] == newValue)
if (stringCache.ContainsKey(propertyName) && stringCache[propertyName] == newValue)
return;
// set cache
@ -83,6 +94,9 @@ namespace FileManager
private void writeFile(string propertyName, JToken newValue)
{
if (IsReadOnly)
return;
try
{
var str = newValue?.ToString();
@ -113,6 +127,9 @@ namespace FileManager
// special case: no caching. no logging
public void SetWithJsonPath(string jsonPath, string propertyName, string newValue)
{
if (IsReadOnly)
return;
lock (locker)
{
var jObject = readFile();

View File

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

View File

@ -26,199 +26,119 @@ namespace LibationLauncher
Application.SetCompatibleTextRenderingDefault(false);
// must occur before access to Configuration instance
migrate_to_v5_2_0();
migrate_to_v5_2_0__pre_config();
createSettings();
//***********************************************//
// //
// do not use Configuration before this line //
// //
//***********************************************//
var config = Configuration.Instance;
createSettings(config);
AudibleApiStorage.EnsureAccountsSettingsFileExists();
migrate_to_v4_0_0();
migrate_to_v5_0_0();
ensureSerilogConfig();
configureLogging();
checkForUpdate();
logStartupState();
migrate_to_v5_0_0(config);
migrate_to_v5_2_0__post_config(config);
ensureSerilogConfig(config);
configureLogging(config);
checkForUpdate(config);
logStartupState(config);
Application.Run(new Form1());
}
private static void createSettings()
private static void createSettings(Configuration config)
{
static bool configSetupIsComplete(Configuration config)
=> config.FilesExist
&& !string.IsNullOrWhiteSpace(config.InProgress);
// all returns should be preceded by either:
// - if config.LibationSettingsAreValid
// - error message, Exit()
var config = Configuration.Instance;
if (configSetupIsComplete(config))
static void CancelInstallation()
{
MessageBox.Show("Initial set up cancelled.", "Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
Environment.Exit(0);
}
if (config.LibationSettingsAreValid)
return;
var isAdvanced = false;
var defaultLibationFilesDir = Configuration.UserProfile;
// check for existing settigns in default location
var defaultSettingsFile = Path.Combine(defaultLibationFilesDir, "Settings.json");
if (Configuration.SettingsFileIsValid(defaultSettingsFile))
config.TrySetLibationFiles(defaultLibationFilesDir);
if (config.LibationSettingsAreValid)
return;
var setupDialog = new SetupDialog();
setupDialog.NoQuestionsBtn_Click += (_, __) =>
if (setupDialog.ShowDialog() != DialogResult.OK)
{
config.InProgress ??= Configuration.WinTemp;
config.Books ??= Configuration.AppDir_Relative;
CancelInstallation();
return;
}
if (setupDialog.IsNewUser)
config.TrySetLibationFiles(defaultLibationFilesDir);
else if (setupDialog.IsReturningUser)
{
var libationFilesDialog = new LibationFilesDialog();
if (libationFilesDialog.ShowDialog() != DialogResult.OK)
{
CancelInstallation();
return;
}
config.TrySetLibationFiles(libationFilesDialog.SelectedDirectory);
if (config.LibationSettingsAreValid)
return;
// path did not result in valid settings
MessageBox.Show(
$"No valid settings were found at this location.\r\nWould you like to create a new install settings in this folder?\r\n\r\n{libationFilesDialog.SelectedDirectory}",
"New install?",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (libationFilesDialog.ShowDialog() != DialogResult.Yes)
{
CancelInstallation();
return;
}
}
// if 'new user' was clicked, or if 'returning user' chose new install: show basic settings dialog
config.Books ??= Path.Combine(defaultLibationFilesDir, "Books");
config.InProgress ??= Configuration.WinTemp;
config.AllowLibationFixup = true;
config.DecryptToLossy = false;
if (new SettingsDialog().ShowDialog() != DialogResult.OK)
{
CancelInstallation();
return;
}
if (config.LibationSettingsAreValid)
return;
CancelInstallation();
}
#region migrate_to_v5_0_0 re-register device if device info not in settings
private static void migrate_to_v5_0_0(Configuration config)
{
if (!config.Exists(nameof(config.AllowLibationFixup)))
config.AllowLibationFixup = true;
};
// setupDialog.BasicBtn_Click += (_, __) => // no action needed
setupDialog.AdvancedBtn_Click += (_, __) => isAdvanced = true;
setupDialog.ShowDialog();
if (isAdvanced)
{
var dialog = new LibationFilesDialog();
if (dialog.ShowDialog() != DialogResult.OK)
MessageBox.Show("Libation Files location not changed");
}
if (configSetupIsComplete(config))
return;
if (new SettingsDialog().ShowDialog() == DialogResult.OK)
return;
MessageBox.Show("Initial set up cancelled.", "Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
Environment.Exit(0);
}
#region v3 => v4 migration
static string AccountsSettingsFileLegacy30 => Path.Combine(Configuration.Instance.LibationFiles, "IdentityTokens.json");
private static void migrate_to_v4_0_0()
{
migrateLegacyIdentityFile();
updateSettingsFile();
}
private static void migrateLegacyIdentityFile()
{
if (File.Exists(AccountsSettingsFileLegacy30))
{
// don't always rely on applicable POCOs. some is legacy and must be: json file => JObject
try
{
updateLegacyFileWithLocale();
var account = createAccountFromLegacySettings();
account.DecryptKey = getDecryptKey(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
catch { }
// delete legacy token file
File.Delete(AccountsSettingsFileLegacy30);
}
}
private static void updateLegacyFileWithLocale()
{
var legacyContents = File.ReadAllText(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(AccountsSettingsFileLegacy30, newContents);
}
}
}
private static Account createAccountFromLegacySettings()
{
// get required locale from settings file
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
if (!JObject.Parse(settingsContents).TryGetValue("LocaleCountryCode", out var jLocale))
return null;
var localeName = jLocale.Value<string>();
var locale = Localization.Get(localeName);
var api = EzApiCreator.GetApiAsync(locale, AccountsSettingsFileLegacy30).GetAwaiter().GetResult();
var email = api.GetEmailAsync().GetAwaiter().GetResult();
// identity has likely been updated above. re-get contents
var legacyContents = File.ReadAllText(AccountsSettingsFileLegacy30);
var identity = Identity.FromJson(legacyContents);
if (!identity.IsValid)
return null;
var account = new Account(email)
{
AccountName = $"{email} - {locale.Name}",
LibraryScan = true,
IdentityTokens = identity
};
return account;
}
private static string getDecryptKey(Account account)
{
if (!string.IsNullOrWhiteSpace(account?.DecryptKey))
return account.DecryptKey;
if (!File.Exists(Configuration.Instance.SettingsFilePath) || account is null)
return "";
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
if (JObject.Parse(settingsContents).TryGetValue("DecryptKey", out var jToken))
return jToken.Value<string>() ?? "";
return "";
}
private static void updateSettingsFile()
{
if (!File.Exists(Configuration.Instance.SettingsFilePath))
return;
// use JObject to remove decrypt key and locale from Settings.json
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
var jObj = JObject.Parse(settingsContents);
var jLocale = jObj.Property("LocaleCountryCode");
var jDecryptKey = jObj.Property("DecryptKey");
jDecryptKey?.Remove();
jLocale?.Remove();
if (jDecryptKey != null || jLocale != null)
{
var newContents = jObj.ToString(Formatting.Indented);
File.WriteAllText(Configuration.Instance.SettingsFilePath, newContents);
}
}
#endregion
#region migrate_to_v5_0_0 re-gegister device if device info not in settings
private static void migrate_to_v5_0_0()
{
var persistentDictionary = new PersistentDictionary(Configuration.Instance.SettingsFilePath);
var config = Configuration.Instance;
if (persistentDictionary.GetString(nameof(config.AllowLibationFixup)) is null)
{
persistentDictionary.Set(nameof(config.AllowLibationFixup), true);
}
if (!File.Exists(AudibleApiStorage.AccountsSettingsFile))
return;
@ -258,8 +178,9 @@ namespace LibationLauncher
}
#endregion
#region migrate to v5.2.0 : get rid of meta-directories, combine DownloadsInProgressEnum and DecryptInProgressEnum => InProgress
private static void migrate_to_v5_2_0()
#region migrate to v5.2.0
// get rid of meta-directories, combine DownloadsInProgressEnum and DecryptInProgressEnum => InProgress
private static void migrate_to_v5_2_0__pre_config()
{
{
var settingsKey = "DownloadsInProgressEnum";
@ -290,12 +211,19 @@ namespace LibationLauncher
"WinTemp" => Path.GetFullPath(Path.Combine(Path.GetTempPath(), "Libation")),
_ => path
};
private static void migrate_to_v5_2_0__post_config(Configuration config)
{
if (!config.Exists(nameof(config.AllowLibationFixup)))
config.AllowLibationFixup = true;
if (!config.Exists(nameof(config.DecryptToLossy)))
config.DecryptToLossy = false;
}
#endregion
private static void ensureSerilogConfig()
private static void ensureSerilogConfig(Configuration config)
{
var config = Configuration.Instance;
if (config.GetObject("Serilog") != null)
return;
@ -348,10 +276,8 @@ namespace LibationLauncher
config.SetObject("Serilog", serilogObj);
}
private static void configureLogging()
private static void configureLogging(Configuration config)
{
var config = Configuration.Instance;
// override path. always use current libation files
var logPath = Path.Combine(Configuration.Instance.LibationFiles, "Log.log");
config.SetWithJsonPath("Serilog.WriteTo[1].Args", "path", logPath);
@ -382,7 +308,7 @@ namespace LibationLauncher
//Log.Logger.Here().Debug("Begin Libation. Debug with line numbers");
}
private static void checkForUpdate()
private static void checkForUpdate(Configuration config)
{
try
{
@ -439,10 +365,8 @@ namespace LibationLauncher
MessageBox.Show($"{message}\r\nSee log for details");
}
private static void logStartupState()
private static void logStartupState(Configuration config)
{
var config = Configuration.Instance;
// begin logging session with a form feed
Log.Logger.Information("\r\n\f");
Log.Logger.Information("Begin Libation. {@DebugInfo}", new

View File

@ -9,9 +9,11 @@ namespace LibationWinForms.Dialogs
{
public partial class DirectoryOrCustomSelectControl : UserControl
{
public bool SelectedDirectoryIsKnown => knownDirectoryRb.Checked;
public bool SelectedDirectoryIsCustom => customDirectoryRb.Checked;
public string SelectedDirectory
=> customDirectoryRb.Checked ? customTb.Text.Trim()
: knownDirectoryRb.Checked ? directorySelectControl.SelectedDirectory
=> SelectedDirectoryIsKnown ? directorySelectControl.SelectedDirectory
: SelectedDirectoryIsCustom ? customTb.Text.Trim()
: null;
public DirectoryOrCustomSelectControl()
@ -25,8 +27,8 @@ namespace LibationWinForms.Dialogs
/// <summary>Set items for combobox</summary>
/// <param name="knownDirectories">List rather than IEnumerable so that client can determine display order</param>
/// <param name="defaultDirectory"></param>
public void SetDirectoryItems(List<Configuration.KnownDirectories> knownDirectories, Configuration.KnownDirectories? defaultDirectory = Configuration.KnownDirectories.UserProfile)
=> this.directorySelectControl.SetDirectoryItems(knownDirectories, defaultDirectory);
public void SetDirectoryItems(List<Configuration.KnownDirectories> knownDirectories, Configuration.KnownDirectories? defaultDirectory = Configuration.KnownDirectories.UserProfile, string subDirectory = null)
=> this.directorySelectControl.SetDirectoryItems(knownDirectories, defaultDirectory, subDirectory);
/// <summary>set selection</summary>
/// <param name="directory"></param>
@ -41,7 +43,13 @@ namespace LibationWinForms.Dialogs
public void SelectDirectory(string directory)
{
directory = directory?.Trim() ?? "";
selectDir(Configuration.GetKnownDirectory(directory), directory);
// remove SubDirectory setting to find known directories
var noSubDir = this.directorySelectControl.RemoveSubDirectoryFromPath(directory);
var knownDir = Configuration.GetKnownDirectory(noSubDir);
// DO NOT remove SubDirectory setting for custom
var customDir = directory;
selectDir(knownDir, customDir);
}
private void selectDir(Configuration.KnownDirectories knownDir, string customDir)

View File

@ -13,14 +13,17 @@ namespace LibationWinForms.Dialogs
{
public string Description { get; }
public Configuration.KnownDirectories Value { get; }
private DirectorySelectControl _parentControl;
public string FullPath => Configuration.GetKnownDirectoryPath(Value);
public string FullPath => _parentControl.AddSubDirectoryToPath(Configuration.GetKnownDirectoryPath(Value));
/// <summary>Displaying relative paths is confusing. UI should display absolute equivalent</summary>
public string UiDisplayPath => Value == Configuration.KnownDirectories.AppDir ? Configuration.AppDir_Absolute : FullPath;
public string UiDisplayPath => Value == Configuration.KnownDirectories.AppDir ? _parentControl.AddSubDirectoryToPath(Configuration.AppDir_Absolute) : FullPath;
public DirectoryComboBoxItem(Configuration.KnownDirectories knownDirectory)
public DirectoryComboBoxItem(DirectorySelectControl parentControl, Configuration.KnownDirectories knownDirectory)
{
_parentControl = parentControl;
Value = knownDirectory;
Description = Value.GetDescription();
}
@ -28,20 +31,42 @@ namespace LibationWinForms.Dialogs
public override string ToString() => Description;
}
private DirectoryComboBoxItem selectedItem => (DirectoryComboBoxItem)this.directoryComboBox.SelectedItem;
public string SelectedDirectory => selectedItem?.FullPath;
private string _subDirectory;
internal string AddSubDirectoryToPath(string path) => string.IsNullOrWhiteSpace(_subDirectory) ? path : System.IO.Path.Combine(path, _subDirectory);
internal string RemoveSubDirectoryFromPath(string path)
{
if (string.IsNullOrWhiteSpace(_subDirectory))
return path;
path = path?.Trim() ?? "";
if (string.IsNullOrWhiteSpace(path))
return path;
var bottomDir = System.IO.Path.GetFileName(path);
if (_subDirectory.EqualsInsensitive(bottomDir))
return System.IO.Path.GetDirectoryName(path);
return path;
}
private DirectoryComboBoxItem selectedItem => (DirectoryComboBoxItem)this.directoryComboBox.SelectedItem;
public DirectorySelectControl() => InitializeComponent();
/// <summary>Set items for combobox</summary>
/// <param name="knownDirectories">List rather than IEnumerable so that client can determine display order</param>
/// <param name="defaultDirectory">Optional default item to select</param>
public void SetDirectoryItems(List<Configuration.KnownDirectories> knownDirectories, Configuration.KnownDirectories? defaultDirectory = null)
public void SetDirectoryItems(List<Configuration.KnownDirectories> knownDirectories, Configuration.KnownDirectories? defaultDirectory = null, string subDirectory = null)
{
// set this 1st so all DirectoryComboBoxItems can reference it
_subDirectory = subDirectory;
this.directoryComboBox.Items.Clear();
foreach (var dir in knownDirectories.Where(d => d != Configuration.KnownDirectories.None).Distinct())
this.directoryComboBox.Items.Add(new DirectoryComboBoxItem(dir));
this.directoryComboBox.Items.Add(new DirectoryComboBoxItem(this, dir));
SelectDirectory(defaultDirectory);
}
@ -49,7 +74,14 @@ namespace LibationWinForms.Dialogs
/// <summary>set selection</summary>
/// <param name="directory"></param>
/// <returns>True is there was a matching entry</returns>
public bool SelectDirectory(string directory) => SelectDirectory(Configuration.GetKnownDirectory(directory));
public bool SelectDirectory(string directory)
{
directory = directory?.Trim() ?? "";
var noSubDir = RemoveSubDirectoryFromPath(directory);
var knownDir = Configuration.GetKnownDirectory(noSubDir);
return SelectDirectory(knownDir);
}
/// <summary>set selection</summary>
/// <param name="directory"></param>

View File

@ -6,8 +6,7 @@ namespace LibationWinForms.Dialogs
{
public partial class LibationFilesDialog : Form
{
private Configuration config { get; } = Configuration.Instance;
private Func<string, string> desc { get; } = Configuration.GetDescription;
public string SelectedDirectory { get; private set; }
public LibationFilesDialog() => InitializeComponent();
@ -16,7 +15,9 @@ namespace LibationWinForms.Dialogs
if (this.DesignMode)
return;
libationFilesDescLbl.Text = desc(nameof(config.LibationFiles));
var config = Configuration.Instance;
libationFilesDescLbl.Text = Configuration.GetDescription(nameof(config.LibationFiles));
libationFilesSelectControl.SetSearchTitle("Libation Files");
libationFilesSelectControl.SetDirectoryItems(new()
@ -31,12 +32,15 @@ namespace LibationWinForms.Dialogs
private void saveBtn_Click(object sender, EventArgs e)
{
var libationDir = libationFilesSelectControl.SelectedDirectory;
if (!config.TrySetLibationFiles(libationDir))
if (!System.IO.Directory.Exists(libationDir))
{
MessageBox.Show("Not saving change to Libation Files location. This folder does not exist:\r\n" + libationDir);
return;
}
SelectedDirectory = libationDir;
this.DialogResult = DialogResult.OK;
this.Close();
}

View File

@ -28,181 +28,186 @@
/// </summary>
private void InitializeComponent()
{
this.booksLocationLbl = new System.Windows.Forms.Label();
this.booksLocationDescLbl = new System.Windows.Forms.Label();
this.inProgressDescLbl = new System.Windows.Forms.Label();
this.saveBtn = new System.Windows.Forms.Button();
this.cancelBtn = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.inProgressSelectControl = new LibationWinForms.Dialogs.DirectorySelectControl();
this.allowLibationFixupCbox = new System.Windows.Forms.CheckBox();
this.booksSelectControl = new LibationWinForms.Dialogs.DirectoryOrCustomSelectControl();
this.convertLosslessRb = new System.Windows.Forms.RadioButton();
this.convertLossyRb = new System.Windows.Forms.RadioButton();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// booksLocationLbl
//
this.booksLocationLbl.AutoSize = true;
this.booksLocationLbl.Location = new System.Drawing.Point(13, 15);
this.booksLocationLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.booksLocationLbl.Name = "booksLocationLbl";
this.booksLocationLbl.Size = new System.Drawing.Size(85, 15);
this.booksLocationLbl.TabIndex = 0;
this.booksLocationLbl.Text = "Books location";
//
// booksLocationDescLbl
//
this.booksLocationDescLbl.AutoSize = true;
this.booksLocationDescLbl.Location = new System.Drawing.Point(106, 96);
this.booksLocationDescLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.booksLocationDescLbl.Name = "booksLocationDescLbl";
this.booksLocationDescLbl.Size = new System.Drawing.Size(39, 15);
this.booksLocationDescLbl.TabIndex = 2;
this.booksLocationDescLbl.Text = "[desc]";
//
// inProgressDescLbl
//
this.inProgressDescLbl.AutoSize = true;
this.inProgressDescLbl.Location = new System.Drawing.Point(10, 46);
this.inProgressDescLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.inProgressDescLbl.Name = "inProgressDescLbl";
this.inProgressDescLbl.Size = new System.Drawing.Size(43, 45);
this.inProgressDescLbl.TabIndex = 1;
this.inProgressDescLbl.Text = "[desc]\r\n[line 2]\r\n[line 3]";
//
// 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, 268);
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 = 4;
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, 268);
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 = 5;
this.cancelBtn.Text = "Cancel";
this.cancelBtn.UseVisualStyleBackColor = true;
this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.convertLossyRb);
this.groupBox1.Controls.Add(this.convertLosslessRb);
this.groupBox1.Controls.Add(this.inProgressSelectControl);
this.groupBox1.Controls.Add(this.allowLibationFixupCbox);
this.groupBox1.Controls.Add(this.inProgressDescLbl);
this.groupBox1.Location = new System.Drawing.Point(19, 114);
this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.groupBox1.Size = new System.Drawing.Size(902, 143);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Advanced settings for control freaks";
//
// inProgressSelectControl
//
this.inProgressSelectControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.booksLocationDescLbl = new System.Windows.Forms.Label();
this.inProgressDescLbl = new System.Windows.Forms.Label();
this.saveBtn = new System.Windows.Forms.Button();
this.cancelBtn = new System.Windows.Forms.Button();
this.advancedSettingsGb = new System.Windows.Forms.GroupBox();
this.convertLossyRb = new System.Windows.Forms.RadioButton();
this.convertLosslessRb = new System.Windows.Forms.RadioButton();
this.inProgressSelectControl = new LibationWinForms.Dialogs.DirectorySelectControl();
this.allowLibationFixupCbox = new System.Windows.Forms.CheckBox();
this.booksSelectControl = new LibationWinForms.Dialogs.DirectoryOrCustomSelectControl();
this.booksGb = new System.Windows.Forms.GroupBox();
this.advancedSettingsGb.SuspendLayout();
this.booksGb.SuspendLayout();
this.SuspendLayout();
//
// booksLocationDescLbl
//
this.booksLocationDescLbl.AutoSize = true;
this.booksLocationDescLbl.Location = new System.Drawing.Point(7, 19);
this.booksLocationDescLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.booksLocationDescLbl.Name = "booksLocationDescLbl";
this.booksLocationDescLbl.Size = new System.Drawing.Size(69, 15);
this.booksLocationDescLbl.TabIndex = 2;
this.booksLocationDescLbl.Text = "[book desc]";
//
// inProgressDescLbl
//
this.inProgressDescLbl.AutoSize = true;
this.inProgressDescLbl.Location = new System.Drawing.Point(8, 127);
this.inProgressDescLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.inProgressDescLbl.Name = "inProgressDescLbl";
this.inProgressDescLbl.Size = new System.Drawing.Size(43, 45);
this.inProgressDescLbl.TabIndex = 1;
this.inProgressDescLbl.Text = "[desc]\r\n[line 2]\r\n[line 3]";
//
// 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, 380);
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 = 4;
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, 380);
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 = 5;
this.cancelBtn.Text = "Cancel";
this.cancelBtn.UseVisualStyleBackColor = true;
this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click);
//
// advancedSettingsGb
//
this.advancedSettingsGb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.inProgressSelectControl.Location = new System.Drawing.Point(10, 94);
this.inProgressSelectControl.Name = "inProgressSelectControl";
this.inProgressSelectControl.Size = new System.Drawing.Size(885, 46);
this.inProgressSelectControl.TabIndex = 2;
//
// allowLibationFixupCbox
//
this.allowLibationFixupCbox.AutoSize = true;
this.allowLibationFixupCbox.Location = new System.Drawing.Point(10, 24);
this.allowLibationFixupCbox.Name = "allowLibationFixupCbox";
this.allowLibationFixupCbox.Size = new System.Drawing.Size(262, 19);
this.allowLibationFixupCbox.TabIndex = 0;
this.allowLibationFixupCbox.Text = "Allow Libation to fix up audiobook metadata";
this.allowLibationFixupCbox.UseVisualStyleBackColor = true;
this.allowLibationFixupCbox.CheckedChanged += new System.EventHandler(this.allowLibationFixupCbox_CheckedChanged);
//
// booksSelectControl
//
this.booksSelectControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.advancedSettingsGb.Controls.Add(this.convertLossyRb);
this.advancedSettingsGb.Controls.Add(this.convertLosslessRb);
this.advancedSettingsGb.Controls.Add(this.inProgressSelectControl);
this.advancedSettingsGb.Controls.Add(this.allowLibationFixupCbox);
this.advancedSettingsGb.Controls.Add(this.inProgressDescLbl);
this.advancedSettingsGb.Location = new System.Drawing.Point(12, 141);
this.advancedSettingsGb.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.advancedSettingsGb.Name = "advancedSettingsGb";
this.advancedSettingsGb.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.advancedSettingsGb.Size = new System.Drawing.Size(908, 226);
this.advancedSettingsGb.TabIndex = 3;
this.advancedSettingsGb.TabStop = false;
this.advancedSettingsGb.Text = "Advanced settings for control freaks";
//
// convertLossyRb
//
this.convertLossyRb.AutoSize = true;
this.convertLossyRb.Location = new System.Drawing.Point(7, 88);
this.convertLossyRb.Name = "convertLossyRb";
this.convertLossyRb.Size = new System.Drawing.Size(242, 19);
this.convertLossyRb.TabIndex = 0;
this.convertLossyRb.Text = "Download my books as .MP3 files (Lossy)";
this.convertLossyRb.UseVisualStyleBackColor = true;
//
// convertLosslessRb
//
this.convertLosslessRb.AutoSize = true;
this.convertLosslessRb.Checked = true;
this.convertLosslessRb.Location = new System.Drawing.Point(7, 63);
this.convertLosslessRb.Name = "convertLosslessRb";
this.convertLosslessRb.Size = new System.Drawing.Size(307, 19);
this.convertLosslessRb.TabIndex = 0;
this.convertLosslessRb.TabStop = true;
this.convertLosslessRb.Text = "Download books as .M4B files (Lossless Mp4a format)";
this.convertLosslessRb.UseVisualStyleBackColor = true;
//
// inProgressSelectControl
//
this.inProgressSelectControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.booksSelectControl.Location = new System.Drawing.Point(106, 12);
this.booksSelectControl.Name = "booksSelectControl";
this.booksSelectControl.Size = new System.Drawing.Size(815, 81);
this.booksSelectControl.TabIndex = 1;
//
// convertLosslessRb
//
this.convertLosslessRb.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.convertLosslessRb.AutoSize = true;
this.convertLosslessRb.Checked = true;
this.convertLosslessRb.Location = new System.Drawing.Point(692, 24);
this.convertLosslessRb.Name = "convertLosslessRb";
this.convertLosslessRb.Size = new System.Drawing.Size(108, 19);
this.convertLosslessRb.TabIndex = 0;
this.convertLosslessRb.TabStop = true;
this.convertLosslessRb.Text = "Mp4a (Lossless)";
this.convertLosslessRb.UseVisualStyleBackColor = true;
//
// convertLossyRb
//
this.convertLossyRb.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.convertLossyRb.AutoSize = true;
this.convertLossyRb.Location = new System.Drawing.Point(806, 24);
this.convertLossyRb.Name = "convertLossyRb";
this.convertLossyRb.Size = new System.Drawing.Size(89, 19);
this.convertLossyRb.TabIndex = 0;
this.convertLossyRb.Text = "Mp3 (Lossy)";
this.convertLossyRb.UseVisualStyleBackColor = true;
//
// SettingsDialog
//
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, 309);
this.Controls.Add(this.booksSelectControl);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.cancelBtn);
this.Controls.Add(this.saveBtn);
this.Controls.Add(this.booksLocationDescLbl);
this.Controls.Add(this.booksLocationLbl);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.Name = "SettingsDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Edit Settings";
this.Load += new System.EventHandler(this.SettingsDialog_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
this.inProgressSelectControl.Location = new System.Drawing.Point(10, 175);
this.inProgressSelectControl.Name = "inProgressSelectControl";
this.inProgressSelectControl.Size = new System.Drawing.Size(552, 46);
this.inProgressSelectControl.TabIndex = 2;
//
// allowLibationFixupCbox
//
this.allowLibationFixupCbox.AutoSize = true;
this.allowLibationFixupCbox.Checked = true;
this.allowLibationFixupCbox.CheckState = System.Windows.Forms.CheckState.Checked;
this.allowLibationFixupCbox.Location = new System.Drawing.Point(7, 22);
this.allowLibationFixupCbox.Name = "allowLibationFixupCbox";
this.allowLibationFixupCbox.Size = new System.Drawing.Size(262, 19);
this.allowLibationFixupCbox.TabIndex = 0;
this.allowLibationFixupCbox.Text = "Allow Libation to fix up audiobook metadata";
this.allowLibationFixupCbox.UseVisualStyleBackColor = true;
this.allowLibationFixupCbox.CheckedChanged += new System.EventHandler(this.allowLibationFixupCbox_CheckedChanged);
//
// booksSelectControl
//
this.booksSelectControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.booksSelectControl.Location = new System.Drawing.Point(7, 37);
this.booksSelectControl.Name = "booksSelectControl";
this.booksSelectControl.Size = new System.Drawing.Size(895, 81);
this.booksSelectControl.TabIndex = 1;
//
// booksGb
//
this.booksGb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.booksGb.Controls.Add(this.booksSelectControl);
this.booksGb.Controls.Add(this.booksLocationDescLbl);
this.booksGb.Location = new System.Drawing.Point(12, 12);
this.booksGb.Name = "booksGb";
this.booksGb.Size = new System.Drawing.Size(908, 123);
this.booksGb.TabIndex = 6;
this.booksGb.TabStop = false;
this.booksGb.Text = "Books location";
//
// SettingsDialog
//
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, 421);
this.Controls.Add(this.booksGb);
this.Controls.Add(this.advancedSettingsGb);
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 = "SettingsDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Edit Settings";
this.Load += new System.EventHandler(this.SettingsDialog_Load);
this.advancedSettingsGb.ResumeLayout(false);
this.advancedSettingsGb.PerformLayout();
this.booksGb.ResumeLayout(false);
this.booksGb.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label booksLocationLbl;
private System.Windows.Forms.Label booksLocationDescLbl;
private System.Windows.Forms.Label inProgressDescLbl;
private System.Windows.Forms.Button saveBtn;
private System.Windows.Forms.Button cancelBtn;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox advancedSettingsGb;
private System.Windows.Forms.CheckBox allowLibationFixupCbox;
private DirectoryOrCustomSelectControl booksSelectControl;
private DirectorySelectControl inProgressSelectControl;
private System.Windows.Forms.RadioButton convertLossyRb;
private System.Windows.Forms.RadioButton convertLosslessRb;
}
private System.Windows.Forms.GroupBox booksGb;
}
}

View File

@ -21,12 +21,15 @@ namespace LibationWinForms.Dialogs
this.inProgressDescLbl.Text = desc(nameof(config.InProgress));
booksSelectControl.SetSearchTitle("books location");
booksSelectControl.SetDirectoryItems(new()
{
booksSelectControl.SetDirectoryItems(
new()
{
Configuration.KnownDirectories.UserProfile,
Configuration.KnownDirectories.AppDir,
Configuration.KnownDirectories.MyDocs
},
Configuration.KnownDirectories.UserProfile,
Configuration.KnownDirectories.AppDir,
Configuration.KnownDirectories.MyDocs
}, Configuration.KnownDirectories.UserProfile);
"Books");
booksSelectControl.SelectDirectory(config.Books);
allowLibationFixupCbox.Checked = config.AllowLibationFixup;
@ -54,13 +57,26 @@ namespace LibationWinForms.Dialogs
config.InProgress = inProgressSelectControl.SelectedDirectory;
var newBooks = booksSelectControl.SelectedDirectory;
if (!Directory.Exists(newBooks))
if (string.IsNullOrWhiteSpace(newBooks))
{
MessageBox.Show($"Not saving change to Books location. This folder does not exist:\r\n{newBooks}");
MessageBox.Show("Cannot set Books Location to blank");
return;
}
else
config.Books = newBooks;
if (!Directory.Exists(newBooks))
{
if (booksSelectControl.SelectedDirectoryIsCustom)
{
MessageBox.Show($"Not saving change to Books location. This folder does not exist:\r\n{newBooks}");
return;
}
if (booksSelectControl.SelectedDirectoryIsKnown)
Directory.CreateDirectory(newBooks);
}
config.Books = newBooks;
this.DialogResult = DialogResult.OK;
this.Close();

View File

@ -30,63 +30,57 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SetupDialog));
this.welcomeLbl = new System.Windows.Forms.Label();
this.noQuestionsBtn = new System.Windows.Forms.Button();
this.basicBtn = new System.Windows.Forms.Button();
this.advancedBtn = new System.Windows.Forms.Button();
this.newUserBtn = new System.Windows.Forms.Button();
this.returningUserBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// welcomeLbl
//
this.welcomeLbl.AutoSize = true;
this.welcomeLbl.Location = new System.Drawing.Point(12, 9);
this.welcomeLbl.Location = new System.Drawing.Point(14, 10);
this.welcomeLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.welcomeLbl.Name = "welcomeLbl";
this.welcomeLbl.Size = new System.Drawing.Size(399, 117);
this.welcomeLbl.Size = new System.Drawing.Size(449, 135);
this.welcomeLbl.TabIndex = 0;
this.welcomeLbl.Text = resources.GetString("welcomeLbl.Text");
//
// noQuestionsBtn
// newUserBtn
//
this.noQuestionsBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.noQuestionsBtn.Location = new System.Drawing.Point(15, 129);
this.noQuestionsBtn.Name = "noQuestionsBtn";
this.noQuestionsBtn.Size = new System.Drawing.Size(396, 57);
this.noQuestionsBtn.TabIndex = 1;
this.noQuestionsBtn.Text = "NO-QUESTIONS SETUP\r\n\r\nAccept all defaults";
this.noQuestionsBtn.UseVisualStyleBackColor = true;
this.newUserBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.newUserBtn.Location = new System.Drawing.Point(18, 156);
this.newUserBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.newUserBtn.Name = "newUserBtn";
this.newUserBtn.Size = new System.Drawing.Size(462, 66);
this.newUserBtn.TabIndex = 2;
this.newUserBtn.Text = "NEW USER\r\n\r\nChoose settings";
this.newUserBtn.UseVisualStyleBackColor = true;
this.newUserBtn.Click += new System.EventHandler(this.newUserBtn_Click);
//
// basicBtn
// returningUserBtn
//
this.basicBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.basicBtn.Location = new System.Drawing.Point(15, 192);
this.basicBtn.Name = "basicBtn";
this.basicBtn.Size = new System.Drawing.Size(396, 57);
this.basicBtn.TabIndex = 2;
this.basicBtn.Text = "BASIC SETUP\r\n\r\nChoose settings";
this.basicBtn.UseVisualStyleBackColor = true;
//
// advancedBtn
//
this.advancedBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.advancedBtn.Location = new System.Drawing.Point(15, 255);
this.advancedBtn.Name = "advancedBtn";
this.advancedBtn.Size = new System.Drawing.Size(396, 57);
this.advancedBtn.TabIndex = 3;
this.advancedBtn.Text = "ADVANCED SETUP\r\n\r\nChoose settings and where to store them";
this.advancedBtn.UseVisualStyleBackColor = true;
this.returningUserBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.returningUserBtn.Location = new System.Drawing.Point(18, 228);
this.returningUserBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.returningUserBtn.Name = "returningUserBtn";
this.returningUserBtn.Size = new System.Drawing.Size(462, 66);
this.returningUserBtn.TabIndex = 3;
this.returningUserBtn.Text = "RETURNING USER\r\n\r\nI have previously installed Libation. This is an upgrade or re-" +
"install";
this.returningUserBtn.UseVisualStyleBackColor = true;
this.returningUserBtn.Click += new System.EventHandler(this.returningUserBtn_Click);
//
// SetupDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(423, 324);
this.Controls.Add(this.advancedBtn);
this.Controls.Add(this.basicBtn);
this.Controls.Add(this.noQuestionsBtn);
this.ClientSize = new System.Drawing.Size(493, 308);
this.Controls.Add(this.returningUserBtn);
this.Controls.Add(this.newUserBtn);
this.Controls.Add(this.welcomeLbl);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.Name = "SetupDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Welcome to Libation";
@ -98,8 +92,7 @@
#endregion
private System.Windows.Forms.Label welcomeLbl;
private System.Windows.Forms.Button noQuestionsBtn;
private System.Windows.Forms.Button basicBtn;
private System.Windows.Forms.Button advancedBtn;
private System.Windows.Forms.Button newUserBtn;
private System.Windows.Forms.Button returningUserBtn;
}
}

View File

@ -5,33 +5,25 @@ namespace LibationWinForms.Dialogs
{
public partial class SetupDialog : Form
{
public event EventHandler NoQuestionsBtn_Click
public bool IsNewUser { get; private set; }
public bool IsReturningUser { get; private set; }
public SetupDialog() => InitializeComponent();
private void newUserBtn_Click(object sender, EventArgs e)
{
add => noQuestionsBtn.Click += value;
remove => noQuestionsBtn.Click -= value;
IsNewUser = true;
this.DialogResult = DialogResult.OK;
Close();
}
public event EventHandler BasicBtn_Click
private void returningUserBtn_Click(object sender, EventArgs e)
{
add => basicBtn.Click += value;
remove => basicBtn.Click -= value;
IsReturningUser = true;
this.DialogResult = DialogResult.OK;
Close();
}
public event EventHandler AdvancedBtn_Click
{
add => advancedBtn.Click += value;
remove => advancedBtn.Click -= value;
}
public SetupDialog()
{
InitializeComponent();
noQuestionsBtn.Click += btn_Click;
basicBtn.Click += btn_Click;
advancedBtn.Click += btn_Click;
}
private void btn_Click(object sender, EventArgs e) => Close();
}
}

View File

@ -66,6 +66,6 @@ After you make your selections, get started by importing your library.
Go to Import &gt; Scan Library
Download your entire library from the "Liberate" tab or
liberate your books one at a time by clicking the stoplight</value>
liberate your books one at a time by clicking the stoplight.</value>
</data>
</root>

View File

@ -399,13 +399,20 @@ namespace LibationWinForms
private void advancedSettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
var oldLocation = Configuration.Instance.LibationFiles;
new LibationFilesDialog().ShowDialog();
var libationFilesDialog = new LibationFilesDialog();
if (libationFilesDialog.ShowDialog() != DialogResult.OK)
return;
// no change
if (System.IO.Path.GetFullPath(oldLocation).EqualsInsensitive(System.IO.Path.GetFullPath(Configuration.Instance.LibationFiles)))
if (System.IO.Path.GetFullPath(libationFilesDialog.SelectedDirectory).EqualsInsensitive(System.IO.Path.GetFullPath(Configuration.Instance.LibationFiles)))
return;
if (!Configuration.Instance.TrySetLibationFiles(libationFilesDialog.SelectedDirectory))
{
MessageBox.Show("Not saving change to Libation Files location. This folder does not exist:\r\n" + libationFilesDialog.SelectedDirectory);
return;
}
MessageBox.Show(
"You have changed a file path important for this program. All files will remain in their original location; nothing will be moved. Libation must be restarted so these changes are handled correctly.",
"Closing Libation",