Skip to content

Commit

Permalink
Log Registry LongPathsEnabled in v:diagnostic (#10223)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JanProvaznik authored Jun 18, 2024
1 parent 0a3683c commit 4a45d56
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 7 deletions.
57 changes: 51 additions & 6 deletions src/Framework/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,25 +594,70 @@ private static void SetMaxPath()
}
}

internal static bool IsMaxPathLegacyWindows()
internal enum LongPathsStatus
{
/// <summary>
/// The registry key is set to 0 or does not exist.
/// </summary>
Disabled,

/// <summary>
/// The registry key does not exist.
/// </summary>
Missing,

/// <summary>
/// The registry key is set to 1.
/// </summary>
Enabled,

/// <summary>
/// Not on Windows.
/// </summary>
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;
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/MSBuild/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,19 @@
<value>succeeded: {0}</value>
<comment>{0} whole number</comment>
</data>
<data name="LongPaths" xml:space="preserve">
<value>Based on the Windows registry key LongPathsEnabled, the LongPaths feature is {0}.</value>
<comment>"Windows" is the OS, "LongPathsEnabled" should not be localized, and {0} will be "enabled"/"disabled"/"not set"</comment>
</data>
<data name="LongPaths_Enabled" xml:space="preserve">
<value>enabled</value>
</data>
<data name="LongPaths_Disabled" xml:space="preserve">
<value>disabled</value>
</data>
<data name="LongPaths_Missing" xml:space="preserve">
<value>not set</value>
</data>
<!-- **** TerminalLogger strings end **** -->
<!--
The command line message bucket is: MSB1001 - MSB1999
Expand Down
20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a45d56

Please sign in to comment.