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-07-03 19:47:31 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:20:29 +0300
commitadde2107d1effebd18358b60bc190c7bd4e5d75b (patch)
treec32e80f0f03c999ed3738e3331ae45b00a037ee5
parent1f30f7f693ac1d66c3cfd66413f6bb78be256479 (diff)
Removed Platform::ReadPathForFile
-rw-r--r--iphone/Common/WebViewController.h5
-rw-r--r--iphone/Common/WebViewController.mm21
-rw-r--r--iphone/Maps/Settings/CountriesViewController.mm13
-rw-r--r--iphone/Sloynik/Shared/global.mm9
-rw-r--r--platform/platform.cpp14
-rw-r--r--platform/platform.hpp10
-rw-r--r--platform/platform_tests/platform_test.cpp21
-rw-r--r--qt/about.cpp16
-rw-r--r--qt/guide_page.cpp7
-rw-r--r--qt/main.cpp5
-rw-r--r--qt/mainwindow.cpp17
-rw-r--r--words/sloynik_engine.cpp22
-rw-r--r--words/sloynik_engine.hpp4
-rw-r--r--words/sloynik_index.cpp6
-rw-r--r--words/sloynik_index.hpp2
-rw-r--r--words/words_tests/words_tests.pro4
16 files changed, 106 insertions, 70 deletions
diff --git a/iphone/Common/WebViewController.h b/iphone/Common/WebViewController.h
index bdf988d015..5f88055f3e 100644
--- a/iphone/Common/WebViewController.h
+++ b/iphone/Common/WebViewController.h
@@ -3,10 +3,15 @@
@interface WebViewController : UIViewController
{
NSURL * m_url;
+ NSString * m_htmlText;
}
@property (nonatomic, retain) NSURL * m_url;
+@property (nonatomic, retain) NSString * m_htmlText;
- (id) initWithUrl: (NSURL *)url andTitleOrNil:(NSString *)title;
+- (id) initWithHtml: (NSString *)htmlText
+ baseUrl:(NSURL *)url
+ andTitleOrNil:(NSString *)title;
@end
diff --git a/iphone/Common/WebViewController.mm b/iphone/Common/WebViewController.mm
index 4f3d142303..6ef1dc514c 100644
--- a/iphone/Common/WebViewController.mm
+++ b/iphone/Common/WebViewController.mm
@@ -3,6 +3,7 @@
@implementation WebViewController
@synthesize m_url;
+@synthesize m_htmlText;
- (id) initWithUrl: (NSURL *)url andTitleOrNil:(NSString *)title
{
@@ -16,6 +17,21 @@
return self;
}
+- (id) initWithHtml: (NSString *)htmlText
+ baseUrl:(NSURL *)url
+ andTitleOrNil:(NSString *)title
+{
+ self = [super initWithNibName:nil bundle:nil];
+ if (self)
+ {
+ self.m_htmlText = htmlText;
+ self.m_url = url;
+ if (title)
+ self.navigationItem.title = title;
+ }
+ return self;
+}
+
- (void)dealloc
{
[super dealloc];
@@ -40,7 +56,10 @@
webView.autoresizesSubviews = YES;
webView.autoresizingMask= (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
- [webView loadRequest:[NSURLRequest requestWithURL:m_url]];
+ if (m_htmlText)
+ [webView loadHTMLString:m_htmlText baseURL:m_url];
+ else
+ [webView loadRequest:[NSURLRequest requestWithURL:m_url]];
self.view = webView;
[webView release];
diff --git a/iphone/Maps/Settings/CountriesViewController.mm b/iphone/Maps/Settings/CountriesViewController.mm
index efe49fb2b0..b15aac9264 100644
--- a/iphone/Maps/Settings/CountriesViewController.mm
+++ b/iphone/Maps/Settings/CountriesViewController.mm
@@ -60,13 +60,16 @@ static bool IsOurIndex(TIndex const & theirs, TIndex const & ours)
{
// display WebView with About text
- string const sFilePath =
- GetPlatform().ReadPathForFile("about-travelguide-iphone.html");
- NSString * filePath = [NSString stringWithUTF8String:sFilePath.c_str()];
- NSURL * url = [NSURL fileURLWithPath:filePath];
+ NSString * text;
+ {
+ ReaderPtr<Reader> r = GetPlatform().GetReader("about-travelguide-iphone.html");
+ string s;
+ r.ReadAsString(s);
+ text = [NSString stringWithUTF8String:s.c_str()];
+ }
WebViewController * aboutViewController =
- [[WebViewController alloc] initWithUrl:url andTitleOrNil:@"About"];
+ [[WebViewController alloc] initWithHtml:text baseUrl:nil andTitleOrNil:@"About"];
[self.navigationController pushViewController:aboutViewController animated:YES];
[aboutViewController release];
}
diff --git a/iphone/Sloynik/Shared/global.mm b/iphone/Sloynik/Shared/global.mm
index 7c1045ca38..f0a2d9bbbc 100644
--- a/iphone/Sloynik/Shared/global.mm
+++ b/iphone/Sloynik/Shared/global.mm
@@ -64,13 +64,6 @@ sl::SloynikEngine * CreateSloynikEngine()
{
ASSERT(!g_pEngine, ());
LOG(LINFO, ("Creating sloynik engine."));
- NSBundle * bundle = [NSBundle mainBundle];
- string const dictionaryPath = [[bundle pathForResource:@"dictionary" ofType:@"slf"] UTF8String];
- string const indexPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
- NSUserDomainMask,
- YES)
- objectAtIndex:0]
- UTF8String] + string("/index");
sl::StrFn strFn;
strFn.Create = StrCreateApple;
strFn.Destroy = StrDestroyApple;
@@ -84,7 +77,7 @@ sl::SloynikEngine * CreateSloynikEngine()
LOG(LINFO, ("Version:", [nsVersion UTF8String]));
strFn.m_PrimaryCompareId = [[NSString stringWithFormat:@"%@ 1", nsVersion] hash];
strFn.m_SecondaryCompareId = [[NSString stringWithFormat:@"%@ 2", nsVersion] hash];
- sl::SloynikEngine * pEngine = new sl::SloynikEngine(dictionaryPath, indexPath, strFn);
+ sl::SloynikEngine * pEngine = new sl::SloynikEngine("dictionary.slf", "index", strFn);
LOG(LINFO, ("Sloynik engine created."));
return pEngine;
}
diff --git a/platform/platform.cpp b/platform/platform.cpp
index d4410a7dba..d19a7415b1 100644
--- a/platform/platform.cpp
+++ b/platform/platform.cpp
@@ -15,13 +15,15 @@
#include "../base/start_mem_debug.hpp"
-string BasePlatformImpl::ReadPathForFile(string const & file) const
+string ReadPathForFile(string const & writableDir,
+ string const & resourcesDir,
+ string const & file)
{
- string fullPath = m_writableDir + file;
- if (!IsFileExists(fullPath))
+ string fullPath = writableDir + file;
+ if (!GetPlatform().IsFileExists(fullPath))
{
- fullPath = m_resourcesDir + file;
- if (!IsFileExists(fullPath))
+ fullPath = resourcesDir + file;
+ if (!GetPlatform().IsFileExists(fullPath))
MYTHROW(FileAbsentException, ("File doesn't exist", fullPath));
}
return fullPath;
@@ -29,7 +31,7 @@ string BasePlatformImpl::ReadPathForFile(string const & file) const
ModelReader * BasePlatformImpl::GetReader(string const & file) const
{
- return new FileReader(ReadPathForFile(file), 10, 12);
+ return new FileReader(ReadPathForFile(m_writableDir, m_resourcesDir, file), 10, 12);
}
bool BasePlatformImpl::GetFileSize(string const & file, uint64_t & size) const
diff --git a/platform/platform.hpp b/platform/platform.hpp
index 0154335d99..f856ea45de 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -29,15 +29,10 @@ public:
/// @return resource dir (on some platforms it's differ from Writable dir)
virtual string ResourcesDir() const = 0;
- /// @name Get the reader path or reader itself for file decriptor.
- /// Throws FileAbsentException
+ /// @return reader for file decriptor.
+ /// @throws FileAbsentException
/// @param[in] file descriptor which we want to read
- //@{
- /// @return fully resolved path including file name
- virtual string ReadPathForFile(string const & file) const = 0;
-
virtual ModelReader * GetReader(string const & file) const = 0;
- //@}
/// @name File operations
//@{
@@ -90,7 +85,6 @@ protected:
public:
virtual string WritableDir() const { return m_writableDir; }
virtual string ResourcesDir() const { return m_resourcesDir; }
- virtual string ReadPathForFile(string const & file) const;
virtual ModelReader * GetReader(string const & file) const;
virtual void GetFilesInDir(string const & directory, string const & mask, FilesList & res) const;
diff --git a/platform/platform_tests/platform_test.cpp b/platform/platform_tests/platform_test.cpp
index daa18061ea..582103cdb8 100644
--- a/platform/platform_tests/platform_test.cpp
+++ b/platform/platform_tests/platform_test.cpp
@@ -38,20 +38,21 @@ UNIT_TEST(WritablePathForFile)
TEST_EQUAL(p1, p2, ());
}
-UNIT_TEST(ReadPathForFile)
+UNIT_TEST(GetReader)
{
char const * NON_EXISTING_FILE = "mgbwuerhsnmbui45efhdbn34.tmp";
char const * arr[] = { "drawing_rules.bin", "basic.skn", "classificator.txt", "minsk-pass.mwm" };
Platform & p = GetPlatform();
for (size_t i = 0; i < ARRAY_SIZE(arr); ++i)
{
- TEST_GREATER(p.ReadPathForFile(arr[i]).size(), 0, ("File should exist!"));
+ ReaderPtr<Reader> r = p.GetReader(arr[i]);
+ TEST_GREATER(r.Size(), 0, ("File should exist!"));
}
bool wasException = false;
try
{
- p.ReadPathForFile(NON_EXISTING_FILE);
+ ReaderPtr<Reader> r = p.GetReader(NON_EXISTING_FILE);
}
catch (FileAbsentException const &)
{
@@ -72,13 +73,13 @@ UNIT_TEST(GetFilesInDir)
TEST_EQUAL(files.size(), 0, ());
}
-UNIT_TEST(GetFileSize)
-{
- Platform & pl = GetPlatform();
- uint64_t size = 0;
- pl.GetFileSize(pl.ReadPathForFile("classificator.txt").c_str(), size);
- TEST_GREATER(size, 0, ("File classificator.txt should exist for test"));
-}
+//UNIT_TEST(GetFileSize)
+//{
+// Platform & pl = GetPlatform();
+// uint64_t size = 0;
+// pl.GetFileSize(pl.ReadPathForFile("classificator.txt").c_str(), size);
+// TEST_GREATER(size, 0, ("File classificator.txt should exist for test"));
+//}
UNIT_TEST(CpuCores)
{
diff --git a/qt/about.cpp b/qt/about.cpp
index d3eebb93e7..3a650857fc 100644
--- a/qt/about.cpp
+++ b/qt/about.cpp
@@ -33,18 +33,22 @@ AboutDialog::AboutDialog(QWidget * parent)
hBox->addWidget(labelIcon);
hBox->addWidget(labelVersion);
- char const sAboutFileName [] = "about-travelguide-desktop.html";
- QFile file(GetPlatform().ReadPathForFile(sAboutFileName).c_str());
- if (file.open(QIODevice::ReadOnly))
+ string aboutText;
+ try
{
- QByteArray aboutData = file.readAll();
- file.close();
+ ReaderPtr<Reader> reader = GetPlatform().GetReader("about-travelguide-desktop.html");
+ reader.ReadAsString(aboutText);
+ }
+ catch (...)
+ {}
+ if (!aboutText.empty())
+ {
QTextBrowser * aboutTextBrowser = new QTextBrowser();
aboutTextBrowser->setReadOnly(true);
aboutTextBrowser->setOpenLinks(true);
aboutTextBrowser->setOpenExternalLinks(true);
- aboutTextBrowser->setText(aboutData.constData());
+ aboutTextBrowser->setText(aboutText.c_str());
QVBoxLayout * vBox = new QVBoxLayout();
vBox->addLayout(hBox);
diff --git a/qt/guide_page.cpp b/qt/guide_page.cpp
index 3a536d392b..f1cefde664 100644
--- a/qt/guide_page.cpp
+++ b/qt/guide_page.cpp
@@ -2,8 +2,6 @@
#include "../words/sloynik_engine.hpp"
-#include "../platform/platform.hpp"
-
#include <QtWebKit/QWebView>
#include <QtGui/QLineEdit>
@@ -73,9 +71,6 @@ namespace
void GuidePageHolder::CreateEngine()
{
- string const dicPath = GetPlatform().ReadPathForFile("dictionary.slf");
- string const indPath = GetPlatform().WritableDir() + "index";
-
sl::StrFn fn;
fn.Create = &StrCreate;
fn.Destroy = &StrDestroy;
@@ -86,7 +81,7 @@ void GuidePageHolder::CreateEngine()
fn.m_PrimaryCompareId = 1;
fn.m_SecondaryCompareId = 2;
- m_pEngine.reset(new sl::SloynikEngine(dicPath, indPath, fn));
+ m_pEngine.reset(new sl::SloynikEngine("dictionary.slf", "index", fn));
}
void GuidePageHolder::OnShowPage()
diff --git a/qt/main.cpp b/qt/main.cpp
index ea687e25c0..cac41f46be 100644
--- a/qt/main.cpp
+++ b/qt/main.cpp
@@ -93,7 +93,10 @@ int main(int argc, char *argv[])
buttons << "Accept" << "Decline";
string buffer;
- FileReader(GetPlatform().ReadPathForFile("eula.html")).ReadAsString(buffer);
+ {
+ ReaderPtr<Reader> reader = GetPlatform().GetReader("eula.html");
+ reader.ReadAsString(buffer);
+ }
qt::InfoDialog eulaDialog("MapsWithMe End User Licensing Agreement", buffer.c_str(), NULL, buttons);
eulaAccepted = (eulaDialog.exec() == 1);
Settings::Set(SETTING_EULA_ACCEPTED, eulaAccepted);
diff --git a/qt/mainwindow.cpp b/qt/mainwindow.cpp
index 72d240874f..e46355bf40 100644
--- a/qt/mainwindow.cpp
+++ b/qt/mainwindow.cpp
@@ -94,16 +94,21 @@ MainWindow::MainWindow()
if (bShow)
{
- QFile welcomeTextFile(GetPlatform().ReadPathForFile("welcome.html").c_str());
-
bool bShowUpdateDialog = true;
- if (welcomeTextFile.open(QIODevice::ReadOnly))
+ string text;
+ try
{
- QByteArray text = welcomeTextFile.readAll();
- welcomeTextFile.close();
+ ReaderPtr<Reader> reader = GetPlatform().GetReader("welcome.html");
+ reader.ReadAsString(text);
+ }
+ catch (...)
+ {}
- InfoDialog welcomeDlg(tr("Welcome to MapsWithMe!"), text, this, QStringList(tr("Download Maps")));
+ if (!text.empty())
+ {
+ InfoDialog welcomeDlg(tr("Welcome to MapsWithMe!"), text.c_str(),
+ this, QStringList(tr("Download Maps")));
if (welcomeDlg.exec() == QDialog::Rejected)
bShowUpdateDialog = false;
}
diff --git a/words/sloynik_engine.cpp b/words/sloynik_engine.cpp
index 3c2c74fac3..379a65ba7f 100644
--- a/words/sloynik_engine.cpp
+++ b/words/sloynik_engine.cpp
@@ -1,16 +1,21 @@
#include "sloynik_engine.hpp"
#include "slof_dictionary.hpp"
#include "sloynik_index.hpp"
+
+#include "../platform/platform.hpp"
+
#include "../coding/file_reader.hpp"
#include "../coding/file_writer.hpp"
+
#include "../base/logging.hpp"
#include "../base/macros.hpp"
-sl::SloynikEngine::SloynikEngine(string const & dictionaryPath,
- string const & indexPath,
+sl::SloynikEngine::SloynikEngine(string const & dictionary,
+ string const & index,
StrFn const & strFn)
{
- FileReader * pDicFileReader = new FileReader(dictionaryPath);
+ Platform & pl = GetPlatform();
+ Reader * pDicFileReader = pl.GetReader(dictionary);
// m_pDictionary takes ownership of pDicFileReader.
m_pDictionary.reset(new sl::SlofDictionary(pDicFileReader));
@@ -20,11 +25,11 @@ sl::SloynikEngine::SloynikEngine(string const & dictionaryPath,
stamp.push_back(m_pDictionary->KeyCount());
stamp.push_back(pDicFileReader->Size());
- string const stampPath = indexPath + ".stamp";
+ string const stampFile = index + ".stamp";
bool needIndexBuild = false;
try
{
- FileReader stampReader(stampPath);
+ ReaderPtr<Reader> stampReader(pl.GetReader(stampFile));
if (stampReader.Size() != stamp.size() * sizeof(stamp[0]))
needIndexBuild = true;
else
@@ -45,8 +50,9 @@ sl::SloynikEngine::SloynikEngine(string const & dictionaryPath,
// Uncomment to always rebuild the index: needIndexBuild = true;
if (needIndexBuild)
{
+ string const stampPath = pl.WritablePathForFile(stampFile);
FileWriter::DeleteFileX(stampPath);
- sl::SortedIndex::Build(*m_pDictionary, strFn, indexPath);
+ sl::SortedIndex::Build(*m_pDictionary, strFn, index);
FileWriter stampWriter(stampPath);
stampWriter.Write(&stamp[0], stamp.size() * sizeof(stamp[0]));
@@ -54,7 +60,9 @@ sl::SloynikEngine::SloynikEngine(string const & dictionaryPath,
// By VNG: SortedIndex takes ownership of index reader, so no need to store it here.
//m_pIndexReader.reset(new FileReader(indexPath + ".idx"));
- m_pSortedIndex.reset(new sl::SortedIndex(*m_pDictionary, new FileReader(indexPath + ".idx"), strFn));
+ m_pSortedIndex.reset(new sl::SortedIndex(*m_pDictionary,
+ new FileReader(pl.WritablePathForFile(index + ".idx")),
+ strFn));
}
sl::SloynikEngine::~SloynikEngine()
diff --git a/words/sloynik_engine.hpp b/words/sloynik_engine.hpp
index 1c1bc6d288..c235890f8b 100644
--- a/words/sloynik_engine.hpp
+++ b/words/sloynik_engine.hpp
@@ -17,8 +17,8 @@ class SortedIndex;
class SloynikEngine
{
public:
- SloynikEngine(string const & dictionaryPath,
- string const & indexPath,
+ SloynikEngine(string const & dictionary,
+ string const & index,
sl::StrFn const & strFn);
~SloynikEngine();
diff --git a/words/sloynik_index.cpp b/words/sloynik_index.cpp
index 332b65ae76..7fb9831e61 100644
--- a/words/sloynik_index.cpp
+++ b/words/sloynik_index.cpp
@@ -1,6 +1,8 @@
#include "sloynik_index.hpp"
#include "dictionary.hpp"
+#include "../platform/platform.hpp"
+
#include "../coding/file_writer.hpp"
#include "../coding/timsort/timsort.hpp"
@@ -189,7 +191,7 @@ sl::SortedIndex::Pos sl::SortedIndex::PrefixSearch(string const & prefix)
void sl::SortedIndex::Build(sl::Dictionary const & dictionary,
StrFn const & strFn,
- string const & indexPathPrefix)
+ string const & indexPrefix)
{
LOG(LINFO, ("Building sorted index."));
@@ -214,7 +216,7 @@ void sl::SortedIndex::Build(sl::Dictionary const & dictionary,
// stable_sort(ids.begin(), ids.end(), MakeLessRefProxy(compareLess));
}
- FileWriter idxWriter((indexPathPrefix + ".idx").c_str());
+ FileWriter idxWriter(GetPlatform().WritablePathForFile(indexPrefix + ".idx").c_str());
idxWriter.Write(&ids[0], ids.size() * sizeof(ids[0]));
LOG(LINFO, ("Building sorted index done."));
diff --git a/words/sloynik_index.hpp b/words/sloynik_index.hpp
index c6696a79a8..c549653f08 100644
--- a/words/sloynik_index.hpp
+++ b/words/sloynik_index.hpp
@@ -44,7 +44,7 @@ public:
// Build index.
static void Build(Dictionary const & dictionary,
StrFn const & strFn,
- string const & indexPathPrefix);
+ string const & indexPrefix);
private:
#pragma pack(push, 1)
diff --git a/words/words_tests/words_tests.pro b/words/words_tests/words_tests.pro
index 3056ec2749..98bf9fb670 100644
--- a/words/words_tests/words_tests.pro
+++ b/words/words_tests/words_tests.pro
@@ -4,10 +4,12 @@ CONFIG += console
CONFIG -= app_bundle
ROOT_DIR = ../..
-DEPENDENCIES = words coding base zlib bzip2
+DEPENDENCIES = platform words coding base zlib bzip2
include($$ROOT_DIR/common.pri)
+QT += core
+
SOURCES += $$ROOT_DIR/testing/testingmain.cpp \
sorted_index_test.cpp \