+ /* PathName MUST BE a path. Check it */
+ lpTempFileName[(PathNameString.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL;
+ FileAttributes = GetFileAttributesW(lpTempFileName);
+ if (FileAttributes == INVALID_FILE_ATTRIBUTES)
+ {
+ /* Append a '\' if necessary */
+ lpTempFileName[(PathNameString.Length / sizeof(WCHAR)) - 1] = L'\\';
+ lpTempFileName[PathNameString.Length / sizeof(WCHAR)] = UNICODE_NULL;
+ FileAttributes = GetFileAttributesW(lpTempFileName);
+ if (FileAttributes == INVALID_FILE_ATTRIBUTES)
+ {
+ SetLastError(ERROR_DIRECTORY);
+ return 0;
+ }
+ }
+ if (!(FileAttributes & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ SetLastError(ERROR_DIRECTORY);
+ return 0;
+ }
+
+ /* Make sure not to mix path & prefix */
+ lpTempFileName[(PathNameString.Length / sizeof(WCHAR)) - 1] = L'\\';
+ RtlInitUnicodeString(&PrefixString, lpPrefixString);
+ if (PrefixString.Length > 3 * sizeof(WCHAR))
+ {
+ PrefixString.Length = 3 * sizeof(WCHAR);
+ }
+
+ /* Append prefix to path */
+ TempFileName = lpTempFileName + PathNameString.Length / sizeof(WCHAR);
+ memmove(TempFileName, PrefixString.Buffer, PrefixString.Length);
+ TempFileName += PrefixString.Length / sizeof(WCHAR);
+
+ /* Then, generate filename */
+ do
+ {
+ /* If user didn't gave any ID, ask Csrss to give one */
+ if (!uUnique)
+ {
+ CsrClientCallServer(&ApiMessage, NULL, MAKE_CSR_API(GET_TEMP_FILE, CSR_NATIVE), sizeof(CSR_API_MESSAGE));
+ if (ApiMessage.Data.GetTempFile.UniqueID == 0)
+ {
+ Num++;
+ continue;
+ }
+
+ ID = ApiMessage.Data.GetTempFile.UniqueID;
+ }
+ else
+ {
+ ID = uUnique;
+ }
+
+ /* Convert that ID to wchar */
+ RtlIntegerToChar(ID, 0x10, sizeof(IDString), IDString);
+ Let = IDString;