Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update new ookii library and fix bug crash for root directory #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Assets/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll
Binary file not shown.
39 changes: 8 additions & 31 deletions Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ public class StandaloneFileBrowserWindows : IStandaloneFileBrowser {
public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
var fd = new VistaOpenFileDialog();
fd.Title = title;
fd.InitialDirectory = directory;
fd.Multiselect = multiselect;
if (extensions != null) {
fd.Filter = GetFilterFromFileExtensionList(extensions);
fd.FilterIndex = 1;
}
else {
fd.Filter = string.Empty;
}
fd.Multiselect = multiselect;
if (!string.IsNullOrEmpty(directory)) {
fd.FileName = GetDirectoryPath(directory);
}
var res = fd.ShowDialog(new WindowWrapper(GetActiveWindow()));
var filenames = res == DialogResult.OK ? fd.FileNames : new string[0];
fd.Dispose();
Expand All @@ -48,11 +46,10 @@ public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[]
public string[] OpenFolderPanel(string title, string directory, bool multiselect) {
var fd = new VistaFolderBrowserDialog();
fd.Description = title;
if (!string.IsNullOrEmpty(directory)) {
fd.SelectedPath = GetDirectoryPath(directory);
}
fd.RootFolder = Environment.SpecialFolder.MyComputer;
fd.SelectedPath = directory;
var res = fd.ShowDialog(new WindowWrapper(GetActiveWindow()));
var filenames = res == DialogResult.OK ? new []{ fd.SelectedPath } : new string[0];
var filenames = res == DialogResult.OK ? new[] { fd.SelectedPath } : new string[0];
fd.Dispose();
return filenames;
}
Expand All @@ -64,18 +61,8 @@ public void OpenFolderPanelAsync(string title, string directory, bool multiselec
public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
var fd = new VistaSaveFileDialog();
fd.Title = title;

var finalFilename = "";

if (!string.IsNullOrEmpty(directory)) {
finalFilename = GetDirectoryPath(directory);
}

if (!string.IsNullOrEmpty(defaultName)) {
finalFilename += defaultName;
}

fd.FileName = finalFilename;
fd.InitialDirectory = directory;
fd.FileName = defaultName;
if (extensions != null) {
fd.Filter = GetFilterFromFileExtensionList(extensions);
fd.FilterIndex = 1;
Expand All @@ -100,6 +87,7 @@ public void SaveFilePanelAsync(string title, string directory, string defaultNam
// .NET Framework FileDialog Filter format
// https://msdn.microsoft.com/en-us/library/microsoft.win32.filedialog.filter
private static string GetFilterFromFileExtensionList(ExtensionFilter[] extensions) {
if (extensions == null) return "";
var filterString = "";
foreach (var filter in extensions) {
filterString += filter.Name + "(";
Expand All @@ -120,17 +108,6 @@ 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 += "\\";
}
if (Path.GetPathRoot(directoryPath) == directoryPath) {
return directory;
}
return Path.GetDirectoryName(directoryPath) + Path.DirectorySeparatorChar;
}
}
}

Expand Down