From 7ce4c2dc5cceffcc067df808e9f2f81dbbfa8fec Mon Sep 17 00:00:00 2001 From: Minko Date: Sat, 31 Dec 2022 00:23:56 +0200 Subject: [PATCH] feat: fix on args on run methods and nex profiles --- .github/workflows/dotnet-desktop.yml | 2 +- ShortcutsGrid/Services/Run/RunProcess.cs | 30 +++++++++++++++++++++--- ShortcutsGrid/ShortcutsGrid.csproj | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dotnet-desktop.yml b/.github/workflows/dotnet-desktop.yml index 1c9f602..25c9619 100644 --- a/.github/workflows/dotnet-desktop.yml +++ b/.github/workflows/dotnet-desktop.yml @@ -80,7 +80,7 @@ jobs: cd ${{ env.Proj_Name }} #dotnet publish ShortcutsGrid.csproj /p:PublishProfile="Win System" #copy "bin\Win System\net6.0-windows\publish\win-x64\Win System.exe" ..\\${{ env.Test_Proj_Dir }}\\TestResults - $exes = "Win System","Win Admin","Office","Utils","Browsers","Connections","Disk Tools","Audio","Image","Video","Hardware" + $exes = "Win System","Win Admin","Office","Utils","Browsers","Connections","Disk Tools","Audio","Image","Video","Hardware","Virtual Machines","Programming","Games" foreach ($name in $exes){dotnet publish ShortcutsGrid.csproj /p:PublishProfile="$name"} foreach ($name in $exes){copy "bin\$name\net6.0-windows\publish\win-x64\$name.exe" ..\\${{ env.Test_Proj_Dir }}\\TestResults} diff --git a/ShortcutsGrid/Services/Run/RunProcess.cs b/ShortcutsGrid/Services/Run/RunProcess.cs index d132a04..b4f2ad5 100644 --- a/ShortcutsGrid/Services/Run/RunProcess.cs +++ b/ShortcutsGrid/Services/Run/RunProcess.cs @@ -2,6 +2,9 @@ using System; using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Windows.Documents; public static class RunProcess { @@ -27,8 +30,29 @@ public static string Run(string commandOrPath, bool admin = false) try { string[] cmdAndArgs = commandOrPath.Split(' '); - string args = commandOrPath.Remove(0, cmdAndArgs[0].Length); - ProcessStart(cmdAndArgs[0], admin, args); + string processCommandOrPath = string.Empty; + string args = string.Empty; + if (commandOrPath.Contains('\\')) + { + var pathStructure = cmdAndArgs.ToList(); + for (int i = cmdAndArgs.Length - 1; i > 0; i--) + { + pathStructure.RemoveAt(i); + var fileOrFolder = String.Join(" ", pathStructure.ToArray()); + if (File.Exists(fileOrFolder))//to do case for folder if needed + { + processCommandOrPath = fileOrFolder; + args = commandOrPath.Replace(processCommandOrPath, ""); + break; + } + } + } + else + { + args = commandOrPath.Remove(0, cmdAndArgs[0].Length); + processCommandOrPath = cmdAndArgs[0]; + } + ProcessStart(processCommandOrPath, admin, args); return string.Empty; } catch (Exception ex) { return ex.Message; } @@ -39,7 +63,7 @@ private static void ProcessStart(string commandOrPath, bool admin, string args = { Process process = new Process(); process.StartInfo.UseShellExecute = true; - //todo + //to do ///process.StartInfo.WorkingDirectory = "c:\\"; process.StartInfo.FileName = commandOrPath; process.StartInfo.Arguments = args; diff --git a/ShortcutsGrid/ShortcutsGrid.csproj b/ShortcutsGrid/ShortcutsGrid.csproj index 86d39af..36e7dac 100644 --- a/ShortcutsGrid/ShortcutsGrid.csproj +++ b/ShortcutsGrid/ShortcutsGrid.csproj @@ -6,7 +6,7 @@ enable true win-x64 - Resources\hardware-128.ico + Resources\games-128.ico 1.2.2.1 1.2.2.1 1.2.2