33#include < windows.h>
44#include < tchar.h>
55
6+ #include " StringExt.hpp"
67#include " Registry.hpp"
78
89using namespace std ;
@@ -22,7 +23,7 @@ Registry::WindowsBit Registry::GetWindowsBit()
2223 return windowsBit;
2324}
2425
25- string Registry::GetTextFromKey (const Registry::RootFolder Folder, const char * pPathToFolder, const char * pKeyName)
26+ string Registry::GetTextFromKeyA (const Registry::RootFolder Folder, const char * pPathToFolder, const char * pKeyName)
2627{
2728 HKEY rKey;
2829 DWORD Size = 256 ;
@@ -48,11 +49,37 @@ string Registry::GetTextFromKey(const Registry::RootFolder Folder, const char* p
4849 return returnValue;
4950}
5051
51- string Registry::GetPathToGame (const Games game )
52+ wstring Registry::GetTextFromKeyW (const Registry::RootFolder Folder, const wchar_t * pPathToFolder, const wchar_t * pKeyName )
5253{
53- string Key = " InstallPath" ;
54- string Path = Registry::PATHS_TO_GAMES.find (game)->second .find (GetWindowsBit ())->second ;
55- return GetTextFromKey (Registry::RootFolder::HKLM, Path.c_str (), Key.c_str ());
54+ HKEY rKey;
55+ DWORD Size = 256 ;
56+ WCHAR Reget[Size] = { 0 };
57+
58+ switch (Folder)
59+ {
60+ case Registry::RootFolder::HKCU :
61+ RegOpenKeyExW (HKEY_CURRENT_USER, pPathToFolder, 0 , KEY_READ, &rKey);
62+ break ;
63+
64+ case Registry::RootFolder::HKLM :
65+ RegOpenKeyExW (HKEY_LOCAL_MACHINE, pPathToFolder, 0 , KEY_READ, &rKey);
66+ break ;
67+ }
68+
69+ RegQueryValueExW (rKey, pKeyName, NULL , NULL , (LPBYTE)&Reget, &Size);
70+ RegCloseKey (rKey);
71+
72+ wstring returnValue (Reget);
73+ returnValue.shrink_to_fit ();
74+
75+ return returnValue;
76+ }
77+
78+ wstring Registry::GetPathToGame (const Games game)
79+ {
80+ wstring Key = L" InstallPath" ;
81+ wstring Path = Registry::PATHS_TO_GAMES.find (game)->second .find (GetWindowsBit ())->second ;
82+ return GetTextFromKeyW (Registry::RootFolder::HKLM, Path.c_str (), Key.c_str ());
5683}
5784
5885string Registry::ToString (Games game)
@@ -82,21 +109,21 @@ bool Registry::IsWindow32bit() { return GetWindowsBit() == WindowsBit::Win32; }
82109 {
83110 const char Path[] = {" Control Panel\\ International" };
84111 const char Key[] = {" LocaleName" };
85- return GetTextFromKey (Registry::RootFolder::HKCU, &Path[0 ], &Key[0 ]).substr (0 , 2 );
112+ return GetTextFromKeyA (Registry::RootFolder::HKCU, &Path[0 ], &Key[0 ]).substr (0 , 2 );
86113 }
87114
88115 string Registry::GetWindowsVersion ()
89116 {
90117 const char Path[] = {" SOFTWARE\\ Microsoft\\ Windows NT\\ CurrentVersion" };
91118 const char Key[] = {" ProductName" };
92- return GetTextFromKey (Registry::RootFolder::HKLM, &Path[0 ], &Key[0 ]);
119+ return GetTextFromKeyA (Registry::RootFolder::HKLM, &Path[0 ], &Key[0 ]);
93120 }
94121
95122 string Registry::GetProcessorInfo ()
96123 {
97124 const char Path[] = {" HARDWARE\\ DESCRIPTION\\ System\\ CentralProcessor\\ 0" };
98125 const char Value[] = {" ProcessorNameString" };
99- return GetTextFromKey (Registry::RootFolder::HKLM, &Path[0 ], &Value[0 ]);
126+ return GetTextFromKeyA (Registry::RootFolder::HKLM, &Path[0 ], &Value[0 ]);
100127 }
101128
102129 string Registry::GetMemoryInfo ()
0 commit comments