From 28af05268da1ab59ff23cbfaa6e74159c9cf0433 Mon Sep 17 00:00:00 2001 From: Indu Prakash <6459774+iprak@users.noreply.github.com> Date: Sun, 22 Jan 2023 12:25:50 -0600 Subject: [PATCH] Win32 app / optional port (#609) * Ignore libs_for_simulator content * Accept command line optional port * Fixed order of buttons * Adjusted argv parsing * Changed output assembly to openBeken_win32 * Automatically load the last project --- .gitignore | 1 + openBeken_win32_mvsc2017.vcxproj | 2 ++ src/httpserver/http_tcp_server_nonblocking.c | 7 ++++-- src/sim/Simulator.cpp | 10 ++++++-- src/sim/Simulator.h | 5 ++++ src/sim/sim_sdl.cpp | 1 + src/win_main.c | 26 +++++++++++++++++++- 7 files changed, 47 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index b0056850a..e0c5a2611 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ output/** .vscode node_modules Debug*/** +libs_for_simulator/** \ No newline at end of file diff --git a/openBeken_win32_mvsc2017.vcxproj b/openBeken_win32_mvsc2017.vcxproj index 106712588..9d34c180b 100644 --- a/openBeken_win32_mvsc2017.vcxproj +++ b/openBeken_win32_mvsc2017.vcxproj @@ -83,6 +83,7 @@ $(SolutionDir)$(Configuration)\ $(Configuration)\ + openBeken_win32 $(SolutionDir)$(Configuration)\ @@ -91,6 +92,7 @@ $(SolutionDir)$(Configuration)\ $(Configuration)\ + openBeken_win32 $(SolutionDir)$(Configuration)\ diff --git a/src/httpserver/http_tcp_server_nonblocking.c b/src/httpserver/http_tcp_server_nonblocking.c index 6f0ae4557..76f3d5eb3 100644 --- a/src/httpserver/http_tcp_server_nonblocking.c +++ b/src/httpserver/http_tcp_server_nonblocking.c @@ -10,7 +10,7 @@ SOCKET ListenSocket = INVALID_SOCKET; -#define DEFAULT_PORT "80" +int g_port = 80; int HTTPServer_Start() { @@ -29,7 +29,10 @@ int HTTPServer_Start() { closesocket(ListenSocket); } // Resolve the server address and port - iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result); + char service[6]; + snprintf(service, sizeof(service), "%u", g_port); + + iResult = getaddrinfo(NULL, service, &hints, &result); if ( iResult != 0 ) { printf("getaddrinfo failed with error: %d\n", iResult); WSACleanup(); diff --git a/src/sim/Simulator.cpp b/src/sim/Simulator.cpp index 9acba0309..e035b8dcb 100644 --- a/src/sim/Simulator.cpp +++ b/src/sim/Simulator.cpp @@ -324,9 +324,9 @@ bool CSimulator::saveSimulationAs(const char *s) { void CSimulator::showExitSaveMessageBox() { const SDL_MessageBoxButtonData buttons[] = { + {SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 2, "Cancel"}, { /* .flags, .buttonid, .text */ 0, 0, "No" }, - { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "Yes" }, - { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 2, "Cancel" }, + {SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "Yes"} }; const SDL_MessageBoxColorScheme colorScheme = { @@ -438,5 +438,11 @@ void CSimulator::onKeyDown(int keyCode) { } } +void CSimulator::loadRecentProject() { + if (recents->size() > 0) { + loadSimulation(recents->get(0)); + } +} + #endif diff --git a/src/sim/Simulator.h b/src/sim/Simulator.h index 648583b91..55d22b4ef 100644 --- a/src/sim/Simulator.h +++ b/src/sim/Simulator.h @@ -66,6 +66,11 @@ public: return true; return false; } + + /// + /// Load the last project. + /// + void loadRecentProject(); }; #endif \ No newline at end of file diff --git a/src/sim/sim_sdl.cpp b/src/sim/sim_sdl.cpp index 145f383e2..44053ebaf 100644 --- a/src/sim/sim_sdl.cpp +++ b/src/sim/sim_sdl.cpp @@ -179,6 +179,7 @@ extern "C" int SIM_CreateWindow(int argc, char **argv) glutInit(&argc, argv); sim = new CSimulator(); sim->createWindow(); + sim->loadRecentProject(); return 0; } extern "C" void SIM_RunWindow() { diff --git a/src/win_main.c b/src/win_main.c index 561599eb5..042ede7c0 100644 --- a/src/win_main.c +++ b/src/win_main.c @@ -27,6 +27,7 @@ int accum_time = 0; int win_frameNum = 0; // this time counter is simulated, I need this for unit tests to work int g_simulatedTimeNow = 0; +extern int g_port; #define DEFAULT_FRAME_TIME 5 @@ -182,7 +183,30 @@ int g_bDoingUnitTestsNow = 0; #include "sim/sim_public.h" int __cdecl main(int argc, char **argv) { - bool bWantsUnitTests = 1; + bool bWantsUnitTests = true; + + if (argc > 1) { + int value; + + for (int i = 1; i < argc; i++) { + if (argv[i][0] == '-') { + if (wal_strnicmp(argv[i] + 1, "port", 4) == 0) { + i++; + + if (i < argc && sscanf(argv[i], "%d", &value) == 1) { + g_port = value; + } + } else if (wal_strnicmp(argv[i] + 1, "runUnitTests", 12) == 0) { + i++; + + if (i < argc && sscanf(argv[i], "%d", &value) == 1) { + bWantsUnitTests = value != 0; + } + } + } + } + } + WSADATA wsaData; int iResult;