Skip to content

Commit

Permalink
refactor: Migrate install related functions to GameInstall (#457)
Browse files Browse the repository at this point in the history
This allows for later extending for installing in the appropriate profile
  • Loading branch information
Jan200101 authored Jul 31, 2023
1 parent c73d486 commit 3563a0b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async fn verify_install_location(game_path: String) -> bool {
#[tauri::command]
async fn install_northstar_caller(
window: tauri::Window,
game_path: String,
game_install: GameInstall,
northstar_package_name: Option<String>,
version_number: Option<String>,
) -> Result<bool, String> {
Expand All @@ -315,7 +315,7 @@ async fn install_northstar_caller(

match northstar::install::install_northstar(
window,
&game_path,
game_install,
northstar_package_name,
version_number,
)
Expand All @@ -333,13 +333,13 @@ async fn install_northstar_caller(
#[tauri::command]
async fn update_northstar(
window: tauri::Window,
game_path: String,
game_install: GameInstall,
northstar_package_name: Option<String>,
) -> Result<bool, String> {
log::info!("Updating Northstar");

// Simply re-run install with up-to-date version for upate
install_northstar_caller(window, game_path, northstar_package_name, None).await
install_northstar_caller(window, game_install, northstar_package_name, None).await
}

/// Installs the specified mod
Expand Down
20 changes: 9 additions & 11 deletions src-tauri/src/northstar/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ struct InstallProgress {
async fn do_install(
window: tauri::Window,
nmod: &thermite::model::ModVersion,
game_path: &std::path::Path,
game_install: GameInstall,
) -> Result<()> {
let filename = format!("northstar-{}.zip", nmod.version);
let download_directory = format!("{}/___flightcore-temp-download-dir/", game_path.display());
let download_directory = format!(
"{}/___flightcore-temp-download-dir/",
game_install.game_path
);

log::info!(
"Attempting to create temporary directory {}",
Expand Down Expand Up @@ -91,7 +94,7 @@ async fn do_install(
.unwrap();

log::info!("Extracting Northstar...");
extract(nfile, game_path)?;
extract(nfile, std::path::Path::new(&game_install.game_path))?;

// Delete old copy
log::info!("Delete temp folder again");
Expand All @@ -114,7 +117,7 @@ async fn do_install(

pub async fn install_northstar(
window: tauri::Window,
game_path: &str,
game_install: GameInstall,
northstar_package_name: String,
version_number: Option<String>,
) -> Result<String, String> {
Expand All @@ -134,15 +137,10 @@ pub async fn install_northstar(
// Use passed version or latest if no version was passed
let version = version_number.as_ref().unwrap_or(&nmod.latest);

let game_path = game_install.game_path.clone();
log::info!("Install path \"{}\"", game_path);

match do_install(
window,
nmod.versions.get(version).unwrap(),
std::path::Path::new(game_path),
)
.await
{
match do_install(window, nmod.versions.get(version).unwrap(), game_install).await {
Ok(_) => (),
Err(err) => {
if game_path
Expand Down
4 changes: 2 additions & 2 deletions src-vue/src/plugins/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const store = createStore<FlightCoreStore>({
switch (state.northstar_state) {
// Install northstar if it wasn't detected.
case NorthstarState.INSTALL:
let install_northstar_result = invoke("install_northstar_caller", { gamePath: state.game_install.game_path, northstarPackageName: state.northstar_release_canal });
let install_northstar_result = invoke("install_northstar_caller", { gameInstall: state.game_install, northstarPackageName: state.northstar_release_canal });
state.northstar_state = NorthstarState.INSTALLING;

await install_northstar_result.then((message) => {
Expand All @@ -196,7 +196,7 @@ export const store = createStore<FlightCoreStore>({
// Update northstar if it is outdated.
case NorthstarState.MUST_UPDATE:
// Updating is the same as installing, simply overwrites the existing files
let reinstall_northstar_result = invoke("install_northstar_caller", { gamePath: state.game_install.game_path, northstarPackageName: state.northstar_release_canal });
let reinstall_northstar_result = invoke("install_northstar_caller", { gameInstall: state.game_install, northstarPackageName: state.northstar_release_canal });
state.northstar_state = NorthstarState.UPDATING;

await reinstall_northstar_result.then((message) => {
Expand Down
2 changes: 1 addition & 1 deletion src-vue/src/views/DeveloperView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export default defineComponent({
0
);
let install_northstar_result = invoke("install_northstar_caller", { gamePath: this.$store.state.game_install.game_path, northstarPackageName: this.selected_ns_version.value.package, versionNumber: this.selected_ns_version.value.version });
let install_northstar_result = invoke("install_northstar_caller", { gameInstall: this.$store.state.game_install, northstarPackageName: this.selected_ns_version.value.package, versionNumber: this.selected_ns_version.value.version });
await install_northstar_result
.then((message) => {
Expand Down
2 changes: 1 addition & 1 deletion src-vue/src/views/RepairView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default defineComponent({
0
);
let install_northstar_result = invoke("install_northstar_caller", { gamePath: this.$store.state.game_install.game_path, northstarPackageName: ReleaseCanal.RELEASE });
let install_northstar_result = invoke("install_northstar_caller", { gameInstall: this.$store.state.game_install, northstarPackageName: ReleaseCanal.RELEASE });
appWindow.listen<InstallProgress>(
'northstar-install-download-progress',
Expand Down

0 comments on commit 3563a0b

Please sign in to comment.