aboutsummaryrefslogtreecommitdiff
path: root/libs/bsapacker/src/OverrideFileService.cpp
blob: 3e4ebec07a9fdc78482d3268c7f3e89a7e5cb60a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "OverrideFileService.h"

#include <questionboxmemory.h>
#include <QApplication>
#include <QDialogButtonBox>

namespace BsaPacker {
	const uint16_t FALLOUT_3_NEXUS_ID = 120;
	const uint16_t NEW_VEGAS_NEXUS_ID = 130;

	OverrideFileService::OverrideFileService(
		const IFileWriterService* fileWriterService)
		: m_FileWriterService(fileWriterService)
	{
	}

	// TODO: Add detection for Command Extender and JIP LN NVSE and warn if missing
	bool OverrideFileService::CreateOverrideFile(const int nexusId,
		const QString& modPath,
		const QStringList& archiveNames) const {

		if (nexusId != FALLOUT_3_NEXUS_ID && nexusId != NEW_VEGAS_NEXUS_ID) {
			return false;
		}

		if (MOBase::QuestionBoxMemory::query(QApplication::activeModalWidget(), "BSAPacker", "Create .override file?",
			"Do you want to create an override file for the archive(s)?",
			QDialogButtonBox::No | QDialogButtonBox::Yes, QDialogButtonBox::No) & QDialogButtonBox::No) {
			return false;
		}

		bool res = true;
		for (const QString& baseName : archiveNames) {
			const QString& fileNameNoExtension = modPath + '/' + baseName;
			const std::string& absoluteFileName = fileNameNoExtension.toStdString() + ".override";
			if (!this->m_FileWriterService->Write(absoluteFileName, nullptr, 0)) {
				qWarning() << "Failed to create" << absoluteFileName;
				res = false;
			}
		}

		return res;
	}
} // namespace BsaPacker