From 66b62116c210d12b0b5b9570eaaefacdd2bca5fc Mon Sep 17 00:00:00 2001 From: DreamGuXiang <166664660@qq.com> Date: Fri, 12 Mar 2021 22:50:28 +0800 Subject: [PATCH 1/2] fix update --- LiteLoader/CheckUpdate.cpp | 45 +++++++++++++++++++++----------------- LiteLoader/LiteLoader.cpp | 2 +- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/LiteLoader/CheckUpdate.cpp b/LiteLoader/CheckUpdate.cpp index c7728503c8..13e2f3a35c 100644 --- a/LiteLoader/CheckUpdate.cpp +++ b/LiteLoader/CheckUpdate.cpp @@ -1,12 +1,13 @@ #include "pch.h" -void updateCheck() + +int updateCheck() { std::thread t([] { LPCTSTR lpszAgent = L"WinInetGet/0.1"; HINTERNET hInternet = InternetOpen(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); - DWORD rec_timeout = 300 * 1000; + DWORD rec_timeout = 500 * 1000; InternetSetOption(hInternet, INTERNET_OPTION_RECEIVE_TIMEOUT, &rec_timeout, sizeof(rec_timeout)); LPCTSTR lpszServerName = L"gitee.com"; INTERNET_PORT nServerPort = INTERNET_DEFAULT_HTTPS_PORT; @@ -20,7 +21,7 @@ void updateCheck() INTERNET_SERVICE_HTTP, dwConnectFlags, dwConnectContext); LPCTSTR lpszVerb = L"GET"; - LPCTSTR lpszObjectName = L"/dreamguxiang/llupdate_pages/raw/master/update.json"; + LPCTSTR lpszObjectName = L"/dreamguxiang/LLessentials/raw/master/llupdate.json"; LPCTSTR lpszVersion = NULL; LPCTSTR lpszReferrer = NULL; LPCTSTR* lplpszAcceptTypes = NULL; @@ -57,24 +58,28 @@ void updateCheck() } pMessageBody[dwBytesRead]; std::string res = (char*)pMessageBody; - rapidjson::Document json; - json.Parse(res.c_str());; - if (json.HasParseError()) { - std::cout << "[BDSLiteloader] Failed to get updates(1)\n"; - return; - } - auto arr = json.GetArray(); - std::string LatestRelease = arr[arr.Size() - 1]["name"].GetString(); - int latestVersionNum = arr[arr.Size() - 1]["versionNum"].GetInt(); - if (latestVersionNum < LiteLoaderVersionNum) { - std::cout << "[BDSLiteloader] Found a new version: " << LatestRelease << "\n"; - return; + rapidjson::Document json; + json.Parse(res.c_str()); + for (int i = 0; i < 3; i++) + if (json.HasParseError()) { + std::cout << "[BDSLiteloader] Failed to get updates(1)\n"; + break; + } + auto arr = json.GetArray(); + std::string LatestRelease = arr[arr.Size() - 1]["name"].GetString(); + int latestVersionNum = arr[arr.Size() - 1]["versionNum"].GetInt(); + if (latestVersionNum < LiteLoaderVersionNum) { + std::cout << "[BDSLiteloader] Found a new version: " << LatestRelease << "\n"; + break; + } + if (latestVersionNum == LiteLoaderVersionNum) { + break; + } + if (latestVersionNum > LiteLoaderVersionNum) { + std::cout << "[BDSLiteloader] Using preview version: " << LatestRelease << "\n"; + break; + } } - if (latestVersionNum > LiteLoaderVersionNum) { - std::cout << "[BDSLiteloader] Using preview version: " << LatestRelease << "\n"; - return; - } - } }); t.detach(); } diff --git a/LiteLoader/LiteLoader.cpp b/LiteLoader/LiteLoader.cpp index f249401cda..73250a69cc 100644 --- a/LiteLoader/LiteLoader.cpp +++ b/LiteLoader/LiteLoader.cpp @@ -94,7 +94,7 @@ void FixUpCWD() { void startWBThread(); bool versionCommand(CommandOrigin const& ori, CommandOutput& outp); -void updateCheck(); +int updateCheck(); static void entry(bool fixcwd) { if (fixcwd) From 6e6f5f7af93775bb4ae8bd04616c1936dc3663ef Mon Sep 17 00:00:00 2001 From: DreamGuXiang <166664660@qq.com> Date: Fri, 12 Mar 2021 22:56:14 +0800 Subject: [PATCH 2/2] fix --- LiteLoader/CheckUpdate.cpp | 1 - LiteLoader/ServerCommands.cpp | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LiteLoader/CheckUpdate.cpp b/LiteLoader/CheckUpdate.cpp index 13e2f3a35c..3ce14af525 100644 --- a/LiteLoader/CheckUpdate.cpp +++ b/LiteLoader/CheckUpdate.cpp @@ -60,7 +60,6 @@ int updateCheck() std::string res = (char*)pMessageBody; rapidjson::Document json; json.Parse(res.c_str()); - for (int i = 0; i < 3; i++) if (json.HasParseError()) { std::cout << "[BDSLiteloader] Failed to get updates(1)\n"; break; diff --git a/LiteLoader/ServerCommands.cpp b/LiteLoader/ServerCommands.cpp index b9edb79c52..cad7f531e0 100644 --- a/LiteLoader/ServerCommands.cpp +++ b/LiteLoader/ServerCommands.cpp @@ -1,5 +1,6 @@ #include "pch.h" - +int updateCheck(); bool versionCommand(CommandOrigin const& ori, CommandOutput& outp) { + updateCheck(); outp.success("The server is running Bedrock Dedicated Server with BDSLiteLoader " + (string)LiteLoaderVersion); } \ No newline at end of file