예제 #1
0
    public void FindTxt()
    {
        if (checkDataError())
        {
            return;
        }
        OpenDialogFile ofn = new OpenDialogFile();

        ofn.structSize   = Marshal.SizeOf(ofn);
        ofn.filter       = "All Files\0*.*\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;
        string path = Application.streamingAssetsPath;

        path      = path.Replace('/', '\\');
        ofn.title = "选择索引文件";
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (DllBox.GetOpenFileName(ofn))
        {
            gameObject.transform.Find("LogText").GetComponent <Text>().text = ofn.file;
            data.TxtPath = ofn.file;
        }
    }
예제 #2
0
        static public string GetFilePathByDialog(string title, string defaultPath)
        {
            OpenDialogFile openFileName = new OpenDialogFile();

            openFileName.structSize = Marshal.SizeOf(openFileName);
            //openFileName.filter = "Excel文件(*.xlsx)\0*.xlsx";
            openFileName.file         = new string(new char[512]);
            openFileName.maxFile      = openFileName.file.Length;
            openFileName.fileTitle    = new string(new char[64]);
            openFileName.maxFileTitle = openFileName.fileTitle.Length;
            openFileName.initialDir   = defaultPath;
            openFileName.title        = title;
            openFileName.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;

            DllOpenFileDialog.GetSaveFileName(openFileName);

            return(openFileName.file);
        }
예제 #3
0
        public static string GetFileDir(string varTitle, string varpath)
        {
            OpenDialogFile openFile = new OpenDialogFile();

            openFile.structSize = Marshal.SizeOf(openFile);
            //窗口标题
            if (string.IsNullOrEmpty(varTitle))
            {
                varTitle = "Open Project";
            }
            openFile.title = varTitle;
            varpath        = varpath.Replace('/', '\\');
            //默认路径
            openFile.initialDir = varpath;
            openFile.file       = new string(new char[256]);

            openFile.maxFile      = openFile.file.Length;
            openFile.fileTitle    = new string(new char[256]);
            openFile.maxFileTitle = openFile.fileTitle.Length;
            //OpenDialogDir ofn2 = new OpenDialogDir();
            //ofn2.pszDisplayName = new string(new char[2000]); ;     // 存放目录路径缓冲区
            //if (string.IsNullOrEmpty(varTitle))
            //    ofn2.lpszTitle = "Open Project";// 标题
            ////ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框
            //IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2);

            //char[] charArray = new char[2000];
            //for (int i = 0; i < 2000; i++)
            //    charArray[i] = '\0';

            //DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray);
            //string fullDirPath = new String(charArray);


            //fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0'));
            //注意 一下项目不一定要全选 但是0x00000008项不要缺少
            openFile.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
            if (DllOpenFileDialog.GetOpenFileName(openFile))
            {
                return(openFile.file);
            }
            return(null);
        }
예제 #4
0
    public static string GetFileFromWindowsExplorer()
    {
        var backPath = "";

        OpenDialogFile openFileName = new OpenDialogFile();

        openFileName.structSize   = Marshal.SizeOf(openFileName);
        openFileName.file         = new string(new char[256]);
        openFileName.maxFile      = openFileName.file.Length;
        openFileName.fileTitle    = new string(new char[64]);
        openFileName.maxFileTitle = openFileName.fileTitle.Length;
        openFileName.initialDir   = Application.dataPath.Replace('/', '\\');//默认路径
        openFileName.title        = "打开文件";
        openFileName.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008;
        if (WindowsExplorer.GetSaveFileName(openFileName))
        {
            Debug.Log(openFileName.file);
            Debug.Log(openFileName.fileTitle);
            backPath = openFileName.file;
        }

        return(backPath);
    }
예제 #5
0
 public static extern bool GetSaveFileName([In, Out] OpenDialogFile ofn);
예제 #6
0
    public static void OpenSingleFile(out string filepath, out string filename, params string[] exts)
    {
        bool flag = false;

        filepath = "";

        filename = "";

        OpenDialogFile ofn = new OpenDialogFile();

        ofn.structSize = Marshal.SizeOf(ofn);

        //var str = string.Format("flie {0}(*.{1})|*.{2}", exts[0], exts[0], exts[0]);
        //if(exts.Length > 1)
        //{
        //    for(int i=1;i<exts.Length;++i)
        //    {
        //        str = string.Format("{0}|flie {1}(*.{2})|*.{3}", str, exts[i], exts[i], exts[i]);
        //    }
        //}
        var str = "files(*." + exts[0];

        if (exts.Length > 1)
        {
            for (int i = 1; i < exts.Length; ++i)
            {
                str = string.Format("{0};*.{1}", str, exts[i]);
            }
        }

        str = string.Format("{0})\0*.{1}", str, exts[0]);
        if (exts.Length > 1)
        {
            for (int i = 1; i < exts.Length; ++i)
            {
                str = string.Format("{0};*.{1}", str, exts[i]);
            }
        }
        //str += "\0All files (*.*)\0*.*";
        ofn.filter = str;

        ofn.filterIndex = 1;

        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 = "c:\\"; //默认路径

        //ofn.defExt = null;

        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;    //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR


        if (DllOpenFileDialog.GetOpenFileName(ofn))
        {
            //StartCoroutine(WaitLoad(ofn.file));//加载图片到panle

            Debug.Log("Selected file with full path: {0}" + ofn.file);
            flag = true;
        }
        if (flag == true)
        {
            //System.Diagnostics.Process.Start(ofn.file);
            Debug.Log(ofn.file);

            filepath = ofn.file;

            Debug.Log(ofn.fileTitle);

            if (ofn.fileTitle != null)
            {
                string[] names = ofn.fileTitle.Split('.');
                if (names.Length > 0)
                {
                    filename = names[0];
                }
            }
        }
    }
예제 #7
0
 public static bool GetOpenFileName1([In, Out] OpenDialogFile ofn)
 {
     return(GetOpenFileName(ofn));
 }