mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-21 03:03:46 -04:00
Allow compiling a subdirectory inside commands or plugins source folders into a single DLL
This commit is contained in:
parent
c06e29b163
commit
1cab27bf51
@ -19,6 +19,7 @@
|
||||
using System;
|
||||
using MCGalaxy.Commands;
|
||||
using MCGalaxy.Scripting;
|
||||
using System.IO;
|
||||
|
||||
namespace MCGalaxy.Modules.Compiling
|
||||
{
|
||||
@ -64,24 +65,40 @@ namespace MCGalaxy.Modules.Compiling
|
||||
}
|
||||
|
||||
protected virtual void CompilePlugin(Player p, string[] paths, ICompiler compiler) {
|
||||
string dstPath = IScripting.PluginPath(paths[0]);
|
||||
string pln = paths[0];
|
||||
string dstPath = IScripting.PluginPath(pln);
|
||||
|
||||
for (int i = 0; i < paths.Length; i++)
|
||||
{
|
||||
paths[i] = compiler.PluginPath(paths[i]);
|
||||
}
|
||||
paths = TryDirectory(ICompiler.PLUGINS_SOURCE_DIR, pln, paths, compiler);
|
||||
|
||||
CompilerOperations.Compile(p, compiler, "Plugin", paths, dstPath);
|
||||
}
|
||||
|
||||
protected virtual void CompileCommand(Player p, string[] paths, ICompiler compiler) {
|
||||
string dstPath = IScripting.CommandPath(paths[0]);
|
||||
string cmd = paths[0];
|
||||
string dstPath = IScripting.CommandPath(cmd);
|
||||
|
||||
for (int i = 0; i < paths.Length; i++)
|
||||
{
|
||||
paths[i] = compiler.CommandPath(paths[i]);
|
||||
}
|
||||
paths = TryDirectory(ICompiler.COMMANDS_SOURCE_DIR, cmd, paths, compiler);
|
||||
|
||||
CompilerOperations.Compile(p, compiler, "Command", paths, dstPath);
|
||||
}
|
||||
|
||||
// If first source file doesn't exist, try treating it as a directory instead
|
||||
string[] TryDirectory(string root, string name, string[] srcPaths, ICompiler compiler) {
|
||||
if (File.Exists(srcPaths[0])) return srcPaths;
|
||||
|
||||
string dir = Path.Combine(root, name);
|
||||
if (!Directory.Exists(dir)) return srcPaths;
|
||||
|
||||
return Directory.GetFiles(dir, "*" + compiler.FileExtension);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
ICompiler compiler = ICompiler.Compilers[0];
|
||||
|
@ -28,9 +28,10 @@ namespace MCGalaxy.Modules.Compiling
|
||||
public override CommandAlias[] Aliases { get { return null; } }
|
||||
|
||||
protected override void CompilePlugin(Player p, string[] paths, ICompiler compiler) {
|
||||
string dst = IScripting.PluginPath(paths[0]);
|
||||
string pln = paths[0];
|
||||
string dst = IScripting.PluginPath(pln);
|
||||
|
||||
UnloadPlugin(p, paths[0]);
|
||||
UnloadPlugin(p, pln);
|
||||
base.CompilePlugin(p, paths, compiler);
|
||||
ScriptingOperations.LoadPlugins(p, dst);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user