Continue working on main menu screen and refactor
New method for storing information on report data; rework and migrate settings to version 2; Add new options to ConfirmViewModel; rework some class hierarchy (may change more later)
This commit is contained in:
@@ -9,47 +9,23 @@ using MayShow.Helpers;
|
||||
|
||||
namespace MayShow.Models;
|
||||
|
||||
class PDFReport : ChangeNotifier
|
||||
class PDFReport : PDFReportInfo
|
||||
{
|
||||
private string _baseFolder;
|
||||
private string _title;
|
||||
private List<ReportFile> _files;
|
||||
private DateTime _lastSaved;
|
||||
private DateTime? _lastGenerated;
|
||||
|
||||
public PDFReport()
|
||||
public PDFReport() : base()
|
||||
{
|
||||
_baseFolder = "";
|
||||
_title = "";
|
||||
_files = [];
|
||||
_lastSaved = DateTime.Now;
|
||||
_lastGenerated = null;
|
||||
}
|
||||
|
||||
public string BaseFolder
|
||||
{
|
||||
get => _baseFolder;
|
||||
set { _baseFolder = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set { _title = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public List<ReportFile> Files
|
||||
{
|
||||
get => _files;
|
||||
set { _files = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public DateTime LastSaved
|
||||
{
|
||||
get => _lastSaved;
|
||||
set { _lastSaved = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public DateTime? LastGenerated
|
||||
{
|
||||
get => _lastGenerated;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using MayShow.Helpers;
|
||||
using MayShows.Helpers;
|
||||
|
||||
namespace MayShow.Models;
|
||||
|
||||
class PDFReportInfo : ChangeNotifier
|
||||
{
|
||||
private string? _baseFolder; // might be null
|
||||
private string _uuid;
|
||||
private string _title;
|
||||
private DateTime? _lastSaved;
|
||||
|
||||
public PDFReportInfo() : base()
|
||||
{
|
||||
_baseFolder = null;
|
||||
_uuid = Guid.NewGuid().ToString();
|
||||
_title = "";
|
||||
_lastSaved = null;
|
||||
}
|
||||
|
||||
public string? BaseFolder
|
||||
{
|
||||
get => _baseFolder;
|
||||
set { _baseFolder = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public string UUID
|
||||
{
|
||||
get => _uuid;
|
||||
set { _uuid = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set { _title = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public DateTime? LastSaved
|
||||
{
|
||||
get => _lastSaved;
|
||||
set { _lastSaved = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public void ResetUUID()
|
||||
{
|
||||
UUID = Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
public void DeleteInternalFolderFromDisk()
|
||||
{
|
||||
var path = Path.Combine(Utilities.GetInternalDataPath(), UUID);
|
||||
if (Directory.Exists(path) && path != Utilities.GetInternalDataPath())
|
||||
{
|
||||
Directory.Delete(path, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
@@ -18,10 +19,11 @@ class Settings : ChangeNotifier
|
||||
private string _outputPdfDir;
|
||||
private decimal _imageResizeThreshold;
|
||||
private bool _saveReportJsonDataInInternalDir;
|
||||
private Dictionary<string, string> _workingFolderToInternalFolderName;
|
||||
private Dictionary<string, string> _workingFolderToInternalFolderName; // obsolete
|
||||
private List<PDFReportInfo> _allReportInfo;
|
||||
public int _settingsVersion;
|
||||
|
||||
public Settings()
|
||||
public Settings() : base()
|
||||
{
|
||||
_lastUsedPath = "";
|
||||
_useDocnetPDFImageRendering = true;
|
||||
@@ -30,7 +32,8 @@ class Settings : ChangeNotifier
|
||||
_imageResizeThreshold = 1.5m;
|
||||
_saveReportJsonDataInInternalDir = false;
|
||||
_workingFolderToInternalFolderName = [];
|
||||
_settingsVersion = 1;
|
||||
_allReportInfo = [];
|
||||
_settingsVersion = 2;
|
||||
}
|
||||
|
||||
public Settings(Settings other)
|
||||
@@ -43,6 +46,7 @@ class Settings : ChangeNotifier
|
||||
_saveReportJsonDataInInternalDir = other.SaveReportJsonDataInInternalDir;
|
||||
_workingFolderToInternalFolderName = other.WorkingFolderToInternalFolderName;
|
||||
_settingsVersion = other.SettingsVersion;
|
||||
_allReportInfo = other.AllReportInfo;
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
@@ -95,6 +99,13 @@ class Settings : ChangeNotifier
|
||||
set { _workingFolderToInternalFolderName = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
public List<PDFReportInfo> AllReportInfo
|
||||
{
|
||||
get => _allReportInfo;
|
||||
set { _allReportInfo = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
public int SettingsVersion
|
||||
{
|
||||
@@ -135,6 +146,39 @@ class Settings : ChangeNotifier
|
||||
return json;
|
||||
}
|
||||
|
||||
private static Settings UpgradeSettings(Settings settings)
|
||||
{
|
||||
if (settings.SettingsVersion == 1)
|
||||
{
|
||||
// update settings
|
||||
var internalPath = Utilities.GetInternalDataPath();
|
||||
var list = new List<PDFReportInfo>();
|
||||
foreach (var data in settings.WorkingFolderToInternalFolderName)
|
||||
{
|
||||
var uuid = data.Value;
|
||||
var path = Path.Combine(internalPath, uuid, Constants.ReportSavedDataFileName);
|
||||
var json = File.ReadAllText(path);
|
||||
var jsonContext = new SourceGenerationContext(Utilities.GetSerializerOptions());
|
||||
var report = File.Exists(path) ? JsonSerializer.Deserialize(json, jsonContext.PDFReport) : null;
|
||||
var reportTitle = report?.Title ?? "";
|
||||
var lastSaved = report?.LastSaved;
|
||||
var reportInfo = new PDFReportInfo()
|
||||
{
|
||||
Title = reportTitle,
|
||||
UUID = uuid,
|
||||
LastSaved = lastSaved,
|
||||
BaseFolder = data.Key,
|
||||
};
|
||||
list.Add(reportInfo);
|
||||
}
|
||||
settings.AllReportInfo = list.OrderBy(x => x.Title).ToList();
|
||||
settings.WorkingFolderToInternalFolderName = []; // clear this list; it is no longer used
|
||||
settings.SettingsVersion = 2;
|
||||
// TODO: finish using new array for everything, make sure we save data, etc.
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static Settings LoadSettings()
|
||||
{
|
||||
var path = GetSettingsPath();
|
||||
@@ -144,7 +188,7 @@ class Settings : ChangeNotifier
|
||||
}
|
||||
var json = File.ReadAllText(GetSettingsPath());
|
||||
var jsonContext = new SourceGenerationContext(Utilities.GetSerializerOptions());
|
||||
return JsonSerializer.Deserialize<Settings>(json, jsonContext.Settings) ?? new Settings();
|
||||
return UpgradeSettings(JsonSerializer.Deserialize<Settings>(json, jsonContext.Settings) ?? new Settings());
|
||||
}
|
||||
|
||||
public static async Task<Settings> LoadSettingsAsync()
|
||||
@@ -152,6 +196,6 @@ class Settings : ChangeNotifier
|
||||
using FileStream fileStream = File.OpenRead(GetSettingsPath());
|
||||
var jsonContext = new SourceGenerationContext(Utilities.GetSerializerOptions());
|
||||
var output = await JsonSerializer.DeserializeAsync<Settings>(fileStream, jsonContext.Settings) ?? new Settings();
|
||||
return output;
|
||||
return UpgradeSettings(output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user