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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#include "platform/constants.hpp"
#include "platform/measurement_utils.hpp"
#include "platform/platform.hpp"
#include "platform/settings.hpp"
#include "coding/file_reader.hpp"
#include "base/logging.hpp"
#include "std/target_os.hpp"
#include <algorithm>
#include <future>
#include <memory>
#include <regex>
#include <string>
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QLocale>
using namespace std;
unique_ptr<ModelReader> Platform::GetReader(string const & file, string const & searchScope) const
{
return make_unique<FileReader>(ReadPathForFile(file, searchScope),
READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
}
bool Platform::GetFileSizeByName(string const & fileName, uint64_t & size) const
{
try
{
return GetFileSizeByFullPath(ReadPathForFile(fileName), size);
}
catch (RootException const &)
{
return false;
}
}
void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & outFiles)
{
regex exp(regexp);
QDir dir(QString::fromUtf8(directory.c_str()));
int const count = dir.count();
for (int i = 0; i < count; ++i)
{
string const name = dir[i].toUtf8().data();
if (regex_search(name.begin(), name.end(), exp))
outFiles.push_back(name);
}
}
int Platform::PreCachingDepth() const
{
return 3;
}
int Platform::VideoMemoryLimit() const
{
return 20 * 1024 * 1024;
}
// static
Platform::EError Platform::MkDir(string const & dirName)
{
if (QDir().exists(dirName.c_str()))
return Platform::ERR_FILE_ALREADY_EXISTS;
if(!QDir().mkdir(dirName.c_str()))
{
LOG(LWARNING, ("Can't create directory: ", dirName));
return Platform::ERR_UNKNOWN;
}
return Platform::ERR_OK;
}
void Platform::SetupMeasurementSystem() const
{
auto units = measurement_utils::Units::Metric;
if (settings::Get(settings::kMeasurementUnits, units))
return;
bool const isMetric = QLocale::system().measurementSystem() == QLocale::MetricSystem;
units = isMetric ? measurement_utils::Units::Metric : measurement_utils::Units::Imperial;
settings::Set(settings::kMeasurementUnits, units);
}
#if defined(OMIM_OS_LINUX)
void Platform::RunOnGuiThread(base::TaskLoop::Task && task)
{
ASSERT(m_guiThread, ());
m_guiThread->Push(std::move(task));
}
void Platform::RunOnGuiThread(base::TaskLoop::Task const & task)
{
ASSERT(m_guiThread, ());
m_guiThread->Push(task);
}
#endif // defined(OMIM_OS_LINUX)
extern Platform & GetPlatform()
{
static Platform platform;
return platform;
}
|