diff --git a/BeefLibs/corlib/src/IO/FileDialog.Vista.bf b/BeefLibs/corlib/src/IO/FileDialog.Vista.bf index 994a2382..2bef240c 100644 --- a/BeefLibs/corlib/src/IO/FileDialog.Vista.bf +++ b/BeefLibs/corlib/src/IO/FileDialog.Vista.bf @@ -99,20 +99,30 @@ namespace System.IO private Result SetFileTypes(Windows.COM_IFileDialog* dialog) { List filterItems = scope .(); - GetFilterItems(filterItems, mFilter); - if (filterItems.Count == 0) - return .Ok; - - defer + // Expected input types + // "Text files (*.txt)|*.txt|All files (*.*)|*.*" + // "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*" + if (!String.IsNullOrEmpty(mFilter)) { - for (var filter in filterItems) - { - delete filter.pszName; - delete filter.pszSpec; - } + StringView[] tokens = mFilter.Split!('|'); + if (0 == tokens.Count % 2) + { + // All even numbered tokens should be labels + // Odd numbered tokens are the associated extensions + for (int i = 1; i < tokens.Count; i += 2) + { + Windows.COMDLG_FILTERSPEC ext; + ext.pszSpec = tokens[i].ToScopedNativeWChar!::(); // This may be a semicolon delimited list of extensions (that's ok) + ext.pszName = tokens[i - 1].ToScopedNativeWChar!::(); + filterItems.Add(ext); + } + } } + if (filterItems.IsEmpty) + return .Ok; + Windows.COM_IUnknown.HResult hr = dialog.VT.SetFileTypes(dialog, (uint32)filterItems.Count, filterItems.Ptr); if (hr.Failed) return .Err; @@ -123,37 +133,6 @@ namespace System.IO return .Ok; } - - private static void GetFilterItems(List list, String filter) - { - mixin ToHeapWChar(var str) - { - int encodedLen = System.Text.UTF16.GetEncodedLen(str); - char16* buf = new char16[encodedLen]* ( ? ); - System.Text.UTF16.Encode(str, buf, encodedLen); - buf - } - - // Expected input types - // "Text files (*.txt)|*.txt|All files (*.*)|*.*" - // "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*" - if (!String.IsNullOrEmpty(filter)) - { - StringView[] tokens = filter.Split!('|'); - if (0 == tokens.Count % 2) - { - // All even numbered tokens should be labels - // Odd numbered tokens are the associated extensions - for (int i = 1; i < tokens.Count; i += 2) - { - Windows.COMDLG_FILTERSPEC ext; - ext.pszSpec = ToHeapWChar!(tokens[i]); // This may be a semicolon delimited list of extensions (that's ok) - ext.pszName = ToHeapWChar!(tokens[i - 1]); - list.Add(ext); - } - } - } - } } } #endif \ No newline at end of file diff --git a/BeefLibs/corlib/src/IO/OpenFileDialog.bf b/BeefLibs/corlib/src/IO/OpenFileDialog.bf index 6523c097..c7c79d11 100644 --- a/BeefLibs/corlib/src/IO/OpenFileDialog.bf +++ b/BeefLibs/corlib/src/IO/OpenFileDialog.bf @@ -120,14 +120,16 @@ namespace System.IO Windows.COM_IFileOpenDialog* openDialog = (.)dialog; if (Multiselect) { - openDialog.VT.GetResults(openDialog, let results); + Windows.COM_IShellItemArray* results = null; + openDialog.VT.GetResults(openDialog, out results); if (results != null) { results.VT.GetCount(results, let count); for (uint32 i < count) { - results.VT.GetItemAt(results, i, let item); + Windows.COM_IShellItem* item = null; + results.VT.GetItemAt(results, i, out item); if (item != null) { let filePath = GetFilePathFromShellItem!(item); @@ -140,7 +142,8 @@ namespace System.IO } else { - openDialog.VT.GetResult(openDialog, let shellItem); + Windows.COM_IShellItem* shellItem = null; + openDialog.VT.GetResult(openDialog, out shellItem); if (shellItem != null) { diff --git a/BeefLibs/corlib/src/IO/SaveFileDialog.bf b/BeefLibs/corlib/src/IO/SaveFileDialog.bf index 19064fbc..58e1bca9 100644 --- a/BeefLibs/corlib/src/IO/SaveFileDialog.bf +++ b/BeefLibs/corlib/src/IO/SaveFileDialog.bf @@ -109,7 +109,8 @@ namespace System.IO } Windows.COM_IFileSaveDialog* saveDialog = (.)dialog; - saveDialog.VT.GetResult(saveDialog, let shellItem); + Windows.COM_IShellItem* shellItem = null; + saveDialog.VT.GetResult(saveDialog, out shellItem); if (shellItem != null) {