Welcome to mirror list, hosted at ThFree Co, Russian Federation.

platform.cpp « platform - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d4410a7dba65f60c403eac91fff596119cce5ad0 (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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "platform.hpp"
#include "settings.hpp"

#include "../coding/internal/file_data.hpp"
#include "../coding/file_reader.hpp"

#include "../base/logging.hpp"

#if !defined(OMIM_OS_WINDOWS_NATIVE) && !defined(OMIM_OS_BADA)
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#endif

#include "../base/start_mem_debug.hpp"


string BasePlatformImpl::ReadPathForFile(string const & file) const
{
  string fullPath = m_writableDir + file;
  if (!IsFileExists(fullPath))
  {
    fullPath = m_resourcesDir + file;
    if (!IsFileExists(fullPath))
      MYTHROW(FileAbsentException, ("File doesn't exist", fullPath));
  }
  return fullPath;
}

ModelReader * BasePlatformImpl::GetReader(string const & file) const
{
    return new FileReader(ReadPathForFile(file), 10, 12);
}

bool BasePlatformImpl::GetFileSize(string const & file, uint64_t & size) const
{
  return my::GetFileSize(file, size);
}

void BasePlatformImpl::GetFilesInDir(string const & directory, string const & mask, FilesList & res) const
{
#if !defined(OMIM_OS_WINDOWS_NATIVE) && !defined(OMIM_OS_BADA)
  DIR * dir;
  struct dirent * entry;

  if ((dir = opendir(directory.c_str())) == NULL)
    return;

  // TODO: take wildcards into account...
  string mask_fixed = mask;
  if (mask_fixed.size() && mask_fixed[0] == '*')
    mask_fixed.erase(0, 1);

  do
  {
    if ((entry = readdir(dir)) != NULL)
    {
      string fname(entry->d_name);
      size_t index = fname.rfind(mask_fixed);
      if (index != string::npos && index == fname.size() - mask_fixed.size())
      {
        // TODO: By some strange reason under simulator stat returns -1,
        // may be because of symbolic links?..
        //struct stat fileStatus;
        //if (stat(string(directory + fname).c_str(), &fileStatus) == 0 &&
        //    (fileStatus.st_mode & S_IFDIR) == 0)
        //{
          res.push_back(fname);
        //}
      }
    }
  } while (entry != NULL);

  closedir(dir);
#else
  MYTHROW(NotImplementedException, ("Function not implemented"));
#endif
}

bool BasePlatformImpl::RenameFileX(string const & fOld, string const & fNew) const
{
  return my::RenameFileX(fOld, fNew);
}

void BasePlatformImpl::GetFontNames(FilesList & res) const
{
  res.clear();
  GetFilesInDir(m_resourcesDir, "*.ttf", res);

  sort(res.begin(), res.end());

  for (size_t i = 0; i < res.size(); ++i)
    res[i] = m_resourcesDir + res[i];
}

double BasePlatformImpl::VisualScale() const
{
  return 1.0;
}

string BasePlatformImpl::SkinName() const
{
  return "basic.skn";
}

bool BasePlatformImpl::IsMultiSampled() const
{
  return true;
}

bool BasePlatformImpl::DoPeriodicalUpdate() const
{
  return true;
}

double BasePlatformImpl::PeriodicalUpdateInterval() const
{
  return 0.3;
}

bool BasePlatformImpl::IsBenchmarking() const
{
  bool res = false;
  (void)Settings::Get("IsBenchmarking", res);

#ifndef OMIM_PRODUCTION
  if (res)
  {
    static bool first = true;
    if (first)
    {
      LOG(LCRITICAL, ("Benchmarking only defined in production configuration!"));
      first = false;
    }
    res = false;
  }
#endif

  return res;
}

bool BasePlatformImpl::IsVisualLog() const
{
  return false;
}

int BasePlatformImpl::ScaleEtalonSize() const
{
  return 512 + 256;
}