IsolatedStorageFile.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // System.IO.IsolatedStorage.IsolatedStorageFile
  2. //
  3. // Jonathan Pryor ([email protected])
  4. //
  5. // (C) 2003 Jonathan Pryor
  6. using System;
  7. using System.Collections;
  8. using System.IO;
  9. using System.Reflection;
  10. using System.Security;
  11. using System.Security.Permissions;
  12. namespace System.IO.IsolatedStorage
  13. {
  14. // This is a terribly named class. It doesn't actually represent a file as
  15. // much as a directory
  16. public sealed class IsolatedStorageFile : IsolatedStorage, IDisposable
  17. {
  18. private DirectoryInfo directory;
  19. private IsolatedStorageFile (string directory)
  20. {
  21. this.directory = new DirectoryInfo (directory);
  22. this.directory.Create ();
  23. }
  24. [CLSCompliant(false)]
  25. public override ulong CurrentSize {
  26. get {return IsolatedStorageInfo.GetDirectorySize(directory);}
  27. }
  28. [CLSCompliant(false)]
  29. [MonoTODO ("The IsolatedStorage area should be limited, to prevent DOS attacks. What's a reasonable size?")]
  30. public override ulong MaximumSize {
  31. get {return ulong.MaxValue;}
  32. }
  33. [MonoTODO ("Pay attention to scope")]
  34. public static IEnumerator GetEnumerator (IsolatedStorageScope scope)
  35. {
  36. Array a = Directory.GetFileSystemEntries (IsolatedStorageInfo.GetIsolatedStorageDirectory());
  37. return a.GetEnumerator ();
  38. }
  39. [MonoTODO ("Functional but missing CAS support")]
  40. public static IsolatedStorageFile GetStore (
  41. IsolatedStorageScope scope,
  42. System.Security.Policy.Evidence domainEvidence,
  43. Type domainEvidenceType,
  44. System.Security.Policy.Evidence assemblyEvidence,
  45. Type assemblyEvidenceType)
  46. {
  47. return GetStore (scope);
  48. }
  49. [MonoTODO ("Functional but missing CAS support")]
  50. public static IsolatedStorageFile GetStore (
  51. IsolatedStorageScope scope,
  52. object domainIdentity,
  53. object assemblyIdentity)
  54. {
  55. return GetStore (scope);
  56. }
  57. [MonoTODO ("Functional but missing CAS support")]
  58. public static IsolatedStorageFile GetStore (
  59. IsolatedStorageScope scope,
  60. Type domainEvidenceType,
  61. Type assemblyEvidenceType)
  62. {
  63. return GetStore (scope);
  64. }
  65. private static IsolatedStorageFile GetStore (IsolatedStorageScope scope)
  66. {
  67. string dir = GetScopeDirectory (scope);
  68. storage_scope = scope;
  69. return new IsolatedStorageFile (dir);
  70. }
  71. private static string GetScopeDirectory (IsolatedStorageScope scope)
  72. {
  73. string dir = "";
  74. if ((scope & IsolatedStorageScope.Domain) != 0)
  75. dir = IsolatedStorageInfo.CreateDomainFilename (
  76. Assembly.GetEntryAssembly (),
  77. AppDomain.CurrentDomain);
  78. else
  79. dir = IsolatedStorageInfo.CreateAssemblyFilename (
  80. Assembly.GetEntryAssembly ());
  81. return dir;
  82. }
  83. public static IsolatedStorageFile GetUserStoreForAssembly ()
  84. {
  85. return GetStore (IsolatedStorageScope.User | IsolatedStorageScope.Assembly);
  86. }
  87. public static IsolatedStorageFile GetUserStoreForDomain ()
  88. {
  89. return GetStore (IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly);
  90. }
  91. public static void Remove (IsolatedStorageScope scope)
  92. {
  93. string dir = GetScopeDirectory (scope);
  94. Directory.Delete (dir, true);
  95. }
  96. public void Close ()
  97. {
  98. }
  99. public void CreateDirectory (string dir)
  100. {
  101. directory.CreateSubdirectory (dir);
  102. }
  103. public void DeleteDirectory (string dir)
  104. {
  105. DirectoryInfo subdir = directory.CreateSubdirectory (dir);
  106. subdir.Delete ();
  107. }
  108. public void DeleteFile (string file)
  109. {
  110. File.Delete (directory.Name + "/" + file);
  111. }
  112. public void Dispose ()
  113. {
  114. }
  115. public string[] GetDirectoryNames (string searchPattern)
  116. {
  117. DirectoryInfo[] adi = directory.GetDirectories (searchPattern);
  118. return GetNames (adi);
  119. }
  120. private string[] GetNames (FileSystemInfo[] afsi)
  121. {
  122. string[] r = new string[afsi.Length];
  123. for (int i = 0; i != afsi.Length; ++i)
  124. r[i] = afsi[i].Name;
  125. return r;
  126. }
  127. public string[] GetFileNames (string searchPattern)
  128. {
  129. FileInfo[] afi = directory.GetFiles (searchPattern);
  130. return GetNames (afi);
  131. }
  132. public override void Remove ()
  133. {
  134. directory.Delete (true);
  135. }
  136. ~IsolatedStorageFile ()
  137. {
  138. }
  139. [MonoTODO ("Permissions are CAS related")]
  140. protected override IsolatedStoragePermission GetPermission (PermissionSet ps)
  141. {
  142. throw new NotImplementedException ();
  143. }
  144. }
  145. }