mirror of
https://github.com/mmvanheusden/SteamDepotDownloaderGUI.git
synced 2026-02-04 05:31:19 +01:00
fix: use temp dir
This commit is contained in:
26
src-tauri/Cargo.lock
generated
26
src-tauri/Cargo.lock
generated
@@ -75,9 +75,9 @@ checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
|
||||
|
||||
[[package]]
|
||||
name = "arbitrary"
|
||||
version = "1.3.2"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110"
|
||||
checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223"
|
||||
dependencies = [
|
||||
"derive_arbitrary",
|
||||
]
|
||||
@@ -836,9 +836,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "derive_arbitrary"
|
||||
version = "1.3.2"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611"
|
||||
checksum = "30542c1ad912e0e3d22a1935c290e12e8a29d704a420177a31faad4a601a0800"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -3752,19 +3752,6 @@ dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha256"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18278f6a914fa3070aa316493f7d2ddfb9ac86ebc06fa3b83bffda487e9065b0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"bytes",
|
||||
"hex",
|
||||
"sha2",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shared_child"
|
||||
version = "1.0.1"
|
||||
@@ -4798,18 +4785,17 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "vectum"
|
||||
version = "3.0.0"
|
||||
version = "3.0.1"
|
||||
dependencies = [
|
||||
"async-process",
|
||||
"derive-getters",
|
||||
"fix-path-env",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha256",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tauri-plugin-dialog",
|
||||
"tauri-plugin-fs",
|
||||
"tauri-plugin-shell",
|
||||
"zip",
|
||||
]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "vectum"
|
||||
version = "3.0.0"
|
||||
version = "3.0.1"
|
||||
description = "Download older versions of Steam games with DepotDownloader"
|
||||
authors = ["mmvanheusden"]
|
||||
edition = "2021"
|
||||
@@ -19,10 +19,9 @@ tauri-plugin-dialog = "2.0.3"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
derive-getters = "0.5.0"
|
||||
sha256 = "1.5.0"
|
||||
reqwest = { version = "0.12.9",features = ["blocking"] }
|
||||
zip = "2.2.0"
|
||||
async-process = "2.3.0"
|
||||
tauri-plugin-fs = "2"
|
||||
|
||||
[profile.dev]
|
||||
incremental = true
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"shell:allow-open",
|
||||
"dialog:default",
|
||||
"shell:allow-execute",
|
||||
"shell:allow-spawn"
|
||||
"shell:allow-spawn",
|
||||
"fs:default"
|
||||
]
|
||||
}
|
||||
@@ -5,15 +5,10 @@ use std::{io::Write, path::Path};
|
||||
|
||||
use crate::get_os;
|
||||
use reqwest;
|
||||
use sha256;
|
||||
|
||||
pub static DEPOTDOWNLOADER_VERSION: &str = "2.7.4";
|
||||
|
||||
pub fn calc_checksum(path: &Path) -> io::Result<String> {
|
||||
let bytes = fs::read(path)?;
|
||||
let hash = sha256::digest(&bytes);
|
||||
Ok(hash)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
See: [`test_get_depotdownloader_url()`]
|
||||
@@ -35,6 +30,12 @@ pub async fn download_file(url: &str, filename: &Path) -> io::Result<()> {
|
||||
println!("DEBUG: Not downloading. File already exists.");
|
||||
return Err(io::Error::from(AlreadyExists));
|
||||
}
|
||||
// Create any missing directories.
|
||||
if let Some(p) = filename.parent() {
|
||||
if !p.exists() {
|
||||
fs::create_dir_all(p)?;
|
||||
}
|
||||
}
|
||||
|
||||
let mut file = File::create(filename)?;
|
||||
let response = reqwest::get(url)
|
||||
@@ -57,7 +58,7 @@ pub fn unzip(zip_file: &Path) -> io::Result<()> {
|
||||
|
||||
let outpath = match file.enclosed_name() {
|
||||
Some(path) => path,
|
||||
None => continue
|
||||
None => continue,
|
||||
};
|
||||
|
||||
println!("Extracted {} from archive.", outpath.display());
|
||||
@@ -70,7 +71,6 @@ pub fn unzip(zip_file: &Path) -> io::Result<()> {
|
||||
let mut outfile = File::create(&outpath)?;
|
||||
io::copy(&mut file, &mut outfile)?;
|
||||
|
||||
|
||||
// Copy over permissions from enclosed file to extracted file on UNIX systems.
|
||||
#[cfg(unix)]
|
||||
{
|
||||
|
||||
@@ -9,8 +9,12 @@ use std::time::Duration;
|
||||
|
||||
use crate::depotdownloader::{get_depotdownloader_url, DEPOTDOWNLOADER_VERSION};
|
||||
use crate::terminal::Terminal;
|
||||
use tauri_plugin_shell::{ShellExt};
|
||||
use tauri::{AppHandle, Emitter};
|
||||
use tauri::path::BaseDirectory;
|
||||
use tauri::App;
|
||||
use tauri::{AppHandle, Emitter, Manager};
|
||||
use tauri_plugin_fs::FsExt;
|
||||
use tauri_plugin_fs::FilePath;
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
|
||||
mod depotdownloader;
|
||||
mod steam;
|
||||
@@ -35,12 +39,15 @@ async fn preload_vectum(app: AppHandle) {
|
||||
Terminal::pretty_name(&TERMINAL.get().unwrap()[0]),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// set working directory
|
||||
std::env::set_current_dir(app.path().app_cache_dir().unwrap()).unwrap();
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn start_download(steam_download: steam::SteamDownload, app: AppHandle) {
|
||||
let default_terminal = TERMINAL.get().unwrap();
|
||||
let working_dir = env::current_dir().unwrap();
|
||||
let working_dir = app.path().app_cache_dir().unwrap();
|
||||
let shell = app.shell();
|
||||
|
||||
|
||||
@@ -55,26 +62,30 @@ async fn start_download(steam_download: steam::SteamDownload, app: AppHandle) {
|
||||
println!("\t- Manifest ID: {}", steam_download.manifest_id());
|
||||
println!("\t- Output Path: {}", steam_download.output_path());
|
||||
println!("\t- Default terminal: {}", Terminal::pretty_name(&default_terminal[0]));
|
||||
println!("\t- Terminal command: {:?}", terminal_to_use.create_command(&steam_download, shell));
|
||||
println!("\t- Working directory: {}", working_dir.display());
|
||||
println!("\t- Terminal command: {:?}", terminal_to_use.create_command(&steam_download, shell, working_dir.clone()));
|
||||
println!("\t- Working directory: {}", working_dir.clone() .display());
|
||||
// println!("\t- Working directory2: {}", std::env::current_exe().unwrap().display());
|
||||
// println!("\t- Working directory2: {}", app.path().app_cache_dir().unwrap().display());
|
||||
|
||||
|
||||
println!("----------------------------------------------------------\n");
|
||||
|
||||
|
||||
terminal_to_use.create_command(&steam_download, shell).spawn().ok();
|
||||
terminal_to_use.create_command(&steam_download, shell, working_dir).spawn().ok();
|
||||
}
|
||||
|
||||
/// Downloads the DepotDownloader zip file from the internet based on the OS.
|
||||
#[tauri::command]
|
||||
async fn download_depotdownloader() {
|
||||
async fn download_depotdownloader(app: AppHandle) {
|
||||
let url = get_depotdownloader_url();
|
||||
|
||||
// Where we store the DepotDownloader zip.
|
||||
let zip_filename = format!("DepotDownloader-v{}-{}.zip", DEPOTDOWNLOADER_VERSION, env::consts::OS);
|
||||
let depotdownloader_zip = Path::new(&zip_filename);
|
||||
let depotdownloader_zip = Path::join(app.path().app_cache_dir().unwrap().as_path(), Path::new(&zip_filename));
|
||||
|
||||
println!("Downloading DepotDownloader for {} to {}/{}", env::consts::OS, env::current_dir().unwrap().display(), depotdownloader_zip.display());
|
||||
println!("Downloading DepotDownloader for {} to {}", env::consts::OS, depotdownloader_zip.display());
|
||||
|
||||
match depotdownloader::download_file(url.as_str(), depotdownloader_zip).await {
|
||||
match depotdownloader::download_file(url.as_str(), depotdownloader_zip.as_path()).await {
|
||||
Err(e) => {
|
||||
if e.kind() == io::ErrorKind::AlreadyExists {
|
||||
println!("DepotDownloader already exists. Skipping download.");
|
||||
@@ -83,13 +94,13 @@ async fn download_depotdownloader() {
|
||||
|
||||
println!("Failed to download DepotDownloader: {}", e);
|
||||
return;
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
println!("Succesfully downloaded DepotDownloader from {}", url);
|
||||
|
||||
depotdownloader::unzip(depotdownloader_zip).unwrap();
|
||||
depotdownloader::unzip(depotdownloader_zip.as_path()).unwrap();
|
||||
println!("Succesfully extracted DepotDownloader zip.");
|
||||
}
|
||||
|
||||
@@ -126,19 +137,20 @@ fn main() {
|
||||
// macOS: change dir to documents because upon opening, our current dir by default is "/".
|
||||
if get_os() == "macos" {
|
||||
let _ = fix_path_env::fix(); // todo: does this actually do something useful
|
||||
let documents_dir = format!(
|
||||
"{}/Documents/SteamDepotDownloaderGUI",
|
||||
std::env::var_os("HOME").unwrap().to_str().unwrap()
|
||||
);
|
||||
let documents_dir = Path::new(&documents_dir);
|
||||
// println!("{}", documents_dir.display());
|
||||
// let documents_dir = format!(
|
||||
// "{}/Documents/SteamDepotDownloaderGUI",
|
||||
// std::env::var_os("HOME").unwrap().to_str().unwrap()
|
||||
// );
|
||||
// let documents_dir = Path::new(&documents_dir);
|
||||
// // println!("{}", documents_dir.display());
|
||||
|
||||
std::fs::create_dir_all(documents_dir).unwrap();
|
||||
env::set_current_dir(documents_dir).unwrap();
|
||||
// std::fs::create_dir_all(documents_dir).unwrap();
|
||||
// env::set_current_dir(documents_dir).unwrap();
|
||||
}
|
||||
|
||||
println!();
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use serde::Serialize;
|
||||
use tauri_plugin_shell::process::Command;
|
||||
use std::{env, fs};
|
||||
use std::path::{Path, PathBuf};
|
||||
use tauri::Wry;
|
||||
use tauri_plugin_shell::Shell;
|
||||
use crate::get_os;
|
||||
@@ -125,7 +126,7 @@ impl Terminal {
|
||||
| Terminal (macOS) | We create a bash script and run that using `open`. |
|
||||
|
||||
*/
|
||||
pub fn create_command(&self, steam_download: &SteamDownload, shell: &Shell<Wry>) -> Command {
|
||||
pub fn create_command(&self, steam_download: &SteamDownload, shell: &Shell<Wry>, working_dir: PathBuf) -> Command {
|
||||
let command = create_depotdownloader_command(steam_download);
|
||||
|
||||
match self {
|
||||
@@ -141,72 +142,72 @@ impl Terminal {
|
||||
shell.command("gnome-terminal")
|
||||
.args(&["--", "/usr/bin/env", "sh", "-c"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
Terminal::GNOMEConsole => {
|
||||
shell.command("kgx")
|
||||
.args(&["-e", "/usr/bin/env", "sh", "-c"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
Terminal::Konsole => {
|
||||
shell.command("konsole")
|
||||
.args(&["-e", "/usr/bin/env", "sh", "-c"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
Terminal::Xfce4Terminal => {
|
||||
shell.command("xfce4-terminal")
|
||||
.args(&["-x", "/usr/bin/env", "sh", "-c"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
Terminal::Terminator => {
|
||||
shell.command("terminator")
|
||||
.args(&["-T", "Downloading depot...", "-e"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
Terminal::XTerm => {
|
||||
shell.command("xterm")
|
||||
.args(&["-hold", "-T", "Downloading depot...", "-e", "/usr/bin/env", "sh", "-c"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
Terminal::Kitty => {
|
||||
shell.command("kitty")
|
||||
.args(&["/usr/bin/env", "sh", "-c"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
Terminal::LXTerminal => {
|
||||
shell.command("lxterminal")
|
||||
.args(&["-e", "/usr/bin/env", "sh", "-c"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
Terminal::Tilix => {
|
||||
shell.command("tilix")
|
||||
.args(&["-e", "/usr/bin/env", "sh", "-c"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
Terminal::DeepinTerminal => {
|
||||
shell.command("deepin-terminal")
|
||||
.args(&["-e", "/usr/bin/env", "sh", "-c"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
|
||||
Terminal::Alacritty => {
|
||||
shell.command("alacritty")
|
||||
.args(&["-e", "/usr/bin/env", "sh", "-c"])
|
||||
.args(command)
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
}
|
||||
Terminal::Terminal => {
|
||||
// Create a bash script and run that. Not very secure but it makes this easier.
|
||||
let download_script = format!("#!/bin/bash\ncd {}\n{}",env::current_dir().unwrap().display(), command[0]);
|
||||
let download_script = format!("#!/bin/bash\ncd {}\n{}",working_dir.as_path().display(), command[0]);
|
||||
// println!("{}", download_script);
|
||||
|
||||
fs::write("./script.sh", download_script).unwrap();
|
||||
@@ -220,7 +221,7 @@ impl Terminal {
|
||||
|
||||
shell.command("/usr/bin/open")
|
||||
.args(&["-a", "Terminal", "./script.sh"])
|
||||
.current_dir(env::current_dir().unwrap())
|
||||
.current_dir(working_dir.as_path())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"productName": "SteamDepotDownloaderGUI",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.1",
|
||||
"identifier": "net.oopium.depotdownloader",
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
|
||||
Reference in New Issue
Block a user