Project files: read savedBy through craft-ecproj-format's Head

The craft-ecproj-format pin moves to storytold/craft-libs#409's new
head, where Head::read is the one reader and saved_by() is removed.
effectcraft-project's saved_by reads savedBy with Head::read, and from
ReadError::TooNew for a project with a newer schema.

saved_by now returns None for text that is not a JSON object with a u32
schema. EffectCraft calls it only on files Project::from_json opened,
so opening and importing projects are unchanged.
This commit is contained in:
dotCooCoo
2026-11-01 11:02:30 -08:00
parent 42b04479be
commit b133c0500f
4 changed files with 13 additions and 4 deletions
Generated
+1 -1
View File
@@ -1097,7 +1097,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13af
[[package]]
name = "craft-ecproj-format"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=246e8f837347ac642d6852df89e1425630111d21#246e8f837347ac642d6852df89e1425630111d21"
source = "git+https://github.com/storytold/craft-libs?rev=d74959fb9caca1c5fd393b4351026885b5ba0cc8#d74959fb9caca1c5fd393b4351026885b5ba0cc8"
dependencies = [
"serde",
"serde_json",
+1 -1
View File
@@ -14,7 +14,7 @@ repository = "https://github.com/storytold/effectcraft"
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.1.0", default-features = false, features = ["read"] }
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0" }
craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0" }
craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "246e8f837347ac642d6852df89e1425630111d21" }
craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "d74959fb9caca1c5fd393b4351026885b5ba0cc8" }
# craft-update: app-specific pretend versions apply to startup and manual checks.
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["egui"] }
# internal
+9 -2
View File
@@ -12,8 +12,15 @@ pub const SCHEMA_EFFECT_SPACE: u32 = 2;
/// The EffectCraft version, written into project files as `savedBy`.
pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
/// The EffectCraft version that wrote a project file (its `savedBy`), when it says.
pub use craft_ecproj_format::saved_by;
/// The EffectCraft version that wrote a project file (its `savedBy`), when it says, also for a
/// project whose schema is newer than [`SCHEMA_VERSION`].
pub fn saved_by(text: &str) -> Option<String> {
match craft_ecproj_format::Head::read(text) {
Ok(head) => head.saved_by,
Err(craft_ecproj_format::ReadError::TooNew { saved_by, .. }) => saved_by,
Err(_) => None,
}
}
/// The compositions that were open when a project file was saved and their current times
/// (`activeComp`, `openComps` and `compTimes` next to `savedBy`), so it reopens where it was left
+2
View File
@@ -162,6 +162,8 @@ fn project_files_name_their_version_and_always_read_back() {
assert!(text.trim_start().starts_with("{\n \"savedBy\""), "the version comes first");
assert_eq!(Project::from_json(&text).unwrap(), p);
assert_eq!(crate::saved_by(&p.to_json()), None, "plain JSON (worker hand-offs) has none");
assert_eq!(crate::saved_by(r#"{"savedBy": "999.0.0", "schema": 3}"#).as_deref(), Some("999.0.0"), "a newer schema still names its version");
assert_eq!(crate::saved_by(r#"[2, {}, {}, 1]"#), None, "the array form has none");
// JSON can't hold NaN: saving refuses instead of writing a file that can't be opened.
p.comp_mut(cid).unwrap().layers[0].props.prop_mut("transform/opacity").unwrap().value = Value::Scalar(f64::NAN);
let e = p.to_file_json().unwrap_err().to_string();