From 179e754078c15a76d7049d39d229c3752ac161ef Mon Sep 17 00:00:00 2001 From: koldo Date: Fri, 11 Nov 2016 22:16:33 +0000 Subject: [PATCH] Functions4U: Some improvements and fixes. git-svn-id: svn://ultimatepp.org/upp/trunk@10408 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/Functions4U/Functions4U.cpp | 85 ++++---------------------- bazaar/Functions4U/Functions4U.h | 5 +- bazaar/Functions4U/Functions4U_Gui.cpp | 9 +++ bazaar/Functions4U/Functions4U_Gui.h | 1 + 4 files changed, 26 insertions(+), 74 deletions(-) diff --git a/bazaar/Functions4U/Functions4U.cpp b/bazaar/Functions4U/Functions4U.cpp index cdfd7f4cd..c86afe769 100644 --- a/bazaar/Functions4U/Functions4U.cpp +++ b/bazaar/Functions4U/Functions4U.cpp @@ -1046,11 +1046,11 @@ String Tokenize2(const String &str, const String &token, int &pos) { pos = Null; return Null; } - int npos; - for (int i = 0; i < token.GetCount(); ++i) { + int npos = str.Find(token, pos); +/* for (int i = 0; i < token.GetCount(); ++i) { if ((npos = str.Find(token[i], pos)) >= 0) break; - } + }*/ int oldpos = pos; if (npos < 0) { pos = Null; @@ -1086,28 +1086,7 @@ void Tokenize(const String &str, const String &token, Vector &ret, int p ret << strRet; } } -/* -String Tokenize(const String &str, const String &token, int &pos) { - int npos; - for (int i = 0; i < token.GetCount(); ++i) { - if ((npos = str.Find(token[i], pos)) >= 0) - break; - } - int oldpos = pos; - if (npos < 0) { - pos = str.GetCount(); - return str.Mid(oldpos); - } else { - pos = npos + 1; - return str.Mid(oldpos, npos-oldpos); - } -} -String Tokenize(const String &str, const String &token) { - int dummy = 0; - return Tokenize(str, token, dummy); -} -*/ String GetLine(const String &str, int &pos) { String ret; int npos = str.Find("\n", pos); @@ -1426,47 +1405,7 @@ String FileRealName(const char *_fileName) { #undef CY #endif -/* -bool GetSymLinkPath(const char *linkPath, String &filePath) -{ -#ifdef PLATFORM_WIN32 - HRESULT hres; - IShellLink* psl; - IPersistFile* ppf; - CoInitialize(NULL); - hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, - (PVOID *) &psl); - if(SUCCEEDED(hres)) { - hres = psl->QueryInterface(IID_IPersistFile, (PVOID *) &ppf); - if(SUCCEEDED(hres)) { - hres = ppf->Load(ToSystemCharsetW(linkPath), STGM_READ); - if(SUCCEEDED(hres)) { - char fileW[_MAX_PATH] = {0}; - psl->GetPath(fileW, _MAX_PATH, NULL, 0); - filePath = FromSystemCharset(fileW); - } else - return false; - ppf->Release(); - } else - return false; - psl->Release(); - } else - return false; - CoUninitialize(); - return true; -#else - char buff[_MAX_PATH + 1]; - bool ret; - int len = readlink(linkPath, buff, _MAX_PATH); - if (ret = (len > 0 && len < _MAX_PATH)) - buff[len] = '\0'; - else - *buff = '\0'; - filePath = buff; - return ret; -#endif -} -*/ + bool IsSymLink(const char *path) { #if defined(PLATFORM_WIN32) || defined (PLATFORM_WIN64) return GetFileExt(path) == ".lnk"; @@ -1611,7 +1550,7 @@ bool RenameDeepWildcardsX(const char *path, const char *namewc, const char *newn return true; } -bool DirectoryCopy_Each(const char *dir, const char *newPlace, String relPath, bool replaceOnlyNew) +bool DirectoryCopy_Each(const char *dir, const char *newPlace, String relPath, bool replaceOnlyNew, String filesToExclude) { String dirPath = AppendFileName(dir, relPath); String newPath = AppendFileName(newPlace, relPath); @@ -1622,17 +1561,19 @@ bool DirectoryCopy_Each(const char *dir, const char *newPlace, String relPath, b bool copy = !replaceOnlyNew; if (replaceOnlyNew) { Time newPathTime = FileGetTime(newFullPath); - if (IsNull(newPathTime) || (newPathTime > Time(ff.GetLastWriteTime()))) + if (IsNull(newPathTime) || (newPathTime < Time(ff.GetLastWriteTime()))) copy = true; } if (copy) { - if (!FileCopy(ff.GetPath(), newFullPath)) - return false; + if (!PatternMatchMulti(filesToExclude, ff.GetName())) { + if (!FileCopy(ff.GetPath(), newFullPath)) + return false; + } } } else if (ff.IsFolder()) { DirectoryCreate(AppendFileName(newPath, ff.GetName())); if (!FolderIsEmpty(ff.GetPath())) { - if (!DirectoryCopy_Each(dir, newPlace, AppendFileName(relPath, ff.GetName()), replaceOnlyNew)) + if (!DirectoryCopy_Each(dir, newPlace, AppendFileName(relPath, ff.GetName()), replaceOnlyNew, filesToExclude)) return false; } } @@ -1641,10 +1582,10 @@ bool DirectoryCopy_Each(const char *dir, const char *newPlace, String relPath, b return true; } -bool DirectoryCopyX(const char *dir, const char *newPlace, bool replaceOnlyNew) { +bool DirectoryCopyX(const char *dir, const char *newPlace, bool replaceOnlyNew, String filesToExclude) { if (!DirectoryExists(dir)) return false; - return DirectoryCopy_Each(dir, newPlace, "", replaceOnlyNew); + return DirectoryCopy_Each(dir, newPlace, "", replaceOnlyNew, filesToExclude); } bool FolderIsEmpty(const char *path) { diff --git a/bazaar/Functions4U/Functions4U.h b/bazaar/Functions4U/Functions4U.h index 2706a3807..eb37d5278 100644 --- a/bazaar/Functions4U/Functions4U.h +++ b/bazaar/Functions4U/Functions4U.h @@ -48,7 +48,7 @@ String Tokenize2(const String &str, const String &token); ///////// bool DirectoryExistsX(const char *path, EXT_FILE_FLAGS flags = NO_FLAG); -bool DirectoryCopyX(const char *dir, const char *newPlace, bool replaceOnlyNew = false); +bool DirectoryCopyX(const char *dir, const char *newPlace, bool replaceOnlyNew = false, String filesToExclude = ""); bool DirectoryMove(const char *dir, const char *newPlace); bool DeleteDeepWildcardsX(const char *path, bool filefolder, EXT_FILE_FLAGS flags = NO_FLAG); bool DeleteDeepWildcardsX(const char *pathwc, const char *namewc, bool filefolder, EXT_FILE_FLAGS flags = NO_FLAG); @@ -636,7 +636,8 @@ public: LocalProcessX() : status(STOP_OK), callbackOn(false) {} ~LocalProcessX() {Stop();} enum ProcessStatus {RUNNING = 1, STOP_OK = 0, STOP_TIMEOUT = -1, STOP_USER = -2}; - bool Start(const char *cmd, const char *envptr = 0, const char *dir = 0, double refreshTime = -1, double maxTimeWithoutOutput = -1, double maxRunTime = -1, bool convertcharset = true) { + bool Start(const char *cmd, const char *envptr = 0, const char *dir = 0, double refreshTime = -1, + double maxTimeWithoutOutput = -1, double maxRunTime = -1, bool convertcharset = true) { status = STOP_OK; p.ConvertCharset(convertcharset); timeElapsed.Start(); diff --git a/bazaar/Functions4U/Functions4U_Gui.cpp b/bazaar/Functions4U/Functions4U_Gui.cpp index aa1d77b58..84c0e712a 100644 --- a/bazaar/Functions4U/Functions4U_Gui.cpp +++ b/bazaar/Functions4U/Functions4U_Gui.cpp @@ -135,6 +135,15 @@ void DrawRectLine(Draw& w, Rect &r, int lineWidth, const Color &color) { w.DrawLine(r.left, r.bottom, r.left, r.top, lineWidth, color); } +int GetEditWidth(const String str) { + Font font = StdFont(); + + int ret = 0; + for (int i = 0; i < str.GetCount(); ++i) + ret += font.GetWidth(str[i]); + return ret; +} + END_UPP_NAMESPACE #endif diff --git a/bazaar/Functions4U/Functions4U_Gui.h b/bazaar/Functions4U/Functions4U_Gui.h index 1a8986357..c2803a7cc 100644 --- a/bazaar/Functions4U/Functions4U_Gui.h +++ b/bazaar/Functions4U/Functions4U_Gui.h @@ -89,6 +89,7 @@ void DrawRectLine(Draw& w, int x, int y, int width, int height, int lineWidth, c void DrawRectLine(Draw& w, Point &pos, Size &s, int lineWidth, const Color &color); void DrawRectLine(Draw& w, Rect &r, int lineWidth, const Color &color); +int GetEditWidth(const String str); #endif #endif