https://git.reactos.org/?p=reactos.git;a=commitdiff;h=22e86add33775c9a1a2a6…
commit 22e86add33775c9a1a2a61b9e23b46acfb5a4580
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sun Aug 12 18:23:16 2018 +0900
Commit: Benedikt Freisen <b.freisen(a)gmx.net>
CommitDate: Sun Aug 12 11:23:16 2018 +0200
[MSPAINT] Fix interpretation of command line (#707)
---
base/applications/mspaint/main.cpp | 70 ++++++++++++++++++++++++++++++--------
1 file changed, 56 insertions(+), 14 deletions(-)
diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp
index 8b0bfe7bf8..8abe4ffa41 100644
--- a/base/applications/mspaint/main.cpp
+++ b/base/applications/mspaint/main.cpp
@@ -261,24 +261,66 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR
lpszArgument
if (__argc >= 2)
{
- HBITMAP bmNew = NULL;
- LoadDIBFromFile(&bmNew, __targv[1], &fileTime, &fileSize,
&fileHPPM, &fileVPPM);
- if (bmNew != NULL)
+ WIN32_FIND_DATAW find;
+ HANDLE hFind = FindFirstFileW(__targv[1], &find);
+ if (hFind != INVALID_HANDLE_VALUE)
{
- TCHAR *temp;
- imageModel.Insert(bmNew);
- GetFullPathName(__targv[1], SIZEOF(filepathname), filepathname, &temp);
- CPath pathFileName(filepathname);
- pathFileName.StripPath();
- CString strTitle;
- strTitle.Format(IDS_WINDOWTITLE, (LPCTSTR)pathFileName);
- mainWindow.SetWindowText(strTitle);
- imageModel.ClearHistory();
- isAFile = TRUE;
+ FindClose(hFind);
+
+ // check the file size
+ if (find.nFileSizeHigh || find.nFileSizeLow)
+ {
+ // load it now
+ HBITMAP bmNew = NULL;
+ LoadDIBFromFile(&bmNew, __targv[1], &fileTime, &fileSize,
&fileHPPM, &fileVPPM);
+ if (bmNew)
+ {
+ // valid bitmap file
+ GetFullPathName(__targv[1], SIZEOF(filepathname), filepathname,
NULL);
+ imageModel.Insert(bmNew);
+ CPath pathFileName(filepathname);
+ pathFileName.StripPath();
+
+ CString strTitle;
+ strTitle.Format(IDS_WINDOWTITLE, (LPCTSTR)pathFileName);
+ mainWindow.SetWindowText(strTitle);
+
+ imageModel.ClearHistory();
+
+ isAFile = TRUE;
+ registrySettings.SetMostRecentFile(filepathname);
+ }
+ else
+ {
+ // cannot open and not empty
+ CStringW strText;
+ strText.Format(IDS_LOADERRORTEXT, __targv[1]);
+ MessageBoxW(NULL, strText, NULL, MB_ICONERROR);
+ }
+ }
+ else
+ {
+ // open the empty file
+ GetFullPathName(__targv[1], SIZEOF(filepathname), filepathname, NULL);
+ CPath pathFileName(filepathname);
+ pathFileName.StripPath();
+
+ CString strTitle;
+ strTitle.Format(IDS_WINDOWTITLE, (LPCTSTR)pathFileName);
+ mainWindow.SetWindowText(strTitle);
+
+ imageModel.ClearHistory();
+
+ isAFile = TRUE;
+ registrySettings.SetMostRecentFile(filepathname);
+ }
}
else
{
- exit(0);
+ // does not exist
+ CStringW strText;
+ strText.Format(IDS_LOADERRORTEXT, __targv[1]);
+ MessageBoxW(NULL, strText, NULL, MB_ICONERROR);
}
}