MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / saveLoadOrder

Method saveLoadOrder

src/pluginlist.cpp:683–738  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

681}
682
683bool PluginList::saveLoadOrder(DirectoryEntry& directoryStructure)
684{
685 if (m_GamePlugin->loadOrderMechanism() != IPluginGame::LoadOrderMechanism::FileTime) {
686 // nothing to do
687 return true;
688 }
689
690 log::debug("setting file times on esps");
691
692 for (ESPInfo& esp : m_ESPs) {
693 std::wstring espName = ToWString(esp.name);
694 const FileEntryPtr fileEntry = directoryStructure.findFile(espName);
695 if (fileEntry.get() != nullptr) {
696 QString fileName;
697 bool archive = false;
698 int originid = fileEntry->getOrigin(archive);
699
700 fileName = QString("%1\\%2")
701 .arg(QDir::toNativeSeparators(ToQString(
702 directoryStructure.getOriginByID(originid).getPath())))
703 .arg(esp.name);
704
705 HANDLE file =
706 ::CreateFile(ToWString(fileName).c_str(), GENERIC_READ | GENERIC_WRITE, 0,
707 nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
708 if (file == INVALID_HANDLE_VALUE) {
709 if (::GetLastError() == ERROR_SHARING_VIOLATION) {
710 // file is locked, probably the game is running
711 return false;
712 } else {
713 throw windows_error(
714 QObject::tr("failed to access %1").arg(fileName).toUtf8().constData());
715 }
716 }
717
718 ULONGLONG temp = 0;
719 temp = (145731ULL + esp.priority) * 24 * 60 * 60 * 10000000ULL;
720
721 FILETIME newWriteTime;
722
723 newWriteTime.dwLowDateTime = (DWORD)(temp & 0xFFFFFFFF);
724 newWriteTime.dwHighDateTime = (DWORD)(temp >> 32);
725 esp.time = newWriteTime;
726 fileEntry->setFileTime(newWriteTime);
727 if (!::SetFileTime(file, nullptr, nullptr, &newWriteTime)) {
728 throw windows_error(QObject::tr("failed to set file time %1")
729 .arg(fileName)
730 .toUtf8()
731 .constData());
732 }
733
734 CloseHandle(file);
735 }
736 }
737 return true;
738}
739
740int PluginList::enabledCount() const

Callers 1

savePluginListMethod · 0.80

Calls 7

ToWStringFunction · 0.85
QStringClass · 0.85
windows_errorClass · 0.85
setFileTimeMethod · 0.80
findFileMethod · 0.45
getMethod · 0.45
getOriginMethod · 0.45

Tested by

no test coverage detected