mirror of
https://github.com/ModOrganizer2/modorganizer-installer_fomod_csharp.git
synced 2026-07-27 14:07:20 -07:00
Implement GetExistingDataFileList().
This commit is contained in:
+28
-1
@@ -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
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user