You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.5 KiB

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
public static class FileUtil
{ // My Super Fucking File Manager
public static string OpenFile()
{
FileOpenDialog dialog = new FileOpenDialog();
dialog.structSize = Marshal.SizeOf(dialog);
dialog.filter = "All Files\0*\0\0";
dialog.file = new string(new char[256]);
dialog.maxFile = dialog.file.Length;
dialog.fileTitle = new string(new char[64]);
dialog.maxFileTitle = dialog.fileTitle.Length;
dialog.initialDir = UnityEngine.Application.dataPath;
dialog.title = "Open Card Asset Bundle";
dialog.defExt = "";
dialog.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;
//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_NOCHANGEDIR
if (DialogShow.GetOpenFileName(dialog))
{
Debug.Log(dialog.file);
return dialog.file;
}
return "";
}
public static void WatchFile(string dirPath, string filename, FileSystemEventHandler handler)
{
var watcher = new FileSystemWatcher(dirPath);
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += handler;
watcher.Filter = filename;
watcher.EnableRaisingEvents = true;
}
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class FileOpenDialog
{
public int structSize = 0;
public IntPtr dlgOwner = IntPtr.Zero;
public IntPtr instance = IntPtr.Zero;
public String filter = null;
public String customFilter = null;
public int maxCustFilter = 0;
public int filterIndex = 0;
public String file = null;
public int maxFile = 0;
public String fileTitle = null;
public int maxFileTitle = 0;
public String initialDir = null;
public String title = null;
public int flags = 0;
public short fileOffset = 0;
public short fileExtension = 0;
public String defExt = null;
public IntPtr custData = IntPtr.Zero;
public IntPtr hook = IntPtr.Zero;
public String templateName = null;
public IntPtr reservedPtr = IntPtr.Zero;
public int reservedInt = 0;
public int flagsEx = 0;
}
public class DialogShow
{
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetOpenFileName([In, Out] FileOpenDialog dialog);
}