diff --git a/Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs b/Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs index c86fa75..e8e121b 100755 --- a/Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs +++ b/Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs @@ -18,11 +18,7 @@ public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] } fd.Multiselect = multiselect; if (!string.IsNullOrEmpty(directory)) { - var directoryPath = Path.GetFullPath(directory); - if (!directoryPath.EndsWith("\\")) { - directoryPath += "\\"; - } - fd.FileName = Path.GetDirectoryName(directoryPath) + Path.DirectorySeparatorChar; + fd.FileName = GetDirectoryPath(directory); } var res = fd.ShowDialog(); var filenames = res == DialogResult.OK ? fd.FileNames : new string[0]; @@ -34,11 +30,7 @@ public string[] OpenFolderPanel(string title, string directory, bool multiselect var fd = new VistaFolderBrowserDialog(); fd.Description = title; if (!string.IsNullOrEmpty(directory)) { - var directoryPath = Path.GetFullPath(directory); - if (!directoryPath.EndsWith("\\")) { - directoryPath += "\\"; - } - fd.SelectedPath = Path.GetDirectoryName(directoryPath) + Path.DirectorySeparatorChar; + fd.SelectedPath = GetDirectoryPath(directory); } var res = fd.ShowDialog(); var filenames = res == DialogResult.OK ? new []{ fd.SelectedPath } : new string[0]; @@ -49,8 +41,18 @@ public string[] OpenFolderPanel(string title, string directory, bool multiselect public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) { var fd = new VistaSaveFileDialog(); fd.Title = title; - fd.InitialDirectory = string.IsNullOrEmpty(directory) ? "" : Path.GetFullPath(directory); - fd.FileName = defaultName; + + var finalFilename = ""; + + if (!string.IsNullOrEmpty(directory)) { + finalFilename = GetDirectoryPath(directory); + } + + if (!string.IsNullOrEmpty(defaultName)) { + finalFilename += defaultName; + } + + fd.FileName = finalFilename; if (extensions != null) { fd.Filter = GetFilterFromFileExtensionList(extensions); fd.FilterIndex = 1; @@ -91,6 +93,14 @@ private static string GetFilterFromFileExtensionList(ExtensionFilter[] extension filterString = filterString.Remove(filterString.Length - 1); return filterString; } + + private static string GetDirectoryPath(string directory) { + var directoryPath = Path.GetFullPath(directory); + if (!directoryPath.EndsWith("\\")) { + directoryPath += "\\"; + } + return Path.GetDirectoryName(directoryPath) + Path.DirectorySeparatorChar; + } } } diff --git a/Package/StandaloneFileBrowser.unitypackage b/Package/StandaloneFileBrowser.unitypackage index 7aef830..dbd118c 100644 Binary files a/Package/StandaloneFileBrowser.unitypackage and b/Package/StandaloneFileBrowser.unitypackage differ