public void AddFileData(PackedFileIndexData p_File, string p_SubdirFilename = "")
        {
            string fileName;

            if (p_SubdirFilename.Length == 0)
            {
                fileName = p_File.FilePath;
            }
            else
            {
                fileName = p_SubdirFilename;
            }

            if (fileName.Contains('/'))
            {
                var       nextDir = fileName.Split("/")[0];
                TreeEntry subDir  = null;
                foreach (TreeEntry entry in Items)
                {
                    if (entry.Name.Equals(nextDir))
                    {
                        subDir = entry;
                        break;
                    }
                }
                if (subDir == null)
                {
                    subDir = new TreeEntry(this)
                    {
                        Name = nextDir
                    };
                    Items.Add(subDir);
                }
                subDir.AddFileData(p_File, fileName.Substring(nextDir.Length + 1));
            }
            else
            {
                Items.Add(new TreeEntry(this)
                {
                    Name = fileName, IndexData = p_File
                });
            }
        }
Exemplo n.º 2
0
        private static int RunCat(CatOptions p_Options)
        {
            try {
                ScrapPackedFile     packedFile = new(p_Options.PackedFile);
                PackedFileIndexData fileData   = null;
                try {
                    fileData = packedFile.GetFileIndexDataForFile(p_Options.PackedPath);
                } catch {
                    throw new FileNotFoundException($"File '{p_Options.PackedPath}' dose not exsits in '{p_Options.PackedFile}'");
                }

                FileStream fsPacked = new(p_Options.PackedFile, FileMode.Open);
                try {
                    byte[] readBytes = new byte[fileData.FileSize];

                    fsPacked.Seek(fileData.OriginalOffset, SeekOrigin.Begin);
                    fsPacked.Read(readBytes, 0, (int)fileData.FileSize);

                    if (p_Options.AsHex)
                    {
                        PrintAsHex(readBytes, p_Options.ByteFormat, p_Options.LineFormat, p_Options.BytesPerGroup, p_Options.GroupsPerRow, p_Options.NoPrintLinesNum);
                    }
                    else
                    {
                        var fileContnet = System.Text.Encoding.Default.GetString(readBytes);
                        Console.WriteLine(fileContnet);
                    }
                } finally {
                    fsPacked.Close();
                }
            } catch (Exception ex) {
                Console.Error.WriteLine($"Error: {ex.Message}");
                return(1);
            }

            return(0);
        }