23
23
fileSystemCache hrFilesystem::_cache;
25
const char * MOUNT_SUCCESSFULLY = "Successfully mounted: %s";
26
const char * MOUNT_FAILED = "Failed to mount: %s";
25
const char * MOUNT_SUCCESSFULLY = "\tSuccessfully mounted!";
26
const char * MOUNT_FAILED = "\tFailed to mount!";
29
* Find a case-correct path.
30
* @param path a case-insensitive path
31
* @param baseDir a existing base directory. Certainly does not require case correction.
32
* @return Right path or null string on error.
34
QString hrFilesystem::adjustCaseInPath(const QString &path, const QDir &baseDir)
36
QStringList pathElements = path.split('/');
37
QDir current = baseDir;
39
for ( int j = 0; j < pathElements.size()-1; j++ )
41
QString next = pathElements[j];
43
if (!current.exists(next))
45
QStringList candidates = current.entryList(QStringList() << next, QDir::Dirs | QDir::Readable ); // flag QDir::CaseSensitive does not set by default and this is that we need
47
if (candidates.size() == 0)
49
qCritical("Directory `%s` not found in directory `%s`", qPrintable(next), qPrintable(current.path()));
53
if (candidates.size() != 1)
54
qWarning("Ambiguous element `%s` in directory `%s`, selecting `%s`", qPrintable(next), qPrintable(current.path()), qPrintable(candidates.first()));
56
next = candidates.first();
59
if (!current.cd(next))
61
qCritical("Cannot enter directory `%s` in directory `%s`", qPrintable(next), qPrintable(current.path()));
66
QString last = pathElements.last();
68
if (!current.exists(last))
70
QStringList candidates = current.entryList(QStringList() << last, QDir::Dirs | QDir::Files | QDir::Readable ); // flag QDir::CaseSensitive does not set by default and this is that we need
72
if (candidates.size() == 0)
74
qCritical("File or directory `%s` not found in directory `%s`", qPrintable(last), qPrintable(current.path()));
78
if (candidates.size() != 1)
79
qWarning("Ambiguous element `%s` in directory `%s`, selecting `%s`", qPrintable(last), qPrintable(current.path()), qPrintable(candidates.first()));
81
last = candidates.first();
83
return current.filePath(last);
28
86
bool hrFilesystem::mount(const QString &path)
30
QStringList pathElements = path.split('/');
32
QDir current(hrSettings::get().gameDir());
34
QString normalPath = hrSettings::get().gameDir() + '/' ;
36
for ( int j = 0; j < pathElements.size(); j++ )
38
QStringList el = current.entryList(QStringList() << pathElements[j], QDir::Dirs | QDir::Files );
41
normalPath += el[0] + '/';
42
if ( current.exists(el[0]) )
47
normalPath.remove(normalPath.length() -1, 1); // remove last slash
88
QDir gameRoot = hrSettings::get().gameDir();
90
Q_ASSERT(gameRoot.exists());
92
QString normalPath = adjustCaseInPath(path,gameRoot);
94
if (normalPath.isNull() || !QFile::exists(normalPath))
48
97
qDebug("Trying to mount: %s", qPrintable(normalPath));
50
if ( normalPath.indexOf(".lod", 0, Qt::CaseInsensitive) != -1 )
99
if ( normalPath.endsWith(".lod", Qt::CaseInsensitive) )
52
101
if ( hrLodEngine::fillInternalCache(normalPath) )
53
qDebug(MOUNT_SUCCESSFULLY, qPrintable(normalPath));
102
qDebug(MOUNT_SUCCESSFULLY);
55
qCritical(MOUNT_FAILED, qPrintable(normalPath));
104
qCritical(MOUNT_FAILED);
57
else if ( normalPath.indexOf(".snd", 0, Qt::CaseInsensitive) != -1 )
106
else if ( normalPath.endsWith(".snd", Qt::CaseInsensitive) )
59
108
if ( hrSndEngine::fillInternalCache(normalPath) )
60
qDebug(MOUNT_SUCCESSFULLY, qPrintable(normalPath));
62
qCritical(MOUNT_FAILED, qPrintable(normalPath));
109
qDebug(MOUNT_SUCCESSFULLY);
111
qCritical(MOUNT_FAILED);
115
if ( !mountDir(normalPath))
116
qCritical("\tUnsupported archive type");
118
qDebug(MOUNT_SUCCESSFULLY);
128
void hrFilesystem::mount(const QStringList &path_list)
130
for ( int i = 0; i < path_list.size(); i++)
79
145
_cache.insert(filename, archive);
148
void hrFilesystem::walkDirectory(const QString &path, QStringList &fileList)
150
QFileInfo info(path);
155
QFileInfoList entries = mounted.entryInfoList();
157
for ( int i = 0; i < entries.size(); i++)
159
if ( entries[i].fileName() == "." || entries[i].fileName() == "..")
162
if ( entries[i].isDir() )
164
walkDirectory(entries[i].absoluteFilePath(), fileList);
168
fileList.append(entries[i].absoluteFilePath());
173
bool hrFilesystem::mountDir(const QString &path)
175
QFileInfo info(path);
179
QStringList fileList;
180
walkDirectory(path, fileList);
182
for ( int i = 0; i < fileList.size(); i++)
184
fileList[i].remove(path);
185
fileList[i].remove(0, 1); // remove first '/'
186
hrFilesystem::fillGeneralCache(fileList[i], path);
83
194
Try to find archive where the file located.
84
195
@param filename Filename to found.