diff --git a/src/libraries/System.IO.IsolatedStorage/src/System.IO.IsolatedStorage.csproj b/src/libraries/System.IO.IsolatedStorage/src/System.IO.IsolatedStorage.csproj index 9b5284960f9ae3..2309a8c007ab3f 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System.IO.IsolatedStorage.csproj +++ b/src/libraries/System.IO.IsolatedStorage/src/System.IO.IsolatedStorage.csproj @@ -1,6 +1,6 @@ - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent) + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent) @@ -19,10 +19,18 @@ + + + + + + + + - + diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.AnyMobile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.AnyMobile.cs new file mode 100644 index 00000000000000..4121814515fe67 --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.AnyMobile.cs @@ -0,0 +1,10 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.IO.IsolatedStorage +{ + internal static partial class Helper + { + public const string IsolatedStorageDirectoryName = ".isolated-storage"; + } +} diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.NonMobile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.NonMobile.cs new file mode 100644 index 00000000000000..cde27b6c5e27c4 --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.NonMobile.cs @@ -0,0 +1,10 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.IO.IsolatedStorage +{ + internal static partial class Helper + { + public const string IsolatedStorageDirectoryName = "IsolatedStorage"; + } +} diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs index 5a55e866789ee1..7577ea7ee0495b 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs @@ -12,7 +12,7 @@ internal static partial class Helper { internal static string GetDataDirectory(IsolatedStorageScope scope) { - // This is the relevant special folder for the given scope plus "IsolatedStorage". + // 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) diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.cs index 3b5d6b6afbc7c5..984eeed4046067 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.cs @@ -5,14 +5,12 @@ namespace System.IO.IsolatedStorage { internal static partial class Helper { - private const string IsolatedStorageDirectoryName = "IsolatedStorage"; - private static string? s_machineRootDirectory; private static string? s_roamingUserRootDirectory; private static string? s_userRootDirectory; /// - /// The full root directory is the relevant special folder from Environment.GetFolderPath() plus "IsolatedStorage" + /// The full root directory is the relevant special folder from Environment.GetFolderPath() plus IsolatedStorageDirectoryName /// and a set of random directory names if not roaming. (The random directories aren't created for WinRT as /// the FolderPath locations for WinRT are app isolated already.) /// @@ -21,6 +19,8 @@ internal static partial class Helper /// User: @"C:\Users\jerem\AppData\Local\IsolatedStorage\10v31ho4.bo2\eeolfu22.f2w\" /// User|Roaming: @"C:\Users\jerem\AppData\Roaming\IsolatedStorage\" /// Machine: @"C:\ProgramData\IsolatedStorage\nin03cyc.wr0\o3j0urs3.0sn\" + /// Android path: "/data/user/0/net.dot.System.IO.IsolatedStorage.Tests/files/.config/.isolated-storage/" + /// iOS path: "/var/mobile/Containers/Data/Application/A323CBB9-A2B3-4432-9449-48CC20C07A7D/Documents/.config/.isolated-storage/" /// /// Identity for the current store gets tacked on after this. /// diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.AnyMobile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.AnyMobile.cs new file mode 100644 index 00000000000000..69a2f706779084 --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.AnyMobile.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.IO.IsolatedStorage +{ + public sealed partial class IsolatedStorageFile : IsolatedStorage, IDisposable + { + private string GetIsolatedStorageRoot() + { + return Helper.GetRootDirectory(Scope); + } + } +} diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.NonMobile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.NonMobile.cs new file mode 100644 index 00000000000000..4f547d55cff2f6 --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.NonMobile.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Text; + +namespace System.IO.IsolatedStorage +{ + public sealed partial class IsolatedStorageFile : IsolatedStorage, IDisposable + { + private string GetIsolatedStorageRoot() + { + StringBuilder root = new StringBuilder(Helper.GetRootDirectory(Scope)); + root.Append(SeparatorExternal); + root.Append(IdentityHash); + + return root.ToString(); + } + } +} diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs index 0f024ca64fb23f..4afd6468ceaa3c 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs @@ -43,9 +43,7 @@ internal IsolatedStorageFile(IsolatedStorageScope scope) // InitStore will set up the IdentityHash InitStore(scope, null, null); - StringBuilder sb = new StringBuilder(Helper.GetRootDirectory(scope)); - sb.Append(SeparatorExternal); - sb.Append(IdentityHash); + StringBuilder sb = new StringBuilder(GetIsolatedStorageRoot()); sb.Append(SeparatorExternal); if (Helper.IsApplication(scope)) diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj b/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj index b075376fa8bf89..0410513c46ceb1 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj +++ b/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj @@ -1,6 +1,6 @@ - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Android true @@ -17,7 +17,7 @@ - + @@ -52,6 +52,14 @@ + + + + + + + + diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/HelperTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/HelperTests.cs index 2fe50e59055320..60d65949da7ee2 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/HelperTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/HelperTests.cs @@ -45,7 +45,7 @@ public void GetDataDirectory(IsolatedStorageScope scope) return; string path = Helper.GetDataDirectory(scope); - Assert.Equal("IsolatedStorage", Path.GetFileName(path)); + Assert.Equal(Helper.IsolatedStorageDirectoryName, Path.GetFileName(path)); } } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.AnyMobile.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.AnyMobile.cs new file mode 100644 index 00000000000000..63709fd41ab837 --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.AnyMobile.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Reflection; +using System.Collections.Generic; + +namespace System.IO.IsolatedStorage +{ + public static partial class TestHelper + { + private static List GetRoots() + { + List roots = new List(); + string userRoot = Helper.GetDataDirectory(IsolatedStorageScope.User); + string randomUserRoot = Helper.GetRandomDirectory(userRoot, IsolatedStorageScope.User); + roots.Add(randomUserRoot); + + // Application scope doesn't go under a random dir + roots.Add(userRoot); + return roots; + } + } +} diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.NonMobile.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.NonMobile.cs new file mode 100644 index 00000000000000..e0217dc241a5a9 --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.NonMobile.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Reflection; +using System.Collections.Generic; + +namespace System.IO.IsolatedStorage +{ + public static partial class TestHelper + { + private static List GetRoots() + { + string hash; + object identity; + Helper.GetDefaultIdentityAndHash(out identity, out hash, '.'); + List roots = new List(); + string userRoot = Helper.GetDataDirectory(IsolatedStorageScope.User); + string randomUserRoot = Helper.GetRandomDirectory(userRoot, IsolatedStorageScope.User); + + roots.Add(Path.Combine(randomUserRoot, hash)); + // Application scope doesn't go under a random dir + roots.Add(Path.Combine(userRoot, hash)); + + // https://github.com/dotnet/runtime/issues/2092 + // https://github.com/dotnet/runtime/issues/21742 + if (OperatingSystem.IsWindows() + && !PlatformDetection.IsInAppContainer) + { + roots.Add(Helper.GetDataDirectory(IsolatedStorageScope.Machine)); + } + + return roots; + } + } +} + \ No newline at end of file diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.cs index e3e7f423a7b734..06339504237ddd 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.cs @@ -8,7 +8,7 @@ namespace System.IO.IsolatedStorage { - public static class TestHelper + public static partial class TestHelper { private static PropertyInfo s_rootDirectoryProperty; private static List s_roots; @@ -17,27 +17,8 @@ static TestHelper() { s_rootDirectoryProperty = typeof(IsolatedStorageFile).GetProperty("RootDirectory", BindingFlags.NonPublic | BindingFlags.Instance); - s_roots = new List(); - - string hash; - object identity; - Helper.GetDefaultIdentityAndHash(out identity, out hash, '.'); - - string userRoot = Helper.GetDataDirectory(IsolatedStorageScope.User); - string randomUserRoot = Helper.GetRandomDirectory(userRoot, IsolatedStorageScope.User); - s_roots.Add(Path.Combine(randomUserRoot, hash)); - - // Application scope doesn't go under a random dir - s_roots.Add(Path.Combine(userRoot, hash)); - - // https://github.com/dotnet/runtime/issues/2092 - // https://github.com/dotnet/runtime/issues/21742 - if (OperatingSystem.IsWindows() - && !PlatformDetection.IsInAppContainer) - { - s_roots.Add(Helper.GetDataDirectory(IsolatedStorageScope.Machine)); - } - + s_roots = GetRoots(); + // We don't expose Roaming yet // Helper.GetDataDirectory(IsolatedStorageScope.Roaming); }