diff --git a/reactos/subsys/system/notepad/dialog.c b/reactos/subsys/system/notepad/dialog.c index 53864d97b5e..7efb11ff609 100644 --- a/reactos/subsys/system/notepad/dialog.c +++ b/reactos/subsys/system/notepad/dialog.c @@ -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) { HANDLE hFile; diff --git a/reactos/subsys/system/notepad/dialog.h b/reactos/subsys/system/notepad/dialog.h index 09b748a3542..3725b7dd1d8 100644 --- a/reactos/subsys/system/notepad/dialog.h +++ b/reactos/subsys/system/notepad/dialog.h @@ -55,5 +55,6 @@ VOID DIALOG_TimeDate(VOID); /* utility functions */ VOID ShowLastError(void); BOOL FileExists(LPCWSTR szFilename); +BOOL HasFileExtension(LPCWSTR szFilename); BOOL DoCloseFile(void); void DoOpenFile(LPCWSTR szFileName); diff --git a/reactos/subsys/system/notepad/main.c b/reactos/subsys/system/notepad/main.c index 75ecb84de64..c0f1ed290f7 100644 --- a/reactos/subsys/system/notepad/main.c +++ b/reactos/subsys/system/notepad/main.c @@ -440,8 +440,8 @@ static void HandleCommandLine(LPWSTR cmdline) if (*cmdline) { /* file name is passed in the command line */ - LPCWSTR file_name; - BOOL file_exists; + LPCWSTR file_name = NULL; + BOOL file_exists = FALSE; WCHAR buf[MAX_PATH]; if (cmdline[0] == '"') @@ -455,7 +455,7 @@ static void HandleCommandLine(LPWSTR cmdline) file_exists = TRUE; file_name = cmdline; } - else + else if (!HasFileExtension(cmdline)) { 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))) { file_exists = FALSE; - file_name = cmdline; } else { @@ -476,6 +475,7 @@ static void HandleCommandLine(LPWSTR cmdline) if (file_exists) { + file_name = cmdline; DoOpenFile(file_name); InvalidateRect(Globals.hMainWnd, NULL, FALSE); if (opt_print)