From d8c05b90ae3d7450ca45cbe0ac47649b2659daba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ayta=C3=A7=20Kayadelen?= Date: Fri, 22 Mar 2024 21:54:27 +0100 Subject: [PATCH] fix ExeMover script permissions --- Project-Aurora/ExeMover/ExeMover.csproj | 1 - Project-Aurora/ExeMover/Program.cs | 118 +++++++++++++++--------- 2 files changed, 73 insertions(+), 46 deletions(-) diff --git a/Project-Aurora/ExeMover/ExeMover.csproj b/Project-Aurora/ExeMover/ExeMover.csproj index c1404d57f..f089219a5 100644 --- a/Project-Aurora/ExeMover/ExeMover.csproj +++ b/Project-Aurora/ExeMover/ExeMover.csproj @@ -11,7 +11,6 @@ app.manifest true true - true false false diff --git a/Project-Aurora/ExeMover/Program.cs b/Project-Aurora/ExeMover/Program.cs index a910ceb24..25c051cd9 100644 --- a/Project-Aurora/ExeMover/Program.cs +++ b/Project-Aurora/ExeMover/Program.cs @@ -12,8 +12,17 @@ var userStartup = new StringBuilder(260); SHGetSpecialFolderPath(IntPtr.Zero, userStartup, csidlStartmenu, false); -var globalStartPath = Path.Combine(globalStartup.ToString(), "Programs"); -var userStartPath = Path.Combine(userStartup.ToString(), "Programs"); +string[] startPaths = +[ + Path.Combine(globalStartup.ToString(), "Programs"), + Path.Combine(userStartup.ToString(), "Programs") +]; + +string[] shortcutNames = ["Aurora.lnk", "Aurora - Shortcut.lnk", "Aurora.exe - Shortcut.lnk"]; + +var auroraShortcutPaths = (from startPath in startPaths + from shortcutName in shortcutNames + select Path.Combine(startPath, shortcutName)).ToList(); var currentPath = Path.GetDirectoryName(Environment.ProcessPath); if (currentPath == null) @@ -22,54 +31,73 @@ return; } -var script = """ - param ( - [Parameter(Mandatory = $true)] - [string]$TargetPath, - - [Parameter(Mandatory = $true)] - [string[]]$LnkFiles - ) - - foreach ($lnkFile in $LnkFiles) { - # Create a Shell object - $shell = New-Object -ComObject WScript.Shell - - # Check if the file exists - if (Test-Path $lnkFile) { - # Get the shortcut object - $shortcut = $shell.CreateShortcut($lnkFile) - - # Change the target path - $shortcut.TargetPath = $TargetPath - - # Save the changes - $shortcut.Save() - - Write-Output "Changed target for $($lnkFile) to $TargetPath" - } else { - Write-Output "File $($lnkFile) does not exist." - } - } - - Write-Output "All .lnk files have been updated to target $TargetPath" - """; +const string script = """ + param ( + [Parameter(Mandatory = $true)] + [string]$TargetPath, + + [Parameter(Mandatory = $true)] + [string[]]$LnkFiles + ) + + Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted + + foreach ($lnkFile in $LnkFiles) { + # Create a Shell object + $shell = New-Object -ComObject WScript.Shell + + # Check if the file exists + if (Test-Path $lnkFile) { + # Get the shortcut object + $shortcut = $shell.CreateShortcut($lnkFile) + + # Change the target path + $shortcut.TargetPath = $TargetPath + + # Save the changes + $shortcut.Save() + + Write-Output "Changed target for $($lnkFile) to $TargetPath" + } else { + Write-Output "File $($lnkFile) does not exist." + } + } + + Write-Output "All .lnk files have been updated to target $TargetPath" + """; var newPath = Path.Combine(currentPath, "AuroraRgb.exe"); -string[] auroraShortcutPaths = -[ - Path.Combine(globalStartPath, "Aurora.lnk"), - Path.Combine(userStartPath, "Aurora.lnk"), - Path.Combine(userStartPath, "Aurora - Shortcut.lnk"), - Path.Combine(userStartPath, "Aurora.exe - Shortcut.lnk"), -]; -var lnkFiles = string.Join(", ", auroraShortcutPaths.Select(s => '"' + s + '"')); var powershell = PowerShell.Create().AddScript(script); -powershell.AddParameter("TargetPath", newPath); -powershell.AddParameter("LnkFiles", lnkFiles); -powershell.Invoke(); +powershell.Streams.Verbose.DataAdded += (_, eventArgs) => +{ + Console.WriteLine(powershell.Streams.Verbose[eventArgs.Index]); +}; +powershell.Streams.Debug.DataAdded += (_, eventArgs) => +{ + Console.WriteLine(powershell.Streams.Debug[eventArgs.Index]); +}; +powershell.Streams.Information.DataAdded += (_, eventArgs) => +{ + Console.WriteLine(powershell.Streams.Information[eventArgs.Index]); +}; +powershell.Streams.Warning.DataAdded += (_, eventArgs) => +{ + Console.Error.WriteLine(powershell.Streams.Warning[eventArgs.Index]); +}; +powershell.Streams.Error.DataAdded += (_, eventArgs) => +{ + Console.Error.WriteLine(powershell.Streams.Error[eventArgs.Index]); +}; + +powershell.AddParameter("TargetPath", newPath); +powershell.AddParameter("LnkFiles", auroraShortcutPaths); +var psObjects = powershell.Invoke(); +foreach (var psObject in psObjects) +{ + Console.WriteLine(psObject); +} Process.Start("AuroraRgb.exe"); return;