installer: Write checksum of modified update script to manifest
This prevent having to perform a redundant update on first startup.
This commit is contained in:
1 parent
f9f05aad08
commit
76b5449bad
3 files changed
+59
-3
No files matched your search
+5
-1
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## [Unreleased] - ReleaseDate
|
## [Unreleased] - ReleaseDate
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Avoid redundant update after initial download
|
||||||
|
|
||||||
## [0.2.9] - 2025-12-03
|
## [0.2.9] - 2025-12-03
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -133,8 +137,8 @@
|
|||||||
- First release
|
- First release
|
||||||
|
|
||||||
<!-- next-url -->
|
<!-- next-url -->
|
||||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.9...HEAD
|
|
||||||
|
|
||||||
|
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.9...HEAD
|
||||||
[0.2.9]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.8...v0.2.9
|
[0.2.9]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.8...v0.2.9
|
||||||
[0.2.8]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.7...v0.2.8
|
[0.2.8]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.7...v0.2.8
|
||||||
[0.2.7]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.6...v0.2.7
|
[0.2.7]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.6...v0.2.7
|
||||||
|
|||||||
+28
-2
@@ -6,6 +6,7 @@ use crate::{
|
|||||||
fonts::{Alignment, FontStyle, LayoutJob},
|
fonts::{Alignment, FontStyle, LayoutJob},
|
||||||
mode::{AppEvent, ModeFrameOutput, ModeTransition},
|
mode::{AppEvent, ModeFrameOutput, ModeTransition},
|
||||||
renderer::primitives::{ClippedPrimitive, DrawPrimitive, TextPrimitive},
|
renderer::primitives::{ClippedPrimitive, DrawPrimitive, TextPrimitive},
|
||||||
|
util::replace_in_matching_lines,
|
||||||
};
|
};
|
||||||
use flate2::read::GzDecoder;
|
use flate2::read::GzDecoder;
|
||||||
use parley::{FontFamily, GenericFamily};
|
use parley::{FontFamily, GenericFamily};
|
||||||
@@ -335,9 +336,9 @@ fn download_path_of_building<P: AsRef<Path>>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replaces UpdateCheck with rusty-path-of-building's custom version of it.
|
/// Replaces UpdateCheck with rusty-path-of-building's modified version
|
||||||
fn replace_updatecheck<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()> {
|
fn replace_updatecheck<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()> {
|
||||||
log::info!("Downloading custom UpdateCheck.lua script...");
|
log::info!("Downloading modified UpdateCheck.lua script...");
|
||||||
|
|
||||||
download_file(
|
download_file(
|
||||||
&format!(
|
&format!(
|
||||||
@@ -347,6 +348,31 @@ fn replace_updatecheck<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()> {
|
|||||||
target_dir.as_ref().join("UpdateCheck.lua"),
|
target_dir.as_ref().join("UpdateCheck.lua"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
// Replace original checksum with checksum of modified update script
|
||||||
|
let new_checksum = download_file_contents(&format!(
|
||||||
|
"https://raw.githubusercontent.com/{REPO_NAME}/main/{}",
|
||||||
|
"UpdateCheck.lua.sha1"
|
||||||
|
))?;
|
||||||
|
|
||||||
|
// file contains checksum followed by filename (separated by whitespace)
|
||||||
|
// we only need the checksum
|
||||||
|
let new_checksum = new_checksum
|
||||||
|
.split_whitespace()
|
||||||
|
.next()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("Invalid checksum file"))?;
|
||||||
|
|
||||||
|
let filename = target_dir.as_ref().join("manifest.xml");
|
||||||
|
let manifest = fs::read_to_string(&filename)?;
|
||||||
|
|
||||||
|
let new_manifest = replace_in_matching_lines(
|
||||||
|
&manifest,
|
||||||
|
r#"name="UpdateCheck.lua""#,
|
||||||
|
r#"sha1="([0-9A-Za-z]+)""#,
|
||||||
|
&format!(r#"sha1="{}""#, new_checksum),
|
||||||
|
);
|
||||||
|
|
||||||
|
fs::write(&filename, &new_manifest)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+26
@@ -27,3 +27,29 @@ pub fn calculate_hash<T: Hash>(t: &T) -> u64 {
|
|||||||
t.hash(&mut state);
|
t.hash(&mut state);
|
||||||
state.finish()
|
state.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Performs replacement only in lines that match a given pattern
|
||||||
|
pub fn replace_in_matching_lines(
|
||||||
|
input: &str,
|
||||||
|
match_pattern: &str,
|
||||||
|
replace_pattern: &str,
|
||||||
|
replacement_text: &str,
|
||||||
|
) -> String {
|
||||||
|
let match_re = regex::Regex::new(match_pattern).expect("Invalid match regex");
|
||||||
|
let replace_re = regex::Regex::new(replace_pattern).expect("Invalid replace regex");
|
||||||
|
|
||||||
|
let mut output = String::new();
|
||||||
|
for line in input.lines() {
|
||||||
|
dbg!(&line);
|
||||||
|
if match_re.is_match(line) {
|
||||||
|
// if line matches the pattern, replace
|
||||||
|
let replaced_line = replace_re.replace_all(line, replacement_text);
|
||||||
|
output.push_str(&replaced_line);
|
||||||
|
} else {
|
||||||
|
// otherwise, keep original line
|
||||||
|
output.push_str(line);
|
||||||
|
}
|
||||||
|
output.push('\n');
|
||||||
|
}
|
||||||
|
output
|
||||||
|
}
|
||||||
Reference in new issue
Block a user