CtrlLib: FileSel .lnk improvements

git-svn-id: svn://ultimatepp.org/upp/trunk@13680 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2019-11-05 18:00:10 +00:00
parent 4845f31ae1
commit a6f88dccf3
4 changed files with 50 additions and 14 deletions

View file

@ -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
}

View file

@ -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 <class T>
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); }
};

View file

@ -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<String>& 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) {

View file

@ -263,7 +263,6 @@ protected:
void SetDir(const String& dir);
String GetDir() const;
void AddName(Vector<String>& 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<bool, const String&, Image&> WhenIcon;
void (*WhenIconLazy)(const String& path, Image& result);