コード例 #1
0
ファイル: YpkUtility.cs プロジェクト: efonte/PeaceWalkerTools
        public static void ReplaceText(string sourcePath, string location)
        {
            var workbook = Workbook.Load(sourcePath);

            var sheetMap = workbook.Worksheets.ToDictionary(x => x.Name, x => GetTextList(x));

            var files = Directory.GetFiles(location, "*.ypk");

            foreach (var file in files)
            {
                var olang  = YPK.Read(file);
                var korean = sheetMap[Path.GetFileNameWithoutExtension(file)];

                var list = olang.Entities.SelectMany(x => x.Lines).ToList();

                if (korean.Count != list.Count)
                {
                }
                for (int i = 0; i < list.Count; i++)
                {
                    if (!string.IsNullOrWhiteSpace(korean[i]))
                    {
                        list[i].Text = korean[i].ReplaceWideCharacters();
                    }
                }


                olang.Write(file);
            }
        }
コード例 #2
0
ファイル: YPK.cs プロジェクト: efonte/PeaceWalkerTools
        public static YPK Read(string path)
        {
            var ypk = new YPK();

            using (var reader = new BinaryReader(new MemoryStream(File.ReadAllBytes(path)), Encoding.UTF8))
            {
                while (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    var entity = new Entity();
                    ypk.Entities.Add(entity);
                    var start = reader.BaseStream.Position;
                    reader.ReadInt32();                 // 'GTT\0'
                    var lineCount = reader.ReadInt32(); // LineCount
                    var textStart = reader.ReadInt32(); // TextStart
                    reader.ReadInt32();                 // TotalLength

                    for (int i = 0; i < lineCount; i++)
                    {
                        var sub = new Line();
                        entity.Lines.Add(sub);

                        sub.SyncStart = reader.ReadInt16();
                        sub.SyncEnd   = reader.ReadInt16();
                        sub.Unknown   = reader.ReadInt16();

                        sub.TextStart = reader.ReadInt16();
                        reader.ReadInt16();

                        sub.TextEnd = reader.ReadInt16();
                        reader.ReadInt16();
                        reader.ReadInt16();
                        reader.ReadInt16();
                        reader.ReadInt16();
                    }

                    for (int i = 0; i < lineCount; i++)
                    {
                        reader.BaseStream.Position = start + textStart + entity.Lines[i].TextStart;
                        var textLength = entity.Lines[i].TextEnd - entity.Lines[i].TextStart;
                        var text       = Encoding.UTF8.GetString(reader.ReadBytes(textLength), 0, textLength - 1);
                        entity.Lines[i].Text = text.Replace("\\n", "\n");
                    }

                    reader.BaseStream.Position += (16 - reader.BaseStream.Position % 16) % 16;
                }
            }

            return(ypk);
        }
コード例 #3
0
ファイル: YpkUtility.cs プロジェクト: efonte/PeaceWalkerTools
        public static void ExportToExcel()
        {
            var workbook = new Workbook(WorkbookFormat.Excel2007);

            foreach (var path in Directory.GetFiles("ypk", "*.ypk"))
            {
                var location = Path.GetDirectoryName(path);
                var sheet    = workbook.Worksheets.Add(Path.GetFileNameWithoutExtension(path));

                var ypk = YPK.Read(path);

                var index    = 0;
                var rowIndex = 1;

                sheet.Rows[0].Cells[0].Value = "Index";
                sheet.Rows[0].Cells[1].Value = "SyncStart";
                sheet.Rows[0].Cells[2].Value = "SyncEnd";
                sheet.Rows[0].Cells[3].Value = "Unknown";
                sheet.Rows[0].Cells[4].Value = "Japanese";
                sheet.Rows[0].Cells[5].Value = "Korean";

                sheet.Columns[4].SetWidth(420, WorksheetColumnWidthUnit.Pixel);
                sheet.Columns[5].SetWidth(420, WorksheetColumnWidthUnit.Pixel);

                foreach (var entity in ypk.Entities)
                {
                    foreach (var line in entity.Lines)
                    {
                        var row = sheet.Rows[rowIndex++];
                        row.Cells[0].Value = index;
                        row.Cells[1].Value = line.SyncStart;
                        row.Cells[2].Value = line.SyncEnd;
                        row.Cells[3].Value = line.Unknown;
                        row.Cells[4].Value = line.Text;
                    }

                    index++;
                }
                //var fileName = Path.GetFileName(path);
                //var export = Path.Combine(location, "xml", string.Format("{0}.xml", fileName));
                //SerializationHelper.Save(ypk, export);

                //ypk = SerializationHelper<YPK>.Read(export);
                //ypk.Write(Path.Combine(location, "New", fileName));
            }
            workbook.Save("ypk.xlsx");
        }