1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-03-14 02:16:10 +00:00

Version check for v3.3 (#344)

* Version check for v3.3

* Use enum instead of Option<bool>
This commit is contained in:
asimon-1 2022-05-08 18:48:13 -04:00 committed by GitHub
parent cef391b519
commit f948ceec53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,15 +4,24 @@ use std::fs;
pub const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION");
const VERSION_FILE_PATH: &str = "sd:/TrainingModpack/version.txt";
fn is_current_version(fpath: &str) -> bool {
enum VersionCheck {
Current,
NoFile,
Update,
}
fn is_current_version(fpath: &str) -> VersionCheck {
// Create a blank version file if it doesn't exists
if fs::metadata(fpath).is_err() {
let _ = fs::File::create(fpath).expect("Could not create version file!");
fs::File::create(fpath).expect("Could not create version file!");
return VersionCheck::NoFile;
}
fs::read_to_string(fpath)
.map(|content| content == CURRENT_VERSION)
.unwrap_or(false)
if fs::read_to_string(fpath).unwrap_or("".to_string()) == CURRENT_VERSION {
VersionCheck::Current
} else {
VersionCheck::Update
}
}
fn record_current_version(fpath: &str) {
@ -21,16 +30,36 @@ fn record_current_version(fpath: &str) {
}
pub fn version_check() {
// Display dialog box on launch if changing versions
if !is_current_version(VERSION_FILE_PATH) {
DialogOk::ok(
format!(
"Thank you for installing version {} of the Training Modpack.\n\n\
This version includes a change to the menu button combination, which is now SPECIAL+UPTAUNT.\n\
Please refer to the Github page and the Discord server for a full list of recent changes.",
CURRENT_VERSION
)
);
record_current_version(VERSION_FILE_PATH);
match is_current_version(VERSION_FILE_PATH) {
VersionCheck::Current => {
// Version is current, no need to take any action
}
VersionCheck::Update => {
// Display dialog box on launch if changing versions
DialogOk::ok(
format!(
"Thank you for installing version {} of the Training Modpack.\n\n\
Due to a breaking change in this version, your menu selections and defaults must be reset once.\n\n\
Please refer to the Github page and the Discord server for a full list of recent features, bugfixes, and other changes.",
CURRENT_VERSION
)
);
// Remove old menu selections, silently ignoring errors (i.e. if the file doesn't exist)
fs::remove_file("sd:/TrainingModpack/training_modpack_menu.conf").unwrap_or({});
fs::remove_file("sd:/TrainingModpack/training_modpack_menu_defaults.conf")
.unwrap_or({});
record_current_version(VERSION_FILE_PATH);
}
VersionCheck::NoFile => {
// Display dialog box on fresh installation
DialogOk::ok(
format!(
"Thank you for installing version {} of the Training Modpack.\n\n\
Please refer to the Github page and the Discord server for a full list of features and instructions on how to utilize the improved Training Mode.",
CURRENT_VERSION
)
);
record_current_version(VERSION_FILE_PATH);
}
}
}