Implement GetExistingDataFileList().

This commit is contained in:
Mikaël Capelle
2020-05-18 22:43:44 +02:00
parent b28abccc2f
commit 773ffeadc4
2 changed files with 29 additions and 4 deletions
+28 -1
View File
@@ -77,7 +77,7 @@ namespace CSharp {
std::shared_ptr<MOBase::IFileTree> afterInstall(bool success) {
auto tree = g.DestinationTree;
if (!g.Settings.empty()) {
if (success && !g.Settings.empty()) {
QStringList sList;
for (auto p : g.Settings) {
for (auto v : p.second) {
@@ -164,6 +164,33 @@ namespace CSharp {
return File::ReadAllBytes(path);
}
QStringList getDataFiles(QString folder, QString pattern, bool allFolders) {
QStringList files = g_Organizer->findFiles(folder, [pattern](QString const& filepath) {
return QDir::match(pattern, QFileInfo(filepath).fileName());
});
if (allFolders) {
QStringList directories = g_Organizer->listDirectories(folder);
for (QString directory : directories) {
// MO2 does not like path with . or / (I think), so creating the path manually:
files.append(getDataFiles((folder.isEmpty() ? "" : folder + QDir::separator()) + directory, pattern, allFolders));
}
}
return files;
}
array<String^>^ BaseScriptImpl::GetExistingDataFileList(String^ p_strPath, String^ p_strPattern, bool p_booAllFolders) {
QStringList files = getDataFiles(to_qstring(p_strPath), to_qstring(p_strPattern), p_booAllFolders);
array<String^>^ result = gcnew array<String^>(files.size());
QDir modsDir(g_Organizer->modsPath());
for (int i = 0; i < files.size(); ++i) {
// We need to trim the path to the actual folder containing the mod (did not find a better way):
QString rpath = modsDir.relativeFilePath(files[i]).replace("/", QDir::separator());
result[i] = from_string(rpath.mid(rpath.indexOf(QDir::separator()) + 1).toStdWString());
}
return result;
}
bool BaseScriptImpl::DataFileExists(String^ p_strPath) {
return GetExistingDataFile(p_strPath) != nullptr;
}
+1 -3
View File
@@ -180,9 +180,7 @@ namespace CSharp {
/// <param name="p_strPattern">The pattern against which to filter the file paths.</param>
/// <param name="p_booAllFolders">Whether or not to search through subdirectories.</param>
/// <returns>A filtered list of all files in a user's Data directory.</returns>
static array<String^>^ GetExistingDataFileList(String^ p_strPath, String^ p_strPattern, bool p_booAllFolders) {
throw gcnew NotImplementedException("GetExistingDataFileList");
}
static array<String^>^ GetExistingDataFileList(String^ p_strPath, String^ p_strPattern, bool p_booAllFolders);
/// <summary>
/// Determines if the specified file exists in the user's Data directory.