From 4a45d56330882a5e596e97d05ba568ec32e0603c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Provazn=C3=ADk?= Date: Tue, 18 Jun 2024 16:25:07 +0200 Subject: [PATCH] Log Registry LongPathsEnabled in v:diagnostic (#10223) * Add a message for LongPathsEnabled * refactor LongPathsEnabled logic to a ternary enum * Elaborate and comment the resource string * translations * add state for registry not set * deduplicate --- src/Framework/NativeMethods.cs | 57 +++++++++++++++++-- src/MSBuild/Resources/Strings.resx | 13 +++++ src/MSBuild/Resources/xlf/Strings.cs.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.de.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.es.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.fr.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.it.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.ja.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.ko.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.pl.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.pt-BR.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.ru.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.tr.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf | 20 +++++++ src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf | 20 +++++++ src/MSBuild/XMake.cs | 14 ++++- 16 files changed, 337 insertions(+), 7 deletions(-) diff --git a/src/Framework/NativeMethods.cs b/src/Framework/NativeMethods.cs index 3cd7934c726..63888fd973b 100644 --- a/src/Framework/NativeMethods.cs +++ b/src/Framework/NativeMethods.cs @@ -594,25 +594,70 @@ private static void SetMaxPath() } } - internal static bool IsMaxPathLegacyWindows() + internal enum LongPathsStatus + { + /// + /// The registry key is set to 0 or does not exist. + /// + Disabled, + + /// + /// The registry key does not exist. + /// + Missing, + + /// + /// The registry key is set to 1. + /// + Enabled, + + /// + /// Not on Windows. + /// + NotApplicable, + } + + internal static LongPathsStatus IsLongPathsEnabled() { + if (!IsWindows) + { + return LongPathsStatus.NotApplicable; + } + try { - return IsWindows && !IsLongPathsEnabledRegistry(); + return IsLongPathsEnabledRegistry(); } catch { - return true; + return LongPathsStatus.Disabled; } } + internal static bool IsMaxPathLegacyWindows() + { + var longPathsStatus = IsLongPathsEnabled(); + return longPathsStatus == LongPathsStatus.Disabled || longPathsStatus == LongPathsStatus.Missing; + } + [SupportedOSPlatform("windows")] - private static bool IsLongPathsEnabledRegistry() + private static LongPathsStatus IsLongPathsEnabledRegistry() { using (RegistryKey fileSystemKey = Registry.LocalMachine.OpenSubKey(WINDOWS_FILE_SYSTEM_REGISTRY_KEY)) { - object longPathsEnabledValue = fileSystemKey?.GetValue(WINDOWS_LONG_PATHS_ENABLED_VALUE_NAME, 0); - return fileSystemKey != null && Convert.ToInt32(longPathsEnabledValue) == 1; + object longPathsEnabledValue = fileSystemKey?.GetValue(WINDOWS_LONG_PATHS_ENABLED_VALUE_NAME, -1); + if (fileSystemKey != null && Convert.ToInt32(longPathsEnabledValue) == -1) + { + return LongPathsStatus.Missing; + } + else if (fileSystemKey != null && Convert.ToInt32(longPathsEnabledValue) == 1) + { + return LongPathsStatus.Enabled; + } + else + { + return LongPathsStatus.Disabled; + } } } diff --git a/src/MSBuild/Resources/Strings.resx b/src/MSBuild/Resources/Strings.resx index 1129806b5c5..5dba823befb 100644 --- a/src/MSBuild/Resources/Strings.resx +++ b/src/MSBuild/Resources/Strings.resx @@ -1661,6 +1661,19 @@ succeeded: {0} {0} whole number + + Based on the Windows registry key LongPathsEnabled, the LongPaths feature is {0}. + "Windows" is the OS, "LongPathsEnabled" should not be localized, and {0} will be "enabled"/"disabled"/"not set" + + + enabled + + + disabled + + + not set +