Example #1
0
 inline StreamLogger info()
 {
     return infoEnabled()
          ? StreamLogger([](const std::string& msg) { logger().information(msg); }, "INF")
          : StreamLogger();
 }
Example #2
0
bool ModList::update()
{
	if (!isValid())
		return false;

	QList<Mod> orderedMods;
	QList<Mod> newMods;
	m_dir.refresh();
	auto folderContents = m_dir.entryInfoList();
	bool orderOrStateChanged = false;

	// first, process the ordered items (if any)
	OrderList listOrder = readListFile();
	for (auto item : listOrder)
	{
		QFileInfo infoEnabled(m_dir.filePath(item.id));
		QFileInfo infoDisabled(m_dir.filePath(item.id + ".disabled"));
		int idxEnabled = folderContents.indexOf(infoEnabled);
		int idxDisabled = folderContents.indexOf(infoDisabled);
		bool isEnabled;
		// if both enabled and disabled versions are present, it's a special case...
		if (idxEnabled >= 0 && idxDisabled >= 0)
		{
			// we only process the one we actually have in the order file.
			// and exactly as we have it.
			// THIS IS A CORNER CASE
			isEnabled = item.enabled;
		}
		else
		{
			// only one is present.
			// we pick the one that we found.
			// we assume the mod was enabled/disabled by external means
			isEnabled = idxEnabled >= 0;
		}
		int idx = isEnabled ? idxEnabled : idxDisabled;
		QFileInfo & info = isEnabled ? infoEnabled : infoDisabled;
		// if the file from the index file exists
		if (idx != -1)
		{
			// remove from the actual folder contents list
			folderContents.takeAt(idx);
			// append the new mod
			orderedMods.append(Mod(info));
			if (isEnabled != item.enabled)
				orderOrStateChanged = true;
		}
		else
		{
			orderOrStateChanged = true;
		}
	}
	// if there are any untracked files...
	if (folderContents.size())
	{
		// the order surely changed!
		for (auto entry : folderContents)
		{
			newMods.append(Mod(entry));
		}
		std::sort(newMods.begin(), newMods.end(), [](const Mod & left, const Mod & right)
		{ return left.name().localeAwareCompare(right.name()) <= 0; });
		orderedMods.append(newMods);
		orderOrStateChanged = true;
	}
	// otherwise, if we were already tracking some mods
	else if (mods.size())
	{
		// if the number doesn't match, order changed.
		if (mods.size() != orderedMods.size())
			orderOrStateChanged = true;
		// if it does match, compare the mods themselves
		else
			for (int i = 0; i < mods.size(); i++)
			{
				if (!mods[i].strongCompare(orderedMods[i]))
				{
					orderOrStateChanged = true;
					break;
				}
			}
	}
	beginResetModel();
	mods.swap(orderedMods);
	endResetModel();
	if (orderOrStateChanged && !m_list_file.isEmpty())
	{
		QLOG_INFO() << "Mod list " << m_list_file << " changed!";
		saveListFile();
		emit changed();
	}
	return true;
}