firemail

标题: 代理相关 [打印本页]

作者: Qter    时间: 2020-9-1 11:03
标题: 代理相关
本帖最后由 Qter 于 2020-9-1 16:23 编辑
  1.   const char* proxyinfo = nullptr;
  2.   ArgResult ar = CheckArg("proxyinfo", &proxyinfo);
  3.   if (ar == ARG_FOUND) {
  4.     nsAutoCString hostPort(proxyinfo);
  5.     int32_t portDelimOffset = hostPort.RFindChar(':');
  6.     if (portDelimOffset > 0) {
  7.       nsAutoCString host(Substring(hostPort, 0, portDelimOffset));
  8.       nsAutoCString port(Substring(hostPort, portDelimOffset + 1,
  9.                                    hostPort.Length() - (portDelimOffset + 1)));

  10.       nsCOMPtr<nsIPrefService> prefSvc =
  11.           do_GetService("@mozilla.org/preferences-service;1");

  12.       nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(prefSvc);
  13.       if (prefBranch) {
  14.         prefBranch->SetCharPref("network.proxy.http", host);
  15.         prefBranch->SetCharPref("network.proxy.ssl", host);
  16.         prefBranch->SetCharPref("network.proxy.socks", host);
  17.         nsresult stringErr;
  18.         int32_t portValue = port.ToInteger(&stringErr);
  19.         prefBranch->SetIntPref("network.proxy.http_port", portValue);
  20.         prefBranch->SetIntPref("network.proxy.ssl_port", portValue);
  21.         prefBranch->SetIntPref("network.proxy.socks_port", portValue);

  22.         prefSvc->SavePrefFile(nullptr);
  23.       }
  24.     }
  25.   }
复制代码
上面这种方法vs中调试时会自动退出,实际又可以使用,重新编译一下,和重新编译无关,调整下会话参数位置 把 proxyinfo放到前面如下
  1. -proxyinfo 127.0.0.1:1080 -no-remote -profile $(TopObjDir)\tmp\profile-default -wait-for-browser
复制代码
  1. const char* proxyinfo = nullptr;
  2.   ArgResult ar = CheckArg("proxyinfo", &proxyinfo);
  3.   if (ar == ARG_FOUND) {
  4.     nsAutoCString hostPort(proxyinfo);
  5.     int32_t portDelimOffset = hostPort.RFindChar(':');
  6.     if (portDelimOffset > 0) {
  7.       nsAutoCString host(Substring(hostPort, 0, portDelimOffset));
  8.       nsAutoCString port(Substring(hostPort, portDelimOffset + 1,
  9.                                    hostPort.Length() - (portDelimOffset + 1)));
  10.       nsCOMPtr<nsIFile> proxyconfINI;
  11.       rv = NS_GetSpecialDirectory("UAppData", getter_AddRefs(proxyconfINI));
  12.       NS_ENSURE_SUCCESS(rv, rv);
  13.       proxyconfINI->AppendNative(NS_LITERAL_CSTRING("longchatconfig.ini"));
  14.       bool exists;
  15.       rv = proxyconfINI->Exists(&exists);
  16.       NS_ENSURE_SUCCESS(rv, rv);
  17.        if (!exists) {
  18.         // Create the file so the INI processor can write to it.
  19.         rv = proxyconfINI->Create(nsIFile::NORMAL_FILE_TYPE, 0600);
  20.         NS_ENSURE_SUCCESS(rv, rv);
  21.       }
  22.        nsCOMPtr<nsIINIParserFactory> iniFactory =
  23.           do_GetService("@mozilla.org/xpcom/ini-parser-factory;1", &rv);
  24.        NS_ENSURE_SUCCESS(rv, rv);
  25.         nsCOMPtr<nsIINIParser> iniParser;
  26.         rv = iniFactory->CreateINIParser(proxyconfINI,
  27.         getter_AddRefs(iniParser)); NS_ENSURE_SUCCESS(rv, rv);
  28.         nsCOMPtr<nsIINIParserWriter> iniWriter = do_QueryInterface(iniParser);
  29.         NS_ENSURE_TRUE(iniWriter, NS_ERROR_FAILURE);
  30.         rv = iniWriter->SetString(NS_LITERAL_CSTRING("NetConfig"), NS_LITERAL_CSTRING("ip"), host);
  31.         rv = iniWriter->SetString(NS_LITERAL_CSTRING("NetConfig"), NS_LITERAL_CSTRING("port"), port);
  32.         NS_ENSURE_SUCCESS(rv, rv);
  33.         rv = iniWriter->WriteFile(proxyconfINI);
  34.     }
  35.   }
复制代码





欢迎光临 firemail (http://firemail.wang:8088/) Powered by Discuz! X3