Skip to content

Commit

Permalink
dont delete geode_pkg folder, fix cache archive extraction
Browse files Browse the repository at this point in the history
fixes #37
  • Loading branch information
matcool committed Jul 7, 2024
1 parent b4d3a41 commit 6c5df32
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ fn zip_folder(path: &Path, output: &Path) {

// Setup zip
let mut zip_file = ZipWriter::new(fs::File::create(output).unwrap());
let zip_options = FileOptions::<()>::default().compression_method(zip::CompressionMethod::Deflated);
let zip_options =
FileOptions::<()>::default().compression_method(zip::CompressionMethod::Deflated);

// Iterate files in target path
for item in walkdir::WalkDir::new(path) {
Expand Down Expand Up @@ -142,7 +143,8 @@ fn zip_folder(path: &Path, output: &Path) {

pub fn get_working_dir(id: &String) -> PathBuf {
let working_dir = dirs::cache_dir().unwrap().join("geode_pkg").join(id);
fs::remove_dir_all(&working_dir).unwrap_or(());
// why would u do that :(
// fs::remove_dir_all(&working_dir).unwrap_or(());
fs::create_dir_all(&working_dir).unwrap_or(());
working_dir
}
Expand Down
33 changes: 19 additions & 14 deletions src/util/bmfont.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ fn extract_from_cache(
working_dir: &Path,
cache_bundle: &mut CacheBundle,
shut_up: bool,
) {
) -> bool {
let path_name = path.to_str().unwrap();
if !shut_up {
info!("Extracting '{}' from cache", path_name);
}
cache_bundle.try_extract_cached_into(
return cache_bundle.try_extract_cached_into(
path_name,
&working_dir.join(path.file_name().unwrap().to_str().unwrap()),
);
Expand All @@ -344,21 +344,26 @@ pub fn get_font_bundles(
if let Some(cache_bundle) = cache {
// Cache found
if let Some(p) = cache_bundle.cache.fetch_font_bundles(font) {
if !shut_up {
info!("Using cached files");
}
let bundles = FontBundles::new(p.to_path_buf());

// Extract all files
extract_from_cache(&bundles.sd.png, working_dir, cache_bundle, shut_up);
extract_from_cache(&bundles.sd.fnt, working_dir, cache_bundle, shut_up);
extract_from_cache(&bundles.hd.png, working_dir, cache_bundle, shut_up);
extract_from_cache(&bundles.hd.fnt, working_dir, cache_bundle, shut_up);
extract_from_cache(&bundles.uhd.png, working_dir, cache_bundle, shut_up);
extract_from_cache(&bundles.uhd.fnt, working_dir, cache_bundle, shut_up);

done!("Fetched {} from cache", font.name.bright_yellow());
return bundles;
let success = extract_from_cache(&bundles.sd.png, working_dir, cache_bundle, shut_up)
&& extract_from_cache(&bundles.sd.fnt, working_dir, cache_bundle, shut_up)
&& extract_from_cache(&bundles.hd.png, working_dir, cache_bundle, shut_up)
&& extract_from_cache(&bundles.hd.fnt, working_dir, cache_bundle, shut_up)
&& extract_from_cache(&bundles.uhd.png, working_dir, cache_bundle, shut_up)
&& extract_from_cache(&bundles.uhd.fnt, working_dir, cache_bundle, shut_up);

if success {
if !shut_up {
info!("Using cached files");
}

done!("Fetched {} from cache", font.name.bright_yellow());
return bundles;
} else {
info!("Failed to extract cached files");
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/util/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ impl CacheBundle {
pub fn try_extract_cached_into(&mut self, name: &str, output: &PathBuf) -> bool {
match &mut self.src {
CacheBundleSource::Archive(archive) => {
let Ok(mut cached_file) = archive.by_name(name) else {
// zip doesn't really know what a folder is, so it just sees
// backslashes as a different filename. so ofc it breaks on windows
// and we have to do this
let name = name.replace('\\', "/");
let Ok(mut cached_file) = archive.by_name(&name) else {
return false;
};

Expand Down

0 comments on commit 6c5df32

Please sign in to comment.