work on the Windows fileSystem abstraction, file shoser corection of init and Windows gui is cut corectly

This commit is contained in:
Edouard Dupin 2012-08-31 01:29:30 +02:00
parent 6c15f2b86c
commit c44642ba10
7 changed files with 160 additions and 102 deletions

View File

@ -28,6 +28,7 @@
#include <etk/File.h>
#include <unistd.h>
#include <stdlib.h>
#include <etk/tool.h>
#ifdef __TARGET_OS__Android
# include <stdio.h>
@ -37,11 +38,16 @@
// zip file of the apk file for Android ==> set to zip file apk access
static etk::UString s_fileAPK = "";
etk::UString baseApplName = "ewolNoName";
#ifdef __TARGET_OS__Android
etk::UString baseFolderHome = "/sdcard/"; // home folder
etk::UString baseFolderData = "assets/"; // program Data
#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
@ -109,7 +115,11 @@ void etk::InitDefaultFolder(const char * applName)
char * basicPath = getenv("HOME");
if (NULL == basicPath) {
TK_ERROR("ERROR while trying to get the path of the home folder");
baseFolderHome = "~";
#if defined(__TARGET_OS__Windows)
baseFolderHome = "c:/";
#else
baseFolderHome = "~";
#endif
} else {
baseFolderHome = basicPath;
}
@ -284,15 +294,12 @@ bool etk::File::operator!= (const etk::File &etkF) const
void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te type)
{
char buf[MAX_FILE_NAME];
memset(buf, 0, MAX_FILE_NAME);
char * ok;
#ifdef __TARGET_OS__Android
m_idZipFile = -1;
m_zipData = NULL;
m_zipDataSize = 0;
m_zipReadingOffset = 0;
//m_zipPointerFile = NULL;
m_idZipFile = -1;
m_zipData = NULL;
m_zipDataSize = 0;
m_zipReadingOffset = 0;
//m_zipPointerFile = NULL;
#endif
// Reset ALL DATA :
m_folder = "";
@ -305,8 +312,14 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
} else {
destFilename = newFilename;
}
TK_VERBOSE("2 : Get file Name : " << destFilename << "start with '/'=" << destFilename.StartWith('/'));
if (true == destFilename.StartWith('/')) {
#ifdef __TARGET_OS__Windows
TK_VERBOSE("2 : Get file Name : " << destFilename << "start with 'c:/'=" << destFilename.StartWith("c:/"));
if (true == destFilename.StartWith("c:/")) {
#else
TK_VERBOSE("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_VERBOSE("Incompatible type with a file=\"" << newFilename << "\" ==> force it in direct mode ...");
@ -399,48 +412,17 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
TK_VERBOSE("3 : Get file Name : " << destFilename );
if (true == needUnpack) {
// Get the real Path of the current File
#ifdef __TARGET_OS__Windows
ok = 0;
#else
ok = realpath(destFilename.c_str(), buf);
#endif
if (!ok) {
int32_t lastPos = destFilename.FindBack('/');
if (-1 != lastPos) {
// Get the FileName
etk::UString tmpFilename = destFilename.Extract(lastPos+1);
destFilename.Remove(lastPos, destFilename.Size() - lastPos);
TK_VERBOSE("try to find :\"" << destFilename << "\" / \"" << tmpFilename << "\" ");
#ifdef __TARGET_OS__Windows
ok = 0;
#else
ok = realpath(destFilename.c_str(), buf);
#endif
if (!ok) {
TK_VERBOSE("Can not find real Path name of \"" << destFilename << "\"");
m_shortFilename = tmpFilename;
m_folder = destFilename;
} else {
// ALL is OK ...
m_shortFilename = tmpFilename;
m_folder = destFilename;
}
} else {
TK_VERBOSE("file : \"" << destFilename << "\" ==> No data???");
// Basic ERROR ...
m_shortFilename = destFilename;
}
destFilename = etk::tool::SimplifyPath(destFilename);
int32_t lastPos = destFilename.FindBack('/');
if (-1 != lastPos) {
m_shortFilename = destFilename.Extract(lastPos+1);
m_folder = destFilename.Extract(0, lastPos);
} else {
destFilename = buf;
int32_t lastPos = destFilename.FindBack('/');
if (-1 != lastPos) {
m_shortFilename = destFilename.Extract(lastPos+1);
m_folder = destFilename.Extract(0, lastPos);
} else {
// Basic ERROR ...
TK_VERBOSE("file : \"" << destFilename << "\" ==> No data???");
m_shortFilename = destFilename;
}
// Basic ERROR ...
TK_VERBOSE("file : \"" << destFilename << "\" ==> No data???");
m_shortFilename = destFilename;
m_folder = "";
}
} else {
int32_t lastPos = destFilename.FindBack('/');

View File

@ -227,27 +227,39 @@ namespace etk{
switch (ccc)
{
case LOG_LEVEL_CRITICAL:
strncat(m_tmpChar, ETK_BASH_COLOR_BOLD_RED, MAX_LOG_SIZE);
#if !defined(__TARGET_OS__Windows)
strncat(m_tmpChar, ETK_BASH_COLOR_BOLD_RED, MAX_LOG_SIZE);
#endif
strncat(m_tmpChar, "[C]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_ERROR:
strncat(m_tmpChar, ETK_BASH_COLOR_MAGENTA, MAX_LOG_SIZE);
#if !defined(__TARGET_OS__Windows)
strncat(m_tmpChar, ETK_BASH_COLOR_MAGENTA, MAX_LOG_SIZE);
#endif
strncat(m_tmpChar, "[E]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_WARNING:
strncat(m_tmpChar, ETK_BASH_COLOR_BOLD_RED, MAX_LOG_SIZE);
#if !defined(__TARGET_OS__Windows)
strncat(m_tmpChar, ETK_BASH_COLOR_BOLD_RED, MAX_LOG_SIZE);
#endif
strncat(m_tmpChar, "[W]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_INFO:
strncat(m_tmpChar, ETK_BASH_COLOR_CYAN, MAX_LOG_SIZE);
#if !defined(__TARGET_OS__Windows)
strncat(m_tmpChar, ETK_BASH_COLOR_CYAN, MAX_LOG_SIZE);
#endif
strncat(m_tmpChar, "[I]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_DEBUG:
strncat(m_tmpChar, ETK_BASH_COLOR_YELLOW, MAX_LOG_SIZE);
#if !defined(__TARGET_OS__Windows)
strncat(m_tmpChar, ETK_BASH_COLOR_YELLOW, MAX_LOG_SIZE);
#endif
strncat(m_tmpChar, "[D]", MAX_LOG_SIZE);
break;
case LOG_LEVEL_VERBOSE:
strncat(m_tmpChar, ETK_BASH_COLOR_WHITE, MAX_LOG_SIZE);
#if !defined(__TARGET_OS__Windows)
strncat(m_tmpChar, ETK_BASH_COLOR_WHITE, MAX_LOG_SIZE);
#endif
strncat(m_tmpChar, "[V]", MAX_LOG_SIZE);
break;
default:

View File

@ -23,9 +23,12 @@
*/
#include <etk/tool.h>
#include <etk/File.h>
// for the rand ...
#include <time.h>
#include <math.h>
#include <unistd.h>
#include <stdlib.h>
float etk::tool::frand(float a, float b)
{
@ -82,3 +85,67 @@ bool etk::tool::strnCmpNoCase(const char * input1, const char * input2, int32_t
return true;
}
etk::UString etk::tool::SimplifyPath(etk::UString input)
{
int32_t findStartPos = input.FindForward('/') + 1;
int32_t findPos = input.FindForward('/', findStartPos);
//TK_DEBUG("Siplify : \"" << input << "\"");
int32_t preventBadCode = 0;
while (findPos!=-1)
{
//TK_DEBUG(" string=\"" << input << "\"");
//TK_DEBUG(" '/' @" << findPos);
if (input.Size()<findPos+1) {
// no more element ...
break;
}
if( input[findPos+1] == '/'
|| ( input[findPos+1] == '.'
&& input.Size()==findPos+2 )) {
// cleane the element path
input.Remove(findPos+1, 1);
//TK_DEBUG(" Remove // string=\"" << input << "\"");
} else {
if (input.Size()<findPos+2) {
// no more element ...
break;
}
if( input[findPos+1] == '.'
&& input[findPos+2] == '.') {
// cleane the element path
input.Remove(findStartPos, findPos+3 - findStartPos );
//TK_DEBUG(" Remove xxx/.. string=\"" << input << "\"");
} else if( input[findPos+1] == '.'
&& input[findPos+2] == '/') {
// cleane the element path
input.Remove(findPos+1, 2);
//TK_DEBUG(" Remove ./ string=\"" << input << "\"");
} else {
findStartPos = findPos+1;
}
}
findPos = input.FindForward('/', findStartPos);
preventBadCode++;
if (preventBadCode>5000) {
TK_CRITICAL("ERROR when getting the small path ... this is loop prevention...");
break;
}
}
#ifndef __TARGET_OS__Windows
// for the target that supported the Realpath system :
char buf[MAX_FILE_NAME];
memset(buf, 0, MAX_FILE_NAME);
char * ok = realpath(input.c_str(), buf);
if (!ok) {
TK_ERROR("Error to get the real path");
input = "/";
} else {
input = buf;
}
#endif
//TK_DEBUG(" ==> \"" << input << "\"");
return input;
}

View File

@ -34,6 +34,7 @@ namespace etk {
int32_t irand(int32_t a, int32_t b);
void SortList(etk::Vector<etk::UString *> &m_listDirectory);
bool strnCmpNoCase(const char * input1, const char * input2, int32_t maxLen);
etk::UString SimplifyPath(etk::UString input);
};
};

View File

@ -108,6 +108,11 @@ void guiInterface::KeyboardHide(void)
*/
void guiInterface::ChangeSize(Vector2D<int32_t> size)
{
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
int title_size = GetSystemMetrics(SM_CYCAPTION);
size.x += border_thickness*2;
size.y += border_thickness*2 + title_size;
// TODO : Later
}
@ -300,8 +305,9 @@ int Windows_Run(void)
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE | WS_SIZEBOX,
0, 0, 800, 600,
NULL, NULL, hInstance, NULL );
eSystem::Resize(800, 600-25);
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
int title_size = GetSystemMetrics(SM_CYCAPTION);
eSystem::Resize(800-2*border_thickness, 600-2*border_thickness -title_size);
// enable OpenGL for the window
EnableOpenGL( hWnd, &hDC, &hRC );
@ -380,7 +386,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
WINDOWPOS* tmpVal = (WINDOWPOS*)lParam;
if (NULL != tmpVal) {
//EWOL_DEBUG("WM_WINDOWPOSCHANGING : : (" << tmpVal->x << "," << tmpVal->y << ") ( " << tmpVal->cx << "," << tmpVal->cy << ")");
eSystem::Resize(tmpVal->cx-8, tmpVal->cy - 28);
// in windows system, we need to remove the size of the border elements :
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
int title_size = GetSystemMetrics(SM_CYCAPTION);
eSystem::Resize(tmpVal->cx-2*border_thickness, tmpVal->cy - 2*border_thickness - title_size);
}
}
return 0;

View File

@ -68,7 +68,11 @@ ewol::ListFileSystem::ListFileSystem(void)
m_showTemporaryFile = true;
m_showHidden = true;
m_showFolder = true;
m_folder = "/";
#if defined(__TARGET_OS__Windows)
m_folder = "c:/";
#else
m_folder = "/";
#endif
AddEventId(ewolEventFSFileSelect);
AddEventId(ewolEventFSFileValidate);
AddEventId(ewolEventFSFolderSelect);
@ -123,7 +127,12 @@ void ewol::ListFileSystem::RegenerateView(void)
}
tmpEmement = NULL;
// the ".." permit to show the upper folder (but not availlable for the "/" folder
if (m_folder != "/") {
#if defined(__TARGET_OS__Windows)
if (m_folder != "c:/") {
#else
if (m_folder != "/") {
#endif
tmpEmement = new ewol::elementFS("..", ewol::EFS_FOLDER);
if (NULL != tmpEmement) {
m_list.PushBack(tmpEmement);

View File

@ -31,6 +31,7 @@
#include <ewol/widget/WidgetManager.h>
//#include <etk/Vector.h>
#include <etk/Vector.h>
#include <etk/tool.h>
extern "C" {
// file browsing ...
@ -81,9 +82,12 @@ ewol::FileChooser::FileChooser(void)
ewol::Spacer * mySpacer = NULL;
//ewol::Label * myLabel = NULL;
ewol::Image * myImage = NULL;
#ifdef __TARGET_OS__Android
#if defined(__TARGET_OS__Android)
m_folder = "/mnt/sdcard/";
SetDisplayRatio(0.90);
#elif defined(__TARGET_OS__Windows)
m_folder = "c:/";
SetDisplayRatio(0.80);
#else
m_folder = "/home/";
SetDisplayRatio(0.80);
@ -347,26 +351,10 @@ void ewol::FileChooser::OnReceiveMessage(ewol::EObject * CallerObject, const cha
}
} else if (ewolEventFileChooserListFolder == eventId) {
//==> this is an internal event ...
EWOL_VERBOSE(" old PATH : \"" << m_folder << "\" + \"" << data << "\"");
EWOL_DEBUG(" old PATH : \"" << m_folder << "\" + \"" << data << "\"");
m_folder = m_folder + data;
char buf[MAX_FILE_NAME];
memset(buf, 0, MAX_FILE_NAME);
char * ok;
EWOL_DEBUG("new PATH : \"" << m_folder << "\"");
#ifdef __TARGET_OS__Windows
ok = 0;
#else
ok = realpath(m_folder.c_str(), buf);
#endif
if (!ok) {
EWOL_ERROR("Error to get the real path");
m_folder = "/";
} else {
m_folder = buf;
}
if (m_folder != "/" ) {
m_folder += "/";
}
m_folder = etk::tool::SimplifyPath(m_folder);
SetFileName("");
UpdateCurrentFolder();
} else if (ewolEventFileChooserListFile == eventId) {
@ -385,25 +373,10 @@ void ewol::FileChooser::OnReceiveMessage(ewol::EObject * CallerObject, const cha
AutoDestroy();
} else if(ewolEventFileChooserHome == eventId) {
etk::UString tmpUserFolder = etk::GetUserHomeFolder();
char buf[MAX_FILE_NAME];
memset(buf, 0, MAX_FILE_NAME);
char * ok;
EWOL_DEBUG("new PATH : \"" << tmpUserFolder << "\"");
#ifdef __TARGET_OS__Windows
ok = 0;
#else
ok = realpath(tmpUserFolder.c_str(), buf);
#endif
if (!ok) {
EWOL_ERROR("Error to get the real path");
m_folder = "/";
} else {
m_folder = buf;
}
if (m_folder != "/" ) {
m_folder += "/";
}
m_folder = etk::tool::SimplifyPath(tmpUserFolder);
SetFileName("");
UpdateCurrentFolder();
}
@ -414,6 +387,11 @@ void ewol::FileChooser::OnReceiveMessage(ewol::EObject * CallerObject, const cha
void ewol::FileChooser::UpdateCurrentFolder(void)
{
if (m_folder != "" ) {
if (m_folder[m_folder.Size()-1] != '/') {
m_folder += "/";
}
}
if (NULL != m_widgetListFile) {
m_widgetListFile->SetFolder(m_folder);
}