Notepad will no longer add .txt if you invoke it specifying a file that does not...
authorNathan Woods <npwoods@mess.org>
Mon, 24 Oct 2005 23:44:07 +0000 (23:44 +0000)
committerNathan Woods <npwoods@mess.org>
Mon, 24 Oct 2005 23:44:07 +0000 (23:44 +0000)
svn path=/trunk/; revision=18765

reactos/subsys/system/notepad/dialog.c
reactos/subsys/system/notepad/dialog.h
reactos/subsys/system/notepad/main.c

index 53864d9..7efb11f 100644 (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)
 {
     HANDLE hFile;
index 09b748a..3725b7d 100644 (file)
@@ -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);
index 75ecb84..c0f1ed2 100644 (file)
@@ -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)