-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileSelector.cs
More file actions
58 lines (57 loc) · 2.13 KB
/
FileSelector.cs
File metadata and controls
58 lines (57 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Runtime.InteropServices;
namespace VaniFine
{
public class FileSelector
{
[DllImport("comdlg32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool GetOpenFileName(ref OpenFileName ofn);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
public static string ShowDialog()
{
if (!OperatingSystem.IsWindows())
{
Console.WriteLine("File dialog is only supported on Windows platforms. You can set your file path manually by using arguments.");
Environment.Exit(-1);
}
var ofn = new OpenFileName();
ofn.lStructSize = Marshal.SizeOf(ofn);
ofn.lpstrFilter = "ZIP Archive\0*.zip\0All Files (*.*)\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 = "Select Resource Pack";
if (GetOpenFileName(ref ofn))
return ofn.lpstrFile;
return string.Empty;
}
}
[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;
}
}