Hey all. Here's a random Q for you:
What do you do when looking for a temporary directory?
The Windows
GetTempPath() function returns the following:
1. The path specified by the TMP environment variable.
2. The path specified by the TEMP environment variable, if TMP is not defined.
3. The current directory, if both TMP and TEMP are not defined.
4. An error. |
Unfortunately for this to work, it requires that the user's environment have the following characteristic:
a valid, writable directory must be specified by the given environment variable(s). |
Otherwise you are just as bad off if the function returns the third or fourth outcome.
So, what is the likelihood that the user has boogered his system sufficiently that this will fail? (I don't trust the user.) And if he has, what do you recommend using instead?
I was considering the SP_CACHE (temporary internet files) directory, since that is automatically cleaned regularly... (unlike the TMP/TEMP directory, which Windows never seems to touch).
I was also considering just putting it under SP_LOCALAPPDATA (Local Application Data) as an appropriately named subdirectory...
Have any of you had to deal with this before?
What say ye?
(The question came to mind because of the possibility that a fatal error handler may wish to use a temporary file... so simply having the application fail is not a proper response when the user gets the "fatal error, want to send a report?" dialog.)