Skip to content

Commit

Permalink
Optimize checks for .mohidden extension
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanFeenstra committed Dec 22, 2024
1 parent 8e4e03f commit a17624d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
16 changes: 6 additions & 10 deletions src/filetreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,8 @@ bool FileTreeModel::shouldShowFile(const FileEntry& file) const
{
if (showConflictsOnly() &&
((file.getAlternatives().size() == 0) ||
fs::path(file.getName())
.extension()
.compare(ModInfo::s_HiddenExt.toStdWString()) == 0)) {
QString::fromStdWString(file.getName())
.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive))) {
// only conflicts should be shown, but this file is hidden or not conflicted
return false;
}
Expand All @@ -984,10 +983,8 @@ bool FileTreeModel::shouldShowFile(const FileEntry& file) const
return false;
}

if (!showHiddenFiles() &&
fs::path(file.getName())
.extension()
.compare(ModInfo::s_HiddenExt.toStdWString()) == 0) {
if (!showHiddenFiles() && QString::fromStdWString(file.getName())
.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive)) {
// hidden files shouldn't be shown, but this file is hidden
return false;
}
Expand All @@ -999,9 +996,8 @@ bool FileTreeModel::shouldShowFolder(const DirectoryEntry& dir,
const FileTreeItem* item) const
{
if ((!showHiddenFiles() || showConflictsOnly()) &&
fs::path(dir.getName())
.extension()
.compare(ModInfo::s_HiddenExt.toStdWString()) == 0) {
QString::fromStdWString(dir.getName())
.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive)) {
return false;
}

Expand Down
22 changes: 10 additions & 12 deletions src/modinfodialogconflicts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,18 +598,17 @@ bool GeneralConflictsTab::update()

if (m_tab->origin() != nullptr) {
const auto rootPath = m_tab->mod().absolutePath();
const auto hideExt = ModInfo::s_HiddenExt.toStdWString();
std::set<const DirectoryEntry*> checkedDirs;

for (const auto& file : m_tab->origin()->getFiles()) {
const fs::path nameAsPath(file->getName());
if (nameAsPath.extension().wstring().compare(hideExt) == 0) {
if (QString::fromStdWString(file->getName())
.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive)) {
// skip hidden file conflicts
continue;
} else {
const DirectoryEntry* parent = file->getParent();
auto hidden = false;
// iterate on all parent direEntries to check for .mohiddden
// iterate on all parent directory entries to check for .mohiddden
while (parent != nullptr) {
auto insertResult = checkedDirs.insert(parent);

Expand All @@ -618,8 +617,8 @@ bool GeneralConflictsTab::update()
// well
break;
} else {
const fs::path dirPath(parent->getName());
if (dirPath.extension().wstring().compare(hideExt) == 0) {
if (QString::fromStdWString(parent->getName())
.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive)) {
hidden = true;
break;
}
Expand Down Expand Up @@ -948,21 +947,20 @@ void AdvancedConflictsTab::update()

if (m_tab->origin() != nullptr) {
const auto rootPath = m_tab->mod().absolutePath();
const auto hideExt = ModInfo::s_HiddenExt.toStdWString();

const auto& files = m_tab->origin()->getFiles();
m_model->reserve(files.size());
std::set<const DirectoryEntry*> checkedDirs;

for (const auto& file : files) {
const fs::path nameAsPath(file->getName());
if (nameAsPath.extension().wstring().compare(hideExt) == 0) {
if (QString::fromStdWString(file->getName())
.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive)) {
// skip hidden file conflicts
continue;
} else {
const DirectoryEntry* parent = file->getParent();
auto hidden = false;
// iterate on all parent direEntries to check for .mohiddden
// iterate on all parent directory entries to check for .mohiddden
while (parent != nullptr) {
auto insertResult = checkedDirs.insert(parent);

Expand All @@ -971,8 +969,8 @@ void AdvancedConflictsTab::update()
// well
break;
} else {
const fs::path dirPath(parent->getName());
if (dirPath.extension().wstring().compare(hideExt) == 0) {
if (QString::fromStdWString(parent->getName())
.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive)) {
hidden = true;
break;
}
Expand Down
13 changes: 6 additions & 7 deletions src/modinfowithconflictinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ ModInfoWithConflictInfo::Conflicts ModInfoWithConflictInfo::doConflictCheck() co
}
}

std::wstring name = ToWString(this->name());
const std::wstring hideExt = ToWString(ModInfo::s_HiddenExt);
std::wstring name = ToWString(this->name());

if (m_Core.directoryStructure()->originExists(name)) {
FilesOrigin& origin = m_Core.directoryStructure()->getOriginByName(name);
Expand All @@ -121,16 +120,16 @@ ModInfoWithConflictInfo::Conflicts ModInfoWithConflictInfo::doConflictCheck() co

// for all files in this origin
for (FileEntryPtr file : files) {
const fs::path nameAsPath(file->getName());
if (nameAsPath.extension().wstring().compare(hideExt) == 0) {
if (QString::fromStdWString(file->getName())
.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive)) {
hasHiddenFiles = true;
// skip hidden file conflicts
continue;
} else {
const DirectoryEntry* parent = file->getParent();
auto hidden = false;

// iterate on all parent direEntries to check for .mohiddden
// iterate on all parent directory entries to check for .mohiddden
while (parent != nullptr) {
auto insertResult = checkedDirs.insert(parent);

Expand All @@ -139,8 +138,8 @@ ModInfoWithConflictInfo::Conflicts ModInfoWithConflictInfo::doConflictCheck() co
// well
break;
} else {
const fs::path dirPath(parent->getName());
if (dirPath.extension().wstring().compare(hideExt) == 0) {
if (QString::fromStdWString(parent->getName())
.endsWith(ModInfo::s_HiddenExt, Qt::CaseInsensitive)) {
hasHiddenFiles = hidden = true;
break;
}
Expand Down

0 comments on commit a17624d

Please sign in to comment.