-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change IsolatedStorageFile path for mobile (#83380)
Updated isolated storage root path for mobile platforms --------- Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
- Loading branch information
Showing
18 changed files
with
454 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.NonMobile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,68 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Threading; | ||
using System.Security; | ||
|
||
namespace System.IO.IsolatedStorage | ||
{ | ||
internal static partial class Helper | ||
{ | ||
public const string IsolatedStorageDirectoryName = "IsolatedStorage"; | ||
|
||
internal static string GetDataDirectory(IsolatedStorageScope scope) | ||
{ | ||
// This is the relevant special folder for the given scope plus IsolatedStorageDirectoryName. | ||
// It is meant to replicate the behavior of the VM ComIsolatedStorage::GetRootDir(). | ||
|
||
// (note that Silverlight used "CoreIsolatedStorage" for a directory name and did not support machine scope) | ||
|
||
Environment.SpecialFolder specialFolder = | ||
IsMachine(scope) ? Environment.SpecialFolder.CommonApplicationData : // e.g. C:\ProgramData | ||
IsRoaming(scope) ? Environment.SpecialFolder.ApplicationData : // e.g. C:\Users\Joe\AppData\Roaming | ||
Environment.SpecialFolder.LocalApplicationData; // e.g. C:\Users\Joe\AppData\Local | ||
|
||
string dataDirectory = Environment.GetFolderPath(specialFolder, Environment.SpecialFolderOption.Create); | ||
dataDirectory = Path.Combine(dataDirectory, IsolatedStorageDirectoryName); | ||
|
||
return dataDirectory; | ||
} | ||
|
||
internal static string GetRandomDirectory(string rootDirectory, IsolatedStorageScope scope) | ||
{ | ||
string? randomDirectory = GetExistingRandomDirectory(rootDirectory); | ||
if (string.IsNullOrEmpty(randomDirectory)) | ||
{ | ||
using (Mutex m = CreateMutexNotOwned(rootDirectory)) | ||
{ | ||
if (!m.WaitOne()) | ||
{ | ||
throw new IsolatedStorageException(SR.IsolatedStorage_Init); | ||
} | ||
|
||
try | ||
{ | ||
randomDirectory = GetExistingRandomDirectory(rootDirectory); | ||
if (string.IsNullOrEmpty(randomDirectory)) | ||
{ | ||
// Someone else hasn't created the directory before we took the lock | ||
randomDirectory = Path.Combine(rootDirectory, Path.GetRandomFileName(), Path.GetRandomFileName()); | ||
CreateDirectory(randomDirectory, scope); | ||
} | ||
} | ||
finally | ||
{ | ||
m.ReleaseMutex(); | ||
} | ||
} | ||
} | ||
|
||
return randomDirectory; | ||
} | ||
|
||
private static Mutex CreateMutexNotOwned(string pathName) | ||
{ | ||
return new Mutex(initiallyOwned: false, name: @"Global\" + IdentityHelper.GetStrongHashSuitableForObjectName(pathName)); | ||
} | ||
} | ||
} |
147 changes: 0 additions & 147 deletions
147
src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.