53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using TLang.Common;
|
|
|
|
namespace TLang.VM
|
|
{
|
|
public class DefaultDependencyPool : IDependencyPool
|
|
{
|
|
List<(TLangDependency Dependency,TVMFile File)> items = new List<(TLangDependency Dependency, TVMFile File)>();
|
|
public bool AddDependency(TLangDependency dependency,RootEnvironment env)
|
|
{
|
|
string fileName = $"{dependency.Name}-{dependency.Version}.tvm";
|
|
if(File.Exists(fileName))
|
|
{
|
|
using(var f = File.OpenRead(fileName))
|
|
{
|
|
TVMFile file = new TVMFile(f,env);
|
|
items.Add((dependency,file));
|
|
return file.LoadDependencies(this);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
private static TLangDependencyResponse DefaultDependencyCheck(TLangDependency dep)
|
|
{
|
|
string fileName = $"{dep.Name}-{dep.Version}.tvm";
|
|
if(File.Exists(fileName))
|
|
{
|
|
return new TLangDependencyResponse(){Stream = File.OpenRead(fileName)};
|
|
}
|
|
return new TLangDependencyResponse(){Found = false};
|
|
}
|
|
|
|
public bool DependencyExists(TLangDependency dependency)
|
|
{
|
|
return items.Any(e=>
|
|
e.Dependency.Equals(dependency)
|
|
);
|
|
}
|
|
|
|
public IEnumerator<(TLangDependency Dependency, TVMFile File)> GetEnumerator()
|
|
{
|
|
return items.GetEnumerator();
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return this.GetEnumerator();
|
|
}
|
|
}
|
|
} |