muddesigner/Mud Designer/MudEngine/FileSystem/FileManager.cs
Scionwest_cp 98857cc0de Mud Designer:
- Auto-saving objects is now complete.
 - Removed Save Object button
 - Object Properties no longer displays the Project Information on startup
 - Objects that can be edited within the Designer are displayed in Blue in the treeview
 - Objects that can only be edited within another objects Mini-Editor are displayed in Red and cannot be edited within the main Designer
 - Folders are displayed in Black
 - Objects are not auto-saved until the objects Name is changed from 'New Object'
 - The designer checks to see if the object has been saved yet prior to creating a new object.
 - Double clicking an editable object (shown in blue text) now loads the object for editing.
 - Menu item Project->Game Objects->Environment->New Room opens the Zones Mini-Room Editor if a Zone is loaded.
 - Tooltips added to the Project Explorer and Object Properties panes

Mud Engine:
 - FileManager returns the new directory layout when using GetDataPath
 - Added Zones to SaveDataTypes enum.
 - Game Objects now have a Description attribute attached to their public properties so the Designer can display a description of what the property is for within the Object Properties pane.
 - Added PreCacheObjects Boolean to ProjectInformation for pre-loading objects when the runtime is built.
 - All objects Filename is now set to readonly and cannot be edited within the Designer
 - Started work on Realm.GetZone() method.
 - Room.Zone is no longer hidden from the Object Properties Pane, but set to Readonly.
 - Began work on Moving a Zones Rooms when a Zone is moved within a Realm. 
 - Removed un-needed code within the RealmEditor 
 - UIRoomControl now creates and saves Rooms. Duplicate Rooms cannot be created and Room re-naming is implemented.
 - Removed remaining old code for previous Mud Designer Editors from within Program.cs
2010-01-10 17:57:52 -08:00

134 lines
5.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace MudDesigner.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>
/// Used to ensure that the paths needed to run the game exists.
/// If no path is supplied, the engine uses it's current install path.
/// </summary>
/// <param name="validatedPath"></param>
public static void ValidateDataPaths()
{
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, "Data");
ValidateDataPaths(rootPath);
}
/// <summary>
/// Checks the supplied directory to ensure that all of the engines needed
/// data folders are created. Only use if you want to point your projects in
/// different directory other than InstallBase\Data
/// </summary>
/// <param name="InstallPath"></param>
public static void ValidateDataPaths(string InstallPath)
{
if (!InstallPath.EndsWith("data", true, null))
InstallPath = System.IO.Path.Combine(InstallPath, "Data");
if (!System.IO.Directory.Exists(InstallPath))
System.IO.Directory.CreateDirectory(InstallPath);
foreach (SaveDataTypes value in Enum.GetValues(typeof(SaveDataTypes)))
{
string dataType = value.ToString();
if (value.ToString() == "Root")
continue;
if (!System.IO.Directory.Exists(System.IO.Path.Combine(InstallPath, dataType)))
System.IO.Directory.CreateDirectory(System.IO.Path.Combine(InstallPath, dataType));
}
}
/// <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.
}
}