1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-24 02:28:01 +02:00

Relaxed project name restrictions. Auto-refresh of installed libraries.

This commit is contained in:
Brian Fiete 2020-08-31 11:32:33 -07:00
parent b3354ee635
commit 4d55a32c90
6 changed files with 143 additions and 27 deletions

View file

@ -3,6 +3,8 @@ using System;
using System.Collections;
using System.IO;
using Beefy.utils;
using System.Threading;
using System.Diagnostics;
namespace IDE
{
@ -14,6 +16,68 @@ namespace IDE
public SemVer mVersion ~ delete _;
public VerSpecRecord mLocation ~ delete _;
public ConfigFile mConfigFile;
public bool mParsedConfig;
}
public class Registry
{
public List<RegistryEntry> mEntries = new List<RegistryEntry>() ~ DeleteContainerAndItems!(_);
public Monitor mMonitor = new .() ~ delete _;
public WaitEvent mEvent = new .() ~ delete _;
public ~this()
{
mEvent.WaitFor();
}
public void ParseConfig(RegistryEntry entry)
{
entry.mParsedConfig = true;
if (entry.mLocation.mVerSpec case .Path(let path))
{
String configPath = scope String()..AppendF("{}/BeefProj.toml", path);
StructuredData sd = scope .();
if (sd.Load(configPath) case .Ok)
{
using (sd.Open("Project"))
{
var projName = scope String();
sd.GetString("Name", projName);
if (!projName.IsEmpty)
{
using (mMonitor.Enter())
entry.mProjName.Set(projName);
}
}
}
}
}
public void WaitFor()
{
mEvent.WaitFor();
}
void Resolve()
{
// NOTE: We allow a race condition where ParseConfig can possibly occur on multiple threads
// at the same time
for (var entry in mEntries)
{
if (!entry.mParsedConfig)
ParseConfig(entry);
}
mEvent.Set(true);
}
public void StartResolve()
{
var thread = new Thread(new => Resolve);
thread.Start(true);
}
}
public class LibDirectory
@ -29,9 +93,16 @@ namespace IDE
}
List<ConfigFile> mConfigFiles = new List<ConfigFile>() ~ DeleteContainerAndItems!(_);
public List<RegistryEntry> mRegistry = new List<RegistryEntry>() ~ DeleteContainerAndItems!(_);
public Registry mRegistry ~ delete _;
List<String> mConfigPathQueue = new List<String>() ~ DeleteContainerAndItems!(_);
List<LibDirectory> mLibDirectories = new List<LibDirectory>() ~ DeleteContainerAndItems!(_);
List<FileSystemWatcher> mWatchers = new .() ~ DeleteContainerAndItems!(_);
public bool mLibsChanged;
void LibsChanged()
{
mLibsChanged = true;
}
Result<void> Load(StringView path)
{
@ -49,7 +120,7 @@ namespace IDE
{
RegistryEntry regEntry = new RegistryEntry();
regEntry.mProjName = new String(projName);
mRegistry.Add(regEntry);
mRegistry.mEntries.Add(regEntry);
regEntry.mConfigFile = configFile;
@ -80,18 +151,15 @@ namespace IDE
{
RegistryEntry regEntry = new RegistryEntry();
regEntry.mProjName = new String(projName);
mRegistry.Add(regEntry);
mRegistry.mEntries.Add(regEntry);
regEntry.mConfigFile = configFile;
var verString = scope String();
data.GetString("Version", verString);
regEntry.mVersion = new SemVer();
regEntry.mVersion.Parse("0.0.0");
regEntry.mLocation = new VerSpecRecord();
using (data.Open("Location"))
regEntry.mLocation.SetPath(filePath);
regEntry.mLocation.SetPath(filePath);
}
else
{
@ -116,6 +184,16 @@ namespace IDE
Path.GetAbsolutePath(libDir.mPath, configFile.mConfigDir, absPath);
AddFromLibraryPath(absPath);
absPath.Append(Path.DirectorySeparatorChar);
FileSystemWatcher watcher = new FileSystemWatcher(absPath);
watcher.OnChanged.Add(new (fileName) => LibsChanged());
watcher.OnCreated.Add(new (fileName) => LibsChanged());
watcher.OnDeleted.Add(new (fileName) => LibsChanged());
watcher.OnRenamed.Add(new (newName, oldName) => LibsChanged());
watcher.OnError.Add(new () => LibsChanged());
watcher.StartRaisingEvents();
mWatchers.Add(watcher);
}
}
@ -163,14 +241,18 @@ namespace IDE
public Result<void> Load()
{
ClearAndDeleteItems(mRegistry);
mLibsChanged = false;
delete mRegistry;
mRegistry = new Registry();
ClearAndDeleteItems(mConfigFiles);
ClearAndDeleteItems(mWatchers);
for (int i = mConfigPathQueue.Count - 1; i >= 0; i--)
{
let path = mConfigPathQueue[i];
Try!(Load(path));
}
mRegistry.StartResolve();
return .Ok;
}
}