From 19b933b6196f7c6b2766108fc53e40053c366143 Mon Sep 17 00:00:00 2001 From: vesk4000 Date: Fri, 18 Mar 2022 15:39:33 +0200 Subject: [PATCH] Fixed the launcher so that it can now delete itself as well as Wordler --- Source/CLI/Commands/SolveCommand.cs | 1 + Wordler Launcher/.vscode/launch.json | 26 ++++++++++++++++++ Wordler Launcher/.vscode/tasks.json | 41 ++++++++++++++++++++++++++++ Wordler Launcher/Program.cs | 6 ++-- launcher_args.txt | 1 + run.ps1 | 20 +++++++------- 6 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 Wordler Launcher/.vscode/launch.json create mode 100644 Wordler Launcher/.vscode/tasks.json create mode 100644 launcher_args.txt diff --git a/Source/CLI/Commands/SolveCommand.cs b/Source/CLI/Commands/SolveCommand.cs index c11f6e6..a684c78 100644 --- a/Source/CLI/Commands/SolveCommand.cs +++ b/Source/CLI/Commands/SolveCommand.cs @@ -40,6 +40,7 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Settings if(settings.PowerShellCommands != "") { var psc = new ProcessStartInfo("powershell.exe", " -Command { " + settings.PowerShellCommands.Replace("@ID", Process.GetCurrentProcess().Id.ToString() + " }")); + psc.WorkingDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).FullName; Process.Start(psc); } diff --git a/Wordler Launcher/.vscode/launch.json b/Wordler Launcher/.vscode/launch.json new file mode 100644 index 0000000..9026ea9 --- /dev/null +++ b/Wordler Launcher/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net5.0/Wordler Launcher.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/Wordler Launcher/.vscode/tasks.json b/Wordler Launcher/.vscode/tasks.json new file mode 100644 index 0000000..7413f63 --- /dev/null +++ b/Wordler Launcher/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/Wordler Launcher.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/Wordler Launcher.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/Wordler Launcher.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Wordler Launcher/Program.cs b/Wordler Launcher/Program.cs index e4ecbd7..0f3c22b 100644 --- a/Wordler Launcher/Program.cs +++ b/Wordler Launcher/Program.cs @@ -9,10 +9,12 @@ class Program static void Main(string[] args) { Process wordler = new Process(); - wordler.StartInfo.FileName = Directory.GetCurrentDirectory() + "\\Wordler.exe"; + wordler.StartInfo.FileName = Directory.GetCurrentDirectory() + "\\Wordler\\Wordler.exe"; wordler.StartInfo.UseShellExecute = false; wordler.StartInfo.CreateNoWindow = true; - wordler.StartInfo.Arguments = "--tl 15 --ps \" Wait-Process -Id @ID; $directorypath = (Get-Item .).FullName; $path = $directorypath + '\\Wordlerer\\';If (!(test-path $path)) { mkdir $path }; Remove-Item $directorypath; \""; + wordler.StartInfo.Arguments = File.ReadAllText(Directory.GetCurrentDirectory() + "\\Wordler\\launcher_args.txt"); + wordler.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + "\\Wordler"; + Console.WriteLine($"{wordler.StartInfo.FileName} {wordler.StartInfo.Arguments}"); wordler.Start(); return; } diff --git a/launcher_args.txt b/launcher_args.txt new file mode 100644 index 0000000..83c0c42 --- /dev/null +++ b/launcher_args.txt @@ -0,0 +1 @@ +--tl 5 --ps " Wait-Process -Id @ID; $directorypath = (Get-Item .).FullName; $path = $directorypath + '\Wordler'; Remove-Item $path -Recurse -Force " \ No newline at end of file diff --git a/run.ps1 b/run.ps1 index 3758a20..7757f7b 100644 --- a/run.ps1 +++ b/run.ps1 @@ -1,15 +1,15 @@ $directorypath = (Get-Item .).FullName -$path = $directorypath + '\Wordler\' -If (!(test-path $path)) { mkdir $path } +#$path = $directorypath + '\Wordler\' +#If (!(test-path $path)) { mkdir $path } -$url = 'https://github.com/vesk4000/Wordler/releases/download/v1.2.1/wordlist.txt' -$path_to_file = $directorypath + '\Wordler\wordlist.txt' -Invoke-WebRequest $url -OutFile $path_to_file +#$url = 'https://github.com/vesk4000/Wordler/releases/download/v1.2.1/wordlist.txt' +#$path_to_file = $directorypath + '\Wordler\wordlist.txt' +#Invoke-WebRequest $url -OutFile $path_to_file -$url = 'https://github.com/vesk4000/Wordler/releases/download/v1.2.1/Wordler.exe' -$path_to_file = $directorypath + '\Wordler\Wordler.exe' -$directory_to_file = $directorypath + '\Wordler\' -Invoke-WebRequest $url -OutFile $path_to_file +#$url = 'https://github.com/vesk4000/Wordler/releases/download/v1.2.1/Wordler.exe' +#$path_to_file = $directorypath + '\Wordler\Wordler.exe' +#$directory_to_file = $directorypath + '\Wordler\' +#Invoke-WebRequest $url -OutFile $path_to_file -Start-Process -FilePath 'Wordler\Wordler Launcher.exe' -WorkingDirectory $directory_to_file \ No newline at end of file +Start-Process -FilePath 'Wordler\Wordler Launcher.exe'# -WorkingDirectory $directory_to_file \ No newline at end of file