Provided support for changing the location of the projects save data root.
This commit is contained in:
parent
f5cf0c1f6a
commit
11b2e73f35
5 changed files with 62 additions and 11 deletions
|
@ -15,7 +15,7 @@ namespace MudEngine.Core
|
||||||
#region Public Properties
|
#region Public Properties
|
||||||
public Boolean IsReadOnly
|
public Boolean IsReadOnly
|
||||||
{
|
{
|
||||||
get { return this.isReadOnly; }
|
get { return this.isReadOnly; } //TODO: Rename to ReadOnly and _ReadOnly
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
@ -24,15 +24,9 @@ namespace MudEngine.DAL
|
||||||
{
|
{
|
||||||
public DataPaths()
|
public DataPaths()
|
||||||
{
|
{
|
||||||
String path = Assembly.GetExecutingAssembly().Location;
|
this._InstallRoot = this.GetInstallPath();
|
||||||
String assemblyFile = Path.GetFileName(path);
|
|
||||||
this._InstallRoot = path.Substring(0, path.Length - assemblyFile.Length);
|
|
||||||
|
|
||||||
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Characters"), DataTypes.Characters);
|
this.SetupPaths();
|
||||||
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Environments"), DataTypes.Environments);
|
|
||||||
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Equipment"), DataTypes.Equipment);
|
|
||||||
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Players"), DataTypes.Players);
|
|
||||||
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "GameScripts"), DataTypes.Scripts);
|
|
||||||
|
|
||||||
this.SetExtension(DataTypes.Characters, ".character");
|
this.SetExtension(DataTypes.Characters, ".character");
|
||||||
this.SetExtension(DataTypes.Environments, ".environment");
|
this.SetExtension(DataTypes.Environments, ".environment");
|
||||||
|
@ -41,6 +35,22 @@ namespace MudEngine.DAL
|
||||||
this.SetExtension(DataTypes.Scripts, ".cs");
|
this.SetExtension(DataTypes.Scripts, ".cs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String GetInstallPath()
|
||||||
|
{
|
||||||
|
String path = Assembly.GetExecutingAssembly().Location;
|
||||||
|
String assemblyFile = Path.GetFileName(path);
|
||||||
|
return path.Substring(0, path.Length - assemblyFile.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupPaths()
|
||||||
|
{
|
||||||
|
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Characters"), DataTypes.Characters);
|
||||||
|
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Environments"), DataTypes.Environments);
|
||||||
|
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Equipment"), DataTypes.Equipment);
|
||||||
|
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "Players"), DataTypes.Players);
|
||||||
|
this.SetAbsolutePath(Path.Combine(this._InstallRoot, "GameScripts"), DataTypes.Scripts);
|
||||||
|
}
|
||||||
|
|
||||||
public void SetAbsolutePath(String path, DataTypes objectType)
|
public void SetAbsolutePath(String path, DataTypes objectType)
|
||||||
{
|
{
|
||||||
if (!path.EndsWith(@"\"))
|
if (!path.EndsWith(@"\"))
|
||||||
|
@ -63,11 +73,42 @@ namespace MudEngine.DAL
|
||||||
case DataTypes.Scripts:
|
case DataTypes.Scripts:
|
||||||
this._Scripts = path;
|
this._Scripts = path;
|
||||||
break;
|
break;
|
||||||
|
case DataTypes.Root:
|
||||||
|
this._InstallRoot = path;
|
||||||
|
this.SetupPaths(); //Re-Setup all the paths since the root has changed.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRelativePath(String path, DataTypes objectType)
|
public void SetRelativePath(String path, DataTypes objectType)
|
||||||
{
|
{
|
||||||
|
if (!path.EndsWith(@"\"))
|
||||||
|
path = path.Insert(path.Length, @"\");
|
||||||
|
|
||||||
|
String correctedPath = Path.Combine(this._InstallRoot, path);
|
||||||
|
|
||||||
|
switch (objectType)
|
||||||
|
{
|
||||||
|
case DataTypes.Characters:
|
||||||
|
this._Characters = correctedPath;
|
||||||
|
break;
|
||||||
|
case DataTypes.Environments:
|
||||||
|
this._Environments = correctedPath;
|
||||||
|
break;
|
||||||
|
case DataTypes.Equipment:
|
||||||
|
this._Equipment = correctedPath;
|
||||||
|
break;
|
||||||
|
case DataTypes.Players:
|
||||||
|
this._Players = correctedPath;
|
||||||
|
break;
|
||||||
|
case DataTypes.Scripts:
|
||||||
|
this._Scripts = correctedPath;
|
||||||
|
break;
|
||||||
|
case DataTypes.Root:
|
||||||
|
this._InstallRoot = Path.Combine(this.GetInstallPath(), path);
|
||||||
|
this.SetupPaths(); //Re-setup all the paths since the root has changed.
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String GetPath(DataTypes objectType)
|
public String GetPath(DataTypes objectType)
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
using MudEngine.GameScripts;
|
using MudEngine.GameScripts;
|
||||||
using MudEngine.Core;
|
using MudEngine.Core;
|
||||||
|
@ -41,6 +42,11 @@ namespace MudEngine.DAL
|
||||||
|
|
||||||
public Boolean Save(String filename)
|
public Boolean Save(String filename)
|
||||||
{
|
{
|
||||||
|
if (!Directory.Exists(Path.GetDirectoryName(filename)))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.SaveData.Save(filename);
|
this.SaveData.Save(filename);
|
||||||
|
|
|
@ -119,8 +119,7 @@ namespace MudEngine.Game
|
||||||
|
|
||||||
//Setup default save paths.
|
//Setup default save paths.
|
||||||
this.SavePaths = new DataPaths();
|
this.SavePaths = new DataPaths();
|
||||||
|
this.SavePaths.SetRelativePath("Data", DataTypes.Root);
|
||||||
SetupPaths();
|
|
||||||
|
|
||||||
this.World = new World(this);
|
this.World = new World(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ namespace MudEngine.Scripting
|
||||||
//Instance a reference to the C# code provider, this is what will perform the compiling.
|
//Instance a reference to the C# code provider, this is what will perform the compiling.
|
||||||
CSharpCodeProvider provider = new CSharpCodeProvider(CompilerOptions);
|
CSharpCodeProvider provider = new CSharpCodeProvider(CompilerOptions);
|
||||||
//Create an array of script files found within the ScriptRepository matching the ScriptExtension properties.
|
//Create an array of script files found within the ScriptRepository matching the ScriptExtension properties.
|
||||||
|
if (!Directory.Exists(scriptRepository))
|
||||||
|
Directory.CreateDirectory(scriptRepository);
|
||||||
String[] scripts = Directory.GetFiles(scriptRepository, "*" + this.ScriptExtension, SearchOption.AllDirectories);
|
String[] scripts = Directory.GetFiles(scriptRepository, "*" + this.ScriptExtension, SearchOption.AllDirectories);
|
||||||
|
|
||||||
if (scripts.Length > 0)
|
if (scripts.Length > 0)
|
||||||
|
@ -64,7 +66,10 @@ namespace MudEngine.Scripting
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
Results = new CompilerResults(new TempFileCollection());
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue