From 27b08fa8d3306f153f19f04705f7a4b6114a4319 Mon Sep 17 00:00:00 2001 From: Eduardo Assis Date: Tue, 12 Dec 2023 02:00:55 -0300 Subject: [PATCH] Add validation before file deletion --- GodotEnv/src/features/godot/domain/GodotRepository.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/GodotEnv/src/features/godot/domain/GodotRepository.cs b/GodotEnv/src/features/godot/domain/GodotRepository.cs index 9acf721..428a312 100644 --- a/GodotEnv/src/features/godot/domain/GodotRepository.cs +++ b/GodotEnv/src/features/godot/domain/GodotRepository.cs @@ -456,13 +456,17 @@ [Desktop Entry] case OSType.Windows: { var hardLinkPath = $"{GodotSymlinkPath}.exe"; - await FileClient.DeleteFile(hardLinkPath); + var commonStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); + var applicationsPath = FileClient.Combine(commonStartMenuPath, "Programs", "Godot.lnk"); + + if (FileClient.FileExists(hardLinkPath)) { + await FileClient.DeleteFile(hardLinkPath); + } + await FileClient.ProcessRunner.RunElevatedOnWindows( "cmd.exe", $"/c mklink /H \"{hardLinkPath}\" \"{installation.ExecutionPath}\"" ); - var commonStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); - var applicationsPath = FileClient.Combine(commonStartMenuPath, "Programs", "Godot.lnk"); var command = string.Join(";", "$ws = New-Object -ComObject (\"WScript.Shell\")", $"$s = $ws.CreateShortcut(\"{applicationsPath}\")",