[DEV] Change the etk::File in etk::FSNode to have a compleate abstraction of the file system
This commit is contained in:
parent
b039a0fb29
commit
b03d4c0047
@ -238,13 +238,13 @@ namespace etk{
|
||||
break;
|
||||
case LOG_LEVEL_ERROR:
|
||||
#if !defined(__TARGET_OS__Windows)
|
||||
strncat(m_tmpChar, ETK_BASH_COLOR_MAGENTA, MAX_LOG_SIZE);
|
||||
strncat(m_tmpChar, ETK_BASH_COLOR_RED, MAX_LOG_SIZE);
|
||||
#endif
|
||||
strncat(m_tmpChar, "[E]", MAX_LOG_SIZE);
|
||||
break;
|
||||
case LOG_LEVEL_WARNING:
|
||||
#if !defined(__TARGET_OS__Windows)
|
||||
strncat(m_tmpChar, ETK_BASH_COLOR_BOLD_RED, MAX_LOG_SIZE);
|
||||
strncat(m_tmpChar, ETK_BASH_COLOR_MAGENTA, MAX_LOG_SIZE);
|
||||
#endif
|
||||
strncat(m_tmpChar, "[W]", MAX_LOG_SIZE);
|
||||
break;
|
||||
|
@ -649,11 +649,11 @@ void etk::UString::Clear(void)
|
||||
* @return the position of the first occurence or -1 if not find...
|
||||
*
|
||||
*/
|
||||
int32_t etk::UString::FindForward(const char element, int32_t startPos)
|
||||
int32_t etk::UString::FindForward(const char element, int32_t startPos) const
|
||||
{
|
||||
return FindForward((uniChar_t)element, startPos);
|
||||
}
|
||||
int32_t etk::UString::FindForward(const uniChar_t element, int32_t startPos)
|
||||
int32_t etk::UString::FindForward(const uniChar_t element, int32_t startPos) const
|
||||
{
|
||||
if (startPos < 0) {
|
||||
startPos = 0;
|
||||
@ -678,11 +678,11 @@ int32_t etk::UString::FindForward(const uniChar_t element, int32_t startPos)
|
||||
* @return the position of the first occurence begining by the end or -1 if not find...
|
||||
*
|
||||
*/
|
||||
int32_t etk::UString::FindBack(const char element, int32_t startPos)
|
||||
int32_t etk::UString::FindBack(const char element, int32_t startPos) const
|
||||
{
|
||||
return FindBack((uniChar_t)element, startPos);
|
||||
}
|
||||
int32_t etk::UString::FindBack(const uniChar_t element, int32_t startPos)
|
||||
int32_t etk::UString::FindBack(const uniChar_t element, int32_t startPos) const
|
||||
{
|
||||
if (startPos < 0) {
|
||||
return -1;
|
||||
@ -707,7 +707,7 @@ int32_t etk::UString::FindBack(const uniChar_t element, int32_t startPos)
|
||||
* @return the extracted UString
|
||||
*
|
||||
*/
|
||||
etk::UString etk::UString::Extract(int32_t posStart, int32_t posEnd)
|
||||
etk::UString etk::UString::Extract(int32_t posStart, int32_t posEnd) const
|
||||
{
|
||||
etk::UString out;
|
||||
if (posStart < 0) {
|
||||
|
@ -115,10 +115,10 @@ namespace etk
|
||||
// End With ...
|
||||
bool EndWith(const etk::UString& data);
|
||||
// Find element
|
||||
int32_t FindForward(const char data, int32_t startPos=0);
|
||||
int32_t FindForward(const uniChar_t data, int32_t startPos=0);
|
||||
int32_t FindBack(const char data, int32_t startPos=0x7FFFFFFF);
|
||||
int32_t FindBack(const uniChar_t data, int32_t startPos=0x7FFFFFFF);
|
||||
int32_t FindForward(const char data, int32_t startPos=0) const;
|
||||
int32_t FindForward(const uniChar_t data, int32_t startPos=0) const;
|
||||
int32_t FindBack(const char data, int32_t startPos=0x7FFFFFFF) const;
|
||||
int32_t FindBack(const uniChar_t data, int32_t startPos=0x7FFFFFFF) const;
|
||||
|
||||
bool IsEmpty(void) const;
|
||||
int32_t Size(void) const;
|
||||
@ -138,7 +138,7 @@ namespace etk
|
||||
char * c_str(void);
|
||||
|
||||
// Sting operation :
|
||||
etk::UString Extract(int32_t posStart=0, int32_t posEnd=0x7FFFFFFF);
|
||||
etk::UString Extract(int32_t posStart=0, int32_t posEnd=0x7FFFFFFF) const;
|
||||
|
||||
private :
|
||||
etk::Vector<uniChar_t> m_data; //!< internal data is stored in the Unicode properties ...
|
||||
|
@ -569,7 +569,7 @@ namespace etk
|
||||
* @param[in] posEnd End position to extract data
|
||||
* @return the extracted vector
|
||||
*/
|
||||
Vector<MY_TYPE> Extract(int32_t posStart = 0, int32_t posEnd=0x7FFFFFFF)
|
||||
Vector<MY_TYPE> Extract(int32_t posStart = 0, int32_t posEnd=0x7FFFFFFF) const
|
||||
{
|
||||
Vector<MY_TYPE> out;
|
||||
if (posStart < 0) {
|
||||
|
@ -141,7 +141,7 @@ void etk::InitDefaultFolder(const char * applName)
|
||||
baseFolderData += "/";
|
||||
|
||||
baseFolderDataUser = baseFolderHome;
|
||||
baseFolderDataUser += "/.";
|
||||
baseFolderDataUser += "/.local/share/";
|
||||
baseFolderDataUser += baseApplName;
|
||||
baseFolderDataUser += "/";
|
||||
|
||||
@ -265,8 +265,8 @@ etk::FSNode::~FSNode(void)
|
||||
}
|
||||
}
|
||||
|
||||
//#define TK_DBG_MODE TK_VERBOSE
|
||||
#define TK_DBG_MODE TK_DEBUG
|
||||
#define TK_DBG_MODE TK_VERBOSE
|
||||
//#define TK_DBG_MODE TK_DEBUG
|
||||
|
||||
|
||||
void etk::FSNode::PrivateSetName(etk::UString& newName)
|
||||
@ -364,11 +364,12 @@ void etk::FSNode::PrivateSetName(etk::UString& newName)
|
||||
m_type = etk::FSN_TYPE_RELATIF;
|
||||
}
|
||||
m_userFileName = destFilename;
|
||||
TK_DBG_MODE("3 : parse done : [" << m_type << "->\"" << m_userFileName << "\"");
|
||||
TK_DBG_MODE("3 : parse done : [" << m_type << "]->\"" << m_userFileName << "\"");
|
||||
|
||||
// Now we reduce the path with all un-needed
|
||||
m_userFileName = etk::tool::SimplifyPath(m_userFileName);
|
||||
TK_DBG_MODE("4 : Path simplification : [" << m_type << "->\"" << m_userFileName << "\"");
|
||||
// TODO : set it back again ...
|
||||
//m_userFileName = etk::tool::SimplifyPath(m_userFileName);
|
||||
TK_DBG_MODE("4 : Path simplification : [" << m_type << "]->\"" << m_userFileName << "\"");
|
||||
|
||||
#ifdef __TARGET_OS__Android
|
||||
// Get on android the property of the file ID ... in zip ... ==> maybe done this later ...
|
||||
@ -397,6 +398,25 @@ void etk::FSNode::PrivateSetName(etk::UString& newName)
|
||||
// TODO : Check if it is a file or a folder ...
|
||||
}
|
||||
|
||||
bool DirectExistFile(etk::UString tmpFileNameDirect)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
#error must do this code ...
|
||||
if (etk::FSN_TYPE_DATA == m_type) {
|
||||
if (m_idZipFile >= -1 && m_idZipFile < s_APKnbFiles) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
FILE *myFile=myFile=fopen(tmpFileNameDirect.c_str(),"rb");
|
||||
if(NULL == myFile) {
|
||||
TK_DBG_MODE("check existance of : " << tmpFileNameDirect);
|
||||
return false;
|
||||
}
|
||||
fclose(myFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
etk::UString etk::FSNode::GetFileSystemName(void) const
|
||||
{
|
||||
@ -437,6 +457,46 @@ etk::UString etk::FSNode::GetFileSystemName(void) const
|
||||
break;
|
||||
case etk::FSN_TYPE_THEME:
|
||||
output = baseFolderData + "/theme/";
|
||||
{
|
||||
//etk::UString myCompleateName=baseFolderData + "/theme/";
|
||||
etk::UString themeName("");
|
||||
etk::UString basicName(m_userFileName);
|
||||
int32_t firstPos = m_userFileName.FindForward(':');
|
||||
if (-1 != firstPos) {
|
||||
// we find a theme name : We extracted it :
|
||||
themeName = m_userFileName.Extract(0, firstPos);
|
||||
basicName = m_userFileName.Extract(firstPos+1);
|
||||
}
|
||||
TK_DBG_MODE(" THEME party : \"" << themeName << "\" => \"" << basicName << "\"");
|
||||
|
||||
if (themeName == "") {
|
||||
TK_WARNING("no theme name detected : set it to \"default\"");
|
||||
} else {
|
||||
// Selected theme :
|
||||
// check in the user data :
|
||||
etk::UString tmpCompleateName = baseFolderDataUser + "theme/" + themeName + "/" + basicName;
|
||||
if (true==DirectExistFile(tmpCompleateName)) {
|
||||
return tmpCompleateName;
|
||||
}
|
||||
// check in the Appl data :
|
||||
tmpCompleateName = baseFolderData + "theme/" + themeName + "/" + basicName;
|
||||
if (true==DirectExistFile(tmpCompleateName)) {
|
||||
return tmpCompleateName;
|
||||
}
|
||||
}
|
||||
themeName = "default";
|
||||
// default theme :
|
||||
{
|
||||
// check in the user data :
|
||||
etk::UString tmpCompleateName = baseFolderDataUser + "theme/" + themeName + "/" + basicName;
|
||||
if (true==DirectExistFile(tmpCompleateName)) {
|
||||
return tmpCompleateName;
|
||||
}
|
||||
// check in the Appl data : In every case we return this one ...
|
||||
tmpCompleateName = baseFolderData + "theme/" + themeName + "/" + basicName;
|
||||
return tmpCompleateName;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
output += m_userFileName;
|
||||
@ -646,6 +706,21 @@ etk::UString etk::FSNode::GetNameFile(void) const
|
||||
return "";
|
||||
}
|
||||
|
||||
etk::UString etk::FSNode::GetRelativeFolder(void) const
|
||||
{
|
||||
etk::UString myCompleateName=GetName();
|
||||
|
||||
int32_t lastPos = myCompleateName.FindBack('/');
|
||||
if (-1 != lastPos) {
|
||||
return myCompleateName.Extract(0, lastPos+1);
|
||||
}
|
||||
lastPos = myCompleateName.FindBack(':');
|
||||
if (-1 != lastPos) {
|
||||
return myCompleateName.Extract(0, lastPos+1);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
bool etk::FSNode::Touch(void)
|
||||
{
|
||||
|
@ -183,6 +183,7 @@ namespace etk
|
||||
etk::UString GetNameFolder(void) const;
|
||||
etk::UString GetName(void) const;
|
||||
etk::UString GetNameFile(void) const;
|
||||
etk::UString GetRelativeFolder(void) const;
|
||||
bool Touch(void);
|
||||
FSNType_te GetTypeAccess(void) { return m_type; };
|
||||
bool Remove(void);
|
||||
|
@ -1,840 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file etk/File.cpp
|
||||
* @brief Ewol Tool Kit : File folder and name abstraction (Sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 16/07/2011
|
||||
* @par Project
|
||||
* Ewol TK
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <etk/DebugInternal.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <etk/tool.h>
|
||||
|
||||
#ifdef __TARGET_OS__Android
|
||||
# include <stdio.h>
|
||||
# include <zip/zip.h>
|
||||
#endif
|
||||
|
||||
// zip file of the apk file for Android ==> set to zip file apk access
|
||||
static etk::UString s_fileAPK = "";
|
||||
etk::UString baseApplName = "ewolNoName";
|
||||
#if defined(__TARGET_OS__Android)
|
||||
etk::UString baseFolderHome = "/sdcard/"; // home folder
|
||||
etk::UString baseFolderData = "assets/"; // program Data
|
||||
etk::UString baseFolderDataUser = "/sdcard/.tmp/userData/"; // Data specific user (local modification)
|
||||
etk::UString baseFolderCache = "/sdcard/.tmp/cache/"; // Temporary data (can be removed the next time)
|
||||
#elif defined(__TARGET_OS__Windows)
|
||||
etk::UString baseFolderHome = "c:/test"; // home folder
|
||||
etk::UString baseFolderData = "c:/test/share/"; // program Data
|
||||
etk::UString baseFolderDataUser = "c:/test/userData/"; // Data specific user (local modification)
|
||||
etk::UString baseFolderCache = "c:/Windows/Temp/ewol/"; // Temporary data (can be removed the next time)
|
||||
#else
|
||||
etk::UString baseFolderHome = "~"; // home folder
|
||||
etk::UString baseFolderData = "share/"; // program Data
|
||||
etk::UString baseFolderDataUser = "~/.tmp/userData/"; // Data specific user (local modification)
|
||||
etk::UString baseFolderCache = "~/.tmp/cache/"; // Temporary data (can be removed the next time)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __TARGET_OS__Android
|
||||
static struct zip * s_APKArchive = NULL;
|
||||
static int32_t s_APKnbFiles = 0;
|
||||
static void loadAPK(etk::UString& apkPath)
|
||||
{
|
||||
TK_DEBUG("Loading APK \"" << apkPath << "\"");
|
||||
s_APKArchive = zip_open(apkPath.c_str(), 0, NULL);
|
||||
TK_ASSERT(s_APKArchive != NULL, "Error loading APK ... \"" << apkPath << "\"");
|
||||
//Just for debug, print APK contents
|
||||
s_APKnbFiles = zip_get_num_files(s_APKArchive);
|
||||
TK_INFO("List all files in the APK : " << s_APKnbFiles << " files");
|
||||
for (int iii=0; iii<s_APKnbFiles; iii++) {
|
||||
const char* name = zip_get_name(s_APKArchive, iii, 0);
|
||||
if (name == NULL) {
|
||||
TK_ERROR("Error reading zip file name at index " << iii << " : \"" << zip_strerror(s_APKArchive) << "\"");
|
||||
return;
|
||||
}
|
||||
TK_INFO(" File " << iii << " : \"" << name << "\"");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// for specific device contraint :
|
||||
void etk::SetBaseFolderData(const char * folder)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
baseFolderData = "assets/";
|
||||
s_fileAPK = folder;
|
||||
loadAPK(s_fileAPK);
|
||||
#else
|
||||
TK_WARNING("Not Availlable Outside Android");
|
||||
#endif
|
||||
}
|
||||
|
||||
void etk::SetBaseFolderDataUser(const char * folder)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
baseFolderDataUser = folder;
|
||||
#else
|
||||
TK_WARNING("Not Availlable Outside Android");
|
||||
#endif
|
||||
}
|
||||
|
||||
void etk::SetBaseFolderCache(const char * folder)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
baseFolderCache = folder;
|
||||
#else
|
||||
TK_WARNING("Not Availlable Outside Android");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void etk::InitDefaultFolder(const char * applName)
|
||||
{
|
||||
baseApplName = applName;
|
||||
char * basicPath = getenv("HOME");
|
||||
if (NULL == basicPath) {
|
||||
TK_ERROR("ERROR while trying to get the path of the home folder");
|
||||
#if defined(__TARGET_OS__Windows)
|
||||
baseFolderHome = "c:/";
|
||||
#else
|
||||
baseFolderHome = "~";
|
||||
#endif
|
||||
} else {
|
||||
baseFolderHome = basicPath;
|
||||
}
|
||||
#ifndef __TARGET_OS__Android
|
||||
|
||||
#ifdef MODE_RELEASE
|
||||
baseFolderData = "/usr/share/";
|
||||
#else
|
||||
char cCurrentPath[FILENAME_MAX];
|
||||
if (!getcwd(cCurrentPath, FILENAME_MAX)) {
|
||||
baseFolderData = "./out/Linux/debug/staging/usr/share/";
|
||||
} else {
|
||||
cCurrentPath[FILENAME_MAX - 1] = '\0';
|
||||
baseFolderData = cCurrentPath;
|
||||
baseFolderData += "/out/Linux/debug/staging/usr/share/";
|
||||
}
|
||||
#endif
|
||||
baseFolderData += baseApplName;
|
||||
baseFolderData += "/";
|
||||
|
||||
baseFolderDataUser = baseFolderHome;
|
||||
baseFolderDataUser += "/.";
|
||||
baseFolderDataUser += baseApplName;
|
||||
baseFolderDataUser += "/";
|
||||
|
||||
baseFolderCache = "/tmp/";
|
||||
baseFolderCache += baseApplName;
|
||||
baseFolderCache += "/";
|
||||
#endif
|
||||
#ifdef MODE_RELEASE
|
||||
if (strncmp("ewolApplNoName",applName, 256) != 0) {
|
||||
// start log
|
||||
}
|
||||
#endif
|
||||
TK_INFO("baseFolderHome : \"" << baseFolderHome << "\"");
|
||||
TK_INFO("baseFolderData : \"" << baseFolderData << "\"");
|
||||
TK_INFO("baseFolderDataUser : \"" << baseFolderDataUser << "\"");
|
||||
TK_INFO("baseFolderCache : \"" << baseFolderCache << "\"");
|
||||
}
|
||||
|
||||
etk::UString etk::GetUserHomeFolder(void)
|
||||
{
|
||||
return baseFolderHome;
|
||||
}
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "File"
|
||||
|
||||
|
||||
etk::CCout& etk::operator <<(etk::CCout &os, const etk::File &obj)
|
||||
{
|
||||
os << obj.m_folder;
|
||||
os << "/";
|
||||
os << obj.m_shortFilename;
|
||||
return os;
|
||||
}
|
||||
|
||||
etk::File::File(etk::UString &filename, etk::FileType_te type, int32_t LineNumber)
|
||||
{
|
||||
m_lineNumberOpen = LineNumber;
|
||||
m_PointerFile = NULL;
|
||||
SetCompleateName(filename, type);
|
||||
}
|
||||
|
||||
|
||||
etk::File::File(const char *filename, etk::FileType_te type, int32_t LineNumber)
|
||||
{
|
||||
etk::UString tmpString = filename;
|
||||
m_lineNumberOpen = LineNumber;
|
||||
m_PointerFile = NULL;
|
||||
SetCompleateName(tmpString, type);
|
||||
}
|
||||
|
||||
|
||||
etk::File::File(etk::UString &filename, etk::UString &folder, etk::FileType_te type, int32_t lineNumber)
|
||||
{
|
||||
etk::UString tmpString = folder;
|
||||
tmpString += "/";
|
||||
tmpString += filename;
|
||||
m_PointerFile = NULL;
|
||||
SetCompleateName(tmpString, type);
|
||||
m_lineNumberOpen = lineNumber;
|
||||
}
|
||||
|
||||
etk::File::~File(void)
|
||||
{
|
||||
// nothing to do ...
|
||||
if (NULL != m_PointerFile) {
|
||||
TK_ERROR("Missing close the file : \"" << GetCompleateName() << "\"");
|
||||
fClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
etk::UString etk::File::GetFolder(void) const
|
||||
{
|
||||
return m_folder;
|
||||
}
|
||||
|
||||
etk::UString etk::File::GetShortFilename(void) const
|
||||
{
|
||||
return m_shortFilename;
|
||||
}
|
||||
|
||||
etk::UString etk::File::GetCompleateName(void) const
|
||||
{
|
||||
etk::UString out;
|
||||
out = m_folder;
|
||||
out += "/";
|
||||
out += m_shortFilename;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
const etk::File& etk::File::operator= (const etk::File &etkF )
|
||||
{
|
||||
if( this != &etkF ) // avoid copy to itself
|
||||
{
|
||||
m_folder = etkF.m_folder;
|
||||
m_shortFilename = etkF.m_shortFilename;
|
||||
m_lineNumberOpen = etkF.m_lineNumberOpen;
|
||||
m_type = etkF.m_type;
|
||||
if (NULL != m_PointerFile) {
|
||||
TK_ERROR("Missing close the file : \"" << GetCompleateName() << "\"");
|
||||
fClose();
|
||||
}
|
||||
#ifdef __TARGET_OS__Android
|
||||
m_idZipFile = etkF.m_idZipFile;
|
||||
m_zipData = NULL;
|
||||
m_zipDataSize = 0;
|
||||
m_zipReadingOffset = 0;
|
||||
//m_zipPointerFile = NULL;
|
||||
#endif
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param[in,out]
|
||||
*
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
bool etk::File::operator== (const etk::File &etkF) const
|
||||
{
|
||||
if( this != &etkF ) {
|
||||
if (etkF.GetCompleateName() == GetCompleateName() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param[in,out]
|
||||
*
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
bool etk::File::operator!= (const etk::File &etkF) const
|
||||
{
|
||||
return !(*this == etkF);
|
||||
}
|
||||
|
||||
#define TK_DBG_MODE TK_VERBOSE
|
||||
//#define TK_DBG_MODE TK_DEBUG
|
||||
|
||||
void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te type)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
m_idZipFile = -1;
|
||||
m_zipData = NULL;
|
||||
m_zipDataSize = 0;
|
||||
m_zipReadingOffset = 0;
|
||||
//m_zipPointerFile = NULL;
|
||||
#endif
|
||||
// Reset ALL DATA :
|
||||
m_folder = "";
|
||||
m_shortFilename = "";
|
||||
m_lineNumberOpen = 0;
|
||||
TK_DBG_MODE("1 :Set Name : " << newFilename );
|
||||
etk::UString destFilename;
|
||||
if (newFilename.Size() == 0) {
|
||||
destFilename = "no-name";
|
||||
} else {
|
||||
destFilename = newFilename;
|
||||
}
|
||||
|
||||
#ifdef __TARGET_OS__Windows
|
||||
TK_DBG_MODE("2 : Get file Name : " << destFilename << "start with 'c:/'=" << destFilename.StartWith("c:/"));
|
||||
if (true == destFilename.StartWith("c:/")) {
|
||||
#else
|
||||
TK_DBG_MODE("2 : Get file Name : " << destFilename << "start with '/'=" << destFilename.StartWith('/'));
|
||||
if (true == destFilename.StartWith('/')) {
|
||||
#endif
|
||||
m_type = etk::FILE_TYPE_DIRECT;
|
||||
if (type != etk::FILE_TYPE_DIRECT) {
|
||||
TK_WARNING("Incompatible type with a file=\"" << newFilename << "\" ==> force it in direct mode ...");
|
||||
}
|
||||
} else {
|
||||
if (type == etk::FILE_TYPE_DIRECT) {
|
||||
//TK_WARNING("Incompatible type with a file=\"" << newFilename << "\" ==> force it in FILE_TYPE_DATA mode ...");
|
||||
//m_type = etk::FILE_TYPE_DATA;
|
||||
m_type = etk::FILE_TYPE_DIRECT;
|
||||
// add current path :
|
||||
// Get the command came from the running of the program :
|
||||
char cCurrentPath[FILENAME_MAX];
|
||||
if (!getcwd(cCurrentPath, FILENAME_MAX)) {
|
||||
return;
|
||||
}
|
||||
cCurrentPath[FILENAME_MAX - 1] = '\0';
|
||||
etk::UString tmpFilename = destFilename;
|
||||
destFilename = cCurrentPath;
|
||||
destFilename += "/";
|
||||
destFilename += tmpFilename;
|
||||
} else {
|
||||
m_type = type;
|
||||
}
|
||||
}
|
||||
bool needUnpack = false;
|
||||
#if ETK_DEBUG_LEVEL > 3
|
||||
char *mode = NULL;
|
||||
#endif
|
||||
switch (m_type)
|
||||
{
|
||||
case etk::FILE_TYPE_DATA:
|
||||
{
|
||||
#if DEBUG_LEVEL > 3
|
||||
mode = "FILE_TYPE_DATA";
|
||||
#endif
|
||||
#ifdef __TARGET_OS__Android
|
||||
etk::UString tmpFilename = baseFolderData + destFilename;
|
||||
for (int iii=0; iii<s_APKnbFiles; iii++) {
|
||||
const char* name = zip_get_name(s_APKArchive, iii, 0);
|
||||
if (name == NULL) {
|
||||
return;
|
||||
}
|
||||
if (tmpFilename == name) {
|
||||
m_idZipFile = iii;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (-1 == m_idZipFile) {
|
||||
TK_ERROR("File Does not existed ... in APK : \"" << tmpFilename << "\"");
|
||||
} else {
|
||||
TK_DBG_MODE("File existed ... in APK : \"" << tmpFilename << "\" ==> id=" << m_idZipFile);
|
||||
}
|
||||
#else
|
||||
//etk::UString tmpFilename = destFilename;
|
||||
//destFilename = baseFolderData;
|
||||
//destFilename += tmpFilename;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case etk::FILE_TYPE_USER_DATA:
|
||||
{
|
||||
#if DEBUG_LEVEL > 3
|
||||
mode = "FILE_TYPE_USER_DATA";
|
||||
#endif
|
||||
etk::UString tmpFilename = destFilename;
|
||||
destFilename = baseFolderDataUser;
|
||||
destFilename += tmpFilename;
|
||||
}
|
||||
needUnpack = true;
|
||||
break;
|
||||
case etk::FILE_TYPE_CACHE:
|
||||
{
|
||||
#if DEBUG_LEVEL > 3
|
||||
mode = "FILE_TYPE_CACHE";
|
||||
#endif
|
||||
etk::UString tmpFilename = destFilename;
|
||||
destFilename = baseFolderCache;
|
||||
destFilename += tmpFilename;
|
||||
}
|
||||
needUnpack = true;
|
||||
break;
|
||||
default:
|
||||
// nothing to do ...
|
||||
#if DEBUG_LEVEL > 3
|
||||
mode = "FILE_TYPE_DIRECT";
|
||||
#endif
|
||||
needUnpack = true;
|
||||
break;
|
||||
}
|
||||
TK_DBG_MODE("3 : Get file Name : " << destFilename );
|
||||
if (true == needUnpack) {
|
||||
|
||||
int32_t lastPos = destFilename.FindBack('/');
|
||||
if (-1 != lastPos) {
|
||||
m_shortFilename = destFilename.Extract(lastPos+1);
|
||||
m_folder = destFilename.Extract(0, lastPos);
|
||||
} else {
|
||||
// Basic ERROR ...
|
||||
TK_DBG_MODE("file : \"" << destFilename << "\" ==> No data???");
|
||||
m_shortFilename = destFilename;
|
||||
m_folder = "";
|
||||
}
|
||||
// Get the real Path of the current File
|
||||
m_folder = etk::tool::SimplifyPath(m_folder);
|
||||
} else {
|
||||
int32_t lastPos = destFilename.FindBack('/');
|
||||
if (-1 != lastPos) {
|
||||
m_shortFilename = destFilename.Extract(lastPos+1);
|
||||
m_folder = destFilename.Extract(0, lastPos);
|
||||
} else {
|
||||
// Basic ERROR ...
|
||||
TK_DBG_MODE("file : \"" << destFilename << "\" ==> No data???");
|
||||
m_shortFilename = destFilename;
|
||||
}
|
||||
}
|
||||
TK_DBG_MODE("Set FileName :\"" << m_folder << "\" / \"" << m_shortFilename << "\"");
|
||||
TK_VERBOSE(" ==> mode=" << mode);
|
||||
}
|
||||
|
||||
int32_t etk::File::GetLineNumber(void)
|
||||
{
|
||||
return m_lineNumberOpen;
|
||||
}
|
||||
|
||||
void etk::File::SetLineNumber(int32_t newline)
|
||||
{
|
||||
m_lineNumberOpen = newline;
|
||||
}
|
||||
|
||||
bool etk::File::HasExtention(void)
|
||||
{
|
||||
int32_t lastPos = m_shortFilename.FindBack('.');
|
||||
if( -1 != lastPos // not find the .
|
||||
&& 0 != lastPos // Find a . at the fist position .jdlskjdfklj ==> hiden file
|
||||
&& m_shortFilename.Size() != lastPos ) // Remove file ended with .
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
etk::UString etk::File::GetExtention(void)
|
||||
{
|
||||
etk::UString tmpExt = "";
|
||||
int32_t lastPos = m_shortFilename.FindBack('.');
|
||||
if( -1 != lastPos // not find the .
|
||||
&& 0 != lastPos // Find a . at the fist position .jdlskjdfklj ==> hiden file
|
||||
&& m_shortFilename.Size() != lastPos ) // Remove file ended with .
|
||||
{
|
||||
// Get the FileName
|
||||
tmpExt = m_shortFilename.Extract(lastPos+1);
|
||||
}
|
||||
return tmpExt;
|
||||
}
|
||||
|
||||
#ifdef __TARGET_OS__Android
|
||||
bool etk::File::LoadDataZip(void)
|
||||
{
|
||||
if (NULL != m_zipData) {
|
||||
return true;
|
||||
} else {
|
||||
struct zip_file * m_zipPointerFile= zip_fopen_index(s_APKArchive, m_idZipFile, 0);
|
||||
if (NULL == m_zipPointerFile) {
|
||||
TK_ERROR("Can not find the file name=\"" << GetCompleateName() << "\"");
|
||||
return false;
|
||||
}
|
||||
// get the fileSize .... end read all the data from the zip files
|
||||
struct zip_stat zipFileProperty;
|
||||
zip_stat_init(&zipFileProperty);
|
||||
zip_stat_index(s_APKArchive, m_idZipFile, 0, &zipFileProperty);
|
||||
TK_VERBOSE("LOAD data from the files : \"" << GetCompleateName() << "\"");
|
||||
/*
|
||||
TK_DEBUG(" name=" << zipFileProperty.name);
|
||||
TK_DEBUG(" index=" << zipFileProperty.index);
|
||||
TK_DEBUG(" crc=" << zipFileProperty.crc);
|
||||
TK_DEBUG(" mtime=" << zipFileProperty.mtime);
|
||||
TK_DEBUG(" size=" << zipFileProperty.size);
|
||||
TK_DEBUG(" comp_size=" << zipFileProperty.comp_size);
|
||||
TK_DEBUG(" comp_method=" << zipFileProperty.comp_method);
|
||||
TK_DEBUG(" encryption_method=" << zipFileProperty.encryption_method);
|
||||
*/
|
||||
m_zipDataSize = zipFileProperty.size;
|
||||
m_zipData = new char[m_zipDataSize +10];
|
||||
if (NULL == m_zipData) {
|
||||
TK_ERROR("File allocation ERROR : \"" << GetCompleateName() << "\"");
|
||||
zip_fclose(m_zipPointerFile);
|
||||
return false;
|
||||
}
|
||||
memset(m_zipData, 0, m_zipDataSize +10);
|
||||
int32_t sizeTmp = zip_fread(m_zipPointerFile, m_zipData, m_zipDataSize);
|
||||
if (sizeTmp != m_zipDataSize) {
|
||||
TK_ERROR("File load data ERROR : \"" << GetCompleateName() << "\"");
|
||||
zip_fclose(m_zipPointerFile);
|
||||
delete[] m_zipData;
|
||||
return false;
|
||||
}
|
||||
zip_fclose(m_zipPointerFile);
|
||||
m_zipPointerFile = NULL;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t etk::File::Size(void)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
if (etk::FILE_TYPE_DATA == m_type) {
|
||||
if (true == LoadDataZip()) {
|
||||
return m_zipDataSize;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
FILE *myFile=NULL;
|
||||
etk::UString myCompleateName;
|
||||
switch (m_type)
|
||||
{
|
||||
case etk::FILE_TYPE_DATA:
|
||||
myCompleateName = baseFolderData;
|
||||
break;
|
||||
case etk::FILE_TYPE_USER_DATA:
|
||||
myCompleateName = baseFolderDataUser;
|
||||
break;
|
||||
case etk::FILE_TYPE_CACHE:
|
||||
myCompleateName = baseFolderCache;
|
||||
break;
|
||||
default:
|
||||
myCompleateName = "";
|
||||
break;
|
||||
}
|
||||
myCompleateName += GetCompleateName();
|
||||
myFile=fopen(myCompleateName.c_str(),"rb");
|
||||
if(NULL == myFile) {
|
||||
//EWOL_ERROR("Can not find the file name=\"" << m_folder << "\" / \"" << m_shortFilename << "\"");
|
||||
return -1;
|
||||
}
|
||||
int32_t size = 0;
|
||||
fseek(myFile, 0, SEEK_END);
|
||||
size = ftell(myFile);
|
||||
fseek(myFile, 0, SEEK_SET);
|
||||
fclose(myFile);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
bool etk::File::Exist(void)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
if (etk::FILE_TYPE_DATA == m_type) {
|
||||
if (m_idZipFile >= -1 && m_idZipFile < s_APKnbFiles) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
FILE *myFile=NULL;
|
||||
etk::UString myCompleateName;
|
||||
switch (m_type)
|
||||
{
|
||||
case etk::FILE_TYPE_DATA:
|
||||
myCompleateName = baseFolderData;
|
||||
break;
|
||||
case etk::FILE_TYPE_USER_DATA:
|
||||
myCompleateName = baseFolderDataUser;
|
||||
break;
|
||||
case etk::FILE_TYPE_CACHE:
|
||||
myCompleateName = baseFolderCache;
|
||||
break;
|
||||
default:
|
||||
myCompleateName = "";
|
||||
break;
|
||||
}
|
||||
myCompleateName += GetCompleateName();
|
||||
myFile=fopen(myCompleateName.c_str(),"rb");
|
||||
if(NULL == myFile) {
|
||||
TK_DEBUG("try to open : " << myCompleateName.c_str());
|
||||
return false;
|
||||
}
|
||||
fclose(myFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool etk::File::fOpenRead(void)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
if (etk::FILE_TYPE_DATA == m_type) {
|
||||
return LoadDataZip();
|
||||
}
|
||||
#endif
|
||||
if (NULL != m_PointerFile) {
|
||||
TK_CRITICAL("File Already open : \"" << GetCompleateName() << "\"");
|
||||
return true;
|
||||
}
|
||||
etk::UString myCompleateName;
|
||||
switch (m_type)
|
||||
{
|
||||
case etk::FILE_TYPE_DATA:
|
||||
myCompleateName = baseFolderData;
|
||||
break;
|
||||
case etk::FILE_TYPE_USER_DATA:
|
||||
myCompleateName = baseFolderDataUser;
|
||||
break;
|
||||
case etk::FILE_TYPE_CACHE:
|
||||
myCompleateName = baseFolderCache;
|
||||
break;
|
||||
default:
|
||||
myCompleateName = "";
|
||||
break;
|
||||
}
|
||||
myCompleateName += GetCompleateName();
|
||||
m_PointerFile=fopen(myCompleateName.c_str(),"rb");
|
||||
if(NULL == m_PointerFile) {
|
||||
TK_ERROR("Can not find the file name=\"" << GetCompleateName() << "\"");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool etk::File::fOpenWrite(void)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
if (etk::FILE_TYPE_DATA == m_type) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
if (NULL != m_PointerFile) {
|
||||
TK_CRITICAL("File Already open : \"" << GetCompleateName() << "\"");
|
||||
return true;
|
||||
}
|
||||
etk::UString myCompleateName;
|
||||
switch (m_type)
|
||||
{
|
||||
case etk::FILE_TYPE_DATA:
|
||||
myCompleateName = baseFolderData;
|
||||
break;
|
||||
case etk::FILE_TYPE_USER_DATA:
|
||||
myCompleateName = baseFolderDataUser;
|
||||
break;
|
||||
case etk::FILE_TYPE_CACHE:
|
||||
myCompleateName = baseFolderCache;
|
||||
break;
|
||||
default:
|
||||
myCompleateName = "";
|
||||
break;
|
||||
}
|
||||
myCompleateName += GetCompleateName();
|
||||
m_PointerFile=fopen(myCompleateName.c_str(),"wb");
|
||||
if(NULL == m_PointerFile) {
|
||||
TK_ERROR("Can not find the file name=\"" << GetCompleateName() << "\"");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool etk::File::fClose(void)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
if (etk::FILE_TYPE_DATA == m_type) {
|
||||
if (NULL == m_zipData) {
|
||||
TK_CRITICAL("File Already closed : \"" << GetCompleateName() << "\"");
|
||||
return false;
|
||||
}
|
||||
delete[] m_zipData;
|
||||
m_zipData = NULL;
|
||||
m_zipDataSize = 0;
|
||||
m_zipReadingOffset = 0;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
if (NULL == m_PointerFile) {
|
||||
TK_CRITICAL("File Already closed : \"" << GetCompleateName() << "\"");
|
||||
return false;
|
||||
}
|
||||
fclose(m_PointerFile);
|
||||
m_PointerFile = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
char * etk::File::fGets(char * elementLine, int32_t maxData)
|
||||
{
|
||||
memset(elementLine, 0, maxData);
|
||||
#ifdef __TARGET_OS__Android
|
||||
char * element = elementLine;
|
||||
int32_t outSize = 0;
|
||||
if (etk::FILE_TYPE_DATA == m_type) {//char * tmpData = internalDataFiles[iii].data + m_readingOffset;
|
||||
if (NULL == m_zipData) {
|
||||
element[0] = '\0';
|
||||
return NULL;
|
||||
}
|
||||
if (m_zipReadingOffset>m_zipDataSize) {
|
||||
element[0] = '\0';
|
||||
return NULL;
|
||||
}
|
||||
while (m_zipData[m_zipReadingOffset] != '\0') {
|
||||
if( m_zipData[m_zipReadingOffset] == '\n'
|
||||
|| m_zipData[m_zipReadingOffset] == '\r')
|
||||
{
|
||||
*element = m_zipData[m_zipReadingOffset];
|
||||
element++;
|
||||
m_zipReadingOffset++;
|
||||
*element = '\0';
|
||||
return elementLine;
|
||||
}
|
||||
*element = m_zipData[m_zipReadingOffset];
|
||||
element++;
|
||||
m_zipReadingOffset++;
|
||||
if (m_zipReadingOffset>m_zipDataSize) {
|
||||
*element = '\0';
|
||||
return elementLine;
|
||||
}
|
||||
// check maxData Size ...
|
||||
if (outSize>=maxData-1) {
|
||||
*element = '\0';
|
||||
return elementLine;
|
||||
}
|
||||
outSize++;
|
||||
}
|
||||
if (outSize==0) {
|
||||
return NULL;
|
||||
} else {
|
||||
// send last line
|
||||
return elementLine;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return fgets(elementLine, maxData, m_PointerFile);
|
||||
}
|
||||
|
||||
int32_t etk::File::fRead(void * data, int32_t blockSize, int32_t nbBlock)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
if (etk::FILE_TYPE_DATA == m_type) {
|
||||
if (NULL == m_zipData) {
|
||||
((char*)data)[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
int32_t dataToRead = blockSize * nbBlock;
|
||||
if (dataToRead + m_zipReadingOffset > m_zipDataSize) {
|
||||
nbBlock = ((m_zipDataSize - m_zipReadingOffset) / blockSize);
|
||||
dataToRead = blockSize * nbBlock;
|
||||
}
|
||||
memcpy(data, &m_zipData[m_zipReadingOffset], dataToRead);
|
||||
m_zipReadingOffset += dataToRead;
|
||||
return nbBlock;
|
||||
}
|
||||
#endif
|
||||
return fread(data, blockSize, nbBlock, m_PointerFile);
|
||||
}
|
||||
|
||||
int32_t etk::File::fWrite(void * data, int32_t blockSize, int32_t nbBlock)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
if (etk::FILE_TYPE_DATA == m_type) {
|
||||
TK_CRITICAL("Can not write on data inside APK : \"" << GetCompleateName() << "\"");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return fwrite(data, blockSize, nbBlock, m_PointerFile);
|
||||
}
|
||||
|
||||
|
||||
bool etk::File::fSeek(long int offset, int origin)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
if (etk::FILE_TYPE_DATA == m_type) {
|
||||
if (NULL == m_zipData) {
|
||||
return false;
|
||||
}
|
||||
int32_t positionEnd = 0;
|
||||
switch(origin) {
|
||||
case SEEK_END:
|
||||
positionEnd = m_zipDataSize;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
positionEnd = m_zipReadingOffset;
|
||||
break;
|
||||
default:
|
||||
positionEnd = 0;
|
||||
break;
|
||||
}
|
||||
positionEnd += offset;
|
||||
if (positionEnd < 0) {
|
||||
positionEnd = 0;
|
||||
} else if (positionEnd > m_zipDataSize) {
|
||||
positionEnd = m_zipDataSize;
|
||||
}
|
||||
m_zipReadingOffset = positionEnd;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
fseek(m_PointerFile, offset, origin);
|
||||
if(ferror(m_PointerFile)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char * etk::File::GetDirectPointer(void)
|
||||
{
|
||||
#ifdef __TARGET_OS__Android
|
||||
if (etk::FILE_TYPE_DATA == m_type) {
|
||||
if (NULL == m_zipData) {
|
||||
return NULL;
|
||||
}
|
||||
return m_zipData;
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file etk/os/File.h
|
||||
* @brief Ewol Tool Kit : File folder and name abstraction (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 16/07/2011
|
||||
* @par Project
|
||||
* Ewol TK
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __ETK_FILE_H__
|
||||
#define __ETK_FILE_H__
|
||||
|
||||
#include <etk/UString.h>
|
||||
|
||||
#define MAX_FILE_NAME (10240)
|
||||
|
||||
//http://developer.android.com/guide/topics/data/data-storage.html
|
||||
|
||||
namespace etk
|
||||
{
|
||||
typedef enum {
|
||||
// user might done abstraction ==> acces of the sdcard when possible ...
|
||||
FILE_TYPE_DIRECT,
|
||||
|
||||
// depend of the case
|
||||
// - PC : /usr/shared/programName/
|
||||
// - Android : Internal at the executable file (pointer on static area)
|
||||
// - Apple : Internal at the executable file
|
||||
FILE_TYPE_DATA,
|
||||
|
||||
// depend on case
|
||||
// - PC : ~/.programName/
|
||||
// - Android : /data/data/programName/files/
|
||||
// - Apple : ????
|
||||
FILE_TYPE_USER_DATA,
|
||||
|
||||
// depend on case
|
||||
// - PC : ~/.programName/cache/
|
||||
// - Android : /data/data/programName/cache/
|
||||
// - Apple : ????
|
||||
FILE_TYPE_CACHE,
|
||||
} FileType_te;
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
File(void) { m_lineNumberOpen=0; m_type = etk::FILE_TYPE_DIRECT; m_PointerFile = NULL;}
|
||||
File(etk::UString &filename, etk::FileType_te type = etk::FILE_TYPE_DIRECT, int32_t LineNumber = 0);
|
||||
File(const char *filename, etk::FileType_te type = etk::FILE_TYPE_DIRECT, int32_t LineNumber = 0);
|
||||
File(etk::UString &filename, etk::UString &folder, etk::FileType_te type = etk::FILE_TYPE_DIRECT, int32_t lineNumber = 0);
|
||||
~File(void);
|
||||
etk::UString GetFolder(void) const;
|
||||
etk::UString GetShortFilename(void) const;
|
||||
etk::UString GetCompleateName(void) const;
|
||||
bool HasExtention(void);
|
||||
etk::UString GetExtention(void);
|
||||
int32_t Size(void);
|
||||
bool Exist(void);
|
||||
int32_t GetLineNumber(void);
|
||||
void SetLineNumber(int32_t newline);
|
||||
void SetCompleateName(etk::UString &newFilename, etk::FileType_te type);
|
||||
|
||||
const etk::File& operator= (const etk::File &etkF );
|
||||
bool operator== (const etk::File &etkF ) const;
|
||||
bool operator!= (const etk::File &etkF ) const;
|
||||
friend etk::CCout& operator <<( etk::CCout &os,const etk::File &obj);
|
||||
|
||||
FileType_te GetTypeAccess(void) { return m_type; };
|
||||
char * GetDirectPointer(void);
|
||||
|
||||
// TODO : IO access of the file :
|
||||
bool fOpenRead(void);
|
||||
bool fOpenWrite(void);
|
||||
bool fClose(void);
|
||||
char * fGets(char * elementLine, int32_t maxData);
|
||||
int32_t fRead(void * data, int32_t blockSize, int32_t nbBlock);
|
||||
int32_t fWrite(void * data, int32_t blockSize, int32_t nbBlock);
|
||||
bool fSeek(long int offset, int origin);
|
||||
private :
|
||||
etk::FileType_te m_type;
|
||||
FILE * m_PointerFile;
|
||||
#ifdef __TARGET_OS__Android
|
||||
bool LoadDataZip(void);
|
||||
int32_t m_idZipFile;
|
||||
char * m_zipData;
|
||||
int32_t m_zipDataSize;
|
||||
int32_t m_zipReadingOffset;
|
||||
#endif
|
||||
etk::UString m_folder;
|
||||
etk::UString m_shortFilename;
|
||||
int32_t m_lineNumberOpen;
|
||||
};
|
||||
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::File &obj);
|
||||
|
||||
void SetBaseFolderData(const char * folder);
|
||||
void SetBaseFolderDataUser(const char * folder);
|
||||
void SetBaseFolderCache(const char * folder);
|
||||
void InitDefaultFolder(const char * applName);
|
||||
etk::UString GetUserHomeFolder(void);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
#include <etk/tool.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
// for the rand ...
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
@ -17,7 +17,6 @@ FILE_LIST+= \
|
||||
|
||||
|
||||
FILE_LIST+= \
|
||||
etk/os/File.cpp \
|
||||
etk/os/FSNode.cpp \
|
||||
etk/os/Memory.cpp \
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include <ewol/Debug.h>
|
||||
#include <etk/Vector.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <ewol/Mesh/MeshObj.h>
|
||||
#include <ewol/ResourceManager.h>
|
||||
|
||||
@ -32,14 +32,14 @@
|
||||
ewol::MeshObj::MeshObj(etk::UString _fileName) :
|
||||
ewol::Mesh(_fileName)
|
||||
{
|
||||
etk::File fileName(_fileName, etk::FILE_TYPE_DATA);
|
||||
etk::FSNode fileName(etk::UString("DATA:") + _fileName);
|
||||
// Get the fileSize ...
|
||||
int32_t size = fileName.Size();
|
||||
int32_t size = fileName.FileSize();
|
||||
if (size == 0 ) {
|
||||
EWOL_ERROR("No data in the file named=\"" << fileName << "\"");
|
||||
return;
|
||||
}
|
||||
if(false == fileName.fOpenRead() ) {
|
||||
if(false == fileName.FileOpenRead() ) {
|
||||
EWOL_ERROR("Can not find the file name=\"" << fileName << "\"");
|
||||
return;
|
||||
}
|
||||
@ -54,7 +54,7 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) :
|
||||
etk::Vector< etk::Vector3D<float> > normals;
|
||||
|
||||
|
||||
while (NULL != fileName.fGets(inputDataLine, 2048) )
|
||||
while (NULL != fileName.FileGets(inputDataLine, 2048) )
|
||||
{
|
||||
if (inputDataLine[0]=='v') {
|
||||
if (inputDataLine[1]=='n') {
|
||||
@ -132,7 +132,7 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) :
|
||||
// ???? : mtllib cube.mtl
|
||||
}
|
||||
}
|
||||
fileName.fClose();
|
||||
fileName.FileClose();
|
||||
// For each vertex of each triangle
|
||||
for( uint32_t iii=0; iii<indicesVertices.Size(); iii++ ){
|
||||
// Get the indices of its attributes
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <etk/UString.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <ewol/audio/decWav.h>
|
||||
#include <ewol/Debug.h>
|
||||
|
||||
@ -81,7 +81,7 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
nbSampleOut = 0;
|
||||
waveHeader myHeader;
|
||||
memset(&myHeader, 0, sizeof(waveHeader));
|
||||
etk::File fileAccess(filename, etk::FILE_TYPE_DATA);
|
||||
etk::FSNode fileAccess(etk::UString("DATA:") + filename);
|
||||
// Start loading the XML :
|
||||
EWOL_DEBUG("open file (WAV) \"" << fileAccess << "\"");
|
||||
|
||||
@ -89,12 +89,12 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
EWOL_ERROR("File Does not exist : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
int32_t fileSize = fileAccess.Size();
|
||||
int32_t fileSize = fileAccess.FileSize();
|
||||
if (0==fileSize) {
|
||||
EWOL_ERROR("This file is empty : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
if (false == fileAccess.fOpenRead()) {
|
||||
if (false == fileAccess.FileOpenRead()) {
|
||||
EWOL_ERROR("Can not open the file : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
@ -106,7 +106,7 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
// ----------------------------------------------
|
||||
// read the header :
|
||||
// ----------------------------------------------
|
||||
if (fileAccess.fRead(&myHeader.riffTag, 1, 4)!=4) {
|
||||
if (fileAccess.FileRead(&myHeader.riffTag, 1, 4)!=4) {
|
||||
EWOL_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
@ -124,14 +124,14 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
}
|
||||
// get the data size :
|
||||
unsigned char tmpData[32];
|
||||
if (fileAccess.fRead(tmpData, 1, 4)!=4) {
|
||||
if (fileAccess.FileRead(tmpData, 1, 4)!=4) {
|
||||
EWOL_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
myHeader.size = CONVERT_UINT32(littleEndien, tmpData);
|
||||
|
||||
// get the data size :
|
||||
if (fileAccess.fRead(&myHeader.waveTag, 1, 4)!=4) {
|
||||
if (fileAccess.FileRead(&myHeader.waveTag, 1, 4)!=4) {
|
||||
EWOL_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
@ -144,7 +144,7 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
}
|
||||
|
||||
// get the data size :
|
||||
if (fileAccess.fRead(&myHeader.fmtTag, 1, 4)!=4) {
|
||||
if (fileAccess.FileRead(&myHeader.fmtTag, 1, 4)!=4) {
|
||||
EWOL_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
@ -156,7 +156,7 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
return NULL;
|
||||
}
|
||||
// get the data size :
|
||||
if (fileAccess.fRead(tmpData, 1, 4)!=4) {
|
||||
if (fileAccess.FileRead(tmpData, 1, 4)!=4) {
|
||||
EWOL_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
@ -166,7 +166,7 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
EWOL_ERROR("file : \"" << fileAccess << "\" ==> header error ...");
|
||||
return NULL;
|
||||
}
|
||||
if (fileAccess.fRead(tmpData, 1, 16)!=16) {
|
||||
if (fileAccess.FileRead(tmpData, 1, 16)!=16) {
|
||||
EWOL_ERROR("Can not 16 element in the file : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
@ -190,7 +190,7 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
EWOL_DEBUG(" bytesPerFrame : " << myHeader.waveFormat.bytesPerFrame);
|
||||
EWOL_DEBUG(" bitsPerSample : " << myHeader.waveFormat.bitsPerSample);
|
||||
// get the data size :
|
||||
if (fileAccess.fRead(&myHeader.dataTag, 1, 4)!=4) {
|
||||
if (fileAccess.FileRead(&myHeader.dataTag, 1, 4)!=4) {
|
||||
EWOL_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
@ -202,7 +202,7 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
return NULL;
|
||||
}
|
||||
// get the data size :
|
||||
if (fileAccess.fRead(tmpData, 1, 4)!=4) {
|
||||
if (fileAccess.FileRead(tmpData, 1, 4)!=4) {
|
||||
EWOL_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
|
||||
return NULL;
|
||||
}
|
||||
@ -248,14 +248,14 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
char audioSample[8];
|
||||
if (myHeader.waveFormat.bitsPerSample == 16) {
|
||||
if (myHeader.waveFormat.channelCount == 1) {
|
||||
if (fileAccess.fRead(audioSample, 1, 2)!=2) {
|
||||
if (fileAccess.FileRead(audioSample, 1, 2)!=2) {
|
||||
EWOL_ERROR("Read Error at position : " << iii);
|
||||
return NULL;
|
||||
}
|
||||
left = ((int32_t)((int16_t)CONVERT_INT16(littleEndien, audioSample))) << 16;
|
||||
right = left;
|
||||
} else {
|
||||
if (fileAccess.fRead(audioSample, 1, 4)!=4) {
|
||||
if (fileAccess.FileRead(audioSample, 1, 4)!=4) {
|
||||
EWOL_ERROR("Read Error at position : " << iii);
|
||||
return NULL;
|
||||
}
|
||||
@ -264,14 +264,14 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
}
|
||||
} else if (myHeader.waveFormat.bitsPerSample == 24) {
|
||||
if (myHeader.waveFormat.channelCount == 1) {
|
||||
if (fileAccess.fRead(audioSample, 1, 3)!=3) {
|
||||
if (fileAccess.FileRead(audioSample, 1, 3)!=3) {
|
||||
EWOL_ERROR("Read Error at position : " << iii);
|
||||
return NULL;
|
||||
}
|
||||
left = CONVERT_INT24(littleEndien, audioSample);
|
||||
right = left;
|
||||
} else {
|
||||
if (fileAccess.fRead(audioSample, 1, 6)!=6) {
|
||||
if (fileAccess.FileRead(audioSample, 1, 6)!=6) {
|
||||
EWOL_ERROR("Read Error at position : " << iii);
|
||||
return NULL;
|
||||
}
|
||||
@ -280,14 +280,14 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
}
|
||||
} else if (myHeader.waveFormat.bitsPerSample == 32) {
|
||||
if (myHeader.waveFormat.channelCount == 1) {
|
||||
if (fileAccess.fRead(audioSample, 1, 4)!=4) {
|
||||
if (fileAccess.FileRead(audioSample, 1, 4)!=4) {
|
||||
EWOL_ERROR("Read Error at position : " << iii);
|
||||
return NULL;
|
||||
}
|
||||
left = CONVERT_INT32(littleEndien, audioSample);
|
||||
right = left;
|
||||
} else {
|
||||
if (fileAccess.fRead(audioSample, 1, 8)!=8) {
|
||||
if (fileAccess.FileRead(audioSample, 1, 8)!=8) {
|
||||
EWOL_ERROR("Read Error at position : " << iii);
|
||||
return NULL;
|
||||
}
|
||||
@ -303,7 +303,7 @@ int16_t * ewol::audio::wav::LoadData(etk::UString filename, int8_t nbChan, int32
|
||||
}
|
||||
}
|
||||
// close the file:
|
||||
fileAccess.fClose();
|
||||
fileAccess.FileClose();
|
||||
nbSampleOut = nbSample;
|
||||
return outputData;
|
||||
}
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <etk/UString.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <ewol/widget/Widget.h>
|
||||
#include <ewol/widget/Windows.h>
|
||||
|
||||
|
@ -27,7 +27,6 @@
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <draw/Image.h>
|
||||
#include <ewol/texture/Texture.h>
|
||||
#include <ewol/Resource.h>
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <etk/unicode.h>
|
||||
#include <etk/Vector.h>
|
||||
#include <ewol/font/FontFreeType.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
#include <ewol/openGL/openGL.h>
|
||||
extern "C" {
|
||||
@ -70,17 +71,17 @@ ewol::FontFreeType::FontFreeType(etk::UString fontName) :
|
||||
m_FileBuffer = NULL;
|
||||
m_FileSize = 0;
|
||||
|
||||
etk::File myfile(fontName, etk::FILE_TYPE_DATA);
|
||||
etk::FSNode myfile(etk::UString("DATA:") + fontName);
|
||||
if (false == myfile.Exist()) {
|
||||
EWOL_ERROR("File Does not exist : " << myfile);
|
||||
return;
|
||||
}
|
||||
m_FileSize = myfile.Size();
|
||||
m_FileSize = myfile.FileSize();
|
||||
if (0==m_FileSize) {
|
||||
EWOL_ERROR("This file is empty : " << myfile);
|
||||
return;
|
||||
}
|
||||
if (false == myfile.fOpenRead()) {
|
||||
if (false == myfile.FileOpenRead()) {
|
||||
EWOL_ERROR("Can not open the file : " << myfile);
|
||||
return;
|
||||
}
|
||||
@ -91,9 +92,9 @@ ewol::FontFreeType::FontFreeType(etk::UString fontName) :
|
||||
return;
|
||||
}
|
||||
// load data from the file :
|
||||
myfile.fRead(m_FileBuffer, 1, m_FileSize);
|
||||
myfile.FileRead(m_FileBuffer, 1, m_FileSize);
|
||||
// close the file:
|
||||
myfile.fClose();
|
||||
myfile.FileClose();
|
||||
// load Face ...
|
||||
int32_t error = FT_New_Memory_Face( library, m_FileBuffer, m_FileSize, 0, &m_fftFace );
|
||||
if( FT_Err_Unknown_File_Format == error) {
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
|
||||
#include <ewol/game/GameElementLua.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
/*******************************************************************************
|
||||
** Lua abstraction (START)
|
||||
@ -635,8 +636,8 @@ ewol::GameElementLua::GameElementLua(ewol::SceneElement & sceneElement, etk::USt
|
||||
{
|
||||
tmpObj = this;
|
||||
tmpScene = &m_sceneElement;
|
||||
etk::File fileElement(tmpName, etk::FILE_TYPE_DATA);
|
||||
etk::UString tmpCompleatName = fileElement.GetCompleateName();
|
||||
etk::FSNode fileElement(etk::UString("DATA:") + tmpName);
|
||||
etk::UString tmpCompleatName = fileElement.GetName();
|
||||
|
||||
// create state
|
||||
m_luaState = luaL_newstate();
|
||||
@ -653,12 +654,12 @@ ewol::GameElementLua::GameElementLua(ewol::SceneElement & sceneElement, etk::USt
|
||||
*myBool = false;
|
||||
*myValue = 18;
|
||||
*/
|
||||
int32_t fileSize = fileElement.Size();
|
||||
int32_t fileSize = fileElement.FileSize();
|
||||
if (0==fileSize) {
|
||||
EWOL_ERROR("This file is empty : " << fileElement);
|
||||
return;
|
||||
}
|
||||
if (false == fileElement.fOpenRead()) {
|
||||
if (false == fileElement.FileOpenRead()) {
|
||||
EWOL_ERROR("Can not open the file : " << fileElement);
|
||||
return;
|
||||
}
|
||||
@ -670,9 +671,9 @@ ewol::GameElementLua::GameElementLua(ewol::SceneElement & sceneElement, etk::USt
|
||||
}
|
||||
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
|
||||
// load data from the file :
|
||||
fileElement.fRead(fileBuffer, 1, fileSize);
|
||||
fileElement.FileRead(fileBuffer, 1, fileSize);
|
||||
// close the file:
|
||||
fileElement.fClose();
|
||||
fileElement.FileClose();
|
||||
|
||||
if (luaL_loadbuffer(m_luaState, fileBuffer, fileSize, tmpName.c_str())) {
|
||||
//if (luaL_loadfile(m_luaState, "/home/heero/dev/perso/TethysDefender/assets/elementGame/Cube.lua" ) ) {
|
||||
@ -918,7 +919,7 @@ static ewol::GameElement* LoadSceneElement_lua(ewol::SceneElement & sceneElement
|
||||
tmpName += elementName;
|
||||
tmpName += ".lua";
|
||||
// added a new element :
|
||||
etk::File fileElement(tmpName, etk::FILE_TYPE_DATA);
|
||||
etk::FSNode fileElement(etk::UString("DATA:") + tmpName);
|
||||
if (false == fileElement.Exist()) {
|
||||
EWOL_ERROR("Can not find Game element : " << elementName << " ==> " << tmpName);
|
||||
return NULL;
|
||||
|
@ -36,7 +36,7 @@ ewol::OObject2DColored::OObject2DColored(void)
|
||||
m_triElement = 0;
|
||||
SetColor(1.0, 1.0, 1.0, 1.0);
|
||||
#ifdef __VIDEO__OPENGL_ES_2
|
||||
etk::UString tmpString("color.prog");
|
||||
etk::UString tmpString("DATA:color.prog");
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
||||
|
@ -73,7 +73,7 @@ ewol::OObject2DTextColored::OObject2DTextColored(etk::UString fontName, int32_t
|
||||
m_color = draw::color::black;
|
||||
SetFontProperty(fontName, size);
|
||||
#ifdef __VIDEO__OPENGL_ES_2
|
||||
etk::UString tmpString("textured.prog");
|
||||
etk::UString tmpString("DATA:textured.prog");
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
||||
@ -93,7 +93,7 @@ ewol::OObject2DTextColored::OObject2DTextColored(void) :
|
||||
{
|
||||
m_color = draw::color::black;
|
||||
SetFontProperty(ewol::font::GetDefaultFont(), ewol::font::GetDefaultSize());
|
||||
etk::UString tmpString("textured.prog");
|
||||
etk::UString tmpString("DATA:textured.prog");
|
||||
#ifdef __VIDEO__OPENGL_ES_2
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
|
@ -79,7 +79,7 @@ ewol::OObject2DTextShader::OObject2DTextShader(etk::UString fontName, int32_t si
|
||||
{
|
||||
m_color = draw::color::black;
|
||||
SetFontProperty(fontName, size);
|
||||
etk::UString tmpString("fontDistanceField/font1.prog");
|
||||
etk::UString tmpString("DATA:fontDistanceField/font1.prog");
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
||||
@ -101,7 +101,7 @@ ewol::OObject2DTextShader::OObject2DTextShader(void) :
|
||||
{
|
||||
m_color = draw::color::black;
|
||||
SetFontProperty(ewol::font::GetDefaultFont(), ewol::font::GetDefaultSize());
|
||||
etk::UString tmpString("fontDistanceField/font1.prog");
|
||||
etk::UString tmpString("DATA:fontDistanceField/font1.prog");
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
||||
|
@ -39,7 +39,7 @@ ewol::OObject2DTextured::OObject2DTextured(etk::UString textureName, float sizeX
|
||||
}
|
||||
m_resource = resourceFile;
|
||||
#ifdef __VIDEO__OPENGL_ES_2
|
||||
etk::UString tmpString("textured.prog");
|
||||
etk::UString tmpString("DATA:textured.prog");
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
||||
@ -65,7 +65,7 @@ ewol::OObject2DTextured::OObject2DTextured( float sizeX, float sizeY)
|
||||
m_resource->Flush();
|
||||
}
|
||||
#ifdef __VIDEO__OPENGL_ES_2
|
||||
etk::UString tmpString("textured.prog");
|
||||
etk::UString tmpString("DATA:textured.prog");
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
||||
|
@ -27,7 +27,6 @@
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <draw/Color.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/font/Font.h>
|
||||
#include <etk/Vector.h>
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/openGL/Program.h>
|
||||
#include <ewol/ResourceManager.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
//#define LOCAL_DEBUG EWOL_VERBOSE
|
||||
#define LOCAL_DEBUG EWOL_DEBUG
|
||||
@ -42,35 +43,36 @@ ewol::Program::Program(etk::UString& filename) :
|
||||
EWOL_DEBUG("OGL : load PROGRAM \"" << filename << "\"");
|
||||
// load data from file "all the time ..."
|
||||
|
||||
etk::File file(m_name, etk::FILE_TYPE_DATA);
|
||||
etk::FSNode file(m_name);
|
||||
if (false == file.Exist()) {
|
||||
EWOL_ERROR("File does not Exist : \"" << file << "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
etk::UString fileExtention = file.GetExtention();
|
||||
etk::UString fileExtention = file.FileGetExtention();
|
||||
if (fileExtention != "prog") {
|
||||
EWOL_ERROR("File does not have extention \".prog\" for program but : \"" << fileExtention << "\"");
|
||||
return;
|
||||
}
|
||||
if (false == file.fOpenRead()) {
|
||||
if (false == file.FileOpenRead()) {
|
||||
EWOL_ERROR("Can not open the file : " << file);
|
||||
return;
|
||||
}
|
||||
#define MAX_LINE_SIZE (2048)
|
||||
char tmpData[MAX_LINE_SIZE];
|
||||
while (file.fGets(tmpData, MAX_LINE_SIZE) != NULL) {
|
||||
EWOL_DEBUG(" Read data : \"" << tmpData << "\"");
|
||||
while (file.FileGets(tmpData, MAX_LINE_SIZE) != NULL) {
|
||||
int32_t len = strlen(tmpData);
|
||||
if( tmpData[len-1] == '\n'
|
||||
|| tmpData[len-1] == '\r') {
|
||||
tmpData[len-1] = '\0';
|
||||
len--;
|
||||
}
|
||||
EWOL_DEBUG(" Read data : \"" << tmpData << "\"");
|
||||
if (len == 0) {
|
||||
continue;
|
||||
}
|
||||
etk::UString tmpFilename = tmpData;
|
||||
// get it with relative position :
|
||||
etk::UString tmpFilename = file.GetRelativeFolder() + tmpData;
|
||||
ewol::Shader* tmpShader = NULL;
|
||||
if (false == ewol::resource::Keep(tmpFilename, tmpShader)) {
|
||||
EWOL_CRITICAL("Error while getting a specific shader filename : " << tmpFilename);
|
||||
@ -81,7 +83,7 @@ ewol::Program::Program(etk::UString& filename) :
|
||||
|
||||
}
|
||||
// close the file:
|
||||
file.fClose();
|
||||
file.FileClose();
|
||||
|
||||
UpdateContext();
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#ifdef __VIDEO__OPENGL_ES_2
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/openGL/Shader.h>
|
||||
|
||||
@ -42,13 +42,13 @@ ewol::Shader::Shader(etk::UString& filename):
|
||||
EWOL_DEBUG("OGL : load SHADER \"" << filename << "\"");
|
||||
// load data from file "all the time ..."
|
||||
|
||||
etk::File file(m_name, etk::FILE_TYPE_DATA);
|
||||
etk::FSNode file(m_name);
|
||||
if (false == file.Exist()) {
|
||||
EWOL_ERROR("File does not Exist : \"" << file << "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
etk::UString fileExtention = file.GetExtention();
|
||||
etk::UString fileExtention = file.FileGetExtention();
|
||||
if (fileExtention == "frag") {
|
||||
m_type = GL_FRAGMENT_SHADER;
|
||||
} else if (fileExtention == "vert") {
|
||||
@ -137,18 +137,18 @@ void ewol::Shader::RemoveContextToLate(void)
|
||||
|
||||
void ewol::Shader::Reload(void)
|
||||
{
|
||||
etk::File file(m_name, etk::FILE_TYPE_DATA);
|
||||
etk::FSNode file(m_name);
|
||||
if (false == file.Exist()) {
|
||||
EWOL_ERROR("File does not Exist : \"" << file << "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t fileSize = file.Size();
|
||||
int32_t fileSize = file.FileSize();
|
||||
if (0==fileSize) {
|
||||
EWOL_ERROR("This file is empty : " << file);
|
||||
return;
|
||||
}
|
||||
if (false == file.fOpenRead()) {
|
||||
if (false == file.FileOpenRead()) {
|
||||
EWOL_ERROR("Can not open the file : " << file);
|
||||
return;
|
||||
}
|
||||
@ -165,9 +165,9 @@ void ewol::Shader::Reload(void)
|
||||
}
|
||||
memset(m_fileData, 0, (fileSize+5)*sizeof(char));
|
||||
// load data from the file :
|
||||
file.fRead(m_fileData, 1, fileSize);
|
||||
file.FileRead(m_fileData, 1, fileSize);
|
||||
// close the file:
|
||||
file.fClose();
|
||||
file.FileClose();
|
||||
|
||||
// now change the OGL context ...
|
||||
RemoveContext();
|
||||
|
@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/openGL/VirtualBufferObject.h>
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <ewol/ewol.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <etk/MessageFifo.h>
|
||||
|
@ -286,7 +286,7 @@ void guiInterface::SetTitle(etk::UString& title)
|
||||
Pixmap icon_pixmap;
|
||||
|
||||
// TODO : I don't understand why it does not work ....
|
||||
void SetIcon(etk::File bitmapFile)
|
||||
void SetIcon(etk::FSNode bitmapFile)
|
||||
{
|
||||
#ifdef DEBUG_X11_EVENT
|
||||
EWOL_INFO("X11: try to set icon : " << bitmapFile);
|
||||
@ -295,7 +295,7 @@ void SetIcon(etk::File bitmapFile)
|
||||
if (false == bitmapFile.Exist()) {
|
||||
EWOL_ERROR("X11 Icon File does not Exist ... " << bitmapFile);
|
||||
} else {
|
||||
etk::UString fileExtention = bitmapFile.GetExtention();
|
||||
etk::UString fileExtention = bitmapFile.FileGetExtention();
|
||||
if (fileExtention == "bmp") {
|
||||
// pointer to the WM hints structure.
|
||||
XWMHints* win_hints;
|
||||
@ -1175,7 +1175,7 @@ int main(int argc, char *argv[])
|
||||
//start the basic thread :
|
||||
eSystem::Init();
|
||||
// get the icon file :
|
||||
etk::File myIcon = APP_Icon();
|
||||
etk::FSNode myIcon = APP_Icon();
|
||||
SetIcon(myIcon);
|
||||
|
||||
// Run ...
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <ewol/widget/Windows.h>
|
||||
#include <ewol/ewol.h>
|
||||
#include <ewol/ClipBoard.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
|
||||
namespace guiInterface
|
||||
@ -105,9 +106,9 @@ namespace guiInterface
|
||||
|
||||
|
||||
//!< must be define in CPP by the application ... this are the main init and unInit of the Application
|
||||
void APP_Init(void);
|
||||
void APP_UnInit(void);
|
||||
etk::File APP_Icon(void);
|
||||
void APP_Init(void);
|
||||
void APP_UnInit(void);
|
||||
etk::FSNode APP_Icon(void);
|
||||
|
||||
#define NB_MAX_INPUT (20)
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <etk/Types.h>
|
||||
#include <draw/Image.h>
|
||||
#include <ewol/texture/TextureBMP.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
@ -63,7 +64,7 @@ typedef enum {
|
||||
#undef __class__
|
||||
#define __class__ "texture::TextureBMP"
|
||||
|
||||
void ewol::imageBMP::GenerateImage(etk::File & fileName, draw::Image & ouputImage)
|
||||
void ewol::imageBMP::GenerateImage(etk::FSNode & fileName, draw::Image & ouputImage)
|
||||
{
|
||||
modeBitmap_te m_dataMode = BITS_16_R5G6B5;
|
||||
int32_t m_width = 0;
|
||||
@ -76,35 +77,35 @@ void ewol::imageBMP::GenerateImage(etk::File & fileName, draw::Image & ouputImag
|
||||
EWOL_ERROR("not enought data in the file named=\"" << fileName << "\"");
|
||||
return;
|
||||
}*/
|
||||
if(false == fileName.fOpenRead() ) {
|
||||
if(false == fileName.FileOpenRead() ) {
|
||||
EWOL_ERROR("Can not find the file name=\"" << fileName << "\"");
|
||||
return;
|
||||
}
|
||||
// get the data :
|
||||
if (fileName.fRead(&m_FileHeader,sizeof(bitmapFileHeader_ts),1) != 1) {
|
||||
if (fileName.FileRead(&m_FileHeader,sizeof(bitmapFileHeader_ts),1) != 1) {
|
||||
EWOL_ERROR("error loading file header");
|
||||
fileName.fClose();
|
||||
fileName.FileClose();
|
||||
return;
|
||||
}
|
||||
if (fileName.fRead(&m_InfoHeader,sizeof(bitmapInfoHeader_ts),1) != 1) {
|
||||
if (fileName.FileRead(&m_InfoHeader,sizeof(bitmapInfoHeader_ts),1) != 1) {
|
||||
EWOL_ERROR("error loading file header");
|
||||
fileName.fClose();
|
||||
fileName.FileClose();
|
||||
return;
|
||||
}
|
||||
if(false == fileName.fSeek(m_FileHeader.bfOffBits, SEEK_SET)) {
|
||||
if(false == fileName.FileSeek(m_FileHeader.bfOffBits, SEEK_SET)) {
|
||||
EWOL_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\"");
|
||||
fileName.fClose();
|
||||
fileName.FileClose();
|
||||
return;
|
||||
}
|
||||
// Check the header error :
|
||||
if (m_FileHeader.bfType != 0x4D42) {
|
||||
EWOL_ERROR("the file=\"" << fileName << "\" is not a bitmap file ...");
|
||||
fileName.fClose();
|
||||
fileName.FileClose();
|
||||
return;
|
||||
}
|
||||
if (m_FileHeader.bfReserved != 0x00000000) {
|
||||
EWOL_ERROR("the bfReserved feald is not at 0 ==> not supported format ...");
|
||||
fileName.fClose();
|
||||
fileName.FileClose();
|
||||
return;
|
||||
}
|
||||
if( m_InfoHeader.biBitCount == 16
|
||||
@ -129,7 +130,7 @@ void ewol::imageBMP::GenerateImage(etk::File & fileName, draw::Image & ouputImag
|
||||
m_dataMode = BITS_32_A8R8G8B8;
|
||||
} else {
|
||||
EWOL_ERROR("the biBitCount & biCompression fealds are unknow ==> not supported format ...");
|
||||
fileName.fClose();;
|
||||
fileName.FileClose();;
|
||||
return;
|
||||
}
|
||||
m_width = m_InfoHeader.biWidth;
|
||||
@ -141,11 +142,11 @@ void ewol::imageBMP::GenerateImage(etk::File & fileName, draw::Image & ouputImag
|
||||
if(0 != m_InfoHeader.biSizeImage)
|
||||
{
|
||||
m_data=new uint8_t[m_InfoHeader.biSizeImage];
|
||||
if (fileName.fRead(m_data,m_InfoHeader.biSizeImage,1) != 1){
|
||||
if (fileName.FileRead(m_data,m_InfoHeader.biSizeImage,1) != 1){
|
||||
EWOL_CRITICAL("Can not read the file with the good size...");
|
||||
}
|
||||
}
|
||||
fileName.fClose();
|
||||
fileName.FileClose();
|
||||
|
||||
draw::Color tmpColor(0,0,0,0);
|
||||
|
||||
|
@ -27,14 +27,14 @@
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <draw/Image.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
namespace imageBMP
|
||||
{
|
||||
void GenerateImage(etk::File & fileName, draw::Image & ouputImage);
|
||||
void GenerateImage(etk::FSNode & fileName, draw::Image & ouputImage);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <ewol/texture/TextureFile.h>
|
||||
#include <ewol/texture/Texture.h>
|
||||
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
#include <ewol/texture/TextureBMP.h>
|
||||
#include <parserSVG/parserSVG.h>
|
||||
@ -36,7 +37,7 @@ ewol::TextureFile::TextureFile(etk::UString genName, etk::UString tmpfileName, e
|
||||
Texture(genName)
|
||||
{
|
||||
// load data
|
||||
etk::File fileName(tmpfileName, etk::FILE_TYPE_DATA);
|
||||
etk::FSNode fileName(etk::UString("DATA:") + tmpfileName);
|
||||
if (false == fileName.Exist()) {
|
||||
EWOL_ERROR("File does not Exist ... " << fileName << " from : " << tmpfileName);
|
||||
} else {
|
||||
@ -45,14 +46,14 @@ ewol::TextureFile::TextureFile(etk::UString genName, etk::UString tmpfileName, e
|
||||
SetImageSize(size);
|
||||
}
|
||||
|
||||
etk::UString fileExtention = fileName.GetExtention();
|
||||
etk::UString fileExtention = fileName.FileGetExtention();
|
||||
if (fileExtention == "bmp") {
|
||||
// generate the texture
|
||||
ewol::imageBMP::GenerateImage(fileName, m_data);
|
||||
} else if (fileExtention == "svg") {
|
||||
svg::Parser m_element(fileName);
|
||||
if (false == m_element.IsLoadOk()) {
|
||||
EWOL_ERROR("Error To load SVG file " << fileName.GetCompleateName() );
|
||||
EWOL_ERROR("Error To load SVG file " << fileName );
|
||||
} else {
|
||||
// generate the texture
|
||||
m_element.GenerateAnImage(size, m_data);
|
||||
|
@ -25,17 +25,18 @@
|
||||
|
||||
|
||||
#include <ewol/texture/TextureSVG.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "texture::TextureSVG"
|
||||
|
||||
|
||||
ewol::texture::TextureSVG::TextureSVG(etk::File & fileName, int32_t width, int32_t height) : m_elementParsed(fileName)
|
||||
ewol::texture::TextureSVG::TextureSVG(etk::FSNode & fileName, int32_t width, int32_t height) : m_elementParsed(fileName)
|
||||
{
|
||||
m_loadOK = false;
|
||||
if (false == m_elementParsed.IsLoadOk()) {
|
||||
EWOL_ERROR("Error To load SVG file " << fileName.GetCompleateName() );
|
||||
EWOL_ERROR("Error To load SVG file " << fileName );
|
||||
} else {
|
||||
m_elementParsed.GenerateAnImage(width, height);
|
||||
m_loadOK = true;
|
||||
|
@ -27,7 +27,6 @@
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <etk/os/File.h>
|
||||
#include <parserSVG/parserSVG.h>
|
||||
|
||||
namespace ewol
|
||||
@ -43,7 +42,7 @@ namespace ewol
|
||||
uint8_t * m_data;
|
||||
bool m_loadOK;
|
||||
public:
|
||||
TextureSVG(etk::File & fileName, int32_t width, int32_t height);
|
||||
TextureSVG(etk::FSNode & fileName, int32_t width, int32_t height);
|
||||
~TextureSVG(void);
|
||||
bool LoadOK(void);
|
||||
int32_t Width(void);
|
||||
|
@ -69,7 +69,7 @@ void ewol::Entry::Init(void)
|
||||
ShortCutAdd("ctrl+a", ewolEventEntrySelect, "ALL");
|
||||
ShortCutAdd("ctrl+shift+a", ewolEventEntrySelect, "NONE");
|
||||
#ifdef __VIDEO__OPENGL_ES_2
|
||||
etk::UString tmpString("widgetEntry.prog");
|
||||
etk::UString tmpString("THEME:rounded:widgetEntry.prog");
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
||||
|
@ -25,6 +25,9 @@
|
||||
#include <ewol/widget/ListFileSystem.h>
|
||||
#include <etk/tool.h>
|
||||
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
// TODO : Remove the link with this at this level of abstraction ...
|
||||
extern "C" {
|
||||
// file browsing ...
|
||||
#include <dirent.h>
|
||||
|
@ -32,6 +32,7 @@
|
||||
//#include <etk/Vector.h>
|
||||
#include <etk/Vector.h>
|
||||
#include <etk/tool.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
extern "C" {
|
||||
// file browsing ...
|
||||
|
@ -101,12 +101,12 @@ LOCAL_COPY_FILES := ../../share/textured3D.prog:textured3D.prog \
|
||||
../../share/textured.prog:textured.prog \
|
||||
../../share/textured.frag:textured.frag \
|
||||
../../share/textured.vert:textured.vert \
|
||||
|
||||
|
||||
|
||||
LOCAL_PLOPPPPPPP := \
|
||||
\
|
||||
../../share/widgetEntry.prog:widgetEntry.prog \
|
||||
../../share/widgetEntry.frag:widgetEntry.frag \
|
||||
../../share/widgetEntry.vert:widgetEntry.vert
|
||||
../../share/theme/default/widgetEntry.prog:theme/default/widgetEntry.prog \
|
||||
../../share/theme/default/widgetEntry.frag:theme/default/widgetEntry.frag \
|
||||
../../share/theme/default/widgetEntry.vert:theme/default/widgetEntry.vert \
|
||||
\
|
||||
../../share/theme/rounded/widgetEntry.prog:theme/rounded/widgetEntry.prog \
|
||||
../../share/theme/rounded/widgetEntry.frag:theme/rounded/widgetEntry.frag \
|
||||
../../share/theme/rounded/widgetEntry.vert:theme/rounded/widgetEntry.vert
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user