public Result Open(ref DirectoryName name)
        {
            if (!name.IsValid())
            {
                return(ResultBcat.InvalidArgument.Log());
            }

            lock (Locker)
            {
                if (IsDirectoryOpen)
                {
                    return(ResultBcat.AlreadyOpen.Log());
                }

                var    metaReader = new DeliveryCacheFileMetaAccessor(Server);
                Result rc         = metaReader.ReadApplicationFileMeta(ApplicationId, ref name, false);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                Count           = metaReader.Count;
                _name           = name;
                IsDirectoryOpen = true;

                return(Result.Success);
            }
        }
Example #2
0
        public Result Open(ref DirectoryName directoryName, ref FileName fileName)
        {
            if (!directoryName.IsValid())
            {
                return(ResultBcat.InvalidArgument.Log());
            }

            if (!fileName.IsValid())
            {
                return(ResultBcat.InvalidArgument.Log());
            }

            lock (Locker)
            {
                if (IsFileOpen)
                {
                    return(ResultBcat.AlreadyOpen.Log());
                }

                var    metaReader = new DeliveryCacheFileMetaAccessor(Server);
                Result rc         = metaReader.ReadApplicationFileMeta(ApplicationId, ref directoryName, true);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                rc = metaReader.FindEntry(out DeliveryCacheFileMetaEntry entry, ref fileName);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                Span <byte> filePath = stackalloc byte[0x80];
                Server.GetStorageManager().GetFilePath(filePath, ApplicationId, ref directoryName, ref fileName);

                rc = Server.GetFsClient().OpenFile(out _handle, new U8Span(filePath), OpenMode.Read);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                _metaEntry = entry;
                IsFileOpen = true;

                return(Result.Success);
            }
        }