Changes for using nsSpecialSystemDirectory directory - Bug #18021 - r: jefft

This commit is contained in:
rhp%netscape.com 1999-11-20 03:14:13 +00:00
Родитель b823e0340c
Коммит 74d7368d51
5 изменённых файлов: 29 добавлений и 113 удалений

Просмотреть файл

@ -65,7 +65,10 @@ nsMsgCreateTempFileSpec(char *tFileName)
tFileName = "nsmail.tmp";
nsFileSpec *tmpSpec = new nsFileSpec(nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_TemporaryDirectory));
if (!tmpSpec)
return nsnull;
*tmpSpec += tFileName;
tmpSpec->MakeUnique();

Просмотреть файл

@ -31,6 +31,7 @@
#include "nsIIOService.h"
#include "nsIURI.h"
#include "prprf.h"
#include "nsSpecialSystemDirectory.h"
extern "C" PRBool
EmitThisHeaderForPrefSetting(PRInt32 dispType, const char *header)
@ -86,44 +87,6 @@ EmitThisHeaderForPrefSetting(PRInt32 dispType, const char *header)
//
#define TPATH_LEN 1024
#ifdef WIN32
#include "windows.h"
#endif
char *
GetTheTempDirectoryOnTheSystem(void)
{
char *retPath = (char *)PR_Malloc(TPATH_LEN);
if (!retPath)
return nsnull;
retPath[0] = '\0';
#ifdef WIN32
if (getenv("TEMP"))
PL_strncpy(retPath, getenv("TEMP"), TPATH_LEN); // environment variable
else if (getenv("TMP"))
PL_strncpy(retPath, getenv("TMP"), TPATH_LEN); // How about this environment variable?
else
GetWindowsDirectory(retPath, TPATH_LEN);
#endif
// RICHIE - should do something better here!
#if defined(XP_UNIX) || defined(XP_BEOS)
char *tPath = getenv("TMPDIR");
if (!tPath)
PL_strncpy(retPath, "/tmp/", TPATH_LEN);
else
PL_strncpy(retPath, tPath, TPATH_LEN);
#endif
#ifdef XP_MAC
PL_strncpy(retPath, "", TPATH_LEN);
#endif
return retPath;
}
//
// Create a file spec for the a unique temp file
// on the local machine. Caller must free memory
@ -132,24 +95,15 @@ nsFileSpec *
nsMsgCreateTempFileSpec(char *tFileName)
{
if ((!tFileName) || (!*tFileName))
tFileName = "nsmail.tmp";
tFileName = "emitter.tmp";
// Age old question, where to store temp files....ugh!
char *tDir = GetTheTempDirectoryOnTheSystem();
if (!tDir)
return (new nsFileSpec("mozmail.tmp")); // No need to I18N
nsFileSpec *tmpSpec = new nsFileSpec(tDir);
nsFileSpec *tmpSpec = new nsFileSpec(nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_TemporaryDirectory));
if (!tmpSpec)
{
PR_FREEIF(tDir);
return (new nsFileSpec("mozmail.tmp")); // No need to I18N
}
return nsnull;
*tmpSpec += tFileName;
tmpSpec->MakeUnique();
PR_FREEIF(tDir);
return tmpSpec;
}
@ -164,17 +118,17 @@ nsMsgCreateTempFileName(char *tFileName)
if ((!tFileName) || (!*tFileName))
tFileName = "nsmail.tmp";
nsFileSpec *tmpSpec = new nsFileSpec(nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_TemporaryDirectory));
// Age old question, where to store temp files....ugh!
char *tDir = GetTheTempDirectoryOnTheSystem();
if (!tDir)
if (!tmpSpec)
return "mozmail.tmp"; // No need to I18N
nsFileSpec tmpSpec(tDir);
tmpSpec += tFileName;
tmpSpec.MakeUnique();
*tmpSpec += tFileName;
tmpSpec->MakeUnique();
PR_FREEIF(tDir);
char *tString = (char *)nsCRT::strdup(tmpSpec.GetNativePathCString());
char *tString = (char *)nsCRT::strdup(tmpSpec->GetNativePathCString());
delete tmpSpec;
if (!tString)
return nsCRT::strdup("mozmail.tmp"); // No need to I18N
else

Просмотреть файл

@ -36,7 +36,5 @@ char *nsMsgCreateTempFileName(char *tFileName);
char *nsMimePlatformFileToURL (nsFileSpec aFileSpec);
char *GetTheTempDirectoryOnTheSystem(void);
#endif // _nsEmitterUtils_h_

Просмотреть файл

@ -42,6 +42,7 @@
#include "nsCOMPtr.h"
#include "nsIMsgMailNewsUrl.h"
#include "nsXPIDLString.h"
#include "nsSpecialSystemDirectory.h"
static NS_DEFINE_CID(kMsgHeaderParserCID, NS_MSGHEADERPARSER_CID);
static NS_DEFINE_CID(kCAddressCollecter, NS_ABADDRESSCOLLECTER_CID);
@ -211,15 +212,15 @@ nsMimeXULEmitter::WriteBody(const char *buf, PRUint32 size, PRUint32 *amountWrit
nsresult
nsMimeXULEmitter::OhTheHumanityCleanupTempFileHack()
{
// Age old question, where to store temp files....ugh!
char *tDir = GetTheTempDirectoryOnTheSystem();
if (!tDir)
// Age old question, where to find temp files....ugh!
nsFileSpec *tmpSpec = new nsFileSpec(nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_TemporaryDirectory));
if (!tmpSpec)
return NS_OK;
nsFileSpec tempDir(tDir);
if (tempDir.Exists())
if (tmpSpec->Exists())
{
for (nsDirectoryIterator i(tempDir, PR_FALSE); i.Exists(); i++)
for (nsDirectoryIterator i(*tmpSpec, PR_FALSE); i.Exists(); i++)
{
nsFileSpec possibleTempFile = i.Spec();
char *filename = possibleTempFile.GetLeafName();
@ -235,7 +236,7 @@ nsMimeXULEmitter::OhTheHumanityCleanupTempFileHack()
}
}
PR_FREEIF(tDir);
delete tmpSpec;
return NS_OK;
}

Просмотреть файл

@ -46,6 +46,7 @@
#include "nsIMsgComposeService.h"
#include "nsIMsgCompose.h"
#include "nsMsgI18N.h"
#include "nsSpecialSystemDirectory.h"
//
// Header strings...
@ -101,38 +102,6 @@ nsMimeNewURI(nsIURI** aInstancePtrResult, const char *aSpec)
//
#define TPATH_LEN 1024
static char *
GetTheTempDirectoryOnTheSystem(void)
{
char *retPath = (char *)PR_Malloc(TPATH_LEN);
if (!retPath)
return nsnull;
retPath[0] = '\0';
#ifdef WIN32
if (getenv("TEMP"))
PL_strncpy(retPath, getenv("TEMP"), TPATH_LEN); // environment variable
else if (getenv("TMP"))
PL_strncpy(retPath, getenv("TMP"), TPATH_LEN); // How about this environment variable?
else
GetWindowsDirectory(retPath, TPATH_LEN);
#endif
#if defined(XP_UNIX) || defined(XP_BEOS)
char *tPath = getenv("TMPDIR");
if (!tPath)
PL_strncpy(retPath, "/tmp/", TPATH_LEN);
else
PL_strncpy(retPath, tPath, TPATH_LEN);
#endif
#ifdef XP_MAC
PL_strncpy(retPath, "", TPATH_LEN);
#endif
return retPath;
}
//
// Create a file spec for the a unique temp file
// on the local machine. Caller must free memory
@ -141,24 +110,15 @@ nsFileSpec *
nsMsgCreateTempFileSpec(char *tFileName)
{
if ((!tFileName) || (!*tFileName))
tFileName = "nsmail.tmp";
tFileName = "nsmime.tmp";
// Age old question, where to store temp files....ugh!
char *tDir = GetTheTempDirectoryOnTheSystem();
if (!tDir)
return (new nsFileSpec("mozmail.tmp")); // No need to I18N
nsFileSpec *tmpSpec = new nsFileSpec(tDir);
nsFileSpec *tmpSpec = new nsFileSpec(nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_TemporaryDirectory));
if (!tmpSpec)
{
PR_FREEIF(tDir);
return (new nsFileSpec("mozmail.tmp")); // No need to I18N
}
return nsnull;
*tmpSpec += tFileName;
tmpSpec->MakeUnique();
PR_FREEIF(tDir);
return tmpSpec;
}