示例#1
0
        // To analyze the chunkN.bin
        private void analyze(string filename)
        {
            if (!File.Exists(filename))
            {
                if (!CNMode)
                {
                    PrintLog("Error: file does not exist.");
                }
                else
                {
                    PrintLog("错误:文件不存在");
                }
                return;
            }

            try
            {
                int inputFileMagic;
                using (BinaryReader Reader = new BinaryReader(File.OpenRead(filename))) inputFileMagic = Reader.ReadInt32();
                if (inputFileMagic == Chunk.MagicChunk)
                {
                    if (!CNMode)
                    {
                        PrintLog("Chunk detected,now analyzing...", true);
                    }
                    else
                    {
                        PrintLog("检测到chunk文件,正在解析...", true);
                    }
                    if (mergeChecked)
                    {
                        if (!CNMode)
                        {
                            PrintLog("Merge mode on. The program will merge all the chunk files.");
                        }
                        else
                        {
                            PrintLog("联合解析已开启,程序将整合所有chunkN.bin文件");
                        }
                    }
                    if (!File.Exists($"{AppDomain.CurrentDomain.BaseDirectory}\\oo2core_8_win64.dll"))
                    {
                        if (!CNMode)
                        {
                            PrintLog("Error: oo2core_8_win64.dll not found. Download the file from elsewhere to the executable folder.");
                        }
                        else
                        {
                            PrintLog("错误:未找到oo2core_8_win64.dll,请从其他地方下载该文件至本程序文件夹或使用本程序联网下载功能");
                        }
                        return;
                    }
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        MergeCheckBox.IsEnabled = false;
                    }));
                    if (mergeChecked)
                    {
                        FileInfo chosenChunkFileInfo = new FileInfo(filename);
                        string[] chunkFiles          = Directory.GetFiles(chosenChunkFileInfo.DirectoryName, "chunkG*.bin");
                        Array.Sort(chunkFiles, (a, b) => int.Parse(Regex.Replace(a, "[^0-9]", "")) - int.Parse(Regex.Replace(b, "[^0-9]", "")));
                        foreach (string fileNameEach in chunkFiles)
                        {
                            Chunk cur_chunk = new Chunk();
                            fileNodeList = cur_chunk.AnalyzeChunk(fileNameEach, this, fileNodeList);
                            chunkMap.Add(fileNameEach, cur_chunk);
                        }
                        if (fileNodeList.Count > 0)
                        {
                            fileNodeList[0].sortChildren();
                        }
                    }
                    else
                    {
                        mainChunk    = new Chunk();
                        fileNodeList = mainChunk.AnalyzeChunk(filename, this, fileNodeList);
                    }
                    if (!CNMode)
                    {
                        PrintLog("Analyzation finished.");
                    }
                    else
                    {
                        PrintLog("解析完成");
                    }
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.AllowDrop           = false;
                        maingrid.AllowDrop       = false;
                        ExtractBtn.IsEnabled     = true;
                        FileTree.ItemsSource     = fileNodeList;
                        FilterBox.IsEnabled      = true;
                        ApplyFilterBtn.IsEnabled = true;
                    }));
                }
            }
            catch (Exception e)
            {
                if (!CNMode)
                {
                    PrintLog("Error information is as follows:");
                }
                else
                {
                    PrintLog("错误信息如下:");
                }
                PrintLog(e.Message);
                return;
            }
        }
        // To analyze the chunkN.bin
        private void analyze(string filename)
        {
            if (!File.Exists(filename))
            {
                if (!CNMode)
                {
                    printlog("Error: file does not exist.");
                }
                else
                {
                    printlog("错误:文件不存在");
                }
                return;
            }

            try
            {
                using (BinaryReader Reader = new BinaryReader(File.Open(filename, FileMode.Open))) MagicInputFile = Reader.ReadInt32();
                if (MagicInputFile == MagicChunk)
                {
                    if (!CNMode)
                    {
                        printlog("Chunk detected,now analyzing...", true);
                    }
                    else
                    {
                        printlog("检测到chunk文件,正在解析...", true);
                    }
                    if (CombineChecked)
                    {
                        if (!CNMode)
                        {
                            printlog("Combine mode on. The program will combine all the chunk files.");
                        }
                        else
                        {
                            printlog("联合解析已开启,程序将整合所有chunkN.bin文件");
                        }
                    }
                    if (!File.Exists($"{AppDomain.CurrentDomain.BaseDirectory}\\oo2core_5_win64.dll"))
                    {
                        string oo2corePath = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(filename)) + "\\oo2core_5_win64.dll";
                        if (File.Exists(oo2corePath))
                        {
                            File.Copy(oo2corePath, $"{AppDomain.CurrentDomain.BaseDirectory}\\oo2core_5_win64.dll");
                            if (!CNMode)
                            {
                                printlog($"Copied oo2core_5_win64.dll from {oo2corePath}");
                            }
                            else
                            {
                                printlog($"已从{oo2corePath}拷贝oo2core_5_win64.dll文件");
                            }
                        }
                        else
                        {
                            if (!CNMode)
                            {
                                printlog("Error: oo2core_5_win64.dll not found. Copy the file from your MHW game install path to the executable folder.");
                            }
                            else
                            {
                                printlog("错误:未找到oo2core_5_win64.dll,请从你的怪物猎人:世界游戏安装目录拷贝该文件至本程序文件夹");
                            }
                            return;
                        }
                    }
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        CombineCheckBox.IsEnabled = false;
                    }));
                    if (CombineChecked)
                    {
                        FileInfo chosenChunkFileInfo = new FileInfo(filename);
                        string[] chunkfiles          = Directory.GetFiles(chosenChunkFileInfo.DirectoryName, "chunk*.bin");
                        Array.Sort(chunkfiles, (a, b) => int.Parse(Regex.Replace(a, "[^0-9]", "")) - int.Parse(Regex.Replace(b, "[^0-9]", "")));
                        foreach (string filenameEach in chunkfiles)
                        {
                            Chunk cur_chunk = new Chunk();
                            itemlist = cur_chunk.AnalyzeChunk(filenameEach, this, itemlist);
                            chunkMap.Add(filenameEach, cur_chunk);
                        }
                    }
                    else
                    {
                        mainChunk = new Chunk();
                        itemlist  = mainChunk.AnalyzeChunk(filename, this, itemlist);
                    }
                    if (!CNMode)
                    {
                        printlog("Analyze finished.");
                    }
                    else
                    {
                        printlog("解析完成");
                    }
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.AllowDrop       = false;
                        maingrid.AllowDrop   = false;
                        ExtractBtn.IsEnabled = true;
                        FileTree.ItemsSource = itemlist;
                    }));
                }
            }
            catch (Exception e)
            {
                if (!CNMode)
                {
                    printlog("Error info is as follows:");
                }
                else
                {
                    printlog("错误信息如下:");
                }
                printlog(e.Message);
                return;
            }
        }