本文整理匯總了C++中DirectoryEntry::getOriginByID方法的典型用法代碼示例。如果您正苦於以下問題:C++ DirectoryEntry::getOriginByID方法的具體用法?C++ DirectoryEntry::getOriginByID怎麽用?C++ DirectoryEntry::getOriginByID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DirectoryEntry
的用法示例。
在下文中一共展示了DirectoryEntry::getOriginByID方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: saveLoadOrder
bool PluginList::saveLoadOrder(DirectoryEntry &directoryStructure)
{
if (m_GamePlugin->loadOrderMechanism() != IPluginGame::LoadOrderMechanism::FileTime) {
// nothing to do
return true;
}
qDebug("setting file times on esps");
for (ESPInfo &esp : m_ESPs) {
std::wstring espName = ToWString(esp.m_Name);
const FileEntry::Ptr fileEntry = directoryStructure.findFile(espName);
if (fileEntry.get() != nullptr) {
QString fileName;
bool archive = false;
int originid = fileEntry->getOrigin(archive);
fileName = QString("%1\\%2").arg(QDir::toNativeSeparators(ToQString(directoryStructure.getOriginByID(originid).getPath()))).arg(esp.m_Name);
HANDLE file = ::CreateFile(ToWString(fileName).c_str(), GENERIC_READ | GENERIC_WRITE,
0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (file == INVALID_HANDLE_VALUE) {
if (::GetLastError() == ERROR_SHARING_VIOLATION) {
// file is locked, probably the game is running
return false;
} else {
throw windows_error(QObject::tr("failed to access %1").arg(fileName).toUtf8().constData());
}
}
ULONGLONG temp = 0;
temp = (145731ULL + esp.m_Priority) * 24 * 60 * 60 * 10000000ULL;
FILETIME newWriteTime;
newWriteTime.dwLowDateTime = (DWORD)(temp & 0xFFFFFFFF);
newWriteTime.dwHighDateTime = (DWORD)(temp >> 32);
esp.m_Time = newWriteTime;
fileEntry->setFileTime(newWriteTime);
if (!::SetFileTime(file, nullptr, nullptr, &newWriteTime)) {
throw windows_error(QObject::tr("failed to set file time %1").arg(fileName).toUtf8().constData());
}
CloseHandle(file);
}
}
示例2: refresh
void PluginList::refresh(const QString &profileName
, const DirectoryEntry &baseDirectory
, const QString &pluginsFile
, const QString &loadOrderFile
, const QString &lockedOrderFile)
{
ChangeBracket<PluginList> layoutChange(this);
m_ESPsByName.clear();
m_ESPsByPriority.clear();
m_ESPs.clear();
QStringList primaryPlugins = m_GamePlugin->primaryPlugins();
m_CurrentProfile = profileName;
std::vector<FileEntry::Ptr> files = baseDirectory.getFiles();
for (auto iter = files.begin(); iter != files.end(); ++iter) {
FileEntry::Ptr current = *iter;
if (current.get() == nullptr) {
continue;
}
QString filename = ToQString(current->getName());
QString extension = filename.right(3).toLower();
if ((extension == "esp") || (extension == "esm")) {
bool forceEnabled = Settings::instance().forceEnableCoreFiles() &&
std::find(primaryPlugins.begin(), primaryPlugins.end(), filename.toLower()) != primaryPlugins.end();
bool archive = false;
try {
FilesOrigin &origin = baseDirectory.getOriginByID(current->getOrigin(archive));
QString iniPath = QFileInfo(filename).baseName() + ".ini";
bool hasIni = baseDirectory.findFile(ToWString(iniPath)).get() != nullptr;
QString originName = ToQString(origin.getName());
unsigned int modIndex = ModInfo::getIndex(originName);
if (modIndex != UINT_MAX) {
ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
originName = modInfo->name();
}
m_ESPs.push_back(ESPInfo(filename, forceEnabled, originName, ToQString(current->getFullPath()), hasIni));
} catch (const std::exception &e) {
reportError(tr("failed to update esp info for file %1 (source id: %2), error: %3").arg(filename).arg(current->getOrigin(archive)).arg(e.what()));
}
}
}
if (readLoadOrder(loadOrderFile)) {
int maxPriority = 0;
// assign known load orders
for (std::vector<ESPInfo>::iterator espIter = m_ESPs.begin(); espIter != m_ESPs.end(); ++espIter) {
std::map<QString, int>::const_iterator priorityIter = m_ESPLoadOrder.find(espIter->m_Name.toLower());
if (priorityIter != m_ESPLoadOrder.end()) {
if (priorityIter->second > maxPriority) {
maxPriority = priorityIter->second;
}
espIter->m_Priority = priorityIter->second;
} else {
espIter->m_Priority = -1;
}
}
++maxPriority;
// assign maximum priorities for plugins with unknown priority
for (std::vector<ESPInfo>::iterator espIter = m_ESPs.begin(); espIter != m_ESPs.end(); ++espIter) {
if (espIter->m_Priority == -1) {
espIter->m_Priority = maxPriority++;
}
}
} else {
// no load order stored, determine by date
std::sort(m_ESPs.begin(), m_ESPs.end(), ByDate);
for (size_t i = 0; i < m_ESPs.size(); ++i) {
m_ESPs[i].m_Priority = i;
}
}
std::sort(m_ESPs.begin(), m_ESPs.end(), ByPriority); // first, sort by priority
// remove gaps from the priorities so we can use them as array indices without overflow
for (int i = 0; i < static_cast<int>(m_ESPs.size()); ++i) {
m_ESPs[i].m_Priority = i;
}
std::sort(m_ESPs.begin(), m_ESPs.end(), ByName); // sort by name so alphabetical sorting works
updateIndices();
readEnabledFrom(pluginsFile);
readLockedOrderFrom(lockedOrderFile);
layoutChange.finish();
refreshLoadOrder();
emit dataChanged(this->index(0, 0), this->index(m_ESPs.size(), columnCount()));
//.........這裏部分代碼省略.........