示例#1
0
 static void HandleException(Exception exc)
 {
     if (CstApp.CanHandleException) // when GUI for log is ready
     {
         CstApp.HandleException(exc);
     }
     else
     {
         var excString = exc.ToString();
         if (excString.Contains("netstandard,"))
         {
             MessageBox.Show("Error: .NET core is not installed. Please install latest .NET Framework.\r\n\r\n" + excString);
         }
         else
         {
             MessageBox.Show("Error: " + excString);
         }
     }
 }
示例#2
0
        void ICstAppUser.UninstallOnThisPC()
        {
            if (MessageBox.Show($"Do you really want to uninstall the software and all files in directory {CurrentProcessDirectory}?",
                                "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No) == MessageBoxResult.Yes)
            {
                try
                {
                    var rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                    rk.DeleteValue(AppNameInRegistry, false);
                }
                catch (Exception exc)
                {
                    CstApp.HandleException(exc);
                }

                // delete shortcut on desktop
                try
                {
                    if (File.Exists(DesktopShortcutFileName))
                    {
                        File.Delete(DesktopShortcutFileName);
                    }
                }
                catch (Exception exc)
                {
                    CstApp.HandleException(exc);
                }

                // delete folder in start menu
                try
                {
                    if (File.Exists(StartMenuShortcutFileName))
                    {
                        File.Delete(StartMenuShortcutFileName);
                    }
                }
                catch (Exception exc)
                {
                    CstApp.HandleException(exc);
                }

                // create bat
                // remove files from current folder
                var batFileName = Path.Combine(Path.GetTempPath(), "startrinity_cst_uninstall.bat");
                if (File.Exists(batFileName))
                {
                    File.Delete(batFileName);
                }

                var batScript = new StringBuilder();
                batScript.Append("echo off\r\n");
                batScript.Append("echo uninstalling software...\r\n");

                batScript.AppendFormat(":retry\r\n");
                batScript.AppendFormat("del /S /Q /F \"{0}\\*\"\r\n", CurrentProcessDirectory);
                batScript.AppendFormat("rmdir \"{0}\"\r\n", CurrentProcessDirectory);
                //    batScript.AppendFormat("echo result: %ERRORLEVEL%\r\n");
                batScript.AppendFormat("@if exist \"{0}\" (\r\n", CurrentProcessDirectory);
                batScript.AppendFormat("  echo failed to remove files in '{0}'. trying again..\r\n", CurrentProcessDirectory);
                batScript.Append("  timeout /t 2\r\n"); //   wait 2 sec, retry
                batScript.AppendFormat("  goto retry\r\n");
                batScript.Append(")\r\n");


                File.WriteAllText(batFileName, batScript.ToString());

                // run bat
                System.Diagnostics.Process.Start(batFileName);

                // close this process
                System.Windows.Application.Current.Shutdown();

                // RaisePropertyChanged(() => InstalledOnThisPcAndAutostartInTrayMode);
            }
        }
示例#3
0
        /// <summary>
        /// copies files from current folder to "app data" folder, if not
        /// </summary>
        void ICstAppUser.InstallOnThisPC()
        {
            try
            {
                string mainExeFileName;
                bool   closeThisProcess = false;
                // copy files to LocalPcInstallationFolder
                if (!RunningInstalledOnThisPC)
                {
                    var localPcInstallationFolder = LocalPcInstallationFolder;
                    if (!Directory.Exists(localPcInstallationFolder))
                    {
                        Directory.CreateDirectory(localPcInstallationFolder);
                    }
                    var currentProcessDirectory = CurrentProcessDirectory;
                    foreach (var dllFileName in Directory.GetFiles(currentProcessDirectory, "*.*")
                             .Select(x => x.ToLower())
                             .Where(s => s.EndsWith(".config") || s.EndsWith(".dll") || s.EndsWith(".exe") || s.EndsWith(".json")))
                    {
                        File.Copy(dllFileName, Path.Combine(localPcInstallationFolder, Path.GetFileName(dllFileName)), true);
                    }

                    mainExeFileName = Path.Combine(localPcInstallationFolder, Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
                    File.Copy(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, mainExeFileName, true);

                    // create shortcut on desktop
                    var link = (IShellLink) new ShellLink();
                    link.SetDescription("StarTrinity Continuous Speed Test");
                    link.SetPath(mainExeFileName);
                    var linkFile = (IPersistFile)link;
                    linkFile.Save(DesktopShortcutFileName, false);

                    // create icon in start menu
                    linkFile.Save(StartMenuShortcutFileName, false);

                    // show message box
                    MessageBox.Show($"Installation succeeded.\r\nPress OK to start the new installed program.\r\n\r\nCreated shortcut on desktop and in Start menu\r\nInstallation folder: {localPcInstallationFolder}");

                    // start new process
                    Process.Start(mainExeFileName);

                    closeThisProcess = true;
                }
                else
                {
                    mainExeFileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                }

                if (_cstApp.InstallOnThisPC_AddToAutoStart)
                {
                    var rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                    rk.SetValue(AppNameInRegistry, mainExeFileName + " " + CstApp.TrayCliParameter);
                }

                if (closeThisProcess)
                {
                    System.Windows.Application.Current.Shutdown();
                }
                // RaisePropertyChanged(() => InstalledOnThisPcAndAutostartInTrayMode);
            }
            catch (Exception exc)
            {
                CstApp.HandleException(exc);
            }
        }