mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
synchronization with native branch
This commit is contained in:
parent
072a506dc0
commit
3580e2cd59
20 changed files with 1436 additions and 0 deletions
|
@ -38,6 +38,8 @@ LOCAL_SRC_FILES := \
|
||||||
NativeFormats/JavaNativeFormatPlugin.cpp \
|
NativeFormats/JavaNativeFormatPlugin.cpp \
|
||||||
NativeFormats/JavaPluginCollection.cpp \
|
NativeFormats/JavaPluginCollection.cpp \
|
||||||
NativeFormats/util/AndroidUtil.cpp \
|
NativeFormats/util/AndroidUtil.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/encoding/ZLEncodingCollection.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/encoding/ZLEncodingConverter.cpp \
|
||||||
NativeFormats/zlibrary/core/src/filesystem/ZLDir.cpp \
|
NativeFormats/zlibrary/core/src/filesystem/ZLDir.cpp \
|
||||||
NativeFormats/zlibrary/core/src/filesystem/ZLFSManager.cpp \
|
NativeFormats/zlibrary/core/src/filesystem/ZLFSManager.cpp \
|
||||||
NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp \
|
NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp \
|
||||||
|
@ -53,7 +55,12 @@ LOCAL_SRC_FILES := \
|
||||||
NativeFormats/zlibrary/core/src/logger/ZLLogger.cpp \
|
NativeFormats/zlibrary/core/src/logger/ZLLogger.cpp \
|
||||||
NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp \
|
NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp \
|
||||||
NativeFormats/zlibrary/core/src/util/ZLUnicodeUtil.cpp \
|
NativeFormats/zlibrary/core/src/util/ZLUnicodeUtil.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/xml/ZLAsynchronousInputStream.cpp \
|
||||||
NativeFormats/zlibrary/core/src/xml/ZLXMLReader.cpp \
|
NativeFormats/zlibrary/core/src/xml/ZLXMLReader.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.cpp \
|
||||||
|
NativeFormats/zlibrary/core/src/unix/library/ZLUnixLibrary.cpp \
|
||||||
|
NativeFormats/zlibrary/ui/src/android/filesystem/ZLAndroidFSManager.cpp \
|
||||||
|
NativeFormats/zlibrary/ui/src/android/library/ZLAndroidLibraryImplementation.cpp \
|
||||||
NativeFormats/fbreader/src/formats/FormatPlugin.cpp \
|
NativeFormats/fbreader/src/formats/FormatPlugin.cpp \
|
||||||
NativeFormats/fbreader/src/formats/PluginCollection.cpp \
|
NativeFormats/fbreader/src/formats/PluginCollection.cpp \
|
||||||
NativeFormats/fbreader/src/library/Author.cpp \
|
NativeFormats/fbreader/src/library/Author.cpp \
|
||||||
|
@ -63,6 +70,7 @@ LOCAL_SRC_FILES := \
|
||||||
|
|
||||||
LOCAL_C_INCLUDES := \
|
LOCAL_C_INCLUDES := \
|
||||||
$(LOCAL_PATH)/NativeFormats/util \
|
$(LOCAL_PATH)/NativeFormats/util \
|
||||||
|
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/encoding \
|
||||||
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/filesystem \
|
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/filesystem \
|
||||||
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/image \
|
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/image \
|
||||||
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/language \
|
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/language \
|
||||||
|
|
|
@ -21,12 +21,20 @@
|
||||||
|
|
||||||
JavaVM *AndroidUtil::ourJavaVM = 0;
|
JavaVM *AndroidUtil::ourJavaVM = 0;
|
||||||
|
|
||||||
|
const char * const AndroidUtil::Class_java_util_Locale = "java/util/Locale";
|
||||||
|
const char * const AndroidUtil::Class_ZLibrary = "org/geometerplus/zlibrary/core/library/ZLibrary";
|
||||||
const char * const AndroidUtil::Class_NativeFormatPlugin = "org/geometerplus/fbreader/formats/NativeFormatPlugin";
|
const char * const AndroidUtil::Class_NativeFormatPlugin = "org/geometerplus/fbreader/formats/NativeFormatPlugin";
|
||||||
const char * const AndroidUtil::Class_PluginCollection = "org/geometerplus/fbreader/formats/PluginCollection";
|
const char * const AndroidUtil::Class_PluginCollection = "org/geometerplus/fbreader/formats/PluginCollection";
|
||||||
const char * const AndroidUtil::Class_ZLFile = "org/geometerplus/zlibrary/core/filesystem/ZLFile";
|
const char * const AndroidUtil::Class_ZLFile = "org/geometerplus/zlibrary/core/filesystem/ZLFile";
|
||||||
const char * const AndroidUtil::Class_Book = "org/geometerplus/fbreader/library/Book";
|
const char * const AndroidUtil::Class_Book = "org/geometerplus/fbreader/library/Book";
|
||||||
const char * const AndroidUtil::Class_Tag = "org/geometerplus/fbreader/library/Tag";
|
const char * const AndroidUtil::Class_Tag = "org/geometerplus/fbreader/library/Tag";
|
||||||
|
|
||||||
|
jmethodID AndroidUtil::SMID_java_util_Locale_getDefault;
|
||||||
|
jmethodID AndroidUtil::MID_java_util_Locale_getLanguage;
|
||||||
|
|
||||||
|
jmethodID AndroidUtil::SMID_ZLibrary_Instance;
|
||||||
|
jmethodID AndroidUtil::MID_ZLibrary_getVersionName;
|
||||||
|
|
||||||
jmethodID AndroidUtil::SMID_PluginCollection_Instance;
|
jmethodID AndroidUtil::SMID_PluginCollection_Instance;
|
||||||
|
|
||||||
jmethodID AndroidUtil::MID_ZLFile_getPath;
|
jmethodID AndroidUtil::MID_ZLFile_getPath;
|
||||||
|
@ -52,6 +60,16 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
||||||
JNIEnv *env = getEnv();
|
JNIEnv *env = getEnv();
|
||||||
jclass cls;
|
jclass cls;
|
||||||
|
|
||||||
|
CHECK_NULL( cls = env->FindClass(Class_java_util_Locale) );
|
||||||
|
CHECK_NULL( SMID_java_util_Locale_getDefault = env->GetStaticMethodID(cls, "getDefault", "()Ljava/util/Locale;") );
|
||||||
|
CHECK_NULL( MID_java_util_Locale_getLanguage = env->GetMethodID(cls, "getLanguage", "()Ljava/lang/String;") );
|
||||||
|
env->DeleteLocalRef(cls);
|
||||||
|
|
||||||
|
CHECK_NULL( cls = env->FindClass(Class_ZLibrary) );
|
||||||
|
CHECK_NULL( SMID_ZLibrary_Instance = env->GetStaticMethodID(cls, "Instance", "()Lorg/geometerplus/zlibrary/core/library/ZLibrary;") );
|
||||||
|
CHECK_NULL( MID_ZLibrary_getVersionName = env->GetMethodID(cls, "getVersionName", "()Ljava/lang/String;") );
|
||||||
|
env->DeleteLocalRef(cls);
|
||||||
|
|
||||||
CHECK_NULL( cls = env->FindClass(Class_ZLFile) );
|
CHECK_NULL( cls = env->FindClass(Class_ZLFile) );
|
||||||
CHECK_NULL( MID_ZLFile_getPath = env->GetMethodID(cls, "getPath", "()Ljava/lang/String;") );
|
CHECK_NULL( MID_ZLFile_getPath = env->GetMethodID(cls, "getPath", "()Ljava/lang/String;") );
|
||||||
env->DeleteLocalRef(cls);
|
env->DeleteLocalRef(cls);
|
||||||
|
|
|
@ -30,12 +30,20 @@ private:
|
||||||
static JavaVM *ourJavaVM;
|
static JavaVM *ourJavaVM;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static const char * const Class_java_util_Locale;
|
||||||
|
static const char * const Class_ZLibrary;
|
||||||
static const char * const Class_ZLFile;
|
static const char * const Class_ZLFile;
|
||||||
static const char * const Class_NativeFormatPlugin;
|
static const char * const Class_NativeFormatPlugin;
|
||||||
static const char * const Class_PluginCollection;
|
static const char * const Class_PluginCollection;
|
||||||
static const char * const Class_Book;
|
static const char * const Class_Book;
|
||||||
static const char * const Class_Tag;
|
static const char * const Class_Tag;
|
||||||
|
|
||||||
|
static jmethodID SMID_java_util_Locale_getDefault;
|
||||||
|
static jmethodID MID_java_util_Locale_getLanguage;
|
||||||
|
|
||||||
|
static jmethodID SMID_ZLibrary_Instance;
|
||||||
|
static jmethodID MID_ZLibrary_getVersionName;
|
||||||
|
|
||||||
static jmethodID MID_ZLFile_getPath;
|
static jmethodID MID_ZLFile_getPath;
|
||||||
|
|
||||||
static jmethodID SMID_PluginCollection_Instance;
|
static jmethodID SMID_PluginCollection_Instance;
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DUMMYENCODINGCONVERTER_H__
|
||||||
|
#define __DUMMYENCODINGCONVERTER_H__
|
||||||
|
|
||||||
|
#include "ZLEncodingConverter.h"
|
||||||
|
#include "ZLEncodingConverterProvider.h"
|
||||||
|
|
||||||
|
class DummyEncodingConverterProvider : public ZLEncodingConverterProvider {
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool providesConverter(const std::string &encoding);
|
||||||
|
shared_ptr<ZLEncodingConverter> createConverter();
|
||||||
|
shared_ptr<ZLEncodingConverter> createConverter(const std::string &encoding);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __DUMMYENCODINGCONVERTER_H__ */
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ZLENCODINGCOLLECTIONREADER_H__
|
||||||
|
#define __ZLENCODINGCOLLECTIONREADER_H__
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <ZLXMLReader.h>
|
||||||
|
|
||||||
|
#include "ZLEncodingConverter.h"
|
||||||
|
|
||||||
|
class ZLEncodingCollectionReader : public ZLXMLReader {
|
||||||
|
|
||||||
|
public:
|
||||||
|
ZLEncodingCollectionReader(ZLEncodingCollection &collection);
|
||||||
|
void startElementHandler(const char *tag, const char **attributes);
|
||||||
|
void endElementHandler(const char *tag);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZLEncodingCollection &myCollection;
|
||||||
|
shared_ptr<ZLEncodingSet> myCurrentSet;
|
||||||
|
ZLEncodingConverterInfoPtr myCurrentInfo;
|
||||||
|
std::vector<std::string> myNames;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __ENCODINGCOLLECTIONREADER_H__ */
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ZLFile.h>
|
||||||
|
#include <ZLibrary.h>
|
||||||
|
#include <ZLStringUtil.h>
|
||||||
|
#include <ZLUnicodeUtil.h>
|
||||||
|
#include <ZLXMLReader.h>
|
||||||
|
|
||||||
|
#include "ZLEncodingConverter.h"
|
||||||
|
#include "DummyEncodingConverter.h"
|
||||||
|
//#include "MyEncodingConverter.h"
|
||||||
|
#include "EncodingCollectionReader.h"
|
||||||
|
|
||||||
|
ZLEncodingCollection *ZLEncodingCollection::ourInstance = 0;
|
||||||
|
|
||||||
|
ZLEncodingCollection &ZLEncodingCollection::Instance() {
|
||||||
|
if (ourInstance == 0) {
|
||||||
|
ourInstance = new ZLEncodingCollection();
|
||||||
|
}
|
||||||
|
return *ourInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ZLEncodingCollection::encodingDescriptionPath() {
|
||||||
|
return ZLibrary::ZLibraryDirectory() + ZLibrary::FileNameDelimiter + "encodings";
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLEncodingCollection::ZLEncodingCollection() {
|
||||||
|
registerProvider(new DummyEncodingConverterProvider());
|
||||||
|
//registerProvider(new MyEncodingConverterProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLEncodingCollection::registerProvider(shared_ptr<ZLEncodingConverterProvider> provider) {
|
||||||
|
myProviders.push_back(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLEncodingCollection::init() {
|
||||||
|
if (mySets.empty()) {
|
||||||
|
ZLEncodingCollectionReader(*this).readDocument(ZLFile(
|
||||||
|
encodingDescriptionPath() + ZLibrary::FileNameDelimiter + "Encodings.xml"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLEncodingCollection::~ZLEncodingCollection() {
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<shared_ptr<ZLEncodingConverterProvider> > &ZLEncodingCollection::providers() const {
|
||||||
|
return myProviders;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<shared_ptr<ZLEncodingSet> > &ZLEncodingCollection::sets() {
|
||||||
|
init();
|
||||||
|
return mySets;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLEncodingConverterInfoPtr ZLEncodingCollection::info(const std::string &name) {
|
||||||
|
init();
|
||||||
|
std::string lowerCaseName = ZLUnicodeUtil::toLower(name);
|
||||||
|
if (lowerCaseName == "iso-8859-1") {
|
||||||
|
lowerCaseName = "windows-1252";
|
||||||
|
}
|
||||||
|
return myInfosByName[lowerCaseName];
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<ZLEncodingConverter> ZLEncodingCollection::defaultConverter() {
|
||||||
|
return DummyEncodingConverterProvider().createConverter();
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLEncodingConverterInfoPtr ZLEncodingCollection::info(int code) {
|
||||||
|
std::string name;
|
||||||
|
ZLStringUtil::appendNumber(name, code);
|
||||||
|
return info(name);
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ZLEncodingConverter.h"
|
||||||
|
#include "ZLEncodingConverterProvider.h"
|
||||||
|
|
||||||
|
ZLEncodingConverterProvider::ZLEncodingConverterProvider() {
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLEncodingConverterProvider::~ZLEncodingConverterProvider() {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZLEncodingConverterInfo::canCreateConverter() const {
|
||||||
|
ZLEncodingCollection &collection = ZLEncodingCollection::Instance();
|
||||||
|
const std::vector<shared_ptr<ZLEncodingConverterProvider> > &providers = collection.providers();
|
||||||
|
for (std::vector<shared_ptr<ZLEncodingConverterProvider> >::const_iterator it = providers.begin(); it != providers.end(); ++it) {
|
||||||
|
for (std::vector<std::string>::const_iterator jt = myAliases.begin(); jt != myAliases.end(); ++jt) {
|
||||||
|
if ((*it)->providesConverter(*jt)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<ZLEncodingConverter> ZLEncodingConverterInfo::createConverter() const {
|
||||||
|
ZLEncodingCollection &collection = ZLEncodingCollection::Instance();
|
||||||
|
const std::vector<shared_ptr<ZLEncodingConverterProvider> > &providers = collection.providers();
|
||||||
|
for (std::vector<shared_ptr<ZLEncodingConverterProvider> >::const_iterator it = providers.begin(); it != providers.end(); ++it) {
|
||||||
|
for (std::vector<std::string>::const_iterator jt = myAliases.begin(); jt != myAliases.end(); ++jt) {
|
||||||
|
if ((*it)->providesConverter(*jt)) {
|
||||||
|
return (*it)->createConverter(*jt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ZLEncodingCollection::Instance().defaultConverter();
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLEncodingConverter::ZLEncodingConverter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLEncodingConverter::~ZLEncodingConverter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLEncodingConverter::convert(std::string &dst, const std::string &src) {
|
||||||
|
convert(dst, src.data(), src.data() + src.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLEncodingConverterInfo::ZLEncodingConverterInfo(const std::string &name, const std::string ®ion) : myName(name), myVisibleName(region + " (" + name + ")") {
|
||||||
|
addAlias(myName);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &ZLEncodingConverterInfo::name() const {
|
||||||
|
return myName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &ZLEncodingConverterInfo::visibleName() const {
|
||||||
|
return myVisibleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLEncodingConverterInfo::addAlias(const std::string &alias) {
|
||||||
|
myAliases.push_back(alias);
|
||||||
|
}
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ZLENCODINGCONVERTER_H__
|
||||||
|
#define __ZLENCODINGCONVERTER_H__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <shared_ptr.h>
|
||||||
|
|
||||||
|
class ZLEncodingConverter {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ZLEncodingConverter();
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~ZLEncodingConverter();
|
||||||
|
virtual void convert(std::string &dst, const char *srcStart, const char *srcEnd) = 0;
|
||||||
|
void convert(std::string &dst, const std::string &src);
|
||||||
|
virtual void reset() = 0;
|
||||||
|
virtual bool fillTable(int *map) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZLEncodingConverter(const ZLEncodingConverter&);
|
||||||
|
ZLEncodingConverter &operator = (const ZLEncodingConverter&);
|
||||||
|
};
|
||||||
|
|
||||||
|
class ZLEncodingConverterInfo {
|
||||||
|
|
||||||
|
public:
|
||||||
|
ZLEncodingConverterInfo(const std::string &name, const std::string ®ion);
|
||||||
|
void addAlias(const std::string &alias);
|
||||||
|
|
||||||
|
const std::string &name() const;
|
||||||
|
const std::string &visibleName() const;
|
||||||
|
shared_ptr<ZLEncodingConverter> createConverter() const;
|
||||||
|
bool canCreateConverter() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const std::string myName;
|
||||||
|
const std::string myVisibleName;
|
||||||
|
std::vector<std::string> myAliases;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZLEncodingConverterInfo(const ZLEncodingConverterInfo&);
|
||||||
|
ZLEncodingConverterInfo &operator = (const ZLEncodingConverterInfo&);
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef shared_ptr<ZLEncodingConverterInfo> ZLEncodingConverterInfoPtr;
|
||||||
|
|
||||||
|
class ZLEncodingSet {
|
||||||
|
|
||||||
|
public:
|
||||||
|
ZLEncodingSet(const std::string &name);
|
||||||
|
void addInfo(ZLEncodingConverterInfoPtr info);
|
||||||
|
|
||||||
|
const std::string &name() const;
|
||||||
|
const std::vector<ZLEncodingConverterInfoPtr> &infos() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const std::string myName;
|
||||||
|
std::vector<ZLEncodingConverterInfoPtr> myInfos;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZLEncodingSet(const ZLEncodingSet&);
|
||||||
|
ZLEncodingSet &operator = (const ZLEncodingSet&);
|
||||||
|
};
|
||||||
|
|
||||||
|
class ZLEncodingConverterProvider;
|
||||||
|
|
||||||
|
class ZLEncodingCollection {
|
||||||
|
|
||||||
|
public:
|
||||||
|
static ZLEncodingCollection &Instance();
|
||||||
|
static std::string encodingDescriptionPath();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static ZLEncodingCollection *ourInstance;
|
||||||
|
|
||||||
|
public:
|
||||||
|
const std::vector<shared_ptr<ZLEncodingSet> > &sets();
|
||||||
|
ZLEncodingConverterInfoPtr info(const std::string &name);
|
||||||
|
ZLEncodingConverterInfoPtr info(int code);
|
||||||
|
shared_ptr<ZLEncodingConverter> defaultConverter();
|
||||||
|
void registerProvider(shared_ptr<ZLEncodingConverterProvider> provider);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void addInfo(ZLEncodingConverterInfoPtr info);
|
||||||
|
const std::vector<shared_ptr<ZLEncodingConverterProvider> > &providers() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<shared_ptr<ZLEncodingSet> > mySets;
|
||||||
|
std::map<std::string,ZLEncodingConverterInfoPtr> myInfosByName;
|
||||||
|
std::vector<shared_ptr<ZLEncodingConverterProvider> > myProviders;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZLEncodingCollection();
|
||||||
|
~ZLEncodingCollection();
|
||||||
|
void init();
|
||||||
|
|
||||||
|
friend class ZLEncodingConverterInfo;
|
||||||
|
friend class ZLEncodingCollectionReader;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __ZLENCODINGCONVERTER_H__ */
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ZLENCODINGCONVERTERPROVIDER_H__
|
||||||
|
#define __ZLENCODINGCONVERTERPROVIDER_H__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <shared_ptr.h>
|
||||||
|
|
||||||
|
class ZLEncodingConverter;
|
||||||
|
|
||||||
|
class ZLEncodingConverterProvider {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ZLEncodingConverterProvider();
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~ZLEncodingConverterProvider();
|
||||||
|
virtual bool providesConverter(const std::string &encoding) = 0;
|
||||||
|
virtual shared_ptr<ZLEncodingConverter> createConverter(const std::string &encoding) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZLEncodingConverterProvider(const ZLEncodingConverterProvider&);
|
||||||
|
const ZLEncodingConverterProvider &operator = (const ZLEncodingConverterProvider&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __ZLENCODINGCONVERTERPROVIDER_H__ */
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ZLEncodingConverter.h"
|
||||||
|
|
||||||
|
ZLEncodingSet::ZLEncodingSet(const std::string &name) : myName(name) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLEncodingSet::addInfo(ZLEncodingConverterInfoPtr info) {
|
||||||
|
myInfos.push_back(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &ZLEncodingSet::name() const {
|
||||||
|
return myName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<ZLEncodingConverterInfoPtr> &ZLEncodingSet::infos() const {
|
||||||
|
return myInfos;
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ZLUNIXFSMANAGER_H__
|
||||||
|
#define __ZLUNIXFSMANAGER_H__
|
||||||
|
|
||||||
|
#include "../../filesystem/ZLFSManager.h"
|
||||||
|
|
||||||
|
class ZLUnixFSManager : public ZLFSManager {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void normalizeRealPath(std::string &path) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string resolveSymlink(const std::string &path) const;
|
||||||
|
ZLFSDir *createNewDirectory(const std::string &path) const;
|
||||||
|
ZLFSDir *createPlainDirectory(const std::string &path) const;
|
||||||
|
ZLInputStream *createPlainInputStream(const std::string &path) const;
|
||||||
|
ZLOutputStream *createOutputStream(const std::string &path) const;
|
||||||
|
bool removeFile(const std::string &path) const;
|
||||||
|
|
||||||
|
ZLFileInfo fileInfo(const std::string &path) const;
|
||||||
|
|
||||||
|
int findArchiveFileNameDelimiter(const std::string &path) const;
|
||||||
|
shared_ptr<ZLDir> rootDirectory() const;
|
||||||
|
const std::string &rootDirectoryPath() const;
|
||||||
|
std::string parentPath(const std::string &path) const;
|
||||||
|
|
||||||
|
bool canRemoveFile(const std::string &path) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __ZLUNIXFSMANAGER_H__ */
|
|
@ -0,0 +1,152 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//#include <locale.h>
|
||||||
|
//#include <dlfcn.h>
|
||||||
|
//#include <dirent.h>
|
||||||
|
//#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <ZLibrary.h>
|
||||||
|
#include <ZLStringUtil.h>
|
||||||
|
#include <ZLLogger.h>
|
||||||
|
|
||||||
|
#include "ZLibraryImplementation.h"
|
||||||
|
|
||||||
|
const std::string ZLibrary::FileNameDelimiter("/");
|
||||||
|
const std::string ZLibrary::PathDelimiter(":");
|
||||||
|
const std::string ZLibrary::EndOfLine("\n");
|
||||||
|
|
||||||
|
/*void ZLibrary::initLocale() {
|
||||||
|
const char *locale = setlocale(LC_MESSAGES, "");
|
||||||
|
if (locale != 0) {
|
||||||
|
std::string sLocale = locale;
|
||||||
|
const int dotIndex = sLocale.find('.');
|
||||||
|
if (dotIndex != -1) {
|
||||||
|
sLocale = sLocale.substr(0, dotIndex);
|
||||||
|
}
|
||||||
|
const int dashIndex = std::min(sLocale.find('_'), sLocale.find('-'));
|
||||||
|
if (dashIndex == -1) {
|
||||||
|
ourLanguage = sLocale;
|
||||||
|
} else {
|
||||||
|
ourLanguage = sLocale.substr(0, dashIndex);
|
||||||
|
ourCountry = sLocale.substr(dashIndex + 1);
|
||||||
|
if ((ourLanguage == "es") && (ourCountry != "ES")) {
|
||||||
|
ourCountry = "LA";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
ZLibraryImplementation *ZLibraryImplementation::Instance = 0;
|
||||||
|
|
||||||
|
ZLibraryImplementation::ZLibraryImplementation() {
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLibraryImplementation::~ZLibraryImplementation() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/*static void *loadPlugin(const std::string &path) {
|
||||||
|
ZLLogger::Instance().println(ZLLogger::DEFAULT_CLASS, "loading " + path);
|
||||||
|
void *handle = dlopen(path.c_str(), RTLD_NOW);
|
||||||
|
if (handle == 0) {
|
||||||
|
ZLLogger::Instance().println(ZLLogger::DEFAULT_CLASS, dlerror());
|
||||||
|
}
|
||||||
|
return handle;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
bool ZLibrary::init(int &argc, char **&argv) {
|
||||||
|
#ifdef ZLSHARED
|
||||||
|
const std::string pluginPath = std::string(LIBDIR) + "/zlibrary/ui";
|
||||||
|
|
||||||
|
void *handle = 0;
|
||||||
|
|
||||||
|
if ((argc > 2) && std::string("-zlui") == argv[1]) {
|
||||||
|
std::string pluginName = argv[2];
|
||||||
|
if (!ZLStringUtil::stringEndsWith(pluginName, ".so")) {
|
||||||
|
pluginName = pluginPath + "/zlui-" + pluginName + ".so";
|
||||||
|
}
|
||||||
|
handle = loadPlugin(pluginName);
|
||||||
|
argc -= 2;
|
||||||
|
argv += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle == 0) {
|
||||||
|
DIR *dir = opendir(pluginPath.c_str());
|
||||||
|
if (dir == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::vector<std::string> names;
|
||||||
|
const dirent *file;
|
||||||
|
struct stat fileInfo;
|
||||||
|
while ((file = readdir(dir)) != 0) {
|
||||||
|
const std::string shortName = file->d_name;
|
||||||
|
if ((shortName.substr(0, 5) != "zlui-") ||
|
||||||
|
!ZLStringUtil::stringEndsWith(shortName, ".so")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const std::string fullName = pluginPath + "/" + shortName;
|
||||||
|
stat(fullName.c_str(), &fileInfo);
|
||||||
|
if (!S_ISREG(fileInfo.st_mode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
names.push_back(fullName);
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
|
std::sort(names.begin(), names.end());
|
||||||
|
for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it) {
|
||||||
|
handle = loadPlugin(*it);
|
||||||
|
if (handle != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void (*initLibrary)();
|
||||||
|
*(void**)&initLibrary = dlsym(handle, "initLibrary");
|
||||||
|
const char *error = dlerror();
|
||||||
|
if (error != 0) {
|
||||||
|
ZLLogger::Instance().println(ZLLogger::DEFAULT_CLASS, error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif /* ZLSHARED */
|
||||||
|
initLibrary();
|
||||||
|
|
||||||
|
if (ZLibraryImplementation::Instance == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLibraryImplementation::Instance->init(argc, argv);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*ZLPaintContext *ZLibrary::createContext() {
|
||||||
|
return ZLibraryImplementation::Instance->createContext();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/*void ZLibrary::run(ZLApplication *application) {
|
||||||
|
ZLibraryImplementation::Instance->run(application);
|
||||||
|
}*/
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ZLIBRARYIMPLEMENTATION_H__
|
||||||
|
#define __ZLIBRARYIMPLEMENTATION_H__
|
||||||
|
|
||||||
|
class ZLibraryImplementation {
|
||||||
|
|
||||||
|
public:
|
||||||
|
static ZLibraryImplementation *Instance;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ZLibraryImplementation();
|
||||||
|
virtual ~ZLibraryImplementation();
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void init(int &argc, char **&argv) = 0;
|
||||||
|
// virtual ZLPaintContext *createContext() = 0;
|
||||||
|
// virtual void run(ZLApplication *application) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
void initLibrary();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __ZLIBRARYIMPLEMENTATION_H__ */
|
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
#include <AndroidUtil.h>
|
||||||
|
|
||||||
|
#include "JavaFSDir.h"
|
||||||
|
|
||||||
|
|
||||||
|
JavaFSDir::JavaFSDir(const std::string &name) : ZLFSDir(name) {
|
||||||
|
myJavaFile = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
JavaFSDir::~JavaFSDir() {
|
||||||
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
|
env->DeleteGlobalRef(myJavaFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaFSDir::initJavaFile(JNIEnv *env) {
|
||||||
|
if (myJavaFile == 0) {
|
||||||
|
jobject javaFile = AndroidUtil::createZLFile(env, path());
|
||||||
|
myJavaFile = env->NewGlobalRef(javaFile);
|
||||||
|
env->DeleteLocalRef(javaFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jobjectArray JavaFSDir::getFileChildren(JNIEnv *env) {
|
||||||
|
initJavaFile(env);
|
||||||
|
if (myJavaFile == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject list = env->CallObjectMethod(myJavaFile, AndroidUtil::MID_ZLFile_children);
|
||||||
|
if (list == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
jobjectArray array = (jobjectArray)env->CallObjectMethod(list, AndroidUtil::MID_java_util_Collection_toArray);
|
||||||
|
env->DeleteLocalRef(list);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaFSDir::collectChildren(std::vector<std::string> &names, bool filesNotDirs) {
|
||||||
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
|
jobjectArray array = getFileChildren(env);
|
||||||
|
if (array == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<std::string> filesSet;
|
||||||
|
|
||||||
|
std::string prefix(path());
|
||||||
|
prefix.append("/");
|
||||||
|
size_t prefixLength = prefix.length();
|
||||||
|
|
||||||
|
const jsize size = env->GetArrayLength(array);
|
||||||
|
for (jsize i = 0; i < size; ++i) {
|
||||||
|
jobject file = env->GetObjectArrayElement(array, i);
|
||||||
|
|
||||||
|
jstring javaPath = (jstring)env->CallObjectMethod(file, AndroidUtil::MID_ZLFile_getPath);
|
||||||
|
const char *chars = env->GetStringUTFChars(javaPath, 0);
|
||||||
|
std::string path(chars);
|
||||||
|
env->ReleaseStringUTFChars(javaPath, chars);
|
||||||
|
env->DeleteLocalRef(javaPath);
|
||||||
|
|
||||||
|
if (path.length() > prefixLength) {
|
||||||
|
size_t index = path.find('/', prefixLength);
|
||||||
|
bool isdir = false;
|
||||||
|
if (index != std::string::npos) {
|
||||||
|
path.erase(index);
|
||||||
|
isdir = true;
|
||||||
|
} /*else {
|
||||||
|
isdir = env->CallBooleanMethod(file, AndroidUtil::MID_ZLFile_isDirectory) != 0;
|
||||||
|
}*/
|
||||||
|
if (isdir ^ filesNotDirs) {
|
||||||
|
names.push_back(path.substr(prefixLength));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
env->DeleteLocalRef(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaFSDir::collectSubDirs(std::vector<std::string> &names, bool includeSymlinks) {
|
||||||
|
collectChildren(names, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaFSDir::collectFiles(std::vector<std::string> &names, bool includeSymlinks) {
|
||||||
|
collectChildren(names, true);
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __JAVAFSDIR_H__
|
||||||
|
#define __JAVAFSDIR_H__
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
#include "../../../../core/src/filesystem/ZLFSDir.h"
|
||||||
|
|
||||||
|
class JavaFSDir : public ZLFSDir {
|
||||||
|
|
||||||
|
public:
|
||||||
|
JavaFSDir(const std::string &name);
|
||||||
|
~JavaFSDir();
|
||||||
|
|
||||||
|
void collectSubDirs(std::vector<std::string> &names, bool includeSymlinks);
|
||||||
|
void collectFiles(std::vector<std::string> &names, bool includeSymlinks);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initJavaFile(JNIEnv *env);
|
||||||
|
jobjectArray getFileChildren(JNIEnv *env); // returns array of ZLFile or NULL
|
||||||
|
|
||||||
|
void collectChildren(std::vector<std::string> &names, bool filesNotDirs);
|
||||||
|
|
||||||
|
private:
|
||||||
|
jobject myJavaFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __JAVAFSDIR_H__ */
|
|
@ -0,0 +1,178 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "JavaInputStream.h"
|
||||||
|
|
||||||
|
#include <AndroidUtil.h>
|
||||||
|
|
||||||
|
|
||||||
|
JavaInputStream::JavaInputStream(const std::string &name) : myName(name), myNeedRepositionToStart(false) {
|
||||||
|
myJavaFile = 0;
|
||||||
|
|
||||||
|
myJavaInputStream = 0;
|
||||||
|
myOffset = 0;
|
||||||
|
|
||||||
|
myJavaBuffer = 0;
|
||||||
|
myJavaBufferSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
JavaInputStream::~JavaInputStream() {
|
||||||
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
|
if (myJavaInputStream != 0) {
|
||||||
|
closeStream(env);
|
||||||
|
}
|
||||||
|
env->DeleteGlobalRef(myJavaFile);
|
||||||
|
env->DeleteGlobalRef(myJavaBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JavaInputStream::initStream(JNIEnv *env) {
|
||||||
|
if (myJavaFile == 0) {
|
||||||
|
jobject javaFile = AndroidUtil::createZLFile(env, myName);
|
||||||
|
myJavaFile = env->NewGlobalRef(javaFile);
|
||||||
|
env->DeleteLocalRef(javaFile);
|
||||||
|
if (myJavaFile == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jobject stream = env->CallObjectMethod(myJavaFile, AndroidUtil::MID_ZLFile_getInputStream);
|
||||||
|
if (env->ExceptionCheck()) {
|
||||||
|
env->ExceptionClear();
|
||||||
|
} else {
|
||||||
|
myJavaInputStream = env->NewGlobalRef(stream);
|
||||||
|
myOffset = 0;
|
||||||
|
}
|
||||||
|
env->DeleteLocalRef(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaInputStream::closeStream(JNIEnv *env) {
|
||||||
|
env->CallVoidMethod(myJavaInputStream, AndroidUtil::MID_java_io_InputStream_close);
|
||||||
|
if (env->ExceptionCheck()) {
|
||||||
|
env->ExceptionClear();
|
||||||
|
}
|
||||||
|
env->DeleteGlobalRef(myJavaInputStream);
|
||||||
|
myJavaInputStream = 0;
|
||||||
|
myOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaInputStream::rewind(JNIEnv *env) {
|
||||||
|
if (myOffset > 0) {
|
||||||
|
closeStream(env);
|
||||||
|
initStream(env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JavaInputStream::ensureBufferCapacity(JNIEnv *env, size_t maxSize) {
|
||||||
|
if (myJavaBuffer != 0 && myJavaBufferSize >= maxSize) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
env->DeleteGlobalRef(myJavaBuffer);
|
||||||
|
jbyteArray array = env->NewByteArray(maxSize);
|
||||||
|
myJavaBuffer = (jbyteArray)env->NewGlobalRef(array);
|
||||||
|
env->DeleteLocalRef(array);
|
||||||
|
myJavaBufferSize = maxSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t JavaInputStream::readToBuffer(JNIEnv *env, char *buffer, size_t maxSize) {
|
||||||
|
ensureBufferCapacity(env, maxSize);
|
||||||
|
|
||||||
|
jint result = env->CallIntMethod(myJavaInputStream,
|
||||||
|
AndroidUtil::MID_java_io_InputStream_read, myJavaBuffer, (jint)0, (jint)maxSize);
|
||||||
|
if (env->ExceptionCheck()) {
|
||||||
|
env->ExceptionClear();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (result > 0) {
|
||||||
|
size_t bytesRead = (size_t)result;
|
||||||
|
myOffset += bytesRead;
|
||||||
|
|
||||||
|
jbyte *data = env->GetByteArrayElements(myJavaBuffer, 0);
|
||||||
|
memcpy(buffer, data, bytesRead);
|
||||||
|
env->ReleaseByteArrayElements(myJavaBuffer, data, JNI_ABORT);
|
||||||
|
|
||||||
|
return bytesRead;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t JavaInputStream::skip(JNIEnv *env, size_t offset) {
|
||||||
|
size_t result = (size_t) env->CallLongMethod(myJavaInputStream,
|
||||||
|
AndroidUtil::MID_java_io_InputStream_skip, (jlong)offset);
|
||||||
|
if (env->ExceptionCheck()) {
|
||||||
|
env->ExceptionClear();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
myOffset += result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool JavaInputStream::open() {
|
||||||
|
if (myJavaInputStream == 0) {
|
||||||
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
|
initStream(env);
|
||||||
|
} else {
|
||||||
|
myNeedRepositionToStart = true;
|
||||||
|
}
|
||||||
|
return myJavaInputStream != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t JavaInputStream::read(char *buffer, size_t maxSize) {
|
||||||
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
|
if (myNeedRepositionToStart) {
|
||||||
|
rewind(env);
|
||||||
|
myNeedRepositionToStart = false;
|
||||||
|
}
|
||||||
|
if (buffer != 0) {
|
||||||
|
return readToBuffer(env, buffer, maxSize);
|
||||||
|
} else {
|
||||||
|
return skip(env, maxSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaInputStream::close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t JavaInputStream::sizeOfOpened() {
|
||||||
|
if (myJavaInputStream == 0 || myJavaFile == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
|
return (size_t) env->CallLongMethod(myJavaFile, AndroidUtil::MID_ZLFile_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaInputStream::seek(int offset, bool absoluteOffset) {
|
||||||
|
if (offset < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
|
if (myNeedRepositionToStart || absoluteOffset) {
|
||||||
|
rewind(env);
|
||||||
|
myNeedRepositionToStart = false;
|
||||||
|
}
|
||||||
|
if (offset > 0) {
|
||||||
|
skip(env, offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t JavaInputStream::offset() const {
|
||||||
|
return myNeedRepositionToStart ? 0 : myOffset;
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __JAVAINPUTSTREAM_H__
|
||||||
|
#define __JAVAINPUTSTREAM_H__
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
#include <ZLInputStream.h>
|
||||||
|
|
||||||
|
class JavaInputStream : public ZLInputStream {
|
||||||
|
|
||||||
|
public:
|
||||||
|
JavaInputStream(const std::string &name);
|
||||||
|
~JavaInputStream();
|
||||||
|
bool open();
|
||||||
|
size_t read(char *buffer, size_t maxSize);
|
||||||
|
void close();
|
||||||
|
|
||||||
|
void seek(int offset, bool absoluteOffset);
|
||||||
|
size_t offset() const;
|
||||||
|
size_t sizeOfOpened();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initStream(JNIEnv *env);
|
||||||
|
void closeStream(JNIEnv *env);
|
||||||
|
void rewind(JNIEnv *env);
|
||||||
|
void ensureBufferCapacity(JNIEnv *env, size_t maxSize);
|
||||||
|
size_t readToBuffer(JNIEnv *env, char *buffer, size_t maxSize);
|
||||||
|
size_t skip(JNIEnv *env, size_t offset);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string myName;
|
||||||
|
bool myNeedRepositionToStart;
|
||||||
|
|
||||||
|
jobject myJavaFile;
|
||||||
|
|
||||||
|
jobject myJavaInputStream;
|
||||||
|
size_t myOffset;
|
||||||
|
|
||||||
|
jbyteArray myJavaBuffer;
|
||||||
|
size_t myJavaBufferSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __JAVAINPUTSTREAM_H__ */
|
|
@ -0,0 +1,150 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
#include <ZLStringUtil.h>
|
||||||
|
#include <AndroidUtil.h>
|
||||||
|
|
||||||
|
#include "ZLAndroidFSManager.h"
|
||||||
|
|
||||||
|
#include "JavaInputStream.h"
|
||||||
|
#include "JavaFSDir.h"
|
||||||
|
|
||||||
|
|
||||||
|
std::string ZLAndroidFSManager::convertFilenameToUtf8(const std::string &name) const {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ZLAndroidFSManager::mimeType(const std::string &path) const {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ZLAndroidFSManager::normalizeRealPath(std::string &path) const {
|
||||||
|
if (path.empty()) {
|
||||||
|
return;
|
||||||
|
} else if (path[0] == '~') {
|
||||||
|
if (path.length() == 1 || path[1] == '/') {
|
||||||
|
path.erase(0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int last = path.length() - 1;
|
||||||
|
while ((last > 0) && (path[last] == '/')) {
|
||||||
|
--last;
|
||||||
|
}
|
||||||
|
if (last < (int)path.length() - 1) {
|
||||||
|
path = path.substr(0, last + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int index;
|
||||||
|
while ((index = path.find("/../")) != -1) {
|
||||||
|
int prevIndex = std::max((int)path.rfind('/', index - 1), 0);
|
||||||
|
path.erase(prevIndex, index + 3 - prevIndex);
|
||||||
|
}
|
||||||
|
int len = path.length();
|
||||||
|
if ((len >= 3) && (path.substr(len - 3) == "/..")) {
|
||||||
|
int prevIndex = std::max((int)path.rfind('/', len - 4), 0);
|
||||||
|
path.erase(prevIndex);
|
||||||
|
}
|
||||||
|
while ((index = path.find("/./")) != -1) {
|
||||||
|
path.erase(index, 2);
|
||||||
|
}
|
||||||
|
while (path.length() >= 2 &&
|
||||||
|
path.substr(path.length() - 2) == "/.") {
|
||||||
|
path.erase(path.length() - 2);
|
||||||
|
}
|
||||||
|
while ((index = path.find("//")) != -1) {
|
||||||
|
path.erase(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ZLFileInfo ZLAndroidFSManager::fileInfo(const std::string &path) const {
|
||||||
|
if (useNativeImplementation(path)) {
|
||||||
|
return ZLUnixFSManager::fileInfo(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLFileInfo info;
|
||||||
|
|
||||||
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
|
jobject javaFile = AndroidUtil::createZLFile(env, path);
|
||||||
|
if (javaFile == 0) {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
info.IsDirectory = env->CallBooleanMethod(javaFile, AndroidUtil::MID_ZLFile_isDirectory);
|
||||||
|
const jboolean exists = env->CallBooleanMethod(javaFile, AndroidUtil::MID_ZLFile_exists);
|
||||||
|
if (exists) {
|
||||||
|
info.Exists = true;
|
||||||
|
info.Size = env->CallLongMethod(javaFile, AndroidUtil::MID_ZLFile_size);
|
||||||
|
}
|
||||||
|
env->DeleteLocalRef(javaFile);
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ZLAndroidFSManager::resolveSymlink(const std::string &path) const {
|
||||||
|
if (useNativeImplementation(path)) {
|
||||||
|
return ZLUnixFSManager::resolveSymlink(path);
|
||||||
|
}
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLFSDir *ZLAndroidFSManager::createNewDirectory(const std::string &path) const {
|
||||||
|
if (useNativeImplementation(path)) {
|
||||||
|
return ZLUnixFSManager::createNewDirectory(path);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLFSDir *ZLAndroidFSManager::createPlainDirectory(const std::string &path) const {
|
||||||
|
if (useNativeImplementation(path)) {
|
||||||
|
return ZLUnixFSManager::createPlainDirectory(path);
|
||||||
|
}
|
||||||
|
return new JavaFSDir(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLInputStream *ZLAndroidFSManager::createPlainInputStream(const std::string &path) const {
|
||||||
|
if (useNativeImplementation(path)) {
|
||||||
|
return ZLUnixFSManager::createPlainInputStream(path);
|
||||||
|
}
|
||||||
|
return new JavaInputStream(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*ZLOutputStream *ZLAndroidFSManager::createOutputStream(const std::string &path) const {
|
||||||
|
if (useNativeImplementation(path)) {
|
||||||
|
return ZLUnixFSManager::createOutputStream(path);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
bool ZLAndroidFSManager::removeFile(const std::string &path) const {
|
||||||
|
if (useNativeImplementation(path)) {
|
||||||
|
return ZLUnixFSManager::removeFile(path);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZLAndroidFSManager::canRemoveFile(const std::string &path) const {
|
||||||
|
if (useNativeImplementation(path)) {
|
||||||
|
return ZLUnixFSManager::canRemoveFile(path);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ZLANDROIDFSMANAGER_H__
|
||||||
|
#define __ZLANDROIDFSMANAGER_H__
|
||||||
|
|
||||||
|
#include "../../../../core/src/unix/filesystem/ZLUnixFSManager.h"
|
||||||
|
|
||||||
|
class ZLAndroidFSManager : public ZLUnixFSManager {
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void createInstance();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZLAndroidFSManager();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string convertFilenameToUtf8(const std::string &name) const;
|
||||||
|
std::string mimeType(const std::string &path) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static bool useNativeImplementation(const std::string &path);
|
||||||
|
|
||||||
|
protected: // Overridden methods
|
||||||
|
void normalizeRealPath(std::string &path) const;
|
||||||
|
|
||||||
|
std::string resolveSymlink(const std::string &path) const;
|
||||||
|
ZLFSDir *createNewDirectory(const std::string &path) const;
|
||||||
|
ZLFSDir *createPlainDirectory(const std::string &path) const;
|
||||||
|
ZLInputStream *createPlainInputStream(const std::string &path) const;
|
||||||
|
//ZLOutputStream *createOutputStream(const std::string &path) const;
|
||||||
|
bool removeFile(const std::string &path) const;
|
||||||
|
|
||||||
|
ZLFileInfo fileInfo(const std::string &path) const;
|
||||||
|
|
||||||
|
bool canRemoveFile(const std::string &path) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ZLAndroidFSManager::ZLAndroidFSManager() {}
|
||||||
|
inline void ZLAndroidFSManager::createInstance() { ourInstance = new ZLAndroidFSManager(); }
|
||||||
|
|
||||||
|
inline bool ZLAndroidFSManager::useNativeImplementation(const std::string &path) {
|
||||||
|
return path.length() > 0 && path[0] == '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __ZLANDROIDFSMANAGER_H__ */
|
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
#include <AndroidUtil.h>
|
||||||
|
|
||||||
|
//#include <ZLApplication.h>
|
||||||
|
#include <ZLibrary.h>
|
||||||
|
//#include <ZLLanguageUtil.h>
|
||||||
|
|
||||||
|
#include "../../../../core/src/unix/library/ZLibraryImplementation.h"
|
||||||
|
|
||||||
|
#include "../filesystem/ZLAndroidFSManager.h"
|
||||||
|
//#include "../time/ZLGtkTime.h"
|
||||||
|
//#include "../dialogs/ZLGtkDialogManager.h"
|
||||||
|
//#include "../image/ZLGtkImageManager.h"
|
||||||
|
//#include "../view/ZLGtkPaintContext.h"
|
||||||
|
//#include "../../unix/message/ZLUnixMessage.h"
|
||||||
|
//#include "../../../../core/src/util/ZLKeyUtil.h"
|
||||||
|
//#include "../../../../core/src/unix/xmlconfig/XMLConfig.h"
|
||||||
|
//#include "../../../../core/src/unix/iconv/IConvEncodingConverter.h"
|
||||||
|
//#include "../../../../core/src/unix/curl/ZLCurlNetworkManager.h"
|
||||||
|
|
||||||
|
class ZLAndroidLibraryImplementation : public ZLibraryImplementation {
|
||||||
|
|
||||||
|
private:
|
||||||
|
void init(int &argc, char **&argv);
|
||||||
|
// ZLPaintContext *createContext();
|
||||||
|
// void run(ZLApplication *application);
|
||||||
|
};
|
||||||
|
|
||||||
|
void initLibrary() {
|
||||||
|
new ZLAndroidLibraryImplementation();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZLAndroidLibraryImplementation::init(int &argc, char **&argv) {
|
||||||
|
ZLibrary::parseArguments(argc, argv);
|
||||||
|
|
||||||
|
// XMLConfigManager::createInstance();
|
||||||
|
ZLAndroidFSManager::createInstance();
|
||||||
|
// ZLGtkTimeManager::createInstance();
|
||||||
|
// ZLGtkDialogManager::createInstance();
|
||||||
|
// ZLUnixCommunicationManager::createInstance();
|
||||||
|
// ZLGtkImageManager::createInstance();
|
||||||
|
// ZLEncodingCollection::Instance().registerProvider(new IConvEncodingConverterProvider());
|
||||||
|
// ZLCurlNetworkManager::createInstance();
|
||||||
|
|
||||||
|
// ZLKeyUtil::setKeyNamesFileName("keynames-gtk.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*ZLPaintContext *ZLAndroidLibraryImplementation::createContext() {
|
||||||
|
return new ZLGtkPaintContext();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/*void ZLAndroidLibraryImplementation::run(ZLApplication *application) {
|
||||||
|
ZLDialogManager::Instance().createApplicationWindow(application);
|
||||||
|
application->initWindow();
|
||||||
|
gtk_widget_set_default_direction(ZLLanguageUtil::isRTLLanguage(ZLibrary::Language()) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
|
||||||
|
gtk_main();
|
||||||
|
delete application;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
std::string ZLibrary::Language() {
|
||||||
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
|
jclass cls = env->FindClass(AndroidUtil::Class_java_util_Locale);
|
||||||
|
jobject locale = env->CallStaticObjectMethod(cls, AndroidUtil::SMID_java_util_Locale_getDefault);
|
||||||
|
jstring javaLang = (jstring)env->CallObjectMethod(locale, AndroidUtil::MID_java_util_Locale_getLanguage);
|
||||||
|
const char *langData = env->GetStringUTFChars(javaLang, 0);
|
||||||
|
std::string lang(langData);
|
||||||
|
env->ReleaseStringUTFChars(javaLang, langData);
|
||||||
|
env->DeleteLocalRef(javaLang);
|
||||||
|
env->DeleteLocalRef(locale);
|
||||||
|
env->DeleteLocalRef(cls);
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ZLibrary::Version() {
|
||||||
|
JNIEnv *env = AndroidUtil::getEnv();
|
||||||
|
jclass cls = env->FindClass(AndroidUtil::Class_ZLibrary);
|
||||||
|
jobject zlibrary = env->CallStaticObjectMethod(cls, AndroidUtil::SMID_ZLibrary_Instance);
|
||||||
|
jstring javaVersion = (jstring)env->CallObjectMethod(zlibrary, AndroidUtil::MID_ZLibrary_getVersionName);
|
||||||
|
const char *versionData = env->GetStringUTFChars(javaVersion, 0);
|
||||||
|
std::string version(versionData);
|
||||||
|
env->ReleaseStringUTFChars(javaVersion, versionData);
|
||||||
|
env->DeleteLocalRef(javaVersion);
|
||||||
|
env->DeleteLocalRef(zlibrary);
|
||||||
|
env->DeleteLocalRef(cls);
|
||||||
|
return version;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue