2 // System.IO.IsolatedStorage.MoonIsolatedStorageFile
4 // Moonlight's implementation for the IsolatedStorageFile
7 // Miguel de Icaza (miguel@novell.com)
9 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Security;
35 namespace System.IO.IsolatedStorage {
37 public sealed class IsolatedStorageFile : IDisposable {
40 static string TryDirectory (string path)
43 Directory.CreateDirectory (path);
50 static IsolatedStorageFile ()
52 string xdg_data_home = Environment.GetEnvironmentVariable ("XDG_DATA_HOME");
53 if (xdg_data_home == null || xdg_data_home == String.Empty){
54 xdg_data_home = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
58 basedir = TryDirectory (Path.Combine (xdg_data_home, "moonlight"));
61 // Maybe try a few others?
66 // FIXME: Use the actual url from the plugin for this.
67 appdir = Path.Combine (basedir, "url");
69 Directory.CreateDirectory (appdir);
75 internal IsolatedStorageFile (string basedir)
79 [SecuritySafeCritical]
80 public static IsolatedStorageFile GetUserStoreForApplication ()
83 throw new SecurityException ();
85 return new IsolatedStorageFile (appdir);
88 internal static string Verify (string path)
91 string full = Path.GetFullPath (Path.Combine (appdir, path));
92 if (full.StartsWith (appdir + Path.DirectorySeparatorChar))
95 throw new IsolatedStorageException ();
97 throw new IsolatedStorageException ();
100 [SecuritySafeCritical]
101 public void CreateDirectory (string dir)
104 Directory.CreateDirectory (dir);
107 [SecuritySafeCritical]
108 public void DeleteDirectory (string dir)
111 Directory.Delete (dir);
114 [SecuritySafeCritical]
115 public string [] GetDirectoryNames (string searchPattern)
117 if (searchPattern.IndexOf ('/') != -1)
118 throw new IsolatedStorageException ();
120 return Directory.GetDirectories (appdir, searchPattern);
123 [SecuritySafeCritical]
124 public string [] GetFileNames (string searchPattern)
126 if (searchPattern.IndexOf ('/') != -1)
127 throw new IsolatedStorageException ();
129 return Directory.GetDirectories (appdir, searchPattern);
132 [SecuritySafeCritical]
133 public void DeleteFile (string file)
138 public void Dispose ()
142 [SecuritySafeCritical]
147 [CLSCompliant(false)]
148 public ulong CurrentSize {
154 [CLSCompliant(false)]
155 public ulong MaximumSize {