Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use temporary sourcemod directory when installing #26

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 21 additions & 2 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ impl RunnerContext
helper::join_path(self.sourcemod_path.clone(), crate::STAGING_DIR.to_string())
}

/// Get temporary location on the same drive as sourcemods.
/// {sourcemod_dir}{crate::TEMP_SOURCEMOD_DIR}
/// e.g; /home/kate/.var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps/sourcemods/.tmp-butler
/// C:\Games\Steam\steamapps\sourcemods\.tmp-butler
pub fn get_temp_sourcemod_location(&mut self) -> String {
helper::join_path(self.sourcemod_path.clone(), crate::TEMP_SOURCEMOD_DIR.to_string())
}

/// Get the latest item in `remote_version_list`
pub fn latest_remote_version(&mut self) -> (usize, RemoteVersion)
{
Expand Down Expand Up @@ -185,10 +193,21 @@ impl RunnerContext

/// Download package with Progress Bar.
/// Ok is the location to where it was downloaded to.
pub async fn download_package(version: RemoteVersion) -> Result<String, BeansError>
pub async fn download_package(&mut self, version: RemoteVersion) -> Result<String, BeansError>
{
let av = crate::appvar::parse();
let mut out_loc = helper::get_tmp_dir();
let mut out_loc = self.get_temp_sourcemod_location();

// Remove leftovers from partial installations
// We don't really care if this succeeds so we discard the result
let _ = std::fs::remove_dir_all(&out_loc);

if !helper::dir_exists(out_loc.clone()) {
if let Err(e) = std::fs::create_dir(&out_loc) {
trace!("[RunnerContext::download_package] {:#?}", e);
panic!("failed to make tmp directory at {} ({:})", out_loc, e);
}
}

if let Some(size) = version.pre_sz {
if helper::has_free_space(out_loc.clone(), size)? == false {
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ pub const STAGING_DIR: &str = "/butler-staging";
#[cfg(target_os = "windows")]
pub const STAGING_DIR: &str = "\\butler-staging";

#[cfg(not(target_os = "windows"))]
pub const TEMP_SOURCEMOD_DIR: &str = "/.tmp-butler";
#[cfg(target_os = "windows")]
pub const TEMP_SOURCEMOD_DIR: &str = "\\.tmp-butler";

#[cfg(target_os = "windows")]
flate!(pub static BUTLER_BINARY: [u8] from "Binaries/butler.exe");
#[cfg(not(target_os = "windows"))]
Expand Down
2 changes: 1 addition & 1 deletion src/workflows/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl InstallWorkflow {
}

println!("{:=>60}\nInstalling version {} to {}\n{0:=>60}", "=", version_id, &ctx.sourcemod_path);
let presz_loc = RunnerContext::download_package(version).await?;
let presz_loc = ctx.download_package(version).await?;
Self::install_from(presz_loc.clone(), ctx.sourcemod_path.clone(), Some(version_id)).await?;
if helper::file_exists(presz_loc.clone()) {
std::fs::remove_file(presz_loc)?;
Expand Down
Loading