Exemple #1
0
        private void UndoBtn_OnClick(object sender, RoutedEventArgs e)
        {
            if (_currentId == -1)
            {
                return;
            }
            if (QModernMessageBox.Show("将还原上一次保存的更改\n继续?", "Undo", QModernMessageBox.QModernMessageBoxButtons.YesNo, ModernMessageboxIcons.Info) !=
                ModernMessageboxResult.Button1)
            {
                return;
            }
            _saveFlag = false;
            var currentInfo = _applistData[_currentId];

            currentInfo.Undo();
            foreach (var item in _applistData)
            {
                if (item.TargetPath == currentInfo.TargetPath)
                {
                    //update
                    Helper.UpdateFile(item.FullPath);
                }
            }

            Load();
        }
Exemple #2
0
        public static async Task <T> Post <T>(object controller, object method, T objectToPost)
        {
            try
            {
                var content = new StringContent(JsonHelper.Serialize(objectToPost), Encoding.UTF8,
                                                "application/json");

                var responseMessage =
                    await _client.PostAsync(controller + $"/{method}", content);

                if (responseMessage.IsSuccessStatusCode)
                {
                    var json = await responseMessage.Content.ReadAsStringAsync();

                    if (!string.IsNullOrEmpty(json))
                    {
                        return(JsonHelper.Deserialize <T>(json));
                    }
                }
                else
                {
                    var json = await responseMessage.Content.ReadAsStringAsync();

                    BadRequestMessage badRequest = JsonHelper.Deserialize <BadRequestMessage>(json);
                    QModernMessageBox.Show(badRequest.Message, "Internal Server Error",
                                           QModernMessageBox.QModernMessageBoxButtons.Ok);
                }

                return(default(T));
            }
            catch (Exception ex)
            {
                throw new InternalServerError(ex);
            }
        }
Exemple #3
0
 /// <summary>
 /// 显示消息框
 /// </summary>
 /// <param name="ParentWindow">父窗体</param>
 /// <param name="Message">消息内容</param>
 /// <param name="Title">标题</param>
 /// <param name="Btns">按钮类型</param>
 /// <param name="Icon">图标类型</param>
 /// <param name="PlaySound">播放声音</param>
 /// <returns></returns>
 public static ModernMessageboxResult ShowMessageBox(
     Window ParentWindow,
     string Message,
     string Title,
     QModernMessageBoxButtons Btns = QModernMessageBoxButtons.Ok,
     ModernMessageboxIcons Icon    = ModernMessageboxIcons.None,
     bool PlaySound = true)
 => QModernMessageBox.Show(ParentWindow, Message, Title, Btns, Icon, PlaySound);
        private void deleteselected_Click(object sender, RoutedEventArgs e)
        {
            string name = Passwords.SelectedItem.ToString() + ".apwm";

            File.Delete(Path.Combine(PathFinding.PASSWORDFOLDER, name));
            cleatlist();
            listadd();
            QModernMessageBox.Show($"Success", "Delete Finish!", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
        }
Exemple #5
0
        public static void Decrypter(string inputFile, string outputFile)
        {
            byte[]     passwordBytes = System.Text.Encoding.UTF8.GetBytes(Algorythmen.Auth_Class_System.password_crypt);
            byte[]     salt          = new byte[saltss];
            FileStream cryptfiles    = new FileStream(inputFile, FileMode.Open);

            cryptfiles.Read(salt, 0, salt.Length);
            RijndaelManaged ert = new RijndaelManaged();

            ert.KeySize   = 256;
            ert.BlockSize = 128;
            var key = new Rfc2898DeriveBytes(passwordBytes, salt, 50000);

            ert.Key     = key.GetBytes(ert.KeySize / 8);
            ert.IV      = key.GetBytes(ert.BlockSize / 8);
            ert.Padding = PaddingMode.PKCS7;
            ert.Mode    = CipherMode.CBC;

            CryptoStream cryptoStream = new CryptoStream(cryptfiles, ert.CreateDecryptor(), CryptoStreamMode.Read);

            FileStream fileStreamOutput = new FileStream(outputFile, FileMode.Create);

            int read;

            byte[] buffer = new byte[1048576];

            try
            {
                while ((read = cryptoStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    fileStreamOutput.Write(buffer, 0, read);
                }
            }
            catch (CryptographicException ex_CryptographicException)
            {
                QModernMessageBox.Show($"CryptographicException error:\n{ex_CryptographicException.Message}", "Error Appeard!", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
            }
            catch (Exception ex)
            {
                QModernMessageBox.Show($"Error:\n{ex.Message}", "Error Appeard!", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
            }

            try
            {
                cryptoStream.Close();
            }
            catch (Exception ex)
            {
                QModernMessageBox.Show($"Error by closing CryptoStream::\n{ex.Message}", "Error Appeard!", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
            }
            finally
            {
                fileStreamOutput.Close();
                cryptfiles.Close();
            }
        }
Exemple #6
0
 private void OpenConfig_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Process.Start("notepad.exe", PathFinding.CONFIGFILE);
     }
     catch (Exception x)
     {
         QModernMessageBox.Show($"Error: \n{x}", "Application Error", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
     }
 }
Exemple #7
0
 private void Create_Click(object sender, RoutedEventArgs e)
 {
     if (filenameout.Text != "")
     {
         generate();
     }
     if (filenameout.Text == "")
     {
         QModernMessageBox.Show($"Bitte wähle einen Namen für die Datei", "Application Error", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
     }
 }
Exemple #8
0
 private void Entschluesseln_Click(object sender, RoutedEventArgs e)
 {
     if (entsch_path != "")
     {
         Decrypter(entsch_path, entsch_path + ".CHANGEMEBACK");
         QModernMessageBox.Show($"Die Datei wurde entschlüsselt", "Application Info", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
         entschlusselpath.Content = "Nichts ausgewählt";
     }
     if (entsch_path == "")
     {
         QModernMessageBox.Show($"Keine Datei ausgewählt", "Application Info", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
     }
 }
        public static int checkvaleu()
        {
            int bcc   = 0;
            var MyIni = new IniFile(PathFinding.CONFIGFILE);

            try
            {
                bcc = Int16.Parse(MyIni.Read("Lang", "System"));
            } catch (Exception x)
            {
                QModernMessageBox.Show($"Error: \n{x}", "Application Error", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
                bcc = 0;
            }
            return(bcc);
        }
Exemple #10
0
        public static void CheckerBoolean(bool defau, bool tr1, bool tr2, bool end)
        {
            var    MyIni = new IniFile(PathFinding.CONFIGFILE);
            Thread a     = new Thread(_default_);
            Thread b     = new Thread(_tr2s_);
            Thread c     = new Thread(_tr1_);

            if (defau)
            {
                a.Start();
            }
            initz = 1;
            if (tr1)
            {
                b.Start();
            }
            initz = 2;
            if (tr2)
            {
                c.Start();
            }
            initz = 3;
            if (end)
            {
                switch (initz)
                {
                case 1:

                    a.Abort();
                    break;

                case 2:

                    b.Abort();
                    break;

                case 3:

                    c.Abort();
                    break;

                default:
                    QModernMessageBox.Show($"Error End Audio", "Application Error", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
                    break;
                }
            }
        }
Exemple #11
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var msg = new ModernMessageBox("The quick brown fox jumps over the lazy dog.\n", "hello world", ModernMessageboxIcons.Info, "CSharp", "Java",
                                           "Python")
            {
                Button1Key         = Key.D1,
                Button2Key         = Key.D2,
                Button3Key         = Key.D3,
                CheckboxText       = "Don't show this again",
                CheckboxVisibility = Visibility.Visible,
                TextBoxText        = "some staff",
                TextBoxVisibility  = Visibility.Visible,
            };

            msg.ShowDialog();
            QModernMessageBox.None(msg.TextBoxText, "TextBoxText");
            QModernMessageBox.None(msg.CheckboxChecked.ToString(), "CheckboxChecked");
        }
Exemple #12
0
 private void generate()
 {
     Crypto2(path_main);
     if (path_main + Algorythmen.PathFinding.filename_message == path_out + Algorythmen.PathFinding.filename_message)
     {
         File.Move(path_main + Algorythmen.PathFinding.filename_message, path_out + filenameout.Text + Algorythmen.PathFinding.filename_message);
     }
     else
     {
         File.Move(path_main + Algorythmen.PathFinding.filename_message, path_out + filenameout.Text + Algorythmen.PathFinding.filename_message);
         File.Delete(path_main + Algorythmen.PathFinding.filename_message);
     }
     pahtfile.Content   = "Nichts ausgewählt";
     path_main          = "";
     outputpath.Content = "Nichts ausgewählt";
     path_out           = "";
     QModernMessageBox.Show($"Die Datei wurde erstellt", "Application Info", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
 }
Exemple #13
0
        private void DisableAudio()
        {
            var  MyIni = new IniFile(PathFinding.CONFIGFILE);
            bool b     = Boolean.Parse(MyIni.Read("Music", "Audio").ToString());

            if (b)
            {
                try
                {
                    MyIni.DeleteKey("Music", "Audio");
                    MyIni.Write("Music", "false", "Audio");
                    BackgroundSysteme.MusicSysteme.play(false);
                }
                catch (Exception x)
                {
                    QModernMessageBox.Show($"Error: \n{x}", "Application Error", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
                }
            }
            return;
        }
Exemple #14
0
        private bool SaveCheck()
        {
            if (!_saveFlag || _currentId == -1)
            {
                return(true);
            }
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (QModernMessageBox.Show("更改尚未保存,是否保存?", "提示", QModernMessageBox.QModernMessageBoxButtons.YesNoCancel,
                                           ModernMessageboxIcons.Info))
            {
            case ModernMessageboxResult.Button1:
                return(Save());

            case ModernMessageboxResult.Button2:
                _saveFlag = false;
                return(true);

            default:
                return(false);
            }
        }
        private void Login_Button_Click(object sender, RoutedEventArgs e)
        {
            bool checker = false;

            if (PasswordCrypter.Password.Length < 15)
            {
                QModernMessageBox.Show("Your password is not long enough", "Application Error", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
                return;
            }
            if (PasswordCrypter.Password.Length > 15)
            {
                Algorythmen.Auth_Class_System.password_crypt = sugar + PasswordCrypter.Password + pepper;
            }
            if (Secure_key.Password != "")
            {
                Algorythmen.Auth_Class_System.salt_key = Secure_key.Password;
            }
            if (Secure_key.Password == "" && PasswordCrypter.Password == "")
            {
                checker = false;

                QModernMessageBox.Show("Please fill in all fields!", "Application Error", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
                return;
            }
            else
            {
                checker = true;
            }


            if (checker)
            {
                SChecked(Algorythmen.Auth_Class_System.password_crypt, Algorythmen.Auth_Class_System.salt_key.ToString());
                UI_Management.ControlScreen data = new UI_Management.ControlScreen();
                data.Show();
                this.Hide();
            }
        }
Exemple #16
0
        private void Music_OnOff_Checked(object sender, RoutedEventArgs e)
        {
            var  MyIni = new IniFile(PathFinding.CONFIGFILE);
            bool check = Boolean.Parse(Music_OnOff.IsChecked.ToString().ToLower());

            if (check == false)
            {
                try
                {
                    MyIni.DeleteKey("Music", "Audio");
                    MyIni.Write("Music", "false", "Audio");
                    BackgroundSysteme.MusicSysteme.play(false);
                }
                catch (Exception x)
                {
                    QModernMessageBox.Show($"Error: \n{x}", "Application Error", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
                }
                return;
            }
            if (check)
            {
                bool b = Boolean.Parse(MyIni.Read("Music", "Audio").ToString());
                if (!b)
                {
                    try
                    {
                        MyIni.DeleteKey("Music", "Audio");
                        MyIni.Write("Music", "true", "Audio");
                        BackgroundSysteme.MusicSysteme.play(true);
                    }
                    catch (Exception x)
                    {
                        QModernMessageBox.Show($"Error: \n{x}", "Application Error", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
                    }
                }
                return;
            }
        }
Exemple #17
0
 public static void ShowWarningMessage(Window parentWindow, string Message) => QModernMessageBox.Warning(parentWindow, Message, "警告");
Exemple #18
0
 private void info(string Message)
 {
     QModernMessageBox.Show($"Info:\n{Message}", "Application Information", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
 }
 public void CheckData(string data)
 {
     QModernMessageBox.Show($"{data}", "Error Appeard!", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
 }
Exemple #20
0
        protected override void OnStartup(StartupEventArgs e)
        {
            var splashScreen = new SplashScreenWindow();

            splashScreen.Show();
            string macAndUser = null;
            List <StoredUserEntity> storedUsers       = new List <StoredUserEntity>();
            VersionController       versionController = new VersionController();

            base.OnStartup(e);
            try
            {
                Directory.CreateDirectory(path);
                InstanceAlreadyRunning(e);
                CompareVersions(currentVersion, versionController);
                string currentExePath = Directory.GetCurrentDirectory() + "\\" + Process.GetCurrentProcess().ProcessName + ".exe";
                string exePath        = SecretChatPath + Process.GetCurrentProcess().ProcessName + ".exe";
                //if (Regex.IsMatch(currentExePath.Replace(@"\", ""), exePath.Replace(@"\", ""), RegexOptions.IgnoreCase))
                //{
                //    //Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu ) + "\\Programs");
                //    //File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs\\SecretChat\\test.txt", "bruh");
                DeleteOldVersions();
                CreateStartMenuShortcut();
                //}
                //else
                //{
                //    //if (!currentExePath.Contains("System32"))
                //    //{
                //    //    try
                //    //    {
                //    //        if (System.IO.File.Exists(SecretChatPath + Process.GetCurrentProcess().ProcessName + ".exe"))
                //    //        {
                //    //            System.IO.File.Delete(SecretChatPath + Process.GetCurrentProcess().ProcessName + ".exe");
                //    //        }
                //    //        System.IO.File.Copy(Directory.GetCurrentDirectory() + "\\" + Process.GetCurrentProcess().ProcessName + ".exe", SecretChatPath + Process.GetCurrentProcess().ProcessName + currentVersion + ".exe");
                //    //    }
                //    //    catch
                //    //    {

                //    //    }
                //    //}
                //    CreateStartMenuShortcut(currentVersion);
                //}
                if (System.IO.File.Exists(path + "\\code.txt"))
                {
                    code = System.IO.File.ReadAllText(path + "\\code.txt");
                }
                else
                {
                    code = "000000";
                }
                macAndUser  = GetMac() + Environment.UserName;
                storedUsers = usersController.GetStoredUsers(macAndUser, code);
                if (storedUsers == null)
                {
                    userNameInput = new NameWindow(null);
                    splashScreen.Close();
                    userNameInput.ShowDialog();
                }
                //IsUserStored(storedUsers, ref macStored, macAndUser);

                //userNameInput.Close();
                RemoveProfilePictures(path2, storedUsers);
                CreateFiles(path, macAndUser, path2);
                SaveFilterWords(path);
                Task.Factory.StartNew(() =>
                {
                    //System.Threading.Thread.Sleep(time); //eigentlich 2700
                    this.Dispatcher.Invoke(() =>
                    {
                        var mainWindow = new MainWindow("true", currentVersion);
                        //this.MainWindow = mainWindow;
                    });
                });
            }
            catch (Exception ex)
            {
                if (IsConnectedToInternet() == true)
                {
                    var    st        = new StackTrace(ex, true);
                    var    frame     = st.GetFrame(0);
                    var    line      = frame.GetFileLineNumber();
                    string ErrorInfo = "Zeitüberschreitung, möglicherweise sind unsere Server sind momentan leider nicht verfügbar. Fehler:  " + ex.Message + "  Line: " + line + " in " + frame + "              Der Fehler wurde in Deine Zwischenablage gespeichert.";
                    ModernWpf.MessageBox.Show(ErrorInfo);
                    Environment.Exit(0);
                }
                else
                {
                    splashScreen.Hide();
                    QModernMessageBox.Show("Du bist nicht mit dem Internet verbunden! Bitte versuche es später noch einmal. Fehler: " + ex.Message, "Fehler", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
                    Environment.Exit(0);
                }
            }
        }
Exemple #21
0
 /// <summary>
 /// 警告消息框
 /// </summary>
 /// <param name="Message"></param>
 public static void ShowWarningMessage(string Message) => QModernMessageBox.Warning(Message, "警告");
Exemple #22
0
 public static void ShowErrorMessage(Window parentWindow, Exception Ex) => QModernMessageBox.Error(parentWindow, Ex.Message, "错误");
Exemple #23
0
 private void ButtonBase_OnClick_1(object sender, RoutedEventArgs e)
 {
     QModernMessageBox.Show("The quick brown fox jumps over the lazy dog.", "hello world", QModernMessageBox.QModernMessageBoxButtons.YesNoCancel,
                            ModernMessageboxIcons.Error);
 }
Exemple #24
0
 /// <summary>
 /// 错误消息框
 /// </summary>
 /// <param name="Ex"></param>
 public static void ShowErrorMessage(Exception Ex) => QModernMessageBox.Error(Ex.Message, "错误");
Exemple #25
0
        private void ButtonBase_OnClick_7(object sender, RoutedEventArgs e)
        {
            if (_scaleMode && QModernMessageBox.Show("警告,本操作不可逆。\n继续将清除开发者定义的可缩放图标,除非重新安装该程序,否则该图标可能不能恢复。\n继续操作?", "警告",
                                                     QModernMessageBox.QModernMessageBoxButtons.YesNo, ModernMessageboxIcons.Warning) != ModernMessageboxResult.Button1)
            {
                return;
            }


            if (!(_openFile.ShowDialog() ?? false))
            {
                return;
            }
            try {
                var fs  = File.Open(_openFile.FileName, FileMode.Open, FileAccess.Read);
                var img = new Bitmap(fs);
                var win = new ImageSnipWindow(img, new Size(150, 150));
                win.ShowDialog();
                Bitmap tmpBmp;
                switch (win.Result)
                {
                case ImageSnipWindow.SnapWindowResult.Ok:
                    tmpBmp = win.Dst;
                    break;

                case ImageSnipWindow.SnapWindowResult.Cancel:
                    img.Dispose();
                    fs.Close();
                    return;

                case ImageSnipWindow.SnapWindowResult.Ignore:
                    if (img.Size.Width >= 150 && img.Size.Height >= 150)
                    {
                        //尽量使用原图
                        _newLogoLoc = _openFile.FileName;
                        _logo       = img.ToBitmapSource();
                        goto done;
                    }

                    tmpBmp = img;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (tmpBmp.Size.Width < 150 || tmpBmp.Size.Height < 150)
                {
                    if (tmpBmp.Size.Width < 150 && tmpBmp.Size.Height < 150)
                    {
                        var newBmp = new Bitmap(150, 150);
                        var gps    = Graphics.FromImage(newBmp);
                        gps.CompositingQuality = CompositingQuality.HighQuality;
                        gps.Clear(System.Drawing.Color.Transparent);
                        var x = (150 - tmpBmp.Size.Width) / 2;
                        var y = (150 - tmpBmp.Size.Height) / 2;
                        gps.DrawImage(tmpBmp, x, y, tmpBmp.Size.Width, tmpBmp.Size.Height);
                        tmpBmp.Dispose();
                        tmpBmp = newBmp;
                    }
                    else
                    {
                        tmpBmp = new Bitmap(tmpBmp, 150, 150);
                    }
                }

                _logo       = tmpBmp.ToBitmapSource();
                _newLogoLoc = Path.GetTempFileName() + ".png";
                tmpBmp.Save(_newLogoLoc, ImageFormat.Png);
                tmpBmp.Dispose();
done:
                img.Dispose();
                fs.Close();
            }
            catch (IOException ex) {
                QModernMessageBox.Error($"图片载入失败\n未知错误,无法读取此文件\n详细信息:{ex.Message}", "错误");
                return;
            }

            _saveFlag = true;
            UpdateRender();
        }
        private void SaveNewPass_Click(object sender, RoutedEventArgs e)
        {
            bool b      = false;
            bool result = Regex.IsMatch(FileName.Text, @".*[^\u0000-\u007F].*");

            if (FileName.Text.Length > 13)
            {
                CheckData("The name of the password is too long");
                password_save.Clear();
                email_save.Clear();
                return;
            }
            if (result == true)
            {
                CheckData("Special signs are not allowed");
                password_save.Clear();
                email_save.Clear();
                return;
            }
            if (email_save.Text != "" && password_save.Password != "" && FileName.Text != "")
            {
                string email         = email_save.Text;
                string passwort_save = password_save.Password;


                string filename = FileName.Text;
                foreach (string file in files())
                {
                    if (file == $"{filename}.apwm")
                    {
                        b = true;
                    }
                }

                if (b)
                {
                    QModernMessageBox.Show($"Error:\nPassword {filename} already exist", "Error Appeard!", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
                    return;
                }

                if (!b)
                {
                    var MyIni = new IniFile(PathFinding.PASSWORDFOLDER + $"{filename}.ini");
                    MyIni.Write("USERNAMEEMAIL", email, "DATA");
                    MyIni.Write("PASSWORDPASS", passwort_save, "DATA");
                    try
                    {
                        FileObfusicator.Crypto(PathFinding.PASSWORDFOLDER + $"{filename}.ini");
                    } catch (Exception x)
                    {
                        File.Delete(PathFinding.PASSWORDFOLDER + $"{filename}.ini");
                        CheckData(x.ToString());
                        return;
                    }
                    File.Move(PathFinding.PASSWORDFOLDER + $"{filename}.ini.apwm", PathFinding.PASSWORDFOLDER + $"{filename}.apwm");
                    File.Delete(PathFinding.PASSWORDFOLDER + $"{filename}.ini.apwm");
                    QModernMessageBox.Show($"password stored!", "Sucess!", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Info);
                    password_save.Clear();
                    email_save.Clear();
                    email         = "";
                    passwort_save = "";
                    cleatlist();
                    listadd();
                    return;
                }
            }
            QModernMessageBox.Show($"Nothing cant used as Password", "Error Appeard!", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
        }
Exemple #27
0
        private void Load()
        {
            _sysChangeing = true;

            _newLogoLoc = null; //防止意外的保存
            _logo       = null;
            _scaleMode  = false;

            var currentInfo = _applistData[_currentId];

            if (currentInfo.XmlFile == null)
            {
                try {
                    currentInfo.LoadXmlInfo();
                }
                catch (UnauthorizedAccessException) {
                    QModernMessageBox.Show("无法读取该文件设定.\n权限不足。", "错误", QModernMessageBox.QModernMessageBoxButtons.Ok,
                                           ModernMessageboxIcons.Error);
                    _sysChangeing         = false;
                    appList.SelectedIndex = -1;
                    return;
                }
                catch (IOException ex) {
                    QModernMessageBox.Show("无法读取该文件设定.\n发生了IO异常,请稍后再试\n更多信息:" + ex.Message, "错误",
                                           QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Error);
                    _sysChangeing         = false;
                    appList.SelectedIndex = -1;
                    return;
                }
                catch (Exception e) {
                    Debug.WriteLine("-----EXCEPTION-----");
                    Debug.WriteLine(e);
                    Debug.WriteLine("--------END--------");
                    // ReSharper disable once HeuristicUnreachableCode
                    QModernMessageBox.Show("读取配置文件时发生错误\n已重置到初始值", "错误", QModernMessageBox.QModernMessageBoxButtons.Ok,
                                           ModernMessageboxIcons.Warning);
                    File.Delete(currentInfo.XmlFileLocation);
                    currentInfo.XmlFile = null;
                    Load();
                    return;
                }
            }

            if (currentInfo.XmlFile == null)
            {
                modeCheck.IsChecked = false;

                //set everything to empty

                _currentColor             = Colors.Black;
                _currentColorString       = "black";
                defineIconCheck.IsChecked = false;
                txtWhiteColor.IsChecked   = true;
                colorSelector_1.IsChecked = true;
                grdDevDefIco.Visibility   = Visibility.Collapsed;
            }
            else
            {
                //modeSelctor.SelectedIndex = 1;
                modeCheck.IsChecked         = true;
                largeAppNameCheck.IsChecked = currentInfo.XmlFile.ShowTitleOnLargeIcon;
                try {
                    //Color
                    switch (currentInfo.XmlFile.ColorStr)
                    {
                    case "black":
                        colorSelector_1.IsChecked = true;
                        break;

                    case "silver":
                        colorSelector_2.IsChecked = true;
                        break;

                    case "gray":
                        colorSelector_3.IsChecked = true;
                        break;

                    case "white":
                        colorSelector_4.IsChecked = true;
                        break;

                    case "maroon":
                        colorSelector_5.IsChecked = true;
                        break;

                    case "red":
                        colorSelector_6.IsChecked = true;
                        break;

                    case "purple":
                        colorSelector_7.IsChecked = true;
                        break;

                    case "fuchsia":
                        colorSelector_8.IsChecked = true;
                        break;

                    case "green":
                        colorSelector_9.IsChecked = true;
                        break;

                    case "lime":
                        colorSelector_10.IsChecked = true;
                        break;

                    case "olive":
                        colorSelector_11.IsChecked = true;
                        break;

                    case "yellow":
                        colorSelector_12.IsChecked = true;
                        break;

                    case "navy":
                        colorSelector_13.IsChecked = true;
                        break;

                    case "blue":
                        colorSelector_14.IsChecked = true;
                        break;

                    case "teal":
                        colorSelector_15.IsChecked = true;
                        break;

                    case "aqua":
                        colorSelector_16.IsChecked = true;
                        break;

                    default:
                        try {
                            _currentColor              = Helper.GetColorFromRgbString(currentInfo.XmlFile.ColorStr);
                            _currentColorString        = currentInfo.XmlFile.ColorStr;
                            colorSelector_17.IsChecked = true;
                            defineColorText.Text       = currentInfo.XmlFile.ColorStr;
                        }
                        catch (FormatException) {
                            currentInfo.XmlFile.ColorStr = "black";
                            _currentColor             = Colors.Black;
                            colorSelector_1.IsChecked = true;
                        }

                        break;
                    }

                    //Logo
                    if (string.IsNullOrEmpty(currentInfo.XmlFile.SmallLogoLoc) &&
                        !string.IsNullOrEmpty(currentInfo.XmlFile.LargeLogoLoc))
                    {
                        //replace smallLogo with largeLogo
                        currentInfo.XmlFile.SmallLogoLoc = currentInfo.XmlFile.LargeLogoLoc;
                    }

                    if (!string.IsNullOrEmpty(currentInfo.XmlFile.SmallLogoLoc))
                    {
                        void CheckLargeLoc()
                        {
                            if (string.IsNullOrEmpty(currentInfo.XmlFile.LargeLogoLoc))
                            {
                                currentInfo.XmlFile.LargeLogoLoc = currentInfo.XmlFile.SmallLogoLoc;
                            }
                        }

                        if (File.Exists(currentInfo.XmlFile.GetFullPath(currentInfo.XmlFile.SmallLogoLoc)))
                        {
                            //直接获取
                            Debug.WriteLine(
                                $"Load small icon successfully with file location{currentInfo.XmlFile.SmallLogoLoc}");
                            _logo = new BitmapImage(
                                new Uri(currentInfo.XmlFile.GetFullPath(currentInfo.XmlFile
                                                                        .SmallLogoLoc))); //Load the logo
                            //_scaleMode = false;
                            defineIconCheck.IsChecked = true;
                            grdDevDefIco.Visibility   = Visibility.Collapsed;
                            CheckLargeLoc();
                            goto __hasLogo;
                        }
                        else if (Directory.Exists(
                                     Path.GetDirectoryName(
                                         currentInfo.XmlFile.GetFullPath(currentInfo.XmlFile.SmallLogoLoc))) &&
                                 // ReSharper disable once AssignNullToNotNullAttribute
                                 File.Exists(Path.Combine(Path.GetDirectoryName(currentInfo.TargetPath),
                                                          "Resources.pri")))
                        {
                            //scale模式
                            _scaleMode = true;
                            defineIconCheck.IsChecked = true;
                            //btnChangeLogo.Visibility = Visibility.Collapsed;
                            grdDevDefIco.Visibility = Visibility.Visible;
                            CheckLargeLoc();
                            goto __hasLogo;
                        }
                        else
                        {
                            //异常,清除
                            currentInfo.XmlFile.SmallLogoLoc = currentInfo.XmlFile.LargeLogoLoc = null;
                        }
                    }

                    //_scaleMode = false;
                    defineIconCheck.IsChecked = false;
                    grdDevDefIco.Visibility   = Visibility.Collapsed;
__hasLogo:
                    //txtColorSelector.SelectedIndex = (int)currentInfo.XmlFile.TxtForeground;
                    if (currentInfo.XmlFile.TxtForeground == StartmenuXmlFile.TextCol.light)
                    {
                        txtWhiteColor.IsChecked = true;
                    }
                    else
                    {
                        txtBlackColor.IsChecked = true;
                    }
                }
#if DEBUG
                catch (Exception e) {
                    Debug.WriteLine("-----EXCEPTION-----");
                    Debug.WriteLine(e);
                    Debug.WriteLine("--------END--------");
#else
                catch {
#endif
                    // ReSharper disable once HeuristicUnreachableCode
                    QModernMessageBox.Show("读取配置文件时发生错误\n已重置到初始值", "错误", QModernMessageBox.QModernMessageBoxButtons.Ok,
                                           ModernMessageboxIcons.Warning);
                    File.Delete(currentInfo.XmlFileLocation);
                    currentInfo.XmlFile = null;
                    Load();
                    return;
                }
            }

            undoBtn.IsEnabled = currentInfo.BakFileExist;
            UpdateRender();
            _sysChangeing = false;
        }
Exemple #28
0
 public static void ShowInformationMessage(Window parentWindow, string Message, string Title) => QModernMessageBox.Info(Message, Title);
Exemple #29
0
        private bool Save()
        {
#if DEBUG
            var stop = new Stopwatch();
            stop.Start();
#endif
            if (_currentId == -1)
            {
                return(true);
            }
            var currentInfo = _applistData[_currentId];
            //todo save
            if (_saveFlag)
            {
                if (!(modeCheck.IsChecked ?? false))
                {
                    if (currentInfo.XmlFile != null)
                    {
                        if (QModernMessageBox.Show("将删除所有自定义效果文件\n继续?", "⚠警告",
                                                   QModernMessageBox.QModernMessageBoxButtons.YesNo, ModernMessageboxIcons.Warning) !=
                            ModernMessageboxResult.Button1)
                        {
                            return(false);
                        }
                        currentInfo.XmlFile = null;
                        File.Delete(currentInfo.XmlFileLocation);
                        //                        if (currentInfo.BakFileExist) {
                        //                            File.Delete(currentInfo.BakFileLocation);
                        //                        }
                        //                        if (Directory.Exists(currentInfo.LogoDirLocation)) {
                        //                            Directory.Delete(currentInfo.LogoDirLocation, true);
                        //                        }

                        _logo = null;
                    }
                }
                else
                {
                    if (currentInfo.XmlFile == null)
                    {
                        currentInfo.XmlFile = new StartmenuXmlFile(currentInfo.XmlFileLocation);
                    }

                    currentInfo.XmlFile.ColorStr      = _currentColorString;
                    currentInfo.XmlFile.TxtForeground = (txtWhiteColor.IsChecked ?? false)
                        ? StartmenuXmlFile.TextCol.light
                        : StartmenuXmlFile.TextCol.dark;
                    currentInfo.XmlFile.ShowTitleOnLargeIcon = largeAppNameCheck.IsChecked ?? false;
                    //保存图片
                    var sha1 = SHA1.Create();
                    // ReSharper disable once AssignNullToNotNullAttribute
                    var pathName = currentInfo.LogoDirLocation;
                    if (!Directory.Exists(pathName))
                    {
                        Directory.CreateDirectory(pathName);
                    }

                    //文件名:[DIR]\__StartmenuIcons__\[SHA1].png
                    if (defineIconCheck.IsChecked ?? false)
                    {
                        if (!string.IsNullOrEmpty(_newLogoLoc))
                        {
                            //计算SHA1
                            var fs   = File.Open(_newLogoLoc, FileMode.Open, FileAccess.Read);
                            var hash = BitConverter.ToString(sha1.ComputeHash(fs)).Replace("-", string.Empty).ToLower();
                            fs.Close();
                            var fileName           = Path.Combine(pathName, hash) + Path.GetExtension(_newLogoLoc);
                            var fileNameWithoutDir = Path.Combine(Properties.Resources.IconDirName, hash) +
                                                     Path.GetExtension(_newLogoLoc).ToLower();
                            if (!File.Exists(fileName)) //拷贝图像到目录
                            {
                                File.Copy(_newLogoLoc, fileName);
                            }
                            currentInfo.XmlFile.SmallLogoLoc = currentInfo.XmlFile.LargeLogoLoc = fileNameWithoutDir;
                            _newLogoLoc = null;
                        }
                        else if (string.IsNullOrEmpty(currentInfo.XmlFile.SmallLogoLoc))
                        {
                            QModernMessageBox.Info("需要指定作为图标的图片。", "提示");
                            return(false);
                        }
                    }
                    else
                    {
                        currentInfo.XmlFile.LargeLogoLoc = currentInfo.XmlFile.SmallLogoLoc = string.Empty;
                        if (_newLogoLoc == null)
                        {
                            _logo = null;
                        }
                    }

                    try {
                        currentInfo.Backup();
                        currentInfo.XmlFile.Save();
                        undoBtn.IsEnabled = currentInfo.BakFileExist;
                    }
                    catch (UnauthorizedAccessException) {
                        QModernMessageBox.Error("无法保存设定.\n权限不足.", "错误");
                        return(false);
                    }
                    catch (IOException ex) {
                        QModernMessageBox.Error("无法读取该文件设定.\n发生了IO异常,请稍后再试\n更多信息:" + ex.Message, "错误");
                        _sysChangeing         = false;
                        appList.SelectedIndex = -1;
                        return(false);
                    }
                }

                _saveFlag = false;
            }

            //Update file and let the explorer reload the link
            //需要检查是否有连带文件要update的
            //Helper.UpdateFile(currentInfo.FullPath);
            foreach (var item in _applistData)
            {
                if (item.TargetPath == currentInfo.TargetPath)
                {
                    //update
                    Helper.UpdateFile(item.FullPath);
                }
            }

#if DEBUG
            stop.Stop();
            Debug.WriteLine("save takes:" + stop.Elapsed + " ms");
#endif
            return(true);
        }
Exemple #30
0
        private void CompareVersions(string currentVersion, VersionController versionController)
        {
            string latestVer = "";

            try
            {
                var latestVersion = versionController.GetVersion();
                foreach (var v in latestVersion)
                {
                    latestVer = v.VersionNumber;
                    if (v.VersionNumber.Contains(currentVersion))
                    {
                        upToDate = true; //TRUE
                    }
                }
            }
            catch (Exception e)
            {
                if (IsConnectedToInternet() == false)
                {
                    QModernMessageBox.Show("Du bist nicht mit dem Internet verbunden! Bitte versuche es später noch einmal. Fehler: " + e.Message, "Fehler", QModernMessageBox.QModernMessageBoxButtons.Ok, ModernMessageboxIcons.Warning);
                    Environment.Exit(0);
                }
                else
                {
                    var    st        = new StackTrace(e, true);
                    var    frame     = st.GetFrame(0);
                    var    line      = frame.GetFileLineNumber();
                    string ErrorInfo = "Unbekannter Fehler, sende ihn bitte an Armin um ihn zu beheben. Fehler:  " + e.Message + "  Line: " + line + " in " + frame + "              Der Fehler wurde in Deine Zwischenablage gespeichert.";
                    Clipboard.SetText(ErrorInfo);
                    ModernWpf.MessageBox.Show("Ein unbekannter Fehler ist aufgetreten, möglicherweise haben wir Teschnische Schwierigkeiten, Du wirst nun zu dem Download weitergeleitet (wenn die Versionsnummern gleich sind dann warte bis zum nächsten Update), da die neuste Version dieses Problem höchstwahrscheinlich beheben wird. Damit dies nicht wieder vorkommt sende den Fehler (er wurde in Deine Zwischenablage gespeichert) an folgende Email-Adresse: [email protected]. Secret Chat® wird nun automatisch beendet. Fehler:  " + e.Message + ". Der Fehler wurde in Deine Zwischenablage gespeichert.");
                    Process.Start("https://github.com/SagMeinenNamen/SecretChat/raw/main/SecretChat.exe");
                    Process.Start("https://github.com/SagMeinenNamen/SecretChat/blob/main/SecretChat.exe");
                    Environment.Exit(0);
                }
            }
            if (upToDate == false)
            {
                if (!File.Exists(SecretChatPath + latestVer + "\\SecretChat.exe"))
                {
                    UpdateInfoEventArgs args = new UpdateInfoEventArgs
                    {
                        DownloadURL    = "https://github.com/SagMeinenNamen/SecretChat/raw/main/SecretChat.exe",
                        CurrentVersion = latestVer
                    };
                    Version version = new Version(currentVersion);
                    args.InstalledVersion = version;
                    try
                    {
                        AutoUpdater.ShowSkipButton        = false;
                        AutoUpdater.RunUpdateAsAdmin      = false;
                        AutoUpdater.ShowRemindLaterButton = false;
                        AutoUpdater.DownloadPath          = SecretChatPath + latestVer;
                        AutoUpdater.AppTitle   = "Secret Chat";
                        AutoUpdater.Mandatory  = true;
                        AutoUpdater.UpdateMode = Mode.ForcedDownload;
                        AutoUpdater.DownloadUpdate(args);
                        //if (System.IO.File.Exists(SecretChatPath + "SecretChat.exe"))
                        //{
                        //    try
                        //    {
                        //        System.IO.File.Delete(SecretChatPath + "SecretChat.exe");
                        //    }
                        //    catch
                        //    {

                        //    }
                        //}
                        //System.IO.File.Move(path3, SecretChatPath + "SecretChat" + latestVer + ".exe");
                        //var startInfo = SecretChatPath + "SecretChat" + latestVer + ".exe";
                        //Process.Start(startInfo, "restart");
                        Process.GetCurrentProcess().Kill();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Ein Fehler ist während der Installation aufgetreten: " + e.Message + Environment.NewLine + "Du wirst nun zum manuellen download weitergeleitet.");
                        //ModernWpf.MessageBox.Show("Du brauchst die neuste Version von Secret Chat. Du wirst nun automatisch zum download weitergeleitet. Installiere sie und führe sie aus um Secret Chat wie gewohnt weiter zu verwenden. In Updates sind meistens Fehlerkorrekturen, neue Funktionen oder neue Designs verfügbar!");
                        Process.Start("https://github.com/SagMeinenNamen/SecretChat/raw/main/SecretChat.exe");
                        Process.Start("https://github.com/SagMeinenNamen/SecretChat/blob/main/SecretChat.exe");
                        Thread.Sleep(1000);
                        Environment.Exit(0);
                    }
                }
                else
                {
                    var startInfo = SecretChatPath + latestVer + "\\SecretChat.exe";
                    Process.Start(startInfo, "restart");
                    Environment.Exit(0);
                }
            }
        }