Exemplo n.º 1
0
        public static void WriteFile(Stream stream, XlsxReader xlsx)
        {
            List <Record> list       = xlsx.GetRows("iiiiiIII", "skillBoard").ToList();
            List <Record> stringList = xlsx.GetRows("IIX", "skillBoardStrings").ToList();
            Binary        binary     = new Binary(stream, true);

            List <byte> strBuf = new List <byte>();

            foreach (Record record in stringList)
            {
                record[0] = strBuf.Count / 2;
                var buf = ImasEncoding.Custom.GetBytes((string)record[2]);
                strBuf.AddRange(buf);
                strBuf.Add(0);
                strBuf.Add(0);
            }

            int recordCount = list.Count;

            binary.WriteInt32(recordCount);
            int strBufLen = strBuf.Count / 2;

            binary.WriteInt32(strBufLen);
            stream.Write(strBuf.ToArray());

            for (int i = 0; i < recordCount; i++)
            {
                list[i][2] = stringList[(int)list[i][5]][0];
                list[i][3] = stringList[(int)list[i][6]][0];
                list[i][4] = stringList[(int)list[i][7]][0];
                list[i].Serialise(stream);
            }
        }
Exemplo n.º 2
0
        public async Task GetAndWriteAllCommus(PatchZipFile patchZipFile, IProgress <ProgressData> progress1 = null, IProgress <ProgressData> progress2 = null)
        {
            var commuSheets = xlsx.Sheets.Descendants <Sheet>().Where(sheet => CommuLine.commuSheetNames.Contains(sheet.Name));
            int total1      = commuSheets.Count();
            int count1      = 0;

            foreach (Sheet sheet in commuSheets)
            {
                count1++;
                progress1?.Report(new ProgressData {
                    count = count1, total = total1, filename = sheet.Name
                });
                IEnumerable <CommuLine> lines = await Task.Run(() => xlsx.GetRows <CommuLine>(sheet, progress2));

                IEnumerable <string> commuFilenames = lines.Select(line => line.file).Distinct();
                int total2 = commuFilenames.Count();
                int count2 = 0;
                foreach (string filename in commuFilenames)
                {
                    count2++;
                    var fileLines = lines.Where(line => line.file == filename);
                    if (!patchZipFile.HasFile(filename) && fileLines.Any(line => !string.IsNullOrWhiteSpace(line.message)))
                    {
                        progress2?.Report(new ProgressData {
                            count = count2, total = total2, filename = filename
                        });
                        await Task.Run(() => patchZipFile.AddCommu(filename, fileLines));
                    }
                }
            }
        }
Exemplo n.º 3
0
        public async Task AddGtfs(string dirName, IProgress <ProgressData> progress = null)
        {
            DirectoryInfo    dInfo     = new DirectoryInfo(dirName);
            HashSet <string> filenames =
                new HashSet <string>(dInfo.GetFiles("*.png")
                                     .Select(fInfo => fInfo.Name));

            string               filenameXlsxName = dirName + "/filenames.xlsx";
            XlsxReader           xlsx             = new XlsxReader(filenameXlsxName);
            IEnumerable <Record> records          = (await Task.Run(() => xlsx.GetRows("XXI", "filenames")))
                                                    .Where(record => filenames.Contains((string)record[1]));
            int total = records.Count();
            int count = 0;

            foreach (Record record in records)
            {
                string entryName = (string)record[0];
                string pngName   = dInfo.FullName + '\\' + (string)record[1];
                count++;
                progress?.Report(new ProgressData {
                    count = count, total = total, filename = entryName
                });
                if (!HasFile(entryName))
                {
                    ZipArchiveEntry entry = zipArchive.CreateEntry(entryName);
                    using Stream entryStream = entry.Open();
                    await GTF.WriteGTF(entryStream, new System.Drawing.Bitmap(pngName), (int)record[2]);

                    _entries.Add(new PatchZipEntry(entry));
                }
            }
        }
Exemplo n.º 4
0
 public void PastblWriteTest(string binName, string xlsxName, string alfFileName)
 {
     using XlsxReader xlsx = new XlsxReader(xlsxName);
     List<string> strings = xlsx.GetRows("XX", "pastbl")
         .Where(record => (string)record[0] == alfFileName)
         .Select(record => (string)record[1])
         .ToList();
     using FileStream stream = new FileStream(binName, FileMode.Create, FileAccess.Write);
     Pastbl.WriteFile(stream, strings);
 }
Exemplo n.º 5
0
        public static void WriteFile(Stream stream, XlsxReader xlsx)
        {
            List <Record> mails = new List <Record>();

            foreach (string sheetName in allMailSheetNames)
            {
                mails.AddRange(xlsx.GetRows(mailFormat, sheetName));
            }
            mails.Sort((record1, record2) => ((short)record1[0]).CompareTo((short)record2[0]));
            Record.WriteRecords(stream, mails);
        }
Exemplo n.º 6
0
        private void AddStageInfoFiles(XlsxReader xlsx, IProgress <string> progress)
        {
            progress?.Report(string.Format("Adding stageInfo"));
            IEnumerable <Record> records = xlsx.GetRows(StageInfo.format, StageInfo.sheetName);

            foreach (Record record in records)
            {
                ZipArchiveEntry entry = zipArchive.CreateEntry(StageInfo.parFilePath + (string)record[0]);
                using Stream entryStream = entry.Open();
                record.Serialise(entryStream);
                _entries.Add(new PatchZipEntry(entry));
            }
        }
Exemplo n.º 7
0
 public void WriteRecordTest(string xlsxName, string sheetName, string format)
 {
     using XlsxReader xlsx = new XlsxReader(xlsxName);
     var records = xlsx.GetRows(format, sheetName);
     using (FileStream fileStream = new FileStream("temp.bin", FileMode.Create, FileAccess.Write))
     {
         foreach (Record record in records)
         {
             record.Serialise(fileStream);
         }
     }
     File.Delete("temp.bin");
 }
Exemplo n.º 8
0
        public static void WriteFile(Stream stream, XlsxReader xlsxReader)
        {
            IEnumerable <Record> records = xlsxReader.GetRows(format, "songInfo");
            int recCount = records.Count();

            Binary binary = new Binary(stream, true);

            binary.WriteUInt64(0x534F4E47494E464F);
            binary.WriteInt32(recCount);
            foreach (Record record in records)
            {
                record.Serialise(stream);
            }
        }
Exemplo n.º 9
0
 private void AddRecordFormatFiles(XlsxReader xlsx, IProgress <string> progress)
 {
     foreach (RecordFormat format in RecordFormat.formats)
     {
         if (!HasFile(format.fileName))
         {
             progress?.Report(string.Format("Adding {0}", format.fileName));
             IEnumerable <Record> records = xlsx.GetRows(format.format, format.sheetName);
             if (records.Any())
             {
                 ZipArchiveEntry entry = zipArchive.CreateEntry(format.fileName);
                 using Stream entryStream = entry.Open();
                 Record.WriteRecords(entryStream, records);
                 _entries.Add(new PatchZipEntry(entry));
             }
         }
     }
 }
Exemplo n.º 10
0
        private void AddCatalogFiles(XlsxReader xlsx, IProgress <string> progress)
        {
            progress?.Report(string.Format("Adding catalogs"));
            IEnumerable <Record> records = xlsx.GetRows(Catalog.format, Catalog.sheetName);

            foreach (string filename in Catalog.fileNames)
            {
                var fileRecords = records.Where(record => (string)record[0] == filename).ToList();
                if (fileRecords.Any())
                {
                    ZipArchiveEntry entry = zipArchive.CreateEntry(filename);
                    using Stream entryStream = entry.Open();
                    foreach (Record record in fileRecords)
                    {
                        record.Serialise(entryStream);
                    }
                    _entries.Add(new PatchZipEntry(entry));
                }
            }
        }
Exemplo n.º 11
0
 private void AddPastblFiles(XlsxReader xlsx, IProgress <string> progress)
 {
     foreach (string fileName in Pastbl.fileNames)
     {
         if (!HasFile(fileName))
         {
             progress?.Report(string.Format("Adding {0}", fileName));
             List <string> strings = xlsx.GetRows("XX", "pastbl")
                                     .Where(record => (string)record[0] == fileName)
                                     .Select(record => (string)record[1])
                                     .ToList();
             if (strings.Any())
             {
                 ZipArchiveEntry entry = zipArchive.CreateEntry(fileName);
                 using Stream entryStream = entry.Open();
                 Pastbl.WriteFile(entryStream, strings);
                 _entries.Add(new PatchZipEntry(entry));
             }
         }
     }
 }
Exemplo n.º 12
0
        public async Task AddLyrics(string dirName, IProgress <ProgressData> progress = null)
        {
            DirectoryInfo    dInfo     = new DirectoryInfo(dirName);
            HashSet <string> filenames =
                new HashSet <string>(dInfo.GetFiles("*.xml")
                                     .Select(fInfo => fInfo.Name));

            string               filenameXlsxName = dirName + "/filenames.xlsx";
            XlsxReader           xlsx             = new XlsxReader(filenameXlsxName);
            IEnumerable <Record> records          = xlsx.GetRows("XX", "filenames")
                                                    .Where(record => filenames.Contains((string)record[1]));
            int total = records.Count();
            int count = 0;

            foreach (Record record in records)
            {
                string entryName = (string)record[0];
                string xmlName   = dInfo.FullName + '\\' + (string)record[1];
                count++;
                progress?.Report(new ProgressData {
                    count = count, total = total, filename = entryName
                });
                if (!HasFile(entryName))
                {
                    Xmb xmb = new Xmb();
                    using (FileStream xmlStream = new FileStream(xmlName, FileMode.Open, FileAccess.Read))
                    {
                        xmb.ReadXml(xmlStream);
                    }
                    ZipArchiveEntry entry = zipArchive.CreateEntry(entryName);
                    using Stream entryStream = entry.Open();
                    await xmb.WriteXmb(entryStream);

                    _entries.Add(new PatchZipEntry(entry));
                }
            }
        }
Exemplo n.º 13
0
        public static void WriteFile(Stream stream, XlsxReader xlsx)
        {
            var         stringList   = xlsx.GetRows("IIX", "fanLetterStrings").ToList();
            List <byte> stringBuffer = new List <byte>();

            foreach (Record record in stringList)
            {
                record[1] = stringBuffer.Count / 2;
                foreach (int n in Imas.ImasEncoding.Custom.GetValues((string)record[2]))
                {
                    stringBuffer.Add((byte)((n >> 8) & 0xFF));
                    stringBuffer.Add((byte)(n & 0xFF));
                }
                stringBuffer.Add(0);
                stringBuffer.Add(0);
            }

            var records1 = xlsx.GetRows("iiiss", "fanLetterInfo1").ToList();

            Binary.WriteInt32(stream, true, records1.Count);
            foreach (Record record in records1)
            {
                record.Serialise(stream);
            }

            var records2 = xlsx.GetRows("iii", "fanLetterInfo2").ToList();

            Binary.WriteInt32(stream, true, records2.Count);
            foreach (Record record in records2)
            {
                record.Serialise(stream);
            }

            var records3 = xlsx.GetRows("iii", "fanLetterInfo3").ToList();

            Binary.WriteInt32(stream, true, records3.Count);
            foreach (Record record in records3)
            {
                record.Serialise(stream);
            }

            var records4 = xlsx.GetRows("ss", "fanLetterInfo4").ToList();

            Binary.WriteInt32(stream, true, records4.Count);
            foreach (Record record in records4)
            {
                record.Serialise(stream);
            }

            var letts = xlsx.GetRows("iiiiiiII", "fanLetterInts").ToList();

            Binary.WriteInt32(stream, true, letts.Count);
            foreach (Record record in letts)
            {
                record[4] = stringList[(int)record[6]][1];
                record[5] = stringList[(int)record[7]][1];
                record.Serialise(stream);
            }

            var records6 = xlsx.GetRows("i", "fanLetterInfo6").ToList();

            foreach (Record record in records6)
            {
                record.Serialise(stream);
            }

            stream.Write(stringBuffer.ToArray());
        }
Exemplo n.º 14
0
        public static void WriteFile(Stream stream, XlsxReader xlsx)
        {
            List <Record> list       = xlsx.GetRows("IIIII", "jaJp").ToList();
            List <Record> stringList = xlsx.GetRows("IIXI", "jaJpStrings").ToList();
            Binary        binary     = new Binary(stream, false);

            binary.WriteInt32(0);
            int stringOffset = 16 + 16 * list.Count;

            binary.WriteInt32(stringOffset);
            int recordCount = list.Count;

            binary.WriteInt32(recordCount);
            int data2Offset = 16 + 8 * list.Count;

            binary.WriteInt32(data2Offset);

            for (int i = 0; i < recordCount; i++)
            {
                binary.WriteInt32((int)list[i][0]);
                binary.WriteInt32((int)stringList[(int)list[i][4]][1]);
            }
            for (int i = 0; i < recordCount; i++)
            {
                binary.WriteInt32((int)list[i][2]);
                binary.WriteInt32((int)list[i][3]);
            }

            for (int i = 0; i < stringList.Count; i++)
            {
                stringList[i][1] = (int)(stream.Position - stringOffset);
                string outString = (string)stringList[i][2];
                if (outString.Length == 0)
                {
                    binary.WriteUInt16(0);
                    continue;
                }
                if (outString[0] != (char)0xFEFF)
                {
                    binary.WriteUInt16(0xFEFF);
                }
                if ((int)stringList[i][3] == 1)
                {
                    foreach (char c in outString)
                    {
                        binary.WriteUInt16((ushort)c);
                    }
                }
                else
                {
                    foreach (int n in Imas.ImasEncoding.Custom.GetValues(outString))
                    {
                        binary.WriteUInt16((ushort)n);
                    }
                }
                binary.WriteUInt16(0);
            }

            stream.Position = 16;
            for (int i = 0; i < recordCount; i++)
            {
                binary.WriteInt32((int)list[i][0]);
                binary.WriteInt32((int)stringList[(int)list[i][4]][1]);
            }
        }