Skip to content

Commit

Permalink
v0.4.0: patching should now work
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanHelianthicusDoe committed Sep 19, 2019
1 parent 07d5b4b commit e86dc65
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shticker_book_unwritten"
version = "0.3.1"
version = "0.4.0"
authors = ["Dr. Jonathan Helianthicus Doe, IV <[email protected]>"]
edition = "2018"
description = "Minimal CLI launcher for the Toontown Rewritten MMORPG"
Expand Down
2 changes: 1 addition & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn enter_command_mode<'a, P: AsRef<Path>, U: Iterator<Item = &'a str>>(
.split(char::is_whitespace)
.filter(|arg| !arg.is_empty());
match argv.next() {
None => (),
None => check_children(quiet, &mut children)?,
Some("help") | Some("?") => {
help();
check_children(quiet, &mut children)?;
Expand Down
4 changes: 3 additions & 1 deletion src/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ fn apply_patch<P: AsRef<Path>, Q: AsRef<Path>>(
// Add old data to diff string
for i in 0..ctrl[0] {
if (oldpos + i >= 0) && (oldpos + i < oldsize) {
new[(newpos + i) as usize] += old[(oldpos + i) as usize];
let new_index = (newpos + i) as usize;
let old_index = (oldpos + i) as usize;
new[new_index] = new[new_index].wrapping_add(old[old_index]);
}
}

Expand Down
21 changes: 8 additions & 13 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
fs::{self, File},
io::{self, prelude::*},
os::unix::fs::PermissionsExt,
path::Path,
path::{Path, PathBuf},
};

pub const BUFFER_SIZE: usize = 0x20_00;
Expand Down Expand Up @@ -316,7 +316,7 @@ fn update_existing_file<S: AsRef<str>, P: AsRef<Path>>(
String::with_capacity(patch_file_name.len() + ".extracted".len());
extracted_patch_file_name += patch_file_name;
extracted_patch_file_name += ".extracted";
download_file(
let extracted_patch_path = download_file(
true,
&mut file_buf,
config,
Expand Down Expand Up @@ -357,7 +357,7 @@ fn update_existing_file<S: AsRef<str>, P: AsRef<Path>>(
println!(" Applying patch...");
}

patch::patch_file(&extracted_patch_file_name, full_file_path)?;
patch::patch_file(&extracted_patch_path, full_file_path)?;

if !quiet {
println!(" File patched successfully!");
Expand Down Expand Up @@ -489,7 +489,8 @@ fn sha_from_hash_str<S: AsRef<str>>(hash_str: S) -> Result<[u8; 20], Error> {
}

/// Downloads to the cache if `to_cache`, otherwise downloads to the main
/// installation directory.
/// installation directory. Returns the full path to the downloaded file on
/// success.
#[allow(clippy::too_many_arguments)]
fn download_file<S: AsRef<str>, T: AsRef<str>>(
to_cache: bool,
Expand All @@ -502,7 +503,7 @@ fn download_file<S: AsRef<str>, T: AsRef<str>>(
compressed_sha: &[u8; 20],
decompressed_sha: &[u8; 20],
max_tries: usize,
) -> Result<(), Error> {
) -> Result<PathBuf, Error> {
let mut dl_uri = String::with_capacity(
config.cdn_uri.len() + compressed_file_name.as_ref().len(),
);
Expand Down Expand Up @@ -623,13 +624,7 @@ fn download_file<S: AsRef<str>, T: AsRef<str>>(
println!(" Deleting compressed version...");
}

let mut loc = if to_cache {
config.cache_dir.clone()
} else {
config.install_dir.clone()
};
loc.push(compressed_file_name.as_ref());
fs::remove_file(&loc).map_err(Error::RemoveFileError)?;
fs::remove_file(&compressed_file_path).map_err(Error::RemoveFileError)?;

if !quiet {
println!(
Expand All @@ -638,7 +633,7 @@ fn download_file<S: AsRef<str>, T: AsRef<str>>(
);
}

Ok(())
Ok(decompressed_file_path)
}

fn decompress_file<P: AsRef<Path>>(
Expand Down

0 comments on commit e86dc65

Please sign in to comment.