Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Select Git revision
  • 2a243b5798c2866ce06cb613cc3913dedf9f6373
  • stable default
  • feat-fchv-bus
  • fix-h2-ice-bus
  • powertrains-multiple-axles
  • amdm3/develop
  • issue-1039
  • amdm3/main
  • test/nuget_publish
  • IEPC-experiments
  • amdm2/main
  • amdm2/develop
  • aptngearbox-not-auto
  • playground
  • official/main
  • official/develop
  • issue-templates
  • pdf-reports
  • HEV-timeruns-dev
  • timerun-empower-hybrids
  • timerun-pwheel-hybrids
  • Release/v5.0.3
  • Release/v5.0.1
  • Release/5.0.0-RC
  • Nuget/v0.11.4-DEV
  • Release/v0.11.4-DEV
  • Release/4.3.4-DEV
  • Release/4.3.3
  • Release/4.3.2-RC
  • Release/v4.3.0-DEV
  • Release/4.2.7
  • XMLConverterTool/4.2.6.0
  • Release/4.2.6-RC
  • Release/v4.2.5
  • Release/v4.2.3
  • Release/v4.2.2.3539-RC
  • Release/v4.2.1.3469
  • Release/v0.11.2.3456-DEV
  • Release/v4.2.0.3448-RC
  • Release/v4.1.3.3415
  • Release/v4.1.1.3413
41 results

Vecto3GUI2020Test.csproj

Blame
  • Forked from VECTO / VECTO Sim
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    StarterHelper.cs 2.42 KiB
    using Microsoft.Win32;
    using System;
    using System.Collections;
    using System.Diagnostics;
    using System.IO;
    using System.Reflection;
    
    namespace TUGraz.VECTO
    {
    	class StarterHelper
    	{
    		public static void StartVECTO(string[] args, params string[] validVersions)
    		{
    			var path = "No path found.";
    			string version = "No version found.";
    			if (validVersions is null) {
    				validVersions = new[] { "net45", "net48", "net60" };
    			}
    			try {
    				if (args.Length > 0) {
    					version = args[0].ToLower();
    				} else {
    					version = StarterHelper.GetHighestNETVersion();
    				}
    
    				path = $"{version}\\{Assembly.GetExecutingAssembly().GetName().Name}.exe";
    				Process.Start(new ProcessStartInfo(path) {
    					WorkingDirectory = Directory.GetCurrentDirectory()
    				});
    				ValidateVersion(version, validVersions);
    			} catch (Exception e) {
    				var message = $"Error during starting VECTO.\nDetected .NET version: {version}\nTried to open path: {path}\n{e.Message}";
    				File.AppendAllText("LOG.txt", $"{DateTime.Now} {message}\n");
    				Console.WriteLine(message);
    				throw new Exception(message);
    			}
    		}
    		
    		private static void ValidateVersion(string version, params string[] validVersions)
    		{
    			if (!((IList)validVersions).Contains(version))
    				throw new Exception($"Invalid .NET Version supplied. Only the following values are valid: {string.Join(", ", validVersions)}");
    		}
    		
    		private static string GetHighestNETVersion()
    		{
    			if (SupportsNet60()) {
    				return "net60";
    			}
    
    			if (SupportsNet48()) {
    				return "net48";
    			}
    
    			return "net45";
    		}
    
    		private static bool SupportsNet60()
    		{
    			try {
    				var p = Process.Start(new ProcessStartInfo("dotnet", "--list-runtimes") {
    					CreateNoWindow = true,
    					UseShellExecute = false,
    					RedirectStandardError = true,
    					RedirectStandardOutput = true
    				});
    
    				p.WaitForExit();
    				var output = p.StandardOutput.ReadToEnd();
    				return output.Contains("Microsoft.WindowsDesktop.App 6");
    			} catch (Exception e) {
    				Console.WriteLine(e);
    			}
    
    			return false;
    		}
    
    		private static bool SupportsNet48()
    		{
    			const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
    			using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey)) {
    				if (ndpKey != null && ndpKey.GetValue("Release") != null) {
    					var releaseKey = (int)ndpKey.GetValue("Release");
    					return releaseKey >= 528040;
    				}
    
    				return false;
    			}
    		}
    
    	}
    }