Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
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);
                }
            }
        }