|
|
@@ -28,17 +28,14 @@ const char *const WinStatsServer::_window_class_name = "server";
|
|
|
*
|
|
|
*/
|
|
|
WinStatsServer::
|
|
|
-WinStatsServer() {
|
|
|
+WinStatsServer() : _port(pstats_port) {
|
|
|
+ set_program_brief("Windows PStats client");
|
|
|
+ add_option("p", "port", 0, "", &ProgramBase::dispatch_int, nullptr, &_port);
|
|
|
+
|
|
|
_last_session = Filename::expand_from(
|
|
|
"$USER_APPDATA/Panda3D-" PANDA_ABI_VERSION_STR "/last-session.pstats");
|
|
|
_last_session.set_binary();
|
|
|
|
|
|
- _window = 0;
|
|
|
- _menu_bar = 0;
|
|
|
- _options_menu = 0;
|
|
|
-
|
|
|
- _time_units = 0;
|
|
|
-
|
|
|
// Create the fonts used for rendering the UI.
|
|
|
NONCLIENTMETRICS metrics = {0};
|
|
|
metrics.cbSize = sizeof(NONCLIENTMETRICS);
|
|
|
@@ -51,6 +48,52 @@ WinStatsServer() {
|
|
|
create_window();
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Does something with the additional arguments on the command line (after all
|
|
|
+ * the -options have been parsed). Returns true if the arguments are good,
|
|
|
+ * false otherwise.
|
|
|
+ */
|
|
|
+bool WinStatsServer::
|
|
|
+handle_args(ProgramBase::Args &args) {
|
|
|
+ if (args.empty()) {
|
|
|
+ new_session();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else if (args.size() == 1) {
|
|
|
+ Filename fn = Filename::from_os_specific(args[0]);
|
|
|
+ fn.set_binary();
|
|
|
+ WinStatsMonitor *monitor = new WinStatsMonitor(this);
|
|
|
+ if (!monitor->read(fn)) {
|
|
|
+ delete monitor;
|
|
|
+
|
|
|
+ std::ostringstream stream;
|
|
|
+ stream << "Failed to load session file: " << fn;
|
|
|
+ std::string str = stream.str();
|
|
|
+ MessageBox(_window, str.c_str(), "PStats Error",
|
|
|
+ MB_OK | MB_ICONEXCLAMATION);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Enable the "New Session", "Save Session" and "Close Session" menu items.
|
|
|
+ MENUITEMINFO mii;
|
|
|
+ memset(&mii, 0, sizeof(mii));
|
|
|
+ mii.cbSize = sizeof(mii);
|
|
|
+ mii.fMask = MIIM_STATE;
|
|
|
+ mii.fState = MFS_ENABLED;
|
|
|
+ SetMenuItemInfoA(_session_menu, MI_session_new, FALSE, &mii);
|
|
|
+ SetMenuItemInfoA(_session_menu, MI_session_save, FALSE, &mii);
|
|
|
+ SetMenuItemInfoA(_session_menu, MI_session_close, FALSE, &mii);
|
|
|
+ SetMenuItemInfoA(_session_menu, MI_session_export_json, FALSE, &mii);
|
|
|
+
|
|
|
+ _monitor = monitor;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ nout << "At most one filename may be specified on the command-line.\n";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
@@ -112,16 +155,16 @@ new_session() {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (listen()) {
|
|
|
+ if (listen(_port)) {
|
|
|
{
|
|
|
std::ostringstream strm;
|
|
|
- strm << "PStats Server (listening on port " << pstats_port << ")";
|
|
|
+ strm << "PStats Server (listening on port " << _port << ")";
|
|
|
std::string title = strm.str();
|
|
|
SetWindowTextA(_window, title.c_str());
|
|
|
}
|
|
|
{
|
|
|
std::ostringstream strm;
|
|
|
- strm << "Waiting for client to connect on port " << pstats_port << "...";
|
|
|
+ strm << "Waiting for client to connect on port " << _port << "...";
|
|
|
std::string title = strm.str();
|
|
|
int part = -1;
|
|
|
SendMessage(_status_bar, SB_SETPARTS, 1, (LPARAM)&part);
|
|
|
@@ -155,9 +198,9 @@ new_session() {
|
|
|
|
|
|
std::ostringstream stream;
|
|
|
stream
|
|
|
- << "Unable to open port " << pstats_port
|
|
|
- << ". Try specifying a different\n"
|
|
|
- << "port number using pstats-port in your Config file.";
|
|
|
+ << "Unable to open port " << _port << ". Try specifying a different "
|
|
|
+ << "port number using pstats-port in your Config file or the -p option on "
|
|
|
+ << "the command-line.";
|
|
|
std::string str = stream.str();
|
|
|
MessageBox(_window, str.c_str(), "PStats Error",
|
|
|
MB_OK | MB_ICONEXCLAMATION);
|