Skip to content

Commit

Permalink
Merge pull request #56 from microsoft/noWinSdkFix
Browse files Browse the repository at this point in the history
Fix default images exception when Windows SDK is not installed.
  • Loading branch information
azchohfi authored Jun 28, 2024
2 parents 66e717f + a3fc161 commit 540727c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions MSStore.CLI/Helpers/ProjectImagesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static class ProjectImagesHelper
{
internal static List<string> GetDefaultImagesUsedByApp(List<string> appImagesFileList, List<string>? projectSpecificDefaultImagesFileList, IImageConverter imageConverter, ILogger logger)
{
List<string> defaultImagesFileList = GetDefaultImagesList();
List<string> defaultImagesFileList = GetDefaultImagesList(logger);
if (projectSpecificDefaultImagesFileList != null)
{
defaultImagesFileList.AddRange(projectSpecificDefaultImagesFileList);
Expand All @@ -44,25 +44,34 @@ internal static List<string> GetDefaultImagesUsedByApp(List<string> appImagesFil
return failedImages;
}

private static List<string> GetDefaultImagesList()
private static List<string> GetDefaultImagesList(ILogger logger)
{
var images = new List<string>();

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
images.AddRange(GetWindowsSdkDefaultImages());
images.AddRange(GetWindowsSdkDefaultImages(logger));
}

return images;
}

[SupportedOSPlatform("windows")]
private static string[] GetWindowsSdkDefaultImages()
private static string[] GetWindowsSdkDefaultImages(ILogger logger)
{
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
string defaultImagesDir = Path.Combine(programFiles, "Windows Kits", "10", "App Certification Kit", "DefaultAppImages");
if (Directory.Exists(defaultImagesDir))
{
return Directory.GetFiles(defaultImagesDir, "*.*", SearchOption.AllDirectories);
}

logger.LogWarning(
"Default images directory not found: '{DefaultImagesDir}'. " +
"This may be because the Windows SDK is not installed. " +
"We won't be able to check for default images.", defaultImagesDir);

return Directory.GetFiles(defaultImagesDir, "*.*", SearchOption.AllDirectories);
return Array.Empty<string>();
}

private static List<byte[]> GetHashesForImageFiles(List<string> imageFiles, IImageConverter imageConverter)
Expand Down

0 comments on commit 540727c

Please sign in to comment.