Ejemplo n.º 1
0
        private async void GetAblum(string id)
        {
            var pb = PendingBox.Show("解析中...", null, false, Application.Current.MainWindow, new PendingBoxConfigurations()
            {
                MaxHeight = 160,
                MinWidth  = 400
            });

            try
            {
                SearchListItem.Clear();
                musicinfo?.Clear();
                int api = apiComboBox.SelectedIndex + 1;
                await Task.Run(() =>
                {
                    musicinfo = music.GetAlbum(id, api);
                });

                if (musicinfo == null)
                {
                    pb.Close();
                    MessageBoxX.Show("解析错误", "警告", configurations: new MessageBoxXConfigurations()
                    {
                        MessageBoxIcon = MessageBoxIcon.Error
                    });
                    return;
                }
                foreach (MusicInfo m in musicinfo)
                {
                    SearchListItemModel mod = new SearchListItemModel()
                    {
                        Album      = m.Album,
                        Singer     = m.Singer,
                        IsSelected = false,
                        Title      = m.Title
                    };
                    SearchListItem.Add(mod);
                }
                List.ItemsSource = SearchListItem;
                List.Items.Refresh();
                pb.Close();
            }
            catch
            {
                pb.Close();
                MessageBoxX.Show("解析错误", "警告", configurations: new MessageBoxXConfigurations()
                {
                    MessageBoxIcon = MessageBoxIcon.Error
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 弹框确认进行操作
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool ConfirmAction(string msg)
        {
            var result = MessageBoxX.Show(msg, "警告", Application.Current.MainWindow, MessageBoxButton.YesNo, new MessageBoxXConfigurations()
            {
                MessageBoxStyle = MessageBoxStyle.Classic,
                MessageBoxIcon  = MessageBoxIcon.Warning
            });

            if (result == MessageBoxResult.Yes || result == MessageBoxResult.OK)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public void Delete(DataRowView dataRowView)
        {
            string           name   = dataRowView.Row[Key.name.ToString()].ToString();
            MessageBoxResult result = MessageBoxX.Show("是否二维码: " + name, "删除确认", null, System.Windows.MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.Cancel)
            {
                return;
            }

            // 开始删除
            Store.DataBase.DeleteQRCode(_storageName, name);
            dataRowView.Delete();
        }
Ejemplo n.º 4
0
        private void comboBoxProfiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = comboBoxProfiles.SelectedIndex;

            if (index != -1 && !Global.Settings.Profiles[index].IsDummy)
            {
                try {
                    LoadProfile(index);
                } catch (Exception exception) {
                    MessageBoxX.Show(exception.Message, LogLevel.ERROR);
                    return;
                }
            }
        }
Ejemplo n.º 5
0
        private void MainWindow_Closed(object sender, System.ComponentModel.CancelEventArgs e)
        {
            var v = MessageBoxX.Show("您确定要退出程序吗?", "您要退出吗?", this, MessageBoxButton.OKCancel, "InfoTheme");

            if (v != MessageBoxResult.OK)
            {
                e.Cancel = true;
            }
            else
            {
                e.Cancel = false;
            }
            return;
        }
Ejemplo n.º 6
0
 private static void CheckOS()
 {
     if (Environment.OSVersion.Version.Build < 17763)
     {
         Flags.NoSupport = true;
         if (!Global.Settings.NoSupportDialog)
         {
             MessageBoxX.Show(
                 i18N.TranslateFormat("{0} won't get developers' support, Please do not report any issues or seek help from developers.",
                                      Environment.OSVersion),
                 LogLevel.WARNING);
         }
     }
 }
Ejemplo n.º 7
0
        private void Window_ClosingAsync(object sender, System.ComponentModel.CancelEventArgs e)
        {
            var rest = MessageBoxX.Show("确定退出程序吗?", "警告", Application.Current.MainWindow, MessageBoxButton.YesNo);

            if (rest == MessageBoxResult.Yes)
            {
                e.Cancel = false;
                Application.Current.Shutdown();
            }
            else
            {
                e.Cancel = true;
            }
        }
Ejemplo n.º 8
0
 private void B21_Click(object sender, RoutedEventArgs e)
 {
     if (PassWord.Visibility == Visibility.Visible)
     {
         if (!String.IsNullOrWhiteSpace(Password.Password))
         {
             if (Password.Password == "NULL" || Password.Password == "null")
             {
                 Password.Password = "";
                 PasswordBoxHelper.SetWatermark(Password, " ( 这不是个合法的密码! ) ");
                 return;
             }
             Main.Settings["Features"]["Privacy"]["Password"] = Password.Password;
             SaveSet();
             Password.Password = "";
         }
         this.PassWord.Visibility = Visibility.Collapsed;
     }
     else
     {
         if (Main.Settings["Features"]["Privacy"]["Password"].ToString() != "NULL")
         {
             PassWordEnterF7 EP = new PassWordEnterF7();
             this.IsMaskVisible       = true;
             EP.Owner                 = this;
             EP.WindowStartupLocation = WindowStartupLocation.CenterOwner;
             EP.ShowDialog();
             this.IsMaskVisible = false;
         }
         else
         {
             LoadingSetter.PasswordPass = true;
         }
         if (!LoadingSetter.PasswordPass)
         {
             return;
         }
         LoadingSetter.PasswordPass = false;
         this.PassWord.Visibility   = Visibility.Visible;
         PasswordBoxHelper.SetWatermark(Password, " ( 再次点击设置按钮确定 ) ");
         if (Main.Settings["Features"]["Privacy"]["Password"].ToString() != "NULL")
         {
             PasswordBoxHelper.SetWatermark(Password, " ( 空白将保持已设置的密码 ) ");
         }
         else
         {
             MessageBoxX.Show("私隐密码为弱密码,以 <明文> 记录在设置文件中,这意味着这个密码仅用于警告,没有任何安全性,请不要把重要信息存储在 SSTB 内。", "提示");
         }
     }
 }
Ejemplo n.º 9
0
        private void DeleteProfilePictureBox_Click(object sender, EventArgs e)
        {
            int index = comboBoxProfiles.SelectedIndex;

            if (index != -1)
            {
                if (MessageBoxX.Show(i18N.Translate("Remove this Profile?"), confirm: true) != DialogResult.OK)
                {
                    return;
                }
                RemoveProfile(index);
                comboBoxProfiles.Items[index] = i18N.Translate("None");;
            }
        }
 /// <summary>
 /// 原创榜
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Label_PreviewMouseDown_3(object sender, MouseButtonEventArgs e)
 {
     if (apiComboBox.SelectedIndex == 0)
     {
         GetNeteaseMusicList("2884035");
     }
     if (apiComboBox.SelectedIndex == 1)
     {
         MessageBoxX.Show("该音源无原创榜", "提示", Application.Current.MainWindow, MessageBoxButton.OK, new MessageBoxXConfigurations()
         {
             MessageBoxIcon = MessageBoxIcon.Warning
         });
     }
 }
Ejemplo n.º 11
0
    private void AddButton_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrWhiteSpace(RemarkTextBox.Text))
        {
            MessageBoxX.Show(i18N.Translate("Remark can not be empty"));
            return;
        }

        if (string.IsNullOrWhiteSpace(LinkTextBox.Text))
        {
            MessageBoxX.Show(i18N.Translate("Link can not be empty"));
            return;
        }

        if (!LinkTextBox.Text.StartsWith("HTTP://", StringComparison.OrdinalIgnoreCase) &&
            !LinkTextBox.Text.StartsWith("HTTPS://", StringComparison.OrdinalIgnoreCase))
        {
            MessageBoxX.Show(i18N.Translate("Link must start with http:// or https://"));
            return;
        }

        if (SelectedIndex == -1)
        {
            if (Global.Settings.Subscription.Any(link => link.Remark.Equals(RemarkTextBox.Text)))
            {
                MessageBoxX.Show(i18N.Translate("Subscription with the specified remark already exists"));
                return;
            }

            Global.Settings.Subscription.Add(new Subscription
            {
                Enable    = true,
                Remark    = RemarkTextBox.Text,
                Link      = LinkTextBox.Text,
                UserAgent = UserAgentTextBox.Text
            });
        }
        else
        {
            var subscribeLink = Global.Settings.Subscription[SelectedIndex];

            RenameServers(subscribeLink.Remark, RemarkTextBox.Text);
            subscribeLink.Link      = LinkTextBox.Text;
            subscribeLink.Remark    = RemarkTextBox.Text;
            subscribeLink.UserAgent = UserAgentTextBox.Text;
        }

        LoadSubscriptionLinks();
    }
Ejemplo n.º 12
0
 private void BtnViewCode_Click(object sender, RoutedEventArgs e)
 {
     MessageBoxX.Show(TestDataList[0].IsEnabled.ToString(), "Title");
     if (_isCodeViewing)
     {
         if (Helper.Tier == 2)
         {
             AnimationHelper.SetEasingFunction(GrpPalette, new CubicEase()
             {
                 EasingMode = EasingMode.EaseOut
             });
             AnimationHelper.SetMarginTo(GrpPalette, new Thickness(0, 0, 0, 0));
             AnimationHelper.SetEasingFunction(GrpCode, new CubicEase()
             {
                 EasingMode = EasingMode.EaseOut
             });
             AnimationHelper.SetMarginTo(GrpCode, new Thickness(0, 0, 0, 0));
         }
         else
         {
             GrpPalette.Margin = new Thickness(0, 0, 0, 0);
             GrpCode.Margin    = new Thickness(0, 0, 0, 0);
         }
         BtnViewCode.Content = Properties.Resource.ViewCode;
     }
     else
     {
         if (Helper.Tier == 2)
         {
             AnimationHelper.SetEasingFunction(GrpPalette, new CubicEase()
             {
                 EasingMode = EasingMode.EaseOut
             });
             AnimationHelper.SetMarginTo(GrpPalette, new Thickness(0, -120, 0, 0));
             AnimationHelper.SetEasingFunction(GrpCode, new CubicEase()
             {
                 EasingMode = EasingMode.EaseOut
             });
             AnimationHelper.SetMarginTo(GrpCode, new Thickness(0, 0, 0, -120));
         }
         else
         {
             GrpPalette.Margin = new Thickness(0, -120, 0, 0);
             GrpCode.Margin    = new Thickness(0, 0, 0, -120);
         }
         BtnViewCode.Content = Properties.Resource.CloseCodeViewer;
     }
     _isCodeViewing = !_isCodeViewing;
 }
Ejemplo n.º 13
0
 private void DelRuleButtonClick(object sender, System.Windows.RoutedEventArgs e)
 {
     if (Rule_ListBox.SelectedIndex == -1)
     {
         MessageBoxX.Show("您尚未选择任何规则!", "错误", MessageBoxButton.OK, MessageBoxIcon.Error);
         return;
     }
     else
     {
         RuleList.Remove(RuleList[Rule_ListBox.SelectedIndex]);
         DealOldData();
         Show_List();
         Show_Rule_List();
     }
 }
Ejemplo n.º 14
0
        private void SavePorfilePictureBox_Click(object sender, EventArgs e)
        {
            int index = comboBoxProfiles.SelectedIndex;

            if (index != -1)
            {
                try {
                    SaveProfile(index);
                    comboBoxProfiles.Items[index] = $"[{index + 1}] {ProfileNameText.Text}";
                } catch (Exception exception) {
                    MessageBoxX.Show(exception.Message, LogLevel.ERROR);
                    return;
                }
            }
        }
Ejemplo n.º 15
0
    private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
    {
        if (MessageBoxX.Show(i18N.Translate("Delete or not ? Will clean up the corresponding group of items in the server list"),
                             confirm: true) != DialogResult.OK)
        {
            return;
        }

        var subscribeLink = Global.Settings.Subscription[SelectedIndex];

        DeleteServers(subscribeLink.Remark);
        Global.Settings.Subscription.Remove(subscribeLink);

        LoadSubscriptionLinks();
    }
Ejemplo n.º 16
0
        public void ForbiddenUser(DataRowView dataRowView)
        {
            MessageBoxResult result = MessageBoxX.Show(string.Format("是否禁用用户:{0}", dataRowView.Row[Key.name.ToString()]), "禁用账户", null, MessageBoxButton.OKCancel);

            if (result != MessageBoxResult.OK)
            {
                return;
            }

            User user = dataRowView.Row.ConvertToModel <User>();

            user.forbidden = true;
            Store.DataBase.UpdateUser(user);
            dataRowView.Row[Key.forbidden.ToString()] = true;
        }
Ejemplo n.º 17
0
        public void DeleteUser(DataRowView dataRowView)
        {
            MessageBoxResult result = MessageBoxX.Show(string.Format("是否删除用户:{0}", dataRowView.Row[Key.name.ToString()]), "删除账户", null, MessageBoxButton.OKCancel);

            if (result != MessageBoxResult.OK)
            {
                return;
            }

            // 删除数据库
            Store.DataBase.DeleteUser(dataRowView.Row[Key.userId.ToString()].ToString());

            // 删除视图
            dataRowView.Delete();
        }
Ejemplo n.º 18
0
        private bool ValidateAccount()
        {
            if (string.IsNullOrEmpty(UserName))
            {
                MessageBoxX.Show("请输入用户名", "温馨提示");
                return(false);
            }

            if (string.IsNullOrEmpty(Password))
            {
                MessageBoxX.Show("请输入密码", "温馨提示");
                return(false);
            }
            return(true);
        }
Ejemplo n.º 19
0
        /// <summary>
        ///     搜索出口和TUNTAP适配器
        /// </summary>
        public static bool SearchTapAdapter()
        {
            // 搜索 TUN/TAP 适配器的索引
            if (string.IsNullOrEmpty(Global.TUNTAP.ComponentID = TUNTAP.GetComponentID()))
            {
                Logging.Info("找不到 TAP 适配器");
                if (MessageBoxX.Show(i18N.Translate("TUN/TAP driver is not detected. Is it installed now?"),
                                     confirm: true) == DialogResult.OK)
                {
                    Configuration.addtap();
                    // 给点时间,不然立马安装完毕就查找适配器可能会导致找不到适配器ID
                    Thread.Sleep(1000);
                    if (string.IsNullOrEmpty(Global.TUNTAP.ComponentID = TUNTAP.GetComponentID()))
                    {
                        Logging.Error("找不到 TAP 适配器,驱动可能安装失败");
                        return(false);
                    }
                }
                else
                {
                    Logging.Info("取消安装 TAP 驱动 ");
                    return(false);
                }
            }

            // 根据 ComponentID 寻找 Tap适配器
            try
            {
                var adapter = NetworkInterface.GetAllNetworkInterfaces().First(_ => _.Id == Global.TUNTAP.ComponentID);
                Global.TUNTAP.Adapter = adapter;
                Global.TUNTAP.Index   = adapter.GetIPProperties().GetIPv4Properties().Index;
                Logging.Info(
                    $"TAP 适配器:{adapter.Name} {adapter.Id} {adapter.Description}, index: {Global.TUNTAP.Index}");
            }
            catch (Exception e)
            {
                var msg = e switch
                {
                    InvalidOperationException _ => $"找不到标识符为 {Global.TUNTAP.ComponentID} 的 TAP 适配器: {e.Message}",
                    NetworkInformationException _ => $"获取 Tap 适配器信息错误: {e.Message}",
                    _ => $"Tap 适配器其他异常: {e}"
                };
                Logging.Error(msg);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 20
0
        /**
         * 注册各类监听事件
         *
         **/
        private void RegisterHookEven()
        {
            LogHelper.ShowLog("开始注册事件");
            try
            {
                int    mvid     = Convert.ToInt32(BaseConfig.YOUXI_VID, 16);
                int    mpid     = Convert.ToInt32(BaseConfig.YOUXI_PID, 16);
                IntPtr m_Handle = YouyiSdk.M_Open_VidPid(mvid, mpid);
                //IntPtr m_Handle = YouyiSdk.aeBGGOyo4(3);
                int check = YouyiSdk.M_ResolutionUsed(m_Handle, (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight);
                if ((int)m_Handle == -1)
                {
                    LogHelper.ShowLog("打开设备失败,请检查USB设备是否已经插入");
                    var result = MessageBoxX.Show("请检查USB设备是否已经插入", "提示", Application.Current.MainWindow, MessageBoxButton.OK, new MessageBoxXConfigurations()
                    {
                        MessageBoxIcon = MessageBoxIcon.Error,
                        ButtonBrush    = "#FF4C4C".ToColor().ToBrush(),
                    });
                    this.Shutdown();
                }
                else
                {
                    globalParam.m_Handle = m_Handle;
                    LogHelper.ShowLog("打开设备成功 m_Handle: {0} check: {1}", m_Handle, check);
                }

                // 注册鼠标事件
                mh = new MouseHook();
                mh.SetHook();
                MouseEvens evens = new MouseEvens(m_Handle);
                mh.MouseDownEvent += evens.mh_MouseDownEvent;
                mh.MouseUpEvent   += evens.mh_MouseUpEvent;

                //注册键盘事件
                k_hook = new KeyboardHook();
                KeyboardEvens keyEvens = new KeyboardEvens();
                k_hook.KeyDownEvent  += new System.Windows.Forms.KeyEventHandler(keyEvens.Hook_KeyDown); //按键按下
                k_hook.KeyUpEvent    += new System.Windows.Forms.KeyEventHandler(keyEvens.Hook_KeyUp);   //按键松开
                k_hook.KeyPressEvent += keyEvens.K_hook_KeyPressEvent;
                k_hook.Start();
            }
            catch (DllNotFoundException e)
            {
                LogHelper.ShowLog("调用动态链接库异常 {0}", e.Message);
                MessageBox.Show("软件资源损坏,请重新下载安装 \n" + e.Message);
                this.Shutdown();
            }
        }
Ejemplo n.º 21
0
        private void NotifyUpdate()
        {
            var result = MessageBoxX.Show("检测到新版,是否更新", "提示:", Application.Current.MainWindow, MessageBoxButton.YesNo, new MessageBoxXConfigurations()
            {
                MessageBoxIcon = MessageBoxIcon.Warning
            });

            if (result == MessageBoxResult.Yes)
            {
                Process.Start("https://www.nitian1207.cn/archives/496");
            }
            else
            {
                Environment.Exit(0);
            }
        }
Ejemplo n.º 22
0
        // =======================================

        private void BgworkChange(object sender, ProgressChangedEventArgs e)
        {
            ProgressBar.Value += e.ProgressPercentage;
            if (BeginBtn != null)
            {
                BeginBtn.Content = $"{FileName} Finished";
            }

            if (ProgressBar.Value >= ProgressBar.Maximum)
            {
                MessageBoxX.Show("", "Finished", Application.Current.MainWindow);
                mBgworker.DoWork          -= mDoWorkEventHandler;
                mBgworker.ProgressChanged -= mProgressChangedEventHandler;
                SetUIStates(true);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 失效
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FailDev_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (PublicParam.IsDoTask)
                {
                    Notice.Show("请先关闭顶部[设备运作]!", "提示", 3, MessageBoxIcon.Info);
                    return;
                }

                if (DGdevice.SelectedItem == null)
                {
                    return;
                }
                string flag = (DGdevice.SelectedItem as DataRowView)["DEV_USEFUL"].ToString();
                if (flag != "启用")
                {
                    Notice.Show("该设备暂无法失效!", "提示", 3, MessageBoxIcon.Info);
                    return;
                }
                string device  = (DGdevice.SelectedItem as DataRowView)["DEVICE"].ToString();
                string devtype = (DGdevice.SelectedItem as DataRowView)["DEV_TYPE"].ToString();

                MessageBoxResult result = MessageBoxX.Show("确认失效设备号【" + device + "】的数据?!", "提示", System.Windows.Application.Current.MainWindow, MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    return;
                }

                string res = UpdateUseful(devtype, device, false);
                if (string.IsNullOrEmpty(res))
                {
                    PublicParam.IsRe = true;
                    Notice.Show("失效成功!", "成功", 3, MessageBoxIcon.Success);
                }
                else
                {
                    Notice.Show("失效失败: " + res, "错误", 3, MessageBoxIcon.Error);
                }

                Refresh_Click(sender, (EventArgs)e);
            }
            catch (Exception ex)
            {
                Notice.Show("失效失败: " + ex.Message, "错误", 3, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 24
0
        private void ControlButton_Click(object sender, EventArgs e)
        {
            if (!Regex.Match(PortTextBox.Text, "^[0-9]+$").Success)
            {
                return;
            }
            if (Index == -1)
            {
                Global.Settings.Server.Add(new Models.Server
                {
                    Remark        = RemarkTextBox.Text,
                    Type          = "SSR",
                    Hostname      = AddressTextBox.Text,
                    Port          = int.Parse(PortTextBox.Text),
                    Password      = PasswordTextBox.Text,
                    EncryptMethod = EncryptMethodComboBox.Text,
                    Protocol      = ProtocolComboBox.Text,
                    ProtocolParam = ProtocolParamTextBox.Text,
                    OBFS          = OBFSComboBox.Text,
                    OBFSParam     = OBFSOptionParamTextBox.Text
                });
            }
            else
            {
                Global.Settings.Server[Index] = new Models.Server
                {
                    Remark        = RemarkTextBox.Text,
                    Group         = Global.Settings.Server[Index].Group,
                    Type          = "SSR",
                    Hostname      = AddressTextBox.Text,
                    Port          = int.Parse(PortTextBox.Text),
                    Password      = PasswordTextBox.Text,
                    EncryptMethod = EncryptMethodComboBox.Text,
                    Protocol      = ProtocolComboBox.Text,
                    ProtocolParam = ProtocolParamTextBox.Text,
                    OBFS          = OBFSComboBox.Text,
                    OBFSParam     = OBFSOptionParamTextBox.Text,
                    Country       = null
                };
            }

            Configuration.Save();
            MessageBoxX.Show(i18N.Translate("Saved"));
            Global.MainForm.InitServer();
            Close();
        }
Ejemplo n.º 25
0
        private void ScanButton_Click(object sender, EventArgs e)
        {
            var dialog = new CommonOpenFileDialog {
                IsFolderPicker            = true,
                Multiselect               = false,
                Title                     = i18N.Translate("Select a folder"),
                AddToMostRecentlyUsedList = false,
                EnsurePathExists          = true,
                NavigateToShortcut        = true
            };

            if (dialog.ShowDialog(Win32Native.GetForegroundWindow()) == CommonFileDialogResult.Ok)
            {
                ScanDirectory(dialog.FileName);
                MessageBoxX.Show(i18N.Translate("Scan completed"));
            }
        }
Ejemplo n.º 26
0
        private void WindowX_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            var result = MessageBoxX.Show("是否退出程序", "Error", Application.Current.MainWindow, MessageBoxButton.YesNo, new MessageBoxXConfigurations()
            {
                MessageBoxStyle = MessageBoxStyle.Modern,
            });

            if (result == MessageBoxResult.Yes || result == MessageBoxResult.OK)
            {
                DataControl.BeforeClose();
                System.Environment.Exit(0);
            }
            else
            {
                e.Cancel = true;
            }
        }
Ejemplo n.º 27
0
        private void EditServerPictureBox_Click(object sender, EventArgs e)
        {
            // 当前ServerComboBox中至少有一项
            if (ServerComboBox.SelectedIndex == -1)
            {
                MessageBoxX.Show(i18N.Translate("Please select a server first"));
                return;
            }

            Hide();
            var server = Global.Settings.Server[ServerComboBox.SelectedIndex];

            Servers.GetUtilByTypeName(server.Type).Edit(server);
            InitServer();
            Configuration.Save();
            Show();
        }
Ejemplo n.º 28
0
        private void ControlButton_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(PortTextBox.Text, out var port))
            {
                return;
            }

            if (AlterIDTextBox.Text == "")
            {
                MessageBoxX.Show(i18N.Translate("Please fill in alterID"));
                return;
            }

            if (!int.TryParse(PortTextBox.Text, out var afterId))
            {
                return;
            }

            server.Remark           = RemarkTextBox.Text;
            server.Type             = "VMess";
            server.Hostname         = AddressTextBox.Text;
            server.Port             = port;
            server.UserID           = UserIDTextBox.Text;
            server.AlterID          = afterId;
            server.EncryptMethod    = EncryptMethodComboBox.Text;
            server.TransferProtocol = TransferProtocolComboBox.Text;
            server.FakeType         = FakeTypeComboBox.Text;
            server.Host             = HostTextBox.Text;
            server.Path             = PathTextBox.Text;
            server.QUICSecure       = QUICSecurityComboBox.Text;
            server.QUICSecret       = QUICSecretTextBox.Text;
            server.TLSSecure        = TLSSecureCheckBox.Checked;
            server.UseMux           = UseMuxCheckBox.Checked;
            server.Country          = null;

            if (Global.Settings.Server.IndexOf(server) == -1)
            {
                Global.Settings.Server.Add(server);
            }

            Configuration.Save();
            MessageBoxX.Show(i18N.Translate("Saved"));
            Global.MainForm.InitServer();
            Close();
        }
Ejemplo n.º 29
0
        private string DelRegeist(string key)
        {
            try
            {
                if (MessageBoxResult.No == MessageBoxHelper.MessageBoxShowQuestion("该操作会直接删除盒子注册表,只有在安装盒子时提示已安装相同或更高版本时,进行该操作。是否继续?"))
                {
                    return("");
                }

                //32位和64位配置
                var         useRegistryView = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32;
                RegistryKey localMachine    = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, useRegistryView);

                //删除注册表
                if (localMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\SmartBox", true) != null)
                {
                    localMachine.DeleteSubKeyTree("SOFTWARE\\Wow6432Node\\SmartBox", false);
                    Notice.Show("删除盒子注册表完成HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\SmartBox", "提示", 3, MessageBoxIcon.Info);
                }
                else
                {
                    Notice.Show("未找到盒子注册表路径HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\SmartBox", "提示", 3, MessageBoxIcon.Info);
                }

                if (localMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Smartbox", true) != null)
                {
                    localMachine.DeleteSubKeyTree("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Smartbox", false);
                    Notice.Show("删除盒子注册表完成HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Smartbox", "提示", 3, MessageBoxIcon.Info);
                }
                else
                {
                    Notice.Show("未找到盒子注册表路径HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Smartbox", "提示", 3, MessageBoxIcon.Info);
                }

                localMachine.Close();


                return("");
            }
            catch (Exception ex)
            {
                MessageBoxX.Show(ex.ToString(), "");
                return("");
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        ///     搜索出口和TUNTAP适配器
        /// </summary>
        private static bool SearchAdapters()
        {
            NetworkInterface adapter;

            Logging.Info("搜索适配器");
            if (Win32Native.GetBestRoute(BitConverter.ToUInt32(IPAddress.Parse("114.114.114.114").GetAddressBytes(), 0), 0, out var pRoute) == 0)
            {
                Global.Adapter.Index = pRoute.dwForwardIfIndex;
                adapter = NetworkInterface.GetAllNetworkInterfaces().First(_ => _.GetIPProperties().GetIPv4Properties().Index == Global.Adapter.Index);
                Global.Adapter.Address = adapter.GetIPProperties().UnicastAddresses.First(ip => ip.Address.AddressFamily == AddressFamily.InterNetwork).Address;
                Global.Adapter.Gateway = new IPAddress(pRoute.dwForwardNextHop);
                Logging.Info($"出口 IPv4 地址:{Global.Adapter.Address}");
                Logging.Info($"出口 网关 地址:{Global.Adapter.Gateway}");
                Logging.Info($"出口适配器:{adapter.Name} {adapter.Id} {adapter.Description}, index: {Global.Adapter.Index}");
            }
            else
            {
                Logging.Error("GetBestRoute 搜索失败(找不到出口适配器)");
                return(false);
            }

            // 搜索 TUN/TAP 适配器的索引
            Global.TUNTAP.ComponentID = TUNTAP.GetComponentID();
            if (string.IsNullOrEmpty(Global.TUNTAP.ComponentID))
            {
                Logging.Error("未找到可用 TAP 适配器");
                if (MessageBoxX.Show(i18N.Translate("TUN/TAP driver is not detected. Is it installed now?"), confirm: true) == DialogResult.OK)
                {
                    Configuration.addtap();
                    // 给点时间,不然立马安装完毕就查找适配器可能会导致找不到适配器ID
                    Thread.Sleep(1000);
                    Global.TUNTAP.ComponentID = TUNTAP.GetComponentID();
                }
                else
                {
                    return(false);
                }
            }

            adapter = NetworkInterface.GetAllNetworkInterfaces().First(_ => _.Id == Global.TUNTAP.ComponentID);
            Global.TUNTAP.Adapter = adapter;
            Global.TUNTAP.Index   = adapter.GetIPProperties().GetIPv4Properties().Index;
            Logging.Info($"TAP 适配器:{adapter.Name} {adapter.Id} {adapter.Description}, index: {Global.TUNTAP.Index}");
            return(true);
        }