forked from organicmaps/organicmaps
[Refactoring]
- Add more file api; - IsBenchmark check in settings.ini; - Platform::GetFilesInDir has posix realization now in BasePlatformImpl; - IPhonePlatform fixes;
This commit is contained in:
parent
f0f32767ff
commit
338984fd5a
8 changed files with 139 additions and 73 deletions
|
@ -36,6 +36,7 @@ SOURCES += ../../testing/testingmain.cpp \
|
|||
sha2_test.cpp \
|
||||
value_opt_string_test.cpp \
|
||||
multilang_utf8_string_test.cpp \
|
||||
file_data_test.cpp \
|
||||
|
||||
HEADERS += \
|
||||
reader_test.hpp \
|
||||
|
|
38
coding/coding_tests/file_data_test.cpp
Normal file
38
coding/coding_tests/file_data_test.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include "../../testing/testing.hpp"
|
||||
|
||||
#include "../internal/file_data.hpp"
|
||||
#include "../writer.hpp"
|
||||
|
||||
#include "../../base/logging.hpp"
|
||||
|
||||
|
||||
UNIT_TEST(FileData_Api_Smoke)
|
||||
{
|
||||
string name = "test.file";
|
||||
string newName = "new_test.file";
|
||||
|
||||
try
|
||||
{
|
||||
// just create file and close it immediately
|
||||
my::FileData f(name, my::FileData::OP_WRITE_TRUNCATE);
|
||||
}
|
||||
catch (Writer::OpenException const &)
|
||||
{
|
||||
LOG(LCRITICAL, ("Can't create test file"));
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t sz;
|
||||
TEST_EQUAL(my::GetFileSize(name, sz), true, ());
|
||||
TEST_EQUAL(sz, 0, ());
|
||||
|
||||
TEST_EQUAL(my::RenameFileX(name, newName), true, ());
|
||||
|
||||
TEST_EQUAL(my::GetFileSize(name, sz), false, ());
|
||||
TEST_EQUAL(my::GetFileSize(newName, sz), true, ());
|
||||
TEST_EQUAL(sz, 0, ());
|
||||
|
||||
my::DeleteFileX(newName);
|
||||
|
||||
TEST_EQUAL(my::GetFileSize(newName, sz), false, ());
|
||||
}
|
|
@ -155,24 +155,23 @@ void FileData::Flush()
|
|||
|
||||
bool GetFileSize(string const & fName, uint64_t & sz)
|
||||
{
|
||||
try
|
||||
{
|
||||
typedef my::FileData fdata_t;
|
||||
fdata_t f(fName, fdata_t::OP_READ);
|
||||
sz = f.Size();
|
||||
return true;
|
||||
}
|
||||
catch (Writer::SeekException const &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (Reader::OpenException const &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
typedef my::FileData fdata_t;
|
||||
fdata_t f(fName, fdata_t::OP_READ);
|
||||
sz = f.Size();
|
||||
return true;
|
||||
}
|
||||
catch (Writer::SeekException const &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (Reader::OpenException const &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DeleteFileX(string const & fName)
|
||||
{
|
||||
#ifdef OMIM_OS_BADA
|
||||
|
@ -193,4 +192,13 @@ void DeleteFileX(string const & fName)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool RenameFileX(string const & fOld, string const & fNew)
|
||||
{
|
||||
#ifdef OMIM_OS_BADA
|
||||
return Osp::Io::File::Rename(fOld.c_str(), fNew.c_str());
|
||||
#else
|
||||
return (0 == rename(fOld.c_str(), fNew.c_str()));
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,5 +44,6 @@ private:
|
|||
|
||||
bool GetFileSize(string const & fName, uint64_t & sz);
|
||||
void DeleteFileX(string const & fName);
|
||||
bool RenameFileX(string const & fOld, string const & fNew);
|
||||
|
||||
}
|
||||
|
|
|
@ -8,10 +8,9 @@ public:
|
|||
IPhonePlatform();
|
||||
virtual ~IPhonePlatform();
|
||||
|
||||
virtual void GetFilesInDir(string const & directory, string const & mask, FilesList & outFiles) const;
|
||||
virtual bool RenameFileX(string const & original, string const & newName) const;
|
||||
virtual int CpuCores() const;
|
||||
virtual double VisualScale() const;
|
||||
virtual bool IsMultiSampled() const;
|
||||
virtual string SkinName() const;
|
||||
virtual string DeviceID() const;
|
||||
virtual int ScaleEtalonSize() const;
|
||||
|
|
|
@ -2,15 +2,13 @@
|
|||
#import <Foundation/NSBundle.h>
|
||||
#import <Foundation/NSPathUtilities.h>
|
||||
#import <Foundation/NSProcessInfo.h>
|
||||
|
||||
#import <UIKit/UIDevice.h>
|
||||
#import <UIKit/UIScreen.h>
|
||||
#import <UIKit/UIScreenMode.h>
|
||||
|
||||
#include "IPhonePlatform.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
IPhonePlatform::IPhonePlatform()
|
||||
{
|
||||
|
@ -27,7 +25,7 @@ IPhonePlatform::IPhonePlatform()
|
|||
m_writableDir += '/';
|
||||
|
||||
/// Hardcoding screen resolution depending on the device we are running.
|
||||
m_visualScale = 1.0;
|
||||
m_visualScale = 1.0;
|
||||
m_skinName = "basic.skn";
|
||||
|
||||
/// Calculating resolution
|
||||
|
@ -38,8 +36,8 @@ IPhonePlatform::IPhonePlatform()
|
|||
{
|
||||
m_deviceID = "iPad";
|
||||
m_visualScale = 1.3;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
range = [device.name rangeOfString:@"iPod"];
|
||||
float ver = [device.systemVersion floatValue];
|
||||
|
@ -67,58 +65,17 @@ IPhonePlatform::~IPhonePlatform()
|
|||
{
|
||||
}
|
||||
|
||||
void IPhonePlatform::GetFilesInDir(string const & directory, string const & mask, FilesList & outFiles) const
|
||||
{
|
||||
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))
|
||||
//{
|
||||
outFiles.push_back(fname);
|
||||
//}
|
||||
}
|
||||
}
|
||||
} while (entry != NULL);
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
bool IPhonePlatform::RenameFileX(string const & original, string const & newName) const
|
||||
{
|
||||
return rename(original.c_str(), newName.c_str());
|
||||
}
|
||||
|
||||
int IPhonePlatform::CpuCores() const
|
||||
{
|
||||
NSInteger numCPU = [[NSProcessInfo processInfo] activeProcessorCount];
|
||||
NSInteger numCPU = [[NSProcessInfo processInfo] activeProcessorCount];
|
||||
if (numCPU >= 1)
|
||||
return numCPU;
|
||||
return 1;
|
||||
return numCPU;
|
||||
return 1;
|
||||
}
|
||||
|
||||
string IPhonePlatform::SkinName() const
|
||||
{
|
||||
return m_skinName;
|
||||
return m_skinName;
|
||||
}
|
||||
|
||||
double IPhonePlatform::VisualScale() const
|
||||
|
@ -126,14 +83,19 @@ double IPhonePlatform::VisualScale() const
|
|||
return m_visualScale;
|
||||
}
|
||||
|
||||
bool IPhonePlatform::IsMultiSampled() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int IPhonePlatform::ScaleEtalonSize() const
|
||||
{
|
||||
return m_scaleEtalonSize;
|
||||
return m_scaleEtalonSize;
|
||||
}
|
||||
|
||||
string IPhonePlatform::DeviceID() const
|
||||
{
|
||||
return m_deviceID;
|
||||
return m_deviceID;
|
||||
}
|
||||
|
||||
Platform & GetPlatform()
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
#include "platform.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#include "../coding/internal/file_data.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"
|
||||
|
||||
|
||||
|
@ -24,6 +31,51 @@ 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();
|
||||
|
@ -63,18 +115,21 @@ double BasePlatformImpl::PeriodicalUpdateInterval() const
|
|||
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"));
|
||||
LOG(LCRITICAL, ("Benchmarking only defined in production configuration!"));
|
||||
first = false;
|
||||
}
|
||||
res = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
|
||||
DECLARE_EXCEPTION(FileAbsentException, RootException);
|
||||
DECLARE_EXCEPTION(NotImplementedException, RootException);
|
||||
|
||||
|
||||
class Platform
|
||||
|
@ -84,8 +85,9 @@ public:
|
|||
virtual string ResourcesDir() const { return m_resourcesDir; }
|
||||
virtual string ReadPathForFile(string const & file) const;
|
||||
|
||||
virtual void GetFilesInDir(string const & directory, string const & mask, FilesList & res) const;
|
||||
virtual bool GetFileSize(string const & file, uint64_t & size) const;
|
||||
|
||||
virtual bool RenameFileX(string const & fOld, string const & fNew) const;
|
||||
virtual void GetFontNames(FilesList & res) const;
|
||||
|
||||
virtual double VisualScale() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue