public void Log(NfdResult result, string outPath, string[] outPaths)
        {
            switch (result)
            {
            case NfdResult.NFD_OKAY:
                if (outPaths != null)
                {
                    Debug.LogFormat("[NFD] Selected multiple ‹{0}›", string.Join("› ‹", outPaths));
                }
                else
                {
                    Debug.LogFormat("[NFD] Selected ‹{0}›", outPath);
                }
                break;

            case NfdResult.NFD_ERROR:
                var err = NativeFileDialog.GetError();
                if (!string.IsNullOrEmpty(err))
                {
                    Debug.LogError("[NFD] Error: " + err);
                }
                else
                {
                    Debug.LogError("[NFD] Error: Unknown Reason");
                }
                break;

            case NfdResult.NFD_CANCEL:
                Debug.Log("[NFD] Cancelled");
                break;
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void Show()
        {
            string outPath = null;

            string[]  outPaths = null;
            NfdResult result   = NfdResult.NFD_CANCEL;

            switch (fileDialogType)
            {
            case FileDialogType.Open:
                if (!allowOpenMultiple)
                {
                    result = NativeFileDialog.OpenDialog(filterList, defaultPath, out outPath);
                }
                else
                {
                    result = NativeFileDialog.OpenDialogMultiple(filterList, defaultPath, out outPaths);
                    if (outPaths != null && outPaths.Length > 0)
                    {
                        outPath = outPaths[0];
                    }
                }
                break;

            case FileDialogType.Folder:
                result = NativeFileDialog.PickFolder(defaultPath, out outPath);
                break;

            case FileDialogType.Save:
                result = NativeFileDialog.SaveDialog(filterList, defaultPath, out outPath);
                break;
            }

            if (onResult != null)
            {
                onResult.Invoke(result, outPath, outPaths);
            }
        }
Esempio n. 5
0
        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);
        }