Start work on copy files to internal
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user