mirror of
https://github.com/crskycode/GARbro.git
synced 2026-06-06 21:58:53 +08:00
Compare commits
3 Commits
v1.5.43-pr
...
runtime-co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d33d84ecf9 | ||
|
|
cb32888ffd | ||
|
|
2224d25063 |
@@ -90,6 +90,7 @@ namespace GARbro.GUI
|
||||
|
||||
void WindowRendered ()
|
||||
{
|
||||
var compilation_error = FormatCatalog.Instance.LastError;
|
||||
DirectoryViewModel vm = null;
|
||||
try
|
||||
{
|
||||
@@ -105,6 +106,10 @@ namespace GARbro.GUI
|
||||
}
|
||||
ViewModel = vm;
|
||||
lv_SelectItem (0);
|
||||
if (compilation_error != null)
|
||||
{
|
||||
PopupError (compilation_error.Message, "GameRes library initialization error");
|
||||
}
|
||||
if (!vm.IsArchive)
|
||||
SetStatusText (guiStrings.MsgReady);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,11 @@ using System.ComponentModel.Composition;
|
||||
using System.ComponentModel.Composition.Hosting;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameRes.Collections;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using Microsoft.CSharp;
|
||||
using GameRes.Collections;
|
||||
|
||||
namespace GameRes
|
||||
{
|
||||
@@ -77,12 +80,16 @@ namespace GameRes
|
||||
|
||||
private FormatCatalog ()
|
||||
{
|
||||
var assembly_location = Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
var plugins_dll = Path.Combine (assembly_location, "ArcPlugins.dll");
|
||||
CompilePlugins (Path.Combine (assembly_location, "Plugins"), plugins_dll);
|
||||
|
||||
//An aggregate catalog that combines multiple catalogs
|
||||
var catalog = new AggregateCatalog();
|
||||
//Adds all the parts found in the same assembly as the Program class
|
||||
catalog.Catalogs.Add (new AssemblyCatalog (typeof(FormatCatalog).Assembly));
|
||||
//Adds parts matching pattern found in the directory of the assembly
|
||||
catalog.Catalogs.Add (new DirectoryCatalog (Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly().Location), "Arc*.dll"));
|
||||
catalog.Catalogs.Add (new DirectoryCatalog (assembly_location, "Arc*.dll"));
|
||||
|
||||
//Create the CompositionContainer with the parts in the catalog
|
||||
var container = new CompositionContainer (catalog);
|
||||
@@ -218,6 +225,50 @@ namespace GameRes
|
||||
var bin = new BinaryFormatter();
|
||||
bin.Serialize (output, db);
|
||||
}
|
||||
|
||||
private void CompilePlugins (string source_dir, string target)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists (source_dir))
|
||||
return;
|
||||
var dir = new DirectoryInfo (source_dir);
|
||||
var files = dir.EnumerateFiles ("*.cs");
|
||||
if (!files.Any())
|
||||
return;
|
||||
if (File.Exists (target))
|
||||
{
|
||||
var target_info = new FileInfo (target);
|
||||
var recent_plugin = files.OrderByDescending (f => f.LastWriteTime).First();
|
||||
if (recent_plugin.LastWriteTime < target_info.LastWriteTime)
|
||||
return;
|
||||
}
|
||||
var provider = new CSharpCodeProvider();
|
||||
var parameters = new CompilerParameters { OutputAssembly = target };
|
||||
#if DEBUG
|
||||
parameters.IncludeDebugInformation = true;
|
||||
#endif
|
||||
parameters.ReferencedAssemblies.Add ("System.dll");
|
||||
parameters.ReferencedAssemblies.Add ("System.ComponentModel.Composition.dll");
|
||||
parameters.ReferencedAssemblies.Add (System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
var source = files.Select (f => f.FullName).ToArray();
|
||||
var results = provider.CompileAssemblyFromFile (parameters, source);
|
||||
if (results.Errors.HasErrors)
|
||||
{
|
||||
var error_text = new StringBuilder ("Plugins compilation failed due to errors.\r\n");
|
||||
foreach (CompilerError error in results.Errors)
|
||||
{
|
||||
var filename = Path.GetFileName (error.FileName);
|
||||
error_text.AppendFormat ("{0}:{1}: [{2}] {3}\r\n", filename, error.Line, error.ErrorNumber, error.ErrorText);
|
||||
}
|
||||
throw new ApplicationException (error_text.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception X)
|
||||
{
|
||||
LastError = X;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
Reference in New Issue
Block a user