Rewrote logic for maps adding. First, we read all maps from resources,

next, replace existing maps from writable data path
This commit is contained in:
Alex Zolotarev 2011-06-01 20:21:19 +02:00 committed by Alex Zolotarev
parent 6c18bb6844
commit 1da1ecf3b6
7 changed files with 53 additions and 19 deletions

View file

@ -10,6 +10,7 @@ public:
virtual ~IPhonePlatform();
virtual double TimeInSec() const;
virtual string WritableDir() const;
virtual string ResourcesDir() const;
virtual string ReadPathForFile(char const * file) const;
virtual int GetFilesInDir(string const & directory, string const & mask, FilesList & outFiles) const;
virtual bool GetFileSize(string const & file, uint64_t & size) const;

View file

@ -98,6 +98,11 @@ string IPhonePlatform::ReadPathForFile(char const * file) const
return path;
}
virtual string IPhonePlatform::ResourcesDir() const
{
return m_resourcesPath;
}
string IPhonePlatform::WritableDir() const
{
return m_writablePath;

View file

@ -463,21 +463,54 @@ void FrameWork<TModel>::AddRedrawCommandSure()
}
}
struct PathAppender
{
string const & m_path;
PathAppender(string const & path) : m_path(path) {}
void operator()(string & elem)
{
elem.insert(elem.begin(), m_path.begin(), m_path.end());
}
};
template <typename TModel>
void FrameWork<TModel>::EnumLocalMaps(Platform::FilesList & filesList)
{
// activate all downloaded maps
Platform & p = GetPlatform();
// scan for pre-installed maps in resources
string const resPath = p.ResourcesDir();
Platform::FilesList resFiles;
p.GetFilesInDir(resPath, "*" DATA_FILE_EXTENSION, resFiles);
// scan for probably updated maps in data dir
string const dataPath = p.WritableDir();
Platform::FilesList dataFiles;
p.GetFilesInDir(dataPath, "*" DATA_FILE_EXTENSION, dataFiles);
// wipe out same maps from resources, which have updated
// downloaded versions in data path
for (Platform::FilesList::iterator it = resFiles.begin(); it != resFiles.end();)
{
Platform::FilesList::iterator found = find(dataFiles.begin(), dataFiles.end(), *it);
if (found != dataFiles.end())
it = resFiles.erase(it);
else
++it;
}
// make full resources paths
for_each(resFiles.begin(), resFiles.end(), PathAppender(resPath));
// make full data paths
for_each(dataFiles.begin(), dataFiles.end(), PathAppender(dataPath));
filesList.clear();
p.GetFilesInDir(dataPath, "*" DATA_FILE_EXTENSION, filesList);
filesList.assign(resFiles.begin(), resFiles.end());
filesList.insert(filesList.end(), dataFiles.begin(), dataFiles.end());
}
template <typename TModel>
void FrameWork<TModel>::EnumBenchmarkMaps(Platform::FilesList & filesList)
{
filesList.clear();
filesList.push_back("Belarus.mwm");
filesList.push_back(GetPlatform().ReadPathForFile("Belarus.mwm"));
}
template <typename TModel>

View file

@ -210,7 +210,7 @@ public:
bind(&FrameWork::RepaintRect, this, _1),
enumMapsFn);
LOG(LINFO, ("Storage initialized"));
};
}
void StartLocationService(LocationRetrievedCallbackT observer);
void StopLocationService();

View file

@ -26,6 +26,8 @@ public:
return WritableDir() + file;
}
virtual string ResourcesDir() const = 0;
/// Throws FileAbsentException
/// @param[in] file just file name which we want to read
/// @return fullPath fully resolved path including file name

View file

@ -243,6 +243,12 @@ public:
return m_writableDir;
}
/// @return path to /data/ with ending slash
virtual string ResourcesDir() const
{
return m_resourcesDir;
}
virtual string ReadPathForFile(char const * file) const
{
string fullPath = m_writableDir + file;

View file

@ -59,26 +59,13 @@ namespace storage
for (Platform::FilesList::iterator it = filesList.begin(); it != filesList.end(); ++it)
{ // simple way to avoid continuous crashes with invalid data files
try {
m_addMap(GetPlatform().WritableDir() + *it);
m_addMap(*it);
} catch (std::exception const & e)
{
FileWriter::DeleteFileX(GetPlatform().WritableDir() + *it);
FileWriter::DeleteFileX(*it);
LOG(LWARNING, (e.what(), "while adding file", *it, "so this file is deleted"));
}
}
// separate code to activate world data file from resources
// if it's not found in writable data dir
Platform::FilesList::iterator found = std::find(filesList.begin(), filesList.end(),
string(WORLD_FILE_NAME DATA_FILE_EXTENSION));
if (found == filesList.end())
{
try {
m_addMap(GetPlatform().ReadPathForFile(WORLD_FILE_NAME DATA_FILE_EXTENSION));
} catch (std::exception const & e)
{
LOG(LWARNING, (e.what(), "while adding world data file"));
}
}
}
string Storage::UpdateBaseUrl() const