public static extern bool GetSaveFileName([In, Out] OpenFileName ofn);
public static bool GetSFN([In, Out] OpenFileName ofn) { return(GetSaveFileName(ofn)); }
/// <summary>导航并读取用户选择的文件 </summary> public async static Task <byte[]> PickFile() { #if UNITY_STANDALONE_WIN || UNITY_EDITOR OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "pdb文件(*.pdb)\0*.pdb\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.title = "选择文件"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (LocalDialog.GetOpenFileName(ofn)) { using (FileStream fs = new FileStream(ofn.file, FileMode.Open, FileAccess.Read)) { if (fs.Length > MAX_FILE_SIZE) { throw new SelectFileException(SelectFileError.OverSize); } byte[] file = new byte[fs.Length]; await fs.ReadAsync(file, 0, file.Length); return(file); } } throw new SelectFileException(SelectFileError.Cancel); #elif ENABLE_WINMD_SUPPORT StorageFile file = null; bool isCompleteZZZ = false; object syncRoot = new object(); FileOpenPicker picker = new FileOpenPicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary, ViewMode = PickerViewMode.List, }; picker.FileTypeFilter.Add(".pdb"); UnityEngine.WSA.Application.InvokeOnUIThread(async() => { file = await picker.PickSingleFileAsync(); lock (syncRoot) { isCompleteZZZ = true; } }, true); while (true) { lock (syncRoot) { if (isCompleteZZZ) { break; } } await Task.Run(() => { Thread.Sleep(100); }); } if (file != null) { ulong size = (await file.GetBasicPropertiesAsync()).Size;//字节大小 if (size > MAX_FILE_SIZE) { throw new SelectFileException(SelectFileError.OverSize); } else { string text = await FileIO.ReadTextAsync(file, Windows.Storage.Streams.UnicodeEncoding.Utf8); return(Encoding.UTF8.GetBytes(text)); } } else { throw new SelectFileException(SelectFileError.Cancel); } #else throw new NotImplementedException(string.Format("[IOUtil.PickFile]Implemented Platform:{0}", Application.platform.ToString())); #endif }