Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src-tauri/src/development/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ pub async fn install_git_main(game_install_path: &str) -> Result<String, String>
};

let extract_directory = format!(
"{}/___flightcore-temp/download-dir/launcher-pr-{}",
game_install_path, latest_commit_sha
"{game_install_path}/___flightcore-temp/download-dir/launcher-pr-{latest_commit_sha}"
);
match std::fs::create_dir_all(extract_directory.clone()) {
Ok(_) => (),
Err(err) => {
return Err(format!(
"Failed creating temporary download directory: {}",
err
"Failed creating temporary download directory: {err}"
))
}
};
Expand All @@ -42,7 +40,7 @@ pub async fn install_git_main(game_install_path: &str) -> Result<String, String>
match zip_extract::extract(std::io::Cursor::new(archive), &target_dir, true) {
Ok(()) => (),
Err(err) => {
return Err(format!("Failed unzip: {}", err));
return Err(format!("Failed unzip: {err}"));
}
};

Expand All @@ -52,14 +50,13 @@ pub async fn install_git_main(game_install_path: &str) -> Result<String, String>
// - Northstar.dll
let files_to_copy = vec!["NorthstarLauncher.exe", "Northstar.dll"];
for file_name in files_to_copy {
let source_file_path = format!("{}/{}", extract_directory, file_name);
let destination_file_path = format!("{}/{}", game_install_path, file_name);
let source_file_path = format!("{extract_directory}/{file_name}");
let destination_file_path = format!("{game_install_path}/{file_name}");
match std::fs::copy(source_file_path, destination_file_path) {
Ok(_result) => (),
Err(err) => {
return Err(format!(
"Failed to copy necessary file {} from temp dir: {}",
file_name, err
"Failed to copy necessary file {file_name} from temp dir: {err}"
))
}
};
Expand All @@ -70,8 +67,7 @@ pub async fn install_git_main(game_install_path: &str) -> Result<String, String>
Ok(()) => (),
Err(err) => {
return Err(format!(
"Failed to delete temporary download directory: {}",
err
"Failed to delete temporary download directory: {err}"
))
}
}
Expand Down
16 changes: 8 additions & 8 deletions src-tauri/src/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn get_list_of_tags(project: Project) -> Result<Vec<TagWrapper>, String> {
};

// Fetch the list of tags for the repository as a `Vec<Tag>`.
let tags_url = format!("https://api.github.com/repos/{}/tags", repo_name);
let tags_url = format!("https://api.github.com/repos/{repo_name}/tags");
let tags: Vec<Tag> = client.get(tags_url).send().unwrap().json().unwrap();

// Map each `Tag` element to a `TagWrapper` element with the desired label and `Tag` value.
Expand Down Expand Up @@ -108,7 +108,7 @@ pub fn compare_tags_flightcore(first_tag: Tag, second_tag: Tag) -> Result<String
let mut full_patch_notes = "".to_string();

let mut patch_notes: Vec<String> = [].to_vec();
println!("{}", repo);
println!("{repo}");
// let repo = "R2Northstar/NorthstarLauncher";
let comparison_url = format!(
"https://api.github.com/repos/{}/compare/{}...{}",
Expand Down Expand Up @@ -170,10 +170,10 @@ fn generate_flightcore_release_notes(commits: Vec<String>) -> String {
_ => "**Other:**",
};

release_notes.push_str(&format!("{}\n", section_title));
release_notes.push_str(&format!("{section_title}\n"));

for commit_message in commit_list {
release_notes.push_str(&format!("- {}\n", commit_message));
release_notes.push_str(&format!("- {commit_message}\n"));
}

release_notes.push('\n');
Expand Down Expand Up @@ -235,10 +235,10 @@ pub fn compare_tags_northstar(first_tag: Tag, second_tag: Tag) -> Result<String,
let mut authors_set = std::collections::HashSet::new();

for repo in repos {
full_patch_notes += &format!("{}\n\n", repo);
full_patch_notes += &format!("{repo}\n\n");

let mut patch_notes: Vec<String> = [].to_vec();
println!("{}", repo);
println!("{repo}");
// let repo = "R2Northstar/NorthstarLauncher";
let comparison_url = format!(
"https://api.github.com/repos/{}/compare/{}...{}",
Expand Down Expand Up @@ -306,7 +306,7 @@ fn turn_pr_number_into_link(input: &str, repo: &str) -> String {
let re = Regex::new(r"#(\d+)").unwrap();

// Generate pull request link
let pull_link = format!("https://github.com/{}/pull/", repo);
re.replace_all(input, format!("[{}#$1]({}$1)", last_line, pull_link))
let pull_link = format!("https://github.com/{repo}/pull/");
re.replace_all(input, format!("[{last_line}#$1]({pull_link}$1)"))
.to_string()
}
31 changes: 13 additions & 18 deletions src-tauri/src/github/pull_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,12 @@ pub async fn get_launcher_download_link(commit_sha: String) -> Result<String, St
for i in 1..=10 {
// Crossreference with runs API
let runs_response: ActionsRunsResponse = match check_github_api(&format!(
"https://api.github.com/repos/R2Northstar/NorthstarLauncher/actions/runs?page={}",
i
"https://api.github.com/repos/R2Northstar/NorthstarLauncher/actions/runs?page={i}"
))
.await
{
Ok(result) => serde_json::from_value(result).unwrap(),
Err(err) => return Err(format!("{}", err)),
Err(err) => return Err(format!("{err}")),
};

// Cross-reference commit sha against workflow runs
Expand Down Expand Up @@ -236,20 +235,19 @@ pub async fn get_launcher_download_link(commit_sha: String) -> Result<String, St
}

Err(format!(
"Couldn't grab download link for \"{}\". Corresponding PR might be too old and therefore no CI build has been detected. Maybe ask author to update?",
commit_sha
"Couldn't grab download link for \"{commit_sha}\". Corresponding PR might be too old and therefore no CI build has been detected. Maybe ask author to update?"
))
}

/// Adds a batch file that allows for launching Northstar with mods PR profile
fn add_batch_file(game_install_path: &str) {
let batch_path = format!("{}/r2ns-launch-mod-pr-version.bat", game_install_path);
let batch_path = format!("{game_install_path}/r2ns-launch-mod-pr-version.bat");
let path = Path::new(&batch_path);
let display = path.display();

// Open a file in write-only mode, returns `io::Result<File>`
let mut file = match File::create(path) {
Err(why) => panic!("couldn't create {}: {}", display, why),
Err(why) => panic!("couldn't create {display}: {why}"),
Ok(file) => file,
};

Expand All @@ -258,7 +256,7 @@ fn add_batch_file(game_install_path: &str) {
"NorthstarLauncher.exe -profile=R2Northstar-PR-test-managed-folder\r\n";

match file.write_all(batch_file_content.as_bytes()) {
Err(why) => panic!("couldn't write to {}: {}", display, why),
Err(why) => panic!("couldn't write to {display}: {why}"),
Ok(_) => log::info!("successfully wrote to {}", display),
}
}
Expand Down Expand Up @@ -296,8 +294,7 @@ pub async fn apply_launcher_pr(
Ok(_) => (),
Err(err) => {
return Err(format!(
"Failed creating temporary download directory: {}",
err
"Failed creating temporary download directory: {err}"
))
}
};
Expand All @@ -306,7 +303,7 @@ pub async fn apply_launcher_pr(
match zip_extract::extract(io::Cursor::new(archive), &target_dir, true) {
Ok(()) => (),
Err(err) => {
return Err(format!("Failed unzip: {}", err));
return Err(format!("Failed unzip: {err}"));
}
};

Expand All @@ -316,14 +313,13 @@ pub async fn apply_launcher_pr(
// - Northstar.dll
let files_to_copy = vec!["NorthstarLauncher.exe", "Northstar.dll"];
for file_name in files_to_copy {
let source_file_path = format!("{}/{}", extract_directory, file_name);
let source_file_path = format!("{extract_directory}/{file_name}");
let destination_file_path = format!("{}/{}", game_install.game_path, file_name);
match std::fs::copy(source_file_path, destination_file_path) {
Ok(_result) => (),
Err(err) => {
return Err(format!(
"Failed to copy necessary file {} from temp dir: {}",
file_name, err
"Failed to copy necessary file {file_name} from temp dir: {err}"
))
}
};
Expand All @@ -334,8 +330,7 @@ pub async fn apply_launcher_pr(
Ok(()) => (),
Err(err) => {
return Err(format!(
"Failed to delete temporary download directory: {}",
err
"Failed to delete temporary download directory: {err}"
))
}
}
Expand Down Expand Up @@ -383,11 +378,11 @@ pub async fn apply_mods_pr(
Err(err) => return Err(err.to_string()),
}

let target_dir = std::path::PathBuf::from(format!("{}/mods", profile_folder)); // Doesn't need to exist
let target_dir = std::path::PathBuf::from(format!("{profile_folder}/mods")); // Doesn't need to exist
match zip_extract::extract(io::Cursor::new(archive), &target_dir, true) {
Ok(()) => (),
Err(err) => {
return Err(format!("Failed unzip: {}", err));
return Err(format!("Failed unzip: {err}"));
}
};
// Add batch file to launch right profile
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/mod_management/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct ModJson {

/// Parses `manifest.json` for Thunderstore mod string
fn parse_for_thunderstore_mod_string(nsmod_path: &str) -> Result<String, anyhow::Error> {
let manifest_json_path = format!("{}/manifest.json", nsmod_path);
let ts_author_txt_path = format!("{}/thunderstore_author.txt", nsmod_path);
let manifest_json_path = format!("{nsmod_path}/manifest.json");
let ts_author_txt_path = format!("{nsmod_path}/thunderstore_author.txt");

// Check if `manifest.json` exists and parse
let data = std::fs::read_to_string(manifest_json_path)?;
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn parse_installed_mods(
for directory in directories {
let directory_str = directory.to_str().unwrap().to_string();
// Check if mod.json exists
let mod_json_path = format!("{}/mod.json", directory_str);
let mod_json_path = format!("{directory_str}/mod.json");
if !std::path::Path::new(&mod_json_path).exists() {
continue;
}
Expand Down
14 changes: 6 additions & 8 deletions src-tauri/src/mod_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn get_enabled_mods(game_install: &GameInstall) -> Result<serde_json::value:
// Parse JSON
let res: serde_json::Value = match serde_json::from_str(&data) {
Ok(result) => result,
Err(err) => return Err(format!("Failed to read JSON due to: {}", err)),
Err(err) => return Err(format!("Failed to read JSON due to: {err}")),
};

// Return parsed data
Expand Down Expand Up @@ -255,7 +255,7 @@ pub fn parse_mods_in_package(
for directory in directories {
let directory_str = directory.to_str().unwrap().to_string();
// Check if mod.json exists
let mod_json_path = format!("{}/mod.json", directory_str);
let mod_json_path = format!("{directory_str}/mod.json");
if !std::path::Path::new(&mod_json_path).exists() {
continue;
}
Expand Down Expand Up @@ -613,8 +613,7 @@ pub async fn fc_download_mod_and_install(
for special_mod in MODS_WITH_SPECIAL_REQUIREMENTS {
if thunderstore_mod_string.contains(special_mod) {
return Err(format!(
"{} has special install requirements and cannot be installed with FlightCore",
thunderstore_mod_string
"{thunderstore_mod_string} has special install requirements and cannot be installed with FlightCore"
));
}
}
Expand Down Expand Up @@ -667,7 +666,7 @@ pub async fn fc_download_mod_and_install(
log::warn!("libthermite couldn't install mod {thunderstore_mod_string} due to {err:?}",);
return match err {
ThermiteError::SanityError(e) => Err(
format!("Mod failed sanity check during install. It's probably not correctly formatted. {}", e)
format!("Mod failed sanity check during install. It's probably not correctly formatted. {e}")
),
_ => Err(err.to_string()),
};
Expand Down Expand Up @@ -703,7 +702,7 @@ fn delete_mod_folder(ns_mod_directory: &str) -> Result<(), String> {
let mod_json_path = ns_mod_dir_path.join("mod.json");
if !mod_json_path.exists() {
// If it doesn't exist, return an error
return Err(format!("mod.json does not exist in {}", ns_mod_directory));
return Err(format!("mod.json does not exist in {ns_mod_directory}"));
}

match std::fs::remove_dir_all(ns_mod_directory) {
Expand Down Expand Up @@ -747,8 +746,7 @@ fn delete_package_folder(ts_package_directory: &str) -> Result<(), String> {
if !mod_json_path.exists() {
// If it doesn't exist, return an error
return Err(format!(
"manifest.json does not exist in {}",
ts_package_directory
"manifest.json does not exist in {ts_package_directory}"
));
}

Expand Down
18 changes: 8 additions & 10 deletions src-tauri/src/northstar/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ async fn do_install(
) -> Result<()> {
let filename = format!("northstar-{}.zip", nmod.version);
let temp_dir = format!("{}/___flightcore-temp", game_install.game_path);
let download_directory = format!("{}/download-dir", temp_dir);
let extract_directory = format!("{}/extract-dir", temp_dir);
let download_directory = format!("{temp_dir}/download-dir");
let extract_directory = format!("{temp_dir}/extract-dir");

log::info!("Attempting to create temporary directory {}", temp_dir);
std::fs::create_dir_all(download_directory.clone())?;
std::fs::create_dir_all(extract_directory.clone())?;

let download_path = format!("{}/{}", download_directory, filename);
let download_path = format!("{download_directory}/{filename}");
log::info!("Download path: {download_path}");

let last_emit = RefCell::new(Instant::now()); // Keep track of the last time a signal was emitted
Expand Down Expand Up @@ -146,15 +146,13 @@ async fn do_install(
// - rename the Profile

// Move DLL into the default R2Northstar Profile
let old_dll_path = format!("{}/{}", extract_directory, NORTHSTAR_DLL);
let new_dll_path = format!(
"{}/{}/{}",
extract_directory, NORTHSTAR_DEFAULT_PROFILE, NORTHSTAR_DLL
);
let old_dll_path = format!("{extract_directory}/{NORTHSTAR_DLL}");
let new_dll_path =
format!("{extract_directory}/{NORTHSTAR_DEFAULT_PROFILE}/{NORTHSTAR_DLL}");
std::fs::rename(old_dll_path, new_dll_path)?;

// rename default R2Northstar Profile to the profile we want to use
let old_profile_path = format!("{}/{}/", extract_directory, NORTHSTAR_DEFAULT_PROFILE);
let old_profile_path = format!("{extract_directory}/{NORTHSTAR_DEFAULT_PROFILE}/");
let new_profile_path = format!("{}/{}/", extract_directory, game_install.profile);
std::fs::rename(old_profile_path, new_profile_path)?;
}
Expand Down Expand Up @@ -188,7 +186,7 @@ async fn do_install(

// Safety check for mod.json
// Just so that we won't ever have a https://github.com/ValveSoftware/steam-for-linux/issues/3671 moment
let mod_json_path = format!("{}/mod.json", path_to_delete_string);
let mod_json_path = format!("{path_to_delete_string}/mod.json");
let mod_json_path = std::path::Path::new(&mod_json_path);

if !mod_json_path.exists() {
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/src/northstar/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn validate_profile(game_install: GameInstall, profile: String) -> bool {
pub fn delete_profile(game_install: GameInstall, profile: String) -> Result<(), String> {
// Check if the Profile actually exists
if !validate_profile(game_install.clone(), profile.clone()) {
return Err(format!("{} is not a valid Profile", profile));
return Err(format!("{profile} is not a valid Profile"));
}

log::info!("Deleting Profile {}", profile);
Expand All @@ -89,7 +89,7 @@ pub fn delete_profile(game_install: GameInstall, profile: String) -> Result<(),

match std::fs::remove_dir_all(profile_path) {
Ok(()) => Ok(()),
Err(err) => Err(format!("Failed to delete Profile: {}", err)),
Err(err) => Err(format!("Failed to delete Profile: {err}")),
}
}

Expand All @@ -102,12 +102,12 @@ pub fn clone_profile(
) -> Result<(), String> {
// Check if the old Profile already exists
if !validate_profile(game_install.clone(), old_profile.clone()) {
return Err(format!("{} is not a valid Profile", old_profile));
return Err(format!("{old_profile} is not a valid Profile"));
}

// Check that new Profile does not already exist
if validate_profile(game_install.clone(), new_profile.clone()) {
return Err(format!("{} already exists", new_profile));
return Err(format!("{new_profile} already exists"));
}

log::info!("Cloning Profile {} to {}", old_profile, new_profile);
Expand Down
Loading
Loading