Add file name utils to platform.pro

This commit is contained in:
vng 2012-06-22 18:22:14 -07:00 committed by Alex Zolotarev
parent ff55299029
commit 92236836ac
5 changed files with 41 additions and 13 deletions

View file

@ -0,0 +1,21 @@
#include "file_name_utils.hpp"
namespace pl
{
void GetNameWithoutExt(string & name)
{
string::size_type const i = name.find_last_of(".");
if (i != string::npos)
name.erase(i);
}
void GetNameFromURLRequest(string & name)
{
string::size_type const i = name.find_last_of("/\\");
if (i != string::npos)
name = name.substr(i+1);
}
}

View file

@ -0,0 +1,9 @@
#pragma once
#include "../std/string.hpp"
namespace pl
{
void GetNameWithoutExt(string & name);
void GetNameFromURLRequest(string & name);
}

View file

@ -62,6 +62,7 @@ HEADERS += \
chunks_download_strategy.hpp \
servers_list.hpp \
constants.hpp \
file_name_utils.hpp
SOURCES += \
preferred_languages.cpp \
@ -71,3 +72,4 @@ SOURCES += \
chunks_download_strategy.cpp \
platform.cpp \
servers_list.cpp \
file_name_utils.cpp

View file

@ -7,6 +7,7 @@
#include "../platform/platform.hpp"
#include "../platform/servers_list.hpp"
#include "../platform/file_name_utils.hpp"
#include "../coding/file_writer.hpp"
#include "../coding/file_reader.hpp"
@ -347,13 +348,11 @@ namespace storage
void Storage::Unsubscribe(int slotId)
{
for (list<CountryObservers>::iterator it = m_observers.begin();
it != m_observers.end();
++it)
for (ObserversContT::iterator i = m_observers.begin(); i != m_observers.end(); ++i)
{
if (it->m_slotId == slotId)
if (i->m_slotId == slotId)
{
m_observers.erase(it);
m_observers.erase(i);
return;
}
}
@ -385,11 +384,7 @@ namespace storage
// get file descriptor
string file = request.Data();
// FIXME
string::size_type const i = file.find_last_of("/\\");
if (i != string::npos)
file = file.substr(i+1);
pl::GetNameFromURLRequest(file);
/// @todo By the way - this code os obsolete.
/// It doesn't supported properly in android now (because of Platform::RunOnGuiThread).
@ -444,8 +439,8 @@ namespace storage
void Storage::ReportProgress(TIndex const & idx, pair<int64_t, int64_t> const & p)
{
for (list<CountryObservers>::const_iterator it = m_observers.begin(); it != m_observers.end(); ++it)
it->m_progressFn(idx, p);
for (ObserversContT::const_iterator i = m_observers.begin(); i != m_observers.end(); ++i)
i->m_progressFn(idx, p);
}
void Storage::OnMapDownloadProgress(HttpRequest & request)

View file

@ -102,7 +102,8 @@ namespace storage
int m_slotId;
};
list<CountryObservers> m_observers;
typedef list<CountryObservers> ObserversContT;
ObserversContT m_observers;
//@}
/// @name Communicate with Framework