-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- unused currently. - minor function rename.
- Loading branch information
1 parent
37b4cc8
commit afcb392
Showing
5 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Windows.Storage.Pickers; | ||
|
||
namespace Lively.UI.WinUI.Helpers | ||
{ | ||
|
||
//https://github.com/microsoft/WindowsAppSDK/issues/2504 | ||
public static class FilePickerUtil | ||
{ | ||
[DllImport("comdlg32.dll", SetLastError = true, CharSet = CharSet.Auto)] | ||
private static extern bool GetOpenFileName(ref OpenFileName ofn); | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] | ||
public struct OpenFileName | ||
{ | ||
public int lStructSize; | ||
public IntPtr hwndOwner; | ||
public IntPtr hInstance; | ||
public string lpstrFilter; | ||
public string lpstrCustomFilter; | ||
public int nMaxCustFilter; | ||
public int nFilterIndex; | ||
public string lpstrFile; | ||
public int nMaxFile; | ||
public string lpstrFileTitle; | ||
public int nMaxFileTitle; | ||
public string lpstrInitialDir; | ||
public string lpstrTitle; | ||
public int Flags; | ||
public short nFileOffset; | ||
public short nFileExtension; | ||
public string lpstrDefExt; | ||
public IntPtr lCustData; | ||
public IntPtr lpfnHook; | ||
public string lpTemplateName; | ||
public IntPtr pvReserved; | ||
public int dwReserved; | ||
public int flagsEx; | ||
} | ||
|
||
public static async Task<string> FilePicker(string[] filter) => | ||
false ? await FilePickerUwp(filter) : FilePickerCsWin32(filter); | ||
|
||
private static async Task<string> FilePickerUwp(string[] filter) | ||
{ | ||
var filePicker = new FileOpenPicker(); | ||
filePicker.SetOwnerWindow(App.Services.GetRequiredService<MainWindow>()); | ||
//filePicker.FileTypeFilter.Add("*"); | ||
foreach (var item in filter) | ||
{ | ||
filePicker.FileTypeFilter.Add(item); | ||
} | ||
return (await filePicker.PickSingleFileAsync())?.Path; | ||
} | ||
|
||
private static string FilePickerCsWin32(string[] filters) | ||
{ | ||
var ofn = new OpenFileName(); | ||
ofn.lStructSize = Marshal.SizeOf(ofn); | ||
/* | ||
ofn.lpstrFilter = "filterName"; | ||
foreach (string filter in filters) | ||
{ | ||
ofn.lpstrFilter += $"*{filter};"; | ||
} | ||
ofn.lpstrFilter += "\0\0"; | ||
*/ | ||
ofn.lpstrFile = new string(new char[256]); | ||
ofn.nMaxFile = ofn.lpstrFile.Length; | ||
ofn.lpstrFileTitle = new string(new char[64]); | ||
ofn.nMaxFileTitle = ofn.lpstrFileTitle.Length; | ||
//ofn.lpstrTitle = dialogTitle; | ||
if (GetOpenFileName(ref ofn)) | ||
return ofn.lpstrFile; | ||
return string.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters