Skip to content

Commit

Permalink
Merge branch 'datadirs' into 'master'
Browse files Browse the repository at this point in the history
Launcher: Improve directory appending UX and heuristics (bug #7502)

Closes #7502

See merge request OpenMW/openmw!3490
  • Loading branch information
psi29a committed Oct 26, 2023
2 parents 416e833 + f68bd3b commit 0350041
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
Bug #7450: Evading obstacles does not work for actors missing certain animations
Bug #7459: Icons get stacked on the cursor when picking up multiple items simultaneously
Bug #7472: Crash when enchanting last projectiles
Bug #7502: Data directories dialog (0.48.0) forces adding subdirectory instead of intended directory
Bug #7505: Distant terrain does not support sample size greater than cell size
Bug #7553: Faction reaction loading is incorrect
Bug #7557: Terrain::ChunkManager::createChunk is called twice for the same position, lod on initial loading
Expand Down
73 changes: 48 additions & 25 deletions apps/launcher/datafilespage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,35 @@ namespace
{
void contentSubdirs(const QString& path, QStringList& dirs)
{
QStringList fileFilter{ "*.esm", "*.esp", "*.omwaddon", "*.bsa", "*.ba2", "*.omwscripts" };
QStringList dirFilter{ "bookart", "icons", "meshes", "music", "sound", "textures" };
static const QStringList fileFilter{
"*.esm",
"*.esp",
"*.bsa",
"*.ba2",
"*.omwgame",
"*.omwaddon",
"*.omwscripts",
};

static const QStringList dirFilter{
"animations",
"bookart",
"fonts",
"icons",
"interface",
"l10n",
"meshes",
"music",
"mygui",
"scripts",
"shaders",
"sound",
"splash",
"strings",
"textures",
"trees",
"video",
};

QDir currentDir(path);
if (!currentDir.entryInfoList(fileFilter, QDir::Files).empty()
Expand Down Expand Up @@ -587,41 +614,37 @@ void Launcher::DataFilesPage::updateCloneProfileOkButton(const QString& text)
mCloneProfileDialog->setOkButtonEnabled(!text.isEmpty() && ui.profilesComboBox->findText(text) == -1);
}

QString Launcher::DataFilesPage::selectDirectory()
{
QFileDialog fileDialog(this);
fileDialog.setFileMode(QFileDialog::Directory);
fileDialog.setOptions(QFileDialog::Option::ShowDirsOnly | QFileDialog::Option::ReadOnly);

if (fileDialog.exec() == QDialog::Rejected)
return {};

return QDir(fileDialog.selectedFiles()[0]).canonicalPath();
}

void Launcher::DataFilesPage::addSubdirectories(bool append)
{
int selectedRow = append ? ui.directoryListWidget->count() : ui.directoryListWidget->currentRow();

if (selectedRow == -1)
return;

const auto rootDir = selectDirectory();
if (rootDir.isEmpty())
QString rootPath = QFileDialog::getExistingDirectory(
this, tr("Select Directory"), QDir::homePath(), QFileDialog::ShowDirsOnly | QFileDialog::Option::ReadOnly);

if (rootPath.isEmpty())
return;

const QDir rootDir(rootPath);
rootPath = rootDir.canonicalPath();

QStringList subdirs;
contentSubdirs(rootDir, subdirs);
contentSubdirs(rootPath, subdirs);

if (subdirs.empty())
// Always offer to append the root directory just in case
if (subdirs.isEmpty() || subdirs[0] != rootPath)
subdirs.prepend(rootPath);
else if (subdirs.size() == 1)
{
// we didn't find anything that looks like a content directory, add directory selected by user
if (ui.directoryListWidget->findItems(rootDir, Qt::MatchFixedString).isEmpty())
{
ui.directoryListWidget->addItem(rootDir);
mNewDataDirs.push_back(rootDir);
refreshDataFilesView();
}
// We didn't find anything else that looks like a content directory
// Automatically add the directory selected by user
if (!ui.directoryListWidget->findItems(rootPath, Qt::MatchFixedString).isEmpty())
return;
ui.directoryListWidget->addItem(rootPath);
mNewDataDirs.push_back(rootPath);
refreshDataFilesView();
return;
}

Expand Down
1 change: 0 additions & 1 deletion apps/launcher/datafilespage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ namespace Launcher
void reloadCells(QStringList selectedFiles);
void refreshDataFilesView();
void updateNavMeshProgress(int minDataSize);
QString selectDirectory();

/**
* Returns the file paths of all selected content files
Expand Down

0 comments on commit 0350041

Please sign in to comment.