From aad7c0376387ddc35caa186b321af416c29760e1 Mon Sep 17 00:00:00 2001 From: Jaex Date: Thu, 24 Mar 2016 21:03:10 +0200 Subject: [PATCH] Added message box to open file, folder functions to notify user if file or folder is not exist --- ShareX.HelpersLib/Helpers/Helpers.cs | 61 +++++++++++++++------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/ShareX.HelpersLib/Helpers/Helpers.cs b/ShareX.HelpersLib/Helpers/Helpers.cs index 04066cd1e..b00531f8e 100644 --- a/ShareX.HelpersLib/Helpers/Helpers.cs +++ b/ShareX.HelpersLib/Helpers/Helpers.cs @@ -389,18 +389,37 @@ public static string GetProperName(string name) return sb.ToString(); } + public static void OpenFile(string filePath) + { + if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) + { + TaskEx.Run(() => + { + try + { + Process.Start(filePath); + } + catch (Exception e) + { + DebugHelper.WriteException(e, $"OpenFile({filePath}) failed"); + } + }); + } + else + { + MessageBox.Show(Resources.Helpers_OpenFile_File_not_exist_ + Environment.NewLine + filePath, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + public static void OpenFolder(string folderPath) { - if (!string.IsNullOrEmpty(folderPath)) + if (!string.IsNullOrEmpty(folderPath) && Directory.Exists(folderPath)) { - if (Directory.Exists(folderPath)) - { - Process.Start("explorer.exe", folderPath); - } - else - { - MessageBox.Show(Resources.Helpers_OpenFolder_Folder_not_exist_ + "\r\n" + folderPath, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + Process.Start("explorer.exe", folderPath); + } + else + { + MessageBox.Show(Resources.Helpers_OpenFolder_Folder_not_exist_ + Environment.NewLine + folderPath, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); } } @@ -408,7 +427,11 @@ public static void OpenFolderWithFile(string filePath) { if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) { - Process.Start("explorer.exe", string.Format("/select,\"{0}\"", filePath)); + Process.Start("explorer.exe", $"/select,\"{filePath}\""); + } + else + { + MessageBox.Show(Resources.Helpers_OpenFile_File_not_exist_ + Environment.NewLine + filePath, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information); } } @@ -498,24 +521,6 @@ public static bool IsDefaultInstallDir() return Application.ExecutablePath.StartsWith(path); } - public static void OpenFile(string filepath) - { - if (!string.IsNullOrEmpty(filepath) && File.Exists(filepath)) - { - TaskEx.Run(() => - { - try - { - Process.Start(filepath); - } - catch (Exception e) - { - DebugHelper.WriteException(e, string.Format("OpenFile({0}) failed", filepath)); - } - }); - } - } - public static bool IsValidIPAddress(string ip) { if (string.IsNullOrEmpty(ip)) return false;