示例#1
0
 public void AddChild(GameFile child)
 {
     this.childs.Add(child);
 }
示例#2
0
        private static void Decompiler(string fileIn, string folderOut)
        {
            Stack <GameFile> fileStack = new Stack <GameFile>();

            fileStack.Push(new GameFile(fileIn)
            {
                FilePath = folderOut
            });

            IEnumerable <Type>     packerList = GetPackTypes();
            Dictionary <Type, int> stats      = new Dictionary <Type, int>();

            stats.Add(typeof(GameFile), 0);
            stats.Add(typeof(ErrorFile), 0);
            stats.Add(typeof(FinalFile), 0);
            foreach (Type t in packerList)
            {
                stats.Add(t, 0);
            }

            // Console info
            int xOld = Console.CursorLeft;
            int yOld = Console.CursorTop;

            Console.WriteLine("000000 processed files.");
            Console.CursorVisible = false;

            while (fileStack.Count > 0)
            {
                GameFile currentFile = fileStack.Pop();
                if (currentFile.Size == 0)
                {
                    continue;
                }

                // Match the format
                Packer packer = null;
                foreach (Type packerType in packerList)
                {
                    packer = (Packer)Activator.CreateInstance(packerType, currentFile);
                    if (!packer.IsValid())
                    {
                        packer = null;
                    }
                    else
                    {
                        stats[packerType]++;
                        break;
                    }
                }

                if (packer == null)
                {
                    // Export file
                    #if !DEBUG
                    currentFile.Export();
                    #endif
                    currentFile.Dispose();
                    stats[typeof(FinalFile)]++;
                }
                else
                {
                    // Decompress file
                    GameFile[] unpacked = packer.Unpack();
                    stats[typeof(ErrorFile)] += (unpacked.Length == 0 ? 1 : 0);
                    for (int i = unpacked.Length - 1; i >= 0; i--)
                    {
                        fileStack.Push(unpacked[i]);
                    }

                    if (currentFile.NumChilds == 0)
                    {
                        currentFile.Dispose();
                    }
                }

                // Update the info of the console
                int xNew = Console.CursorLeft;
                int yNew = Console.CursorTop;
                Console.SetCursorPosition(xOld, yOld);
                Console.Write((++stats[typeof(GameFile)]).ToString().PadLeft(6, '0'));
                Console.SetCursorPosition(xNew, yNew);
            }

            // Show stats
            Console.WriteLine("# Statistics #");
            foreach (Type key in stats.Keys)
            {
                Console.WriteLine("|_[{0}]\t-> {1}", key, stats[key]);
            }
        }