From c44642ba108cdd2a53378a564c614a4817bbc2f9 Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Fri, 31 Aug 2012 01:29:30 +0200 Subject: [PATCH] work on the Windows fileSystem abstraction, file shoser corection of init and Windows gui is cut corectly --- Sources/libetk/etk/File.cpp | 92 ++++++++----------- Sources/libetk/etk/Stream.h | 24 +++-- Sources/libetk/etk/tool.cpp | 67 ++++++++++++++ Sources/libetk/etk/tool.h | 1 + Sources/libewol/ewol/os/gui.Windows.cpp | 15 ++- .../libewol/ewol/widget/ListFileSystem.cpp | 13 ++- .../libewol/ewol/widget/meta/FileChooser.cpp | 50 +++------- 7 files changed, 160 insertions(+), 102 deletions(-) diff --git a/Sources/libetk/etk/File.cpp b/Sources/libetk/etk/File.cpp index 231200ee..3385525e 100644 --- a/Sources/libetk/etk/File.cpp +++ b/Sources/libetk/etk/File.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef __TARGET_OS__Android # include @@ -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('/'); diff --git a/Sources/libetk/etk/Stream.h b/Sources/libetk/etk/Stream.h index 1a223528..d76d3e2a 100644 --- a/Sources/libetk/etk/Stream.h +++ b/Sources/libetk/etk/Stream.h @@ -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: diff --git a/Sources/libetk/etk/tool.cpp b/Sources/libetk/etk/tool.cpp index 9b90355e..4ecdaff6 100644 --- a/Sources/libetk/etk/tool.cpp +++ b/Sources/libetk/etk/tool.cpp @@ -23,9 +23,12 @@ */ #include +#include // for the rand ... #include #include +#include +#include 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()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; +} + diff --git a/Sources/libetk/etk/tool.h b/Sources/libetk/etk/tool.h index 3e0931c9..daac969e 100644 --- a/Sources/libetk/etk/tool.h +++ b/Sources/libetk/etk/tool.h @@ -34,6 +34,7 @@ namespace etk { int32_t irand(int32_t a, int32_t b); void SortList(etk::Vector &m_listDirectory); bool strnCmpNoCase(const char * input1, const char * input2, int32_t maxLen); + etk::UString SimplifyPath(etk::UString input); }; }; diff --git a/Sources/libewol/ewol/os/gui.Windows.cpp b/Sources/libewol/ewol/os/gui.Windows.cpp index 7c53ab35..b8ebe811 100644 --- a/Sources/libewol/ewol/os/gui.Windows.cpp +++ b/Sources/libewol/ewol/os/gui.Windows.cpp @@ -108,6 +108,11 @@ void guiInterface::KeyboardHide(void) */ void guiInterface::ChangeSize(Vector2D 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; diff --git a/Sources/libewol/ewol/widget/ListFileSystem.cpp b/Sources/libewol/ewol/widget/ListFileSystem.cpp index 9af770f7..5e8d2874 100644 --- a/Sources/libewol/ewol/widget/ListFileSystem.cpp +++ b/Sources/libewol/ewol/widget/ListFileSystem.cpp @@ -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); diff --git a/Sources/libewol/ewol/widget/meta/FileChooser.cpp b/Sources/libewol/ewol/widget/meta/FileChooser.cpp index ac836626..fe226bfb 100644 --- a/Sources/libewol/ewol/widget/meta/FileChooser.cpp +++ b/Sources/libewol/ewol/widget/meta/FileChooser.cpp @@ -31,6 +31,7 @@ #include //#include #include +#include 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); }