コード例 #1
0
        public static bool Start(V2RayVMess server, int listen)
        {
            string config_path = $@"{App.DirectoryV2Ray}\{v2ray_config_json_name}";
            string config_text = Properties.Resources.v2ray_config_json;

            string outbound = V2RayVMess.ToJson(server);

            config_text = config_text.Replace(config_listen_port, listen.ToString(CultureInfo.InvariantCulture));
            config_text = config_text.Replace(config_outbound, outbound);

            if (!FileUtil.WriteUTF8(config_path, config_text))
            {
                return(false);
            }

            try
            {
                process_v2ray = Process.Start(
                    new ProcessStartInfo
                {
                    FileName         = V2RayExePath,
                    Arguments        = $@"-config {config_path}",
                    WorkingDirectory = App.DirectoryV2Ray,
                    CreateNoWindow   = true,
                    UseShellExecute  = false,
                    LoadUserProfile  = false,
                });
            }
            catch
            {
                return(false);
            }

            return(true);
        }