From 602fa75092422097877b81e565bc6ba019732262 Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Thu, 17 Feb 2022 10:34:04 +0100 Subject: [PATCH] Replaced Every Process.Start with a file by the ProcessStartInfo with UseShellExecute true. (The simple version didn't work under .net5.0) --- VECTO/GUI/AboutBox.vb | 17 ++++-------- VECTO/GUI/JiraDialog.vb | 16 +++++------- VECTO/GUI/MainForm.vb | 26 +++++++++---------- VECTO/GUI/WelcomeDialog.vb | 5 ++-- VECTO3GUI2020/Helper/ProcessHelper.cs | 6 ++--- .../Implementation/AboutViewModel.cs | 6 ++--- Vecto3GUI2020Test/UI/DesktopSession.cs | 5 ---- Vecto3GUI2020Test/UI/VECTO3GUI2020Session.cs | 6 ++--- 8 files changed, 34 insertions(+), 53 deletions(-) diff --git a/VECTO/GUI/AboutBox.vb b/VECTO/GUI/AboutBox.vb index 41667f5a83..c6b819ac8a 100644 --- a/VECTO/GUI/AboutBox.vb +++ b/VECTO/GUI/AboutBox.vb @@ -13,29 +13,22 @@ Imports TUGraz.VectoCore.Utils ''' <summary> ''' About Dialog. Shows Licence and contact/support information ''' </summary> -''' <remarks></remarks> Public Class AboutBox - 'Initialize - Private Sub F10_AboutBox_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load + Private Sub F10_AboutBox_Load(sender As Object, e As EventArgs) Handles MyBase.Load Text = "VECTO " & VECTOvers & " / VectoCore" & VectoSimulationCore.BranchSuffix & " " & COREvers End Sub - 'e-mail links---------------------------------------------------------------- Private Sub LinkLabel1_LinkClicked_1(sender As Object, e As LinkLabelLinkClickedEventArgs) _ Handles LinkLabel1.LinkClicked - Process.Start("mailto:jrc-vecto@ec.europa.eu") + Process.Start(New ProcessStartInfo("mailto:jrc-vecto@ec.europa.eu") With {.UseShellExecute = True}) End Sub - '---------------------------------------------------------------------------- - - 'Picture Links------------------------------------------------------------------ Private Sub PictureBoxJRC_Click(sender As Object, e As EventArgs) Handles PictureBoxJRC.Click - Process.Start("http://ec.europa.eu/dgs/jrc/index.cfm") + Process.Start(New ProcessStartInfo("http://ec.europa.eu/dgs/jrc/index.cfm") With {.UseShellExecute = True}) End Sub - - + Private Sub LinkLabel2_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) _ Handles LinkLabel2.LinkClicked - Process.Start("https://joinup.ec.europa.eu/community/eupl/og_page/eupl") + Process.Start(New ProcessStartInfo("https://joinup.ec.europa.eu/community/eupl/og_page/eupl") With {.UseShellExecute = True}) End Sub End Class diff --git a/VECTO/GUI/JiraDialog.vb b/VECTO/GUI/JiraDialog.vb index 9e68b24150..c78e21c5cd 100644 --- a/VECTO/GUI/JiraDialog.vb +++ b/VECTO/GUI/JiraDialog.vb @@ -1,33 +1,31 @@ Imports System.IO -Imports System.Windows.Forms Public Class JiraDialog - Private Sub OK_Button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles OK_Button.Click + Private Sub OK_Button_Click(sender As Object, e As EventArgs) Handles OK_Button.Click DialogResult = DialogResult.OK Close() End Sub Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked - If File.Exists(Path.Combine(MyAppPath, "User Manual\JIRA Quick Start Guide.pdf")) Then - Process.Start(Path.Combine(MyAppPath, "User Manual\JIRA Quick Start Guide.pdf")) + Dim fileName = Path.Combine(MyAppPath, "User Manual\JIRA Quick Start Guide.pdf") + If File.Exists(fileName) Then + Process.Start(New ProcessStartInfo(fileName) With {.UseShellExecute = True}) Else MsgBox("File not found!", MsgBoxStyle.Critical) End If End Sub Private Sub LinkLabel3_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel3.LinkClicked - Dim bodytext As String - - bodytext = "Please provide the following information:" & "%0A" & + Dim bodytext = "Please provide the following information:" & "%0A" & "- Email" & "%0A" & "- Name, Surname" & "%0A" & "- Country of workplace" & "%0A" & "- Position" - Process.Start("mailto:JRC-VECTO@ec.europa.eu?subject=CITnet%20account&body=" & bodytext) + Process.Start(New ProcessStartInfo("mailto:JRC-VECTO@ec.europa.eu?subject=CITnet%20account&body=" & bodytext) With {.UseShellExecute = True}) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click - Process.Start("https://citnet.tech.ec.europa.eu/CITnet/jira/browse/VECTO") + Process.Start(New ProcessStartInfo("https://citnet.tech.ec.europa.eu/CITnet/jira/browse/VECTO") With {.UseShellExecute = True}) End Sub End Class diff --git a/VECTO/GUI/MainForm.vb b/VECTO/GUI/MainForm.vb index 005ca70e46..8c36cfd648 100644 --- a/VECTO/GUI/MainForm.vb +++ b/VECTO/GUI/MainForm.vb @@ -763,7 +763,7 @@ lbFound: Private Sub OpenLogToolStripMenuItem_Click(sender As Object, e As EventArgs) _ Handles OpenLogToolStripMenuItem.Click - Process.Start(Path.Combine(MyAppPath, "log.txt")) + Process.Start(new ProcessStartInfo(Path.Combine(MyAppPath, "log.txt")) with {.UseShellExecute = true}) End Sub Private Sub SettingsToolStripMenuItem_Click(sender As Object, e As EventArgs) _ @@ -773,20 +773,20 @@ lbFound: Private Sub UserManualToolStripMenuItem_Click(sender As Object, e As EventArgs) _ Handles UserManualToolStripMenuItem.Click - If File.Exists(Path.Combine(MyAppPath, "User Manual\help.html")) Then - Dim defaultBrowserPath As String = BrowserUtils.GetDefaultBrowserPath() - Process.Start(defaultBrowserPath, $"""file://{Path.Combine(MyAppPath, "User Manual\help.html")}""") - Else - MsgBox("User Manual not found!", MsgBoxStyle.Critical) - End If + OpenFileExternal("User Manual\help.html") End Sub Private Sub UpdateNotesToolStripMenuItem_Click(sender As Object, e As EventArgs) _ Handles UpdateNotesToolStripMenuItem.Click - If File.Exists(Path.Combine(MyAppPath, "User Manual\Release Notes.pdf")) Then - Process.Start(Path.Combine(MyAppPath, "User Manual\Release Notes.pdf")) + OpenFileExternal("User Manual\Release Notes.pdf") + End Sub + + Private Sub OpenFileExternal(filename As String) + Dim filepath = Path.Combine(MyAppPath, filename) + If File.Exists(filepath) Then + Process.Start(new ProcessStartInfo(filepath) With {.UseShellExecute = true}) Else - MsgBox("Release Notes not found!", MsgBoxStyle.Critical) + MsgBox("File not found!", MsgBoxStyle.Critical) End If End Sub @@ -1563,9 +1563,9 @@ lbFound: txt = txt.Replace("\", "/") txt = "file:///" & txt Try - Process.Start(txt) + Process.Start(new ProcessStartInfo(txt) With {.UseShellExecute = True}) Catch ex As Exception - MsgBox("Cannot open link! (-_-;)") + MsgBox("Cannot open link!") End Try ElseIf _ Len(CStr(LvMsg.SelectedItems(0).Tag)) > 5 AndAlso @@ -1577,7 +1577,7 @@ lbFound: Microsoft.VisualBasic.Left(CStr(LvMsg.SelectedItems(0).Tag), 5) = "<RUN>" Then txt = CStr(LvMsg.SelectedItems(0).Tag).Replace("<RUN>", "") Try - Process.Start(txt) + Process.Start(new ProcessStartInfo(txt) With {.UseShellExecute = true}) Catch ex As Exception GUIMsg(MessageType.Err, "Could not run '" & txt & "'!") End Try diff --git a/VECTO/GUI/WelcomeDialog.vb b/VECTO/GUI/WelcomeDialog.vb index 916fb0b2ce..8e511bb206 100644 --- a/VECTO/GUI/WelcomeDialog.vb +++ b/VECTO/GUI/WelcomeDialog.vb @@ -30,7 +30,7 @@ Public Class WelcomeDialog 'Open Release Notes Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If File.Exists(Path.Combine(MyAppPath, "User Manual\Release Notes.pdf")) Then - Process.Start(Path.Combine(MyAppPath, "User Manual\Release Notes.pdf")) + Process.Start(New ProcessStartInfo(Path.Combine(MyAppPath, "User Manual\Release Notes.pdf")) With {.UseShellExecute = true}) Else MsgBox("Release Notes not found!", MsgBoxStyle.Critical) End If @@ -39,8 +39,7 @@ Public Class WelcomeDialog 'Open Quick Start Guide Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If File.Exists(Path.Combine(MyAppPath, "User Manual\help.html")) Then - Dim defaultBrowserPath As String = BrowserUtils.GetDefaultBrowserPath() - Process.Start(defaultBrowserPath, $"""file://{Path.Combine(MyAppPath, "User Manual\help.html")}""") + Process.Start(new ProcessStartInfo(Path.Combine(MyAppPath, "User Manual\help.html")) With {.UseShellExecute = true}) Else MsgBox("User Manual not found!", MsgBoxStyle.Critical) End If diff --git a/VECTO3GUI2020/Helper/ProcessHelper.cs b/VECTO3GUI2020/Helper/ProcessHelper.cs index a5383aa430..e8de544054 100644 --- a/VECTO3GUI2020/Helper/ProcessHelper.cs +++ b/VECTO3GUI2020/Helper/ProcessHelper.cs @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; -using System.Threading.Tasks; namespace VECTO3GUI2020.Helper { @@ -25,7 +23,7 @@ namespace VECTO3GUI2020.Helper explorerCommandStrBuilder.Append(" /select "); explorerCommandStrBuilder.Append(path); - StartProcess("explorer.exe", ("/select," + path)); + StartProcess("explorer.exe", "/select," + path); } @@ -63,7 +61,7 @@ namespace VECTO3GUI2020.Helper try { - Process.Start(command, argumentsString); + Process.Start(new ProcessStartInfo(command, argumentsString) { UseShellExecute = true}); } catch (Exception e) { diff --git a/VECTO3GUI2020/ViewModel/Implementation/AboutViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/AboutViewModel.cs index 95b9472d2f..22d39d6457 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/AboutViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/AboutViewModel.cs @@ -43,7 +43,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation private void DoLinkClickedCommand() { - Process.Start(EUPLLink); + Process.Start(new ProcessStartInfo(EUPLLink) { UseShellExecute = true}); } public ICommand MailClickedCommand @@ -53,7 +53,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation private void DoMailClickedCommand() { - Process.Start(JRCMail); + Process.Start(new ProcessStartInfo(JRCMail) { UseShellExecute = true}); } public ICommand JrcPicClickedCommand @@ -63,7 +63,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation private void DoJrcPicClickedCommand() { - Process.Start(JRCPic); + Process.Start(new ProcessStartInfo(JRCPic) { UseShellExecute = true}); } #endregion diff --git a/Vecto3GUI2020Test/UI/DesktopSession.cs b/Vecto3GUI2020Test/UI/DesktopSession.cs index d71ebdb979..7e4941c8ca 100644 --- a/Vecto3GUI2020Test/UI/DesktopSession.cs +++ b/Vecto3GUI2020Test/UI/DesktopSession.cs @@ -1,12 +1,7 @@ using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; namespace Vecto3GUI2020Test { diff --git a/Vecto3GUI2020Test/UI/VECTO3GUI2020Session.cs b/Vecto3GUI2020Test/UI/VECTO3GUI2020Session.cs index 2f9abe2cbe..2f9ebe751a 100644 --- a/Vecto3GUI2020Test/UI/VECTO3GUI2020Session.cs +++ b/Vecto3GUI2020Test/UI/VECTO3GUI2020Session.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Appium.Windows; +using System.Reflection; using VECTO3GUI2020.Properties; namespace Vecto3GUI2020Test.UI @@ -13,9 +14,6 @@ namespace Vecto3GUI2020Test.UI protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723"; private const string NotepadAppId = @"C:\Windows\System32\notepad.exe"; - private const string vectoLocation = - @"C:\Users\Harry\source\repos\vecto-dev\VECTO3GUI2020\bin\Debug\VECTO3GUI2020.exe"; - private static Process winappDriverProcess; internal static WindowsDriver<WindowsElement> session; @@ -38,7 +36,7 @@ namespace Vecto3GUI2020Test.UI appiumOptions.AddAdditionalCapability("app", @"C:\Users\Harry\source\repos\vecto-dev\VECTO3GUI2020\bin\Debug\VECTO3GUI2020.exe"); appiumOptions.AddAdditionalCapability("deviceName", "WindowsPC"); session = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appiumOptions); - session.ActivateApp(vectoLocation); + session.ActivateApp(Assembly.GetExecutingAssembly().Location); // Use the session to control the app Assert.IsNotNull(session); -- GitLab