Repository: microsoft/PowerToys
File: src/modules/launcher/Wox.Infrastructure/Image/ImageLoader.cs (C#)

Code before:
            ".ico",
        };

        // Checks whether it is a valid PNG by checking the 8 bytes at the beginning of the file.
        public static bool IsValidPngSignature(string filePath)
        {
            byte[] pngSignature = { 137, 80, 78, 71, 13, 10, 26, 10 };
            byte[] buffer = new byte[8];

            using FileStream fs = new(filePath, FileMode.Open, FileAccess.Read);
            return fs.Read(buffer, 0, buffer.Length) == buffer.Length && pngSignature.SequenceEqual(buffer);
        }

        public static void Initialize(Theme theme)
        {
            _hashGenerator = new ImageHashGenerator();

            foreach (var icon in new[] { Constant.ErrorIcon, Constant.LightThemedErrorIcon })
            {
                var uri = new Uri(icon);

                try
                {
                    if (File.Exists(uri.LocalPath) && IsValidPngSignature(uri.LocalPath))
                    {
                        Log.Info($"Image file '{icon}' is a valid PNG.", MethodBase.GetCurrentMethod().DeclaringType);

                        BitmapImage bmi = new BitmapImage();
                        bmi.BeginInit();
                        bmi.UriSource = uri;
                        bmi.CacheOption = BitmapCacheOption.OnLoad;
                        bmi.EndInit();
                        ImageSource img = bmi;
                        img.Freeze();
                        ImageCache[icon] = img;
                    }
                    else
                    {
                        Log.Error($"Image file '{icon}' is not a valid PNG.", MethodBase.GetCurrentMethod().DeclaringType);
                    }
                }
                catch (COMException comEx)
                {
                    Log.Exception($"COMException was thrown in {uri.LocalPath} file.", comEx, MethodBase.GetCurrentMethod().DeclaringType);
                }
            }

            UpdateIconPath(theme);
            Task.Run(() =>
            {
                Stopwatch.Normal("ImageLoader.Initialize - Preload images cost", async () =>

Review comment (bug):
Only `debug` or remove it. We should not spam the log file.

Code after:
            ".ico",
        };

        // Checks whether it is a valid PNG by checking the 8 bytes at the beginning of the file.
        public static bool IsValidPngSignature(string filePath)
        {
            byte[] pngSignature = { 137, 80, 78, 71, 13, 10, 26, 10 };
            byte[] buffer = new byte[8];

            using FileStream fs = new(filePath, FileMode.Open, FileAccess.Read);
            return fs.Read(buffer, 0, buffer.Length) == buffer.Length && pngSignature.SequenceEqual(buffer);
        }

        public static void Initialize(Theme theme)
        {
            _hashGenerator = new ImageHashGenerator();

            foreach (var icon in new[] { Constant.ErrorIcon, Constant.LightThemedErrorIcon })
            {
                var uri = new Uri(icon);

                try
                {
                    if (File.Exists(uri.LocalPath) && IsValidPngSignature(uri.LocalPath))
                    {
                        BitmapImage bmi = new BitmapImage();
                        bmi.BeginInit();
                        bmi.UriSource = uri;
                        bmi.CacheOption = BitmapCacheOption.OnLoad;
                        bmi.EndInit();
                        ImageSource img = bmi;
                        img.Freeze();
                        ImageCache[icon] = img;
                    }
                    else
                    {
                        Log.Error($"Image file '{icon}' is not a valid PNG.", MethodBase.GetCurrentMethod().DeclaringType);
                    }
                }
                catch (COMException comEx)
                {
                    Log.Exception($"COMException was thrown in {uri.LocalPath} file.", comEx, MethodBase.GetCurrentMethod().DeclaringType);
                }
            }

            UpdateIconPath(theme);
            Task.Run(() =>
            {
                Stopwatch.Normal("ImageLoader.Initialize - Preload images cost", async () =>
                {
                    foreach (var (path, _) in ImageCache.Usage)