99#include < QIcon>
1010#include < QtConcurrent>
1111
12+ Q_DECLARE_METATYPE (Hash)
13+
1214FileTreeModel::FileTreeModel(HashDatabase &database, bool showUnknown, const QString &gamePath, SqPackResource *data, QObject *parent)
1315 : QAbstractItemModel(parent)
1416 , gameData(data)
@@ -28,16 +30,26 @@ FileTreeModel::FileTreeModel(HashDatabase &database, bool showUnknown, const QSt
2830 QFileInfo info = it.fileInfo ();
2931 if (info.exists () && (info.completeSuffix () == QStringLiteral (" win32.index" ))) {
3032 std::string pathStd = info.filePath ().toStdString ();
31- auto indexEntries = physis_index_parse (pathStd.c_str ());
32- for (uint32_t i = 0 ; i < indexEntries.num_entries ; i++) {
33- if (knownDirHashes.contains (indexEntries.dir_entries [i])) {
34- QString name;
35- if (m_database.knowsFile (indexEntries.filename_entries [i])) {
36- name = m_database.getFilename (indexEntries.filename_entries [i]);
33+ const auto indexEntries = physis_index_parse (pathStd.c_str ());
34+ for (uint32_t i = 0 ; i < indexEntries.num_hashes ; i++) {
35+ const auto hash = indexEntries.hashes [i];
36+ switch (hash.tag ) {
37+ case Hash::Tag::SplitPath: {
38+ const auto completeHash =
39+ static_cast <uint32_t >(static_cast <uint64_t >(hash.split_path .path ) << 32 | static_cast <uint64_t >(hash.split_path .name ));
40+ if (knownDirHashes.contains (hash.split_path .path )) {
41+ QString name;
42+ if (m_database.knowsFile (completeHash)) {
43+ name = m_database.getFilename (completeHash);
44+ }
45+ addFile (knownDirHashes[hash.split_path .path ], completeHash, name, hash, info.filePath ());
46+ } else {
47+ addFolder (rootItem, hash.split_path .path );
3748 }
38- addFile (knownDirHashes[indexEntries.dir_entries [i]], indexEntries.filename_entries [i], name);
39- } else {
40- addFolder (rootItem, indexEntries.dir_entries [i]);
49+ } break ;
50+ case Hash::Tag::FullPath:
51+ Q_UNREACHABLE (); // shouldn't be in basic index files
52+ break ;
4153 }
4254 }
4355 }
@@ -122,10 +134,14 @@ QVariant FileTreeModel::data(const QModelIndex &index, int role) const
122134 }
123135
124136 return path;
125- } else if (role == IsUnknown ) {
137+ } else if (role == IsUnknownRole ) {
126138 return item->name .isEmpty (); // unknown files/folders have no name (obviously, we don't know what its named!)
127- } else if (role == IsFolder ) {
139+ } else if (role == IsFolderRole ) {
128140 return item->type == TreeType::Folder;
141+ } else if (role == HashRole) {
142+ return QVariant::fromValue (item->originalHash );
143+ } else if (role == IndexPathRole) {
144+ return item->indexPath ;
129145 } else if (role == Qt::DisplayRole) {
130146 if (item->type == TreeType::Folder) {
131147 if (item->name .isEmpty ()) {
@@ -194,7 +210,7 @@ void FileTreeModel::addKnownFolder(const QString &string)
194210 }
195211}
196212
197- void FileTreeModel::addFile (TreeInformation *parentItem, uint32_t name, const QString &realName)
213+ void FileTreeModel::addFile (TreeInformation *parentItem, uint32_t name, const QString &realName, Hash originalHash, const QString &indexPath )
198214{
199215 if (realName.isEmpty () && !m_showUnknown) {
200216 return ;
@@ -206,6 +222,8 @@ void FileTreeModel::addFile(TreeInformation *parentItem, uint32_t name, const QS
206222 fileItem->type = TreeType::File;
207223 fileItem->parent = parentItem;
208224 fileItem->row = parentItem->children .size ();
225+ fileItem->originalHash = originalHash;
226+ fileItem->indexPath = indexPath;
209227
210228 parentItem->children .push_back (fileItem);
211229}
0 commit comments