コード例 #1
0
ファイル: SfpFile.cs プロジェクト: josephmoresena/sfpack
        /// <summary>
        /// Creates the relative path of an entry in the sfp file.
        /// </summary>
        /// <param name="entries">Sfp entries indexed by offset.</param>
        /// <param name="nameTable">Sfp file name table indexed by offset.</param>
        /// <param name="offset">Sfp entry offset.</param>
        /// <returns>Relative path of sfp entry.</returns>
        private static String BuildPath(IReadOnlyDictionary <Int64, SfpEntry> entries, IReadOnlyDictionary <Int64, String> nameTable, Int64 offset)
        {
            SfpEntry entry = entries[offset];
            String   path  = "";

            do
            {
                if (entry.NameOffset != 0)
                {
                    path = $"{nameTable[entry.NameOffset]}{path}";
                }
                offset = entry.ParentOffset;
                entry  = entries[offset];
                path   = $"{Path.DirectorySeparatorChar}{path}";
            } while (offset != entry.ParentOffset);
            return(path);
        }
コード例 #2
0
ファイル: SfpFile.cs プロジェクト: josephmoresena/sfpack
        /// <summary>
        /// Reads recursively all the entries contained in the sfp file.
        /// </summary>
        /// <param name="strm">Sfp stream data.</param>
        /// <param name="offset_ent">Sfp entry offset.</param>
        /// <param name="entries">Sfp entries indexed by offset.</param>
        private unsafe static void ReadEntry(Stream strm, Int64 offset_ent, Dictionary <Int64, SfpEntry> entries)
        {
            SfpEntry entry;

            Byte[] data;
            strm.Seek(offset_ent, SeekOrigin.Begin);
            data = new Byte[sizeof(SfpEntry)];
            strm.Read(data, 0, data.Length);
            entry = SfpEntry.CreateFromBytes(data);
            entries.Add(offset_ent, entry);
            if (entry.IsDir == 1)
            {
                for (Int64 offset = entry.StartOffset; offset < (entry.StartOffset + entry.DataLength); offset += data.Length)
                {
                    ReadEntry(strm, offset, entries);
                }
            }
        }