1
1
using System . Diagnostics ;
2
2
using System . Reflection ;
3
+ using System . Runtime . InteropServices ;
4
+ [ DllImport ( "User32.dll" , CharSet = CharSet . Unicode ) ]
5
+ static extern int MessageBox ( IntPtr h , string m , string c , int type ) ;
6
+
7
+ findJavaVersion ( ) ;
3
8
4
9
Directory . CreateDirectory ( "Embedded_Circuits" ) ;
5
10
21
26
22
27
}
23
28
24
- Console . Write ( "Java Version: " ) ;
25
- findJavaVersion ( ) ;
26
-
27
29
//Start Main Simulation screen
28
30
Process p = new Process ( ) ;
29
31
p . StartInfo . UseShellExecute = false ;
35
37
p . StartInfo . FileName + " " +
36
38
p . StartInfo . Arguments ) ;
37
39
p . Start ( ) ;
38
- Thread . Sleep ( 50 ) ; //to allow Digital to start before this program terminates..
40
+ // Thread.Sleep(50); //to allow Digital to start before this program terminates..
39
41
40
42
static void findJavaVersion ( )
41
43
{
42
- try
43
- {
44
- ProcessStartInfo psi = new ProcessStartInfo ( ) ;
45
- psi . FileName = "java" ;
46
- psi . Arguments = " -version" ;
47
- psi . RedirectStandardError = true ;
48
- psi . UseShellExecute = false ;
49
-
50
- Process pr = Process . Start ( psi ) ;
51
- string strOutput = pr . StandardError . ReadLine ( ) . Split ( ' ' ) [ 2 ] . Replace ( "\" " , "" ) ;
52
-
53
- Console . WriteLine ( strOutput ) ;
54
- if ( strOutput . Contains ( "'java' is not recognized as an internal or external command" ) )
55
- {
56
- Console . WriteLine ( "Java doesn't seem to be installed on this machine.\n " +
57
- "Please download & install java, then try again." ) ;
58
- throw new Exception ( "Java not found." ) ;
59
- }
60
- }
61
- catch ( Exception ex )
44
+ ProcessStartInfo psi = new ProcessStartInfo ( ) ;
45
+ psi . FileName = "java" ;
46
+ psi . Arguments = " -version" ;
47
+ psi . RedirectStandardError = true ;
48
+ psi . UseShellExecute = false ;
49
+ Process pr = Process . Start ( psi ) ;
50
+
51
+ string strOutput = pr . StandardError . ReadLine ( ) . Split ( ' ' ) [ 2 ] . Replace ( "\" " , "" ) ;
52
+ if ( strOutput . Contains ( "'java' is not recognized as an internal or external command" ) )
62
53
{
63
- Console . WriteLine ( "Exception is " + ex . Message ) ;
54
+ MessageBox ( ( IntPtr ) 0 , "Java doesn't seem to be installed on this machine.\n " +
55
+ "Please download & install java, then try again.\n \n " +
56
+ "I determined that Java is missing by trying the command 'java -version' in console,\n " +
57
+ "to which the output was:\n " + strOutput , "Java not found on this machine." , 0 ) ;
58
+ throw new ApplicationException ( "Java not found." ) ; //to not continue unpacking and trying to launch Digital
64
59
}
65
60
}
0 commit comments