Skip to content

Commit

Permalink
Minor updates and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalsleuth committed Feb 9, 2024
1 parent 506de09 commit 52ea97e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 79 deletions.
Binary file modified WIN-FOR-Tool-List.pdf
Binary file not shown.
188 changes: 114 additions & 74 deletions WinFOR-Customizer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ public TextBoxOutputter(TextBox output)
public override void Write(char value)
{
base.Write(value);
textBox.Dispatcher.BeginInvoke(new Action(() =>
textBox.Dispatcher.BeginInvoke(new Action(async () =>
{
textBox.AppendText(value.ToString());
await Task.Delay(100);
textBox.Focus();
textBox.CaretIndex = textBox.Text.Length;
textBox.ScrollToEnd();
Expand Down Expand Up @@ -531,25 +532,14 @@ private static bool ExtractCustomTheme(string zipFile)
string themeFolder = Path.Join(themePath, themeName);
try
{
var identity = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
if (!Directory.Exists($"{themeFolder}"))
if (Directory.Exists($"{themeFolder}"))
{
Directory.CreateDirectory($"{themeFolder}");
DirectoryInfo destDirInfo = new(themeFolder);
destDirInfo.Attributes &= FileAttributes.ReadOnly;
DirectorySecurity destSecurityRules = new();
destSecurityRules.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
destDirInfo.SetAccessControl(destSecurityRules);
ManageDirectory(themeFolder, "delete");
ManageDirectory(themeFolder, "create");
}
else
{
Directory.Delete(themeFolder, true);
Directory.CreateDirectory($"{themeFolder}");
DirectoryInfo destDirInfo = new(themeFolder);
destDirInfo.Attributes &= FileAttributes.ReadOnly;
DirectorySecurity destSecurityRules = new();
destSecurityRules.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
destDirInfo.SetAccessControl(destSecurityRules);
ManageDirectory($"{themeFolder}", "create");
}
ConsoleOutput($"Extracting {zipFile} to {themeFolder}");
ZipFile.ExtractToDirectory(zipFile!, themeFolder, true);
Expand Down Expand Up @@ -731,6 +721,65 @@ private void FileExitClick(object sender, RoutedEventArgs e)
{
Close();
}
private static void ManageDirectory(string dirToManage, string dirOperation, string destDir = "")
{
var identity = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
try
{
if (dirOperation == "create")
{
Directory.CreateDirectory(dirToManage);
DirectoryInfo manageDirInfo = new(dirToManage);
manageDirInfo.Attributes &= ~FileAttributes.ReadOnly;
DirectorySecurity destSecurityRules = new();
destSecurityRules.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
manageDirInfo.SetAccessControl(destSecurityRules);
}
else if (dirOperation == "delete")
{
DirectoryInfo manageDirInfo = new(dirToManage);
manageDirInfo.Attributes &= ~FileAttributes.ReadOnly;
DirectorySecurity destSecurityRules = new();
destSecurityRules.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
manageDirInfo.SetAccessControl(destSecurityRules);
FileInfo[] fileNames = manageDirInfo.GetFiles("*", SearchOption.AllDirectories);
DirectoryInfo[] directoryNames = manageDirInfo.GetDirectories("*", SearchOption.AllDirectories);
foreach (DirectoryInfo directoryName in directoryNames)
{
directoryName.Attributes &= ~FileAttributes.ReadOnly;
}
foreach (FileInfo fileName in fileNames)
{
fileName.Attributes &= ~FileAttributes.ReadOnly;
fileName.Delete();
}
Directory.Delete(dirToManage, true);
}
else if (dirOperation == "perms")
{
DirectoryInfo manageDirInfo = new(dirToManage);
manageDirInfo.Attributes &= ~FileAttributes.ReadOnly;
DirectorySecurity destSecurityRules = new();
destSecurityRules.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
manageDirInfo.SetAccessControl(destSecurityRules);
}
else if (dirOperation == "move" && destDir != "")
{
DirectoryInfo manageDirInfo = new(dirToManage);
manageDirInfo.Attributes &= ~FileAttributes.ReadOnly;
DirectorySecurity destSecurityRules = new();
destSecurityRules.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
manageDirInfo.SetAccessControl(destSecurityRules);
Directory.Move(dirToManage, destDir);
}
}
catch (Exception ex)
{
ConsoleOutput($"[ERROR] Unable to manage directory {dirToManage}:\n{ex}");
return;
}

}
private async void InstallClick(object sender, RoutedEventArgs e)
// The main function for determining the status of all fields and initiating the installation of the Win-FOR environment
{
Expand Down Expand Up @@ -871,7 +920,14 @@ private async void InstallClick(object sender, RoutedEventArgs e)
string uriZip = currentReleaseData[1];
string uriHash = currentReleaseData[2];
ConsoleOutput($"{tempDir} is being created for temporary storage of required files");
CreateTempDirectory(tempDir);
if (!Directory.Exists(tempDir))
{
ManageDirectory(tempDir, "create");
}
else
{
ManageDirectory(tempDir, "perms");
}
if (!CheckGitInstalled(gitVersion))
{
ConsoleOutput($"Git {gitVersion} is not installed");
Expand Down Expand Up @@ -939,7 +995,11 @@ private async void InstallClick(object sender, RoutedEventArgs e)
return;
}
}

ConsoleOutput("Checking for and removing previous repo folder");
if (Directory.Exists(@"C:\ProgramData\Salt Project\Salt\srv\salt\win\"))
{
ManageDirectory(@"C:\ProgramData\Salt Project\Salt\srv\salt\win\", "delete");
}
string stateFile = GenerateState("install", isThemed);
statesExtracted = ExtractStates(tempDir, releaseVersion);
if (statesExtracted)
Expand Down Expand Up @@ -992,38 +1052,6 @@ private async void InstallClick(object sender, RoutedEventArgs e)
ConsoleOutput($"[ERROR] Unable to complete the installation process:\n{ex}");
}
}
public static void CreateTempDirectory(string tempDir)
// Creates a pre-defined temp directory to store required files
{
try
{
if (Directory.Exists(tempDir))
{
ConsoleOutput($"Directory {tempDir} already exists");
DirectoryInfo tempDirInfo = new(tempDir);
tempDirInfo.Attributes &= FileAttributes.ReadOnly;
DirectorySecurity tempDirSecurityRules = new();
var identity = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
tempDirSecurityRules.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
tempDirInfo.SetAccessControl(tempDirSecurityRules);
return;
}
else
{
DirectoryInfo tempDirInfo = Directory.CreateDirectory(tempDir);
tempDirInfo.Attributes &= FileAttributes.ReadOnly;
DirectorySecurity tempDirSecurityRules = new();
var identity = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
tempDirSecurityRules.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
tempDirInfo.SetAccessControl(tempDirSecurityRules);
}
}
catch (Exception ex)
{
ConsoleOutput($"[ERROR] Unable to create temp directory {tempDir}:\n{ex}");
return;
}
}
private static bool CheckSaltStackInstalled(string saltVersion)
// Checks if the pre-determined version of SaltStack is installed
{
Expand Down Expand Up @@ -1119,10 +1147,13 @@ private static async Task DownloadSaltStack(string tempDir, string saltVersion,
if (!Directory.Exists(tempDir))
{
ConsoleOutput($"{tempDir} does not exist. Creating...");
CreateTempDirectory(tempDir);
ManageDirectory(tempDir, "create");
ConsoleOutput($"{tempDir} created");
}

else
{
ManageDirectory(tempDir, "perms");
}
if (File.Exists($"{tempDir}{saltFile}"))
{
ConsoleOutput("Found previous download of SaltStack - comparing hash");
Expand Down Expand Up @@ -1202,9 +1233,13 @@ private static async Task DownloadGit(string tempDir, string gitVersion, string
if (!Directory.Exists(tempDir))
{
ConsoleOutput($"{tempDir} does not exist. Creating...");
CreateTempDirectory(tempDir);
ManageDirectory(tempDir, "create");
ConsoleOutput($"{tempDir} created");
}
else
{
ManageDirectory(tempDir, "perms");
}
if (File.Exists($"{tempDir}{gitFile}"))
{
ConsoleOutput("Found previous download of Git - comparing hash");
Expand Down Expand Up @@ -1308,7 +1343,11 @@ private static async Task<bool> DownloadStates(string tempDir, string currentRel
if (!Directory.Exists(tempDir))
{
ConsoleOutput($"Temp directory {tempDir} does not exist, creating...");
CreateTempDirectory(tempDir);
ManageDirectory(tempDir, "create");
}
else
{
ManageDirectory(tempDir, "perms");
}
ConsoleOutput($"Downloading {uriZip}");
bool zipStatus = await FileDownload(uriZip, @$"{tempDir}\{currentRelease}.zip");
Expand Down Expand Up @@ -1387,8 +1426,8 @@ private static bool ExtractStates(string tempDir, string release)
string saltPath = @"C:\ProgramData\Salt Project\Salt\";
if (!Directory.Exists($"{saltPath}srv"))
{
Directory.CreateDirectory($"{saltPath}srv");
Directory.CreateDirectory($@"{saltPath}srv\salt\");
ManageDirectory($"{saltPath}srv", "create");
ManageDirectory($@"{saltPath}srv\salt\", "create");
saltPath = $@"{saltPath}srv\salt\";
}
else
Expand All @@ -1401,22 +1440,11 @@ private static bool ExtractStates(string tempDir, string release)
ConsoleOutput($"Extracting {file} to {tempDir}");
ZipFile.ExtractToDirectory(file, tempDir, true);
ConsoleOutput($"Moving {distroFolder} folder to {distroDest}");
var identity = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
if (Directory.Exists(distroDest))
{
DirectoryInfo destDirInfo = new(distroDest);
destDirInfo.Attributes &= FileAttributes.ReadOnly;
DirectorySecurity destSecurityRules = new();
destSecurityRules.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
destDirInfo.SetAccessControl(destSecurityRules);
Directory.Delete(distroDest, true);
}
DirectoryInfo distroDirInfo = new(distroFolder);
distroDirInfo.Attributes &= FileAttributes.ReadOnly;
DirectorySecurity distroSecurityRules = new();
distroSecurityRules.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
distroDirInfo.SetAccessControl(distroSecurityRules);
Directory.Move(distroFolder, distroDest);
ManageDirectory(distroDest, "delete");
}
ManageDirectory(distroFolder, "move", distroDest);
extracted = true;
}
catch (Exception ex)
Expand Down Expand Up @@ -1548,8 +1576,14 @@ private async void DownloadOnly(object? sender, RoutedEventArgs e)
downloadPath = DownloadsPath.Text;
}
ConsoleOutput($"{tempDir} is being created for temporary storage of required files");
CreateTempDirectory(tempDir);

if (!Directory.Exists(tempDir))
{
ManageDirectory(tempDir, "create");
}
else
{
ManageDirectory(tempDir, "perms");
}
if (!CheckGitInstalled(gitVersion))
{
ConsoleOutput($"Git {gitVersion} is not installed");
Expand Down Expand Up @@ -1976,8 +2010,14 @@ private async void InstallWslOnly(object sender, RoutedEventArgs e)
string? saltVersion = softwareConfig[0].Software!["saltstack"].SoftwareVersion!;
string? saltHash = softwareConfig[0].Software!["saltstack"].SoftwareHash!;
ConsoleOutput($"{tempDir} is being created for temporary storage of required files");
CreateTempDirectory(tempDir);

if (!Directory.Exists(tempDir))
{
ManageDirectory(tempDir, "create");
}
else
{
ManageDirectory(tempDir, "perms");
}
if (!CheckGitInstalled(gitVersion))
{
ConsoleOutput($"Git is being downloaded.");
Expand Down
2 changes: 1 addition & 1 deletion WinFOR-Customizer/Win-FOR Customizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/digitalsleuth/win-for</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<ApplicationIcon>img\fp.ico</ApplicationIcon>
<Version>9.1.0</Version>
<Version>9.2.0</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Authors>Corey Forman (digitalsleuth)</Authors>
Expand Down
8 changes: 4 additions & 4 deletions layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@
"Passware Encryption Analyzer": {
"CbName": "packages_passware_encryption_analyzer",
"CbContent": "Passware Encryption Analyzer",
"DAID": "{6D809377-6AF0-444B-8957-A3773F02200E}\\Passware\\Encryption Analyzer 2023\\PasswareEncryptionAnalyzer.exe",
"DAID": "{6D809377-6AF0-444B-8957-A3773F02200E}\\Passware\\Encryption Analyzer 2024\\PasswareEncryptionAnalyzer.exe",
"AUMID": false,
"DALP": false,
"StartMenu": true,
Expand Down Expand Up @@ -2326,7 +2326,7 @@
"DAID": "",
"AUMID": false,
"DALP": false,
"StartMenu": true,
"StartMenu": false,
"Checked": true,
"Enabled": true,
"ExtraTiles": []
Expand Down Expand Up @@ -2557,7 +2557,7 @@
"DAID": "",
"AUMID": false,
"DALP": false,
"StartMenu": true,
"StartMenu": false,
"Checked": true,
"Enabled": true,
"ExtraTiles": []
Expand Down Expand Up @@ -2685,7 +2685,7 @@
"DAID": "",
"AUMID": false,
"DALP": false,
"StartMenu": true,
"StartMenu": false,
"Checked": true,
"Enabled": true,
"ExtraTiles": []
Expand Down

0 comments on commit 52ea97e

Please sign in to comment.