public static void SetTransistorRoot(string rootDirectory) { lock (Lock) { TexturesByName.Clear(); AtlasesByTextureName.Clear(); RootDirectory = rootDirectory; Packages.Clear(); LoadedPackages.Clear(); var files = Directory.EnumerateFiles(rootDirectory); var packageFiles = files.Where(x => Path.GetExtension(x) == PKG_EXT) .Select(Path.GetFileNameWithoutExtension); var manifestFiles = files.Where(x => Path.GetExtension(x) == PKG_MANIFEST_EXT) .Select(Path.GetFileNameWithoutExtension); Packages = packageFiles.Union(manifestFiles).ToList(); Packages.Sort(); PackageSizes = new Dictionary <string, long>(); foreach (var name in Packages) { var package = Path.Combine(rootDirectory, name + PKG_EXT); var manifest = Path.Combine(rootDirectory, name + PKG_MANIFEST_EXT); PackageSizes[name] = (new FileInfo(package)).Length + (new FileInfo(manifest)).Length; } if (OnRootChanged != null) { OnRootChanged(); } } }
public static void ReleasePackage(string packageName) { lock (Lock) { LoadedPackages.Remove(packageName); } GC.Collect(); }
public void Remove(Package package, ModuleCollection modules, IWriterCollection writers) { if (LoadedPackages.Contains(package)) { Unload(package, modules, writers); } PackagesCollection.Packages.Remove(package); }
public static Package LoadPackage(string packageName, Package.AsyncLoadPackageCallback cb) { var baseFile = Path.Combine(RootDirectory, packageName); var package = new Package(packageName, baseFile + PKG_MANIFEST_EXT, baseFile + PKG_EXT); package.Load(cb); lock (Lock) { LoadedPackages.Add(packageName, package); UpdateLinkDicts(new PackageReference(packageName, PackageReference.Files.Manifest), package.ManifestContents); UpdateLinkDicts(new PackageReference(packageName, PackageReference.Files.Package), package.PackageContents); } if (OnPackageLoad != null) { OnPackageLoad(packageName, package); } return(package); }
public void Unload(Package package, ModuleCollection modules, IWriterCollection writers) { if (!LoadedPackages.Contains(package)) { throw new Exception(string.Format("The package {0} is not loaded", package.Name)); } Dictionary <string, System.Reflection.Assembly> asmDic = new Dictionary <string, System.Reflection.Assembly>(); foreach (var module in package.Modules) { Type moduleType = null; System.Reflection.Assembly asm = null; try { if (!asmDic.ContainsKey(module.Assembly)) { asmDic.Add(module.Assembly, Util.LoadAssembly(module.Assembly)); } asm = asmDic[module.Assembly]; moduleType = asm.GetType(module.ModuleType); modules.Uninstall(moduleType, writers); writers.Verbose.WriteLine(string.Format("Uninstalled module '{0}' from assembly '{1}'", moduleType, asm)); } catch (Exception ex) { writers.Error.WriteLine(string.Format("An error occured while uninstalling module '{0}' from assembly '{1}' :: {2}\r\n{3}" , moduleType, asm.CodeBase.Replace("file:///", string.Empty), ex.Message, ex.StackTrace)); writers.Error.WriteLine("The application should be restarted to ensure that the package is fully unloaded."); } } _loadedPackageNames.Remove(package.Name); }
public static bool IsLoaded(string packageName) { lock (Lock) { return(LoadedPackages.ContainsKey(packageName) && LoadedPackages[packageName] != null); } }