Skip to content

Commit

Permalink
Use Environment.SpecialFolder.UserProfile, not SpecialFolder.Personal (
Browse files Browse the repository at this point in the history
…#194)

Context: dotnet/runtime#68610

In Mono and .NET prior to .NET 8, the
[`System.Environment.SpecialFolder`][0]`.Personal` enum value would
refer to `$HOME` on Unix platforms.

This will be changing in .NET 8, such that
`Environment.SpecialFolder.Personal` will instead refer to
`$XDG_DOCUMENTS_DIR` (if set) or `$HOME/Documents`.  This is for
"semantic compatibility" with .NET on Windows.

Replace usage of `Environment.SpecialFolder.Personal` with
`Environment.SpecialFolder.UserProfile`, so that our code continues
to work as expected under .NET 8.

[0]: https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-6.0
  • Loading branch information
eerhardt authored Sep 15, 2022
1 parent 29f11f2 commit 0be567a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static IEnumerable<string> GetMacOSMicrosoftDistJdkPaths ()
var jdks = AppDomain.CurrentDomain.GetData ($"GetMacOSMicrosoftJdkPaths jdks override! {typeof (JdkInfo).AssemblyQualifiedName}")
?.ToString ();
if (jdks == null) {
var home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
var home = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
jdks = Path.Combine (home, "Library", "Developer", "Xamarin", "jdk");
}
if (!Directory.Exists (jdks))
Expand Down
6 changes: 3 additions & 3 deletions src/Xamarin.Android.Tools.AndroidSdk/OS.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.IO;
Expand Down Expand Up @@ -69,15 +69,15 @@ static string GetProgramFilesX86 ()
internal static string GetXamarinAndroidCacheDir ()
{
if (IsMac) {
var home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
var home = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
return Path.Combine (home, "Library", "Caches", "Xamarin.Android");
} else if (IsWindows) {
var localAppData = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
return Path.Combine (localAppData, "Xamarin.Android", "Cache");
} else {
var home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
var xdgCacheHome = Environment.GetEnvironmentVariable ("XDG_CACHE_HOME");
if (string.IsNullOrEmpty (xdgCacheHome)) {
var home = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
xdgCacheHome = Path.Combine (home, ".cache");
}
return Path.Combine (xdgCacheHome, "Xamarin.Android");
Expand Down
4 changes: 2 additions & 2 deletions src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkUnix.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -111,7 +111,7 @@ protected override IEnumerable<string> GetAllAvailableAndroidSdks ()
}

// Check some hardcoded paths for good measure
var macSdkPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "Library", "Android", "sdk");
var macSdkPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.UserProfile), "Library", "Android", "sdk");
yield return macSdkPath;
}

Expand Down

0 comments on commit 0be567a

Please sign in to comment.