@@ -392,43 +392,36 @@ R"( //私骰作成 即可成为我的主人~
392392 llStartTime = time (nullptr );
393393 DD::debugLog (" Dice.WebInit" );
394394 if (console[" EnableWebUI" ]) {
395+ fs::path dirWebUI{ DiceDir / " webui" };
395396 try {
396397 const std::string port_option = std::string (AllowInternetAccess ? " 0.0.0.0" : " 127.0.0.1" ) + " :" + std::to_string (Port);
397398
398- std::vector<std::string> mg_options = { " document_root" , (DiceDir / " webui " ) .u8string (), " listening_ports" , port_option.c_str () };
399+ std::vector<std::string> mg_options = { " document_root" , dirWebUI .u8string (), " listening_ports" , port_option.c_str () };
399400
400401 ManagerServer = std::make_unique<CivetServer>(mg_options);
401- #ifdef _WIN32
402- if (HRSRC hRsrcInfo = FindResource (hDllModule, MAKEINTRESOURCE (ID_ADMIN_HTML), TEXT (" FILE" ))) {
403- DWORD dwSize = SizeofResource (hDllModule, hRsrcInfo);
404- if (HGLOBAL hGlobal = LoadResource (hDllModule, hRsrcInfo)) {
405- LPVOID pBuffer = LockResource (hGlobal); // 锁定资源
406- char * pByte = new char [dwSize + 1 ];
407- memcpy_s (pByte, dwSize, pBuffer, dwSize);
408- FreeResource (hGlobal);// 释放资源
409- fs::create_directories (DiceDir / " webui" );
410- fstream fweb{ DiceDir / " webui" / " webui.html" };
411- std::stringstream buffer;
412- buffer << fweb.rdbuf ();
413- string content = buffer.str ();
414- if (content != pByte) {
415- fweb.write (pByte, dwSize);
416- }
417- delete[] pByte;
418- }
402+ #ifndef __ANDROID__
403+ if (!fs::exists (dirWebUI / " .git" ) && fs::exists (dirWebUI)) {
404+ console.log (" 删除旧index.html" );
405+ fs::remove_all (dirWebUI);
406+ }
407+ if (!fs::exists (dirWebUI)) {
408+ DiceRepo repo{ dirWebUI, " https://gitee.com/diceki/DiceWebUI.git" };
409+ }
410+ else {
411+ DiceRepo repo{ dirWebUI };
412+ string errinfo;
413+ repo.update (errinfo);
419414 }
420415#else
421416 if (string html; Network::GET (" https://raw.sevencdn.com/Dice-Developer-Team/Dice/newdev/Dice/webui.html" , html)) {
422- fs::create_directories (DiceDir / " webui " );
423- ofstream fweb{ DiceDir / " webui" / " webui .html" };
417+ fs::create_directories (dirWebUI );
418+ ofstream fweb{ DiceDir / " webui" / " index .html" };
424419 fweb.write (html.c_str (), html.length ());
425420 }
426- else if (!fs::exists (DiceDir / " webui" / " index.html" )) {
421+ #endif
422+ if (!fs::exists (DiceDir / " webui" / " index.html" )) {
427423 console.log (" 获取webui页面失败!相关功能无法使用!" , 0b10 );
428424 }
429- #endif
430- if (fs::exists (DiceDir / " webui" / " webui.html" ))
431- fs::copy_file (DiceDir / " webui" / " webui.html" , DiceDir / " webui" / " index.html" , fs::copy_options::update_existing);
432425 ManagerServer->addHandler (" /api/basicinfo" , h_basicinfoapi);
433426 ManagerServer->addHandler (" /api/custommsg" , h_msgapi);
434427 ManagerServer->addHandler (" /api/adminconfig" , h_config);
0 commit comments