From a67482c09569edb6d1a8297d91cb7fd01531b0bd Mon Sep 17 00:00:00 2001 From: eATM Date: Fri, 15 Apr 2022 01:36:57 +0800 Subject: [PATCH] a --- msedge/msedge.cpp | 65 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/msedge/msedge.cpp b/msedge/msedge.cpp index e260f96..b0aa3a0 100644 --- a/msedge/msedge.cpp +++ b/msedge/msedge.cpp @@ -8,18 +8,14 @@ #include using namespace easy; +jsoncpp jsonConfig; + //安装卸载 void install(bool isInstall) { eString err_message; - jsoncpp json; - if (!json.readConfig("config.json")) - { - process.exit("缺少config.json文件"); - } - - eString edge_path = json["edge_path"].asString(); + eString edge_path = jsonConfig["edge_path"].asString(); eString edge_dir = edge_path.to_file_dir(); edge_dir.pop_back(); @@ -27,12 +23,12 @@ void install(bool isInstall) auto my_dir = process.exe_dir(); my_dir.pop_back(); - json["reg_paths"].forEach([&](jsoncpp& item) + jsonConfig["reg_paths"].forEach([&](jsoncpp& item) { eString path = item["path"].asString(); eString name = item["name"].asString(); eString value = item["value"].asString(); - + if (isInstall) { value.replaceAll("[EXE]", my_path); @@ -43,7 +39,7 @@ void install(bool isInstall) value.replaceAll("[DIR]", edge_dir); } - if (!util::write_reg_string(path,name,value)) + if (!util::write_reg_string(path, name, value)) { if (!err_message.empty()) err_message += "\r\n"; err_message += util::Format("与入路径失败:{}", path); @@ -65,9 +61,14 @@ int APIENTRY WinMain(_In_ HINSTANCE hInstance, UNREFERENCED_PARAMETER(lpCmdLine); eString cmdstr(lpCmdLine); + if (!jsonConfig.readConfig("config.json")) + { + process.exit("缺少config.json文件"); + } + console.set_logfile(); process.set_exception_dump(false); - + bool isInstall = cmdstr.compare_icase("/install"); bool isUninstall = cmdstr.compare_icase("/uninstall"); if (isInstall || isUninstall) @@ -77,19 +78,44 @@ int APIENTRY WinMain(_In_ HINSTANCE hInstance, } eString urlStr; - + do { console.log("{}", cmdstr); eString url = cmdstr.get_url_paramsv("url"); if (url.empty()) break; - auto keysv = url.get_url_paramsv("q"); + + if (url.find("://") == std::string::npos) url = util::url_decode(url); + + eStringV keysv = url.get_url_paramsv("q"); if (!keysv.empty()) { console.log("key:{}", keysv); - urlStr = "https://www.google.com.hk/search?q="; - urlStr += keysv; + + //搜索类型 %3A为:的编码 + eStringV subType = keysv.Mid("", "%3A"); + + //匹配配置文件 + if (!subType.empty() && jsonConfig["urls"][subType].isString()) + { + urlStr = jsonConfig["urls"][subType].asString(); + keysv = keysv.substr(subType.size() + 3); + } + + //如果没有则使用缺省的搜索引擎 + if (urlStr.empty() && jsonConfig["urls"]["default"].isString()) + { + urlStr = jsonConfig["urls"]["default"].asString(); + } + + //如果再没有就使用google + if (urlStr.empty()) + { + urlStr = "https://www.google.com.hk/search?q=[KEY]"; + } + + urlStr.replaceAll("[KEY]", keysv); } else { urlStr = url; @@ -100,13 +126,18 @@ int APIENTRY WinMain(_In_ HINSTANCE hInstance, } console.log("url:{}", urlStr); } while (false); - + if (!urlStr.empty()) { process.run_app(urlStr); } else { - box.MessageInfo(cmdstr, "未知参数"); + console.log("未知参数:{}", lpCmdLine); + eString edge_path = jsonConfig["edge_path"].asString(); + if (!edge_path.empty()) + { + process.run_app(edge_path, lpCmdLine); + } } return 0; } \ No newline at end of file