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>2011-10-31 00:14:52 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:27:10 +0300
commiteea66458919753af7edc32b9210adfa1a1f36751 (patch)
tree4545e07fbda279938b77b45069c7973c2437a857 /platform/platform_qt.cpp
parent29f6e38b349ca9620ed36a637c692fbccb12eb32 (diff)
Completed platform refactoring and fixed paths for resources/writable dirs
Diffstat (limited to 'platform/platform_qt.cpp')
-rw-r--r--platform/platform_qt.cpp111
1 files changed, 1 insertions, 110 deletions
diff --git a/platform/platform_qt.cpp b/platform/platform_qt.cpp
index 10ab490789..17895bfe08 100644
--- a/platform/platform_qt.cpp
+++ b/platform/platform_qt.cpp
@@ -8,119 +8,10 @@
#include <QtCore/QFileInfo>
#include <QtCore/QTemporaryFile>
-// default writable directory name for dev/standalone installs
-#define MAPDATA_DIR "data"
-// default writable dir name in LocalAppData or ~/Library/AppData/ folders
-#define LOCALAPPDATA_DIR "MapsWithMe"
-// default Resources read-only dir
-#define RESOURCES_DIR "Resources"
-
-/// @name Platform-dependent implementations in separate files
-//@{
-bool GetUserWritableDir(string & outDir);
-bool GetPathToBinary(string & outDir);
-//@}
-
-static bool IsDirectoryWritable(string const & dir)
-{
- if (!dir.empty())
- {
- QString qDir = dir.c_str();
- if (dir[dir.size() - 1] != '/' && dir[dir.size() - 1] != '\\')
- qDir.append('/');
-
- QTemporaryFile file(qDir + "XXXXXX");
- if (file.open())
- return true;
- }
- return false;
-}
-
-/// Scans all upper directories for the presence of given directory
-/// @param[in] startPath full path to lowest file in hierarchy (usually binary)
-/// @param[in] dirName directory name we want to be present
-/// @return if not empty, contains full path to existing directory
-static string DirFinder(string const & startPath, string dirName)
-{
- char const SLASH = QDir::separator().toAscii();
- dirName = SLASH + dirName + SLASH;
-
- size_t slashPos = startPath.size();
- while (slashPos > 0 && (slashPos = startPath.rfind(SLASH, slashPos - 1)) != string::npos)
- {
- string const dir = startPath.substr(0, slashPos) + dirName;
- if (QFileInfo(dir.c_str()).exists())
- return dir;
- }
- return string();
-}
-
-static bool GetOSSpecificResourcesDir(string const & exePath, string & dir)
-{
- dir = DirFinder(exePath, RESOURCES_DIR);
- return !dir.empty();
-}
-
-static void InitResourcesDir(string & dir)
-{
- // Resources dir can be any "data" folder found in the nearest upper directory,
- // where all necessary resources files are present and accessible
- string exePath;
- CHECK( GetPathToBinary(exePath), ("Can't get full path to executable") );
- dir = DirFinder(exePath, MAPDATA_DIR);
- if (dir.empty())
- {
- CHECK( GetOSSpecificResourcesDir(exePath, dir), ("Can't retrieve resources directory") );
- }
-
- /// @todo Check all necessary files
-}
-
-static void InitWritableDir(string & dir)
-{
- // Writable dir can be any "data" folder found in the nearest upper directory
- // ./data - For Windows portable builds
- // ../data
- // ../../data - For developer builds
- // etc. (for Mac in can be up to 6 levels above due to packages structure
- // and if no _writable_ "data" folder was found, User/Application Data/MapsWithMe will be used
-
- string path;
- CHECK( GetPathToBinary(path), ("Can't get full path to executable") );
- dir = DirFinder(path, MAPDATA_DIR);
- if (dir.empty() || !IsDirectoryWritable(dir))
- {
- CHECK( GetUserWritableDir(dir), ("Can't get User's Application Data writable directory") );
- }
-}
-
-static string ReadPathForFile(string const & writableDir,
- string const & resourcesDir, string const & file)
-{
- string fullPath = writableDir + file;
- if (!GetPlatform().IsFileExists(fullPath))
- {
- fullPath = resourcesDir + file;
- if (!GetPlatform().IsFileExists(fullPath))
- MYTHROW(FileAbsentException, ("File doesn't exist", fullPath));
- }
- return fullPath;
-}
-
////////////////////////////////////////////////////////////////////////////////////////
-Platform::Platform()
-{
- InitWritableDir(m_writableDir);
- InitResourcesDir(m_resourcesDir);
-}
-
-Platform::~Platform()
-{
-}
-
ModelReader * Platform::GetReader(string const & file) const
{
- return new FileReader(ReadPathForFile(m_writableDir, m_resourcesDir, file), 10, 12);
+ return new FileReader(ReadPathForFile(file), 10, 12);
}
bool Platform::GetFileSize(string const & file, uint64_t & size) const