-
Notifications
You must be signed in to change notification settings - Fork 0
/
homm3singleton.cpp
61 lines (48 loc) · 1.44 KB
/
homm3singleton.cpp
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
/*
* homm3-wallpaper, live HOMM3 wallpaper
* Copyright (C) 2022-2024 i.Dark_Templar <[email protected]>
*
* Subject to terms and condition provided in LICENSE.txt
*
*/
#include "homm3singleton.h"
#include <QtCore/QUrl>
#include "vcmi/CBinaryReader.h"
#include "vcmi/CFileInputStream.h"
#include "lod_archive.h"
std::shared_ptr<Homm3MapSingleton> Homm3MapSingleton::s_instance;
std::mutex Homm3MapSingleton::s_instance_mutex;
std::shared_ptr<Homm3MapSingleton> Homm3MapSingleton::getInstance()
{
std::lock_guard<std::mutex> instance_lock(s_instance_mutex);
if (!s_instance)
{
s_instance = std::shared_ptr<Homm3MapSingleton>(new Homm3MapSingleton);
}
return s_instance;
}
void Homm3MapSingleton::setDataArchives(const QStringList &files)
{
std::map<std::string, std::tuple<std::string, LodEntry> > new_lod_entries;
for (const auto &file: files)
{
try
{
QUrl file_url(file);
file_url.setScheme(QLatin1String("file"));
std::string filename = file_url.toLocalFile().toLocal8Bit().data();
CFileInputStream file_stream{std::filesystem::path(filename)};
CBinaryReader reader(&file_stream);
std::vector<LodEntry> parsed_lod_entries = read_lod_archive_header(reader);
for (auto iter = parsed_lod_entries.begin(); iter != parsed_lod_entries.end(); ++iter)
{
new_lod_entries[iter->name] = std::tie(filename, *iter);
}
}
catch (...)
{
// ignore
}
}
lod_entries = std::move(new_lod_entries);
}