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 <etk/File.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <etk/tool.h>
#ifdef __TARGET_OS__Android #ifdef __TARGET_OS__Android
# include <stdio.h> # include <stdio.h>
@ -37,11 +38,16 @@
// zip file of the apk file for Android ==> set to zip file apk access // zip file of the apk file for Android ==> set to zip file apk access
static etk::UString s_fileAPK = ""; static etk::UString s_fileAPK = "";
etk::UString baseApplName = "ewolNoName"; etk::UString baseApplName = "ewolNoName";
#ifdef __TARGET_OS__Android #if defined(__TARGET_OS__Android)
etk::UString baseFolderHome = "/sdcard/"; // home folder etk::UString baseFolderHome = "/sdcard/"; // home folder
etk::UString baseFolderData = "assets/"; // program Data etk::UString baseFolderData = "assets/"; // program Data
etk::UString baseFolderDataUser = "/sdcard/.tmp/userData/"; // Data specific user (local modification) 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) 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 #else
etk::UString baseFolderHome = "~"; // home folder etk::UString baseFolderHome = "~"; // home folder
etk::UString baseFolderData = "share/"; // program Data etk::UString baseFolderData = "share/"; // program Data
@ -109,7 +115,11 @@ void etk::InitDefaultFolder(const char * applName)
char * basicPath = getenv("HOME"); char * basicPath = getenv("HOME");
if (NULL == basicPath) { if (NULL == basicPath) {
TK_ERROR("ERROR while trying to get the path of the home folder"); TK_ERROR("ERROR while trying to get the path of the home folder");
#if defined(__TARGET_OS__Windows)
baseFolderHome = "c:/";
#else
baseFolderHome = "~"; baseFolderHome = "~";
#endif
} else { } else {
baseFolderHome = basicPath; baseFolderHome = basicPath;
} }
@ -284,9 +294,6 @@ bool etk::File::operator!= (const etk::File &etkF) const
void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te type) 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 #ifdef __TARGET_OS__Android
m_idZipFile = -1; m_idZipFile = -1;
m_zipData = NULL; m_zipData = NULL;
@ -305,8 +312,14 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
} else { } else {
destFilename = newFilename; destFilename = newFilename;
} }
#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('/')); TK_VERBOSE("2 : Get file Name : " << destFilename << "start with '/'=" << destFilename.StartWith('/'));
if (true == destFilename.StartWith('/')) { if (true == destFilename.StartWith('/')) {
#endif
m_type = etk::FILE_TYPE_DIRECT; m_type = etk::FILE_TYPE_DIRECT;
if (type != etk::FILE_TYPE_DIRECT) { if (type != etk::FILE_TYPE_DIRECT) {
TK_VERBOSE("Incompatible type with a file=\"" << newFilename << "\" ==> force it in direct mode ..."); TK_VERBOSE("Incompatible type with a file=\"" << newFilename << "\" ==> force it in direct mode ...");
@ -399,39 +412,8 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
TK_VERBOSE("3 : Get file Name : " << destFilename ); TK_VERBOSE("3 : Get file Name : " << destFilename );
if (true == needUnpack) { if (true == needUnpack) {
// Get the real Path of the current File // Get the real Path of the current File
#ifdef __TARGET_OS__Windows destFilename = etk::tool::SimplifyPath(destFilename);
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;
}
} else {
destFilename = buf;
int32_t lastPos = destFilename.FindBack('/'); int32_t lastPos = destFilename.FindBack('/');
if (-1 != lastPos) { if (-1 != lastPos) {
m_shortFilename = destFilename.Extract(lastPos+1); m_shortFilename = destFilename.Extract(lastPos+1);
@ -440,7 +422,7 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
// Basic ERROR ... // Basic ERROR ...
TK_VERBOSE("file : \"" << destFilename << "\" ==> No data???"); TK_VERBOSE("file : \"" << destFilename << "\" ==> No data???");
m_shortFilename = destFilename; m_shortFilename = destFilename;
} m_folder = "";
} }
} else { } else {
int32_t lastPos = destFilename.FindBack('/'); int32_t lastPos = destFilename.FindBack('/');

View File

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

View File

@ -23,9 +23,12 @@
*/ */
#include <etk/tool.h> #include <etk/tool.h>
#include <etk/File.h>
// for the rand ... // for the rand ...
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include <unistd.h>
#include <stdlib.h>
float etk::tool::frand(float a, float b) 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; 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); int32_t irand(int32_t a, int32_t b);
void SortList(etk::Vector<etk::UString *> &m_listDirectory); void SortList(etk::Vector<etk::UString *> &m_listDirectory);
bool strnCmpNoCase(const char * input1, const char * input2, int32_t maxLen); 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) 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 // TODO : Later
} }
@ -300,8 +305,9 @@ int Windows_Run(void)
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE | WS_SIZEBOX, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE | WS_SIZEBOX,
0, 0, 800, 600, 0, 0, 800, 600,
NULL, NULL, hInstance, NULL ); NULL, NULL, hInstance, NULL );
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
eSystem::Resize(800, 600-25); int title_size = GetSystemMetrics(SM_CYCAPTION);
eSystem::Resize(800-2*border_thickness, 600-2*border_thickness -title_size);
// enable OpenGL for the window // enable OpenGL for the window
EnableOpenGL( hWnd, &hDC, &hRC ); EnableOpenGL( hWnd, &hDC, &hRC );
@ -380,7 +386,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
WINDOWPOS* tmpVal = (WINDOWPOS*)lParam; WINDOWPOS* tmpVal = (WINDOWPOS*)lParam;
if (NULL != tmpVal) { if (NULL != tmpVal) {
//EWOL_DEBUG("WM_WINDOWPOSCHANGING : : (" << tmpVal->x << "," << tmpVal->y << ") ( " << tmpVal->cx << "," << tmpVal->cy << ")"); //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; return 0;

View File

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

View File

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