Skip to content

Commit

Permalink
feat(install): implement local package install
Browse files Browse the repository at this point in the history
  • Loading branch information
QaidVoid committed Nov 5, 2024
1 parent e17258e commit 457f117
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 177 deletions.
11 changes: 6 additions & 5 deletions src/core/file.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use std::{
fs::File,
io::{BufReader, Read},
};
use std::io::{BufReader, Read};

use super::constant::{APPIMAGE_MAGIC_BYTES, ELF_MAGIC_BYTES, FLATIMAGE_MAGIC_BYTES};

#[derive(PartialEq, Eq)]
pub enum FileType {
AppImage,
FlatImage,
ELF,
Unknown,
}

pub fn get_file_type(file: &mut BufReader<File>) -> FileType {
pub fn get_file_type<T>(file: &mut BufReader<T>) -> FileType
where
T: std::io::Read,
{
let mut magic_bytes = [0u8; 12];
if file.read_exact(&mut magic_bytes).is_ok() {
if magic_bytes[8..] == APPIMAGE_MAGIC_BYTES {
Expand Down
36 changes: 32 additions & 4 deletions src/core/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{
env, mem,
env,
io::Write,
mem,
path::{Path, PathBuf},
};

Expand All @@ -13,6 +15,8 @@ use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
};

use crate::warn;

use super::{
color::{Color, ColorExt},
constant::{BIN_PATH, CACHE_PATH, INSTALL_TRACK_PATH, PACKAGES_PATH, REGISTRY_PATH},
Expand Down Expand Up @@ -88,9 +92,12 @@ pub fn parse_size(size_str: &str) -> Option<u64> {
let size_str = size_str.trim();
let units = [
("B", 1u64),
("KB", 1024u64),
("MB", 1024u64 * 1024),
("GB", 1024u64 * 1024 * 1024),
("KB", 1000u64),
("MB", 1000u64 * 1000),
("GB", 1000u64 * 1000 * 1000),
("KiB", 1024u64),
("MiB", 1024u64 * 1024),
("GiB", 1024u64 * 1024 * 1024),
];

for (unit, multiplier) in &units {
Expand Down Expand Up @@ -348,3 +355,24 @@ pub fn download_progress_style(with_msg: bool) -> ProgressStyle {
)
.progress_chars("━━")
}

#[derive(PartialEq, Eq)]
pub enum AskType {
Warn,
Normal,
}

pub fn interactive_ask(ques: &str, ask_type: AskType) -> Result<String> {
if ask_type == AskType::Warn {
warn!("{ques}");
} else {
println!("{ques}");
}

std::io::stdout().flush()?;

let mut response = String::new();
std::io::stdin().read_line(&mut response)?;

Ok(response.trim().to_owned())
}
14 changes: 7 additions & 7 deletions src/package/appimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ pub async fn integrate_appimage(
match resolve_and_extract(&squashfs, node, &output_path, &mut HashSet::new()) {
Ok(()) => {
if extension == "png" {
process_icon(&output_path, &package.bin_name, data_path).await?;
process_icon(&output_path, &package.pkg_name, data_path).await?;
} else {
process_desktop(&output_path, &package.bin_name, &package.name, data_path)
process_desktop(&output_path, &package.pkg_name, &package.pkg, data_path)
.await?;
}
}
Expand Down Expand Up @@ -315,20 +315,20 @@ pub async fn integrate_using_remote_files(package: &Package, file_path: &Path) -
let desktop_content = match desktop_content {
Some(content) => content,
None => create_default_desktop_entry(
&package.bin_name,
&package.name,
&package.pkg_name,
&package.pkg,
&package.category.replace(',', ";"),
),
};

fs::write(&desktop_output_path, &desktop_content).await?;

try_join!(
process_icon(&icon_output_path, &package.bin_name, data_path),
process_icon(&icon_output_path, &package.pkg_name, data_path),
process_desktop(
&desktop_output_path,
&package.bin_name,
&package.name,
&package.pkg_name,
&package.pkg,
data_path
)
)?;
Expand Down
Loading

0 comments on commit 457f117

Please sign in to comment.