mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-03 02:36:50 +13:00
fixed #3584: Handle invalid personal folder path in application settings
This commit is contained in:
parent
93e077a691
commit
7f84c812d4
3 changed files with 46 additions and 20 deletions
|
@ -884,6 +884,21 @@ public static void CreateDirectoryFromFilePath(string path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsValidFilePath(string path)
|
||||||
|
{
|
||||||
|
FileInfo fi = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fi = new FileInfo(path);
|
||||||
|
}
|
||||||
|
catch (ArgumentException) { }
|
||||||
|
catch (PathTooLongException) { }
|
||||||
|
catch (NotSupportedException) { }
|
||||||
|
|
||||||
|
return fi != null;
|
||||||
|
}
|
||||||
|
|
||||||
public static void CopyFile(string filePath, string destinationFolder, bool overwrite = true)
|
public static void CopyFile(string filePath, string destinationFolder, bool overwrite = true)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(filePath) && !string.IsNullOrEmpty(destinationFolder))
|
if (!string.IsNullOrEmpty(filePath) && !string.IsNullOrEmpty(destinationFolder))
|
||||||
|
|
|
@ -65,11 +65,13 @@ private void SettingsForm_FormClosed(object sender, FormClosedEventArgs e)
|
||||||
{
|
{
|
||||||
string currentPersonalPath = txtPersonalFolderPath.Text;
|
string currentPersonalPath = txtPersonalFolderPath.Text;
|
||||||
|
|
||||||
if (!currentPersonalPath.Equals(lastPersonalPath, StringComparison.InvariantCultureIgnoreCase))
|
if (!currentPersonalPath.Equals(lastPersonalPath, StringComparison.InvariantCultureIgnoreCase) &&
|
||||||
|
(string.IsNullOrEmpty(currentPersonalPath) || Helpers.IsValidFilePath(currentPersonalPath)))
|
||||||
{
|
{
|
||||||
Program.WritePersonalPathConfig(currentPersonalPath);
|
if (Program.WritePersonalPathConfig(currentPersonalPath))
|
||||||
|
{
|
||||||
MessageBox.Show("You must reopen ShareX for personal folder changes to take effect.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("You must reopen ShareX for personal folder changes to take effect.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,28 +302,34 @@ private void UpdatePersonalFolderPathPreview()
|
||||||
{
|
{
|
||||||
string personalPath = txtPersonalFolderPath.Text;
|
string personalPath = txtPersonalFolderPath.Text;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(personalPath))
|
try
|
||||||
{
|
{
|
||||||
if (Program.PortableApps)
|
if (string.IsNullOrEmpty(personalPath))
|
||||||
{
|
{
|
||||||
personalPath = Program.PortableAppsPersonalFolder;
|
if (Program.PortableApps)
|
||||||
}
|
{
|
||||||
else if (Program.Portable)
|
personalPath = Program.PortableAppsPersonalFolder;
|
||||||
{
|
}
|
||||||
personalPath = Program.PortablePersonalFolder;
|
else if (Program.Portable)
|
||||||
|
{
|
||||||
|
personalPath = Program.PortablePersonalFolder;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
personalPath = Program.DefaultPersonalFolder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
personalPath = Program.DefaultPersonalFolder;
|
personalPath = Helpers.GetAbsolutePath(personalPath);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
personalPath = Helpers.ExpandFolderVariables(personalPath);
|
|
||||||
personalPath = Helpers.GetAbsolutePath(personalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
lblPreviewPersonalFolderPath.Text = personalPath;
|
lblPreviewPersonalFolderPath.Text = personalPath;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
lblPreviewPersonalFolderPath.Text = "Error: " + e.Message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region General
|
#region General
|
||||||
|
|
|
@ -447,7 +447,7 @@ public static string ReadPersonalPathConfig()
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WritePersonalPathConfig(string path)
|
public static bool WritePersonalPathConfig(string path)
|
||||||
{
|
{
|
||||||
if (path == null)
|
if (path == null)
|
||||||
{
|
{
|
||||||
|
@ -470,6 +470,7 @@ public static void WritePersonalPathConfig(string path)
|
||||||
{
|
{
|
||||||
Helpers.CreateDirectoryFromFilePath(PersonalPathConfigFilePath);
|
Helpers.CreateDirectoryFromFilePath(PersonalPathConfigFilePath);
|
||||||
File.WriteAllText(PersonalPathConfigFilePath, path, Encoding.UTF8);
|
File.WriteAllText(PersonalPathConfigFilePath, path, Encoding.UTF8);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (UnauthorizedAccessException)
|
catch (UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
|
@ -478,6 +479,8 @@ public static void WritePersonalPathConfig(string path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
|
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
|
||||||
|
|
Loading…
Reference in a new issue