blob: 9cea91b66e26348dcee4fcbcedf2342bd458de62 (
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "ArchiveNameService.h"
#include "NexusId.h"
#include <QFileInfo>
namespace BsaPacker
{
ArchiveNameService::ArchiveNameService(const IModContext* modContext)
: m_ModContext(modContext)
{
}
QString ArchiveNameService::GetFileExtension() const
{
switch (this->m_ModContext->GetNexusId()) {
case NexusId::Morrowind:
case NexusId::Oblivion:
case NexusId::Fallout3:
case NexusId::NewVegas:
case NexusId::Skyrim:
case NexusId::SkyrimSE:
case NexusId::Enderal:
case NexusId::EnderalSE:
return QStringLiteral(".bsa");
case NexusId::Fallout4:
case NexusId::Starfield:
return QStringLiteral(".ba2");
default:
return QString();
}
}
QString ArchiveNameService::GetArchiveFullPath(const bsa_archive_type_e type, const IModDto* modDto) const
{
const QString& pathNoExt(QDir::toNativeSeparators(modDto->Directory() + '/' + modDto->ArchiveName() + this->Infix(type)));
const QString& suffix = this->Suffix(pathNoExt);
return QDir::toNativeSeparators(pathNoExt + suffix + this->GetFileExtension());
}
QString ArchiveNameService::Infix(const bsa_archive_type_e type) const
{
switch (type) {
case baFO4:
case baSF:
return QStringLiteral(" - Main");
case baSFdds:
case baFO4dds:
return QStringLiteral(" - Textures");
case baTES3:
case baTES4:
case baFO3:
case baSSE:
case baNone:
default:
return QString();
};
}
// gets the number to append when there are multiple archives
// a way to avoid overwriting any existing files
QString ArchiveNameService::Suffix(const QString& pathNoExt) const {
int archiveIndex = 0;
const QString& fileExt = this->GetFileExtension();
QFileInfo fileInfo(pathNoExt + fileExt);
while (fileInfo.exists()) {
++archiveIndex;
fileInfo.setFile(pathNoExt + QString::number(archiveIndex) + fileExt);
}
if (archiveIndex != 0) {
return QString::number(archiveIndex);
}
return QString();
}
}
|