Beispiel #1
0
    static string SaveFile(string path, string title, bool multiselect, string filter)
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);

        ofn.filter = filter;

        ofn.file = new string(new char[256]);

        ofn.maxFile = ofn.file.Length;

        ofn.fileTitle = new string(new char[64]);

        ofn.maxFileTitle = ofn.fileTitle.Length;

        path = path.Replace('/', '\\');
        //默认路径
        ofn.initialDir = path;
        //ofn.InitialDirectory = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets";
        ofn.title = title;

        ofn.defExt = "unity3d";                                                     //显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetSaveFileName(ofn))
        {
            Debug.Log("Selected file with full path: {0}" + ofn.file);
        }
        return(ofn.file);
    }
    public static string SaveFileDialog(AssetFileType fileType, string windowTitle = "保存文件", string initPath = null)
    {
        OpenFileName ofn = InitDialogCommon(windowTitle, initPath);

        GetFliter(fileType, out ofn.filter, out ofn.defExt);
        ofn.flags = (int)(
            OpenFileNameFlags.OFN_EXPLORER
            | OpenFileNameFlags.OFN_FILEMUSTEXIST
            | OpenFileNameFlags.OFN_PATHMUSTEXIST
            | OpenFileNameFlags.OFN_NOCHANGEDIR
            );
        if (WindowDll.GetSaveFileName(ofn))
        {
            IntPtr filePointer = ofn.file;
            string file        = Marshal.PtrToStringAuto(filePointer);
            return(file);
        }
        return(null);
    }
Beispiel #3
0
    public void SaveFileWin(string fileContent)
    {
        WindowsOpenFile wof = new WindowsOpenFile();

        wof.structSize = Marshal.SizeOf(wof);

        wof.filter = "All Files\0*.*\0\0";

        wof.file = new string(new char[256]);

        wof.maxFile = wof.file.Length;

        wof.fileTitle = new string(new char[64]);

        wof.maxFileTitle = wof.fileTitle.Length;
        string path = Application.streamingAssetsPath;

        path = path.Replace('/', '\\');
        //默认路径
        wof.initialDir = path;
        //ofn.initialDir = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets";
        wof.title = "Open Project";

        wof.defExt = "json";//显示文件的类型
        //注意 一下项目不一定要全选 但是0x00000008项不要缺少
        wof.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (WindowDll.GetSaveFileName(wof))
        {
            Debug.Log("SaveFileWin = " + wof.file);
            FileStream fileStream = new FileStream(wof.file, FileMode.Create);
            byte[]     bts        = new UTF8Encoding().GetBytes(fileContent);
            fileStream.Write(bts, 0, bts.Length);
            fileStream.Close();
            //GameReadExcel(wof.file);
        }
    }