Skip to content

Commit

Permalink
Pause installer instead of exiting when panic handler finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
drojf committed Sep 19, 2021
1 parent 201db37 commit 6461a12
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
17 changes: 3 additions & 14 deletions install_loader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,17 @@ Please check the installer not already running, and folder [{}] is writeable"#,
};

if no_launcher_gui {
return panic_handler::fallback_installer();
}
else if register_job_result.is_ok() {
return panic_handler::fallback_installer_pause();
} else if register_job_result.is_ok() {
// This function blocks forever until the user quits the graphical installer
ui::ui_loop();
} else {
windows_utilities::show_console_window();

// If job object not registered properly, use fallback/console installer
// This ensures that everything is cleaned up properly as windows will automatically
// clean up child processes when the console window is closed.
println!("Warning: Failed to register job object! You're probably using Windows 7!");
println!("Don't worry - you can use the terminal based installer below");
if let Err(error) = panic_handler::fallback_installer() {
println!("Fallback Installer has failed with: {:?}", error);
println!(
"Please help us by reporting the error and submitting the crash log
- on our Discord server: https://discord.gg/pf5VhF9
- or, as a Github issue: https://github.com/07th-mod/python-patcher/issues"
);
panic_handler::pause("Press ENTER to quit the installer");
}
return panic_handler::fallback_installer_pause();
}

Ok(())
Expand Down
50 changes: 45 additions & 5 deletions install_loader/src/panic_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,25 @@ Please help us by reporting the error and submitting the crash log
expl
}

pub fn fallback_installer() -> Result<(), Box<dyn Error>> {
pub fn fallback_installer_pause() -> Result<(), Box<dyn Error>> {
windows_utilities::show_console_window();

if let Err(error) = fallback_installer() {
println!("Fallback Installer has failed with: {:?}", error);
println!(
"
Please help us by taking a screenshot of the error and uploading it:
- on our Discord server: https://discord.gg/pf5VhF9
- or, as a Github issue: https://github.com/07th-mod/python-patcher/issues"
);
pause("Press ENTER to quit the installer");
return Err(error);
}

Ok(())
}

fn fallback_installer() -> Result<(), Box<dyn Error>> {
eprintln!("\n------------- NOTE: 'Fallback Mode' is available ----------");

// Check if the installer is being run from a temporary folder
Expand Down Expand Up @@ -187,7 +205,31 @@ Please make sure it's installed.

println!("Extraction Complete - Please wait while installer starts in your browser...");

python_launcher::launch_python_script(&config, graphical)?.wait()
let launch_result = python_launcher::launch_python_script(&config, graphical);

let mut process_runner = match launch_result {
Ok(process_runner) => process_runner,
Err(error) => {
println!(
r#"
Error starting python process: {}
Please check if any antivirus software or permission issues are stopping the installer from running."#,
error
);
return Err(error);
}
};

match process_runner.wait() {
Ok(res) => res,
Err(error) => {
println!("\nPython process exited with error: {}", error);
return Err(error);
}
}

Ok(())
}

/// When called, changes the default panic handler to print useful information to the end user and
Expand Down Expand Up @@ -219,10 +261,8 @@ pub fn set_hook(log_filename: String) {
eprintln!("Error: Crash log could not be written!");
}

if let Err(error) = fallback_installer() {
if let Err(error) = fallback_installer_pause() {
println!("Fallback Installer Error: {}", error);
};

pause("\nInstaller finished. Press any key to exit.");
}));
}

0 comments on commit 6461a12

Please sign in to comment.