Skip to content

Commit 9ec5a71

Browse files
Code Quality: Prevent crash when setting invalid files as lock screen wallpaper (#17779)
Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com> Co-authored-by: Yair <[email protected]>
1 parent 9fe7b3b commit 9ec5a71

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/Files.App/Services/Windows/WindowsWallpaperService.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public unsafe void SetDesktopWallpaper(string szPath)
1818
{
1919
// Instantiate IDesktopWallpaper
2020
using ComPtr<IDesktopWallpaper> pDesktopWallpaper = default;
21-
HRESULT hr = pDesktopWallpaper.CoCreateInstance(CLSID.CLSID_DesktopWallpaper).ThrowOnFailure();
21+
HRESULT hr = pDesktopWallpaper.CoCreateInstance(CLSID.CLSID_DesktopWallpaper);
2222

2323
// Get total count of all available monitors
24-
hr = pDesktopWallpaper.Get()->GetMonitorDevicePathCount(out var dwMonitorCount).ThrowOnFailure();
24+
hr = pDesktopWallpaper.Get()->GetMonitorDevicePathCount(out var dwMonitorCount);
2525

2626
fixed (char* pszPath = szPath)
2727
{
@@ -31,8 +31,8 @@ public unsafe void SetDesktopWallpaper(string szPath)
3131
for (uint dwIndex = 0u; dwIndex < dwMonitorCount; dwIndex++)
3232
{
3333
// Set the wallpaper
34-
hr = pDesktopWallpaper.Get()->GetMonitorDevicePathAt(dwIndex, &pMonitorId).ThrowOnFailure();
35-
hr = pDesktopWallpaper.Get()->SetWallpaper(pMonitorId, pszPath).ThrowOnFailure();
34+
hr = pDesktopWallpaper.Get()->GetMonitorDevicePathAt(dwIndex, &pMonitorId);
35+
hr = pDesktopWallpaper.Get()->SetWallpaper(pMonitorId, pszPath);
3636

3737
pMonitorId = default;
3838
}
@@ -44,7 +44,7 @@ public unsafe void SetDesktopSlideshow(string[] aszPaths)
4444
{
4545
// Instantiate IDesktopWallpaper
4646
using ComPtr<IDesktopWallpaper> pDesktopWallpaper = default;
47-
HRESULT hr = pDesktopWallpaper.CoCreateInstance(CLSID.CLSID_DesktopWallpaper).ThrowOnFailure();
47+
HRESULT hr = pDesktopWallpaper.CoCreateInstance(CLSID.CLSID_DesktopWallpaper);
4848

4949
uint dwCount = (uint)aszPaths.Length;
5050
ITEMIDLIST** ppItemIdList = stackalloc ITEMIDLIST*[aszPaths.Length];
@@ -55,15 +55,15 @@ public unsafe void SetDesktopSlideshow(string[] aszPaths)
5555

5656
// Get an IShellItemArray from the array of the PIDL
5757
using ComPtr<IShellItemArray> pShellItemArray = default;
58-
hr = PInvoke.SHCreateShellItemArrayFromIDLists(dwCount, ppItemIdList, pShellItemArray.GetAddressOf()).ThrowOnFailure();
58+
hr = PInvoke.SHCreateShellItemArrayFromIDLists(dwCount, ppItemIdList, pShellItemArray.GetAddressOf());
5959

6060
// Release the allocated PIDL
6161
for (uint dwIndex = 0u; dwIndex < dwCount; dwIndex++)
6262
PInvoke.CoTaskMemFree((void*)ppItemIdList[dwIndex]);
6363

6464
// Set the slideshow and its position
65-
hr = pDesktopWallpaper.Get()->SetSlideshow(pShellItemArray.Get()).ThrowOnFailure();
66-
hr = pDesktopWallpaper.Get()->SetPosition(DESKTOP_WALLPAPER_POSITION.DWPOS_FILL).ThrowOnFailure();
65+
hr = pDesktopWallpaper.Get()->SetSlideshow(pShellItemArray.Get());
66+
hr = pDesktopWallpaper.Get()->SetPosition(DESKTOP_WALLPAPER_POSITION.DWPOS_FILL);
6767
}
6868

6969
/// <inheritdoc/>

0 commit comments

Comments
 (0)