Beispiel #1
0
        public static bool Save(out string filepath,
                                string initialDir = null,
                                string name       = null,
                                string title      = null,
                                string filter     = null,
                                string defExt     = null)
        {
            OpenFileName ofn = new OpenFileName();

            ofn.structSize = Marshal.SizeOf(ofn);

            ofn.filter = (filter != null) ? filter : "All Files (*.*)\0*.*\0";

            var pls = new char[256];

            ((name != null) ? name : "file").ToCharArray().CopyTo((Span <char>)pls);
            ofn.file    = new String(pls);
            ofn.maxFile = ofn.file.Length;

            ofn.fileTitle    = new String(new char[64]);
            ofn.maxFileTitle = ofn.fileTitle.Length;

            ofn.initialDir = (initialDir != null) ? initialDir : "";
            ofn.title      = (title != null) ? title : "Save";
            ofn.defExt     = (defExt != null) ? defExt : "";

            ofn.flags |= LibWrap.OFN_OVERWRITEPROMPT;

            bool success = LibWrap.GetSaveFileName(ofn);

            // sussy info
            //Console.WriteLine("Selected file with full path: {0}", ofn.file);

            //Console.WriteLine("Selected file name: {0}", ofn.fileTitle);
            //Console.WriteLine("Offset from file name: {0}", ofn.fileOffset);
            //Console.WriteLine("Offset from file extension: {0}", ofn.fileExtension);

            filepath = ofn.file;
            return(success);
        }
Beispiel #2
0
        public static bool Open(out string filepath,
                                string initialDir = null,
                                string title      = null,
                                string filter     = null,
                                string defExt     = null)
        {
            OpenFileName ofn = new OpenFileName();

            ofn.structSize = Marshal.SizeOf(ofn);

            ofn.filter = (filter != null) ? filter : "All Files (*.*)\0*.*\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.initialDir = (initialDir != null) ? initialDir : "";
            ofn.title      = (title != null) ? title : "Open";
            ofn.defExt     = (defExt != null) ? defExt : "";

            // !!!
            ofn.flags |= LibWrap.OFN_NOCHANGEDIR; // what kind person decided that it's good idea to change execution directory when calling this mess (._. )
            // !!!

            bool success = LibWrap.GetOpenFileName(ofn);

            // sussy info
            //Console.WriteLine("Selected file with full path: {0}", ofn.file);

            //Console.WriteLine("Selected file name: {0}", ofn.fileTitle);
            //Console.WriteLine("Offset from file name: {0}", ofn.fileOffset);
            //Console.WriteLine("Offset from file extension: {0}", ofn.fileExtension);

            filepath = ofn.file;
            return(success);
        }