summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-07-11 13:32:48 +0200
committersalmonik <raisersoft@proton.me>2026-07-11 13:32:48 +0200
commit7df4ceb1cf2a6edc058d28527140598ca90e1f10 (patch)
treec8ade0334e962f0089ef4535cb07d5feaf6b857a /src/main.rs
downloadfactorio-mod-downloader-7df4ceb1cf2a6edc058d28527140598ca90e1f10.tar.gz
factorio-mod-downloader-7df4ceb1cf2a6edc058d28527140598ca90e1f10.zip
initmain
Diffstat (limited to '')
-rw-r--r--src/main.rs102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..78f17f8
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,102 @@
1mod downloader;
2
3#[cfg(feature = "gui")]
4mod gui;
5
6// ---------------------------------------------------------------------------
7// GUI entry point (when the "gui" feature is enabled)
8// ---------------------------------------------------------------------------
9#[cfg(feature = "gui")]
10fn main() -> eframe::Result<()> {
11 let options = eframe::NativeOptions {
12 viewport: egui::ViewportBuilder::default()
13 .with_inner_size([800.0, 650.0])
14 .with_min_inner_size([600.0, 400.0]),
15 ..Default::default()
16 };
17
18 eframe::run_native(
19 "Factorio Mod Downloader",
20 options,
21 Box::new(|_cc| Ok(Box::new(gui::App::new()))),
22 )
23}
24
25// ---------------------------------------------------------------------------
26// CLI entry point (when the "gui" feature is disabled)
27// ---------------------------------------------------------------------------
28#[cfg(not(feature = "gui"))]
29fn main() {
30 let args: Vec<String> = std::env::args().collect();
31
32 if args.len() < 2 {
33 eprintln!("Factorio Mod Downloader (CLI)");
34 eprintln!();
35 eprintln!(
36 "Usage: {} <mod_url_or_name> [output_directory] [options]",
37 args[0]
38 );
39 eprintln!();
40 eprintln!("Options:");
41 eprintln!(" --version <VER> Download a specific version instead of latest");
42 eprintln!(" --include-optional Also download optional dependencies");
43 eprintln!();
44 eprintln!("Examples:");
45 eprintln!(" {} my-cool-mod", args[0]);
46 eprintln!(
47 " {} https://mods.factorio.com/mod/my-cool-mod ./mods",
48 args[0]
49 );
50 eprintln!(
51 " {} my-cool-mod ./mods --version 2.1.0 --include-optional",
52 args[0]
53 );
54 std::process::exit(1);
55 }
56
57 let mod_url = &args[1];
58
59 let output = if args.len() >= 3 && !args[2].starts_with("--") {
60 std::path::PathBuf::from(&args[2])
61 } else {
62 std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from("."))
63 };
64
65 let mut target_version: Option<&str> = None;
66 let mut include_optional = false;
67
68 let mut i = if args.len() >= 3 && !args[2].starts_with("--") {
69 3
70 } else {
71 2
72 };
73 while i < args.len() {
74 match args[i].as_str() {
75 "--version" => {
76 if i + 1 < args.len() {
77 target_version = Some(&args[i + 1]);
78 i += 1;
79 } else {
80 eprintln!("Error: --version requires a value");
81 std::process::exit(1);
82 }
83 }
84 "--include-optional" => {
85 include_optional = true;
86 }
87 other => {
88 eprintln!("Unknown option: {other}");
89 std::process::exit(1);
90 }
91 }
92 i += 1;
93 }
94
95 match downloader::run_cli_download(mod_url, &output, target_version, include_optional) {
96 Ok(()) => {}
97 Err(e) => {
98 eprintln!("Error: {:#}", e);
99 std::process::exit(1);
100 }
101 }
102}