Fix command line parsing to accept unquoted files as single argument once again.

Add DefaultIcon key to registry.
Close root key handle when modifying registry.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@405 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
harrybharry 2009-01-27 00:48:17 +00:00
parent 6eda888b6e
commit 6fe5d8ac78
2 changed files with 48 additions and 2 deletions

View File

@ -344,6 +344,7 @@ void RegExtDlg::writeNppPath()
// Write the value for new document
::RegOpenKeyEx(HKEY_CLASSES_ROOT, nppName, 0, KEY_ALL_ACCESS, &hRootKey);
::RegSetValueEx(hRootKey, NULL, 0, REG_SZ, (LPBYTE)nppDoc, (lstrlen(nppDoc)+1)*sizeof(TCHAR));
RegCloseKey(hRootKey);
TCHAR nppPath[MAX_PATH];
::GetModuleFileName(_hInst, nppPath, MAX_PATH);
@ -355,4 +356,33 @@ void RegExtDlg::writeNppPath()
}
RegCloseKey(hKey);
}
//Set default icon value
lstrcpy(regStr, nppName);
lstrcat(regStr, TEXT("\\DefaultIcon"));
nRet = ::RegCreateKeyEx(
HKEY_CLASSES_ROOT,
regStr,
0,
NULL,
0,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisp);
if (nRet == ERROR_SUCCESS)
{
//if (dwDisp == REG_CREATED_NEW_KEY)
{
TCHAR nppPath[MAX_PATH];
::GetModuleFileName(_hInst, nppPath, MAX_PATH);
TCHAR nppPathParam[256] = TEXT("\"");
lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\",0"));
::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR));
}
RegCloseKey(hKey);
}
}

View File

@ -34,7 +34,25 @@ bool checkSingleFile(const TCHAR * commandLine) {
return false;
}
//commandLine should contain path to n++ executable running
void parseCommandLine(TCHAR * commandLine, ParamVector & paramVector) {
//params.erase(params.begin());
//remove the first element, since thats the path the the executable (GetCommandLine does that)
TCHAR stopChar = TEXT(' ');
int i = 0;
if (commandLine[0] == TEXT('\"')) {
stopChar = TEXT('\"');
commandLine++;
}
//while this is not really DBCS compliant, space and quote are in the lower 127 ASCII range
while(commandLine[0] && commandLine[0] != stopChar)
commandLine++;
commandLine++; //advance past stopChar
//kill remaining spaces
while(commandLine[0] == TEXT(' '))
commandLine++;
bool isFile = checkSingleFile(commandLine); //if the commandline specifies only a file, open it as such
if (isFile) {
paramVector.push_back(commandLine);
@ -129,8 +147,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR cmdLineAnsi, int nCmdSh
LPTSTR cmdLine = ::GetCommandLine();
ParamVector params;
parseCommandLine(cmdLine, params);
params.erase(params.begin()); //remove the first element, since thats the path the the executable (GetCommandLine does that)
bool TheFirstOne = true;
::SetLastError(NO_ERROR);