1#![doc = include_str!("../README.md")]
2#![doc(
3 html_logo_url = "https://tanepiper.github.io/unbanished/assets/un-banished-icon.svg",
4 html_favicon_url = "https://tanepiper.github.io/unbanished/favicon.svg"
5)]
6
7pub mod api;
8pub mod install;
9pub mod nxm;
10
11#[cfg(feature = "native")]
12pub mod native;
13
14pub const GAME_DOMAIN: &str = "banished";
16
17pub const GAME_ID: u32 = 617;
19
20pub const API_V1: &str = "https://api.nexusmods.com/v1";
22
23pub const API_V2: &str = "https://api.nexusmods.com/v2/graphql";
25
26#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct App {
29 pub name: String,
31 pub version: String,
33}
34
35impl App {
36 pub fn un_banished(version: &str) -> App {
38 App {
39 name: "Un-Banished".to_string(),
40 version: version.to_string(),
41 }
42 }
43}
44
45#[derive(Debug, Clone, PartialEq, Eq)]
47pub struct Request {
48 pub method: &'static str,
50 pub url: String,
52 pub headers: Vec<(String, String)>,
54 pub body: Option<String>,
56}
57
58#[derive(Debug, Clone, PartialEq, Eq)]
60pub enum Error {
61 NoKey,
63 Network(String),
65 Status(u16, String),
67 Answer(String),
69 NeedsPremium,
72 Unsupported(String),
74 NoPackage,
76}
77
78impl std::fmt::Display for Error {
79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 match self {
81 Error::NoKey => write!(f, "no Nexus Mods API key is set"),
82 Error::Network(m) => write!(f, "could not reach Nexus Mods: {m}"),
83 Error::Status(s, m) => write!(f, "Nexus Mods answered {s}: {m}"),
84 Error::Answer(m) => write!(f, "unexpected answer from Nexus Mods: {m}"),
85 Error::NeedsPremium => write!(
86 f,
87 "this download needs Nexus Mods Premium, or a link from the mod page's \
88 \"Mod Manager Download\" button"
89 ),
90 Error::Unsupported(e) => write!(
91 f,
92 "a .{e} archive cannot be opened here; download it from Nexus Mods and put its \
93 .pkm file in the WinData folder"
94 ),
95 Error::NoPackage => write!(f, "the download holds no .pkm mod package"),
96 }
97 }
98}
99
100impl std::error::Error for Error {}