1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-03-18 04:16:11 +00:00
UltimateTrainingModpack/src/common/release.rs
jugeeya bc3d2d8df5
Add rustfmt action (#265)
* Add rustfmt action

* Update rust.yml

* Format Rust code using rustfmt

* Update consts.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2021-09-14 14:05:48 -07:00

35 lines
1.3 KiB
Rust

use skyline_web::DialogOk;
use std::fs;
use std::io::Write;
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 {
// 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!");
}
let content = fs::read_to_string(fpath).unwrap_or_else(|_| "".to_string());
content == CURRENT_VERSION
}
fn record_current_version(fpath: &str) {
// Write the current version to the version file
let mut f = fs::File::create(fpath).unwrap();
write!(f, "{}", CURRENT_VERSION.to_owned()).expect("Could not record current version!");
}
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);
}
}