Virtu/Virtu/Wpf/Services/WpfStorageService.cs
Sean Fausett 8382195feb Initial sound emulation for WPF and XNA+Windows platforms via COM interop to DirectSound.
Added rudimentary UI to Silverlight and WPF platforms to enable disk selection at runtime.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4024459
2009-07-26 23:22:00 +00:00

59 lines
1.8 KiB
C#

using System;
using System.Deployment.Application;
using System.IO;
using System.IO.IsolatedStorage;
namespace Jellyfish.Virtu.Services
{
public sealed class WpfStorageService : StorageService
{
public WpfStorageService(Machine machine) :
base(machine)
{
}
public override void Load(string path, Action<Stream> reader)
{
try
{
using (IsolatedStorageFile store = GetStore())
{
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, store))
{
reader(stream);
}
}
}
catch (FileNotFoundException)
{
}
catch (IsolatedStorageException)
{
}
}
public override void Save(string path, Action<Stream> writer)
{
try
{
using (IsolatedStorageFile store = GetStore())
{
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, store))
{
writer(stream);
}
}
}
catch (IsolatedStorageException)
{
}
}
private static IsolatedStorageFile GetStore()
{
return ApplicationDeployment.IsNetworkDeployed ? // clickonce
IsolatedStorageFile.GetUserStoreForApplication() : IsolatedStorageFile.GetUserStoreForAssembly();
}
}
}