public static bool Read(int skin, IFileEntry file,
            ref Dictionary<String, String> animations, Logger logger)
        {
            bool result = true;

            logger.Event("Parsing animation list: " + file.FileName );

            try
            {
                // Get the data from the archive
                MemoryStream myInput = new MemoryStream( file.GetContent() );
                StreamReader reader = new StreamReader(myInput);

                ParseAnimations(skin, reader, ref animations);

                reader.Close();
                myInput.Close();
            }
            catch
            {
                logger.Error("Failed to parse animation list: " + file.FileName);

                result = false;
                animations.Clear();
            }

            return result;
        }
        public static bool Read(IFileEntry file, ref InibinFile data, Logger logger)
        {
            bool result = true;

            logger.Event("Reading inibin: " + file.FileName);

            try
            {
                // Get the data from the archive
                MemoryStream myInput = new MemoryStream( file.GetContent() );
                result = ReadCharacterInibin(myInput, ref data, logger);

                int end = file.FileName.LastIndexOf("/");
                String directory = file.FileName.Substring(0, end);
                String archive = file.GetRootPath();
                archive = archive.Replace("\\", "/");
                end = archive.LastIndexOf("/");
                archive = archive.Substring(0, end);

                data.directory = new DirectoryInfo(archive + "/" + directory);
                myInput.Close();
            }
            catch(Exception e)
            {
                logger.Error("Unable to open memory stream: " + file.FileName);
                logger.Error(e.Message);
                result = false;
            }

            return result;
        }
Exemple #3
0
        public FileMatch(IFileEntry sourceFile, IFileEntry destinationFile)
        {
            if (sourceFile == null)
            {
                throw new ArgumentNullException("sourceFile");
            }

            if (destinationFile == null)
            {
                throw new ArgumentNullException("destinationFile");
            }

            this.SourceFile = sourceFile;
            this.DestinationFile = destinationFile;
        }
Exemple #4
0
        /// <summary>
        /// Read in binary .anm file from RAF.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="data">The contents of the file are stored in here.</param>
        /// <returns></returns>
        public static bool Read(IFileEntry file, ref ANMFile data, Logger logger)
        {
            bool result = true;

            logger.Event("Reading anm: " + file.FileName);

            try
            {
                // Get the data from the archive
                MemoryStream myInput = new MemoryStream( file.GetContent() );
                result = ReadBinary(myInput, ref data, logger);
                myInput.Close();
            }
            catch(Exception e)
            {
                logger.Error("Unable to open memory stream: " + file.FileName);
                logger.Error(e.Message);
                result = false;
            }

            return result;
        }
Exemple #5
0
 /// <summary>
 /// Initialize<br/>
 /// 初始化<br/>
 /// </summary>
 /// <param name="fileEntry">File entry</param>
 public FileEntryResult(IFileEntry fileEntry) :
     this(fileEntry, null, Pair.Create <long?, long?>(null, null))
 {
 }
 public Task ArchiveAsync(IFileEntry fileEntry, CancellationToken cancellationToken = default)
 {
     return(Task.CompletedTask);
 }
 public Task CreateAsync(IFileEntry fileEntry, Stream stream, CancellationToken cancellationToken = default)
 {
     fileEntry.FileLocation = "Fake.txt";
     return(Task.CompletedTask);
 }
 public FileEndedEventArgs(IFileEntry file, bool success)
 {
     File    = file;
     Success = success;
 }
 /// <inheritdoc/>
 public abstract void MoveEntry(IFileEntry entry, string newPath);
Exemple #10
0
 public IFileSystemFile GetFileSystemFile(IFileEntry fileEntry)
 {
     return new FileSystemFile(fileEntry);
 }
Exemple #11
0
 /// <inheritdoc/>
 public Task UpdateFileWrittenAsync(IFileEntry fileEntry, long position, byte[] data)
 {
     return(Written.InvokeAsync(new(fileEntry, position, data) ));
 }
Exemple #12
0
 /// <summary>
 /// 获取局部文件流列表
 /// </summary>
 /// <param name="filenames"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <param name="totalLength"></param>
 /// <param name="actualLength"></param>
 /// <param name="actualStart"></param>
 /// <param name="actualEnd"></param>
 /// <returns></returns>
 public static IEnumerable <IFileEntry> GetEntries(IEnumerable <string> filenames, long start, long end, out long totalLength, out long actualLength, out long actualStart, out long actualEnd, out bool outOfRange)
 {
     outOfRange = false;
     if (filenames != null && filenames.Any())
     {
         actualStart = start;
         actualEnd   = end;
         IEnumerable <IFileEntry> entries = GetEntries(filenames, out totalLength);
         if (entries.Any())
         {
             if (start >= totalLength - 1)
             {
                 actualStart = 0;
             }
             if (end < 0)
             {
                 actualEnd = totalLength - 1;
             }
             actualLength = actualEnd - actualStart + 1;
             if (end >= totalLength || start >= totalLength || (end >= 0 && start > end))
             {
                 outOfRange = true;
                 return(entries.ToArray());
             }
             long slot = 0, slot0 = 0;
             int  skip = 0;
             int  take = 0;
             foreach (IFileEntry file in entries)
             {
                 slot += file.Length;
                 if (start >= slot)  // skip掉它!
                 {
                     skip++;
                     slot0 = slot;
                 }
                 else if (end < 0) // 全部读取,则直接中断循环即可
                 {
                     take = entries.Count() - skip;
                     break;
                 }
                 else if (end <= slot)    // take它!为什么用<=而不是<? 答:如果end=slot,则表示取序号0的1个字节,所以这个entry还是应该take
                 {
                     take++;
                 }
                 else
                 {
                     break;
                 }
             }
             entries = entries.Skip(skip).Take(take).ToArray();
             IFileEntry firstFile = entries.First();
             firstFile.StartPosition = start - slot0;
             if (end >= 0)
             {
                 IFileEntry lastFile = entries.Last();
                 lastFile.EndPosition = lastFile.Length + end - slot;
             }
             return(entries);
         }
     }
     totalLength = actualLength = actualStart = 0;
     actualEnd   = -1;
     return(new IFileEntry[0]);
 }
Exemple #13
0
 /// <summary>
 /// Write byte array to file
 /// </summary>
 /// <param name="entry">File entry</param>
 /// <param name="bytes">Byte array</param>
 public static void WriteAllBytes(this IFileEntry entry, byte[] bytes)
 {
     using (var stream = entry.OpenWrite()) {
         stream.Write(bytes, 0, bytes.Length);
     }
 }
Exemple #14
0
 /// <summary>
 /// Initialize<br/>
 /// 初始化<br/>
 /// </summary>
 /// <param name="fileEntry">File entry</param>
 /// <param name="bytesRange">Range request in bytes</param>
 public FileEntryResult(IFileEntry fileEntry, Pair <long?, long?> bytesRange) :
     this(fileEntry, null, bytesRange)
 {
 }
Exemple #15
0
 /// <summary>
 /// Initialize<br/>
 /// 初始化<br/>
 /// </summary>
 /// <param name="fileEntry">File entry</param>
 /// <param name="ifModifiedSince">Cached modify time received from client</param>
 public FileEntryResult(IFileEntry fileEntry, DateTime?ifModifiedSince) :
     this(fileEntry, ifModifiedSince, Pair.Create <long?, long?>(null, null))
 {
 }
 /// <summary>
 /// A default <see cref="FileEndedEventArgs"/> constructor.
 /// </summary>
 /// <param name="file">File that is ended.</param>
 /// <param name="success">Result of file end upload.</param>
 /// <param name="fileInvalidReason">Reason for file failure.</param>
 public FileEndedEventArgs(IFileEntry file, bool success, FileInvalidReason fileInvalidReason)
 {
     File              = file;
     Success           = success;
     FileInvalidReason = fileInvalidReason;
 }
Exemple #17
0
        public RemoteFileEntryStream(IJSFileModule jsModule, ElementReference elementRef, IFileEntry fileEntry, IFileEntryNotifier fileEntryNotifier, int maxMessageSize, TimeSpan segmentFetchTimeout, CancellationToken cancellationToken)
        {
            this.jsModule            = jsModule;
            this.elementRef          = elementRef;
            this.fileEntry           = fileEntry;
            this.fileEntryNotifier   = fileEntryNotifier;
            this.maxMessageSize      = maxMessageSize;
            this.segmentFetchTimeout = segmentFetchTimeout;
            fillBufferCts            = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
            var pipe = new Pipe(new(pauseWriterThreshold: this.maxMessageSize, resumeWriterThreshold: this.maxMessageSize) );

            pipeReader = pipe.Reader;

            _ = FillBuffer(pipe.Writer, fillBufferCts.Token);
        }
 /// <inheritdoc/>
 public virtual Task MoveEntryAsync(IFileEntry entry, string newPath)
 {
     MoveEntry(entry, newPath);
     return(Task.CompletedTask);
 }
 public FileWrittenEventArgs(IFileEntry file, long position, byte[] data)
 {
     File     = file;
     Position = position;
     Data     = data;
 }
 public async Task DeleteAsync(IFileEntry fileEntry, CancellationToken cancellationToken = default)
 {
     await _client.DeleteObjectAsync(_bucketName, fileEntry.FileLocation, cancellationToken);
 }
 public FileProgressedEventArgs(IFileEntry file, double progress)
 {
     File     = file;
     Progress = progress;
 }
 public Task <byte[]> ReadAsync(IFileEntry fileEntry, CancellationToken cancellationToken = default)
 {
     return(Task.FromResult(Encoding.UTF8.GetBytes("The content is generated by Fake Storage Manager.")));
 }
 public FileStartedEventArgs(IFileEntry file)
 {
     File = file;
 }
Exemple #24
0
 public void CopyFile(IFileEntry source, IFileEntry destination)
 {
     File.Copy(source.FilePath, destination.FilePath, true);
 }
Exemple #25
0
 internal Task UpdateFileEndedAsync(IFileEntry fileEntry, bool success)
 {
     return(Ended.InvokeAsync(new FileEndedEventArgs(fileEntry, success)));
 }
 public FileSystemFile(IFileEntry fileEntry)
 {
     this.fileEntry = fileEntry;
 }
Exemple #27
0
 internal Task UpdateFileWrittenAsync(IFileEntry fileEntry, long position, byte[] data)
 {
     return(Written.InvokeAsync(new FileWrittenEventArgs(fileEntry, position, data)));
 }
 public FileInstance(IFileEntry entry, ReadOnlyFileSystem fileSystem)
 {
     FileEntry  = entry;
     FileSystem = fileSystem;
 }
Exemple #29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            /*
             * 需求
             * 1、支持存储扩展:磁盘文件系统..........................DONE
             * 2、支持存储扩展:MongoDB GridFS........................DONE
             * 3、支持GFS存储
             * 4、支持FTP存储
             * 5、支持下载断点续传....................................DONE
             * 6、支持文件压缩
             * 7、支持文件合并........................................DONE
             * 8、支持css/js压缩 .....................................DONE
             * 9、支持客户端缓存(强验证 弱验证).....................DONE
             */
            Response.ClearHeaders();

            string filename = Request["f"];

            if (!string.IsNullOrEmpty(filename))
            {
                string mimeType;
                IEnumerable <string> filenames = FileHelper.ParseFilenames(filename, out mimeType);
                Response.ContentType = mimeType;

                long start = 0, end = 0, length, totalLength;

                DateTime lastModified;
                string   range =
                    Request.Headers["Range"],
                         ifrangeETag = Request.Headers["If-Range"],
                         ifnmETag    = Request.Headers["If-None-Match"],
                         eTag        = FileHelper.GetETag(filenames, out lastModified, true);


                Response.Cache.SetMaxAge(TimeSpan.FromMinutes(1));


                // If-None-Matched的处理(304的处理)
                if (string.IsNullOrEmpty(range) && !string.IsNullOrEmpty(ifnmETag) && ifnmETag == eTag) // 在不存在Range的前提下,如果存在etag,并且匹配,则返回304(除非有range)
                {
                    End304(eTag);
                    return;
                }

                if (!string.IsNullOrEmpty(range))
                {
                    Response.AddHeader("Accept-Ranges", "bytes");
                    ParseRange(range, out start, out end);
                    //eTag = FileHelper.GetETag(lastModified, start, end);

                    // If-Range的处理
                    if (!string.IsNullOrEmpty(ifrangeETag) && ifrangeETag != eTag) // 在range存在的前提下,如果有if-range,并且客户端文件已经失效,则返回整个服务器端文件(设置起始均为0,重新设置etag)
                    {
                        start = 0;
                        end   = -1;
                        //Response.StatusCode = 200;
                    }
                    else
                    {
                        Response.StatusCode = 206;  // HTTP 206: partial content(局部内容)
                    }
                }

                // 输出文件内容
                IEnumerable <IFileEntry> entries;
                if (Response.StatusCode == 206)
                {
                    bool outOfRange;
                    entries = FileHelper.GetEntries(filenames, start, end, out totalLength, out length, out start, out end, out outOfRange);
                    if (outOfRange && ifrangeETag != null)
                    {
                        Response.StatusCode = 200;
                    }
                    else
                    {
                        Response.AddHeader("Content-Range", string.Format(end >= totalLength - 1 ? "bytes {0}-/{2}" : "bytes {0}-{1}/{2}", start, end, totalLength));
                        if (outOfRange)
                        {
                            EndResponse(416);
                            return;
                        }
                    }
                }
                else
                {
                    entries = FileHelper.GetEntries(filenames, out length);
                }
                if (!entries.Any())
                {
                    EndResponse(404);
                    return;
                }

                if (Response.StatusCode == 200)
                {
                    if (Request.QueryString["min"] != null)
                    {
                        entries = new IFileEntry[] { new MiniFileEntry {
                                                         Entries = entries
                                                     } };
                        length = entries.First().Length;
                    }
                    Response.Cache.SetLastModified(lastModified);
                }

                Response.AddHeader("Content-Length", length.ToString());
                Response.AddHeader("ETag", eTag);
                FileHelper.OutputTo(entries, Response.OutputStream);

                Response.End();
            }
            else
            {
                EndResponse(403);
            }
        }