cpclib_runner/runner/emulator/
amspirit.rs1use std::sync::OnceLock;
2
3use cpclib_common::event::EventObserver;
4
5use crate::delegated::{
6 ArchiveFormat, DelegateApplicationDescription, DownloadableInformation, ExecutableInformation,
7 InternetStaticCompiledApplication, MutiplatformUrls, StaticInformation
8};
9use crate::runner::runner::RunInDir;
10
11pub const AMSPIRIT_CMD: &str = "amspirit";
12
13#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
14pub enum AmspiritVersion {
15 #[default]
16 V2RC1,
17 Rc1_01
18}
19
20impl InternetStaticCompiledApplication for AmspiritVersion {}
21
22impl ExecutableInformation for AmspiritVersion {
23 fn target_os_folder(&self) -> &'static str {
24 match self {
25 Self::V2RC1 => "CPC_AMSpiriT_v2.00b_Win_x64",
26 Self::Rc1_01 => "CPC_AMSpiriT_RC_v1.01_Win_x64"
27 }
28 }
29
30 fn target_os_exec_fname(&self) -> &'static str {
31 match self {
32 Self::V2RC1 => "CPC_AMSpiriT_v2.00b_Win_x64\\Amspirit v2.00b_x64.exe",
33 Self::Rc1_01 => "CPC_AMSpiriT_RC_v1.01_Win_x64\\Amspirit_v1.01_RC_x64.exe"
34 }
35 }
36
37 fn target_os_run_in_dir(&self) -> RunInDir {
38 RunInDir::AppDir
39 }
40}
41
42impl StaticInformation for AmspiritVersion {
43 fn static_download_urls(&self) -> &'static MutiplatformUrls {
44 match self {
45 Self::V2RC1 => {
46 static URLS1: OnceLock<MutiplatformUrls> = OnceLock::new();
47 URLS1.get_or_init(|| MutiplatformUrls::unique_url("https://www.amspirit.fr/content/files/2025/07/CPC_AMSpiriT_v2_RC1_Win_x64.7z"))
48 },
49 Self::Rc1_01 => {
50 static URLS2: OnceLock<MutiplatformUrls> = OnceLock::new();
51 URLS2.get_or_init(|| MutiplatformUrls::unique_url("https://www.amspirit.fr/content/files/2024/04/CPC_AMSpiriT_RC_v1.01_Win_x64.7z"))
52 }
53 }
54 }
55}
56
57impl DownloadableInformation for AmspiritVersion {
58 fn target_os_archive_format(&self) -> ArchiveFormat {
59 ArchiveFormat::SevenZ
60 }
61
62 fn target_os_postinstall<E: EventObserver>(&self) -> Option<crate::delegated::PostInstall<E>> {
63 let owned_original = match self {
64 Self::Rc1_01 => "CPC_AMSpiriT_RC_v1.01_Win_x64/Amspirit v1.01_RC_x64.exe".to_owned(),
65 _ => {
66 return None;
67 }
68 };
69 let owned_result = self.target_os_exec_fname().to_owned();
70
71 let post_install: Box<dyn Fn(&DelegateApplicationDescription<E>) -> Result<(), String>> =
72 Box::new(move |d: &DelegateApplicationDescription<E>| {
73 std::fs::rename(
74 d.cache_folder().join(&owned_original),
75 d.cache_folder().join(&owned_result)
76 )
77 .map_err(|e| e.to_string())
78 });
79
80 Some(post_install.into())
81 }
82}