Notepad will no longer add .txt if you invoke it specifying a file that does not exist, but has a file extension

svn path=/trunk/; revision=18765
This commit is contained in:
Nathan Woods 2005-10-24 23:44:07 +00:00
parent e0968c78d0
commit 0345348a28
3 changed files with 16 additions and 4 deletions

View file

@ -139,6 +139,17 @@ BOOL FileExists(LPCWSTR szFilename)
} }
BOOL HasFileExtension(LPCWSTR szFilename)
{
LPCWSTR s;
s = wcsrchr(szFilename, '\\');
if (s)
szFilename = s;
return wcsrchr(szFilename, '.') != NULL;
}
static VOID DoSaveFile(VOID) static VOID DoSaveFile(VOID)
{ {
HANDLE hFile; HANDLE hFile;

View file

@ -55,5 +55,6 @@ VOID DIALOG_TimeDate(VOID);
/* utility functions */ /* utility functions */
VOID ShowLastError(void); VOID ShowLastError(void);
BOOL FileExists(LPCWSTR szFilename); BOOL FileExists(LPCWSTR szFilename);
BOOL HasFileExtension(LPCWSTR szFilename);
BOOL DoCloseFile(void); BOOL DoCloseFile(void);
void DoOpenFile(LPCWSTR szFileName); void DoOpenFile(LPCWSTR szFileName);

View file

@ -440,8 +440,8 @@ static void HandleCommandLine(LPWSTR cmdline)
if (*cmdline) if (*cmdline)
{ {
/* file name is passed in the command line */ /* file name is passed in the command line */
LPCWSTR file_name; LPCWSTR file_name = NULL;
BOOL file_exists; BOOL file_exists = FALSE;
WCHAR buf[MAX_PATH]; WCHAR buf[MAX_PATH];
if (cmdline[0] == '"') if (cmdline[0] == '"')
@ -455,7 +455,7 @@ static void HandleCommandLine(LPWSTR cmdline)
file_exists = TRUE; file_exists = TRUE;
file_name = cmdline; file_name = cmdline;
} }
else else if (!HasFileExtension(cmdline))
{ {
static const WCHAR txtW[] = { '.','t','x','t',0 }; static const WCHAR txtW[] = { '.','t','x','t',0 };
@ -463,7 +463,6 @@ static void HandleCommandLine(LPWSTR cmdline)
if (!lstrcmp(txtW, cmdline + lstrlen(cmdline) - lstrlen(txtW))) if (!lstrcmp(txtW, cmdline + lstrlen(cmdline) - lstrlen(txtW)))
{ {
file_exists = FALSE; file_exists = FALSE;
file_name = cmdline;
} }
else else
{ {
@ -476,6 +475,7 @@ static void HandleCommandLine(LPWSTR cmdline)
if (file_exists) if (file_exists)
{ {
file_name = cmdline;
DoOpenFile(file_name); DoOpenFile(file_name);
InvalidateRect(Globals.hMainWnd, NULL, FALSE); InvalidateRect(Globals.hMainWnd, NULL, FALSE);
if (opt_print) if (opt_print)