private void MakeEmailableReportFile()
{
var filename = ("Report " + DateTime.UtcNow.ToString("u") + ".zip").Replace(':', '.');
filename = filename.SanitizeFilename('#');
var zipFile = TempFile.WithFilename(filename);
_emailableReportFilePath = zipFile.Path;
var zip = new BloomZipFile(_emailableReportFilePath);
using (var file = TempFile.WithFilenameInTempFolder("report.txt"))
{
using (var stream = RobustFile.CreateText(file.Path))
{
stream.WriteLine(GetFullDescriptionContents(false));
if (_includeBook.Visible && _includeBook.Checked) // only Visible if Book is not null
{
stream.WriteLine();
stream.WriteLine(
"REMEMBER: if the attached zip file appears empty, it may have non-ascii in the file names. Open with 7zip and you should see it.");
}
}
zip.AddTopLevelFile(file.Path);
if (_includeBook.Visible && _includeBook.Checked) // only Visible if Book is not null
{
zip.AddDirectory(Book.FolderPath);
}
}
if (_includeScreenshot.Checked)
{
using (var file = TempFile.WithFilenameInTempFolder("screenshot.png"))
{
SIL.IO.RobustIO.SaveImage(_screenshot, file.Path, ImageFormat.Png);
zip.AddTopLevelFile(file.Path);
}
}
if (Logger.Singleton != null)
{
try
{
using (var logFile = GetLogFile())
{
zip.AddTopLevelFile(logFile.Path);
}
}
catch (Exception)
{
// just ignore
}
}
zip.Save();
}