mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 04:23:09 +00:00
Updater Fix/Improvements (#606)
* Updater Fix/Improvements In SetAccessRule(): A call to the Directory.SetAccessControl method was added to apply the changes made to the DirectorySecurity object. Additionally, the function does not handle possible exceptions that may occur during code execution. This version of the function attempts to set the access rule for the specified directory and, if an error occurs during the process, prints an error message on the screen. This helps to identify and fix possible problems that may occur during code execution. In Install(): The function checks if the destination directory exists before attempting to delete it. Additionally, a destDir variable was created to store the path of the 'destination directory' and a destFile variable to store the path of the 'destination file'. This makes the code a little more readable. In Application_Idle(): A MessageBox.Show was included to display a dialog box with the message "Updates are available. Do you want to update now?" and two buttons: "Yes" and "No". If the user clicks on the "Yes" button, the UpdateNotifcationClick method is called to start the update process. Otherwise, the dialog box is closed and no action is taken. The dialog box will only be shown once for each available update, as the UsePrompt variable is set to false after the dialog box is shown for the first time. when trying to update, updater.exe crashed and presented the following error, as shown in the print below: unhandled exception: Unable to create a file that already exists. * Updater Fix/Improvements
This commit is contained in:
parent
68916159c8
commit
0d33f4ead1
2 changed files with 33 additions and 11 deletions
|
@ -188,9 +188,18 @@ namespace Toolbox
|
|||
UpdateProgram.CommitList.Count > 0)
|
||||
{
|
||||
updateToolstrip.Enabled = true;
|
||||
UsePrompt = false;
|
||||
|
||||
// Shows an on-screen message that updates are available
|
||||
DialogResult result = MessageBox.Show("Updates are available. Do you want to update now?", "Update Available", MessageBoxButtons.YesNo);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
UpdateNotifcationClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void UpdateNotifcationClick()
|
||||
{
|
||||
if (UpdateProgram.CommitList.Count <= 0)
|
||||
|
|
|
@ -89,14 +89,18 @@ namespace Updater
|
|||
SetAccessRule(dir);
|
||||
|
||||
string dirName = new DirectoryInfo(dir).Name;
|
||||
string destDir = Path.Combine(folderDir, dirName + @"\");
|
||||
|
||||
if (!dirName.Equals("Hashes", StringComparison.CurrentCultureIgnoreCase) // Let's keep the users custom hashes in tact
|
||||
&& Directory.Exists(Path.Combine(folderDir, dirName + @"\")))
|
||||
&& Directory.Exists(destDir))
|
||||
{
|
||||
Directory.Delete(Path.Combine(folderDir, dirName + @"\"), true);
|
||||
Directory.Delete(destDir, true);
|
||||
}
|
||||
|
||||
Directory.Move(dir, Path.Combine(folderDir, dirName + @"\"));
|
||||
if (Directory.Exists(destDir))
|
||||
Directory.Delete(destDir, true);
|
||||
|
||||
Directory.Move(dir, destDir);
|
||||
}
|
||||
foreach (string file in Directory.GetFiles("master/"))
|
||||
{
|
||||
|
@ -107,21 +111,30 @@ namespace Updater
|
|||
SetAccessRule(file);
|
||||
SetAccessRule(folderDir);
|
||||
|
||||
if (File.Exists(Path.Combine(folderDir, Path.GetFileName(file))))
|
||||
{
|
||||
File.Delete(Path.Combine(folderDir, Path.GetFileName(file)));
|
||||
}
|
||||
File.Move(file, Path.Combine(folderDir, Path.GetFileName(file)));
|
||||
string destFile = Path.Combine(folderDir, Path.GetFileName(file));
|
||||
if (File.Exists(destFile))
|
||||
File.Delete(destFile);
|
||||
|
||||
File.Move(file, destFile);
|
||||
}
|
||||
}
|
||||
|
||||
static void SetAccessRule(string directory)
|
||||
{
|
||||
System.Security.AccessControl.DirectorySecurity sec = System.IO.Directory.GetAccessControl(directory);
|
||||
FileSystemAccessRule accRule = new FileSystemAccessRule(Environment.UserDomainName + "\\" + Environment.UserName, FileSystemRights.FullControl, AccessControlType.Allow);
|
||||
sec.AddAccessRule(accRule);
|
||||
try
|
||||
{
|
||||
System.Security.AccessControl.DirectorySecurity sec = System.IO.Directory.GetAccessControl(directory);
|
||||
FileSystemAccessRule accRule = new FileSystemAccessRule(Environment.UserDomainName + "\\" + Environment.UserName, FileSystemRights.FullControl, AccessControlType.Allow);
|
||||
sec.AddAccessRule(accRule);
|
||||
Directory.SetAccessControl(directory, sec);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Failed to set access rule for directory '{directory}': {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void Download(string CompileDate)
|
||||
{
|
||||
foreach (Release latest in releases)
|
||||
|
|
Loading…
Reference in a new issue