Rearrange files to shared project

This commit is contained in:
2026-03-04 21:09:54 +09:00
parent 182055d19e
commit 385f794b03
61 changed files with 68 additions and 45 deletions
+58
View File
@@ -0,0 +1,58 @@
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;
namespace MayShow.Models;
class PDFReport : ChangeNotifier
{
private string _baseFolder;
private string _title;
private List<ReportFile> _files;
private DateTime _lastSaved;
private DateTime? _lastGenerated;
public PDFReport()
{
_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;
set { _lastGenerated = value; NotifyPropertyChanged(); }
}
}
+83
View File
@@ -0,0 +1,83 @@
using System;
using System.IO;
using System.Text.Json.Serialization;
using MayShow.Helpers;
namespace MayShow.Models;
class ReportFile : ChangeNotifier
{
private string _title;
private DateTime _receiptDateTime;
private string _notes;
private string _filePath;
public ReportFile()
{
_title = "";
_receiptDateTime = DateTime.Now;
_notes = "";
_filePath = "";
}
public ReportFile(ReportFile other)
{
Title = _title = other.Title;
ReceiptDateTime = _receiptDateTime = other.ReceiptDateTime;
Notes = _notes = other.Notes;
FilePath = _filePath = other.FilePath;
}
public string Title
{
get => _title;
set { _title = value; NotifyPropertyChanged(); }
}
public DateTime ReceiptDateTime
{
get => _receiptDateTime;
set
{
_receiptDateTime = value;
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(ReceiptDate));
}
}
[JsonIgnore]
public DateOnly ReceiptDate
{
get => DateOnly.FromDateTime(_receiptDateTime);
}
public string Notes
{
get => _notes;
set { _notes = value; NotifyPropertyChanged(); }
}
public string FilePath
{
get => _filePath;
set
{
_filePath = value;
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(FileName));
NotifyPropertyChanged(nameof(IsFileFoundOnDisk));
}
}
[JsonIgnore]
public string FileName
{
get => Path.GetFileName(_filePath);
}
[JsonIgnore]
public bool IsFileFoundOnDisk
{
get => File.Exists(FilePath);
}
}
+157
View File
@@ -0,0 +1,157 @@
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 Settings : ChangeNotifier
{
private string _lastUsedPath;
private bool _useDocnetPDFImageRendering;
private bool _saveOutputPdfInWorkingDir;
private string _outputPdfDir;
private decimal _imageResizeThreshold;
private bool _saveReportJsonDataInInternalDir;
private Dictionary<string, string> _workingFolderToInternalFolderName;
public int _settingsVersion;
public Settings()
{
_lastUsedPath = "";
_useDocnetPDFImageRendering = true;
_saveOutputPdfInWorkingDir = true;
_outputPdfDir = "";
_imageResizeThreshold = 1.5m;
_saveReportJsonDataInInternalDir = false;
_workingFolderToInternalFolderName = [];
_settingsVersion = 1;
}
public Settings(Settings other)
{
_lastUsedPath = other.LastUsedPath;
_useDocnetPDFImageRendering = other.UseDocnetPDFImageRendering;
_saveOutputPdfInWorkingDir = other.SaveOutputPdfInWorkingDir;
_outputPdfDir = other.OutputPdfDir;
_imageResizeThreshold = other.ImageResizeThreshold;
_saveReportJsonDataInInternalDir = other.SaveReportJsonDataInInternalDir;
_workingFolderToInternalFolderName = other.WorkingFolderToInternalFolderName;
_settingsVersion = other.SettingsVersion;
}
[JsonInclude]
public string LastUsedPath
{
get => _lastUsedPath;
set { _lastUsedPath = value; NotifyPropertyChanged(); }
}
[JsonInclude]
[JsonPropertyName("UseDocnetPFDImageRendering")] // ...this typo now has to live because people have this saved on disk...
public bool UseDocnetPDFImageRendering
{
get => _useDocnetPDFImageRendering;
set { _useDocnetPDFImageRendering = value; NotifyPropertyChanged(); }
}
[JsonInclude]
public bool SaveOutputPdfInWorkingDir
{
get => _saveOutputPdfInWorkingDir;
set { _saveOutputPdfInWorkingDir = value; NotifyPropertyChanged(); }
}
[JsonInclude]
public string OutputPdfDir
{
get => _outputPdfDir;
set { _outputPdfDir = value; NotifyPropertyChanged(); }
}
[JsonInclude]
public decimal ImageResizeThreshold
{
get => _imageResizeThreshold;
set { _imageResizeThreshold = value; NotifyPropertyChanged(); }
}
[JsonInclude]
public bool SaveReportJsonDataInInternalDir
{
get => _saveReportJsonDataInInternalDir;
set { _saveReportJsonDataInInternalDir = value; NotifyPropertyChanged(); }
}
[JsonInclude]
public Dictionary<string, string> WorkingFolderToInternalFolderName
{
get => _workingFolderToInternalFolderName;
set { _workingFolderToInternalFolderName = value; NotifyPropertyChanged(); }
}
[JsonInclude]
public int SettingsVersion
{
get => _settingsVersion;
set { _settingsVersion = value; NotifyPropertyChanged(); }
}
public static string SettingsFileName = "settings.json";
public static string GetSettingsPath()
{
var path = Utilities.GetInternalDataPath();
return Path.Combine(path, SettingsFileName);
}
public string SaveSettingsNotAsync()
{
var jsonContext = new SourceGenerationContext(Utilities.GetSerializerOptions());
using MemoryStream memoryStream = new MemoryStream();
JsonSerializer.Serialize(memoryStream, this, jsonContext.Settings);
memoryStream.Position = 0;
using var reader = new StreamReader(memoryStream);
var json = reader.ReadToEnd();
File.WriteAllText(GetSettingsPath(), json);
return json;
}
public async Task<string> SaveSettingsAsync()
{
var jsonContext = new SourceGenerationContext(Utilities.GetSerializerOptions());
using MemoryStream memoryStream = new MemoryStream();
await JsonSerializer.SerializeAsync(memoryStream, this, jsonContext.Settings);
memoryStream.Position = 0;
using var reader = new StreamReader(memoryStream);
var json = await reader.ReadToEndAsync();
await File.WriteAllTextAsync(GetSettingsPath(), json);
return json;
}
public static Settings LoadSettings()
{
var path = GetSettingsPath();
if (!File.Exists(path))
{
return new Settings();
}
var json = File.ReadAllText(GetSettingsPath());
var jsonContext = new SourceGenerationContext(Utilities.GetSerializerOptions());
return JsonSerializer.Deserialize<Settings>(json, jsonContext.Settings) ?? new Settings();
}
public static async Task<Settings> LoadSettingsAsync()
{
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;
}
}
@@ -0,0 +1,8 @@
namespace MayShow.Models;
enum ShutdownCheckOptions
{
SaveAndShutdown,
NoSaveShutdown,
CancelShutdown,
}