コード例 #1
0
        /// <summary>
        /// Main function for automatic archive building from a folder.
        /// </summary>
        static void BuildFromFolder(string[] args)
        {
            bool createPB = false;

            filePath    = args[0];
            compressPRS = false;
            for (int a = 0; a < args.Length; a++)
            {
                if (args[a] == "-prs")
                {
                    compressPRS = true;
                }
                if (args[a] == "-pb")
                {
                    createPB = true;
                }
            }
            //Folder mode
            if (Directory.Exists(filePath))
            {
                GenericArchive arc;
                string         indexfilename = Path.Combine(filePath, "index.txt");
                List <string>  filenames     = new List <string>(File.ReadAllLines(indexfilename).Where(a => !string.IsNullOrEmpty(a)));
                string         ext           = Path.GetExtension(filenames[0]).ToLowerInvariant();
                switch (ext)
                {
                case ".pvr":
                    if (createPB)
                    {
                        folderMode = ArchiveFromFolderMode.PB;
                        arc        = new PBFile();
                    }
                    else
                    {
                        folderMode = ArchiveFromFolderMode.PVM;
                        arc        = new PuyoFile();
                    }
                    break;

                case ".gvr":
                    arc        = new PuyoFile(true);
                    folderMode = ArchiveFromFolderMode.GVM;
                    break;

                case ".wav":
                case ".adx":
                    folderMode = ArchiveFromFolderMode.DAT;
                    arc        = new DATFile();
                    break;

                case ".png":
                case ".jpg":
                case ".bmp":
                case ".dds":
                case ".gif":
                default:
                    folderMode = ArchiveFromFolderMode.PVMX;
                    arc        = new PVMXFile();
                    break;
                }
                Console.WriteLine("Creating {0} archive from folder: {1}", folderMode.ToString(), filePath);
                int id = 0;
                foreach (string line in filenames)
                {
                    string[] split    = line.Split(',');
                    string   filename = split[0];
                    switch (folderMode)
                    {
                    case ArchiveFromFolderMode.DAT:
                        arc.Entries.Add(new DATEntry(Path.Combine(filePath, filename)));
                        extension = ".dat";
                        break;

                    case ArchiveFromFolderMode.PVM:
                        arc.Entries.Add(new PVMEntry(Path.Combine(filePath, filename)));
                        extension = ".pvm";
                        break;

                    case ArchiveFromFolderMode.GVM:
                        arc.Entries.Add(new GVMEntry(Path.Combine(filePath, filename)));
                        extension = ".gvm";
                        break;

                    case ArchiveFromFolderMode.PB:
                        PBFile pbf = (PBFile)arc;
                        arc.Entries.Add(new PBEntry(Path.Combine(filePath, filename), pbf.GetCurrentOffset(id, filenames.Count)));
                        extension = ".pb";
                        break;

                    case ArchiveFromFolderMode.PVMX:
                        extension = ".pvmx";
                        filename  = split[1];
                        int  width  = 0;
                        int  height = 0;
                        uint gbix   = uint.Parse(split[0]);
                        if (split.Length > 2)
                        {
                            width  = int.Parse(split[2].Split('x')[0]);
                            height = int.Parse(split[2].Split('x')[1]);
                        }
                        arc.Entries.Add(new PVMXEntry(Path.GetFileName(filename), gbix, File.ReadAllBytes(Path.Combine(filePath, filename)), width, height));
                        break;

                    default:
                        extension = ".bin";
                        break;
                    }
                    Console.WriteLine("Added entry {0}: {1}", id.ToString(), filename);
                    id++;
                }
                byte[] data = arc.GetBytes();
                outputPath = Path.GetFullPath(filePath) + extension;
                if (compressPRS)
                {
                    Console.WriteLine("Compressing to PRS...");
                    data       = FraGag.Compression.Prs.Compress(data);
                    outputPath = Path.ChangeExtension(outputPath, ".PRS");
                }
                Console.WriteLine("Output file: {0}", outputPath);
                File.WriteAllBytes(outputPath, data);
            }
        }
コード例 #2
0
        /// <summary>
        /// Main function for automatic archive building from a folder.
        /// </summary>
        static void BuildFromFolder(string[] args)
        {
            bool createPB   = false;
            bool createARCX = false;

            filePath    = args[0];
            compressPRS = false;
            for (int a = 0; a < args.Length; a++)
            {
                if (args[a] == "-prs")
                {
                    compressPRS = true;
                }
                if (args[a] == "-pb")
                {
                    createPB = true;
                }
                if (args[a] == "-arcx")
                {
                    createARCX = true;
                }
            }
            // Folder mode
            if (Directory.Exists(filePath))
            {
                GenericArchive arc;
                string         indexfilename = Path.Combine(filePath, "index.txt");
                if (createARCX)
                {
                    CreateARCX(filePath);
                    return;
                }
                if (!File.Exists(indexfilename))
                {
                    BuildPAK(filePath);
                    return;
                }
                List <string> filenames = new List <string>(File.ReadAllLines(indexfilename).Where(a => !string.IsNullOrEmpty(a)));
                string        ext       = Path.GetExtension(filenames[0]).ToLowerInvariant();
                if (filenames[0].Contains(","))
                {
                    string[] checkf = filenames[0].Split(',');
                    ext = Path.GetExtension(checkf[0].ToLowerInvariant());
                }
                switch (ext)
                {
                case ".pvr":
                    if (createPB)
                    {
                        folderMode = ArchiveFromFolderMode.PB;
                        arc        = new PBFile();
                    }
                    else
                    {
                        folderMode = ArchiveFromFolderMode.PVM;
                        arc        = new PuyoFile();
                    }
                    break;

                case ".gvr":
                    arc        = new PuyoFile(true);
                    folderMode = ArchiveFromFolderMode.GVM;
                    break;

                case ".xvr":
                    arc        = new XVM();
                    folderMode = ArchiveFromFolderMode.XVM;
                    break;

                case ".wav":
                case ".adx":
                    folderMode = ArchiveFromFolderMode.DAT;
                    arc        = new DATFile();
                    break;

                case ".mpb":
                case ".mdb":
                case ".msb":
                case ".osb":
                case ".fpb":
                case ".fob":
                case ".fpw":
                case ".psr":
                    folderMode = ArchiveFromFolderMode.MLT;
                    arc        = new MLTFile();
                    break;

                case ".gcaxmpb":
                case ".gcaxmsb":
                    folderMode = ArchiveFromFolderMode.gcaxMLT;
                    arc        = new gcaxMLTFile();
                    break;

                case ".png":
                case ".jpg":
                case ".bmp":
                case ".dds":
                case ".gif":
                default:
                    folderMode = ArchiveFromFolderMode.PVMX;
                    arc        = new PVMXFile();
                    break;
                }
                Console.WriteLine("Creating {0} archive from folder: {1}", folderMode.ToString(), filePath);
                int id = 0;
                foreach (string line in filenames)
                {
                    string[] split    = line.Split(',');
                    string   filename = split[0];
                    switch (folderMode)
                    {
                    case ArchiveFromFolderMode.gcaxMLT:
                        int bIDgc = int.Parse(split[1]);
                        arc.Entries.Add(new gcaxMLTEntry(Path.Combine(filePath, filename), bIDgc));
                        extension = ".mlt";
                        break;

                    case ArchiveFromFolderMode.MLT:
                        int    bID             = int.Parse(split[1]);
                        int    mem             = int.Parse(split[2], System.Globalization.NumberStyles.HexNumber);
                        int    sz              = int.Parse(split[3]);
                        int    version         = 1;
                        int    revision        = 1;
                        string versionfilename = Path.Combine(filePath, "version.txt");
                        if (File.Exists(versionfilename))
                        {
                            string[] ver = File.ReadAllLines(versionfilename);
                            version  = int.Parse(ver[0]);
                            revision = int.Parse(ver[1]);
                            MLTFile mlt = (MLTFile)arc;
                            mlt.Version  = (byte)version;
                            mlt.Revision = (byte)revision;
                        }
                        arc.Entries.Add(new MLTEntry(Path.Combine(filePath, filename), bID, mem, sz));
                        extension = ".mlt";
                        break;

                    case ArchiveFromFolderMode.DAT:
                        arc.Entries.Add(new DATEntry(Path.Combine(filePath, filename)));
                        extension = ".dat";
                        break;

                    case ArchiveFromFolderMode.PVM:
                        arc.Entries.Add(new PVMEntry(Path.Combine(filePath, filename)));
                        extension = ".pvm";
                        break;

                    case ArchiveFromFolderMode.GVM:
                        arc.Entries.Add(new GVMEntry(Path.Combine(filePath, filename)));
                        extension = ".gvm";
                        break;

                    case ArchiveFromFolderMode.PB:
                        PBFile pbf = (PBFile)arc;
                        arc.Entries.Add(new PBEntry(Path.Combine(filePath, filename), pbf.GetCurrentOffset(id, filenames.Count)));
                        extension = ".pb";
                        break;

                    case ArchiveFromFolderMode.PVMX:
                        extension = ".pvmx";
                        filename  = split[1];
                        int  width  = 0;
                        int  height = 0;
                        uint gbix   = uint.Parse(split[0]);
                        if (split.Length > 2)
                        {
                            width  = int.Parse(split[2].Split('x')[0]);
                            height = int.Parse(split[2].Split('x')[1]);
                        }
                        arc.Entries.Add(new PVMXEntry(Path.GetFileName(filename), gbix, File.ReadAllBytes(Path.Combine(filePath, filename)), width, height));
                        break;

                    case ArchiveFromFolderMode.XVM:
                        arc.Entries.Add(new XVMEntry(Path.Combine(filePath, filename)));
                        extension = ".xvm";
                        break;

                    default:
                        extension = ".bin";
                        break;
                    }
                    Console.WriteLine("Added entry {0}: {1}", id.ToString(), filename);
                    id++;
                }
                byte[] data = arc.GetBytes();
                outputPath = Path.GetFullPath(filePath) + extension;
                if (compressPRS)
                {
                    Console.WriteLine("Compressing to PRS...");
                    data       = FraGag.Compression.Prs.Compress(data);
                    outputPath = Path.ChangeExtension(outputPath, ".PRS");
                }
                Console.WriteLine("Output file: {0}", outputPath);
                File.WriteAllBytes(outputPath, data);
            }
        }