From a6f88dccf39b74d9a84f79eb48351cd1d1360c97 Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 5 Nov 2019 18:00:10 +0000 Subject: [PATCH] CtrlLib: FileSel .lnk improvements git-svn-id: svn://ultimatepp.org/upp/trunk@13680 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Cpu.cpp | 29 +++++++++++++++++++++++++++++ uppsrc/Core/Ops.h | 4 +++- uppsrc/CtrlLib/FileSel.cpp | 28 ++++++++++++++++------------ uppsrc/CtrlLib/FileSel.h | 3 ++- 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/uppsrc/Core/Cpu.cpp b/uppsrc/Core/Cpu.cpp index ced544207..60aabb90f 100644 --- a/uppsrc/Core/Cpu.cpp +++ b/uppsrc/Core/Cpu.cpp @@ -171,4 +171,33 @@ void EndianSwap(int *v, size_t count) ENDIAN_SWAP void EndianSwap(int64 *v, size_t count) ENDIAN_SWAP void EndianSwap(uint64 *v, size_t count) ENDIAN_SWAP +#ifdef COMPILER_MINGW + +static int fast_mingw_tlsndx = 0; + +void PreallocateFastMingwTls() +{ // preallocate "simple" tls entries so that they are not used up by other code + ONCELOCK { // Preallocate + fast_mingw_tlsndx = TlsAlloc(); + while(TlsAlloc() < 60); + } +} + +INITBLOCK { + PreallocateFastMingwTls(); +} + +int FastMingwTlsAlloc() +{ + int ndx; + INTERLOCKED { + PreallocateFastMingwTls(); + ndx = fast_mingw_tlsndx++; + ASSERT(ndx <= 60); + } + return ndx; +} + +#endif + } diff --git a/uppsrc/Core/Ops.h b/uppsrc/Core/Ops.h index d9d2884b5..cb710b375 100644 --- a/uppsrc/Core/Ops.h +++ b/uppsrc/Core/Ops.h @@ -323,6 +323,8 @@ int SignificantBits64(uint64 x) // This is hopefully a temporary fix for abysmal MINGW thread_local implementation // ALSO IMPORTANT: There are some mingw/lld issues that prevent TLS stuff to be used in inlines +int FastMingwTlsAlloc(); + template struct FastMingwTls { int ndx = -1; @@ -356,7 +358,7 @@ public: const T operator->() const { return (T)(uintptr_t)Slot(); } operator T() const { return (T)(uintptr_t)Slot(); } - FastMingwTls() { ndx = TlsAlloc(); ASSERT(ndx < 60); } + FastMingwTls() { ndx = FastMingwTlsAlloc(); } FastMingwTls(T x) : FastMingwTls() { operator=(x); } }; diff --git a/uppsrc/CtrlLib/FileSel.cpp b/uppsrc/CtrlLib/FileSel.cpp index 44e53a013..aca9135f7 100644 --- a/uppsrc/CtrlLib/FileSel.cpp +++ b/uppsrc/CtrlLib/FileSel.cpp @@ -536,8 +536,12 @@ bool Load(FileList& list, const String& dir, const char *patterns, bool dirs, show = true; if(!show && hiddenfiles && fi.is_file) show = true; - if(fi.filename != "." && fi.filename != ".." != 0 && + if(fi.filename != "." && fi.filename != ".." && + #ifdef PLATFORM_WIN32 + (fi.is_directory || FileSel::IsLnkFile(fi.filename) || PatternMatchMulti(patterns, fi.filename)) && + #else (fi.is_directory || PatternMatchMulti(patterns, fi.filename)) && + #endif MatchSearch(fi.filename, search) && show) { Image img; #ifdef PLATFORM_POSIX @@ -591,7 +595,7 @@ static auxthread_t auxthread__ sExeIconThread(void *) strncpy(path, sExePath, 1024); sExeMutex.Leave(); AvoidPaintingCheck__(); - SHGetFileInfo(sExePath, FILE_ATTRIBUTE_NORMAL, &info, sizeof(info), SHGFI_ICON|SHGFI_SMALLICON); + SHGetFileInfo(path, FILE_ATTRIBUTE_NORMAL, &info, sizeof(info), SHGFI_ICON|SHGFI_SMALLICON); sExeMutex.Enter(); memcpy(&sExeInfo, &info, sizeof(info)); sExeRunning = false; @@ -608,9 +612,11 @@ void LazyExeFileIcons::Done(Image img) return; const FileList::File& f = list->Get(ii); WhenIcon(false, f.name, img); - if(f.hidden) - img = Contrast(img, 200); - list->SetIcon(ii, img); + if(!IsNull(img)) { + if(f.hidden) + img = Contrast(img, 200); + list->SetIcon(ii, img); + } pos++; } @@ -986,7 +992,7 @@ void FileSel::AddName(Vector& fn, String& f) { f.Clear(); } -bool FileSel::IsLnkFile(const String& p) const +bool FileSel::IsLnkFile(const String& p) { int l = p.GetLength() - 4; return l >= 0 && p[l] == '.' && ToLower(p[l + 1]) == 'l' && ToLower(p[l + 2]) == 'n' && ToLower(p[l + 3]) == 'k'; @@ -1145,12 +1151,10 @@ bool FileSel::OpenItem() { LoadNet(); return true; } - if(GetFileExt(path) == ".lnk") { - String p = ResolveLnkDir(m.name); - if(p.GetCount()) { - SetDir(p); - return true; - } + String p = ResolveLnkDir(m.name); + if(p.GetCount()) { + SetDir(p); + return true; } #endif if(m.isdir) { diff --git a/uppsrc/CtrlLib/FileSel.h b/uppsrc/CtrlLib/FileSel.h index 9fc173939..916e9bb0b 100644 --- a/uppsrc/CtrlLib/FileSel.h +++ b/uppsrc/CtrlLib/FileSel.h @@ -263,7 +263,6 @@ protected: void SetDir(const String& dir); String GetDir() const; void AddName(Vector& fn, String& o); - bool IsLnkFile(const String& p) const; String ResolveLnk(const String& name) const; String ResolveLnkDir(const String& name) const; String ResolveLnkFile(const String& name) const; @@ -282,6 +281,8 @@ protected: typedef FileSel CLASSNAME; public: + static bool IsLnkFile(const String& p); + Event WhenIcon; void (*WhenIconLazy)(const String& path, Image& result);