Skip to content

Commit 21cf063

Browse files
committed
Merge pull request fdorg#446 from fdorg/feature/mongoose-server-update
Updated the webserver with a better sample code
2 parents 4f90d9b + 493ad51 commit 21cf063

File tree

7 files changed

+576
-31
lines changed

7 files changed

+576
-31
lines changed

External/Plugins/ProjectManager/Actions/Webserver.cs

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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()

External/Plugins/ProjectManager/PluginMain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ void OpenSwf(string path)
881881
string doc = project.TestMovieCommand;
882882
try
883883
{
884-
if (string.IsNullOrEmpty(project.TestMovieCommand))
884+
if (string.IsNullOrEmpty(doc) || doc == "/" || doc == "\\")
885885
{
886886
doc = project.OutputPathAbsolute;
887887
if (File.Exists(doc)) doc = Path.GetDirectoryName(doc);
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11

22
:: http://cesanta.com/docs/Embed.shtml
33

4+
:: ATTENTION!
5+
:: make sure the binary is 32 bits (default with Visual C++ Express)
6+
47
set FLAGS=-DMONGOOSE_NO_DAV -DMONGOOSE_NO_CGI -DMONGOOSE_NO_AUTH -DMONGOOSE_NO_LOGGING
58

69
mkdir obj
7-
cl mongoose_server.c mongoose.c %FLAGS% /TC /MD /Fo.\obj\
10+
cl server.c mongoose.c %FLAGS% /TC /MD /Fo.\obj\
811

FlashDevelop/Bin/Debug/Tools/webserver/mongoose_server.c

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)