initial commit

This commit is contained in:
DecDuck
2024-10-06 01:10:57 +10:00
commit f6cd7c3d1f
42 changed files with 5528 additions and 0 deletions

7
src-tauri/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas

4338
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

27
src-tauri/Cargo.toml Normal file
View File

@ -0,0 +1,27 @@
[package]
name = "drop-app"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "drop_app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2.0.0", features = [] }
[dependencies]
tauri = { version = "2.0.0", features = [] }
tauri-plugin-shell = "2.0.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
ciborium = "0.2.2"
xz2 = "0.1.7"
rayon = "1.10.0"

3
src-tauri/build.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

View File

@ -0,0 +1,10 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"shell:allow-open"
]
}

BIN
src-tauri/icons/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
src-tauri/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
src-tauri/icons/icon.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
src-tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

24
src-tauri/src/lib.rs Normal file
View File

@ -0,0 +1,24 @@
mod unpacker;
use tauri::Runtime;
use unpacker::unpack;
#[tauri::command]
async fn unpack_debug<R: Runtime>(
app: tauri::AppHandle<R>,
window: tauri::Window<R>,
) -> Result<String, String> {
unpack().unwrap();
return Ok("Successful".to_string());
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![unpack_debug])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

6
src-tauri/src/main.rs Normal file
View File

@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
drop_app_lib::run()
}

93
src-tauri/src/unpacker.rs Normal file
View File

@ -0,0 +1,93 @@
use ciborium::from_reader;
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use serde::Deserialize;
use std::{
collections::HashMap,
fs::{create_dir_all, File},
io::{self, BufReader, Error, Seek},
os::unix::fs::PermissionsExt,
path::Path,
};
use tauri::Runtime;
use xz2::bufread::XzDecoder;
#[derive(Deserialize)]
struct ManifestChunk {
uuid: String,
index: i64,
}
#[derive(Deserialize)]
struct ManifestRecord {
chunks: Vec<ManifestChunk>,
permissions: Vec<bool>,
}
#[derive(Deserialize)]
struct Manifest {
record: HashMap<String, ManifestRecord>,
}
fn generate_permissions(permissions: Vec<bool>) -> u32 {
// Base 8
let mut perms: u32 = 0;
// Read
if permissions[0] {
perms += 4;
}
// Write
if permissions[1] {
perms += 2;
}
// Execute
if permissions[2] {
perms += 1;
}
perms *= 8 * 8;
perms += 4 * 8 + 4;
return perms;
}
pub fn unpack() -> Result<(), Error> {
let chunk_size: u64 = 1024 * 1024 * 16;
let input = Path::new("/home/decduck/Dev/droplet-output");
let output = Path::new("/home/decduck/Dev/droplet-rebuilt");
let manifest_path = input.join("manifest.drop");
let manifest_file_handle = File::open(manifest_path).unwrap();
let manifest: Manifest = from_reader(manifest_file_handle).unwrap();
manifest.record.into_par_iter().for_each(|(key, value)| {
let file = output.join(key.clone());
create_dir_all(file.parent().unwrap()).unwrap();
let mut file_handle = File::create(file).unwrap();
#[cfg(unix)]
{
let mut file_permissions = file_handle.metadata().unwrap().permissions();
file_permissions.set_mode(generate_permissions(value.permissions));
file_handle.set_permissions(file_permissions).unwrap();
}
for chunk in value.chunks {
let chunk_path = input.join(chunk.uuid + ".bin");
let chunk_handle = File::open(chunk_path).unwrap();
let chunk_reader = BufReader::new(chunk_handle);
let mut decompressor = XzDecoder::new(chunk_reader);
let offset = u64::try_from(chunk.index).unwrap() * chunk_size;
file_handle.seek(io::SeekFrom::Start(offset)).unwrap();
io::copy(&mut decompressor, &mut file_handle).unwrap();
}
});
return Ok(());
}

36
src-tauri/tauri.conf.json Normal file
View File

@ -0,0 +1,36 @@
{
"$schema": "https://schema.tauri.app/config/2.0.0",
"productName": "drop-app",
"version": "0.1.0",
"identifier": "dev.drop.drop",
"build": {
"beforeDevCommand": "yarn dev",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "yarn build",
"frontendDist": "../dist"
},
"app": {
"windows": [
{
"title": "drop-app",
"width": 800,
"height": 600
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}