コード例 #1
0
        /// <summary>
        /// 新建进程,载入V2ray配置文件字符串
        /// 返回新进程pid。
        /// </summary>
        public int LoadV2rayConfigString(Config config, List <int> _selecteds)
        {
            int    pid       = -1;
            string configStr = V2rayConfigHandler.GenerateClientSpeedtestConfigString(config, _selecteds, out string msg);

            if (configStr == "")
            {
                ShowMsg(false, msg);
            }
            else
            {
                ShowMsg(false, msg);
                pid = V2rayStartNew(configStr);
                //V2rayRestart();
                // start with -config
            }
            return(pid);
        }
コード例 #2
0
 /// <summary>
 /// 载入V2ray
 /// </summary>
 public void LoadV2ray(Config config)
 {
     if (Global.reloadV2ray)
     {
         string msg      = string.Empty;
         string fileName = Utils.GetPath(v2rayConfigRes);
         if (V2rayConfigHandler.GenerateClientConfig(config, fileName, out msg) != 0)
         {
             ShowMsg(false, msg);
         }
         else
         {
             ShowMsg(true, msg);
             V2rayRestart();
             SetSysAgent(config);
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// 批量添加服务器
        /// </summary>
        /// <param name="config"></param>
        /// <param name="clipboardData"></param>
        /// <param name="subid"></param>
        /// <returns></returns>
        public static int AddBatchServers(ref Config config, string clipboardData, string subid = "")
        {
            if (Utils.IsNullOrEmpty(clipboardData))
            {
                return(-1);
            }
            if (clipboardData.IndexOf("vmess") >= 0 && clipboardData.IndexOf("vmess") == clipboardData.LastIndexOf("vmess"))
            {
                clipboardData = clipboardData.Replace("\r\n", "").Replace("\n", "");
            }
            int countServers = 0;

            //string[] arrData = clipboardData.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            string[] arrData = clipboardData.Split(Environment.NewLine.ToCharArray());
            foreach (string str in arrData)
            {
                string    msg;
                VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(str, out msg);
                if (vmessItem == null)
                {
                    continue;
                }
                vmessItem.subid = subid;
                if (vmessItem.configType == (int)EConfigType.Vmess)
                {
                    if (AddServer(ref config, vmessItem, -1) == 0)
                    {
                        countServers++;
                    }
                }
                else if (vmessItem.configType == (int)EConfigType.Shadowsocks)
                {
                    if (AddShadowsocksServer(ref config, vmessItem, -1) == 0)
                    {
                        countServers++;
                    }
                }
            }
            if (countServers > 0)
            {
                return(0);
            }
            return(-1);
        }
コード例 #4
0
ファイル: MainFormHandler.cs プロジェクト: zmx170331/v2rayN
        public void Export2ClientConfig(int index, Config config)
        {
            //int index = GetLvSelectedIndex();
            if (index < 0)
            {
                return;
            }
            if (config.vmess[index].configType != (int)EConfigType.Vmess &&
                config.vmess[index].configType != (int)EConfigType.VLESS)
            {
                UI.Show(UIRes.I18N("NonVmessService"));
                return;
            }

            SaveFileDialog fileDialog = new SaveFileDialog
            {
                Filter           = "Config|*.json",
                FilterIndex      = 2,
                RestoreDirectory = true
            };

            if (fileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string fileName = fileDialog.FileName;

            if (Utils.IsNullOrEmpty(fileName))
            {
                return;
            }
            Config configCopy = Utils.DeepCopy(config);

            configCopy.index = index;
            if (V2rayConfigHandler.Export2ClientConfig(configCopy, fileName, out string msg) != 0)
            {
                UI.Show(msg);
            }
            else
            {
                UI.ShowWarning(string.Format(UIRes.I18N("SaveClientConfigurationIn"), fileName));
            }
        }
コード例 #5
0
ファイル: V2rayHandler.cs プロジェクト: a1ex4ord/v2rayN
        /// <summary>
        /// 载入V2ray
        /// </summary>
        public void LoadV2ray(Config config)
        {
            if (Global.reloadV2ray)
            {
                var item = ConfigHandler.GetDefaultServer(ref config);
                if (item == null)
                {
                    ShowMsg(false, ResUI.CheckServerSettings);
                    return;
                }

                if (SetCore(config, item) != 0)
                {
                    ShowMsg(false, ResUI.CheckServerSettings);
                    return;
                }
                string fileName = Utils.GetPath(v2rayConfigRes);
                if (V2rayConfigHandler.GenerateClientConfig(item, fileName, out string msg, out string content) != 0)
                {
                    ShowMsg(false, msg);
                }
                else
                {
                    ShowMsg(false, msg);
                    ShowMsg(true, $"[{config.GetGroupRemarks(item.groupId)}] {item.GetSummary()}");
                    V2rayRestart();
                }

                //start a socks service
                if (item.configType == EConfigType.Custom && item.preSocksPort > 0)
                {
                    var itemSocks = new VmessItem()
                    {
                        configType = EConfigType.Socks,
                        address    = Global.Loopback,
                        port       = item.preSocksPort
                    };
                    if (V2rayConfigHandler.GenerateClientConfig(itemSocks, null, out string msg2, out string configStr) == 0)
                    {
                        processId = V2rayStartNew(configStr);
                    }
                }
            }
コード例 #6
0
ファイル: MainFormHandler.cs プロジェクト: wpyok500/v2rayN
        public void Export2ServerConfig(VmessItem item, Config config)
        {
            if (item == null)
            {
                return;
            }
            if (item.configType != EConfigType.Vmess &&
                item.configType != EConfigType.VLESS)
            {
                UI.Show(ResUI.NonVmessService);
                return;
            }

            SaveFileDialog fileDialog = new SaveFileDialog
            {
                Filter           = "Config|*.json",
                FilterIndex      = 2,
                RestoreDirectory = true
            };

            if (fileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string fileName = fileDialog.FileName;

            if (Utils.IsNullOrEmpty(fileName))
            {
                return;
            }
            //Config configCopy = Utils.DeepCopy(config);
            //configCopy.index = index;
            if (V2rayConfigHandler.Export2ServerConfig(item, fileName, out string msg) != 0)
            {
                UI.Show(msg);
            }
            else
            {
                UI.ShowWarning(string.Format(ResUI.SaveServerConfigurationIn, fileName));
            }
        }
コード例 #7
0
        /// <summary>
        /// 载入V2ray
        /// </summary>
        public void LoadV2ray(Config config)
        {
            if (Global.reloadV2ray)
            {
                string fileName = Utils.GetPath(v2rayConfigRes);
                if (V2rayConfigHandler.GenerateClientConfig(config, fileName, false, out string msg) != 0)
                {
                    ShowMsg(false, msg);
                }
                else
                {
                    var vmessSelected = config.vmess[config.index];
                    var isTrojan      = vmessSelected.configType == (int)EConfigType.Trojan;

                    // construct trojan config file before start
                    if (isTrojan)
                    {
                        TrojanConfigCli cfg = new TrojanConfigCli
                        {
                            remote_addr = vmessSelected.address,
                            remote_port = vmessSelected.port,
                            password    = new List <string>()
                            {
                                vmessSelected.id
                            },
                            local_port = config.inbound[0].localPort
                        };
                        if (config.allowLANConn)
                        {
                            cfg.local_addr = "0.0.0.0";
                        }

                        Utils.ToJsonFile(cfg, Utils.GetPath("config.json"));
                    }


                    ShowMsg(true, msg);
                    V2rayRestart(config.vmess[config.index].configType == (int)EConfigType.Trojan);
                }
            }
        }
コード例 #8
0
ファイル: V2rayHandler.cs プロジェクト: xxoolm/v2rayN-2
        /// <summary>
        /// 载入V2ray
        /// </summary>
        public void LoadV2ray(Config config)
        {
            if (Global.reloadV2ray)
            {
                var item = ConfigHandler.GetDefaultServer(ref config);
                if (item == null)
                {
                    ShowMsg(false, UIRes.I18N("CheckServerSettings"));
                    return;
                }

                SetCore(config, item);
                string fileName = Utils.GetPath(v2rayConfigRes);
                if (V2rayConfigHandler.GenerateClientConfig(item, fileName, false, out string msg) != 0)
                {
                    ShowMsg(false, msg);
                }
                else
                {
                    ShowMsg(true, msg);
                    V2rayRestart();
                }
            }
        }
コード例 #9
0
ファイル: ConfigHandler.cs プロジェクト: zza830/v2rayN
        /// <summary>
        /// 批量添加服务器
        /// </summary>
        /// <param name="config"></param>
        /// <param name="clipboardData"></param>
        /// <param name="subid"></param>
        /// <returns>成功导入的数量</returns>
        public static int AddBatchServers(ref Config config, string clipboardData, string subid = "")
        {
            if (Utils.IsNullOrEmpty(clipboardData))
            {
                return(-1);
            }
            //if (clipboardData.IndexOf("vmess") >= 0 && clipboardData.IndexOf("vmess") == clipboardData.LastIndexOf("vmess"))
            //{
            //    clipboardData = clipboardData.Replace("\r\n", "").Replace("\n", "");
            //}
            int countServers = 0;

            //string[] arrData = clipboardData.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            string[] arrData = clipboardData.Split(Environment.NewLine.ToCharArray());
            foreach (string str in arrData)
            {
                //maybe sub
                if (str.StartsWith(Global.httpsProtocol) || str.StartsWith(Global.httpProtocol))
                {
                    if (AddSubItem(ref config, str) == 0)
                    {
                        countServers++;
                    }
                    continue;
                }
                VmessItem vmessItem = V2rayConfigHandler.ImportFromClipboardConfig(str, out string msg);
                if (vmessItem == null)
                {
                    continue;
                }
                vmessItem.subid = subid;
                if (vmessItem.configType == (int)EConfigType.Vmess)
                {
                    if (AddServer(ref config, vmessItem, -1) == 0)
                    {
                        countServers++;
                    }
                }
                else if (vmessItem.configType == (int)EConfigType.Shadowsocks)
                {
                    if (AddShadowsocksServer(ref config, vmessItem, -1) == 0)
                    {
                        countServers++;
                    }
                }
                else if (vmessItem.configType == (int)EConfigType.Socks)
                {
                    if (AddSocksServer(ref config, vmessItem, -1) == 0)
                    {
                        countServers++;
                    }
                }
                else if (vmessItem.configType == (int)EConfigType.Trojan)
                {
                    if (AddTrojanServer(ref config, vmessItem, -1) == 0)
                    {
                        countServers++;
                    }
                }
            }
            return(countServers);
        }