Пример #1
0
        public int CreateFile(string filename, System.IO.FileAccess access, System.IO.FileShare share, System.IO.FileMode mode, System.IO.FileOptions options, DokanFileInfo info)
        {
            int ret = DokanNet.DOKAN_SUCCESS;

            filename = CleanFileName(filename);

            try
            {
                Debug("CreateFile {0}", filename);

                string Directory = nfsClient.GetDirectoryName(filename);
                string FileName  = nfsClient.GetFileName(filename);
                string FullPath  = nfsClient.Combine(FileName, Directory);

                if (nfsClient.IsDirectory(FullPath))
                {
                    return(ret);
                }

                switch (mode)
                {
                case FileMode.Open:
                {
                    Debug("Open");
                    if (!nfsClient.FileExists(FullPath))
                    {
                        ret = -DokanNet.ERROR_FILE_NOT_FOUND;
                    }
                    break;
                }

                case FileMode.CreateNew:
                {
                    Debug("CreateNew");
                    if (nfsClient.FileExists(FullPath))
                    {
                        ret = -DokanNet.ERROR_ALREADY_EXISTS;
                    }
                    else
                    {
                        nfsClient.CreateFile(FullPath);
                    }
                    break;
                }

                case FileMode.Create:
                {
                    Debug("Create");
                    if (nfsClient.FileExists(FullPath))
                    {
                        nfsClient.DeleteFile(FullPath);
                    }

                    nfsClient.CreateFile(FullPath);
                    break;
                }

                case FileMode.OpenOrCreate:
                {
                    Debug("OpenOrCreate");
                    if (!nfsClient.FileExists(FullPath))
                    {
                        nfsClient.CreateFile(FullPath);
                    }
                    break;
                }

                case FileMode.Truncate:
                {
                    Debug("Truncate");
                    if (!nfsClient.FileExists(FullPath))
                    {
                        ret = -DokanNet.ERROR_FILE_NOT_FOUND;
                    }
                    else
                    {
                        nfsClient.CreateFile(FullPath);
                    }
                    break;
                }

                case FileMode.Append:
                {
                    Debug("Appen");
                    if (!nfsClient.FileExists(FullPath))
                    {
                        ret = -DokanNet.ERROR_FILE_NOT_FOUND;
                    }
                    break;
                }

                default:
                {
                    Debug("Error unknown FileMode {0}", mode);
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                ret = -DokanNet.DOKAN_ERROR;
                Debug("CreateFile file {0} exception {1}", filename, ex.Message);
            }
            return(ret);
        }