diff --git a/pykd/windbgext.cpp b/pykd/windbgext.cpp index b11c996..dc0a917 100644 --- a/pykd/windbgext.cpp +++ b/pykd/windbgext.cpp @@ -117,7 +117,7 @@ KDLIB_EXT_COMMAND_METHOD_IMPL(PykdExt, py) std::string scriptFileName; if ( args.size() > 0 ) { - scriptFileName = getScriptFileName( args[0] ); + scriptFileName = getScriptFileName( args[0] ); if ( scriptFileName.empty() ) { @@ -247,16 +247,18 @@ void PykdExt::printUsage() std::string PykdExt::getScriptFileName( const std::string &scriptName ) { - bool fileHasPyExt = false; + std::string scriptFileName = findScript( scriptName ); - if ( scriptName.length() > 3 ) - fileHasPyExt = scriptName.rfind(".py") == scriptName.length() - 3; - - std::string fullFileName = scriptName; + if ( scriptFileName.empty() && (scriptName.rfind(".py") != scriptName.length() - 3) ) + scriptFileName = findScript( scriptName + ".py" ); - if (!fileHasPyExt) - fullFileName += ".py"; - + return scriptFileName; +} + +/////////////////////////////////////////////////////////////////////////////// + +std::string PykdExt::findScript( const std::string &fullFileName ) +{ if ( GetFileAttributesA(fullFileName.c_str()) != INVALID_FILE_ATTRIBUTES ) return fullFileName; @@ -287,10 +289,9 @@ std::string PykdExt::getScriptFileName( const std::string &scriptName ) if (bufSize > 0) { - fullFileName = std::string(&fullFileNameCStr[0]); - return fullFileName; + return std::string(&fullFileNameCStr[0]); } - } + } } return ""; diff --git a/pykd/windbgext.h b/pykd/windbgext.h index 876f279..68d60ee 100644 --- a/pykd/windbgext.h +++ b/pykd/windbgext.h @@ -25,6 +25,7 @@ private: virtual void tearDown(); std::string getScriptFileName( const std::string &scriptName ); + std::string findScript( const std::string &fullFileName ); std::vector m_paths;