Esempio n. 1
0
        /// <summary>
        /// MLTFileが追加された場合の処理。TabContextListを生成
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private void addTabContextToList(MLTFile file)
        {
            if (file == null)
            {
                return;
            }

            var index = this.TabContextList.Count;

            // indexが0ならプレビュー用のプレフィックスを追加
            Func <string> getName = () => {
                if (index == 0)
                {
                    return($"[Preview] {file.Name}");
                }
                return(file.Name);
            };

            var tabContext = new TabContext();

            tabContext.TabHeaderName.Value = getName();
            tabContext.MLTFile.Value       = file;
            this.TabContextList.Add(tabContext);

            // 追加したタブを選択
            this.SelectedIndex.Value = this.TabContextList.Count - 1;
        }
Esempio n. 2
0
 /// <summary>
 /// 設定されているMLTFileの更新
 /// </summary>
 /// <param name="file"></param>
 private void updateMLTFile(MLTFile file)
 {
     if (file != null)
     {
         this.MLTPageList.Value = file.Pages;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// MLTFileの入れ替えが発生した場合の処理
        /// </summary>
        /// <param name="newFile"></param>
        /// <param name="oldFile"></param>
        private void replaceTabContext(MLTFile newFile, MLTFile oldFile)
        {
            var item  = this.TabContextList.First(x => x.MLTFile.Value == oldFile);
            var index = this.TabContextList.IndexOf(item);

            // indexが0ならプレビュー用のプレフィックスを追加
            Func <string> getName = () => {
                if (index == 0)
                {
                    return($"[Preview] {newFile.Name}");
                }
                return(newFile.Name);
            };

            var tabContext = new TabContext();

            tabContext.TabHeaderName.Value = getName();
            tabContext.MLTFile.Value       = newFile;

            // 入れ替え
            this.TabContextList[index] = tabContext;

            // 入れ替えたタブを選択
            this.SelectedIndex.Value = index;
        }
Esempio n. 4
0
 /// <summary>
 /// MLTFileが更新された時の処理
 /// </summary>
 /// <param name="file"></param>
 private void updateMLTFile(MLTFile file)
 {
     if (file != null)
     {
         // TreeViewを更新
         this.MLTPageIndexList.Value = this.createMLTIndexList(file);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// 既存MLTファイルのオープンとタブへの追加
        /// </summary>
        private void openMLTFile()
        {
            var new_mlt_file = new MLTFile();

            // ファイル選択ダイアログを開く
            new_mlt_file.OpemMLTFileWithDialog();

            // タブを追加
            this.TabItems.Add(
                new TabItemContent
            {
                File = new_mlt_file,
                Page = new ReactiveProperty <MLTPage>(new_mlt_file.GetCurrentPage())
            });

            // 追加したタブを選択
            this.SelectedIndex.Value = this.TabItems.Count - 1;
        }
Esempio n. 6
0
        /// <summary>
        /// MLTファイルの作成とタブへの追加
        /// </summary>
        private void createNewMLTFile()
        {
            var new_mlt_file = new MLTFile();

            // 空ページで初期化
            new_mlt_file.Pages.Add(new MLTPage());

            // タブを追加
            this.TabItems.Add(
                new TabItemContent
            {
                File = new_mlt_file,
                Page = new ReactiveProperty <MLTPage>(new_mlt_file.GetCurrentPage())
            });

            // 追加したタブを選択
            this.SelectedIndex.Value = this.TabItems.Count - 1;
        }
Esempio n. 7
0
        private void updatePreviewTab(MLTFileTreeNode node)
        {
            if (node == null)
            {
                return;
            }

            if (node.IsDirectory == false)
            {
                var file = new MLTFile();

                // MLTファイルのオープン
                file.OpenMLTFile(node.Path);

                // 現在のグループタブのプレビュータブを更新
                var groupTab = this.getCurrentGroupTabContext();
                groupTab.TabFileList[0] = file;
            }
        }
Esempio n. 8
0
        private void addNewTab(MLTFileTreeNode node)
        {
            if (node == null)
            {
                return;
            }

            if (node.IsDirectory == false)
            {
                var file = new MLTFile();

                // MLTファイルのオープン
                file.OpenMLTFile(node.Path);

                // 現在のグループタブにタブ追加
                var groupTab = this.getCurrentGroupTabContext();
                groupTab.TabFileList.Add(file);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// MLTFileからMLTPageIndexの生成
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private ObservableCollection <MLTPageIndex> createMLTIndexList(MLTFile file)
        {
            // メモ:縦線が揃わなくて見た目がひどいので、インデックス値は0埋めで揃える

            var mltPageIndexList = new ObservableCollection <MLTPageIndex>();
            ObservableCollection <MLTPageIndex> children = null;
            var isCaptionChild = false;

            foreach (var page in file.Pages)
            {
                if (page.IsCaption)
                {
                    children = new ObservableCollection <MLTPageIndex>();
                    mltPageIndexList.Add(new MLTPageIndex
                    {
                        Text     = string.Format("{0:D3}. {1}", page.Index, page.RawText),
                        Page     = page,
                        Children = children
                    });
                    isCaptionChild = true;
                }
                else
                {
                    if (isCaptionChild)
                    {
                        children.Add(new MLTPageIndex
                        {
                            Text = string.Format("{0:D3}. {1}", page.Index, page.Name),
                            Page = page
                        });
                    }
                    else
                    {
                        mltPageIndexList.Add(new MLTPageIndex
                        {
                            Text = string.Format("{0:D3}. {1}", page.Index, page.Name),
                            Page = page
                        });
                    }
                }
            }
            return(mltPageIndexList);
        }
Esempio n. 10
0
        /// <summary>
        /// グループタブの初期化
        /// </summary>
        private void initGroupTab()
        {
            var maxTabCount = 12;

            foreach (var i in Enumerable.Range(0, maxTabCount))
            {
                var ctx = new GroupTabContext();
                // グループタブの初期ヘッダ名(1始まり)
                ctx.TabHeaderName.Value = $"Group {i + 1}";
                // Previewタブ用のダミーデータを追加
                var previewDammyFile = new MLTFile();
                previewDammyFile.Name = "";
                previewDammyFile.Pages.Clear();
                ctx.TabFileList.Add(previewDammyFile);

                this.GroupTabList.Add(ctx);
            }

            this.SelectedIndex.Value = 0;
        }
Esempio n. 11
0
        /// <summary>
        /// Main function for extracting archives.
        /// </summary>
        static void ExtractArchive(string[] args)
        {
            GenericArchive arc;
            string         arcname = extension.ToUpperInvariant();

            Console.WriteLine("Extracting {0} file: {1}", arcname.Substring(1, arcname.Length - 1), filePath);
            byte[] arcdata = File.ReadAllBytes(filePath);
            outputPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath));
            switch (extension.ToLowerInvariant())
            {
            case (".rel"):
                outputPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + "_dec.rel");
                Console.WriteLine("Output file: {0}", outputPath);
                byte[] inputData  = File.ReadAllBytes(args[0]);
                byte[] outputData = SplitTools.HelperFunctions.DecompressREL(inputData);
                File.WriteAllBytes(outputPath, outputData);
                Console.WriteLine("File extracted!");
                return;

            case (".pvmx"):
                arc = new PVMXFile(arcdata);
                break;

            case (".arcx"):
                arc = new ARCXFile(arcdata);
                break;

            case (".prs"):
                arcdata = FraGag.Compression.Prs.Decompress(arcdata);
                if (ARCXFile.Identify(arcdata))
                {
                    arc = new ARCXFile(arcdata);
                }
                else if (PuyoFile.Identify(arcdata) == PuyoArchiveType.Unknown)
                {
                    outputPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + ".bin");
                    Console.WriteLine("Output file: {0}", Path.GetFullPath(outputPath));
                    File.WriteAllBytes(outputPath, arcdata);
                    Console.WriteLine("Archive extracted!");
                    return;
                }
                else
                {
                    arc = new PuyoFile(arcdata);
                }
                break;

            case (".pvm"):
            case (".gvm"):
                arc = new PuyoFile(arcdata);
                break;

            case (".xvm"):
                arc = new XVM(arcdata);
                break;

            case (".pb"):
                arc = new PBFile(arcdata);
                break;

            case (".pak"):
                arc = new PAKFile(filePath);
                break;

            case (".dat"):
                arc = new DATFile(arcdata);
                break;

            case (".mdl"):
                arc = new MDLArchive(arcdata);
                break;

            case (".mdt"):
                arc = new MDTArchive(arcdata);
                break;

            case (".mld"):
                arc = new MLDArchive(arcdata);
                break;

            case (".mlt"):
            case (".gcaxmlt"):
                string test = System.Text.Encoding.ASCII.GetString(arcdata, 0, 4);
                if (test == "gcax")
                {
                    arc = new gcaxMLTFile(arcdata, Path.GetFileNameWithoutExtension(filePath));
                }
                else
                {
                    arc = new MLTFile(arcdata, Path.GetFileNameWithoutExtension(filePath));
                }
                break;

            default:
                Console.WriteLine("Unknown archive type");
                return;
            }
            Console.WriteLine("Output folder: {0}", Path.GetFullPath(outputPath));
            Directory.CreateDirectory(outputPath);
            foreach (GenericArchiveEntry entry in arc.Entries)
            {
                if (entry.Data == null)
                {
                    Console.WriteLine("Entry {0} has no data", entry.Name);
                    continue;
                }
                Console.WriteLine("Extracting file: {0}", entry.Name);
                if (arc is ARCXFile)
                {
                    ARCXFile.ARCXEntry ARCXentry = (ARCXFile.ARCXEntry)entry;
                    Directory.CreateDirectory(Path.Combine(outputPath, ARCXentry.Folder));
                    File.WriteAllBytes(Path.Combine(outputPath, ARCXentry.Folder, entry.Name), entry.Data);
                }
                else
                {
                    File.WriteAllBytes(Path.Combine(outputPath, entry.Name), entry.Data);
                }
            }
            arc.CreateIndexFile(outputPath);
            Console.WriteLine("Archive extracted!");
        }
Esempio n. 12
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);
            }
        }