fix: use temp dir

This commit is contained in:
Maarten van Heusden
2024-11-17 20:59:48 +01:00
parent a8cd68fce6
commit bbdf0955db
11 changed files with 105 additions and 73 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "vectum",
"private": true,
"version": "3.0.0",
"version": "3.0.1",
"type": "module",
"license": "GPL-3.0-only",
"scripts": {
@@ -13,6 +13,7 @@
"dependencies": {
"@tauri-apps/api": "2.1.1",
"@tauri-apps/plugin-dialog": "2.0.1",
"@tauri-apps/plugin-fs": "~2",
"@tauri-apps/plugin-shell": "2.0.1",
"jquery": "^3.7.1"
},

10
pnpm-lock.yaml generated
View File

@@ -14,6 +14,9 @@ importers:
'@tauri-apps/plugin-dialog':
specifier: 2.0.1
version: 2.0.1
'@tauri-apps/plugin-fs':
specifier: ~2
version: 2.0.2
'@tauri-apps/plugin-shell':
specifier: 2.0.1
version: 2.0.1
@@ -413,6 +416,9 @@ packages:
'@tauri-apps/plugin-dialog@2.0.1':
resolution: {integrity: sha512-fnUrNr6EfvTqdls/ufusU7h6UbNFzLKvHk/zTuOiBq01R3dTODqwctZlzakdbfSp/7pNwTKvgKTAgl/NAP/Z0Q==}
'@tauri-apps/plugin-fs@2.0.2':
resolution: {integrity: sha512-4YZaX2j7ta81M5/DL8aN10kTnpUkEpkPo1FTYPT8Dd0ImHe3azM8i8MrtjrDGoyBYLPO3zFv7df/mSCYF8oA0Q==}
'@tauri-apps/plugin-shell@2.0.1':
resolution: {integrity: sha512-akU1b77sw3qHiynrK0s930y8zKmcdrSD60htjH+mFZqv5WaakZA/XxHR3/sF1nNv9Mgmt/Shls37HwnOr00aSw==}
@@ -1154,6 +1160,10 @@ snapshots:
dependencies:
'@tauri-apps/api': 2.1.1
'@tauri-apps/plugin-fs@2.0.2':
dependencies:
'@tauri-apps/api': 2.1.1
'@tauri-apps/plugin-shell@2.0.1':
dependencies:
'@tauri-apps/api': 2.1.1

26
src-tauri/Cargo.lock generated
View File

@@ -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",
]

View File

@@ -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

View File

@@ -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"
]
}

View File

@@ -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)]
{

View File

@@ -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![

View File

@@ -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())
}
}

View File

@@ -1,6 +1,6 @@
{
"productName": "SteamDepotDownloaderGUI",
"version": "3.0.0",
"version": "3.0.1",
"identifier": "net.oopium.depotdownloader",
"build": {
"beforeDevCommand": "pnpm dev",

View File

@@ -174,6 +174,18 @@
</div>
</div>
<div hidden id="nopathwarning">
<div class="flash flash-warn mx-2 mt-2 color-shadow-medium" id="emptyalert">
<svg class="octicon" height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
<path
d="M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM0 8a8 8 0 1116 0A8 8 0 010 8zm6.5-.25A.75.75 0 017.25 7h1a.75.75 0 01.75.75v2.75h.25a.75.75 0 010 1.5h-2a.75.75 0 010-1.5h.25v-2h-.25a.75.75 0 01-.75-.75zM8 6a1 1 0 100-2 1 1 0 000 2z"
fill-rule="evenodd"></path>
</svg>
Please choose a download location.
</div>
</div>
<div class="flash mx-2 mt-2 color-shadow-medium" hidden id="downloadingnotice">
<svg class="octicon" height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
<path

View File

@@ -77,7 +77,7 @@ $(async () => {
$("#pickpath").on("click", async () => {
// Open a dialog
downloadDirectory = await openDialog({
title: "Choose where to download the game. You can specify the directory later.",
title: "Choose where to save the game download.",
multiple: false,
directory: true,
canCreateDirectories: true
@@ -92,6 +92,9 @@ $(async () => {
$("#checkpath").prop("ariaDisabled", false);
$("#checkpath").prop("disabled", false);
$("#downloadbtn").prop("ariaDisabled", false);
$("#nopathwarning").prop("hidden", true);
console.log(downloadDirectory);
});
@@ -113,9 +116,15 @@ $(async () => {
// Loop through invalid fields. If there are any, make those "errored" and block the download button.
for (const id of invalidFields()) {
document.getElementById(id)?.parentElement?.classList.toggle("errored", true);
$("#emptywarning").prop("hidden", false);
$("#downloadbtn").prop("ariaDisabled", true);
}
$("#emptywarning").prop("hidden", false);
$("#downloadbtn").prop("ariaDisabled", true);
return;
}
if (downloadDirectory == null) {
$("#nopathwarning").prop("hidden", false);
$("#downloadbtn").prop("ariaDisabled", true);
return;
}
@@ -126,7 +135,6 @@ $(async () => {
const terminalChoice = (document.getElementById("terminal-dropdown") as HTMLSelectElement).selectedIndex;
const directoryNameChoice = $("#folder-name-custom-input").val();
// Output path w/ directories chosen is: {downloadDirectory}/{directoryNameChoice}
const vectumOptions = {
terminal: terminalChoice == 13 ? null : terminalChoice,