[System.Security.SecurityCritical] // auto-generated #endif public void Remove() { #if !FEATURE_LEGACYNETCF bool removedAll = true; FileLock groupLock = FileLock.GetFileLock(Path.Combine(IsolatedStorageFile.IsolatedStorageRoot, IsolatedStorageFile.s_LockPathPrefix), IsolatedStorageFile.s_GroupPathPrefix + "-" + m_ObfuscatedId); try { groupLock.Lock(); foreach (string storeDir in Directory.UnsafeGetDirectories(Path.Combine(IsolatedStorageFile.IsolatedStorageRoot, IsolatedStorageFile.s_StorePathPrefix), "*", SearchOption.TopDirectoryOnly)) { string groupFile = Path.Combine(storeDir, IsolatedStorageFile.s_GroupFileName); if (m_ObfuscatedId.Equals(File.UnsafeReadAllText(groupFile))) { IsolatedStorageFile f = IsolatedStorageFile.GetUserStoreFromGroupAndStorePath(Group, storeDir); removedAll = removedAll & f.TryRemove(); } } IsolatedStorageFile.TouchFile(Path.Combine(m_GroupPath, IsolatedStorageFile.s_CleanupFileName)); if (removedAll) { IsolatedStorageAccountingInfo.RemoveAccountingInfo(m_GroupPath); File.UnsafeDelete(Path.Combine(m_GroupPath, IsolatedStorageFile.s_IdFileName)); File.UnsafeDelete(Path.Combine(m_GroupPath, IsolatedStorageFile.s_CleanupFileName)); Directory.UnsafeDelete(m_GroupPath, false); } } catch (IOException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (UnauthorizedAccessException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } finally { groupLock.Unlock(); } #else // !FEATURE_LEGACYNETCF try { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { isf.Remove(); } } catch (IOException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (UnauthorizedAccessException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } #endif // !FEATURE_LEGACYNETCF }
[System.Security.SecurityCritical] // auto-generated #endif private static string FetchOrCreateGroup(string groupName, out IsolatedStorageAccountingInfo accountInfo, bool retry) { string obfuscatedGroupName = GetHash(groupName); string groupRootPath = GetGroupPathFromName(groupName); FileLock rootLock = FileLock.GetFileLock(IsolatedStorageRoot); try { rootLock.Lock(); if(Directory.UnsafeExists(groupRootPath)) { if(File.UnsafeExists(Path.Combine(groupRootPath, s_CleanupFileName))) { if (retry) { // The IsolatedStorageGroup object we construct here has dummy data for the Quota and Used Size, // But it doesn't really matter, since we won't use that information for anything. We just want // to use the Group's Remove method. (new IsolatedStorageGroup(groupName, 0, 0, groupRootPath)).Remove(); return FetchOrCreateGroup(groupName, out accountInfo, false); } else { throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_Init")); } } else { // We should ensure that the id.dat, quota.dat and used.dat files exist. if (!File.UnsafeExists(Path.Combine(groupRootPath, s_IdFileName))) { // We can simply recreate the id.dat file if it is missing File.UnsafeWriteAllText(Path.Combine(groupRootPath, s_IdFileName), groupName); } else { // Check for colision. if (!groupName.Equals(File.UnsafeReadAllText(Path.Combine(groupRootPath, s_IdFileName)))) { throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_Init")); } } if (!IsolatedStorageAccountingInfo.IsAccountingInfoValid(groupRootPath)) { // We'll delete all the stuff tied to this group and recreate these files. if (!DeleteStoresForGroup(obfuscatedGroupName)) { // We couldn't clean an existing store that belongs to this group. So we will fail to create the group, doing // so would mess up our bookkeeping information. throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_Init")); } } accountInfo = new IsolatedStorageAccountingInfo(groupRootPath); return groupRootPath; } } else { // We might be in a weird state where the "g" directory got deleted but there are stores still in that group around // This could happen if a someone deleted the "g" directory with Windows Explorer or Finder or something. We should // ensure there are no stores for this group here. if (!DeleteStoresForGroup(obfuscatedGroupName)) { // We couldn't clean an existing store that belongs to this group. So we will fail to create the group, doing // so would mess up our bookkeeping information. throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_Init")); } Directory.UnsafeCreateDirectory(groupRootPath); TouchFile(Path.Combine(groupRootPath, s_CleanupFileName)); File.UnsafeWriteAllText(Path.Combine(groupRootPath, s_IdFileName), groupName); File.UnsafeDelete(Path.Combine(groupRootPath, s_CleanupFileName)); accountInfo = new IsolatedStorageAccountingInfo(groupRootPath); return groupRootPath; } } catch(IOException e) { throw GetIsolatedStorageException("IsolatedStorage_Init", e); } catch (UnauthorizedAccessException e) { throw GetIsolatedStorageException("IsolatedStorage_Init", e); } finally { rootLock.Unlock(); } }
[System.Security.SecurityCritical] // auto-generated #endif private static string FetchOrCreateGroup(string groupName, out IsolatedStorageAccountingInfo accountInfo) { return FetchOrCreateGroup(groupName, out accountInfo, true); }
[System.Security.SecurityCritical] // auto-generated #endif public static IEnumerable<IsolatedStorageGroup> GetGroups() { List<IsolatedStorageGroup> groups = new List<IsolatedStorageGroup>(); #if !FEATURE_LEGACYNETCF try { foreach (string groupDir in Directory.UnsafeGetDirectories(Path.Combine(IsolatedStorageFile.IsolatedStorageRoot, IsolatedStorageFile.s_GroupPathPrefix), "*", SearchOption.TopDirectoryOnly)) { string idFile = Path.Combine(groupDir, IsolatedStorageFile.s_IdFileName); string id; FileLock groupLock = FileLock.GetFileLock(Path.Combine(IsolatedStorageFile.IsolatedStorageRoot, IsolatedStorageFile.s_LockPathPrefix), IsolatedStorageFile.s_GroupPathPrefix + "-" + DirectoryInfo.UnsafeCreateDirectoryInfo(groupDir).Name); try { groupLock.Lock(); if(!File.UnsafeExists(Path.Combine(groupDir, IsolatedStorageFile.s_CleanupFileName))) { id = File.UnsafeReadAllText(idFile); if (IsolatedStorageAccountingInfo.IsAccountingInfoValid(groupDir)) { using (IsolatedStorageAccountingInfo accountingInfo = new IsolatedStorageAccountingInfo(groupDir)) { groups.Add(new IsolatedStorageGroup(id, accountingInfo.Quota, accountingInfo.UsedSize, groupDir)); } } else { // In this case we've tried to deseriaize a group that doesn't have valid data. We'll try to remove it. try { new IsolatedStorageGroup(id, 0, 0, groupDir).Remove(); } catch (Exception) { // We couldn't remove the group for some reason. Ignore it and move on. } } } } catch (IOException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (UnauthorizedAccessException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } finally { groupLock.Unlock(); } } } catch (IOException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (UnauthorizedAccessException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } #else try { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { groups.Add(new IsolatedStorageGroup(isf.GroupName, Int64.MaxValue, 0, IsolatedStorageFile.IsolatedStorageRoot)); } } catch (IOException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (UnauthorizedAccessException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (IsolatedStorageException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } #endif return groups; }
[System.Security.SecurityCritical] // auto-generated #endif public static IEnumerable <IsolatedStorageGroup> GetGroups() { List <IsolatedStorageGroup> groups = new List <IsolatedStorageGroup>(); #if !FEATURE_LEGACYNETCF try { foreach (string groupDir in Directory.UnsafeGetDirectories(Path.Combine(IsolatedStorageFile.IsolatedStorageRoot, IsolatedStorageFile.s_GroupPathPrefix), "*", SearchOption.TopDirectoryOnly)) { string idFile = Path.Combine(groupDir, IsolatedStorageFile.s_IdFileName); string id; FileLock groupLock = FileLock.GetFileLock(Path.Combine(IsolatedStorageFile.IsolatedStorageRoot, IsolatedStorageFile.s_LockPathPrefix), IsolatedStorageFile.s_GroupPathPrefix + "-" + DirectoryInfo.UnsafeCreateDirectoryInfo(groupDir).Name); try { groupLock.Lock(); if (!File.UnsafeExists(Path.Combine(groupDir, IsolatedStorageFile.s_CleanupFileName))) { id = File.UnsafeReadAllText(idFile); if (IsolatedStorageAccountingInfo.IsAccountingInfoValid(groupDir)) { using (IsolatedStorageAccountingInfo accountingInfo = new IsolatedStorageAccountingInfo(groupDir)) { groups.Add(new IsolatedStorageGroup(id, accountingInfo.Quota, accountingInfo.UsedSize, groupDir)); } } else { // In this case we've tried to deseriaize a group that doesn't have valid data. We'll try to remove it. try { new IsolatedStorageGroup(id, 0, 0, groupDir).Remove(); } catch (Exception) { // We couldn't remove the group for some reason. Ignore it and move on. } } } } catch (IOException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (UnauthorizedAccessException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } finally { groupLock.Unlock(); } } } catch (IOException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (UnauthorizedAccessException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } #else try { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { groups.Add(new IsolatedStorageGroup(isf.GroupName, Int64.MaxValue, 0, IsolatedStorageFile.IsolatedStorageRoot)); } } catch (IOException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (UnauthorizedAccessException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (IsolatedStorageException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } #endif return(groups); }