@@ -44,30 +44,42 @@ namespace NativeMsh
4444 }
4545 else if (*iter == L' p' || *iter == L' P' )
4646 {
47- this ->pathToPowerShellAssemblies = this ->getValueFromLine (line, psHomeDirTag);
48- if (this ->pathToPowerShellAssemblies .size () > 0 ) // Found a match
47+ std::wstring psHomeDir = this ->getValueFromLine (line, psHomeDirTag);
48+ HANDLE dirHandle = CreateFileW (psHomeDir.c_str (), GENERIC_READ, FILE_SHARE_READ, NULL , OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
49+ if (INVALID_HANDLE_VALUE != dirHandle)
4950 {
50- std::wstring::const_iterator slashIter = this -> pathToPowerShellAssemblies . end ( );
51- slashIter-- ;
52- if (*slashIter != L ' \\ ' )
51+ CloseHandle (dirHandle );
52+ this -> pathToPowerShellAssemblies = psHomeDir ;
53+ if (this -> pathToPowerShellAssemblies . size () > 0 ) // Found a match
5354 {
54- // Guarantee that there is a '\' at the end of the path
55- this ->pathToPowerShellAssemblies .append (L" \\ " );
55+ std::wstring::const_iterator slashIter = this ->pathToPowerShellAssemblies .end ();
56+ slashIter--;
57+ if (*slashIter != L' \\ ' )
58+ {
59+ // Guarantee that there is a '\' at the end of the path
60+ this ->pathToPowerShellAssemblies .append (L" \\ " );
61+ }
5662 }
5763 }
5864 break ;
5965 }
6066 else if (*iter == L' c' || *iter == L' C' )
6167 {
62- this ->coreClrDirectory = this ->getValueFromLine (line, coreClrDirTag);
63- if (this ->coreClrDirectory .size () > 0 ) // Found a match
68+ std::wstring coreClrDir = this ->getValueFromLine (line, coreClrDirTag);
69+ HANDLE dirHandle = CreateFileW (coreClrDir.c_str (), GENERIC_READ, FILE_SHARE_READ, NULL , OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
70+ if (INVALID_HANDLE_VALUE != dirHandle)
6471 {
65- std::wstring::const_iterator slashIter = this -> coreClrDirectory . end ( );
66- slashIter-- ;
67- if (*slashIter != L ' \\ ' )
72+ CloseHandle (dirHandle );
73+ this -> coreClrDirectory = this -> getValueFromLine (line, coreClrDirTag) ;
74+ if (this -> coreClrDirectory . size () > 0 ) // Found a match
6875 {
69- // Guarantee that there is a '\' at the end of the path
70- this ->coreClrDirectory .append (L" \\ " );
76+ std::wstring::const_iterator slashIter = this ->coreClrDirectory .end ();
77+ slashIter--;
78+ if (*slashIter != L' \\ ' )
79+ {
80+ // Guarantee that there is a '\' at the end of the path
81+ this ->coreClrDirectory .append (L" \\ " );
82+ }
7183 }
7284 }
7385 break ;
0 commit comments