Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using MS.Internal;
using System.Net;
using System.Net.Cache;
using System.Text;
using MS.Win32;
using Microsoft.Win32.SafeHandles;

Expand Down Expand Up @@ -111,16 +110,13 @@ Stream stream
entry.inputUri = uri;
entry.inputStream = stream;

string cacheFolder = MS.Win32.WinInet.InternetCacheFolder.LocalPath;
bool passed = false;

// Get the file path
StringBuilder tmpFileName = new StringBuilder(NativeMethods.MAX_PATH);
MS.Win32.UnsafeNativeMethods.GetTempFileName(cacheFolder, "WPF", 0, tmpFileName);

try
{
string pathToUse = tmpFileName.ToString();
// Use Path.GetTempFileName whose .NET 8+ implementation avoids the
// Win32 GetTempFileName 65k file limit by generating random filenames.
string pathToUse = Path.GetTempFileName();
SafeFileHandle fileHandle = MS.Win32.UnsafeNativeMethods.CreateFile(
pathToUse,
dwDesiredAccess: NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE,
Expand All @@ -135,7 +131,7 @@ Stream stream
{
throw new Win32Exception();
}

entry.outputStream = new FileStream(fileHandle, FileAccess.ReadWrite);
entry.streamPath = pathToUse;
passed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ namespace MS.Win32
{
internal partial class UnsafeNativeMethods
{
[DllImport(ExternDll.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, EntryPoint = "GetTempFileName")]
internal static extern uint _GetTempFileName(string tmpPath, string prefix, uint uniqueIdOrZero, StringBuilder tmpFileName);

internal static uint GetTempFileName(string tmpPath, string prefix, uint uniqueIdOrZero, StringBuilder tmpFileName)
{
uint result = _GetTempFileName(tmpPath, prefix, uniqueIdOrZero, tmpFileName);
if (result == 0)
{
throw new Win32Exception();
}

return result;
}

[DllImport(ExternDll.Shell32, CharSet = CharSet.Auto, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern int ExtractIconEx(
string szExeFileName,
Expand Down