private static string CreateIsolatedPath(IsolatedStorageFile isf, string path, FileMode mode)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
if (!Enum.IsDefined(typeof(FileMode), mode))
{
throw new ArgumentException("mode");
}
if (isf == null)
{
// we can't call GetUserStoreForDomain here because it depends on
// Assembly.GetCallingAssembly (), which would be our constructor,
// i.e. the result would always be mscorlib.dll. So we need to do
// a small stack walk to find who's calling the constructor
StackFrame sf = new StackFrame(3); // skip self and constructor
isf = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly,
IsolatedStorageFile.GetDomainIdentityFromEvidence(AppDomain.CurrentDomain.Evidence),
IsolatedStorageFile.GetAssemblyIdentityFromEvidence(sf.GetMethod().ReflectedType.Assembly.UnprotectedGetEvidence()));
}
// ensure that the _root_ isolated storage can be (and is) created.
FileInfo fi = new FileInfo(isf.Root);
if (!fi.Directory.Exists)
{
fi.Directory.Create();
}
// other directories (provided by 'path') must already exists
string file = Path.Combine(isf.Root, path);
fi = new FileInfo(file);
if (!fi.Directory.Exists)
{
// don't leak the path information for isolated storage
string msg = Locale.GetText("Could not find a part of the path \"{0}\".");
throw new DirectoryNotFoundException(String.Format(msg, path));
}
// FIXME: this is probably a good place to Assert our security
// needs (once Mono supports imperative security stack modifiers)
return(file);
}