Ejemplo n.º 1
0
        public void Close()
        {
            if (Mode != FileSystemMode.Read)
            {
                Save();
            }

            content.Close();
            content  = null;
            fragment = null;
            chunk    = null;
        }
Ejemplo n.º 2
0
        public FileSystemResultCode Open(FileSystemMode mode, string contentPath, string indexPath)
        {
            Mode            = mode;
            ContentFilePath = contentPath;
            IndexFilePath   = indexPath;

            if (Mode != FileSystemMode.Create && !File.Exists(ContentFilePath))
            {
                return(FileSystemResultCode.ContentFileNotExistError);
            }
            if (Mode != FileSystemMode.Create && !File.Exists(IndexFilePath))
            {
                return(FileSystemResultCode.IndexFileNotExistError);
            }

            content = new FileContent();
            chunk   = new FileChunk();
            if (Mode != FileSystemMode.Read)
            {
                fragment = new FileFragment();
            }

            FileSystemResultCode resultCode = FileSystemResultCode.Success;

            resultCode = content.OpenContent(ContentFilePath, Mode);
            if (resultCode == FileSystemResultCode.Success)
            {
                if (Mode != FileSystemMode.Create)
                {
                    FileStream indexStream = null;
                    try
                    {
                        indexStream = new FileStream(IndexFilePath, FileMode.Open, FileAccess.Read, FileShare.None);
                        resultCode  = chunk.ReadFromStream(indexStream);
                        if (resultCode == FileSystemResultCode.Success && fragment != null)
                        {
                            resultCode = fragment.ReadFromStream(indexStream);
                        }
                    }
                    catch
                    {
                        resultCode = FileSystemResultCode.IndexFileNotExistError;
                    }
                    finally
                    {
                        if (indexStream != null)
                        {
                            indexStream.Close();
                        }
                    }
                }
            }

            if (resultCode != FileSystemResultCode.Success)
            {
                content.Close();
                content  = null;
                fragment = null;
                chunk    = null;
            }

            return(resultCode);
        }