firemail
标题:
代理相关
[打印本页]
作者:
Qter
时间:
2020-9-1 11:03
标题:
代理相关
本帖最后由 Qter 于 2020-9-1 16:23 编辑
const char* proxyinfo = nullptr;
ArgResult ar = CheckArg("proxyinfo", &proxyinfo);
if (ar == ARG_FOUND) {
nsAutoCString hostPort(proxyinfo);
int32_t portDelimOffset = hostPort.RFindChar(':');
if (portDelimOffset > 0) {
nsAutoCString host(Substring(hostPort, 0, portDelimOffset));
nsAutoCString port(Substring(hostPort, portDelimOffset + 1,
hostPort.Length() - (portDelimOffset + 1)));
nsCOMPtr<nsIPrefService> prefSvc =
do_GetService("@mozilla.org/preferences-service;1");
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(prefSvc);
if (prefBranch) {
prefBranch->SetCharPref("network.proxy.http", host);
prefBranch->SetCharPref("network.proxy.ssl", host);
prefBranch->SetCharPref("network.proxy.socks", host);
nsresult stringErr;
int32_t portValue = port.ToInteger(&stringErr);
prefBranch->SetIntPref("network.proxy.http_port", portValue);
prefBranch->SetIntPref("network.proxy.ssl_port", portValue);
prefBranch->SetIntPref("network.proxy.socks_port", portValue);
prefSvc->SavePrefFile(nullptr);
}
}
}
复制代码
上面这种方法vs中调试时会自动退出,实际又可以使用,重新编译一下,和重新编译无关,调整下会话参数位置 把 proxyinfo放到前面如下
-proxyinfo 127.0.0.1:1080 -no-remote -profile $(TopObjDir)\tmp\profile-default -wait-for-browser
复制代码
const char* proxyinfo = nullptr;
ArgResult ar = CheckArg("proxyinfo", &proxyinfo);
if (ar == ARG_FOUND) {
nsAutoCString hostPort(proxyinfo);
int32_t portDelimOffset = hostPort.RFindChar(':');
if (portDelimOffset > 0) {
nsAutoCString host(Substring(hostPort, 0, portDelimOffset));
nsAutoCString port(Substring(hostPort, portDelimOffset + 1,
hostPort.Length() - (portDelimOffset + 1)));
nsCOMPtr<nsIFile> proxyconfINI;
rv = NS_GetSpecialDirectory("UAppData", getter_AddRefs(proxyconfINI));
NS_ENSURE_SUCCESS(rv, rv);
proxyconfINI->AppendNative(NS_LITERAL_CSTRING("longchatconfig.ini"));
bool exists;
rv = proxyconfINI->Exists(&exists);
NS_ENSURE_SUCCESS(rv, rv);
if (!exists) {
// Create the file so the INI processor can write to it.
rv = proxyconfINI->Create(nsIFile::NORMAL_FILE_TYPE, 0600);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIINIParserFactory> iniFactory =
do_GetService("@mozilla.org/xpcom/ini-parser-factory;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIINIParser> iniParser;
rv = iniFactory->CreateINIParser(proxyconfINI,
getter_AddRefs(iniParser)); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIINIParserWriter> iniWriter = do_QueryInterface(iniParser);
NS_ENSURE_TRUE(iniWriter, NS_ERROR_FAILURE);
rv = iniWriter->SetString(NS_LITERAL_CSTRING("NetConfig"), NS_LITERAL_CSTRING("ip"), host);
rv = iniWriter->SetString(NS_LITERAL_CSTRING("NetConfig"), NS_LITERAL_CSTRING("port"), port);
NS_ENSURE_SUCCESS(rv, rv);
rv = iniWriter->WriteFile(proxyconfINI);
}
}
复制代码
欢迎光临 firemail (http://firemail.wang:8088/)
Powered by Discuz! X3