-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete files while respecting dry-run, verbosity
- Loading branch information
Showing
7 changed files
with
252 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,3 +260,4 @@ paket-files/ | |
__pycache__/ | ||
*.pyc | ||
/build/ | ||
launchSettings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace MsiZapEx | ||
{ | ||
class FileSystemModifier : IDisposable | ||
{ | ||
private List<string> _deleteFolders = new List<string>(); | ||
private List<string> _deleteFiles = new List<string>(); | ||
|
||
public void Dispose() | ||
{ | ||
foreach (string folder in _deleteFolders) | ||
{ | ||
DeleteFolder(folder); | ||
} | ||
_deleteFolders.Clear(); | ||
foreach (string file in _deleteFiles) | ||
{ | ||
DeleteFile(file); | ||
} | ||
_deleteFiles.Clear(); | ||
} | ||
|
||
private void DeleteFile(string path) | ||
{ | ||
if (!File.Exists(path)) | ||
{ | ||
return; | ||
} | ||
|
||
if ((Settings.Instance?.DryRun == true) || (Settings.Instance?.Verbose == true)) | ||
{ | ||
Console.WriteLine($"Delete file '{path}'"); | ||
if (Settings.Instance?.DryRun == true) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
File.SetAttributes(path, FileAttributes.Normal); | ||
File.Delete(path); | ||
} | ||
|
||
private void DeleteFolder(string path) | ||
{ | ||
if (!Directory.Exists(path)) | ||
{ | ||
return; | ||
} | ||
|
||
if ((Settings.Instance?.DryRun == true) || (Settings.Instance?.Verbose == true)) | ||
{ | ||
Console.WriteLine($"Delete folder '{path}'"); | ||
if (Settings.Instance?.DryRun == true) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
IEnumerable<string> files = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories); | ||
foreach (string file in files) | ||
{ | ||
DeleteFile(file); | ||
} | ||
Directory.Delete(path, true); | ||
} | ||
|
||
public void DeferDeleteFile(string path) | ||
{ | ||
_deleteFiles.Add(path); | ||
} | ||
|
||
public void DeferDeleteFolder(string path) | ||
{ | ||
_deleteFolders.Add(path); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.