From a0147102b6f21451d045ca6e8adeaa3ba774b92c Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 17 Nov 2020 22:44:02 +0000 Subject: [PATCH] Added: environment path support --- Models/TileModel.cs | 20 +++++++------------- Windows/Forms/Tile/TTilePanel.cs | 14 +++++++------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Models/TileModel.cs b/Models/TileModel.cs index f195aa8..53f8dcf 100644 --- a/Models/TileModel.cs +++ b/Models/TileModel.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Drawing; @@ -19,18 +20,11 @@ namespace AppLauncher.Models public override string ToString() => this.Title ?? string.Empty; - //public void Update(TileModel model) - //{ - // this.Title = model.Title; - // this.ProcessFilename = model.ProcessFilename; - // this.ProcessArgument = model.ProcessArgument; - // this.ProcessWorkingDirectory = model.ProcessWorkingDirectory; - // this.ProcessWindowStyle = model.ProcessWindowStyle; - // this.ProcessAsAdmin = model.ProcessAsAdmin; - // this.Position = model.Position; - // this.IsGroup = model.IsGroup; - // this.Items = model.Items; - //} + public string CleanProcessFilename => (string.IsNullOrWhiteSpace(this.ProcessFilename) ? string.Empty : Environment.ExpandEnvironmentVariables(this.ProcessFilename)); + + public string CleanProcessArgument => (string.IsNullOrWhiteSpace(this.ProcessArgument) ? string.Empty : Environment.ExpandEnvironmentVariables(this.ProcessArgument)); + + public string CleanProcessWorkingDirectory => (string.IsNullOrWhiteSpace(this.ProcessWorkingDirectory) ? string.Empty : Environment.ExpandEnvironmentVariables(this.ProcessWorkingDirectory)); } } diff --git a/Windows/Forms/Tile/TTilePanel.cs b/Windows/Forms/Tile/TTilePanel.cs index dd28ad7..88ad239 100644 --- a/Windows/Forms/Tile/TTilePanel.cs +++ b/Windows/Forms/Tile/TTilePanel.cs @@ -283,21 +283,21 @@ namespace AppLauncher.Windows.Forms return; } - if (string.IsNullOrWhiteSpace(model.ProcessFilename)) + if (string.IsNullOrWhiteSpace(model.CleanProcessFilename)) { return; } - if (!File.Exists(model.ProcessFilename)) + if (!File.Exists(model.CleanProcessFilename)) { return; } ProcessStartInfo p = new ProcessStartInfo(); - p.FileName = model.ProcessFilename; + p.FileName = model.CleanProcessFilename; p.WindowStyle = model.ProcessWindowStyle; - if (!string.IsNullOrWhiteSpace(model.ProcessArgument)) p.Arguments = model.ProcessArgument; - if (!string.IsNullOrWhiteSpace(model.ProcessWorkingDirectory)) p.WorkingDirectory = model.ProcessWorkingDirectory; + if (!string.IsNullOrWhiteSpace(model.CleanProcessArgument)) p.Arguments = model.CleanProcessArgument; + if (!string.IsNullOrWhiteSpace(model.CleanProcessWorkingDirectory)) p.WorkingDirectory = model.CleanProcessWorkingDirectory; if (model.ProcessAsAdmin) p.Verb = "runas"; MainForm parentForm = findMainForm(); @@ -324,14 +324,14 @@ namespace AppLauncher.Windows.Forms protected Image getIcon(TileModel model) { - if (!File.Exists(model.ProcessFilename)) + if (!File.Exists(model.CleanProcessFilename)) { return null; } try { - return Icon.ExtractAssociatedIcon(model.ProcessFilename)?.ToBitmap(); + return Icon.ExtractAssociatedIcon(model.CleanProcessFilename)?.ToBitmap(); } catch {