Automatically detect MyPictures shell folder path

More shell folders can be supported later
This commit is contained in:
Michael Delpach 2016-01-16 12:42:42 +08:00
parent bb3fbf637d
commit ae025adf46
2 changed files with 18 additions and 2 deletions

View file

@ -625,7 +625,7 @@ public static bool BrowseFolder(string title, TextBox tb, string initialDirector
if (fsd.ShowDialog())
{
tb.Text = fsd.FileName;
tb.Text = GetVariableFolderPath(fsd.FileName);
return true;
}
}
@ -633,6 +633,22 @@ public static bool BrowseFolder(string title, TextBox tb, string initialDirector
return false;
}
public static string GetVariableFolderPath(string folderPath)
{
folderPath = folderPath.Replace(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "%UserProfile%");
folderPath = folderPath.Replace(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "%MyPictures%");
return folderPath;
}
public static string ExpandFolderVariables(string folderPath)
{
folderPath = folderPath.Replace("%MyPictures%", Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));
folderPath = folderPath.Replace("%UserProfile%", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
return Environment.ExpandEnvironmentVariables(folderPath);
}
public static bool WaitWhile(Func<bool> check, int interval, int timeout = -1)
{
Stopwatch timer = Stopwatch.StartNew();

View file

@ -219,7 +219,7 @@ public static string ScreenshotsParentFolder
{
if (Settings != null && Settings.UseCustomScreenshotsPath && !string.IsNullOrEmpty(Settings.CustomScreenshotsPath))
{
return Environment.ExpandEnvironmentVariables(Settings.CustomScreenshotsPath);
return Helpers.ExpandFolderVariables(Settings.CustomScreenshotsPath);
}
return Path.Combine(PersonalFolder, "Screenshots");