Move application logic from view to Launcher
This commit is contained in:
parent
41620352e8
commit
123a32ff9b
@ -31,12 +31,10 @@ namespace FileManager
|
||||
*/
|
||||
#endregion
|
||||
|
||||
private const string configFilename = "LibationSettings.json";
|
||||
|
||||
private PersistentDictionary persistentDictionary { get; }
|
||||
|
||||
[Description("Location of the configuration file where these settings are saved. Please do not edit this file directly while Libation is running.")]
|
||||
public string Filepath { get; }
|
||||
public string Filepath => Path.Combine(Path.GetDirectoryName(Exe.FileLocationOnDisk), "Settings.json");
|
||||
|
||||
[Description("[Advanced. Leave alone in most cases.] Your user-specific key used to decrypt your audible files (*.aax) into audio files you can use anywhere (*.m4b)")]
|
||||
public string DecryptKey
|
||||
@ -90,13 +88,10 @@ namespace FileManager
|
||||
public static Configuration Instance { get; } = new Configuration();
|
||||
private Configuration()
|
||||
{
|
||||
Filepath = getPath();
|
||||
|
||||
// load json values into memory
|
||||
persistentDictionary = new PersistentDictionary(Filepath);
|
||||
ensureDictionaryEntries();
|
||||
|
||||
// setUserFilesDirectoryDefault
|
||||
// don't create dir. dir creation is the responsibility of places that use the dir
|
||||
if (string.IsNullOrWhiteSpace(LibationFiles))
|
||||
LibationFiles = Path.Combine(Path.GetDirectoryName(Exe.FileLocationOnDisk), "Libation");
|
||||
@ -113,67 +108,6 @@ namespace FileManager
|
||||
return attribute?.Description;
|
||||
}
|
||||
|
||||
private static string getPath()
|
||||
{
|
||||
// search folders for config file. accept the first match
|
||||
var defaultdir = Path.GetDirectoryName(Exe.FileLocationOnDisk);
|
||||
|
||||
var baseDirs = new HashSet<string>
|
||||
{
|
||||
defaultdir,
|
||||
getNonDevelopmentDir(defaultdir),
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.Personal)
|
||||
};
|
||||
|
||||
var subDirs = baseDirs.Select(dir => Path.Combine(dir, "Libation"));
|
||||
var dirs = baseDirs.Concat(subDirs).ToList();
|
||||
|
||||
foreach (var dir in dirs)
|
||||
{
|
||||
var f = Path.Combine(dir, configFilename);
|
||||
if (File.Exists(f))
|
||||
return f;
|
||||
}
|
||||
|
||||
return Path.Combine(defaultdir, configFilename);
|
||||
}
|
||||
|
||||
private static string getNonDevelopmentDir(string path)
|
||||
{
|
||||
// examples:
|
||||
// \Libation\Core2_0\bin\Debug\netcoreapp3.1
|
||||
// \Libation\StndLib\bin\Debug\netstandard2.1
|
||||
// \Libation\MyWnfrm\bin\Debug
|
||||
// \Libation\Core2_0\bin\Release\netcoreapp3.1
|
||||
// \Libation\StndLib\bin\Release\netstandard2.1
|
||||
// \Libation\MyWnfrm\bin\Release
|
||||
|
||||
var curr = new DirectoryInfo(path);
|
||||
|
||||
if (!curr.Name.EqualsInsensitive("debug") && !curr.Name.EqualsInsensitive("release") && !curr.Name.StartsWithInsensitive("netcoreapp") && !curr.Name.StartsWithInsensitive("netstandard"))
|
||||
return path;
|
||||
|
||||
// get out of netcore/standard dir => debug
|
||||
if (curr.Name.StartsWithInsensitive("netcoreapp") || curr.Name.StartsWithInsensitive("netstandard"))
|
||||
curr = curr.Parent;
|
||||
|
||||
if (!curr.Name.EqualsInsensitive("debug") && !curr.Name.EqualsInsensitive("release"))
|
||||
return path;
|
||||
|
||||
// get out of debug => bin
|
||||
curr = curr.Parent;
|
||||
if (!curr.Name.EqualsInsensitive("bin"))
|
||||
return path;
|
||||
|
||||
// get out of bin
|
||||
curr = curr.Parent;
|
||||
// get out of csproj-level dir
|
||||
curr = curr.Parent;
|
||||
|
||||
// curr should now be sln-level dir
|
||||
return curr.FullName;
|
||||
}
|
||||
|
||||
private void ensureDictionaryEntries()
|
||||
{
|
||||
var stringProperties = getDictionaryProperties().Select(p => p.Name).ToList();
|
||||
|
||||
@ -78,7 +78,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationServices", "Appl
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dinah.Core.WindowsDesktop", "..\Dinah.Core\Dinah.Core.WindowsDesktop\Dinah.Core.WindowsDesktop.csproj", "{059CE32C-9AD6-45E9-A166-790DFFB0B730}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsDesktopUtilities", "WindowsDesktopUtilities\WindowsDesktopUtilities.csproj", "{E7EFD64D-6630-4426-B09C-B6862A92E3FD}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsDesktopUtilities", "WindowsDesktopUtilities\WindowsDesktopUtilities.csproj", "{E7EFD64D-6630-4426-B09C-B6862A92E3FD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibationLauncher", "LibationLauncher\LibationLauncher.csproj", "{F3B04A3A-20C8-4582-A54A-715AF6A5D859}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -194,6 +196,10 @@ Global
|
||||
{E7EFD64D-6630-4426-B09C-B6862A92E3FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E7EFD64D-6630-4426-B09C-B6862A92E3FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E7EFD64D-6630-4426-B09C-B6862A92E3FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F3B04A3A-20C8-4582-A54A-715AF6A5D859}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F3B04A3A-20C8-4582-A54A-715AF6A5D859}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F3B04A3A-20C8-4582-A54A-715AF6A5D859}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F3B04A3A-20C8-4582-A54A-715AF6A5D859}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -226,6 +232,7 @@ Global
|
||||
{B95650EA-25F0-449E-BA5D-99126BC5D730} = {41CDCC73-9B81-49DD-9570-C54406E852AF}
|
||||
{059CE32C-9AD6-45E9-A166-790DFFB0B730} = {43E3ACB3-E0BC-4370-8DBB-E3720C8C8FD1}
|
||||
{E7EFD64D-6630-4426-B09C-B6862A92E3FD} = {F0CBB7A7-D3FB-41FF-8F47-CF3F6A592249}
|
||||
{F3B04A3A-20C8-4582-A54A-715AF6A5D859} = {8679CAC8-9164-4007-BDD2-F004810EDA14}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {615E00ED-BAEF-4E8E-A92A-9B82D87942A9}
|
||||
|
||||
26
LibationLauncher/LibationLauncher.csproj
Normal file
26
LibationLauncher/LibationLauncher.csproj
Normal file
@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ApplicationIcon>libation.ico</ApplicationIcon>
|
||||
<AssemblyName>Libation</AssemblyName>
|
||||
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LibationWinForm\LibationWinForm.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -1,29 +1,33 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using Dinah.Core.Logging;
|
||||
using FileManager;
|
||||
using LibationWinForm;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Serilog;
|
||||
|
||||
namespace LibationWinForm
|
||||
namespace LibationLauncher
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
[STAThread]
|
||||
static void Main()
|
||||
static class Program
|
||||
{
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
if (!createSettings())
|
||||
return;
|
||||
|
||||
init();
|
||||
initLogging();
|
||||
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
|
||||
private static bool createSettings()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(FileManager.Configuration.Instance.Books))
|
||||
if (!string.IsNullOrWhiteSpace(Configuration.Instance.Books))
|
||||
return true;
|
||||
|
||||
var welcomeText = @"
|
||||
@ -44,7 +48,7 @@ Go to Import > Scan Library
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void init()
|
||||
private static void initLogging()
|
||||
{
|
||||
// default. for reference. output example:
|
||||
// 2019-11-26 08:48:40.224 -05:00 [DBG] Begin Libation
|
||||
@ -54,8 +58,14 @@ Go to Import > Scan Library
|
||||
var code_outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] (at {Caller}) {Message:lj}{NewLine}{Exception}";
|
||||
|
||||
|
||||
var logPath = System.IO.Path.Combine(FileManager.Configuration.Instance.LibationFiles, "Log.log");
|
||||
var logPath = System.IO.Path.Combine(Configuration.Instance.LibationFiles, "Log.log");
|
||||
|
||||
//var configuration = new ConfigurationBuilder()
|
||||
// .AddJsonFile("appsettings.json")
|
||||
// .Build();
|
||||
//Log.Logger = new LoggerConfiguration()
|
||||
// .ReadFrom.Configuration(configuration)
|
||||
// .CreateLogger();
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.Enrich.WithCaller()
|
||||
.MinimumLevel.Debug()
|
||||
11
LibationLauncher/appsettings.json
Normal file
11
LibationLauncher/appsettings.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": "Debug",
|
||||
"Enrich": "WithCaller"
|
||||
}
|
||||
}
|
||||
BIN
LibationLauncher/libation.ico
Normal file
BIN
LibationLauncher/libation.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
@ -1,11 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ApplicationIcon>libation.ico</ApplicationIcon>
|
||||
<AssemblyName>Libation</AssemblyName>
|
||||
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
@ -39,11 +38,4 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -13,9 +13,6 @@ namespace LibationWinForm
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
// initial call here will initiate config loading
|
||||
private Configuration config { get; } = Configuration.Instance;
|
||||
|
||||
private string backupsCountsLbl_Format { get; }
|
||||
private string pdfsCountsLbl_Format { get; }
|
||||
private string visibleCountLbl_Format { get; }
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"": ""
|
||||
}
|
||||
@ -9,6 +9,7 @@ see comments at top of file:
|
||||
|
||||
LocalDb
|
||||
=======
|
||||
only works if LocalDb is separately installed on host box
|
||||
SSMS db connection: (LocalDb)\MSSQLLocalDB
|
||||
eg: Server=(localdb)\mssqllocaldb;Database=DataLayer.LibationContext;Integrated Security=true;
|
||||
LocalDb database files live at:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user