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_win.cpp
parent29f6e38b349ca9620ed36a637c692fbccb12eb32 (diff)
Completed platform refactoring and fixed paths for resources/writable dirs
Diffstat (limited to 'platform/platform_win.cpp')
-rw-r--r--platform/platform_win.cpp65
1 files changed, 59 insertions, 6 deletions
diff --git a/platform/platform_win.cpp b/platform/platform_win.cpp
index ff59584210..b0013e7c95 100644
--- a/platform/platform_win.cpp
+++ b/platform/platform_win.cpp
@@ -1,27 +1,28 @@
#include "platform.hpp"
+#include "../coding/file_writer.hpp"
+
#include "../std/windows.hpp"
#include <shlobj.h>
+#include <sys/stat.h>
-#define LOCALAPPDATA_DIR "MapsWithMe"
-
-bool GetUserWritableDir(string & outDir)
+static bool GetUserWritableDir(string & outDir)
{
char pathBuf[MAX_PATH] = {0};
if (SUCCEEDED(::SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, pathBuf)))
{
outDir = pathBuf;
::CreateDirectoryA(outDir.c_str(), NULL);
- outDir += "\\" LOCALAPPDATA_DIR "\\";
+ outDir += "\\MapsWithMe\\";
::CreateDirectoryA(outDir.c_str(), NULL);
return true;
}
return false;
}
-/// @return full path including binary itself
-bool GetPathToBinary(string & outPath)
+/// @return Full path to the executable file
+static bool GetPathToBinary(string & outPath)
{
// get path to executable
char pathBuf[MAX_PATH] = {0};
@@ -33,6 +34,58 @@ bool GetPathToBinary(string & outPath)
return false;
}
+Platform::Platform()
+{
+ string path;
+ CHECK(GetPathToBinary(path), ("Can't get path to binary"));
+
+ // resources path:
+ // 1. try to use data folder in the same path as executable
+ // 2. if not found, try to use ..\..\..\data (for development only)
+ path.erase(path.find_last_of('\\'));
+ if (IsFileExists(path + "\\data\\"))
+ m_resourcesDir = path + "\\data\\";
+ else
+ {
+#ifndef OMIM_PRODUCTION
+ path.erase(path.find_last_of('\\'));
+ path.erase(path.find_last_of('\\'));
+ if (IsFileExists(path + "\\data\\"))
+ m_resourcesDir = path + "\\data\\";
+#else
+ CHECK(false, ("Can't find resources directory"));
+#endif
+ }
+
+ // writable path:
+ // 1. the same as resources if we have write access to this folder
+ // 2. otherwise, use system-specific folder
+ try
+ {
+ FileWriter tmpfile(m_resourcesDir + "mapswithmetmptestfile");
+ tmpfile.Write("Hi from Alex!", 13);
+ FileWriter::DeleteFileX(m_resourcesDir + "mapswithmetmptestfile");
+ m_writableDir = m_resourcesDir;
+ }
+ catch (FileWriter::RootException const &)
+ {
+ CHECK(GetUserWritableDir(m_writableDir), ("Can't get writable directory"));
+ }
+
+ LOG(LDEBUG, ("Resources Directory:", m_resourcesDir));
+ LOG(LDEBUG, ("Writable Directory:", m_writableDir));
+}
+
+Platform::~Platform()
+{
+}
+
+bool Platform::IsFileExists(string const & file) const
+{
+ struct _stat s;
+ return _stat(file.c_str(), &s) == 0;
+}
+
int Platform::CpuCores() const
{
SYSTEM_INFO sysinfo;