#region Copyright /* -------------------------------------------------------------------------------- This source file is part of Xenocide by Project Xenocide Team For the latest info on Xenocide, see http://www.projectxenocide.com/ This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA. -------------------------------------------------------------------------------- */ /* * @file GameOptions.cs * @date Created: 2009/10/19 * @author File creator: John Perrin * @author Credits: none */ #endregion #region Using Statements using System; using System.Collections.Generic; using System.Text; using System.Xml.Serialization; using System.Runtime.Serialization.Formatters.Binary; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Storage; using System.IO; using Microsoft.Xna.Framework; #endregion namespace Xenocide.Source.Utils { /// /// Provides some common methods for persisting game data /// static class FileUtil { /// /// Get the container (directory) holding the requested file /// /// Full path to requested file /// the container public static StorageContainer GetContainer(string pathName) { // this bit is dummy on windows string directory = Path.GetDirectoryName(pathName); IAsyncResult result = Guide.BeginShowStorageDeviceSelector(PlayerIndex.One, null, null); StorageDevice device = Guide.EndShowStorageDeviceSelector(result); // Now open container(directory) return device.OpenContainer(directory); } /// /// Get correct pathname to use to get a file /// Allow for path being different on an X-Box /// /// container holding the file /// full path /// correct path public static string TruePathName(StorageContainer container, string pathName) { return Path.Combine(container.Path, Path.GetFileName(pathName)); } /// /// Will check to see if a file exists. /// /// File Name to check for /// public static bool DoesFileExist(string pathName) { using (StorageContainer container = GetContainer(pathName)) { return File.Exists(TruePathName(container, pathName)); } } } }