|
1 |
| -using System.Diagnostics; |
| 1 | +using System.ComponentModel; |
| 2 | +using System.Diagnostics; |
2 | 3 | using ChessEngineAPI.App;
|
3 | 4 |
|
4 | 5 | AppDomain.CurrentDomain.ProcessExit += CloseHandler;
|
5 | 6 |
|
6 | 7 | Console.WriteLine("Initializing application...\n");
|
7 | 8 |
|
| 9 | +string PythonPath = ""; |
| 10 | + |
| 11 | +try |
| 12 | +{ |
| 13 | + FileStream fs = File.OpenRead("PythonPath"); |
| 14 | + StreamReader sreader = new StreamReader(fs); |
| 15 | + PythonPath = Convert.ToString(sreader.ReadToEnd()); |
| 16 | + sreader.Close(); |
| 17 | + fs.Close(); |
| 18 | +} |
| 19 | +catch |
| 20 | +{ |
| 21 | + Console.WriteLine("\nPython Path is invalid. Please enter new Path: "); |
| 22 | + PythonPath = Console.ReadLine(); |
| 23 | + FileStream _fs = File.Create("PythonPath"); |
| 24 | + StreamWriter swrite = new StreamWriter(_fs); |
| 25 | + swrite.WriteLine(PythonPath); |
| 26 | + swrite.Close(); |
| 27 | + _fs.Close(); |
| 28 | +} |
| 29 | + |
| 30 | +Process process; |
| 31 | + |
| 32 | +try |
| 33 | +{ |
| 34 | + process = Process.Start(PythonPath); |
| 35 | + process.Kill(true); |
| 36 | +} |
| 37 | +catch |
| 38 | +{ |
| 39 | + Console.WriteLine("\nPython Path is invalid. Please enter new Path: "); |
| 40 | + PythonPath = Console.ReadLine(); |
| 41 | + FileStream _fs = File.Create("PythonPath"); |
| 42 | + StreamWriter swrite = new StreamWriter(_fs); |
| 43 | + swrite.WriteLine(PythonPath); |
| 44 | + swrite.Close(); |
| 45 | + _fs.Close(); |
| 46 | +} |
| 47 | + |
| 48 | +string StockFishPath = ""; |
| 49 | + |
| 50 | +try |
| 51 | +{ |
| 52 | + FileStream fs2 = File.OpenRead("StockFishPath"); |
| 53 | + StreamReader sreader2 = new StreamReader(fs2); |
| 54 | + StockFishPath = Convert.ToString(sreader2.ReadToEnd()); |
| 55 | + sreader2.Close(); |
| 56 | + fs2.Close(); |
| 57 | + |
| 58 | +} |
| 59 | +catch |
| 60 | +{ |
| 61 | + Console.WriteLine("\nStockFish Path is invalid. Please enter new Path: "); |
| 62 | + StockFishPath = Console.ReadLine(); |
| 63 | + FileStream _fs = File.Create("StockFishPath"); |
| 64 | + StreamWriter swrite = new StreamWriter(_fs); |
| 65 | + swrite.WriteLine(StockFishPath); |
| 66 | + swrite.Close(); |
| 67 | + _fs.Close(); |
| 68 | +} |
| 69 | + |
| 70 | +Process process2; |
| 71 | + |
| 72 | +try |
| 73 | +{ |
| 74 | + process2 = Process.Start(PythonPath); |
| 75 | + process2.Kill(true); |
| 76 | +} |
| 77 | +catch |
| 78 | +{ |
| 79 | + Console.WriteLine("\nStockFish Path is invalid. Please enter new Path: "); |
| 80 | + StockFishPath = Console.ReadLine(); |
| 81 | + FileStream _fs = File.Create("StockFishPath"); |
| 82 | + StreamWriter swrite = new StreamWriter(_fs); |
| 83 | + swrite.WriteLine(StockFishPath); |
| 84 | + swrite.Close(); |
| 85 | + _fs.Close(); |
| 86 | +} |
| 87 | + |
| 88 | + |
8 | 89 | mainApp = new App();
|
9 | 90 |
|
10 |
| -Console.WriteLine($"\nFinished initialization of application at port :{GlobalVars.Port}."); |
| 91 | +Console.WriteLine($"\n\nFinished initialization of application at port :{GlobalVars.Port}."); |
11 | 92 |
|
12 | 93 | while (ApplicationIsRunning)
|
13 | 94 | {
|
@@ -62,6 +143,26 @@ private static void PyProcessOutputHandler(object sender, DataReceivedEventArgs
|
62 | 143 | Console.WriteLine(sender.ToString() + " - " + args.Data.ToString());
|
63 | 144 | }
|
64 | 145 |
|
| 146 | + public static bool ExistsOnPath(string exeName) |
| 147 | + { |
| 148 | + try |
| 149 | + { |
| 150 | + using (Process p = new Process()) |
| 151 | + { |
| 152 | + p.StartInfo.UseShellExecute = false; |
| 153 | + p.StartInfo.FileName = "where"; |
| 154 | + p.StartInfo.Arguments = exeName; |
| 155 | + p.Start(); |
| 156 | + p.WaitForExit(); |
| 157 | + return p.ExitCode == 0; |
| 158 | + } |
| 159 | + } |
| 160 | + catch (Win32Exception) |
| 161 | + { |
| 162 | + throw new Exception("'where' command is not on path"); |
| 163 | + } |
| 164 | + } |
| 165 | + |
65 | 166 | public static string OpenPY()
|
66 | 167 | {
|
67 | 168 | //Open python script that runs chess engine.
|
|
0 commit comments