@@ -38,18 +38,45 @@ public static void StartServer(string path)
3838 return ;
3939 }
4040
41+ ValidatePath ( path ) ;
42+ CreateServer ( ) ;
43+
44+ // open browser
45+ PluginBase . MainForm . CallCommand ( "RunProcess" , "http://localhost:" + portServed + "/" + fileServed ) ;
46+ }
47+
48+ static void ValidatePath ( string path )
49+ {
4150 if ( File . Exists ( path ) )
4251 {
4352 fileServed = Path . GetFileName ( path ) ;
4453 path = Path . GetDirectoryName ( path ) ;
4554 }
4655 else fileServed = "" ;
4756 pathServed = path ;
57+ }
58+
59+ static void CreateServer ( )
60+ {
61+ var ToolsWebserver = Path . Combine ( PathHelper . ToolDir , "webserver" ) ;
62+ var config = GetServerConfig ( Path . Combine ( ToolsWebserver , "server.ini" ) ) ;
63+ if ( config == null ) return ;
64+
65+ var server = Path . Combine ( ToolsWebserver , config [ "executable" ] ) ;
66+ var arguments = config [ "arguments" ] . Replace ( "{doc}" , pathServed ) . Replace ( "{port}" , portServed . ToString ( ) ) ;
67+
68+ TraceManager . Add ( "Web Server starting with root: " + pathServed ) ;
69+ if ( config . ContainsKey ( "verbose" ) && config [ "verbose" ] . ToLower ( ) == "true" )
70+ TraceManager . Add ( "Server process: " + server + " " + arguments ) ;
71+
72+ StartProcess ( server , arguments ) ;
73+ }
4874
49- TraceManager . Add ( "Web Server starting with root: " + path ) ;
50- var server = Path . Combine ( PathHelper . ToolDir , "webserver\\ server.exe" ) ;
51- var infos = new ProcessStartInfo ( server , portServed . ToString ( ) ) ;
52- infos . Arguments = "" + portServed ;
75+ static void StartProcess ( string executable , string arguments )
76+ {
77+ var infos = new ProcessStartInfo ( ) ;
78+ infos . FileName = executable ;
79+ infos . Arguments = arguments ;
5380 infos . WorkingDirectory = pathServed ;
5481 infos . WindowStyle = ProcessWindowStyle . Hidden ;
5582 try
@@ -61,8 +88,29 @@ public static void StartServer(string path)
6188 TraceManager . Add ( "Unable to start the webserver: " + ex . Message , 3 ) ;
6289 return ;
6390 }
91+ }
6492
65- PluginBase . MainForm . CallCommand ( "RunProcess" , "http://localhost:" + portServed + "/" + fileServed ) ;
93+ static Dictionary < string , string > GetServerConfig ( string configPath )
94+ {
95+ var ini = ConfigHelper . Parse ( configPath , true ) ;
96+ if ( ! ini . ContainsKey ( "Default" ) )
97+ {
98+ TraceManager . Add ( "Missing " + configPath , 3 ) ;
99+ return null ;
100+ }
101+
102+ var config = ini [ "Default" ] ;
103+ if ( ! config . ContainsKey ( "executable" ) )
104+ {
105+ TraceManager . Add ( "Missing 'executable' entry in in " + configPath , 3 ) ;
106+ return null ;
107+ }
108+ if ( ! config . ContainsKey ( "arguments" ) )
109+ {
110+ TraceManager . Add ( "Missing 'arguments' entry in in " + configPath , 3 ) ;
111+ return null ;
112+ }
113+ return config ;
66114 }
67115
68116 public static void KillServer ( )
0 commit comments