1- #include " ./meojson/json.hpp"
2-
31#include < iostream>
42#include < windows.h>
53#include < string>
64#include < tuple>
7- #include < string>
85#include < vector>
96#include < wininet.h>
107#include < fstream>
11- #include < string>
128
139#pragma comment(lib, "wininet.lib")
1410
1511std::string QQDonwload = " https://dldir1.qq.com/qqfile/qq/QQNT/b07cb1a5/QQ9.9.15.27597_x64.exe" ;
12+
13+ std::string getMidText (std::string str, std::string str1, std::string str2)
14+ {
15+ std::string returnStr;
16+ int strIndex = str.find (str1);
17+ if (strIndex != -1 )
18+ {
19+ strIndex = strIndex + str1.length ();
20+ int endIndex = str.find (str2, strIndex);
21+ if (endIndex != -1 )
22+ {
23+ returnStr = str.substr (strIndex, endIndex - strIndex);
24+ return returnStr;
25+ }
26+ }
27+ return returnStr;
28+ }
29+
1630bool HttpGet (const std::string &url, std::string &response)
1731{
1832 HINTERNET hInternet = InternetOpen (" HTTPGET" , INTERNET_OPEN_TYPE_DIRECT, NULL , NULL , 0 );
@@ -83,20 +97,15 @@ std::string getNapCatVersionByPackageMirror()
8397
8498 return " " ;
8599}
100+
86101std::string getNapCatVersionByPackage ()
87102{
88103 std::string res = getNapCatVersionByPackageMirror ();
89104 if (res.empty ())
90105 {
91106 return " " ;
92107 }
93- auto ret = json::parse (res);
94- if (!ret)
95- {
96- return " " ;
97- }
98- json::value &value = *ret;
99- return (std::string)value[" version" ];
108+ return getMidText (res, " \" version\" : \" " , " \" " );
100109}
101110
102111std::tuple<bool , std::string> getQQInstalled ()
@@ -122,26 +131,20 @@ std::tuple<bool, std::string> getQQInstalled()
122131 QQPath = QQPath.substr (0 , QQPath.find_last_of (" \\ " )); // 截取路径
123132 return std::make_tuple (true , QQPath);
124133}
134+
125135std::string getNapCatVersion ()
126136{
127137 std::string response = " " ;
128138 // 开始请求HTTP http://nclatest.znin.net/ 解析Json
129139 if (HttpGet (" http://nclatest.znin.net/" , response))
130140 {
131- // std::cout << res->status << std::endl;
132- // std::cout << res->get_header_value("Content-Type") << std::endl;
133- // std::cout << res->body << std::endl;
134- auto ret = json::parse (response);
135- if (!ret)
136- {
137- return " " ;
138- }
139- json::value &value = *ret;
140- // std::cout << (std::string)value["tag_name"] << std::endl;
141- return (std::string)value[" tag_name" ];
141+ // "html_url": "https://github.com/NapNeko/NapCatQQ/releases/tag/v2.3.5",
142+ // 获取v2.3.5这种值
143+ return getMidText (response," https://github.com/NapNeko/NapCatQQ/releases/tag/" , " \" " );
142144 }
143145 return " " ;
144146}
147+
145148int getQQVersionByPackage (std::string QQPath)
146149{
147150 // 组装目录 .\resources\app\package.json
@@ -159,15 +162,9 @@ int getQQVersionByPackage(std::string QQPath)
159162 packageData += line;
160163 }
161164 QQVersionFile.close ();
162- // 解析Json
163- auto ret = json::parse (packageData);
164- if (!ret)
165- {
166- return 0 ;
167- }
168- json::value &value = *ret;
169- return std::stoi ((std::string)value[" buildVersion" ]);
165+ return std::stoi (getMidText (packageData, " \" buildVersion\" :" , " ," ));
170166}
167+
171168int getQQVersionByConfig (std::string QQPath)
172169{
173170 // 组装目录 .\config\config.json
@@ -185,15 +182,9 @@ int getQQVersionByConfig(std::string QQPath)
185182 packageData += line;
186183 }
187184 QQVersionFile.close ();
188- // 解析Json
189- auto ret = json::parse (packageData);
190- if (!ret)
191- {
192- return 0 ;
193- }
194- json::value &value = *ret;
195- return std::stoi ((std::string)value[" buildId" ]);
185+ return std::stoi (getMidText (packageData, " \" buildId\" : \" " , " \" " ));
196186}
187+
197188int main ()
198189{
199190 bool isQQInstalled;
@@ -262,30 +253,6 @@ int main()
262253 // 调用powershell的 Expand-Archive -Path "./NapCat.Shell.zip" -DestinationPath "./NapCatQQ/" -Force 解压
263254 system (" powershell Expand-Archive -Path \" ./NapCat.Shell.zip\" -DestinationPath \" ./NapCatQQ/\" -Force" );
264255 system (" cls" );
265- // 移动./NapCatQQ/dbghelp.dll 到QQPath
266- // std::string dbghelpPath = QQPath + "\\dbghelp.dll";
267- // // 获取当前目录
268- // char currentPath[1024];
269- // GetCurrentDirectory(1024, currentPath);
270- // std::string dbghelpNapCatPath = currentPath;
271- // dbghelpNapCatPath += "\\NapCatQQ\\dbghelp.dll";
272- // std::cout << "Target: dbghelp.dll:" << dbghelpPath << std::endl;
273- // std::cout << "Source: dbghelp.dll:" << dbghelpNapCatPath << std::endl;
274- // // 判断是否被占用
275- // system("taskkill /f /im QQ.exe");
276- // // 判断原来的dbghelp.dll是否存在
277- // if (std::ifstream(dbghelpPath))
278- // {
279- // // 删除原来的dbghelp.dll
280- // std::remove(dbghelpPath.c_str());
281- // }
282- // // 移动dbghelp.dll
283- // std::rename(dbghelpNapCatPath.c_str(), dbghelpPath.c_str());
284- // 弹出提示框是否启动NapCat
285- // int ret = MessageBox(NULL, TEXT("是否启动NapCat?"), TEXT("NapCat"), MB_YESNO);
286- // 启动powershell 设置Set-ExecutionPolicy Unrestricted
287- // system("powershell Set-ExecutionPolicy Unrestricted");
288- // 获取当前目录
289256 std::cout << " 欢迎使用哦~~ 双击启动在启动本程序NapCatQQ目录下 launcher.bat 或者 launcher-win10.bat 即可" << std::endl;
290257 system (" pause" );
291258 return 0 ;
0 commit comments