コード例 #1
0
        private void AddServerQRCode(object parameter)
        {
            string ssBase64 = parameter as string;

            if (string.IsNullOrWhiteSpace(ssBase64))
            {
                ZXing.Result result = QRCode.DecodeScreen();
                if (result == null || string.IsNullOrWhiteSpace(result.Text))
                {
                    InterfaceCtrl.ShowHomeNotify(sr_server_not_found);
                    InterfaceCtrl.NotifyIcon.ShowMessage(sr_server_not_found);
                    return;
                }

                ssBase64 = result.Text;
            }

            if (V2RayVMess.FromVMessBase64(ssBase64) is V2RayVMess server)
            {
                AddServer(server, out int added, out int updated);

                string notify;
                if (SettingManager.Configuration.IsReplaceOldServer)
                {
                    notify = added > 0 ? $"{added} {sr_server_x_added}" : $"{updated} {sr_server_x_updated}";
                }
                else
                {
                    notify = added > 0 ? $"{added} {sr_server_x_added}" : sr_server_already_exist;
                }

                if (Application.Current.MainWindow.IsActive)
                {
                    InterfaceCtrl.ShowHomeNotify(notify);
                }
                else
                {
                    InterfaceCtrl.NotifyIcon.ShowMessage(notify);
                }
            }
            else
            {
                if (Application.Current.MainWindow.IsActive)
                {
                    InterfaceCtrl.ShowHomeNotify(sr_server_not_found);
                }
                else
                {
                    InterfaceCtrl.NotifyIcon.ShowMessage(sr_server_not_found);
                }
            }
        }