internal static string FixProductName()

in JetBrains.HabitatDetector/src/Impl/Windows/WindowsHelper.cs [191:238]


    internal static string FixProductName(string productName, uint buildNumber)
    {
      // Windows 10:
      //   | Build | Workstation | Server    |
      //   +=======+=============+===========+
      //   | 10240 |   10 1507   | --------- |
      //   | 10586 |      1511   | --------- |
      //   | 14393 |      1607   | 2016 1607 |
      //   | 15063 |      1703   | --------- |
      //   | 16299 |      1709   |      1709 |
      //   | 17134 |      1803   |      1803 |
      //   | 17763 |      1809   | 2019 1809 |
      //   | 18362 |      1903   |      1903 |
      //   | 18363 |      1909   |      1909 |
      //   | 19041 |      2004   |      2004 |
      //   | 19042 |      20H2   |      20H2 |
      //   | 19043 |      21H1   | --------- |
      //   | 19044 |      21H2   | --------- |
      //   | 19045 |      22H2   | --------- |
      //   | 20348 | ----------- | 2022 21H2 |
      //   | 22000 |   11 21H2   | --------- |
      //   | 22621 |      22H2   | --------- |
      //   | 22631 |      23H2   | --------- |
      //   | 25398 | ----------- |      23H2 |
      //   | 26100 |      23H2   | 2025 24H2 |

      // See https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions

      // Note(ww898): The `product_name` for Windows Vista has `(TM)` in name, so remove it!
      productName = productName.Replace(" (TM)", "");

      // Note(ww898): Fix OS name because we want to avoid COM WMI calls!!!
      if (productName.IndexOf(" Server", StringComparison.Ordinal) != -1)
      {
        if (buildNumber >= 14393 && !Regex.IsMatch(productName, @"Server \d+"))
          productName = productName.Replace("Server", buildNumber >= 20348 ? "Server 2022" : buildNumber >= 17763 ? "Server 2019" : "Server 2016");
      }
      else
      {
        if (buildNumber >= 22000)
          productName = productName.Replace("Windows 10", "Windows 11");

        if (buildNumber >= 10240 && !Regex.IsMatch(productName, @"Windows \d+"))
          productName = productName.Replace("Windows", buildNumber >= 22000 ? "Windows 11" : "Windows 10");
      }

      return productName;
    }