diff --git a/TODO.txt b/TODO.txt index c756bd6..9eaa4c3 100644 --- a/TODO.txt +++ b/TODO.txt @@ -14,8 +14,14 @@ -output in internal dir (default) -always ask me every time (opens save file picker after generating PDF to ask user where they want it) -always put in X folder (uses existing option) --add option to backup added files to internal data directory (always on for iOS) --make backup of last generated PDF somewhere +~-add option to backup added files to internal data directory (always on for iOS) + *-add option + -add to settings view + -add logic to CreatePDFReportViewModel + -programmed in but not tested yet +-make backup of last generated PDF somewhere (another internal folder, most likely); + -save to PDF report data somewhere for safe-keeping + -allow loading by user -iOS-specific (MAUI essentials?) -maui community essentials https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/get-started?tabs=CommunityToolkitMaui -I don't think this is what we are looking for ultimately....? @@ -31,6 +37,8 @@ -https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/data/share?view=net-maui-10.0&tabs=macios -Make sure clipboard works (not sure if it will out of the box or not) -https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/data/clipboard?view=net-maui-10.0 + -show report file size in recent list + -make sure setting for backup files is not available (always backs up files on iOS) ----------- diff --git a/src/MayShow.Shared/Models/Settings.cs b/src/MayShow.Shared/Models/Settings.cs index c2c9909..16647c5 100644 --- a/src/MayShow.Shared/Models/Settings.cs +++ b/src/MayShow.Shared/Models/Settings.cs @@ -24,6 +24,7 @@ class Settings : ChangeNotifier public string _reportDateFormat; public int _settingsVersion; private PDFSaveLocation _pdfOutputSaveLocation; + public bool _copyFilesToInternalDir; public Settings() : base() { @@ -38,6 +39,10 @@ class Settings : ChangeNotifier _dataGridDateFormat = "dd/MM/yyyy"; _reportDateFormat = "yyyy-MM-dd"; _pdfOutputSaveLocation = PDFSaveLocation.BaseFolder; + _copyFilesToInternalDir = false; + #if IOS + _copyFilesToInternalDir = true; + #endif } public Settings(Settings other) @@ -53,6 +58,7 @@ class Settings : ChangeNotifier _dataGridDateFormat = other.DataGridDateFormat; _reportDateFormat = other.ReportDateFormat; _pdfOutputSaveLocation = other.PDFOutputSaveLocation; + _copyFilesToInternalDir = other.CopyFilesToInternalDir; } [JsonInclude] @@ -133,6 +139,13 @@ class Settings : ChangeNotifier set { _reportDateFormat = value; NotifyPropertyChanged(); } } + [JsonInclude] + public bool CopyFilesToInternalDir + { + get => _copyFilesToInternalDir; + set { _copyFilesToInternalDir = value; NotifyPropertyChanged(); } + } + public static string SettingsFileName = "settings.json"; public static string GetSettingsPath() diff --git a/src/MayShow.Shared/ViewModels/CreatePDFReportViewModel.cs b/src/MayShow.Shared/ViewModels/CreatePDFReportViewModel.cs index 795374d..9410c6e 100644 --- a/src/MayShow.Shared/ViewModels/CreatePDFReportViewModel.cs +++ b/src/MayShow.Shared/ViewModels/CreatePDFReportViewModel.cs @@ -344,6 +344,24 @@ class CreatePDFReportViewModel : BaseViewModel, ICanCheckShutdown, ILogger else { var date = Utilities.CheckValidDateInString(filePath); + if (_settings.CopyFilesToInternalDir) + { + // copy file to internal folder, then add report file based on that path + // make sure file names are not conflicting with one another, too. + var fileName = Path.GetFileName(filePath); + var fileNameNoExt = Path.GetFileNameWithoutExtension(filePath); + var extension = Path.GetExtension(filePath); + var copyToPath = Path.Combine(_pdfReport.BaseFolder, fileName); + var rnd = new Random(); + // TODO: test to make sure this works + while (File.Exists(copyToPath)) + { + fileName = fileNameNoExt + rnd.Next(1, 999999) + "." + extension; + copyToPath = Path.Combine(_pdfReport.BaseFolder, fileName); + } + File.Copy(filePath, copyToPath); + filePath = copyToPath; + } ReportFiles.Add(new ReportFile() { Title = Path.GetFileName(filePath),