Skip to content

Commit

Permalink
default to using same file name as provided appimage
Browse files Browse the repository at this point in the history
  • Loading branch information
QaidVoid committed Nov 14, 2024
1 parent 8d429d7 commit bcafa52
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
4 changes: 4 additions & 0 deletions squishy-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ squishy appimage path/to/app.AppImage --filter "squishy" --icon --desktop --apps
# Provide custom offset (it'd be calculated automatically if not provided)
# Appimage offset can be read using `path/to/app.AppImage --appimage-offset`
squishy appimage path/to/app.AppImage --offset 128128 --icon --desktop --appstream --write

# The default output file has same name as the provided file.
# Use --original-name to save as the same file name found inside SquashFS
squishy appimage path/to/app.AppImage --icon --write --original-name
```

### Command Options
Expand Down
34 changes: 26 additions & 8 deletions squishy-cli/src/appimage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
ffi::{OsStr, OsString},
fs::{self, File},
io::{Read, Seek, SeekFrom},
path::Path,
Expand Down Expand Up @@ -157,17 +158,34 @@ impl<'a> AppImage<'a> {
appstream
}

pub fn write<P: AsRef<Path>>(&self, file: P, output_dir: P) -> Result<()> {
pub fn write<P: AsRef<Path>>(
&self,
file: P,
output_dir: P,
output_name: Option<&OsStr>,
) -> Result<()> {
let file = file.as_ref();
let file_name = file.file_name().unwrap();
let file_name = output_name
.map(|output_name| {
let name_with_extension = file
.extension()
.map(|ext| {
format!(
"{}.{}",
output_name.to_string_lossy(),
ext.to_string_lossy()
)
})
.unwrap_or_else(|| file.file_name().unwrap().to_string_lossy().to_string());

OsString::from(name_with_extension)
})
.unwrap_or_else(|| file.file_name().unwrap().to_os_string());

fs::create_dir_all(&output_dir)?;
let output_path = output_dir.as_ref().join(file_name);
fs::create_dir_all(output_path.parent().unwrap())?;
self.squashfs.write_file(file, &output_path)?;
println!(
"Wrote {} to {}",
file_name.to_string_lossy(),
output_path.to_string_lossy()
);
println!("Wrote {} to {}", file.display(), output_path.display());
Ok(())
}
}
4 changes: 4 additions & 0 deletions squishy-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ pub enum Commands {
/// Whether to write files to disk
#[arg(required = false, long, short)]
write: Option<Option<PathBuf>>,

/// Whether to extract the file with the original name from the squashfs inside the AppImage
#[arg(required = false, long = "original-name")]
original_name: bool,
},
}
14 changes: 11 additions & 3 deletions squishy-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn main() {
desktop,
appstream,
write,
original_name,
} => {
if file.exists() {
let appimage = match AppImage::new(filter.as_deref(), &file, offset) {
Expand All @@ -37,10 +38,17 @@ fn main() {
None
};

let output_name = original_name
.then_some(None)
.or(Some(file.file_name()))
.unwrap();

if desktop {
if let Some(desktop) = appimage.find_desktop() {
if let Some(ref write_path) = write_path {
appimage.write(&desktop.path, write_path).unwrap();
appimage
.write(&desktop.path, write_path, output_name)
.unwrap();
} else {
println!("Desktop file: {}", desktop.path.display());
}
Expand All @@ -51,7 +59,7 @@ fn main() {
if icon {
if let Some(icon) = appimage.find_icon() {
if let Some(ref write_path) = write_path {
appimage.write(&icon.path, write_path).unwrap();
appimage.write(&icon.path, write_path, output_name).unwrap();
} else {
println!("Icon: {}", icon.path.display());
}
Expand All @@ -62,7 +70,7 @@ fn main() {
if appstream {
if let Some(icon) = appimage.find_appstream() {
if let Some(ref write_path) = write_path {
appimage.write(&icon.path, write_path).unwrap();
appimage.write(&icon.path, write_path, output_name).unwrap();
} else {
println!("Appstream file: {}", icon.path.display());
}
Expand Down

0 comments on commit bcafa52

Please sign in to comment.