-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rahul
committed
Aug 17, 2023
1 parent
00ba85c
commit b8f59b0
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
mod installer; | ||
|
||
use std::{ffi::OsStr, path::PathBuf}; | ||
|
||
use crate::core::{ | ||
buckets::{Buckets, Query}, | ||
config::*, | ||
download::*, | ||
}; | ||
|
||
use crate::utils::*; | ||
|
||
pub fn install(app: &str) { | ||
let query = app.trim().to_lowercase(); | ||
|
||
let (app_name, manifest) = match query.split_once('/') { | ||
Some((bucket, app_name)) => ( | ||
app_name, | ||
Buckets::query_app(app_name) | ||
.unwrap() | ||
.get_app_from(app_name, bucket), | ||
), | ||
None => (app, Buckets::query_app(app).unwrap().get_app(app)), | ||
}; | ||
|
||
let manifest = manifest.unwrap(); | ||
let file_name = Downloader::download(app_name, true).unwrap(); | ||
let cache_dir = Config::cache_dir().unwrap(); | ||
|
||
let srcs = file_name | ||
.iter() | ||
.map(|f| match f { | ||
DownloadStatus::Downloaded(s) => s, | ||
DownloadStatus::DownloadedAndVerified(s) => s, | ||
DownloadStatus::AlreadyInCache(s) => s, | ||
}) | ||
.map(|s| cache_dir.join(s)) | ||
.collect::<Vec<_>>(); | ||
|
||
let version = &manifest.version; | ||
|
||
let app_dir = Config::app_dir().unwrap(); | ||
let app_dir = app_dir.join(app_name); | ||
let app_dir = app_dir.join(version); | ||
|
||
if !app_dir.exists() { | ||
PathBuf::create(app_dir.clone()).unwrap(); | ||
use sevenz_rust::decompress_file; | ||
for src in srcs { | ||
if src | ||
.extension() | ||
.unwrap_or_default() | ||
.to_string_lossy() | ||
.to_string() | ||
== "7z" | ||
{ | ||
decompress_file(src, &app_dir).unwrap(); | ||
} | ||
} | ||
} | ||
|
||
println!("{app_name}\n{manifest:#?}\n{file_name:#?} at {app_dir:?}"); | ||
} |