cpclib_runner/runner/emulator/
ace.rs1use std::collections::BTreeMap;
2
3use cpclib_common::camino::Utf8PathBuf;
4use directories::BaseDirs;
5use scraper::{Html, Selector};
6
7use crate::delegated::{
8 ArchiveFormat, DownloadableInformation, DynamicUrlInformation, ExecutableInformation,
9 InternetDynamicCompiledApplication, MutiplatformUrls, cpclib_download
10};
11
12pub const ACE_CMD: &str = "ace";
13
14const ACE_URL: &str = "http://www.roudoudou.com/ACE-DL";
15
16#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
17pub enum AceVersion {
18 #[default]
19 UnknownLastVersion, Bnd4, ZenSummer, WakePoint }
24
25impl DownloadableInformation for AceVersion {
26 fn target_os_archive_format(&self) -> crate::delegated::ArchiveFormat {
27 #[cfg(target_os = "windows")]
28 return ArchiveFormat::Zip;
29 #[cfg(target_os = "linux")]
30 return ArchiveFormat::TarGz;
31 #[cfg(target_os = "macos")]
32 return ArchiveFormat::Zip;
33 }
34}
35impl DynamicUrlInformation for AceVersion {
36 fn dynamic_download_urls(&self) -> Result<MutiplatformUrls, String> {
37 match self {
38 Self::UnknownLastVersion => {
39 let mut content = cpclib_download(ACE_URL)?;
40 let mut html = String::new();
41 content
42 .read_to_string(&mut html)
43 .map_err(|e| e.to_string())?;
44
45 let document = Html::parse_document(&html);
46 let selector = Selector::parse("#dl td a")
47 .map_err(|e| e.to_string())
48 .map_err(|e| e.to_string())?;
49
50 let mut map = BTreeMap::new();
51 for element in document.select(&selector) {
52 map.insert(element.inner_html(), element.attr("href").unwrap());
53 }
54
55 let macos = map
56 .get("All versions")
57 .map(|url| format!("{ACE_URL}/{url}"));
58 let windows = map
59 .get("x64 (64 bits)")
60 .map(|url| format!("{ACE_URL}/{url}"));
61 let linux = map
62 .get("Ubuntu 24.04 LTS (AVX2)")
63 .map(|url| format!("{ACE_URL}/{url}"));
64
65 Ok(MutiplatformUrls {
66 linux,
67 windows,
68 macos
69 })
70 },
71 AceVersion::Bnd4 => {
72 Ok(MutiplatformUrls {
73 linux: Some("http://www.roudoudou.com/ACE-DL/BZen.tar.gz".to_string()),
74 windows: Some("http://www.roudoudou.com/ACE-DL/W64bnd4.zip".to_string()),
75 macos: None
76 })
77 },
78 AceVersion::ZenSummer => {
79 Ok(MutiplatformUrls {
80 linux: Some(
81 "http://www.roudoudou.com/ACE-DL/LinuxZenSummer.tar.gz".to_string()
82 ),
83 windows: Some("http://www.roudoudou.com/ACE-DL/Win64Summer.zip".to_string()),
84 macos: None
85 })
86 },
87 AceVersion::WakePoint => {
88 Ok(MutiplatformUrls {
89 linux: Some("http://www.roudoudou.com/ACE-DL/BZen.tar.gz".to_string()),
90 windows: Some("http://www.roudoudou.com/ACE-DL/BWIN64.zip".to_string()),
91 macos: Some("http://www.roudoudou.com/ACE-DL/BMAC.zip".to_string())
92 })
93 },
94 }
95 }
96}
97
98impl ExecutableInformation for AceVersion {
99 fn target_os_folder(&self) -> &'static str {
100 match self {
101 AceVersion::UnknownLastVersion => "UnknownLastAceVersion",
102 AceVersion::Bnd4 => "AceWakePoint",
103 AceVersion::ZenSummer => "AceBnd4",
104 AceVersion::WakePoint => "AceZenSummer"
105 }
106 }
107
108 fn target_os_exec_fname(&self) -> &'static str {
109 #[cfg(target_os = "windows")]
110 return "AceDL.exe";
111 #[cfg(target_os = "linux")]
112 return "AceDL";
113 }
114}
115
116impl InternetDynamicCompiledApplication for AceVersion {}
117
118impl AceVersion {
119 pub fn config_file(&self) -> Utf8PathBuf {
120 let p = match self {
121 Self::ZenSummer | Self::Bnd4 | Self::UnknownLastVersion => {
122 BaseDirs::new()
123 .unwrap()
124 .config_local_dir()
125 .join("ACE-DL_futuristics/config.cfg")
126 },
127 _ => unimplemented!()
128 };
129
130 Utf8PathBuf::from_path_buf(p).unwrap()
131 }
132}
133
134impl AceVersion {
135 pub fn screenshots_folder(&self) -> Utf8PathBuf {
136 let conf = self.configuration::<()>();
137
138 conf.cache_folder().join("export").join("screenshot")
139 }
140
141 pub fn roms_folder(&self) -> Utf8PathBuf {
142 let conf = self.configuration::<()>();
143
144 conf.cache_folder().join("media").join("rom")
145 }
146
147 pub fn albireo_folder(&self) -> Utf8PathBuf {
148 let conf = self.configuration::<()>();
149
150 conf.cache_folder().join("media").join("albireo1")
151 }
152}