@@ -52,79 +52,7 @@ pub fn exit_blocking(code: i32) {
5252 std:: process:: exit ( code) ;
5353}
5454
55- fn kill_other_instances ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
56- // Determine the image name of the current executable
57- let this_exe = env:: current_exe ( ) ?;
58- let image_name = this_exe. file_name ( )
59- . and_then ( |s| s. to_str ( ) )
60- . ok_or ( "Failed to determine current executable name" ) ?
61- . to_string ( ) ;
62-
63- let this_pid = std:: process:: id ( ) ;
64- info ! ( "Attempting to terminate other running instances of {}..." , image_name) ;
65-
66- // Query tasklist for processes with the same image name, in CSV for easier parsing -- somewhat hacky but works
67- let output = Command :: new ( "tasklist" )
68- . args ( [ "/FI" , & format ! ( "IMAGENAME eq {}" , image_name) , "/FO" , "CSV" ] )
69- . output ( ) ?;
70-
71- if !output. status . success ( ) {
72- let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
73- warn ! ( "tasklist failed while searching for other instances: {}" , stderr) ;
74- return Ok ( ( ) ) ;
75- }
76-
77- let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
78- let mut killed_any = false ;
79-
80- for ( i, line) in stdout. lines ( ) . enumerate ( ) {
81- if i == 0 { continue ; } // skip header
82- let trimmed = line. trim ( ) ;
83- if trimmed. is_empty ( ) { continue ; }
84- // CSV fields quoted, expect: "Image Name","PID","Session Name","Session#","Mem Usage"
85- // We'll split commas and trim surrounding quotes.
86- let parts: Vec < String > = trimmed. split ( ',' )
87- . map ( |s| s. trim ( ) . trim_matches ( '"' ) . to_string ( ) )
88- . collect ( ) ;
89- if parts. len ( ) < 2 { continue ; }
90- let pid_str = & parts[ 1 ] ;
91- if let Ok ( pid) = pid_str. parse :: < u32 > ( ) {
92- if pid == this_pid {
93- continue ; // skip self
94- }
95- // Attempt to kill this PID
96- let kill = Command :: new ( "taskkill" ) . args ( [ "/PID" , & pid. to_string ( ) , "/F" ] ) . output ( ) ;
97- match kill {
98- Ok ( res) => {
99- if res. status . success ( ) {
100- info ! ( "Terminated process PID {} ({})" , pid, image_name) ;
101- killed_any = true ;
102- } else {
103- let stderr = String :: from_utf8_lossy ( & res. stderr ) ;
104- // If the process exited between list and kill, ignore the error.
105- warn ! ( "Failed to terminate PID {}: {}" , pid, stderr) ;
106- }
107- }
108- Err ( e) => warn ! ( "taskkill failed for PID {}: {}" , pid, e) ,
109- }
110- }
111- }
112-
113- if killed_any {
114- // Allow a brief moment for the OS to release file handles
115- thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
116- }
117-
118- Ok ( ( ) )
119- }
120-
121-
12255pub fn handle_installation ( args : & Cli ) {
123- if let Err ( e) = kill_other_instances ( ) {
124- warn ! ( "Failed to terminate other instances automatically: {}" , e) ;
125- warn ! ( "Continuing with installation; this may fail if files are locked." ) ;
126- }
127-
12856 let mut install_path = None ;
12957 if let Some ( path_str) = & args. install_dir {
13058 info ! ( "Starting installation..." ) ;
@@ -156,7 +84,7 @@ pub fn handle_installation(args: &Cli) {
15684 } ,
15785 Err ( e) => {
15886 error ! ( "Failed to set up startup service: {:?}" , e) ;
159- println ! ( "\n \n \t Setup failed! Please try again.\n " ) ;
87+ println ! ( "\n \n \t • Setup failed! Please close all OS windows (including Task Manager, and Services) and try again.\n " ) ;
16088 exit_blocking ( 1 ) ;
16189 }
16290 }
@@ -165,7 +93,7 @@ pub fn handle_installation(args: &Cli) {
16593 if args. add_startup_task {
16694 let exe_path = resolve_exe_path ( install_path) ;
16795 let mut task_args = filtered_passthrough_args ( ) ;
168- // Always add -silent for scheduled task
96+ // Always add ` -silent` for scheduled tasks
16997 task_args. push ( OsString :: from ( "-silent" ) ) ;
17098
17199 match setup_startup_scheduled_task ( & exe_path, task_args) {
@@ -349,7 +277,7 @@ fn resolve_exe_path(install_path: Option<PathBuf>) -> PathBuf {
349277fn filtered_passthrough_args ( ) -> Vec < OsString > {
350278 // List of parameters to skip when passing through to the service/task (second arg is whether it takes a value)
351279 let skip = [
352- ( name_of ! ( install in Cli ) , false ) ,
280+ ( name_of ! ( install_tui in Cli ) , false ) ,
353281 ( name_of ! ( install_dir in Cli ) , true ) ,
354282 ( name_of ! ( add_startup_service in Cli ) , false ) ,
355283 ( name_of ! ( add_startup_task in Cli ) , false ) ,
@@ -399,7 +327,8 @@ fn remove_existing_service_if_any(manager: &ServiceManager, name: &str, wait_aft
399327 info ! ( "Service '{}' already exists. Trying to delete it." , name) ;
400328 let _ = service. stop ( ) ;
401329 if let Err ( e) = service. delete ( ) {
402- error ! ( "Failed to delete service '{}'. You might need to close Services and Task Manager windows and/or log out from or restart your computer to proceed" , name) ;
330+ error ! ( "Failed to delete service '{}'." , name) ;
331+ error ! ( "You might need to close Services and Task Manager windows and/or log out from or restart your computer to proceed" ) ;
403332 error ! ( "Error: {}" , e) ;
404333 exit_blocking ( 2 ) ;
405334 } else {
0 commit comments