@@ -118,6 +118,7 @@ static bool set_if_mode (const char *arg);
118118static bool set_interactive_ttl (const char * arg );
119119static bool set_home_pos (const char * arg );
120120static bool set_home_pos_from_location_API (const char * arg );
121+ static bool launch_setup_exe (void );
121122static bool set_host_port_raw_in (const char * arg );
122123static bool set_host_port_raw_out (const char * arg );
123124static bool set_host_port_sbs_in (const char * arg );
@@ -751,6 +752,31 @@ static bool modeS_init (void)
751752 if (strcmp (Modes .cfg_file , "NUL" ) && !cfg_open_and_parse (Modes .cfg_file , config ))
752753 return (false);
753754
755+ /* Check if homepos is unconfigured (-1,-1) and launch setup.exe */
756+ if (Modes .home_pos_ok && Modes .home_pos .lat == -1.0 && Modes .home_pos .lon == -1.0 )
757+ {
758+ LOG_STDERR ("Home position is not configured. Launching setup.exe...\n" );
759+ if (!launch_setup_exe ())
760+ {
761+ LOG_STDERR ("Setup failed or was cancelled. Cannot proceed without a valid home position.\n" );
762+ return (false);
763+ }
764+ /* Reload config to get the updated homepos */
765+ LOG_STDERR ("Reloading configuration...\n" );
766+ if (!cfg_open_and_parse (Modes .cfg_file , config ))
767+ {
768+ LOG_STDERR ("Failed to reload configuration file.\n" );
769+ return (false);
770+ }
771+ /* Verify homepos was updated */
772+ if (!Modes .home_pos_ok || (Modes .home_pos .lat == -1.0 && Modes .home_pos .lon == -1.0 ))
773+ {
774+ LOG_STDERR ("Home position is still not configured after setup. Cannot proceed.\n" );
775+ return (false);
776+ }
777+ LOG_STDERR ("Home position configured: %.6f,%.6f\n" , Modes .home_pos .lat , Modes .home_pos .lon );
778+ }
779+
754780 if (Modes .http_ipv6_only )
755781 Modes .http_ipv6 = true;
756782
@@ -4208,6 +4234,46 @@ static void set_debug_bits (const char *flags)
42084234 }
42094235}
42104236
4237+ /**
4238+ * Launch setup.exe and wait for it to complete.
4239+ * Returns true if setup.exe exits with code 0, false otherwise.
4240+ */
4241+ static bool launch_setup_exe (void )
4242+ {
4243+ mg_file_path setup_path ;
4244+ intptr_t exit_code ;
4245+
4246+ /* Construct path to setup.exe in the same directory as the executable */
4247+ snprintf (setup_path , sizeof (setup_path ), "%s\\setup.exe" , Modes .where_am_I );
4248+
4249+ /* Check if setup.exe exists */
4250+ if (GetFileAttributesA (setup_path ) == INVALID_FILE_ATTRIBUTES )
4251+ {
4252+ LOG_STDERR ("setup.exe not found at: %s\n" , setup_path );
4253+ LOG_STDERR ("Please ensure setup.exe is in the same directory as dump1090.exe\n" );
4254+ return (false);
4255+ }
4256+
4257+ LOG_STDERR ("Launching setup.exe...\n" );
4258+
4259+ exit_code = _spawnl (_P_WAIT , setup_path , setup_path , NULL );
4260+
4261+ if (exit_code == -1 )
4262+ {
4263+ LOG_STDERR ("Failed to launch setup.exe\n" );
4264+ return (false);
4265+ }
4266+
4267+ if (exit_code != 0 )
4268+ {
4269+ LOG_STDERR ("Setup exited with code %ld.\n" , exit_code );
4270+ return (false);
4271+ }
4272+
4273+ LOG_STDERR ("Setup completed successfully.\n" );
4274+ return (true);
4275+ }
4276+
42114277static bool set_home_pos (const char * arg )
42124278{
42134279 pos_t pos ;
0 commit comments