muddesigner/MudEngine/FileSystem/FileManager.cs
Scionwest_cp dc311f5aa5 Added MudEngine Project to the Solution. I will slowly be moving the MudDesigner.MudEngine classes out of the Mud Designer Solution and into it's own.
Currently the Mud Designer still contains the old MudEngine classes until migration has been completed.
2010-07-15 18:53:38 -07:00

96 lines
3.3 KiB
C#

//Microsoft .NET Framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace MudEngine.FileSystem
{
/// <summary>
/// Handles saving and loading of engine objects
/// </summary>
public static class FileManager
{
public enum OutputFormats
{
XML = 0,
}
/// <summary>
/// The filetype that the MUDs files will be saved as
/// </summary>
public static OutputFormats FileType
{
get;
set;
}
/// <summary>
/// Saves the object using the specified output format
/// </summary>
/// <param name="Filename"></param>
/// <param name="o"></param>
public static void Save(string Filename, object o)
{
if (FileType == OutputFormats.XML)
{
XmlSerialization.Save(Filename, o);
}
}
/// <summary>
/// Loads the object using the specified FileType format
/// </summary>
/// <param name="Filename"></param>
/// <param name="o"></param>
/// <returns></returns>
public static object Load(string Filename, object o)
{
if (FileType == OutputFormats.XML)
{
return XmlSerialization.Load(Filename, o);
}
else return null;
}
/// <summary>
/// Returns the complete path to the specified data's save folder.
/// </summary>
/// <param name="DataType"></param>
/// <returns></returns>
public static string GetDataPath(SaveDataTypes DataType)
{
string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName;
string assemblyName = System.IO.Path.GetFileName(assemblyPath);
string installBase = assemblyPath.Substring(0, assemblyPath.Length - assemblyName.Length);
string rootPath = System.IO.Path.Combine(installBase, "Project");
if (DataType == SaveDataTypes.Root)
return rootPath;
else
return System.IO.Path.Combine(rootPath, DataType.ToString());
}
public static string GetDataPath(string Realm, string Zone)
{
string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName;
string assemblyName = System.IO.Path.GetFileName(assemblyPath);
string installBase = assemblyPath.Substring(0, assemblyPath.Length - assemblyName.Length);
string rootPath = System.IO.Path.Combine(installBase, "Project");
string realmsPath = System.IO.Path.Combine(rootPath, "Realms");
string requestRealm = Path.Combine(realmsPath, Realm);
string requestedRealmZones = Path.Combine(requestRealm, "Zones");
string requestedZone = Path.Combine(requestedRealmZones, Zone);
return requestedZone;
}
public static string GetDataPath(string Realm, string Zone, string Room)
{
return System.IO.Path.Combine(GetDataPath(Realm, Zone), Room);
}
//TODO Write CopyDirectory method.
}
}