Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
easyatm committed Apr 14, 2022
1 parent b1ae342 commit a67482c
Showing 1 changed file with 48 additions and 17 deletions.
65 changes: 48 additions & 17 deletions msedge/msedge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,27 @@
#include <easy/easy.h>
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();

auto my_path = process.exe_path();
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);
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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;
}

0 comments on commit a67482c

Please sign in to comment.