diff options
| author | Tannin <devnull@localhost> | 2013-06-05 10:05:29 +0200 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2013-06-05 10:05:29 +0200 |
| commit | 97111de1409a59eea9e7ab5050ab70f4d01ddb8e (patch) | |
| tree | 6d3ed6dd899573d23bef15adb2519173cd844b76 /src | |
| parent | 280691ebc36d34c803a5bd8e01616680b0d2fafb (diff) | |
| parent | 1606c1366f5d0ba304334b0e57680fb99feb88b9 (diff) | |
Merge
Diffstat (limited to 'src')
| -rw-r--r-- | src/installationmanager.cpp | 9 | ||||
| -rw-r--r-- | src/main.cpp | 3 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 118 | ||||
| -rw-r--r-- | src/mainwindow.h | 5 | ||||
| -rw-r--r-- | src/modinfo.cpp | 25 | ||||
| -rw-r--r-- | src/modinfo.h | 12 | ||||
| -rw-r--r-- | src/modlist.cpp | 14 | ||||
| -rw-r--r-- | src/modlist.h | 2 | ||||
| -rw-r--r-- | src/modlistsortproxy.cpp | 14 | ||||
| -rw-r--r-- | src/overwriteinfodialog.ui | 7 | ||||
| -rw-r--r-- | src/qtgroupingproxy.cpp | 9 | ||||
| -rw-r--r-- | src/qtgroupingproxy.h | 1 | ||||
| -rw-r--r-- | src/shared/directoryentry.cpp | 6 | ||||
| -rw-r--r-- | src/shared/util.cpp | 13 | ||||
| -rw-r--r-- | src/shared/util.h | 2 | ||||
| -rw-r--r-- | src/syncoverwritedialog.cpp | 24 | ||||
| -rw-r--r-- | src/syncoverwritedialog.h | 2 |
17 files changed, 173 insertions, 93 deletions
diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index fee6361a..75ab11a3 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -68,7 +68,7 @@ template <typename T> T resolveFunction(QLibrary &lib, const char *name) InstallationManager::InstallationManager(QWidget *parent) : QObject(parent), m_ParentWidget(parent), - m_InstallationProgress(parent), m_SupportedExtensions() //boost::assign::list_of("zip")("rar")("7z")("fomod") + m_InstallationProgress(parent), m_SupportedExtensions(boost::assign::list_of("zip")("rar")("7z")("fomod")) { QLibrary archiveLib("dlls\\archive.dll"); if (!archiveLib.load()) { @@ -695,10 +695,9 @@ bool InstallationManager::install(const QString &fileName, GuessedValue<QString> try { { // simple case IPluginInstallerSimple *installerSimple = dynamic_cast<IPluginInstallerSimple*>(installer); - if ((installerSimple != NULL) && (filesTree != NULL) && (installer->isArchiveSupported(*filesTree))) { - installResult = installerSimple->install(modName, *filesTree); + installResult = installerSimple->install(modName, *filesTree, version, modID); if (installResult == IPluginInstaller::RESULT_SUCCESS) { mapToArchive(filesTree); // the simple installer only prepares the installation, the rest works the same for all installers @@ -716,9 +715,7 @@ bool InstallationManager::install(const QString &fileName, GuessedValue<QString> ((filesTree == NULL) && installerCustom->isArchiveSupported(fileName)))) { std::set<QString> installerExtensions = installerCustom->supportedExtensions(); if (installerExtensions.find(fileInfo.suffix()) != installerExtensions.end()) { - if (testOverwrite(modName)) { - installResult = installerCustom->install(modName, fileName); - } + installResult = installerCustom->install(modName, fileName, version, modID); } } } diff --git a/src/main.cpp b/src/main.cpp index 7146f4d1..3f8ea46f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,8 +94,6 @@ void removeOldLogfiles() // set up required folders (for a first install or after an update or to fix a broken installation) bool bootstrap() { - qDebug("bootstapping"); - GameInfo &gameInfo = GameInfo::instance(); // remove the temporary backup directory in case we're restarting after an update @@ -150,7 +148,6 @@ bool bootstrap() } // verify the hook-dll exists - qDebug("checking dll"); QString dllName = qApp->applicationDirPath() + "/" + ToQString(AppConfig::hookDLLName()); HMODULE dllMod = ::LoadLibraryW(ToWString(dllName).c_str()); if (dllMod == NULL) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3cf2846e..fb88bbad 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -610,6 +610,19 @@ void MainWindow::downloadFilterChanged(const QString &filter) } } +void MainWindow::expandModList(const QModelIndex &index) +{ + QAbstractItemModel *model = ui->modList->model(); +#pragma message("why is this so complicated? mapping the index doesn't work, probably a bug in QtGroupingProxy?") + for (int i = 0; i < model->rowCount(); ++i) { + QModelIndex targetIdx = model->index(i, 0); + if (model->data(targetIdx).toString() == index.data().toString()) { + ui->modList->expand(targetIdx); + break; + } + } +} + bool MainWindow::saveCurrentLists() { if (m_DirectoryUpdate) { @@ -954,13 +967,17 @@ bool MainWindow::registerPlugin(QObject *plugin) if (verifyPlugin(proxy)) { QStringList pluginNames = proxy->pluginList(QCoreApplication::applicationDirPath() + "/" + ToQString(AppConfig::pluginPath())); foreach (const QString &pluginName, pluginNames) { - QObject *proxiedPlugin = proxy->instantiate(pluginName); - if (proxiedPlugin != NULL) { - if (registerPlugin(proxiedPlugin)) { - qDebug("loaded plugin \"%s\"", pluginName.toUtf8().constData()); - } else { - qWarning("plugin \"%s\" failed to load", pluginName.toUtf8().constData()); + try { + QObject *proxiedPlugin = proxy->instantiate(pluginName); + if (proxiedPlugin != NULL) { + if (registerPlugin(proxiedPlugin)) { + qDebug("loaded plugin \"%s\"", pluginName.toUtf8().constData()); + } else { + qWarning("plugin \"%s\" failed to load", pluginName.toUtf8().constData()); + } } + } catch (const std::exception &e) { + reportError(tr("failed to init plugin %1: %2").arg(pluginName).arg(e.what())); } } return true; @@ -1059,9 +1076,13 @@ IModInterface *MainWindow::getMod(const QString &name) } -IModInterface *MainWindow::createMod(const QString &name) +IModInterface *MainWindow::createMod(GuessedValue<QString> &name) { - QString fixedName = name; + if (!m_InstallationManager.testOverwrite(name)) { + return NULL; + } + +/* QString fixedName = name; fixDirectoryName(fixedName); unsigned int index = ModInfo::getIndex(fixedName); if (index != UINT_MAX) { @@ -1070,8 +1091,8 @@ IModInterface *MainWindow::createMod(const QString &name) throw MyException(tr("The mod \"%1\" already exists!").arg(fixedName)); } return result.data(); - } else { - QString targetDirectory = QDir::fromNativeSeparators(m_Settings.getModDirectory()).append("/").append(fixedName.trimmed()); + } else {*/ + QString targetDirectory = QDir::fromNativeSeparators(m_Settings.getModDirectory()).append("/").append(name); QSettings settingsFile(targetDirectory.mid(0).append("/meta.ini"), QSettings::IniFormat); @@ -1081,7 +1102,7 @@ IModInterface *MainWindow::createMod(const QString &name) settingsFile.setValue("category", 0); settingsFile.setValue("installationFile", 0); return ModInfo::createFrom(QDir(targetDirectory), &m_DirectoryStructure).data(); - } +// } } bool MainWindow::removeMod(IModInterface *mod) @@ -2187,9 +2208,6 @@ void MainWindow::modStatusChanged(unsigned int index) ModInfo::Ptr modInfo = ModInfo::getByIndex(index); if (m_CurrentProfile->modEnabled(index)) { DirectoryRefresher::addModToStructure(m_DirectoryStructure, modInfo->name(), m_CurrentProfile->getModPriority(index), modInfo->absolutePath()); -/* m_DirectoryStructure->addFromOrigin(ToWString(modInfo->name()), - ToWString(QDir::toNativeSeparators(modInfo->absolutePath())), - m_CurrentProfile->getModPriority(index));*/ DirectoryRefresher::cleanStructure(m_DirectoryStructure); } else { if (m_DirectoryStructure->originExists(ToWString(modInfo->name()))) { @@ -2197,6 +2215,16 @@ void MainWindow::modStatusChanged(unsigned int index) origin.enable(false); } } + + for (unsigned int i = 0; i < m_CurrentProfile->numMods(); ++i) { + ModInfo::Ptr modInfo = ModInfo::getByIndex(i); + int priority = m_CurrentProfile->getModPriority(i); + if (m_DirectoryStructure->originExists(ToWString(modInfo->name()))) { + m_DirectoryStructure->getOriginByName(ToWString(modInfo->name())).setPriority(priority); + } + } + m_DirectoryStructure->getFileRegister()->sortOrigins(); + refreshLists(); } catch (const std::exception& e) { reportError(tr("failed to update mod list: %1").arg(e.what())); @@ -2481,11 +2509,15 @@ void MainWindow::modlistChanged(const QModelIndex &index, int role) m_PluginList.enableESP(esm); } + int enabled = 0; QStringList esps = dir.entryList(QStringList("*.esp"), QDir::Files); foreach (const QString &esp, esps) { - m_PluginList.enableESP(esp); + if (!m_PluginList.isEnabled(esp)) { + m_PluginList.enableESP(esp); + ++enabled; + } } - if (esps.count() > 1) { + if (enabled > 1) { MessageDialog::showMessage(tr("Multiple esps activated, please check that they don't conflict."), this); } } @@ -2624,9 +2656,6 @@ void MainWindow::displayModInformation(ModInfo::Ptr modInfo, unsigned int index, FilesOrigin& origin = m_DirectoryStructure->getOriginByName(ToWString(modInfo->name())); origin.enable(false); -/* m_DirectoryStructure->addFromOrigin(ToWString(modInfo->name()), - ToWString(QDir::toNativeSeparators(modInfo->absolutePath())), - m_CurrentProfile->getModPriority(index));*/ DirectoryRefresher::addModToStructure(m_DirectoryStructure, modInfo->name(), m_CurrentProfile->getModPriority(index), modInfo->absolutePath()); @@ -2795,14 +2824,21 @@ void MainWindow::syncOverwrite() void MainWindow::createModFromOverwrite() { - QString name = QInputDialog::getText(this, tr("Create Mod..."), - tr("This will move all files from overwrite into a new, regular mod." - "Please enter a name: ")); - QString fixedName = fixDirectoryName(name); - if (fixedName.isEmpty()) { - reportError(tr("Invalid name")); - return; - } else if (getMod(fixedName) != NULL) { + GuessedValue<QString> name; + name.setFilter(&fixDirectoryName); + + while (name->isEmpty()) { + bool ok; + name.update(QInputDialog::getText(this, tr("Create Mod..."), + tr("This will move all files from overwrite into a new, regular mod.\n" + "Please enter a name: "), QLineEdit::Normal, "", &ok), + GUESS_USER); + if (!ok) { + return; + } + } + + if (getMod(name) != NULL) { reportError(tr("A mod with this name already exists")); return; } @@ -2812,6 +2848,8 @@ void MainWindow::createModFromOverwrite() ModInfo::Ptr overwriteInfo = ModInfo::getByIndex(m_ContextRow); shellMove(QStringList(overwriteInfo->absolutePath() + "\\*"), QStringList(newMod->absolutePath()), this); + + refreshModList(); } @@ -2827,7 +2865,6 @@ void MainWindow::on_modList_doubleClicked(const QModelIndex &index) if (!index.isValid()) { return; } -// QModelIndex sourceIdx = m_ModListGroupProxy->mapToSource(index); QModelIndex sourceIdx = mapToModel(&m_ModList, index); if (!sourceIdx.isValid()) { return; @@ -2857,8 +2894,7 @@ bool MainWindow::addCategories(QMenu *menu, int targetID) if (m_CategoryFactory.getParentID(i) == targetID) { QMenu *targetMenu = menu; if (m_CategoryFactory.hasChildren(i)) { - targetMenu = menu->addMenu( - m_CategoryFactory.getCategoryName(i).replace('&', "&&")); + targetMenu = menu->addMenu(m_CategoryFactory.getCategoryName(i).replace('&', "&&")); } int id = m_CategoryFactory.getCategoryID(i); @@ -2897,7 +2933,6 @@ void MainWindow::saveCategoriesFromMenu(QMenu *menu, int modRow) if (widgetAction != NULL) { QCheckBox *checkbox = qobject_cast<QCheckBox*>(widgetAction->defaultWidget()); modInfo->setCategory(widgetAction->data().toInt(), checkbox->isChecked()); -// m_ModList.setModCategory(modRow, widgetAction->data().toInt(), checkbox->isChecked()); } } } @@ -2911,15 +2946,24 @@ void MainWindow::saveCategories() qCritical("not a menu?"); return; } -// m_ModList.resetCategories(m_ContextRow); QModelIndexList selected = ui->modList->selectionModel()->selectedRows(); + if (selected.size() > 0) { + int min = INT_MAX; + int max = INT_MIN; + for (int i = 0; i < selected.size(); ++i) { - saveCategoriesFromMenu(menu, m_ModListSortProxy->mapToSource(selected.at(i)).row()); + QModelIndex temp = mapToModel(&m_ModList, selected.at(i)); + if (temp.row() < min) min = temp.row(); + if (temp.row() > max) max = temp.row(); + saveCategoriesFromMenu(menu, mapToModel(&m_ModList, selected.at(i)).row()); } + //m_ModList.notifyChange(min, max); + refreshModList(); } else { saveCategoriesFromMenu(menu, m_ContextRow); + m_ModList.notifyChange(m_ContextRow); } refreshFilters(); @@ -4243,18 +4287,14 @@ void MainWindow::on_groupCombo_currentIndexChanged(int index) newModel = NULL; } break; } + if (newModel != NULL) { -// newModel->setSourceModel(m_ModListSortProxy); m_ModListSortProxy->setSourceModel(newModel); connect(ui->modList, SIGNAL(expanded(QModelIndex)),newModel, SLOT(expanded(QModelIndex))); connect(ui->modList, SIGNAL(collapsed(QModelIndex)), newModel, SLOT(collapsed(QModelIndex))); - connect(newModel, SIGNAL(expandItem(QModelIndex)), ui->modList, SLOT(expand(QModelIndex))); + connect(newModel, SIGNAL(expandItem(QModelIndex)), this, SLOT(expandModList(QModelIndex))); -// ui->modList->setModel(newModel); } else { m_ModListSortProxy->setSourceModel(&m_ModList); -// ui->modList->setModel(m_ModListSortProxy); } -// ui->modList->setModel(m_ModListSortProxy); - // ui->modList->setSelectionMode(QAbstractItemView::ExtendedSelection); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 24cdb91e..7a1e1bc2 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -50,6 +50,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "pluginlistsortproxy.h" #include "tutorialcontrol.h" #include "savegameinfowidgetgamebryo.h" +#include <guessedvalue.h> namespace Ui { class MainWindow; @@ -100,7 +101,7 @@ public: virtual QString downloadsPath() const; virtual MOBase::VersionInfo appVersion() const; virtual MOBase::IModInterface *getMod(const QString &name); - virtual MOBase::IModInterface *createMod(const QString &name); + virtual MOBase::IModInterface *createMod(MOBase::GuessedValue<QString> &name); virtual bool removeMod(MOBase::IModInterface *mod); virtual void modDataChanged(MOBase::IModInterface *mod); virtual QVariant pluginSetting(const QString &pluginName, const QString &key) const; @@ -419,6 +420,8 @@ private slots: void espFilterChanged(const QString &filter); void downloadFilterChanged(const QString &filter); + void expandModList(const QModelIndex &index); + private slots: // ui slots // actions void on_actionAdd_Profile_triggered(); diff --git a/src/modinfo.cpp b/src/modinfo.cpp index a08a4ccd..e3e0487b 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -509,6 +509,7 @@ bool ModInfoRegular::setName(const QString &name) QString newPath = m_Path.mid(0).replace(m_Path.length() - m_Name.length(), m_Name.length(), name); QDir modDir(m_Path.mid(0, m_Path.length() - m_Name.length())); + if (m_Name.compare(name, Qt::CaseInsensitive) == 0) { QString tempName = name; tempName.append("_temp"); @@ -524,23 +525,29 @@ bool ModInfoRegular::setName(const QString &name) return false; } } else { - if (!modDir.rename(m_Name, name)) { + if (!shellRename(modDir.absoluteFilePath(m_Name), modDir.absoluteFilePath(name))) { + qCritical("failed to rename mod %s (errorcode %d)", + qPrintable(name), ::GetLastError()); return false; } } std::map<QString, unsigned int>::iterator nameIter = s_ModsByName.find(m_Name); - unsigned int index = nameIter->second; - s_ModsByName.erase(nameIter); - - m_Name = name; - m_Path = newPath; + if (nameIter != s_ModsByName.end()) { + unsigned int index = nameIter->second; + s_ModsByName.erase(nameIter); - s_ModsByName[m_Name] = index; + m_Name = name; + m_Path = newPath; - std::sort(s_Collection.begin(), s_Collection.end(), ByName); + s_ModsByName[m_Name] = index; - updateIndices(); + std::sort(s_Collection.begin(), s_Collection.end(), ByName); + updateIndices(); + } else { // otherwise mod isn't registered yet? + m_Name = name; + m_Path = newPath; + } return true; } diff --git a/src/modinfo.h b/src/modinfo.h index faf33f0d..a261296b 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -215,18 +215,6 @@ public: virtual void setCategory(int categoryID, bool active) = 0; /** - * @brief set the name of this mod - * - * set the name of this mod. This will also update the name of the - * directory that contains this mod - * - * @param name new name of the mod - * @return true on success, false if the new name can't be used (i.e. because the new - * directory name wouldn't be valid) - **/ - virtual bool setName(const QString &name) = 0; - - /** * @brief change the notes (manually set information) for this mod * @param notes new notes */ diff --git a/src/modlist.cpp b/src/modlist.cpp index 3fc8ae23..f87687bb 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -203,7 +203,12 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const return QVariant(); } } else if (column == COL_PRIORITY) { - return m_Profile->getModPriority(modIndex); + int priority = modInfo->getFixedPriority(); + if (priority != INT_MIN) { + return priority; + } else { + return m_Profile->getModPriority(modIndex); + } } else { return modInfo->getNexusID(); } @@ -648,13 +653,14 @@ void ModList::removeRow(int row, const QModelIndex&) } -void ModList::notifyChange(int row) +void ModList::notifyChange(int rowStart, int rowEnd) { - if (row < 0) { + if (rowStart < 0) { beginResetModel(); endResetModel(); } else { - emit dataChanged(this->index(row, 0), this->index(row, this->columnCount() - 1)); + if (rowEnd == -1) rowEnd = rowStart; + emit dataChanged(this->index(rowStart, 0), this->index(rowEnd, this->columnCount() - 1)); } } diff --git a/src/modlist.h b/src/modlist.h index a0b6e841..99f43b5c 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -91,7 +91,7 @@ public: */ void removeRowForce(int row); - void notifyChange(int row); + void notifyChange(int rowStart, int rowEnd = -1); static QString getColumnName(int column); diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 17dca5fc..ede83659 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -157,16 +157,12 @@ bool ModListSortProxy::lessThan(const QModelIndex &left, case ModList::COL_MODID: lt = leftMod->getNexusID() < rightMod->getNexusID(); break; case ModList::COL_VERSION: lt = leftMod->getVersion() < rightMod->getVersion(); break; case ModList::COL_PRIORITY: { - if (m_Profile != NULL) { - int leftPrio = leftMod->getFixedPriority(); - int rightPrio = rightMod->getFixedPriority(); - if (leftPrio == INT_MIN) leftPrio = m_Profile->getModPriority(leftIndex); - if (rightPrio == INT_MIN) rightPrio = m_Profile->getModPriority(rightIndex); + QVariant leftPrio = left.data(); + if (!leftPrio.isValid()) leftPrio = left.data(Qt::UserRole); + QVariant rightPrio = right.data(); + if (!rightPrio.isValid()) rightPrio = right.data(Qt::UserRole); - lt = leftPrio < rightPrio; - } else { - lt = leftMod->name() < rightMod->name(); - } + return leftPrio.toInt() < rightPrio.toInt(); } break; } return lt; diff --git a/src/overwriteinfodialog.ui b/src/overwriteinfodialog.ui index c6119ca6..2c194ecf 100644 --- a/src/overwriteinfodialog.ui +++ b/src/overwriteinfodialog.ui @@ -34,6 +34,13 @@ </widget>
</item>
<item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>You can use drag&drop to move files and directories to regular mods.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
diff --git a/src/qtgroupingproxy.cpp b/src/qtgroupingproxy.cpp index 4e066f65..3891cc12 100644 --- a/src/qtgroupingproxy.cpp +++ b/src/qtgroupingproxy.cpp @@ -57,6 +57,7 @@ QtGroupingProxy::QtGroupingProxy(QAbstractItemModel *model, QModelIndex rootNode connect( sourceModel(), SIGNAL(layoutChanged()), SLOT(buildTree()) );
connect( sourceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
SLOT(modelDataChanged(QModelIndex,QModelIndex)) );
+ connect( sourceModel(), SIGNAL(modelReset()), this, SLOT(resetModel()) );
if( groupedColumn != -1 )
setGroupedColumn( groupedColumn );
@@ -487,7 +488,7 @@ QtGroupingProxy::data( const QModelIndex &index, int role ) const default: {
QModelIndex parentIndex = this->index( row, 0, index.parent() );
if (m_groupHash.value( row ).count() > 0) {
- return this->index(0, 0, parentIndex).data(role);
+ return this->index(0, column, parentIndex).data(role);
} else {
return QVariant();
}
@@ -985,6 +986,12 @@ QtGroupingProxy::modelRowsRemoved( const QModelIndex &parent, int start, int end }
void
+QtGroupingProxy::resetModel()
+{
+ buildTree();
+}
+
+void
QtGroupingProxy::modelDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight )
{
//TODO: need to look in the groupedColumn and see if it changed and changed grouping accordingly
diff --git a/src/qtgroupingproxy.h b/src/qtgroupingproxy.h index e09ae7b4..7df069f7 100644 --- a/src/qtgroupingproxy.h +++ b/src/qtgroupingproxy.h @@ -103,6 +103,7 @@ private slots: void modelRowsInserted( const QModelIndex &, int, int );
void modelRowsAboutToBeRemoved( const QModelIndex &, int ,int );
void modelRowsRemoved( const QModelIndex &, int, int );
+ void resetModel();
protected:
/** Maps an item to a group.
diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp index abf9affb..9958b934 100644 --- a/src/shared/directoryentry.cpp +++ b/src/shared/directoryentry.cpp @@ -192,7 +192,6 @@ void FileEntry::addOrigin(int origin, FILETIME fileTime, const std::wstring &arc m_Origin = origin;
m_FileTime = fileTime;
m_Archive = archive;
-// } else if (FilesOrigin::getByID(origin).getPriority() > FilesOrigin::getByID(m_Origin).getPriority()) {
} else if (m_Parent->getOriginByID(origin).getPriority() > m_Parent->getOriginByID(m_Origin).getPriority()) {
if (std::find(m_Alternatives.begin(), m_Alternatives.end(), m_Origin) == m_Alternatives.end()) {
m_Alternatives.push_back(m_Origin);
@@ -269,7 +268,10 @@ bool FileEntry::removeOrigin(int origin) // sorted by priority descending
static bool ByOriginPriority(DirectoryEntry *entry, int LHS, int RHS)
{
- return entry->getOriginByID(LHS).getPriority() < entry->getOriginByID(RHS).getPriority();
+ int l = entry->getOriginByID(LHS).getPriority(); if (l < 0) l = INT_MAX;
+ int r = entry->getOriginByID(RHS).getPriority(); if (r < 0) r = INT_MAX;
+
+ return l < r;
}
diff --git a/src/shared/util.cpp b/src/shared/util.cpp index e61ae8a6..1c4bf5b6 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -28,6 +28,19 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. namespace MOShared {
+bool FileExists(const std::string &filename)
+{
+ WIN32_FIND_DATAA findData;
+ ZeroMemory(&findData, sizeof(WIN32_FIND_DATAA));
+ HANDLE search = ::FindFirstFileExA(filename.c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, NULL, 0);
+ if (search == INVALID_HANDLE_VALUE) {
+ return false;
+ } else {
+ FindClose(search);
+ return true;
+ }
+}
+
bool FileExists(const std::wstring &filename)
{
WIN32_FIND_DATAW findData;
diff --git a/src/shared/util.h b/src/shared/util.h index 80983cb0..4af1fb1e 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -30,7 +30,7 @@ namespace MOShared { static const int MAXPATH_UNICODE = 32767;
-
+bool FileExists(const std::string &filename);
bool FileExists(const std::wstring &filename);
bool FileExists(const std::wstring &searchPath, const std::wstring &filename);
diff --git a/src/syncoverwritedialog.cpp b/src/syncoverwritedialog.cpp index aae0fd7c..be9d06c2 100644 --- a/src/syncoverwritedialog.cpp +++ b/src/syncoverwritedialog.cpp @@ -37,7 +37,7 @@ SyncOverwriteDialog::SyncOverwriteDialog(const QString &path, DirectoryEntry *di ui(new Ui::SyncOverwriteDialog), m_SourcePath(path), m_DirectoryStructure(directoryStructure) { ui->setupUi(this); - refresh(path, directoryStructure); + refresh(path); QHeaderView *headerView = ui->syncTree->header(); #if QT_VERSION >= 0x050000 @@ -56,6 +56,14 @@ SyncOverwriteDialog::~SyncOverwriteDialog() } +static void addToComboBox(QComboBox *box, const QString &name, const QVariant &userData) +{ + if (QString::compare(name, "overwrite", Qt::CaseInsensitive) != 0) { + box->addItem(name, userData); + } +} + + void SyncOverwriteDialog::readTree(const QString &path, DirectoryEntry *directoryStructure, QTreeWidgetItem *subTree) { QDir overwrite(path); @@ -86,9 +94,12 @@ void SyncOverwriteDialog::readTree(const QString &path, DirectoryEntry *director QComboBox* combo = new QComboBox(ui->syncTree); combo->addItem(tr("<don't sync>"), -1); if (entry != NULL) { + bool ignore; + int origin = entry->getOrigin(ignore); + addToComboBox(combo, ToQString(m_DirectoryStructure->getOriginByID(origin).getName()), origin); const std::vector<int> &alternatives = entry->getAlternatives(); for (std::vector<int>::const_iterator iter = alternatives.begin(); iter != alternatives.end(); ++iter) { - combo->addItem(ToQString(m_DirectoryStructure->getOriginByID(*iter).getName()), *iter); + addToComboBox(combo, ToQString(m_DirectoryStructure->getOriginByID(*iter).getName()), *iter); } combo->setCurrentIndex(combo->count() - 1); } else { @@ -103,10 +114,10 @@ void SyncOverwriteDialog::readTree(const QString &path, DirectoryEntry *director } -void SyncOverwriteDialog::refresh(const QString &path, DirectoryEntry *directoryStructure) +void SyncOverwriteDialog::refresh(const QString &path) { QTreeWidgetItem *rootItem = new QTreeWidgetItem(ui->syncTree, QStringList("<data>")); - readTree(path, directoryStructure, rootItem); + readTree(path, m_DirectoryStructure, rootItem); ui->syncTree->addTopLevelItem(rootItem); ui->syncTree->expandAll(); } @@ -141,6 +152,11 @@ void SyncOverwriteDialog::applyTo(QTreeWidgetItem *item, const QString &path, co } } } + + QDir dir(m_SourcePath + "/" + path); + if ((path.length() > 0) && (dir.count() == 2)) { + dir.rmpath("."); + } } diff --git a/src/syncoverwritedialog.h b/src/syncoverwritedialog.h index da7c8cf5..74c9a58f 100644 --- a/src/syncoverwritedialog.h +++ b/src/syncoverwritedialog.h @@ -40,7 +40,7 @@ public: void apply(const QString &modDirectory); private: - void refresh(const QString &path, MOShared::DirectoryEntry *directoryStructure); + void refresh(const QString &path); void readTree(const QString &path, MOShared::DirectoryEntry *directoryStructure, QTreeWidgetItem *subTree); void applyTo(QTreeWidgetItem *item, const QString &path, const QString &modDirectory); |
