From a24fca0e8768419a9f6a0c3b8027375ca8eab342 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Wed, 11 Mar 2026 15:14:57 +0100 Subject: [PATCH 01/12] Basic watcher started config for library paths --- Cargo.lock | 254 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 + src/main.rs | 44 ++++++++- 3 files changed, 299 insertions(+), 2 deletions(-) create mode 100644 Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..960189d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,254 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "inotify" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd5b3eaf1a28b758ac0faa5a4254e8ab2705605496f1b1f3fbbc3988ad73d199" +dependencies = [ + "bitflags", + "futures-core", + "inotify-sys", + "libc", + "tokio", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + +[[package]] +name = "libc" +version = "0.2.183" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776" +dependencies = [ + "serde_core", +] + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +dependencies = [ + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys", +] + +[[package]] +name = "toml" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "399b1124a3c9e16766831c6bba21e50192572cdd98706ea114f9502509686ffc" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "1.0.0+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32c2555c699578a4f59f0cc68e5116c8d7cabbd45e1409b989d4be085b53f13e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.0.9+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "uniloader" +version = "0.1.0" +dependencies = [ + "inotify", + "serde", + "toml", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "winnow" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" diff --git a/Cargo.toml b/Cargo.toml index 0909e94..a8a89b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] +inotify = "0.11.1" +serde = { version = "1.0.228", features = ["derive"] } +toml = "1.0.6" diff --git a/src/main.rs b/src/main.rs index e7a11a9..381e2c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,43 @@ -fn main() { - println!("Hello, world!"); +use std::{env, path::PathBuf}; + +use inotify::{Inotify, WatchMask}; +use serde::Deserialize; + +#[derive(Debug, Deserialize)] +struct Config { + libraries: LibConfig, +} + +impl Config {} + +#[derive(Debug, Deserialize)] +struct LibConfig { + component_search_engine_symbols: PathBuf, + component_serach_engine_footprints: PathBuf, +} + +fn main() -> std::io::Result<()> { + let downloads = PathBuf::from(env::var("HOME").unwrap()).join("Downloads"); + + println!("Watching {:?}", downloads); + + let mut inotify = Inotify::init()?; + + inotify.watches().add(&downloads, WatchMask::MOVED_TO)?; + + let mut buffer = [0u8; 4096]; + + loop { + let events = inotify.read_events_blocking(&mut buffer)?; + + for event in events { + if let Some(name) = event.name { + if let Some(name_str) = name.to_str() { + if name_str.starts_with("LIB") { + println!("Component Search Engine Detected"); + } + } + } + } + } } From c0a6c4da913fd1983449ec9956fe00980281a951 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Wed, 11 Mar 2026 22:14:33 +0100 Subject: [PATCH 02/12] Started conversion from inotify to notify --- Cargo.lock | 202 +++++++++++++++++++++++++++++++++++++++++++--------- Cargo.toml | 2 +- src/main.rs | 45 ++++++------ 3 files changed, 192 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 960189d..2389b90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.11.0" @@ -15,10 +21,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] -name = "futures-core" -version = "0.3.32" +name = "fsevent-sys" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] [[package]] name = "hashbrown" @@ -42,11 +51,9 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd5b3eaf1a28b758ac0faa5a4254e8ab2705605496f1b1f3fbbc3988ad73d199" dependencies = [ - "bitflags", - "futures-core", + "bitflags 2.11.0", "inotify-sys", "libc", - "tokio", ] [[package]] @@ -58,12 +65,38 @@ dependencies = [ "libc", ] +[[package]] +name = "kqueue" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac30106d7dce88daf4a3fcb4879ea939476d5074a9b7ddd0fb97fa4bed5596a" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + [[package]] name = "libc" version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + [[package]] name = "mio" version = "1.1.1" @@ -71,15 +104,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" dependencies = [ "libc", + "log", "wasi", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] -name = "pin-project-lite" -version = "0.2.17" +name = "notify" +version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3" +dependencies = [ + "bitflags 2.11.0", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "notify-types", + "walkdir", + "windows-sys 0.60.2", +] + +[[package]] +name = "notify-types" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42b8cfee0e339a0337359f3c88165702ac6e600dc01c0cc9579a92d62b08477a" +dependencies = [ + "bitflags 2.11.0", +] [[package]] name = "proc-macro2" @@ -99,6 +154,15 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "serde" version = "1.0.228" @@ -138,16 +202,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "socket2" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" -dependencies = [ - "libc", - "windows-sys", -] - [[package]] name = "syn" version = "2.0.117" @@ -159,19 +213,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tokio" -version = "1.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" -dependencies = [ - "libc", - "mio", - "pin-project-lite", - "socket2", - "windows-sys", -] - [[package]] name = "toml" version = "1.0.6+spec-1.1.0" @@ -221,23 +262,51 @@ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" name = "uniloader" version = "0.1.0" dependencies = [ - "inotify", + "notify", "serde", "toml", ] +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -247,6 +316,71 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + [[package]] name = "winnow" version = "0.7.15" diff --git a/Cargo.toml b/Cargo.toml index a8a89b8..a430fc6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] -inotify = "0.11.1" +notify = "8.2.0" serde = { version = "1.0.228", features = ["derive"] } toml = "1.0.6" diff --git a/src/main.rs b/src/main.rs index 381e2c2..0ca9764 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,10 @@ -use std::{env, path::PathBuf}; +use std::{ + env, + path::{Path, PathBuf}, + sync::mpsc, +}; -use inotify::{Inotify, WatchMask}; +use notify::{Event, RecursiveMode, Result, Watcher}; use serde::Deserialize; #[derive(Debug, Deserialize)] @@ -16,28 +20,25 @@ struct LibConfig { component_serach_engine_footprints: PathBuf, } -fn main() -> std::io::Result<()> { +fn main() -> Result<()> { + let (tx, rx) = mpsc::channel::>(); + let mut watcher = notify::recommended_watcher(tx)?; let downloads = PathBuf::from(env::var("HOME").unwrap()).join("Downloads"); + watcher.watch(&downloads, RecursiveMode::Recursive)?; - println!("Watching {:?}", downloads); - - let mut inotify = Inotify::init()?; - - inotify.watches().add(&downloads, WatchMask::MOVED_TO)?; - - let mut buffer = [0u8; 4096]; - - loop { - let events = inotify.read_events_blocking(&mut buffer)?; - - for event in events { - if let Some(name) = event.name { - if let Some(name_str) = name.to_str() { - if name_str.starts_with("LIB") { - println!("Component Search Engine Detected"); - } - } - } + for res in rx { + match res { + Ok(event) => println!("event: {:?}", event.paths[0]), + Err(e) => println!("watch error: {:?}", e), } } + + Ok(()) +} + +fn validate_lib(path: PathBuf) -> bool { + if path.is_file() { + let filename = path.file_name(); + } + return false; } From 3154823312546f9b89c7b7bccf14c89cf2212344 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Wed, 11 Mar 2026 23:33:40 +0100 Subject: [PATCH 03/12] Simply source filtering and started config --- Cargo.lock | 21 ++++++++++ Cargo.toml | 1 + src/main.rs | 116 +++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 119 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2389b90..887b604 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,6 +213,26 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "toml" version = "1.0.6+spec-1.1.0" @@ -264,6 +284,7 @@ version = "0.1.0" dependencies = [ "notify", "serde", + "thiserror", "toml", ] diff --git a/Cargo.toml b/Cargo.toml index a430fc6..46ae1d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ edition = "2024" [dependencies] notify = "8.2.0" serde = { version = "1.0.228", features = ["derive"] } +thiserror = "2.0.18" toml = "1.0.6" diff --git a/src/main.rs b/src/main.rs index 0ca9764..b003588 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,34 +1,94 @@ use std::{ - env, - path::{Path, PathBuf}, + env, fs, + path::{self, Path, PathBuf}, sync::mpsc, }; -use notify::{Event, RecursiveMode, Result, Watcher}; -use serde::Deserialize; +use notify::{Event, EventKind, RecursiveMode, Watcher, event::CreateKind}; +use serde::{Deserialize, Serialize}; +use thiserror::Error; -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] struct Config { - libraries: LibConfig, + libraries: Option, } -impl Config {} +impl Config { + fn load_or_create() -> Result { + let config_path = + PathBuf::from(env::var("HOME").unwrap()).join(".config/uniloader/config.toml"); -#[derive(Debug, Deserialize)] + if config_path.exists() { + let contents = fs::read_to_string(&config_path).map_err(|_| ConfigError::ConfigErr)?; + let config: Config = toml::from_str(&contents).map_err(|_| ConfigError::ConfigErr)?; + Ok(config) + } else { + fs::create_dir_all(config_path.parent().unwrap()) + .map_err(|_| ConfigError::ConfigErr)?; + let config = Config { libraries: None }; + let contents = toml::to_string_pretty(&config).map_err(|_| ConfigError::ConfigErr)?; + fs::write(&config_path, contents).map_err(|_| ConfigError::ConfigErr)?; + Ok(config) + } + } +} + +#[derive(Debug, Deserialize, Serialize, Clone)] struct LibConfig { - component_search_engine_symbols: PathBuf, - component_serach_engine_footprints: PathBuf, + symacsys_symbols: Option, + symacsys_footprints: Option, } -fn main() -> Result<()> { - let (tx, rx) = mpsc::channel::>(); +enum SourceType { + SymacSys, + UltraLibrarian, +} + +#[derive(Error, Debug)] +enum ConfigError { + #[error("Config error")] + ConfigErr, +} + +#[derive(Error, Debug)] +enum SourceError { + #[error("Unknown Source")] + SourceUnknown, + #[error("Filename Error")] + FilenameError, +} + +fn main() -> notify::Result<()> { + let config = Config::load_or_create().unwrap(); + if config.libraries.is_some() { + if config.libraries.clone().unwrap().symacsys_symbols.is_some() { + println!("{:?}", config.libraries.unwrap().symacsys_symbols.unwrap()); + } + } + let (tx, rx) = mpsc::channel::>(); let mut watcher = notify::recommended_watcher(tx)?; let downloads = PathBuf::from(env::var("HOME").unwrap()).join("Downloads"); - watcher.watch(&downloads, RecursiveMode::Recursive)?; + watcher.watch(&downloads, RecursiveMode::NonRecursive)?; for res in rx { match res { - Ok(event) => println!("event: {:?}", event.paths[0]), + Ok(event) => { + if event.kind != EventKind::Create(CreateKind::File) { + continue; + } + if !validate_zip(&event.paths[0]) { + continue; + } + + let Ok(source_type) = find_source_type(&event.paths[0]) else { + continue; + }; + + match source_type { + SourceType::SymacSys => println!("SymacSys detected"), + SourceType::UltraLibrarian => println!("UltraLibrarian detected"), + } + } Err(e) => println!("watch error: {:?}", e), } } @@ -36,9 +96,27 @@ fn main() -> Result<()> { Ok(()) } -fn validate_lib(path: PathBuf) -> bool { - if path.is_file() { - let filename = path.file_name(); - } - return false; +fn validate_zip(path: &Path) -> bool { + path.is_file() + && path + .extension() + .and_then(|e| e.to_str()) + .map(|e| e.eq_ignore_ascii_case("zip")) + .unwrap_or(false) +} + +fn find_source_type(path: &Path) -> Result { + let name = path + .file_name() + .ok_or(SourceError::FilenameError)? + .to_str() + .ok_or(SourceError::FilenameError)?; + + if name.starts_with("LIB_") { + Ok(SourceType::SymacSys) + } else if name.starts_with("ul_") { + Ok(SourceType::UltraLibrarian) + } else { + Err(SourceError::SourceUnknown) + } } From 42e48d8930f2d7bc744317736af984265a41a07b Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Thu, 12 Mar 2026 21:15:39 +0100 Subject: [PATCH 04/12] Cross platform fix --- Cargo.lock | 334 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/main.rs | 32 +++-- 3 files changed, 356 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 887b604..3716a8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + [[package]] name = "bitflags" version = "1.3.2" @@ -14,12 +20,40 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + [[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "fsevent-sys" version = "4.1.0" @@ -29,12 +63,46 @@ dependencies = [ "libc", ] +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", + "wasip3", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + [[package]] name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + [[package]] name = "indexmap" version = "2.13.0" @@ -42,7 +110,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.16.1", + "serde", + "serde_core", ] [[package]] @@ -65,6 +135,12 @@ dependencies = [ "libc", ] +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + [[package]] name = "kqueue" version = "1.1.1" @@ -85,18 +161,36 @@ dependencies = [ "libc", ] +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + [[package]] name = "libc" version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + [[package]] name = "log" version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + [[package]] name = "mio" version = "1.1.1" @@ -127,6 +221,18 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "notify-debouncer-mini" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17849edfaabd9a5fef1c606d99cfc615a8e99f7ac4366406d86c7942a3184cf2" +dependencies = [ + "log", + "notify", + "notify-types", + "tempfile", +] + [[package]] name = "notify-types" version = "2.1.0" @@ -136,6 +242,22 @@ dependencies = [ "bitflags 2.11.0", ] +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -154,6 +276,25 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags 2.11.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + [[package]] name = "same-file" version = "1.0.6" @@ -163,6 +304,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + [[package]] name = "serde" version = "1.0.228" @@ -193,6 +340,19 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + [[package]] name = "serde_spanned" version = "1.0.4" @@ -213,6 +373,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + [[package]] name = "thiserror" version = "2.0.18" @@ -278,11 +451,18 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "uniloader" version = "0.1.0" dependencies = [ "notify", + "notify-debouncer-mini", "serde", "thiserror", "toml", @@ -304,6 +484,58 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasip2" +version = "1.0.1+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +dependencies = [ + "wit-bindgen 0.46.0", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags 2.11.0", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + [[package]] name = "winapi-util" version = "0.1.11" @@ -407,3 +639,103 @@ name = "winnow" version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" + +[[package]] +name = "wit-bindgen" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags 2.11.0", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 46ae1d1..9c5d637 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] notify = "8.2.0" +notify-debouncer-mini = "0.7.0" serde = { version = "1.0.228", features = ["derive"] } thiserror = "2.0.18" toml = "1.0.6" diff --git a/src/main.rs b/src/main.rs index b003588..ea5aeab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,9 +2,15 @@ use std::{ env, fs, path::{self, Path, PathBuf}, sync::mpsc, + thread::sleep, + time::Duration, }; -use notify::{Event, EventKind, RecursiveMode, Watcher, event::CreateKind}; +use notify::{ + Event, EventKind, RecursiveMode, Watcher, + event::{CreateKind, ModifyKind}, +}; +use notify_debouncer_mini::{DebouncedEvent, new_debouncer}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -65,22 +71,28 @@ fn main() -> notify::Result<()> { println!("{:?}", config.libraries.unwrap().symacsys_symbols.unwrap()); } } - let (tx, rx) = mpsc::channel::>(); - let mut watcher = notify::recommended_watcher(tx)?; + let (tx, rx) = mpsc::channel::, notify::Error>>(); + + let mut debouncer = new_debouncer(Duration::from_secs(2), tx)?; let downloads = PathBuf::from(env::var("HOME").unwrap()).join("Downloads"); - watcher.watch(&downloads, RecursiveMode::NonRecursive)?; + println!("{:?}", downloads); + + debouncer + .watcher() + .watch(&downloads, RecursiveMode::NonRecursive)?; for res in rx { match res { - Ok(event) => { - if event.kind != EventKind::Create(CreateKind::File) { - continue; - } - if !validate_zip(&event.paths[0]) { + Ok(events) => { + println!("{:?}", events.len()); + let event = events[0].clone(); + let path = event.path; + + if !validate_zip(&path) { continue; } - let Ok(source_type) = find_source_type(&event.paths[0]) else { + let Ok(source_type) = find_source_type(&path) else { continue; }; From acec9a3ce0e4f25e77a120db6c007cc0cb04ff10 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Thu, 12 Mar 2026 21:24:42 +0100 Subject: [PATCH 05/12] Revert "Cross platform fix" This reverts commit 42e48d8930f2d7bc744317736af984265a41a07b. --- Cargo.lock | 334 +--------------------------------------------------- Cargo.toml | 1 - src/main.rs | 32 ++--- 3 files changed, 11 insertions(+), 356 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3716a8a..887b604 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anyhow" -version = "1.0.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" - [[package]] name = "bitflags" version = "1.3.2" @@ -20,40 +14,12 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - [[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" -[[package]] -name = "errno" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" -dependencies = [ - "libc", - "windows-sys 0.61.2", -] - -[[package]] -name = "fastrand" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" - -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - [[package]] name = "fsevent-sys" version = "4.1.0" @@ -63,46 +29,12 @@ dependencies = [ "libc", ] -[[package]] -name = "getrandom" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" -dependencies = [ - "cfg-if", - "libc", - "r-efi", - "wasip2", - "wasip3", -] - -[[package]] -name = "hashbrown" -version = "0.15.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -dependencies = [ - "foldhash", -] - [[package]] name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "id-arena" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" - [[package]] name = "indexmap" version = "2.13.0" @@ -110,9 +42,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", - "hashbrown 0.16.1", - "serde", - "serde_core", + "hashbrown", ] [[package]] @@ -135,12 +65,6 @@ dependencies = [ "libc", ] -[[package]] -name = "itoa" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" - [[package]] name = "kqueue" version = "1.1.1" @@ -161,36 +85,18 @@ dependencies = [ "libc", ] -[[package]] -name = "leb128fmt" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" - [[package]] name = "libc" version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" -[[package]] -name = "linux-raw-sys" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" - [[package]] name = "log" version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" -[[package]] -name = "memchr" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" - [[package]] name = "mio" version = "1.1.1" @@ -221,18 +127,6 @@ dependencies = [ "windows-sys 0.60.2", ] -[[package]] -name = "notify-debouncer-mini" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17849edfaabd9a5fef1c606d99cfc615a8e99f7ac4366406d86c7942a3184cf2" -dependencies = [ - "log", - "notify", - "notify-types", - "tempfile", -] - [[package]] name = "notify-types" version = "2.1.0" @@ -242,22 +136,6 @@ dependencies = [ "bitflags 2.11.0", ] -[[package]] -name = "once_cell" -version = "1.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" - -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn", -] - [[package]] name = "proc-macro2" version = "1.0.106" @@ -276,25 +154,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "r-efi" -version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" - -[[package]] -name = "rustix" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" -dependencies = [ - "bitflags 2.11.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.61.2", -] - [[package]] name = "same-file" version = "1.0.6" @@ -304,12 +163,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "semver" -version = "1.0.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" - [[package]] name = "serde" version = "1.0.228" @@ -340,19 +193,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_json" -version = "1.0.149" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" -dependencies = [ - "itoa", - "memchr", - "serde", - "serde_core", - "zmij", -] - [[package]] name = "serde_spanned" version = "1.0.4" @@ -373,19 +213,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" -dependencies = [ - "fastrand", - "getrandom", - "once_cell", - "rustix", - "windows-sys 0.61.2", -] - [[package]] name = "thiserror" version = "2.0.18" @@ -451,18 +278,11 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - [[package]] name = "uniloader" version = "0.1.0" dependencies = [ "notify", - "notify-debouncer-mini", "serde", "thiserror", "toml", @@ -484,58 +304,6 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" -[[package]] -name = "wasip2" -version = "1.0.1+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" -dependencies = [ - "wit-bindgen 0.46.0", -] - -[[package]] -name = "wasip3" -version = "0.4.0+wasi-0.3.0-rc-2026-01-06" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" -dependencies = [ - "wit-bindgen 0.51.0", -] - -[[package]] -name = "wasm-encoder" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" -dependencies = [ - "leb128fmt", - "wasmparser", -] - -[[package]] -name = "wasm-metadata" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" -dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" -dependencies = [ - "bitflags 2.11.0", - "hashbrown 0.15.5", - "indexmap", - "semver", -] - [[package]] name = "winapi-util" version = "0.1.11" @@ -639,103 +407,3 @@ name = "winnow" version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" - -[[package]] -name = "wit-bindgen" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" - -[[package]] -name = "wit-bindgen" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" -dependencies = [ - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" -dependencies = [ - "anyhow", - "heck", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" -dependencies = [ - "anyhow", - "heck", - "indexmap", - "prettyplease", - "syn", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" -dependencies = [ - "anyhow", - "prettyplease", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", -] - -[[package]] -name = "wit-component" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" -dependencies = [ - "anyhow", - "bitflags 2.11.0", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser", -] - -[[package]] -name = "zmij" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 9c5d637..46ae1d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,6 @@ edition = "2024" [dependencies] notify = "8.2.0" -notify-debouncer-mini = "0.7.0" serde = { version = "1.0.228", features = ["derive"] } thiserror = "2.0.18" toml = "1.0.6" diff --git a/src/main.rs b/src/main.rs index ea5aeab..b003588 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,15 +2,9 @@ use std::{ env, fs, path::{self, Path, PathBuf}, sync::mpsc, - thread::sleep, - time::Duration, }; -use notify::{ - Event, EventKind, RecursiveMode, Watcher, - event::{CreateKind, ModifyKind}, -}; -use notify_debouncer_mini::{DebouncedEvent, new_debouncer}; +use notify::{Event, EventKind, RecursiveMode, Watcher, event::CreateKind}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -71,28 +65,22 @@ fn main() -> notify::Result<()> { println!("{:?}", config.libraries.unwrap().symacsys_symbols.unwrap()); } } - let (tx, rx) = mpsc::channel::, notify::Error>>(); - - let mut debouncer = new_debouncer(Duration::from_secs(2), tx)?; + let (tx, rx) = mpsc::channel::>(); + let mut watcher = notify::recommended_watcher(tx)?; let downloads = PathBuf::from(env::var("HOME").unwrap()).join("Downloads"); - println!("{:?}", downloads); - - debouncer - .watcher() - .watch(&downloads, RecursiveMode::NonRecursive)?; + watcher.watch(&downloads, RecursiveMode::NonRecursive)?; for res in rx { match res { - Ok(events) => { - println!("{:?}", events.len()); - let event = events[0].clone(); - let path = event.path; - - if !validate_zip(&path) { + Ok(event) => { + if event.kind != EventKind::Create(CreateKind::File) { + continue; + } + if !validate_zip(&event.paths[0]) { continue; } - let Ok(source_type) = find_source_type(&path) else { + let Ok(source_type) = find_source_type(&event.paths[0]) else { continue; }; From abf2b235c60c3e203db16d197afa0850399da38e Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Fri, 13 Mar 2026 20:04:52 +0100 Subject: [PATCH 06/12] SymacSys sym import working --- Cargo.lock | 877 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 2 + src/main.rs | 206 +++++++++++- 3 files changed, 1073 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 887b604..318a2a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,44 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + [[package]] name = "bitflags" version = "1.3.2" @@ -14,12 +52,165 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bzip2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c" +dependencies = [ + "libbz2-rs-sys", +] + +[[package]] +name = "cc" +version = "1.2.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "constant_time_eq" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "deflate64" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "807800ff3288b621186fe0a8f3392c4652068257302709c24efd918c3dffcdc2" + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + [[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "miniz_oxide", + "zlib-rs", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "fsevent-sys" version = "4.1.0" @@ -29,12 +220,103 @@ dependencies = [ "libc", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi 5.3.0", + "wasip2", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 6.0.0", + "wasip2", + "wasip3", + "wasm-bindgen", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + [[package]] name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + [[package]] name = "indexmap" version = "2.13.0" @@ -42,7 +324,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.16.1", + "serde", + "serde_core", ] [[package]] @@ -65,6 +349,41 @@ dependencies = [ "libc", ] +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.4", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "kqueue" version = "1.1.1" @@ -85,6 +404,18 @@ dependencies = [ "libc", ] +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libbz2-rs-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c4a545a15244c7d945065b5d392b2d2d7f21526fba56ce51467b06ed445e8f7" + [[package]] name = "libc" version = "0.2.183" @@ -97,6 +428,31 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "lzma-rust2" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47bb1e988e6fb779cf720ad431242d3f03167c1b3f2b1aae7f1a94b2495b36ae" +dependencies = [ + "sha2", +] + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + [[package]] name = "mio" version = "1.1.1" @@ -136,6 +492,65 @@ dependencies = [ "bitflags 2.11.0", ] +[[package]] +name = "num-conv" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest", + "hmac", +] + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppmd-rust" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efca4c95a19a79d1c98f791f10aebd5c1363b473244630bb7dbde1dc98455a24" + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -154,6 +569,24 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "same-file" version = "1.0.6" @@ -163,6 +596,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + [[package]] name = "serde" version = "1.0.228" @@ -193,6 +632,19 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + [[package]] name = "serde_spanned" version = "1.0.4" @@ -202,6 +654,46 @@ dependencies = [ "serde_core", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "simd-adler32" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.117" @@ -233,6 +725,26 @@ dependencies = [ "syn", ] +[[package]] +name = "time" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +dependencies = [ + "deranged", + "js-sys", + "num-conv", + "powerfmt", + "serde_core", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" + [[package]] name = "toml" version = "1.0.6+spec-1.1.0" @@ -272,22 +784,48 @@ version = "1.0.6+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" +[[package]] +name = "typed-path" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e28f89b80c87b8fb0cf04ab448d5dd0dd0ade2f8891bae878de66a75a28600e" + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + [[package]] name = "unicode-ident" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "uniloader" version = "0.1.0" dependencies = [ + "chrono", "notify", "serde", "thiserror", "toml", + "zip", ] +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "walkdir" version = "2.5.0" @@ -304,6 +842,103 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags 2.11.0", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + [[package]] name = "winapi-util" version = "0.1.11" @@ -313,12 +948,65 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.60.2" @@ -407,3 +1095,190 @@ name = "winnow" version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags 2.11.0", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zip" +version = "8.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b680f2a0cd479b4cff6e1233c483fdead418106eae419dc60200ae9850f6d004" +dependencies = [ + "aes", + "bzip2", + "constant_time_eq", + "crc32fast", + "deflate64", + "flate2", + "getrandom 0.4.2", + "hmac", + "indexmap", + "lzma-rust2", + "memchr", + "pbkdf2", + "ppmd-rust", + "sha1", + "time", + "typed-path", + "zeroize", + "zopfli", + "zstd", +] + +[[package]] +name = "zlib-rs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be3d40e40a133f9c916ee3f9f4fa2d9d63435b5fbe1bfc6d9dae0aa0ada1513" + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" + +[[package]] +name = "zopfli" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249" +dependencies = [ + "bumpalo", + "crc32fast", + "log", + "simd-adler32", +] + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.16+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 46ae1d1..e0e4b13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,9 @@ version = "0.1.0" edition = "2024" [dependencies] +chrono = "0.4.44" notify = "8.2.0" serde = { version = "1.0.228", features = ["derive"] } thiserror = "2.0.18" toml = "1.0.6" +zip = "8.2.0" diff --git a/src/main.rs b/src/main.rs index b003588..cf0d817 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,20 @@ use std::{ - env, fs, + env, + fs::{self, File}, + ops::Not, path::{self, Path, PathBuf}, sync::mpsc, }; +use chrono::Local; use notify::{Event, EventKind, RecursiveMode, Watcher, event::CreateKind}; use serde::{Deserialize, Serialize}; use thiserror::Error; +use zip::ZipArchive; #[derive(Debug, Deserialize, Serialize)] struct Config { - libraries: Option, + libraries: LibConfig, } impl Config { @@ -25,7 +29,11 @@ impl Config { } else { fs::create_dir_all(config_path.parent().unwrap()) .map_err(|_| ConfigError::ConfigErr)?; - let config = Config { libraries: None }; + let config = Config { + libraries: LibConfig { + path: PathBuf::from("~/KiCad/libraries/"), + }, + }; let contents = toml::to_string_pretty(&config).map_err(|_| ConfigError::ConfigErr)?; fs::write(&config_path, contents).map_err(|_| ConfigError::ConfigErr)?; Ok(config) @@ -35,8 +43,7 @@ impl Config { #[derive(Debug, Deserialize, Serialize, Clone)] struct LibConfig { - symacsys_symbols: Option, - symacsys_footprints: Option, + path: PathBuf, } enum SourceType { @@ -58,13 +65,96 @@ enum SourceError { FilenameError, } -fn main() -> notify::Result<()> { - let config = Config::load_or_create().unwrap(); - if config.libraries.is_some() { - if config.libraries.clone().unwrap().symacsys_symbols.is_some() { - println!("{:?}", config.libraries.unwrap().symacsys_symbols.unwrap()); +#[derive(Error, Debug)] +enum ImportError { + #[error("Unknown Path")] + InvalidPath, + #[error("Corrputed Zip")] + InvalidZip, +} + +struct SymbolLibrary { + version: String, + symbols: Vec, +} + +struct Symbol { + name: String, + raw: String, +} + +impl SymbolLibrary { + fn new() -> Self { + SymbolLibrary { + version: "20211014".to_string(), + symbols: Vec::new(), } } + fn write(&self) -> String { + let mut out = format!( + "(kicad_symbol_lib\n\t(version {})\n\t(generator \"uniloader\")\n", + self.version, + ); + + for sym in &self.symbols { + out.push_str(&sym.raw); + out.push_str("\n"); + } + + out.push_str(")"); + out + } + + fn from_str(input: &str) -> Self { + let input = input.replace("\r\n", "\n"); + let mut version = String::new(); + let mut symbols = Vec::new(); + + if let Some(v_start) = input.find("(version ") { + let rest = &input[v_start + 9..]; + if let Some(v_end) = rest.find(')') { + version = rest[..v_end].trim().to_string(); + } + } + + let mut i = 0; + let chars: Vec = input.chars().collect(); + + while i < chars.len() { + if input[i..].starts_with("(symbol ") { + let start = i; + let mut depth = 0; + + while i < chars.len() { + if chars[i] == '(' { + depth += 1; + } else if chars[i] == ')' { + depth -= 1; + + if depth == 0 { + let end = i + 1; + let raw = input[start..end].to_string(); + + let name = raw.split('"').nth(1).unwrap_or("unknown").to_string(); + + symbols.push(Symbol { name, raw }); + + break; + } + } + i += 1; + } + } + i += 1; + } + + Self { version, symbols } + } +} + +fn main() -> notify::Result<()> { + let config = Config::load_or_create().unwrap(); + println!("{:?}", config.libraries.path); let (tx, rx) = mpsc::channel::>(); let mut watcher = notify::recommended_watcher(tx)?; let downloads = PathBuf::from(env::var("HOME").unwrap()).join("Downloads"); @@ -85,7 +175,12 @@ fn main() -> notify::Result<()> { }; match source_type { - SourceType::SymacSys => println!("SymacSys detected"), + SourceType::SymacSys => { + println!("SymacSys detected, Installing..."); + let Ok(_) = import_symacsys(&event.paths[0], &config) else { + continue; + }; + } SourceType::UltraLibrarian => println!("UltraLibrarian detected"), } } @@ -120,3 +215,92 @@ fn find_source_type(path: &Path) -> Result { Err(SourceError::SourceUnknown) } } + +fn extract_zip(path: &Path, config: &Config) -> Result { + let file = File::open(path).map_err(|_| ImportError::InvalidPath)?; + let mut archive = ZipArchive::new(file).map_err(|_| ImportError::InvalidZip)?; + + let Some(file_name) = path.file_stem() else { + return Err(ImportError::InvalidPath); + }; + + let tmp_path = config.libraries.path.join("tmp").join(file_name); + + fs::create_dir_all(&tmp_path).map_err(|_| ImportError::InvalidPath)?; + + archive + .extract(&tmp_path) + .map_err(|_| ImportError::InvalidPath)?; + + fs::remove_file(path).map_err(|_| ImportError::InvalidPath)?; + Ok(tmp_path) +} + +fn import_symacsys(path: &Path, config: &Config) -> Result<(), ImportError> { + let tmp_path = extract_zip(path, config)?; + + let dirs = fs::read_dir(&tmp_path).map_err(|_| ImportError::InvalidPath)?; + + let Some(data_dir) = dirs + .filter_map(|e| e.ok()) + .find(|entry| entry.file_type().map(|t| t.is_dir()).unwrap_or(false)) + .map(|entry| entry.path()) + else { + return Err(ImportError::InvalidPath); + }; + + let kicad_dir = data_dir.join("KiCad"); + + let results = fs::read_dir(&kicad_dir).map_err(|_| ImportError::InvalidPath)?; + + let Some(sym) = results + .filter_map(|e| e.ok()) + .find(|entry| { + entry + .path() + .extension() + .map(|ext| ext == "kicad_sym") + .unwrap_or(false) + }) + .map(|entry| entry.path()) + else { + return Err(ImportError::InvalidPath); + }; + + let sym_str = fs::read_to_string(&sym).map_err(|_| ImportError::InvalidPath)?; + + let new_lib = SymbolLibrary::from_str(&sym_str); + + let symacsys_path = config.libraries.path.join("SymacSys"); + let symacsys_sym = symacsys_path.join("SymacSys_Components.kicad_sym"); + + fs::create_dir_all(symacsys_path).map_err(|_| ImportError::InvalidPath)?; + + let mut current_lib: SymbolLibrary; + + if symacsys_sym.exists() { + let symacsys_sym_str = + fs::read_to_string(&symacsys_sym).map_err(|_| ImportError::InvalidPath)?; + current_lib = SymbolLibrary::from_str(&symacsys_sym_str); + } else { + current_lib = SymbolLibrary::new(); + let symacsys_sym_str = current_lib.write(); + fs::write(&symacsys_sym, symacsys_sym_str).map_err(|_| ImportError::InvalidPath)?; + } + + for symbol in new_lib.symbols { + current_lib.symbols.push(symbol); + } + + let out_lib = current_lib.write(); + fs::write(&symacsys_sym, out_lib).map_err(|_| ImportError::InvalidPath)?; + + println!("{:?}", tmp_path); + + fs::remove_dir_all(tmp_path).map_err(|_| { + println!("Error rmdir"); + ImportError::InvalidPath + })?; + + Ok(()) +} From c5c8b78ebb9b291654e7bed72b670524f798d1b4 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Fri, 13 Mar 2026 22:33:54 +0100 Subject: [PATCH 07/12] Fully working SymacSys sym and mod import --- src/main.rs | 112 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 44 deletions(-) diff --git a/src/main.rs b/src/main.rs index cf0d817..25b2c7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,10 @@ use std::{ env, fs::{self, File}, - ops::Not, - path::{self, Path, PathBuf}, + path::{Path, PathBuf}, sync::mpsc, }; -use chrono::Local; use notify::{Event, EventKind, RecursiveMode, Watcher, event::CreateKind}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -237,70 +235,96 @@ fn extract_zip(path: &Path, config: &Config) -> Result { } fn import_symacsys(path: &Path, config: &Config) -> Result<(), ImportError> { + // Extract ZIP archive from downloads folder into libraries/tmp let tmp_path = extract_zip(path, config)?; - let dirs = fs::read_dir(&tmp_path).map_err(|_| ImportError::InvalidPath)?; - - let Some(data_dir) = dirs + // Find directory containing extracted library data + let data_dir = fs::read_dir(&tmp_path) + .map_err(|_| ImportError::InvalidPath)? .filter_map(|e| e.ok()) .find(|entry| entry.file_type().map(|t| t.is_dir()).unwrap_or(false)) .map(|entry| entry.path()) - else { - return Err(ImportError::InvalidPath); - }; + .ok_or(ImportError::InvalidPath)?; + // Locate KiCad directory let kicad_dir = data_dir.join("KiCad"); - let results = fs::read_dir(&kicad_dir).map_err(|_| ImportError::InvalidPath)?; - - let Some(sym) = results + // Read all entries once + let entries: Vec<_> = fs::read_dir(&kicad_dir) + .map_err(|_| ImportError::InvalidPath)? .filter_map(|e| e.ok()) - .find(|entry| { + .collect(); + + // Collect all symbol and footprint files + let sym_files: Vec = entries + .iter() + .filter(|entry| { entry .path() .extension() - .map(|ext| ext == "kicad_sym") + .map(|e| e == "kicad_sym") .unwrap_or(false) }) .map(|entry| entry.path()) - else { + .collect(); + + let mod_files: Vec = entries + .iter() + .filter(|entry| { + entry + .path() + .extension() + .map(|e| e == "kicad_mod") + .unwrap_or(false) + }) + .map(|entry| entry.path()) + .collect(); + + if sym_files.is_empty() && mod_files.is_empty() { return Err(ImportError::InvalidPath); + } + + // Target library paths + let symacsys_root = config.libraries.path.join("SymacSys"); + let symacsys_sym = symacsys_root.join("SymacSys_Components.kicad_sym"); + let symacsys_pretty = symacsys_root.join("SymacSys_Footprints.pretty"); + + fs::create_dir_all(&symacsys_root).map_err(|_| ImportError::InvalidPath)?; + fs::create_dir_all(&symacsys_pretty).map_err(|_| ImportError::InvalidPath)?; + + // Load or create symbol library + let mut current_lib = if symacsys_sym.exists() { + let contents = fs::read_to_string(&symacsys_sym).map_err(|_| ImportError::InvalidPath)?; + SymbolLibrary::from_str(&contents) + } else { + SymbolLibrary::new() }; - let sym_str = fs::read_to_string(&sym).map_err(|_| ImportError::InvalidPath)?; + // Import symbols from every .kicad_sym file + for sym_path in sym_files { + let sym_str = fs::read_to_string(&sym_path).map_err(|_| ImportError::InvalidPath)?; + let new_lib = SymbolLibrary::from_str(&sym_str); - let new_lib = SymbolLibrary::from_str(&sym_str); - - let symacsys_path = config.libraries.path.join("SymacSys"); - let symacsys_sym = symacsys_path.join("SymacSys_Components.kicad_sym"); - - fs::create_dir_all(symacsys_path).map_err(|_| ImportError::InvalidPath)?; - - let mut current_lib: SymbolLibrary; - - if symacsys_sym.exists() { - let symacsys_sym_str = - fs::read_to_string(&symacsys_sym).map_err(|_| ImportError::InvalidPath)?; - current_lib = SymbolLibrary::from_str(&symacsys_sym_str); - } else { - current_lib = SymbolLibrary::new(); - let symacsys_sym_str = current_lib.write(); - fs::write(&symacsys_sym, symacsys_sym_str).map_err(|_| ImportError::InvalidPath)?; + for symbol in new_lib.symbols { + if !current_lib.symbols.iter().any(|s| s.name == symbol.name) { + current_lib.symbols.push(symbol); + } + } } - for symbol in new_lib.symbols { - current_lib.symbols.push(symbol); + // Write updated symbol library + let output = current_lib.write(); + fs::write(&symacsys_sym, output).map_err(|_| ImportError::InvalidPath)?; + + // Copy all footprint files + for mod_path in mod_files { + let filename = mod_path.file_name().ok_or(ImportError::InvalidPath)?; + let target = symacsys_pretty.join(filename); + fs::copy(mod_path, target).map_err(|_| ImportError::InvalidPath)?; } - let out_lib = current_lib.write(); - fs::write(&symacsys_sym, out_lib).map_err(|_| ImportError::InvalidPath)?; - - println!("{:?}", tmp_path); - - fs::remove_dir_all(tmp_path).map_err(|_| { - println!("Error rmdir"); - ImportError::InvalidPath - })?; + // Delete temporary folder + fs::remove_dir_all(tmp_path).map_err(|_| ImportError::InvalidPath)?; Ok(()) } From 1307b389a12bd9cfd9dc0935b01e44bbead60ac0 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Fri, 13 Mar 2026 22:34:09 +0100 Subject: [PATCH 08/12] Cargo clippy --fix --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 25b2c7f..f17dc90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,10 +96,10 @@ impl SymbolLibrary { for sym in &self.symbols { out.push_str(&sym.raw); - out.push_str("\n"); + out.push('\n'); } - out.push_str(")"); + out.push(')'); out } From 6a293e57595269ecc927174f772738310a383935 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Fri, 13 Mar 2026 22:46:35 +0100 Subject: [PATCH 09/12] Fully working UltraLibrarian sym and mod import --- src/main.rs | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index f17dc90..a4bfab7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -179,7 +179,12 @@ fn main() -> notify::Result<()> { continue; }; } - SourceType::UltraLibrarian => println!("UltraLibrarian detected"), + SourceType::UltraLibrarian => { + println!("UltraLibrarian detected, Installing..."); + let Ok(_) = import_ultralibrarian(&event.paths[0], &config) else { + continue; + }; + } } } Err(e) => println!("watch error: {:?}", e), @@ -328,3 +333,102 @@ fn import_symacsys(path: &Path, config: &Config) -> Result<(), ImportError> { Ok(()) } + +fn import_ultralibrarian(path: &Path, config: &Config) -> Result<(), ImportError> { + // Extract ZIP archive from downloads folder into libraries/tmp + let tmp_path = extract_zip(path, config)?; + + // Find directory containing extracted library data + let data_dir = fs::read_dir(&tmp_path) + .map_err(|_| ImportError::InvalidPath)? + .filter_map(|e| e.ok()) + .find(|entry| entry.file_type().map(|t| t.is_dir()).unwrap_or(false)) + .map(|entry| entry.path()) + .ok_or(ImportError::InvalidPath)?; + + let pretty_dir = data_dir.join("footprints.pretty"); + + // Read all entries once + let root_entries: Vec<_> = fs::read_dir(&data_dir) + .map_err(|_| ImportError::InvalidPath)? + .filter_map(|e| e.ok()) + .collect(); + + let pretty_entries: Vec<_> = fs::read_dir(&pretty_dir) + .map_err(|_| ImportError::InvalidPath)? + .filter_map(|e| e.ok()) + .collect(); + + // Collect all symbol and footprint files + let sym_files: Vec = root_entries + .iter() + .filter(|entry| { + entry + .path() + .extension() + .map(|e| e == "kicad_sym") + .unwrap_or(false) + }) + .map(|entry| entry.path()) + .collect(); + + let mod_files: Vec = pretty_entries + .iter() + .filter(|entry| { + entry + .path() + .extension() + .map(|e| e == "kicad_mod") + .unwrap_or(false) + }) + .map(|entry| entry.path()) + .collect(); + + if sym_files.is_empty() && mod_files.is_empty() { + return Err(ImportError::InvalidPath); + } + + // Target library paths + let ultralibrarian_root = config.libraries.path.join("UltraLibrarian"); + let ultralibrarian_sym = ultralibrarian_root.join("UltraLibrarian_Components.kicad_sym"); + let ultralibrarian_pretty = ultralibrarian_root.join("UltraLibrarian_Footprints.pretty"); + + fs::create_dir_all(&ultralibrarian_root).map_err(|_| ImportError::InvalidPath)?; + fs::create_dir_all(&ultralibrarian_pretty).map_err(|_| ImportError::InvalidPath)?; + + // Load or create symbol library + let mut current_lib = if ultralibrarian_sym.exists() { + let contents = + fs::read_to_string(&ultralibrarian_sym).map_err(|_| ImportError::InvalidPath)?; + SymbolLibrary::from_str(&contents) + } else { + SymbolLibrary::new() + }; + + // Import symbols from every .kicad_sym file + for sym_path in sym_files { + let sym_str = fs::read_to_string(&sym_path).map_err(|_| ImportError::InvalidPath)?; + let new_lib = SymbolLibrary::from_str(&sym_str); + + for symbol in new_lib.symbols { + if !current_lib.symbols.iter().any(|s| s.name == symbol.name) { + current_lib.symbols.push(symbol); + } + } + } + + // Write updated symbol library + let output = current_lib.write(); + fs::write(&ultralibrarian_sym, output).map_err(|_| ImportError::InvalidPath)?; + + // Copy all footprint files + for mod_path in mod_files { + let filename = mod_path.file_name().ok_or(ImportError::InvalidPath)?; + let target = ultralibrarian_pretty.join(filename); + fs::copy(mod_path, target).map_err(|_| ImportError::InvalidPath)?; + } + + // Delete temporary folder + fs::remove_dir_all(tmp_path).map_err(|_| ImportError::InvalidPath)?; + Ok(()) +} From 81a1a0b32c878572d9ec760c5b7c3c573c051050 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Fri, 13 Mar 2026 23:31:07 +0100 Subject: [PATCH 10/12] Fully working SnapMagic sym and mod import --- src/main.rs | 198 +++++++++++++++++++++++++++++----------------------- 1 file changed, 110 insertions(+), 88 deletions(-) diff --git a/src/main.rs b/src/main.rs index a4bfab7..9c7defa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::{ env, fs::{self, File}, + io::Read, path::{Path, PathBuf}, sync::mpsc, }; @@ -47,6 +48,7 @@ struct LibConfig { enum SourceType { SymacSys, UltraLibrarian, + SnapMagic, } #[derive(Error, Debug)] @@ -185,6 +187,12 @@ fn main() -> notify::Result<()> { continue; }; } + SourceType::SnapMagic => { + println!("SnapMagic detected, Installing..."); + let Ok(_) = import_snapmagic(&event.paths[0], &config) else { + continue; + }; + } } } Err(e) => println!("watch error: {:?}", e), @@ -211,12 +219,30 @@ fn find_source_type(path: &Path) -> Result { .ok_or(SourceError::FilenameError)?; if name.starts_with("LIB_") { - Ok(SourceType::SymacSys) + return Ok(SourceType::SymacSys); } else if name.starts_with("ul_") { - Ok(SourceType::UltraLibrarian) - } else { - Err(SourceError::SourceUnknown) + return Ok(SourceType::UltraLibrarian); } + + let file = File::open(path).map_err(|_| SourceError::SourceUnknown)?; + let mut archive = ZipArchive::new(file).map_err(|_| SourceError::SourceUnknown)?; + for i in 0..archive.len() { + let Ok(mut file) = archive.by_index(i) else { + continue; + }; + let name = file.name(); + + if name.to_lowercase().contains("how-to-import") { + let mut contents = String::new(); + file.read_to_string(&mut contents) + .map_err(|_| SourceError::SourceUnknown)?; + + if contents.to_lowercase().contains("snapeda") { + return Ok(SourceType::SnapMagic); + } + } + } + Err(SourceError::SourceUnknown) } fn extract_zip(path: &Path, config: &Config) -> Result { @@ -240,10 +266,8 @@ fn extract_zip(path: &Path, config: &Config) -> Result { } fn import_symacsys(path: &Path, config: &Config) -> Result<(), ImportError> { - // Extract ZIP archive from downloads folder into libraries/tmp let tmp_path = extract_zip(path, config)?; - // Find directory containing extracted library data let data_dir = fs::read_dir(&tmp_path) .map_err(|_| ImportError::InvalidPath)? .filter_map(|e| e.ok()) @@ -251,16 +275,12 @@ fn import_symacsys(path: &Path, config: &Config) -> Result<(), ImportError> { .map(|entry| entry.path()) .ok_or(ImportError::InvalidPath)?; - // Locate KiCad directory let kicad_dir = data_dir.join("KiCad"); - // Read all entries once - let entries: Vec<_> = fs::read_dir(&kicad_dir) - .map_err(|_| ImportError::InvalidPath)? - .filter_map(|e| e.ok()) - .collect(); + let entries = fs::read_dir(&kicad_dir) + .map(|rd| rd.filter_map(|e| e.ok()).collect::>()) + .unwrap_or_default(); - // Collect all symbol and footprint files let sym_files: Vec = entries .iter() .filter(|entry| { @@ -285,60 +305,19 @@ fn import_symacsys(path: &Path, config: &Config) -> Result<(), ImportError> { .map(|entry| entry.path()) .collect(); - if sym_files.is_empty() && mod_files.is_empty() { - return Err(ImportError::InvalidPath); - } + let root = config.libraries.path.join("SymacSys"); + let sym = root.join("SymacSys_Components.kicad_sym"); + let pretty = root.join("SymacSys_Footprints.pretty"); - // Target library paths - let symacsys_root = config.libraries.path.join("SymacSys"); - let symacsys_sym = symacsys_root.join("SymacSys_Components.kicad_sym"); - let symacsys_pretty = symacsys_root.join("SymacSys_Footprints.pretty"); + install_library(sym_files, mod_files, &root, &sym, &pretty)?; - fs::create_dir_all(&symacsys_root).map_err(|_| ImportError::InvalidPath)?; - fs::create_dir_all(&symacsys_pretty).map_err(|_| ImportError::InvalidPath)?; - - // Load or create symbol library - let mut current_lib = if symacsys_sym.exists() { - let contents = fs::read_to_string(&symacsys_sym).map_err(|_| ImportError::InvalidPath)?; - SymbolLibrary::from_str(&contents) - } else { - SymbolLibrary::new() - }; - - // Import symbols from every .kicad_sym file - for sym_path in sym_files { - let sym_str = fs::read_to_string(&sym_path).map_err(|_| ImportError::InvalidPath)?; - let new_lib = SymbolLibrary::from_str(&sym_str); - - for symbol in new_lib.symbols { - if !current_lib.symbols.iter().any(|s| s.name == symbol.name) { - current_lib.symbols.push(symbol); - } - } - } - - // Write updated symbol library - let output = current_lib.write(); - fs::write(&symacsys_sym, output).map_err(|_| ImportError::InvalidPath)?; - - // Copy all footprint files - for mod_path in mod_files { - let filename = mod_path.file_name().ok_or(ImportError::InvalidPath)?; - let target = symacsys_pretty.join(filename); - fs::copy(mod_path, target).map_err(|_| ImportError::InvalidPath)?; - } - - // Delete temporary folder fs::remove_dir_all(tmp_path).map_err(|_| ImportError::InvalidPath)?; - Ok(()) } fn import_ultralibrarian(path: &Path, config: &Config) -> Result<(), ImportError> { - // Extract ZIP archive from downloads folder into libraries/tmp let tmp_path = extract_zip(path, config)?; - // Find directory containing extracted library data let data_dir = fs::read_dir(&tmp_path) .map_err(|_| ImportError::InvalidPath)? .filter_map(|e| e.ok()) @@ -348,18 +327,14 @@ fn import_ultralibrarian(path: &Path, config: &Config) -> Result<(), ImportError let pretty_dir = data_dir.join("footprints.pretty"); - // Read all entries once - let root_entries: Vec<_> = fs::read_dir(&data_dir) - .map_err(|_| ImportError::InvalidPath)? - .filter_map(|e| e.ok()) - .collect(); + let root_entries = fs::read_dir(&data_dir) + .map(|rd| rd.filter_map(|e| e.ok()).collect::>()) + .unwrap_or_default(); - let pretty_entries: Vec<_> = fs::read_dir(&pretty_dir) - .map_err(|_| ImportError::InvalidPath)? - .filter_map(|e| e.ok()) - .collect(); + let pretty_entries = fs::read_dir(&pretty_dir) + .map(|rd| rd.filter_map(|e| e.ok()).collect::>()) + .unwrap_or_default(); - // Collect all symbol and footprint files let sym_files: Vec = root_entries .iter() .filter(|entry| { @@ -384,28 +359,76 @@ fn import_ultralibrarian(path: &Path, config: &Config) -> Result<(), ImportError .map(|entry| entry.path()) .collect(); - if sym_files.is_empty() && mod_files.is_empty() { - return Err(ImportError::InvalidPath); - } + let root = config.libraries.path.join("UltraLibrarian"); + let sym = root.join("UltraLibrarian_Components.kicad_sym"); + let pretty = root.join("UltraLibrarian_Footprints.pretty"); - // Target library paths - let ultralibrarian_root = config.libraries.path.join("UltraLibrarian"); - let ultralibrarian_sym = ultralibrarian_root.join("UltraLibrarian_Components.kicad_sym"); - let ultralibrarian_pretty = ultralibrarian_root.join("UltraLibrarian_Footprints.pretty"); + install_library(sym_files, mod_files, &root, &sym, &pretty)?; - fs::create_dir_all(&ultralibrarian_root).map_err(|_| ImportError::InvalidPath)?; - fs::create_dir_all(&ultralibrarian_pretty).map_err(|_| ImportError::InvalidPath)?; + fs::remove_dir_all(tmp_path).map_err(|_| ImportError::InvalidPath)?; + Ok(()) +} + +fn import_snapmagic(path: &Path, config: &Config) -> Result<(), ImportError> { + let data_dir = extract_zip(path, config)?; + + let entries = fs::read_dir(&data_dir) + .map(|rd| rd.filter_map(|e| e.ok()).collect::>()) + .unwrap_or_default(); + + let sym_files: Vec = entries + .iter() + .filter(|entry| { + entry + .path() + .extension() + .map(|e| e == "kicad_sym") + .unwrap_or(false) + }) + .map(|entry| entry.path()) + .collect(); + + let mod_files: Vec = entries + .iter() + .filter(|entry| { + entry + .path() + .extension() + .map(|e| e == "kicad_mod") + .unwrap_or(false) + }) + .map(|entry| entry.path()) + .collect(); + + let root = config.libraries.path.join("SnapMagic"); + let sym = root.join("SnapMagic_components.kicad_sym"); + let pretty = root.join("SnapMagic_Footprints.pretty"); + + install_library(sym_files, mod_files, &root, &sym, &pretty)?; + + fs::remove_dir_all(data_dir).map_err(|_| ImportError::InvalidPath)?; + Ok(()) +} + +fn install_library( + sym_files: Vec, + mod_files: Vec, + lib_root: &Path, + sym_file: &Path, + pretty_dir: &Path, +) -> Result<(), ImportError> { + fs::create_dir_all(lib_root).map_err(|_| ImportError::InvalidPath)?; + fs::create_dir_all(pretty_dir).map_err(|_| ImportError::InvalidPath)?; // Load or create symbol library - let mut current_lib = if ultralibrarian_sym.exists() { - let contents = - fs::read_to_string(&ultralibrarian_sym).map_err(|_| ImportError::InvalidPath)?; + let mut current_lib = if sym_file.exists() { + let contents = fs::read_to_string(sym_file).map_err(|_| ImportError::InvalidPath)?; SymbolLibrary::from_str(&contents) } else { SymbolLibrary::new() }; - // Import symbols from every .kicad_sym file + // Install symbols for sym_path in sym_files { let sym_str = fs::read_to_string(&sym_path).map_err(|_| ImportError::InvalidPath)?; let new_lib = SymbolLibrary::from_str(&sym_str); @@ -417,18 +440,17 @@ fn import_ultralibrarian(path: &Path, config: &Config) -> Result<(), ImportError } } - // Write updated symbol library - let output = current_lib.write(); - fs::write(&ultralibrarian_sym, output).map_err(|_| ImportError::InvalidPath)?; + if !current_lib.symbols.is_empty() { + let output = current_lib.write(); + fs::write(sym_file, output).map_err(|_| ImportError::InvalidPath)?; + } - // Copy all footprint files + // Install footprints for mod_path in mod_files { let filename = mod_path.file_name().ok_or(ImportError::InvalidPath)?; - let target = ultralibrarian_pretty.join(filename); + let target = pretty_dir.join(filename); fs::copy(mod_path, target).map_err(|_| ImportError::InvalidPath)?; } - // Delete temporary folder - fs::remove_dir_all(tmp_path).map_err(|_| ImportError::InvalidPath)?; Ok(()) } From 2c1cb54ff041f03e36fb5592052dad4dc42c7688 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Fri, 13 Mar 2026 23:51:50 +0100 Subject: [PATCH 11/12] Added copyright identifier --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 9c7defa..fea6be3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +// Copyright (C) 2026 Hector van der Aa +// SPDX-License-Identifier: GPL-3.0-or-later use std::{ env, fs::{self, File}, From 32dc396e5407e2291590129ed7fbb51b192c0a37 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Fri, 13 Mar 2026 23:51:54 +0100 Subject: [PATCH 12/12] Updated README --- README.md | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 413c459..44a42a7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,42 @@ # UniLoader -A universal library loader for KiCad \ No newline at end of file +A simple daemon that automatically imports any libraries into KiCad. It currently supports symbols and footprints from [SamacSys](https://componentsearchengine.com/), [UltraLibrarian](https://app.ultralibrarian.com/search), [SnapMagic](https://www.snapeda.com/home/) + +## Installation + +An automated install script is planned but currently the repo needs to be cloned, built and installed manually +``` + +git clone https://git.h3cx.dev/h3cx/UniLoader.git + +cd UniLoader + +cargo build -r + +``` +You will then find the binary under `target/release` you can run it manually or create a systemd service to automatically run it at boot + +## Usage + +To get started you will need to set up your config, to do so create a config file +``` + +mkdir ~/.config/uniloader + +touch ~/.config/uniloader/config.toml + +``` +Then use your favorite text editor to open this config and paste in the minimal config +``` + +[libraries] +path = "~/KiCad/libraries/" + +``` +Now that you have set this up, the application should be ready to go, just head over to your favorite library website and download any component. + +Upon downloading the first component from a given online library you will be required to add the library to KiCad. In KiCad open your symbol editor and head to `File->Add Library` then naviagate to the path you set in your config and add the library. Repeat this from the footprint editor for the footprints libraries. + +## Warranty + +Use this program at your own risk, no warranty is provided for anything that it could do to your libraries, KiCad or operating system. If you encounter any issues feel free to open an issue.