config bug fix
This commit is contained in:
parent
b4def2e2d6
commit
79e5545fd3
@ -48,7 +48,11 @@ namespace FileManager
|
|||||||
|
|
||||||
public object GetObject(string propertyName) => persistentDictionary.GetObject(propertyName);
|
public object GetObject(string propertyName) => persistentDictionary.GetObject(propertyName);
|
||||||
public void SetObject(string propertyName, object newValue) => persistentDictionary.SetNonString(propertyName, newValue);
|
public void SetObject(string propertyName, object newValue) => persistentDictionary.SetNonString(propertyName, newValue);
|
||||||
public void SetWithJsonPath(string jsonPath, string propertyName, string newValue, bool suppressLogging = false) => persistentDictionary.SetWithJsonPath(jsonPath, propertyName, newValue, suppressLogging);
|
|
||||||
|
/// <summary>WILL ONLY set if already present. WILL NOT create new</summary>
|
||||||
|
/// <returns>Value was changed</returns>
|
||||||
|
public bool SetWithJsonPath(string jsonPath, string propertyName, string newValue, bool suppressLogging = false)
|
||||||
|
=> persistentDictionary.SetWithJsonPath(jsonPath, propertyName, newValue, suppressLogging);
|
||||||
|
|
||||||
public string SettingsFilePath => Path.Combine(LibationFiles, "Settings.json");
|
public string SettingsFilePath => Path.Combine(LibationFiles, "Settings.json");
|
||||||
|
|
||||||
@ -219,7 +223,12 @@ namespace FileManager
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
persistentDictionary.SetWithJsonPath("Serilog", "MinimumLevel", value.ToString());
|
var valueWasChanged = persistentDictionary.SetWithJsonPath("Serilog", "MinimumLevel", value.ToString());
|
||||||
|
if (!valueWasChanged)
|
||||||
|
{
|
||||||
|
Log.Logger.Information("LogLevel.set attempt. No change");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
configuration.Reload();
|
configuration.Reload();
|
||||||
|
|
||||||
@ -263,7 +272,8 @@ namespace FileManager
|
|||||||
// Config init in Program.ensureSerilogConfig() only happens when serilog setting is first created (prob on 1st run).
|
// Config init in Program.ensureSerilogConfig() only happens when serilog setting is first created (prob on 1st run).
|
||||||
// This Set() enforces current LibationFiles every time we restart Libation or redirect LibationFiles
|
// This Set() enforces current LibationFiles every time we restart Libation or redirect LibationFiles
|
||||||
var logPath = Path.Combine(LibationFiles, "Log.log");
|
var logPath = Path.Combine(LibationFiles, "Log.log");
|
||||||
SetWithJsonPath("Serilog.WriteTo[1].Args", "path", logPath, true);
|
bool settingWasChanged = SetWithJsonPath("Serilog.WriteTo[1].Args", "path", logPath, true);
|
||||||
|
if (settingWasChanged)
|
||||||
configuration?.Reload();
|
configuration?.Reload();
|
||||||
|
|
||||||
return libationFilesPathCache;
|
return libationFilesPathCache;
|
||||||
|
|||||||
@ -142,34 +142,45 @@ namespace FileManager
|
|||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetWithJsonPath(string jsonPath, string propertyName, string newValue, bool suppressLogging = false)
|
/// <summary>WILL ONLY set if already present. WILL NOT create new</summary>
|
||||||
|
/// <returns>Value was changed</returns>
|
||||||
|
public bool SetWithJsonPath(string jsonPath, string propertyName, string newValue, bool suppressLogging = false)
|
||||||
{
|
{
|
||||||
if (IsReadOnly)
|
if (IsReadOnly)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
var path = $"{jsonPath}.{propertyName}";
|
var path = $"{jsonPath}.{propertyName}";
|
||||||
|
|
||||||
{
|
{
|
||||||
// only do this check in string cache, NOT object cache
|
// only do this check in string cache, NOT object cache
|
||||||
if (stringCache.ContainsKey(path) && stringCache[path] == newValue)
|
if (stringCache.ContainsKey(path) && stringCache[path] == newValue)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
// set cache
|
// set cache
|
||||||
stringCache[path] = newValue;
|
stringCache[path] = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
lock (locker)
|
lock (locker)
|
||||||
{
|
{
|
||||||
var jObject = readFile();
|
var jObject = readFile();
|
||||||
var token = jObject.SelectToken(jsonPath);
|
var token = jObject.SelectToken(jsonPath);
|
||||||
var oldValue = token.Value<string>(propertyName);
|
if (token is null || token[propertyName] is null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var oldValue = token.Value<string>(propertyName);
|
||||||
if (oldValue == newValue)
|
if (oldValue == newValue)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
token[propertyName] = newValue;
|
token[propertyName] = newValue;
|
||||||
File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented));
|
File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exDebug)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!suppressLogging)
|
if (!suppressLogging)
|
||||||
{
|
{
|
||||||
@ -180,6 +191,8 @@ namespace FileManager
|
|||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string formatValueForLog(string value)
|
private static string formatValueForLog(string value)
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
|
||||||
<Version>5.3.4.1</Version>
|
<Version>5.3.5.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -351,7 +351,7 @@ Libation.
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// timed out
|
// timed out
|
||||||
var latest = getLatestRelease(TimeSpan.FromSeconds(30));
|
var latest = getLatestRelease(TimeSpan.FromSeconds(10));
|
||||||
if (latest is null)
|
if (latest is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -388,6 +388,11 @@ Libation.
|
|||||||
return;
|
return;
|
||||||
selectedPath = fileSelector.FileName;
|
selectedPath = fileSelector.FileName;
|
||||||
}
|
}
|
||||||
|
catch (AggregateException aggEx)
|
||||||
|
{
|
||||||
|
Log.Logger.Error(aggEx, "Checking for new version too often");
|
||||||
|
return;
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBoxAlertAdmin.Show("Error checking for update", "Error checking for update", ex);
|
MessageBoxAlertAdmin.Show("Error checking for update", "Error checking for update", ex);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
using DataLayer;
|
using DataLayer;
|
||||||
@ -33,6 +34,31 @@ namespace LibationWinForms
|
|||||||
|
|
||||||
beginBookBackupsToolStripMenuItem_format = beginBookBackupsToolStripMenuItem.Text;
|
beginBookBackupsToolStripMenuItem_format = beginBookBackupsToolStripMenuItem.Text;
|
||||||
beginPdfBackupsToolStripMenuItem_format = beginPdfBackupsToolStripMenuItem.Text;
|
beginPdfBackupsToolStripMenuItem_format = beginPdfBackupsToolStripMenuItem.Text;
|
||||||
|
|
||||||
|
// after backing up formats: can set default/temp visible text
|
||||||
|
backupsCountsLbl.Text = "[Calculating backed up book quantities]";
|
||||||
|
pdfsCountsLbl.Text = "[Calculating backed up PDFs]";
|
||||||
|
setVisibleCount(null, 0);
|
||||||
|
|
||||||
|
if (this.DesignMode)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// independent UI updates
|
||||||
|
this.Load += setBackupCountsAsync;
|
||||||
|
this.Load += (_, __) => RestoreSizeAndLocation();
|
||||||
|
this.Load += (_, __) => RefreshImportMenu();
|
||||||
|
|
||||||
|
// start background service
|
||||||
|
this.Load += (_, __) => startBackgroundImageDownloader();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void startBackgroundImageDownloader()
|
||||||
|
{
|
||||||
|
// load default/missing cover images. this will also initiate the background image downloader
|
||||||
|
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
|
||||||
|
PictureStorage.SetDefaultImage(PictureSize._80x80, Properties.Resources.default_cover_80x80.ToBytes(format));
|
||||||
|
PictureStorage.SetDefaultImage(PictureSize._300x300, Properties.Resources.default_cover_300x300.ToBytes(format));
|
||||||
|
PictureStorage.SetDefaultImage(PictureSize._500x500, Properties.Resources.default_cover_500x500.ToBytes(format));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form1_Load(object sender, EventArgs e)
|
private void Form1_Load(object sender, EventArgs e)
|
||||||
@ -40,27 +66,10 @@ namespace LibationWinForms
|
|||||||
if (this.DesignMode)
|
if (this.DesignMode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RestoreSizeAndLocation();
|
|
||||||
|
|
||||||
// load default/missing cover images. this will also initiate the background image downloader
|
|
||||||
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
|
|
||||||
PictureStorage.SetDefaultImage(PictureSize._80x80, Properties.Resources.default_cover_80x80.ToBytes(format));
|
|
||||||
PictureStorage.SetDefaultImage(PictureSize._300x300, Properties.Resources.default_cover_300x300.ToBytes(format));
|
|
||||||
PictureStorage.SetDefaultImage(PictureSize._500x500, Properties.Resources.default_cover_500x500.ToBytes(format));
|
|
||||||
|
|
||||||
RefreshImportMenu();
|
|
||||||
|
|
||||||
setVisibleCount(null, 0);
|
|
||||||
|
|
||||||
reloadGrid();
|
reloadGrid();
|
||||||
|
|
||||||
// also applies filter. ONLY call AFTER loading grid
|
// also applies filter. ONLY call AFTER loading grid
|
||||||
loadInitialQuickFilterState();
|
loadInitialQuickFilterState();
|
||||||
|
|
||||||
// init bottom counts
|
|
||||||
backupsCountsLbl.Text = "[Calculating backed up book quantities]";
|
|
||||||
pdfsCountsLbl.Text = "[Calculating backed up PDFs]";
|
|
||||||
setBackupCounts(null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
@ -161,14 +170,14 @@ namespace LibationWinForms
|
|||||||
{
|
{
|
||||||
gridPanel.Controls.Remove(currProductsGrid);
|
gridPanel.Controls.Remove(currProductsGrid);
|
||||||
currProductsGrid.VisibleCountChanged -= setVisibleCount;
|
currProductsGrid.VisibleCountChanged -= setVisibleCount;
|
||||||
currProductsGrid.BackupCountsChanged -= setBackupCounts;
|
currProductsGrid.BackupCountsChanged -= setBackupCountsAsync;
|
||||||
currProductsGrid.Dispose();
|
currProductsGrid.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
currProductsGrid = new ProductsGrid { Dock = DockStyle.Fill };
|
currProductsGrid = new ProductsGrid { Dock = DockStyle.Fill };
|
||||||
currProductsGrid.VisibleCountChanged += setVisibleCount;
|
currProductsGrid.VisibleCountChanged += setVisibleCount;
|
||||||
currProductsGrid.BackupCountsChanged += setBackupCounts;
|
currProductsGrid.BackupCountsChanged += setBackupCountsAsync;
|
||||||
gridPanel.Controls.Add(currProductsGrid);
|
gridPanel.UIThread(() => gridPanel.Controls.Add(currProductsGrid));
|
||||||
currProductsGrid.Display();
|
currProductsGrid.Display();
|
||||||
}
|
}
|
||||||
ResumeLayout();
|
ResumeLayout();
|
||||||
@ -180,8 +189,9 @@ namespace LibationWinForms
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region bottom: backup counts
|
#region bottom: backup counts
|
||||||
private void setBackupCounts(object _, object __)
|
private async void setBackupCountsAsync(object _, object __)
|
||||||
{
|
{
|
||||||
|
await Task.Run(() => {
|
||||||
var books = DbContexts.GetContext()
|
var books = DbContexts.GetContext()
|
||||||
.GetLibrary_Flat_NoTracking()
|
.GetLibrary_Flat_NoTracking()
|
||||||
.Select(sp => sp.Book)
|
.Select(sp => sp.Book)
|
||||||
@ -189,6 +199,7 @@ namespace LibationWinForms
|
|||||||
|
|
||||||
setBookBackupCounts(books);
|
setBookBackupCounts(books);
|
||||||
setPdfBackupCounts(books);
|
setPdfBackupCounts(books);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
enum AudioFileState { full, aax, none }
|
enum AudioFileState { full, aax, none }
|
||||||
private void setBookBackupCounts(IEnumerable<Book> books)
|
private void setBookBackupCounts(IEnumerable<Book> books)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user