public static NfdResult PickFolder(string defaultPath, out string path) { IntPtr defaultPathPtr = NFDParser.ToNfdString(defaultPath); NfdResult res = NFD_PickFolder(defaultPathPtr, out IntPtr outPath); Marshal.FreeHGlobal(defaultPathPtr); path = res != NfdResult.OKAY ? null : NFDParser.FromNfdString(outPath); if (res == NfdResult.ERROR) { Logger.Log(LogLevel.Error, "nativefiledialog error:"); Logger.Log(LogLevel.Error, GetError()); } return(res); }
public static NfdResult SaveDialog(string filterList, string defaultPath, out string path) { IntPtr filterListPtr = NFDParser.ToNfdString(filterList); IntPtr defaultPathPtr = NFDParser.ToNfdString(defaultPath); NfdResult res = NFD_SaveDialog(filterListPtr, defaultPathPtr, out IntPtr outPath); Marshal.FreeHGlobal(filterListPtr); Marshal.FreeHGlobal(defaultPathPtr); path = res != NfdResult.OKAY ? null : NFDParser.FromNfdString(outPath); // The outPath pointer should also probably be freed here. if (res == NfdResult.ERROR) { Logger.Log(LogLevel.Error, "nativefiledialog error:"); Logger.Log(LogLevel.Error, GetError()); } return(res); }
public static NfdResult OpenDialog(string filterList, string defaultPath, out string path) { IntPtr filterListPtr = NFDParser.ToNfdString(filterList); IntPtr defaultPathPtr = NFDParser.ToNfdString(defaultPath); NfdResult res = NFD_OpenDialog(filterListPtr, defaultPathPtr, out IntPtr outPath); Marshal.FreeHGlobal(filterListPtr); Marshal.FreeHGlobal(defaultPathPtr); path = res != NfdResult.OKAY ? null : NFDParser.FromNfdString(outPath); // Here, we *should* free the outPath pointer. // However, doing so causes a crash! // Does not doing so cause a memory leak? Probably. :) if (res == NfdResult.ERROR) { Logger.Log(LogLevel.Error, "nativefiledialog error:"); Logger.Log(LogLevel.Error, GetError()); } return(res); }
public static string GetError() { return(NFDParser.FromNfdString(NFD_GetError())); }