mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 06:05:58 -06:00
76 lines
1.7 KiB
C++
76 lines
1.7 KiB
C++
#include "ide.h"
|
|
|
|
Mutex s_allfiles_lock;
|
|
VectorMap<String, String> s_allfiles;
|
|
Vector<String> s_allnests;
|
|
|
|
void ForAllSourceFiles(Event<const VectorMap<String, String>&> fn)
|
|
{
|
|
Mutex::Lock __(s_allfiles_lock);
|
|
fn(s_allfiles);
|
|
}
|
|
|
|
void ForAllNests(Event<const Vector<String>&> fn)
|
|
{
|
|
Mutex::Lock __(s_allfiles_lock);
|
|
fn(s_allnests);
|
|
}
|
|
|
|
void GatherAllFiles(const String& path, Index<String>& filei, VectorMap<String, String>& file)
|
|
{
|
|
Sleep(0); // This is supposed to be superlazy
|
|
for(FindFile ff(path + "/*.*"); ff && !Thread::IsShutdownThreads(); ff.Next())
|
|
if(ff.IsFolder() && *ff.GetName() != '.')
|
|
GatherAllFiles(ff.GetPath(), filei, file);
|
|
else
|
|
if(ff.IsFile()) {
|
|
String p = NormalizePath(ff.GetPath());
|
|
String lp = ToLower(p);
|
|
if(filei.Find(lp) < 0) {
|
|
filei.Add(lp);
|
|
file.Add(GetFileName(p), p);
|
|
}
|
|
}
|
|
}
|
|
|
|
CoEvent ide_bg_scheduler;
|
|
|
|
void IdeBackgroundThread()
|
|
{
|
|
while(!Thread::IsShutdownThreads()) {
|
|
VectorMap<String, String> file;
|
|
Index<String> dir;
|
|
Index<String> filei;
|
|
|
|
for(FindFile ff(ConfigFile("*.var")); ff && !Thread::IsShutdownThreads(); ff.Next()) {
|
|
VectorMap<String, String> var;
|
|
LoadVarFile(ff.GetPath(), var);
|
|
for(String d : Split(var.Get("UPP", ""), ';'))
|
|
dir.FindAdd(NormalizePath(d));
|
|
Sleep(0);
|
|
}
|
|
for(String d : dir)
|
|
GatherAllFiles(d, filei, file);
|
|
{
|
|
Mutex::Lock __(s_allfiles_lock);
|
|
s_allfiles = pick(file);
|
|
s_allnests = dir.PickKeys();
|
|
}
|
|
|
|
ide_bg_scheduler.Wait();
|
|
}
|
|
}
|
|
|
|
void StartIdeBackgroundThread()
|
|
{
|
|
Thread::AtShutdown([] {
|
|
ide_bg_scheduler.Broadcast();
|
|
});
|
|
Thread::StartNice(IdeBackgroundThread);
|
|
}
|
|
|
|
void TriggerIdeBackgroundThread(int delay)
|
|
{
|
|
static TimeCallback tm;
|
|
tm.KillSet(delay, [=] { ide_bg_scheduler.Broadcast(); });
|
|
}
|