mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-01 04:30:49 +12:00
fixed #3584: Handle invalid personal folder path in application settings
This commit is contained in:
parent
93e077a691
commit
7f84c812d4
|
@ -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)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(filePath) && !string.IsNullOrEmpty(destinationFolder))
|
||||
|
|
|
@ -65,11 +65,13 @@ private void SettingsForm_FormClosed(object sender, FormClosedEventArgs e)
|
|||
{
|
||||
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);
|
||||
|
||||
MessageBox.Show("You must reopen ShareX for personal folder changes to take effect.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
if (Program.WritePersonalPathConfig(currentPersonalPath))
|
||||
{
|
||||
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;
|
||||
|
||||
if (string.IsNullOrEmpty(personalPath))
|
||||
try
|
||||
{
|
||||
if (Program.PortableApps)
|
||||
if (string.IsNullOrEmpty(personalPath))
|
||||
{
|
||||
personalPath = Program.PortableAppsPersonalFolder;
|
||||
}
|
||||
else if (Program.Portable)
|
||||
{
|
||||
personalPath = Program.PortablePersonalFolder;
|
||||
if (Program.PortableApps)
|
||||
{
|
||||
personalPath = Program.PortableAppsPersonalFolder;
|
||||
}
|
||||
else if (Program.Portable)
|
||||
{
|
||||
personalPath = Program.PortablePersonalFolder;
|
||||
}
|
||||
else
|
||||
{
|
||||
personalPath = Program.DefaultPersonalFolder;
|
||||
}
|
||||
}
|
||||
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
|
||||
|
|
|
@ -447,7 +447,7 @@ public static string ReadPersonalPathConfig()
|
|||
return "";
|
||||
}
|
||||
|
||||
public static void WritePersonalPathConfig(string path)
|
||||
public static bool WritePersonalPathConfig(string path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
|
@ -470,6 +470,7 @@ public static void WritePersonalPathConfig(string path)
|
|||
{
|
||||
Helpers.CreateDirectoryFromFilePath(PersonalPathConfigFilePath);
|
||||
File.WriteAllText(PersonalPathConfigFilePath, path, Encoding.UTF8);
|
||||
return true;
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
|
@ -478,6 +479,8 @@ public static void WritePersonalPathConfig(string path)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
|
||||
|
|
Loading…
Reference in a new issue