@@ -157,7 +157,7 @@ std::string DownloadJsonFromURL(const std::string& url) {
157157 InternetCloseHandle (hInternet);
158158 return " " ;
159159 }
160-
160+
161161 std::string data;
162162 char buffer[4096 ];
163163 DWORD bytesRead;
@@ -193,12 +193,12 @@ nlohmann::json LoadJsonFromFile(const std::wstring& filename) {
193193 JSON_FILE_LOADED = true ; // Could find file
194194
195195 nlohmann::json jsonData;
196- file >> jsonData;
196+ file >> jsonData;
197197 file.close ();
198198
199199 std::string version = " " ;
200200 version = jsonData.value (" version" , " " );
201- log_line (" Loaded JSON file " + wstringToString (filename) + " (version: " + version + " )" );
201+ log_line (" Loaded local JSON file " + wstringToString (filename) + " (version: " + version + " )" );
202202
203203 return jsonData;
204204}
@@ -225,8 +225,8 @@ nlohmann::json LoadJsonFromUrl(const std::string& url) {
225225
226226 std::string version = " " ;
227227 version = jsonData.value (" version" , " " );
228- log_line (" Loaded JSON file from URL " + url + " (version: " + version + " )" );
229-
228+ log_line (" Loaded URL JSON file " + url + " (version: " + version + " )" );
229+
230230 return jsonData;
231231}
232232void LoadDataFromJson (nlohmann::json jsonData) {
@@ -319,7 +319,7 @@ static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lP
319319
320320
321321 // If we're larger than 20 characters we erase the first char to keep the buffer manageable
322- if (keyBuffer.size () > 20 ) keyBuffer.erase (0 , 1 );
322+ if (keyBuffer.size () > 20 ) keyBuffer.erase (0 , 1 );
323323
324324 // Loop through each known shortcut and see if we match
325325 for (const auto & pair : shortcuts) {
@@ -338,7 +338,7 @@ static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lP
338338
339339 if (enableLogging) {
340340 char buffer[100 ];
341- snprintf (buffer, sizeof (buffer), " Heard '%ls'" , pair.first .c_str ());
341+ snprintf (buffer, sizeof (buffer), " Shortcut '%ls' triggered " , pair.first .c_str ());
342342 log_line (buffer);
343343 }
344344
@@ -401,13 +401,15 @@ void CloseWindowAndExit() {
401401void AddToStartup () {
402402 std::wstring progPath = GetExecutableDirectory () + L" \\ OpenKeys.exe" ;
403403 HKEY hkey = NULL ;
404- LONG createStatus = RegCreateKey (HKEY_CURRENT_USER , L" SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" , &hkey); // Creates a key
404+ LONG createStatus = RegCreateKey (HKEY_CURRENT_USER , L" SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" , &hkey); // Creates a key
405405 LONG status = RegSetValueEx (hkey, L" MyApp" , 0 , REG_SZ , (BYTE *)progPath.c_str (), static_cast <DWORD >((progPath.size () + 1 ) * sizeof (wchar_t )));
406406}
407407
408408void LoadShortcuts () {
409409 shortcuts.clear ();
410410 nlohmann::json jsonFILE = LoadJsonFromFile (json_path);
411+
412+ // If there is no local JSON file, we download the default one from github
411413 if (jsonFILE.empty ()) {
412414 log_line (" Downloading default JSON from github: " + json_default_url);
413415 std::string json_default_data = DownloadJsonFromURL (json_default_url);
@@ -431,17 +433,21 @@ void LoadShortcuts() {
431433
432434 jsonFILE = LoadJsonFromFile (json_path);
433435 }
434- if (JsonHasKey (jsonFILE, " external_url" )) { // If the JSON has an external URL, we check the versions and ask to overwrite if they don't match
435- log_line (" User provided URL: " + jsonFILE[" external_url" ].get <std::string>());
436+
437+ // If the JSON has an external URL, we check the versions and ask to overwrite if they don't match
438+ if (JsonHasKey (jsonFILE, " external_url" )) {
439+
436440 nlohmann::json jsonURL = LoadJsonFromUrl (jsonFILE[" external_url" ]);
437441 if (jsonURL.empty ()) {
438442 log_line (" Failed to load JSON from URL: " + jsonFILE[" external_url" ].get <std::string>());
439443 MessageBox (NULL , L" The URL you provided does not contain valid JSON. Please verify URL." , L" Warning" , MB_ICONWARNING );
440444 return ;
441445 }
446+
447+ // The local version and remote versions are different
442448 if (jsonURL[" version" ] != jsonFILE[" version" ]) {
443449 int overwrite = MessageBox (NULL , L" New version of shortcuts found. Would you like to use the new version?" , L" New shortcuts found" , MB_ICONINFORMATION | MB_YESNO );
444-
450+
445451 // If the user chooses to overwrite, we overwrite the local JSON with the one from the URL
446452 if (overwrite == IDYES ) {
447453 // If the remote JSON does not have an external URL, we preserve the local one
@@ -467,6 +473,9 @@ void LoadShortcuts() {
467473 log_line (" Did not overwrite local JSON, using local data" );
468474 }
469475 }
476+ else if (jsonURL[" version" ] == jsonFILE[" version" ]) {
477+ log_line (" Local and remote versions are the same" );
478+ }
470479
471480 }
472481 LoadDataFromJson (jsonFILE);
@@ -509,11 +518,14 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
509518 log_line (" Appdata directory created" );
510519 }
511520 }
512-
521+
513522 if (!f.good ()) {
514523 log_line (" Logfile created (You can disable logging by setting enable_logging to false in your json)" );
515524 }
516- log_line (" OpenKeys started" );
525+
526+ char buffer[100 ];
527+ snprintf (buffer, sizeof (buffer), " OpenKeys v%ls started" , VERSION_STRING .c_str ());
528+ log_line (buffer);
517529
518530 }
519531
@@ -707,7 +719,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
707719 SetViewportOrgEx (hdc, 0 , -scrollY, NULL );
708720
709721 // Draw the text in the full content area (use calculated height)
710- RECT drawRect = { 0 , 0 , rect.right - rect.left , textRect.bottom };
722+ int padding = 4 ;
723+ RECT drawRect = { padding, padding, rect.right - rect.left , textRect.bottom + padding };
711724 DrawTextW (hdc, displayedText.c_str (), -1 , &drawRect, DT_LEFT | DT_TOP | DT_WORDBREAK );
712725
713726 // Restore the graphics state to prevent affecting other parts of the window
0 commit comments