Skip to content

Commit

Permalink
74642 change isostorage path (#75541)
Browse files Browse the repository at this point in the history
* #74642 changed isolated storage path for mobile platforms
  • Loading branch information
mkhamoyan committed Sep 27, 2022
1 parent a7ae072 commit bc27a6a
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent)</TargetFrameworks>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
Expand All @@ -19,10 +19,18 @@
<Compile Include="$(CommonPath)System\Security\IdentityHelper.cs"
Link="Common\System\Security\IdentityHelper.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Android' or '$(TargetPlatformIdentifier)' == 'iOS' or '$(TargetPlatformIdentifier)' == 'MacCatalyst' or '$(TargetPlatformIdentifier)' == 'tvOS'">
<Compile Include="System\IO\IsolatedStorage\Helper.AnyMobile.cs" />
<Compile Include="System\IO\IsolatedStorage\IsolatedStorageFile.AnyMobile.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'Android' and '$(TargetPlatformIdentifier)' != 'iOS' and '$(TargetPlatformIdentifier)' != 'MacCatalyst' and '$(TargetPlatformIdentifier)' != 'tvOS' and '$(TargetPlatformIdentifier)' != ''">
<Compile Include="System\IO\IsolatedStorage\Helper.NonMobile.cs" />
<Compile Include="System\IO\IsolatedStorage\IsolatedStorageFile.NonMobile.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
<Compile Include="System\IO\IsolatedStorage\Helper.Win32.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Unix'">
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'windows'">
<Compile Include="System\IO\IsolatedStorage\Helper.Unix.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// 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.)
///
Expand All @@ -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.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Android</TargetFrameworks>
<IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI>
</PropertyGroup>
<ItemGroup>
Expand All @@ -17,7 +17,7 @@
<Compile Include="..\src\System\IO\IsolatedStorage\Helper.Win32.cs"
Link="Internals\Helper.Win32.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Unix' or '$(TargetPlatformIdentifier)' == 'Browser'">
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'windows'">
<Compile Include="..\src\System\IO\IsolatedStorage\Helper.Unix.cs"
Link="Internals\Helper.Unix.cs" />
</ItemGroup>
Expand Down Expand Up @@ -52,6 +52,14 @@
<Compile Include="System\IO\IsolatedStorage\OpenFileTests.cs" />
<Compile Include="System\IO\IsolatedStorage\TestHelper.cs" />
<Compile Include="System\IO\IsolatedStorage\RemoveTests.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Android' or '$(TargetPlatformIdentifier)' == 'iOS' or '$(TargetPlatformIdentifier)' == 'MacCatalyst' or '$(TargetPlatformIdentifier)' == 'tvOS'">
<Compile Include="..\src\System\IO\IsolatedStorage\Helper.AnyMobile.cs" />
<Compile Include="System\IO\IsolatedStorage\TestHelper.AnyMobile.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'Android' and '$(TargetPlatformIdentifier)' != 'iOS' and '$(TargetPlatformIdentifier)' != 'MacCatalyst' and '$(TargetPlatformIdentifier)' != 'tvOS' and '$(TargetPlatformIdentifier)' != ''">
<Compile Include="..\src\System\IO\IsolatedStorage\Helper.NonMobile.cs" />
<Compile Include="System\IO\IsolatedStorage\TestHelper.NonMobile.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.DirectoryServices\src\System.DirectoryServices.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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<string> GetRoots()
{
List<string> roots = new List<string>();
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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<string> GetRoots()
{
string hash;
object identity;
Helper.GetDefaultIdentityAndHash(out identity, out hash, '.');
List<string> roots = new List<string>();
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;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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<string> s_roots;
Expand All @@ -17,27 +17,8 @@ static TestHelper()
{
s_rootDirectoryProperty = typeof(IsolatedStorageFile).GetProperty("RootDirectory", BindingFlags.NonPublic | BindingFlags.Instance);

s_roots = new List<string>();

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);
}
Expand Down

0 comments on commit bc27a6a

Please sign in to comment.