Esempio n. 1
0
 static void ImportPTP(GameFile objectFile, string value, string openedFileDir, Parameters parameters)
 {
     if (objectFile.GameData is BMD bmd)
     {
         string path = Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name.Replace('/', '+')) + ".PTP");
         if (File.Exists(path))
         {
             PTP PTP  = new PTP(File.ReadAllBytes(path));
             var temp = new BMD(PTP, Static.NewEncoding());
             temp.IsLittleEndian = bmd.IsLittleEndian;
             objectFile.GameData = temp;
         }
     }
 }
Esempio n. 2
0
        static void SaveFile(GameFile objectFile, string savePath, string openedFileDir, Parameters parameters)
        {
            if (objectFile.GameData is PTP ptp)
            {
                if (parameters.AsBMD)
                {
                    string   path     = savePath == "" ? Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name) + ".BMD") : savePath;
                    Encoding encoding = Static.NewEncoding();

                    BMD bmd = new BMD(objectFile.GameData as PTP, encoding);
                    File.WriteAllBytes(path, bmd.GetData());
                }
                else
                {
                    string path = savePath == "" ? Path.Combine(openedFileDir, objectFile.Name) : savePath;
                    File.WriteAllBytes(path, ptp.GetData());
                }
            }
            else
            {
                string path = savePath == "" ? Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name) + "(NEW)" + Path.GetExtension(objectFile.Name)) : savePath;
                File.WriteAllBytes(path, objectFile.GameData.GetData());
            }
        }
Esempio n. 3
0
        static void ImportText(GameFile objectFile, string value, string openedFileDir, Parameters parameters)
        {
            if (objectFile.GameData is PTP ptp)
            {
                string path = value == "" ? Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name) + ".TXT") : value;

                if (File.Exists(path))
                {
                    List <string[]> import = File.ReadAllLines(path, parameters.FileEncoding).Select(x => x.Split('\t')).ToList();

                    LineMap MAP = new LineMap(parameters.Map);

                    if (parameters.LineByLine)
                    {
                        if (MAP[LineMap.Type.NewText] >= 0)
                        {
                            string[] importedText = import
                                                    .Select(x => x[MAP[LineMap.Type.NewText]])
                                                    .ToArray();
                            ptp.ImportTextLBL(importedText);
                        }
                    }
                    else
                    {
                        if (MAP[LineMap.Type.FileName] >= 0
                            & MAP[LineMap.Type.MSGindex] >= 0
                            & MAP[LineMap.Type.StringIndex] >= 0
                            & MAP[LineMap.Type.NewText] >= 0)
                        {
                            string[][] importedText = import
                                                      .Where(x => x.Length >= MAP.MinLength)
                                                      .Where(x => x[MAP[LineMap.Type.FileName]].Equals(objectFile.Name, StringComparison.CurrentCultureIgnoreCase))
                                                      .Where(x => x[MAP[LineMap.Type.NewText]] != "")
                                                      .Select(x => new string[]
                            {
                                x[MAP[LineMap.Type.MSGindex]],
                                x[MAP[LineMap.Type.StringIndex]],
                                x[MAP[LineMap.Type.NewText]]
                            })
                                                      .ToArray();

                            if (parameters.Width > 0)
                            {
                                var charWidth = Static.NewFont().GetCharWidth(Static.NewEncoding());
                                ptp.ImportText(importedText, charWidth, parameters.Width);
                            }
                            else
                            {
                                ptp.ImportText(importedText);
                            }
                        }
                    }

                    if (MAP[LineMap.Type.OldName] >= 0 & MAP[LineMap.Type.NewName] >= 0)
                    {
                        Dictionary <string, string> importedText = import
                                                                   .Where(x => x.Length >= MAP.MinLength)
                                                                   .GroupBy(x => x[MAP[LineMap.Type.OldName]])
                                                                   .ToDictionary(x => x.Key, x => x.First()[MAP[LineMap.Type.NewName]]);
                        ptp.ImportNames(importedText, Static.OldEncoding());
                    }
                }
            }
            else if (objectFile.GameData is StringList strlst)
            {
                string path = value == "" ? Path.Combine(openedFileDir, Path.GetFileNameWithoutExtension(objectFile.Name) + ".TXT") : value;
                if (File.Exists(path))
                {
                    string[][] importedtext = File.ReadAllLines(path, parameters.FileEncoding).Select(x => x.Split('\t')).
                                              Where(x => x.Length > 1 && x[1] != "").ToArray();
                    strlst.ImportText(importedtext);
                }
            }
        }