Provided support for changing the location of the projects save data root.

This commit is contained in:
Scionwest_cp 2012-03-10 19:15:43 -08:00
parent f5cf0c1f6a
commit 11b2e73f35
5 changed files with 62 additions and 11 deletions

View file

@ -15,7 +15,7 @@ namespace MudEngine.Core
#region Public Properties
public Boolean IsReadOnly
{
get { return this.isReadOnly; }
get { return this.isReadOnly; } //TODO: Rename to ReadOnly and _ReadOnly
}
#endregion

View file

@ -24,15 +24,9 @@ namespace MudEngine.DAL
{
public DataPaths()
{
String path = Assembly.GetExecutingAssembly().Location;
String assemblyFile = Path.GetFileName(path);
this._InstallRoot = path.Substring(0, path.Length - assemblyFile.Length);
this._InstallRoot = this.GetInstallPath();
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);
this.SetupPaths();
this.SetExtension(DataTypes.Characters, ".character");
this.SetExtension(DataTypes.Environments, ".environment");
@ -41,6 +35,22 @@ namespace MudEngine.DAL
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)
{
if (!path.EndsWith(@"\"))
@ -63,11 +73,42 @@ namespace MudEngine.DAL
case DataTypes.Scripts:
this._Scripts = path;
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)
{
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)

View file

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Reflection;
using System.IO;
using MudEngine.GameScripts;
using MudEngine.Core;
@ -41,6 +42,11 @@ namespace MudEngine.DAL
public Boolean Save(String filename)
{
if (!Directory.Exists(Path.GetDirectoryName(filename)))
{
Directory.CreateDirectory(Path.GetDirectoryName(filename));
}
try
{
this.SaveData.Save(filename);

View file

@ -119,8 +119,7 @@ namespace MudEngine.Game
//Setup default save paths.
this.SavePaths = new DataPaths();
SetupPaths();
this.SavePaths.SetRelativePath("Data", DataTypes.Root);
this.World = new World(this);
}

View file

@ -51,6 +51,8 @@ namespace MudEngine.Scripting
//Instance a reference to the C# code provider, this is what will perform the compiling.
CSharpCodeProvider provider = new CSharpCodeProvider(CompilerOptions);
//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);
if (scripts.Length > 0)
@ -64,7 +66,10 @@ namespace MudEngine.Scripting
return true;
}
else
{
Results = new CompilerResults(new TempFileCollection());
return false;
}
}
/// <summary>