コード例 #1
0
 public static RateTableFile New(RateTableFileInfo info)
 {
     return new RateTableFile()
     {
         FileName = info.FileName,
         FileType = (int) info.FileType,
         FileData = info.FileData.ToArray(),
         Checksum = info.Checksum
     };
 }
コード例 #2
0
        private ScenarioResult<List<RateTableFileInfo>> ExtractFiles(Stream inputStream)
        {
            List<RateTableFileInfo> rateTableFileList = new List<RateTableFileInfo>();
            using (ZipArchive archive = new ZipArchive(inputStream))
            {
                if (null != archive.Entries)
                {
                    foreach (var entry in archive.Entries)
                    {
                        //start with basic file info
                        RateTableFileInfo fileInfo = new RateTableFileInfo();
                        fileInfo.FileName = entry.Name;
                        switch (Path.GetExtension(entry.Name))
                        {
                            case ".meta":
                                fileInfo.FileType = EFileType.Meta;
                                break;
                            case ".bin":
                                fileInfo.FileType = EFileType.RateTable;
                                break;
                            case ".amx":
                                fileInfo.FileType = EFileType.PawnCode;
                                break;
                            case ".data":
                                fileInfo.FileType = EFileType.Zip2Zone;
                                break;
                            default:
                                fileInfo.FileType = EFileType.Undefined;
                                break;
                        }
                        using (MemoryStream reader = new MemoryStream())
                        {
                            int read;
                            byte[] buffer = new byte[entry.Length];
                            using (Stream input = entry.Open())
                            {
                                while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    reader.Write(buffer, 0, read);
                                }
                                fileInfo.FileData = new List<byte>(reader.ToArray());

                                rateTableFileList.Add(fileInfo);
                            }
                        }
                    }
                }
            }
            return new ScenarioResult<List<RateTableFileInfo>>() { Success = true, Value = rateTableFileList };
        }