Skip to content

Commit

Permalink
add support for tar extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Oct 31, 2023
1 parent f54b436 commit 20b5a77
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
13 changes: 7 additions & 6 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ thiserror = "1.0.48"
log = "0.4.20"
oauth2 = "4.4.2"
axum = "0.6.20"
tar = "0.4.40"

[features]
# by default Tauri runs in production mode
Expand Down
1 change: 0 additions & 1 deletion src-tauri/src/fide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ pub async fn download_fide_db(
0,
"http://ratings.fide.com/download/players_list_xml.zip".to_string(),
app_config_dir(&app.config()).unwrap(),
true,
app.clone(),
None,
Some(false),
Expand Down
9 changes: 6 additions & 3 deletions src-tauri/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub async fn download_file(
id: u64,
url: String,
path: PathBuf,
zip: bool,
app: tauri::AppHandle,
token: Option<String>,
finalize: Option<bool>,
Expand Down Expand Up @@ -71,11 +70,15 @@ pub async fn download_file(

info!("Downloaded file to {}", path.display());

if zip {
if url.ends_with(".zip") {
unzip_file(path, file).await?;
} else if url.ends_with(".tar") {
let mut archive = tar::Archive::new(Cursor::new(file));
archive.unpack(path)?;
} else {
std::fs::write(path, file)?;
std::fs::write(path, file)?
}

if finalize {
app.emit_all(
"download_progress",
Expand Down
1 change: 0 additions & 1 deletion src/components/databases/AddDatabase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ function DatabaseCard({
await invoke("download_file", {
id,
url,
zip: false,
path,
});
setDatabases(await getDatabases());
Expand Down
1 change: 0 additions & 1 deletion src/components/engines/AddEngine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ function EngineCard({
await invoke("download_file", {
id,
url,
zip: true,
path,
});
let appDataDirPath = await appDataDir();
Expand Down
1 change: 0 additions & 1 deletion src/components/puzzles/AddPuzzle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ function PuzzleDbCard({
await invoke("download_file", {
id,
url,
zip: false,
path,
});
setPuzzleDbs(await getPuzzleDatabases());
Expand Down
1 change: 0 additions & 1 deletion src/utils/lichess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ export async function downloadLichess(
await invoke("download_file", {
id: 1,
url,
zip: false,
path,
token,
});
Expand Down

0 comments on commit 20b5a77

Please sign in to comment.