Added message box to open file, folder functions to notify user if file or folder is not exist

This commit is contained in:
Jaex 2016-03-24 21:03:10 +02:00
parent f4a0cbbf24
commit aad7c03763

View file

@ -389,18 +389,37 @@ public static string GetProperName(string name)
return sb.ToString(); 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) 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);
{ }
Process.Start("explorer.exe", folderPath); else
} {
else MessageBox.Show(Resources.Helpers_OpenFolder_Folder_not_exist_ + Environment.NewLine + folderPath, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
{
MessageBox.Show(Resources.Helpers_OpenFolder_Folder_not_exist_ + "\r\n" + folderPath, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
} }
} }
@ -408,7 +427,11 @@ public static void OpenFolderWithFile(string filePath)
{ {
if (!string.IsNullOrEmpty(filePath) && File.Exists(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); 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) public static bool IsValidIPAddress(string ip)
{ {
if (string.IsNullOrEmpty(ip)) return false; if (string.IsNullOrEmpty(ip)) return false;