Skip to content

Commit

Permalink
fix #26 , added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
siblount committed Jan 17, 2024
1 parent 3b60ce2 commit ec31a3e
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions src/DAZ_Installer.Windows/Forms/ProductRecordForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
using System.Linq;
using System.Windows.Forms;
using DAZ_Installer.IO;
using Serilog;

namespace DAZ_Installer.Windows.Forms
{
public partial class ProductRecordForm : Form
{
private ILogger logger = Log.Logger.ForContext<ProductRecordForm>();
private DPProductRecord record;
private DPExtractionRecord extractionRecord;
private uint[] maxFontWidthPerListView = new uint[5];
Expand Down Expand Up @@ -278,7 +280,7 @@ private void deleteProductToolStripMenuItem_Click(object sender, EventArgs e)
"Root content folder doesn't exist", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (r == DialogResult.No) return;
}
deletedFiles = DeleteFiles(extractionRecord.DestinationPath);
deletedFiles = DeleteFiles();
if (deletedFiles == 0)
{
// Quick test.
Expand All @@ -291,12 +293,6 @@ private void deleteProductToolStripMenuItem_Click(object sender, EventArgs e)
"Root content folder doesn't exist", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (r == DialogResult.No) return;
}

foreach (var contentFolder in DPSettings.CurrentSettingsObject.detectedDazContentPaths)
{
deletedFiles = DeleteFiles(contentFolder);
if (deletedFiles > 0) break;
}
}

var delta = extractionRecord.Files.Length - deletedFiles;
Expand All @@ -306,24 +302,18 @@ private void deleteProductToolStripMenuItem_Click(object sender, EventArgs e)
MessageBox.Show($"Some product files failed to be removed.",
"Some files failed to be removed", MessageBoxButtons.OK, MessageBoxIcon.Information);
else Program.Database.RemoveProductRecord(record);
Program.Database.RemoveProductRecord(record, OnProductRecordRemoval);
}

private uint DeleteFiles(string destinationPath)
private uint DeleteFiles()
{
var fs = new DPFileSystem(new DPFileScopeSettings(Array.Empty<string>(), new[] { extractionRecord.DestinationPath }, false));
uint deleteCount = 0;
foreach (var file in extractionRecord.Files)
{
var deletePath = Path.Combine(extractionRecord.DestinationPath, file);
var info = new FileInfo(deletePath);
try
{
info.Delete();
deleteCount++;
}
catch (Exception ex)
{
// DPCommon.WriteToLog($"Failed to remove product file for {record.ProductName}, file: {file}. REASON: {ex}");
}
fs.CreateFileInfo(Path.Combine(extractionRecord.DestinationPath, file)).TryAndFixDelete(out var ex);
if (ex != null) logger.Error(ex, "Failed to remove product file {file} for {record}", file, record.ProductName);
else deleteCount++;
}
return deleteCount;
}
Expand Down

0 comments on commit ec31a3e

Please sign in to comment.