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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Zolotarev <deathbaba@gmail.com>2012-01-06 23:13:29 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:31:23 +0300
commit3932615f2a7e4539b06b8426028067ca92974776 (patch)
tree9da613dd8811122b84b14ba0f7195b30ca558053 /platform
parent99a00dda73a793ef506fcf16ef80f3dab20282ff (diff)
Added Platform::TmpPathForFile() and Platform::SettingsPathForFile()
Closed #492 - Save viewport on Android when external memory is ejected
Diffstat (limited to 'platform')
-rw-r--r--platform/platform.hpp25
-rw-r--r--platform/platform_ios.mm3
-rw-r--r--platform/platform_linux.cpp10
-rw-r--r--platform/platform_mac.mm10
-rw-r--r--platform/platform_win.cpp7
-rw-r--r--platform/settings.cpp6
6 files changed, 56 insertions, 5 deletions
diff --git a/platform/platform.hpp b/platform/platform.hpp
index a4c92a4dca..e73832d640 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -16,14 +16,24 @@ DECLARE_EXCEPTION(NotImplementedException, RootException);
class Platform
{
protected:
- string m_writableDir, m_resourcesDir;
+ /// Usually read-only directory for application resources
+ string m_resourcesDir;
+ /// Writable directory to store downloaded map data
+ /// @note on some systems it can point to external ejectable storage
+ string m_writableDir;
+ /// Temporary directory, can be cleaned up by the system
+ string m_tmpDir;
+ /// Writable directory to store persistent application data
+ string m_settingsDir;
+
class PlatformImpl;
/// Used only on those platforms where needed
PlatformImpl * m_impl;
static bool IsFileExistsByFullPath(string const & filePath);
- /// Internal function to use files from writable dir if they override the same in the resources
+ /// Internal function to use files from writable dir
+ /// if they override the same file in the resources dir
string ReadPathForFile(string const & file) const
{
string fullPath = m_writableDir + file;
@@ -48,6 +58,17 @@ public:
/// @return resource dir (on some platforms it's differ from Writable dir)
string ResourcesDir() const { return m_resourcesDir; }
+ /// @return path for directory with temporary files with slash at the end
+ string TmpDir() const { return m_tmpDir; }
+ /// @return full path to file in the temporary directory
+ string TmpPathForFile(string const & file) const { return TmpDir() + file; }
+
+ /// @return path for directory in the persistent memory, can be the same
+ /// as WritableDir, but on some platforms it's different
+ string SettingsDir() const { return m_settingsDir; }
+ /// @return full path to file in the settings directory
+ string SettingsPathForFile(string const & file) const { return SettingsDir() + file; }
+
/// @return reader for file decriptor.
/// @throws FileAbsentException
/// @param[in] file descriptor which we want to read
diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm
index 404a055d53..cc03facf0b 100644
--- a/platform/platform_ios.mm
+++ b/platform/platform_ios.mm
@@ -50,6 +50,9 @@ Platform::Platform()
NSString * docsDir = [dirPaths objectAtIndex:0];
m_writableDir = [docsDir UTF8String];
m_writableDir += '/';
+ m_settingsDir = m_writableDir;
+ m_tmpDir = [NSHomeDirectory() UTF8String];
+ m_tmpDir += '/tmp/';
// Hardcoding screen resolution depending on the device we are running.
m_impl->m_visualScale = 1.0;
diff --git a/platform/platform_linux.cpp b/platform/platform_linux.cpp
index 9cfebaa4b5..634caf3f17 100644
--- a/platform/platform_linux.cpp
+++ b/platform/platform_linux.cpp
@@ -41,9 +41,17 @@ Platform::Platform()
// @TODO implement correct resources and writable directories for public releases
m_resourcesDir = path + "../../data/";
m_writableDir = m_resourcesDir;
+ m_settingsDir = m_writableDir;
+ char * tmpDir = ::getenv("TMPDIR");
+ if (tmpDir)
+ m_tmpDir = tmpDir;
+ else
+ m_tmpDir = P_tmpdir;
LOG(LDEBUG, ("Resources directory:", m_resourcesDir));
LOG(LDEBUG, ("Writable directory:", m_writableDir));
+ LOG(LDEBUG, ("Tmp directory:", m_tmpDir));
+ LOG(LDEBUG, ("Settings directory:", m_settingsDir));
}
Platform::~Platform()
@@ -58,7 +66,7 @@ bool Platform::IsFileExistsByFullPath(string const & filePath)
int Platform::CpuCores() const
{
- long numCPU = sysconf(_SC_NPROCESSORS_ONLN);
+ const long numCPU = sysconf(_SC_NPROCESSORS_ONLN);
if (numCPU >= 1)
return static_cast<int>(numCPU);
return 1;
diff --git a/platform/platform_mac.mm b/platform/platform_mac.mm
index 7db07c03e8..73e4bb1137 100644
--- a/platform/platform_mac.mm
+++ b/platform/platform_mac.mm
@@ -54,8 +54,18 @@ Platform::Platform()
}
[pool release];
+ m_settingsDir = m_writableDir;
+
+ NSString * tempDir = NSTemporaryDirectory();
+ if (tempDir == nil)
+ tempDir = @"/tmp";
+ m_tmpDir = [tempDir UTF8String];
+ m_tmpDir += '/';
+
LOG(LDEBUG, ("Resources Directory:", m_resourcesDir));
LOG(LDEBUG, ("Writable Directory:", m_writableDir));
+ LOG(LDEBUG, ("Tmp Directory:", m_tmpDir));
+ LOG(LDEBUG, ("Settings Directory:", m_settingsDir));
}
Platform::~Platform()
diff --git a/platform/platform_win.cpp b/platform/platform_win.cpp
index 62934716b2..4edfe71d71 100644
--- a/platform/platform_win.cpp
+++ b/platform/platform_win.cpp
@@ -73,8 +73,15 @@ Platform::Platform()
}
FileWriter::DeleteFileX(m_resourcesDir + "mapswithmetmptestfile");
+ m_settingsDir = m_writableDir;
+ char pathBuf[MAX_PATH] = {0};
+ GetTempPathA(MAX_PATH, pathBuf);
+ m_tmpDir = pathBuf;
+
LOG(LDEBUG, ("Resources Directory:", m_resourcesDir));
LOG(LDEBUG, ("Writable Directory:", m_writableDir));
+ LOG(LDEBUG, ("Tmp Directory:", m_tmpDir));
+ LOG(LDEBUG, ("Settings Directory:", m_settingsDir));
}
Platform::~Platform()
diff --git a/platform/settings.cpp b/platform/settings.cpp
index 67bbf18753..d70b3273a8 100644
--- a/platform/settings.cpp
+++ b/platform/settings.cpp
@@ -23,7 +23,9 @@ namespace Settings
try
{
string str;
- ReaderPtr<Reader>(GetPlatform().GetReader(SETTINGS_FILE_NAME)).ReadAsString(str);
+ {
+ FileReader(GetPlatform().SettingsPathForFile(SETTINGS_FILE_NAME)).ReadAsString(str);
+ }
istringstream stream(str);
string line;
while (stream.good())
@@ -53,7 +55,7 @@ namespace Settings
// @TODO add mutex
try
{
- FileWriter file(GetPlatform().WritablePathForFile(SETTINGS_FILE_NAME));
+ FileWriter file(GetPlatform().SettingsPathForFile(SETTINGS_FILE_NAME));
for (ContainerT::const_iterator it = m_values.begin(); it != m_values.end(); ++it)
{
string line(it->first);