2012-03-24 23:06:51 +00:00
|
|
|
|
using System.IO;
|
2012-03-19 23:57:59 +00:00
|
|
|
|
using System.IO.IsolatedStorage;
|
|
|
|
|
using Axios.Engine.Interfaces;
|
2015-01-03 02:14:38 +00:00
|
|
|
|
using System;
|
2012-03-19 23:57:59 +00:00
|
|
|
|
|
|
|
|
|
namespace Axios.Engine.File
|
|
|
|
|
{
|
|
|
|
|
public class AxiosIsolatedFile : AxiosFile, IAxiosFile
|
|
|
|
|
{
|
2015-01-03 02:14:38 +00:00
|
|
|
|
protected IsolatedStorageFileStream _fs;
|
2012-03-19 23:57:59 +00:00
|
|
|
|
public AxiosIsolatedFile(string filename)
|
|
|
|
|
{
|
|
|
|
|
this._filename = filename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void WriteData(string data, FileMode mode)
|
|
|
|
|
{
|
|
|
|
|
//Make sure that a proper mode is passed
|
|
|
|
|
if (mode == FileMode.Append
|
|
|
|
|
|| mode == FileMode.Create
|
|
|
|
|
|| mode == FileMode.CreateNew
|
|
|
|
|
|| mode == FileMode.Truncate)
|
|
|
|
|
{
|
|
|
|
|
#if WINDOWS
|
|
|
|
|
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForDomain();
|
|
|
|
|
#else
|
|
|
|
|
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
|
|
|
|
|
#endif
|
|
|
|
|
IsolatedStorageFileStream fs = null;
|
|
|
|
|
fs = savegameStorage.OpenFile(_filename, mode);
|
|
|
|
|
StreamWriter sw = new StreamWriter(fs);
|
|
|
|
|
sw.Write(data);
|
|
|
|
|
sw.Close();
|
|
|
|
|
this.Content = data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ReadData()
|
|
|
|
|
{
|
|
|
|
|
string ret = "";
|
|
|
|
|
#if WINDOWS
|
|
|
|
|
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForDomain();
|
|
|
|
|
#else
|
|
|
|
|
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
|
|
|
|
|
#endif
|
|
|
|
|
IsolatedStorageFileStream fs = null;
|
|
|
|
|
fs = savegameStorage.OpenFile(_filename, System.IO.FileMode.Open);
|
|
|
|
|
StreamReader sr = new StreamReader(fs);
|
|
|
|
|
ret = sr.ReadToEnd();
|
|
|
|
|
sr.Close();
|
|
|
|
|
Content = ret;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2012-05-12 23:36:46 +00:00
|
|
|
|
|
2012-05-22 02:53:14 +00:00
|
|
|
|
public override Stream GetStream(FileMode mode)
|
2012-05-12 23:36:46 +00:00
|
|
|
|
{
|
|
|
|
|
#if WINDOWS
|
|
|
|
|
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForDomain();
|
|
|
|
|
#else
|
|
|
|
|
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
|
|
|
|
|
#endif
|
2015-01-03 02:14:38 +00:00
|
|
|
|
_fs = null;
|
|
|
|
|
_fs = savegameStorage.OpenFile(_filename, mode);
|
|
|
|
|
return (Stream)_fs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
// http://msdn.microsoft.com/en-us/library/system.idisposable%28v=vs.110%29.aspx
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (disposed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (disposing && _fs != null)
|
|
|
|
|
{
|
|
|
|
|
_fs.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disposed = true;
|
2012-05-12 23:36:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 23:57:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|