From f5b8eace0a962e427c858b0784414fcb693fca3d Mon Sep 17 00:00:00 2001 From: donho Date: Sat, 27 Oct 2007 23:47:05 +0000 Subject: [PATCH] [BUG_FIXED_AND_NEW_FEATURE] Add open relative file path from command line feature. Fix the crash issue when open a file which does not exist anymore from RFL (if its path exceed certain length). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@65 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 28 +++++++++++++++---- .../WinControls/Preference/preferenceDlg.cpp | 2 +- PowerEditor/src/winmain.cpp | 1 - 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index e85b5988f..6f7414ff3 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -220,11 +220,16 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const char *cmdLine, CmdLi if (cmdLine) { + char currPath[MAX_PATH]; + ::GetCurrentDirectory(sizeof currPath, currPath); + ::SetCurrentDirectory(currPath); + LangType lt = cmdLineParams->_langType; int ln = cmdLineParams->_line2go; if (PathFileExists(cmdLine)) { + doOpen(cmdLine, cmdLineParams->_isReadOnly); if (lt != L_TXT) @@ -417,13 +422,26 @@ bool Notepad_plus::doOpen(const char *fileName, bool isReadOnly) if (!PathFileExists(longFileName)) { - char str2display[128]; - sprintf(str2display, "%s doesn't exist. Create it?", longFileName); + char str2display[MAX_PATH*2]; + char longFileDir[MAX_PATH]; - if (::MessageBox(_hSelf, str2display, "Create new file", MB_YESNO) == IDYES) + strcpy(longFileDir, longFileName); + PathRemoveFileSpec(longFileDir); + + if (PathFileExists(longFileDir)) { - FILE *f = fopen(longFileName, "w"); - fclose(f); + sprintf(str2display, "%s doesn't exist. Create it?", longFileName); + + if (::MessageBox(_hSelf, str2display, "Create new file", MB_YESNO) == IDYES) + { + FILE *f = fopen(longFileName, "w"); + fclose(f); + } + else + { + _lastRecentFileList.remove(longFileName); + return false; + } } else { diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 96cdf086f..b17ec1671 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -641,7 +641,7 @@ BOOL CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM for (int i = L_TXT ; i < L_END ; i++) { string str; - //if ((LangType)i != L_END) + if ((LangType)i != L_USER) { int cmdID = pNppParam->langTypeToCommandID((LangType)i); if ((cmdID != -1) && (getNameStrFromCmd(cmdID, str) == TYPE_CMD)) diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 6508d145b..1524da9f9 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -200,7 +200,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdSh cmdLineParams._isNoPlugin = isInList(FLAG_NO_PLUGIN, lpszCmdLine); cmdLineParams._isReadOnly = isInList(FLAG_READONLY, lpszCmdLine); cmdLineParams._isNoSession = isInList(FLAG_NOSESSION, lpszCmdLine); - //printStr(cmdLineParams._isReadOnly?"RO":"RW"); cmdLineParams._langType = getLangTypeFromParam(lpszCmdLine); cmdLineParams._line2go = getLn2GoFromParam(lpszCmdLine);