diff --git a/.gitattributes b/.gitattributes index 9792d556f..0ff3cca6d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,6 @@ # Preserve canonical source receipts and the runtime icon-discovery snapshot. .gitattributes text eol=lf /assets/icons/ui/design/requested_icons.txt text eol=lf +# SolidCraft designs (.sc): a JSON document or a ZIP container, never Scala source, so they +# stay out of GitHub's language statistics. Git's own text/binary detection handles both kinds. +*.sc -linguist-detectable diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index f8a52eb0e..6b89a0e23 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -19,7 +19,7 @@ body: attributes: label: Steps to reproduce description: | - What you clicked or typed, in order. For a problem on a particular design, `solidcraft-cli script design.solidcraft --out repro.json` turns its history into a script that `solidcraft-cli eval repro.json` replays; attach it, trimmed to the failing step if you can. + What you clicked or typed, in order. For a problem on a particular design, `solidcraft-cli script design.sc --out repro.json` turns its history into a script that `solidcraft-cli eval repro.json` replays; attach it, trimmed to the failing step if you can. Using an AI agent with SolidCraft's MCP server? The `solidcraft-reporting` skill in [`skills/`](https://github.com/tangency-labs/solidcraft/tree/main/skills) has it reproduce the problem in a fresh design and write these steps for you. placeholder: | 1. Sketch a circle on the XY plane diff --git a/README.md b/README.md index d7a9f9c1c..bc993fd47 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ other is a tracked bug. - **Parameters and configurations** with unit-aware expressions. - **Assemblies** with joints, motion studies, contact sets, interference and mass properties. - **Sheet metal** with flanges, hems, fold/unfold and flat patterns, and plastic enclosure features. -- **Files:** STEP, IGES, 3MF, STL, OBJ and glTF in and out where supported, URDF export, `.solidcraft` designs. +- **Files:** STEP, IGES, 3MF, STL, OBJ and glTF in and out where supported, URDF export, `.sc` designs (`.solidcraft` files from earlier releases still open). - **Desktop app, browser app, headless CLI and MCP server**, all running the same commands. The full list is in [docs/capabilities.md](docs/capabilities.md) and [docs/features.md](docs/features.md); diff --git a/apps/solidcraft-cli/examples/studio_evidence.rs b/apps/solidcraft-cli/examples/studio_evidence.rs index e6076443e..a78d95799 100644 --- a/apps/solidcraft-cli/examples/studio_evidence.rs +++ b/apps/solidcraft-cli/examples/studio_evidence.rs @@ -68,7 +68,7 @@ fn run() -> Result<(), String> { let generation_start = Instant::now(); let (commands, command_timings) = session.run_script_timed(&recipe, false).map_err(|e| e.to_string())?; let generation_seconds = generation_start.elapsed().as_secs_f64(); - let design_path = output.with_extension("solidcraft"); + let design_path = output.with_extension(solidcraft_engine::io::DESIGN_EXT); session.execute("file.save_as", &json!({"path":design_path})).map_err(|e| e.to_string())?; let scene = solidcraft_engine::product_scene::extract(&session).map_err(|e| e.to_string())?; let bodies: Vec = scene diff --git a/apps/solidcraft-cli/src/bench_agent.rs b/apps/solidcraft-cli/src/bench_agent.rs index d21867190..ec059c25c 100644 --- a/apps/solidcraft-cli/src/bench_agent.rs +++ b/apps/solidcraft-cli/src/bench_agent.rs @@ -8,7 +8,7 @@ //! no fixture. //! //! ```text -//! solidcraft-cli bench-agent [--scale F] [--script-out script.json] [--save design.solidcraft] +//! solidcraft-cli bench-agent [--scale F] [--script-out script.json] [--save design.sc] //! ``` //! prints one JSON line per hundred commands (mean and max milliseconds, bodies so far), then the //! build total, then the phases `bench-open` prints for the saved design. @@ -205,7 +205,10 @@ pub fn run(args: &[String]) -> Result<(), String> { ); let path = match flag("--save") { Some(p) => p.clone(), - None => std::env::temp_dir().join(format!("bench-agent-{}.solidcraft", std::process::id())).to_string_lossy().into_owned(), + None => std::env::temp_dir() + .join(format!("bench-agent-{}.{}", std::process::id(), solidcraft_engine::io::DESIGN_EXT)) + .to_string_lossy() + .into_owned(), }; s.execute("file.save", &json!({"path": path})).map_err(|e| e.to_string())?; let r = crate::cmd_bench_open(std::slice::from_ref(&path)); diff --git a/apps/solidcraft-cli/src/main.rs b/apps/solidcraft-cli/src/main.rs index 0558aeefe..ebba3484f 100644 --- a/apps/solidcraft-cli/src/main.rs +++ b/apps/solidcraft-cli/src/main.rs @@ -1,10 +1,10 @@ //! SolidCraft headless command line. //! //! ```text -//! solidcraft-cli run [--in design|part.step|mesh.3mf] [--out FILE]... [--save FILE] [--quiet] [--results] [--timings] [--profile] [--json-out FILE] [--allow-errors] -//! solidcraft-cli eval [--in design.solidcraft|part.step] [--json-out FILE] (alias: inspect) measurements as JSON -//! solidcraft-cli script [--out script.json] the design's history as a command script -//! solidcraft-cli bench-open [--parse-only] [--save OUT.solidcraft] [--display LEVEL [--edit NAME EXPR]] [--ops script.json] loading timings as JSON lines +//! solidcraft-cli run [--in design|part.step|mesh.3mf] [--out FILE]... [--save FILE] [--quiet] [--results] [--timings] [--profile] [--json-out FILE] [--allow-errors] +//! solidcraft-cli eval [--in design.sc|part.step] [--json-out FILE] (alias: inspect) measurements as JSON +//! solidcraft-cli script [--out script.json] the design's history as a command script +//! solidcraft-cli bench-open [--parse-only] [--save OUT.sc] [--display LEVEL [--edit NAME EXPR]] [--ops script.json] loading timings as JSON lines //! solidcraft-cli bench-agent [--scale F] [--save F] [--script-out F] a ~1,300-body design built command by command, timed //! solidcraft-cli bench-assistant --connect 127.0.0.1:PORT [--token T] --base-url URL --model NAME [--tasks 1,2,5] [--repeat N] //! [--timeout-s 300] [--json out.json] [--markdown out.md] @@ -56,19 +56,19 @@ struct Command { } /// `run`'s lines in the usage. -const USAGE_RUN: &str = " solidcraft-cli run [--in design.solidcraft|part.step] [--out FILE]... [--save FILE] [--quiet] [--results] [--timings] [--profile] [--json-out FILE] [--allow-errors]\n solidcraft-cli run --in [--out FILE]...\n (a timeline feature that fails fails the run and nothing is written; --allow-errors writes anyway)\n (--timings prints {timings: [{index, command, ms}], total_ms} for a script, with --results its results too;\n --profile adds each command's profile: {boolean_ms, tessellate_ms, other_ms}, the kernel's share)\n"; +const USAGE_RUN: &str = " solidcraft-cli run [--in design.sc|part.step] [--out FILE]... [--save FILE] [--quiet] [--results] [--timings] [--profile] [--json-out FILE] [--allow-errors]\n solidcraft-cli run --in [--out FILE]...\n (a timeline feature that fails fails the run and nothing is written; --allow-errors writes anyway)\n (--timings prints {timings: [{index, command, ms}], total_ms} for a script, with --results its results too;\n --profile adds each command's profile: {boolean_ms, tessellate_ms, other_ms}, the kernel's share)\n"; /// `eval`'s lines in the usage. -const USAGE_EVAL: &str = " solidcraft-cli eval [--in design.solidcraft|part.step] [--json-out FILE] (alias: inspect)\n solidcraft-cli eval --in [--json-out FILE]\n (with both inputs, runs the positional script on --in before measuring; does not automatically save the modified design)\n (--json-out FILE writes the JSON that run (with --results, else the measurement) and eval print to FILE instead of stdout,\n as plain UTF-8: a shell's > can re-encode it, e.g. Windows PowerShell adds a byte-order mark)\n"; +const USAGE_EVAL: &str = " solidcraft-cli eval [--in design.sc|part.step] [--json-out FILE] (alias: inspect)\n solidcraft-cli eval --in [--json-out FILE]\n (with both inputs, runs the positional script on --in before measuring; does not automatically save the modified design)\n (--json-out FILE writes the JSON that run (with --results, else the measurement) and eval print to FILE instead of stdout,\n as plain UTF-8: a shell's > can re-encode it, e.g. Windows PowerShell adds a byte-order mark)\n"; /// `script`'s lines in the usage. -const USAGE_SCRIPT: &str = " solidcraft-cli script [--out script.json]\n (the design's history as a command script that eval and run replay)\n"; +const USAGE_SCRIPT: &str = " solidcraft-cli script [--out script.json]\n (the design's history as a command script that eval and run replay)\n"; /// `bench-open`'s lines in the usage. -const USAGE_BENCH_OPEN: &str = " solidcraft-cli bench-open [--parse-only] [--save OUT.solidcraft] [--display LEVEL [--edit NAME EXPR]] [--ops script.json]\n (--ops: after opening, run each command of the script and undo it, timing the command, the\n evaluations it caused and the view it leaves: placing and meshing what changed)\n"; +const USAGE_BENCH_OPEN: &str = " solidcraft-cli bench-open [--parse-only] [--save OUT.sc] [--display LEVEL [--edit NAME EXPR]] [--ops script.json]\n (--ops: after opening, run each command of the script and undo it, timing the command, the\n evaluations it caused and the view it leaves: placing and meshing what changed)\n"; /// `bench-agent`'s lines in the usage. -const USAGE_BENCH_AGENT: &str = " solidcraft-cli bench-agent [--scale F] [--save design.solidcraft] [--script-out script.json]\n"; +const USAGE_BENCH_AGENT: &str = " solidcraft-cli bench-agent [--scale F] [--save design.sc] [--script-out script.json]\n"; /// `bench-assistant`'s lines in the usage. const USAGE_BENCH_ASSISTANT: &str = " solidcraft-cli bench-assistant --connect 127.0.0.1:PORT [--token T] --base-url URL --model NAME [--tasks 1,2,5] [--repeat N] [--timeout-s 300] [--json out.json] [--markdown out.md]\n"; /// `snapshot`'s lines in the usage. -const USAGE_SNAPSHOT: &str = " solidcraft-cli snapshot [--in design.solidcraft|part.step] --out shot.png [--width W] [--height H] [--view NAME | --camera JSON] [--no-grid] [--no-axes]\n [--body NAME:opacity=0.3,color=#rrggbb]... [--tool NAME]... [--section z=27]\n solidcraft-cli snapshot --in --out shot.png ...\n (as with run, --in starts from a design and the script runs on top of it; an option snapshot doesn't take is an error;\n --view: iso, front, back, top, bottom, left, right, or the name of a view saved in the design with view.save;\n --camera: {target: [x,y,z], yaw, pitch, distance, fov?} in mm and radians, as the MCP screenshot takes it (docs/mcp.md);\n --no-grid and --no-axes leave the ground grid (on Z 0) and the origin's axes out of the picture;\n --body: how one body is drawn, as appearance.assign takes it: opacity 0-1 (below 1 is see-through, so what is inside\n it shows) and color #rrggbb, either or both, once per body;\n --tool: draw this body solid in the tool colour and every other body see-through, so a cut's or a join's tool body\n is visible inside the material it meets; a later --body overrides it;\n --section: cut the model as inspect.section does, so the inside shows: z=27 (the plane through that world\n coordinate, keeping the smaller side), add ,flip to keep the other side, or XY, XZ, YZ, or its own JSON)\n"; +const USAGE_SNAPSHOT: &str = " solidcraft-cli snapshot [--in design.sc|part.step] --out shot.png [--width W] [--height H] [--view NAME | --camera JSON] [--no-grid] [--no-axes]\n [--body NAME:opacity=0.3,color=#rrggbb]... [--tool NAME]... [--section z=27]\n solidcraft-cli snapshot --in --out shot.png ...\n (as with run, --in starts from a design and the script runs on top of it; an option snapshot doesn't take is an error;\n --view: iso, front, back, top, bottom, left, right, or the name of a view saved in the design with view.save;\n --camera: {target: [x,y,z], yaw, pitch, distance, fov?} in mm and radians, as the MCP screenshot takes it (docs/mcp.md);\n --no-grid and --no-axes leave the ground grid (on Z 0) and the origin's axes out of the picture;\n --body: how one body is drawn, as appearance.assign takes it: opacity 0-1 (below 1 is see-through, so what is inside\n it shows) and color #rrggbb, either or both, once per body;\n --tool: draw this body solid in the tool colour and every other body see-through, so a cut's or a join's tool body\n is visible inside the material it meets; a later --body overrides it;\n --section: cut the model as inspect.section does, so the inside shows: z=27 (the plane through that world\n coordinate, keeping the smaller side), add ,flip to keep the other side, or XY, XZ, YZ, or its own JSON)\n"; /// `render`'s lines in the usage. const USAGE_RENDER: &str = " solidcraft-cli render --out image.png [--setup NAME] [--width W] [--height H] [--transparent] [--overwrite] [--timeout SECONDS]\n [--progressive] [--samples N] [--max-depth N] [--seed N] [--exposure EV] [--lighting FILE.json] [--environment FILE.json] [--tone-map reinhard|aces_fitted]\n"; /// `exec`'s lines in the usage. @@ -83,7 +83,7 @@ const USAGE_ORACLE: &str = " solidcraft-cli oracle ... [--json]\n"; const USAGE_FUZZ: &str = " solidcraft-cli fuzz [--from N] [--count N] [--jobs J] [--timeout S] [--steps N] [--minimise] [--out DIR] [--report FILE]\n"; /// `mcp`'s lines in the usage. -const USAGE_MCP: &str = " solidcraft-cli mcp [--headless] [--in design.solidcraft|script.json] [--connect 127.0.0.1:PORT [--token T]] [--allow-path DIR]... [--allow-any-path]\n [--param-check off|warn|strict] [--render-gpu]\n solidcraft-cli mcp setup [--dry-run] [--client opencode|claude-desktop|claude-code|cursor] [--live]\n (adds a `solidcraft` server, with this program's path, to each installed AI client; --live adds `solidcraft-live` for the running app; alias: mcp install)\n"; +const USAGE_MCP: &str = " solidcraft-cli mcp [--headless] [--in design.sc|script.json] [--connect 127.0.0.1:PORT [--token T]] [--allow-path DIR]... [--allow-any-path]\n [--param-check off|warn|strict] [--render-gpu]\n solidcraft-cli mcp setup [--dry-run] [--client opencode|claude-desktop|claude-code|cursor] [--live]\n (adds a `solidcraft` server, with this program's path, to each installed AI client; --live adds `solidcraft-live` for the running app; alias: mcp install)\n"; /// `crashes`'s lines in the usage. const USAGE_CRASHES: &str = " solidcraft-cli crashes [list [--json] | show | replay | dir | clear []]\n"; /// `licences`'s lines in the usage. @@ -817,7 +817,7 @@ fn bench_ops(mut s: Session, script: &str) -> Result { /// Separate file reading, JSON decoding/repair, timeline evaluation and display meshing. pub(crate) fn cmd_bench_open(args: &[String]) -> Result<(), String> { - let path = args.first().ok_or("usage: solidcraft-cli bench-open [--parse-only]")?; + let path = args.first().ok_or("usage: solidcraft-cli bench-open [--parse-only]")?; let t = std::time::Instant::now(); let step = solidcraft_engine::io::is_step_path(path); let limit = if step { solidcraft_engine::io::MAX_STEP_BYTES } else { solidcraft_engine::io::MAX_DESIGN_BYTES }; @@ -863,13 +863,13 @@ pub(crate) fn cmd_bench_open(args: &[String]) -> Result<(), String> { json!({"step": "mesh", "ms": t.elapsed().as_secs_f64() * 1000.0, "place_ms": place_ms, "bodies": st.bodies.len(), "triangles": triangles}) ); let flag = |name: &str| args.iter().position(|a| a == name); - // `--save PATH`: save the opened design without its model cache (to PATH.plain.solidcraft) and + // `--save PATH`: save the opened design without its model cache (to PATH.plain.sc) and // as the app does, with it, then read the cache back. let s = match flag("--save").and_then(|i| args.get(i + 1)) { Some(out) => { let mut s = s; // Without the cache first, for comparison. - let plain = format!("{out}.plain.solidcraft"); + let plain = format!("{out}.plain.{}", solidcraft_engine::io::DESIGN_EXT); let t = std::time::Instant::now(); s.execute("file.save_as", &json!({"path": plain, "cache": false})).map_err(|e| e.to_string())?; let plain_ms = t.elapsed().as_secs_f64() * 1000.0; diff --git a/apps/solidcraft-cli/tests/action_matrix.rs b/apps/solidcraft-cli/tests/action_matrix.rs index 21c34a8b6..fecbcc267 100644 --- a/apps/solidcraft-cli/tests/action_matrix.rs +++ b/apps/solidcraft-cli/tests/action_matrix.rs @@ -92,7 +92,7 @@ fn designs() -> Vec<(String, PathBuf)> { add("regressions", root.join("examples/regressions"), "json"); add("demo", root.join("examples/demo"), "json"); add("typical", root.join("tests/action_matrix/designs"), "json"); - add("demo", root.join("tests/action_matrix/designs"), "solidcraft"); + add("demo", root.join("tests/action_matrix/designs"), solidcraft_engine::io::DESIGN_EXT); let mut cases: Vec = std::fs::read_dir(root.join("tests/oracle")).unwrap().flatten().map(|e| e.path()).filter(|p| p.join("recipe.json").is_file()).collect(); cases.sort(); @@ -105,7 +105,7 @@ fn designs() -> Vec<(String, PathBuf)> { /// Build a design from its file. fn load(path: &Path) -> Result { let mut s = Session::default(); - if path.extension().is_some_and(|x| x == "solidcraft") { + if solidcraft_engine::io::is_design_container_path(path) { s.execute("doc.open", &json!({"path": path.to_string_lossy()})).map_err(|e| e.to_string())?; return Ok(s); } @@ -1558,7 +1558,7 @@ fn sketches_on_loft_and_sweep_faces() { #[test] fn press_pull_on_the_pi_case_floor() { reproduces( - Some("tests/action_matrix/designs/pi-case.solidcraft"), + Some("tests/action_matrix/designs/pi-case.sc"), json!([{"command": "solid.press_pull", "params": {"face": [30, 20, 0], "distance": 1}}]), ); } diff --git a/apps/solidcraft-cli/tests/rebuild_topology.rs b/apps/solidcraft-cli/tests/rebuild_topology.rs index f097b3f4b..26721787b 100644 --- a/apps/solidcraft-cli/tests/rebuild_topology.rs +++ b/apps/solidcraft-cli/tests/rebuild_topology.rs @@ -75,12 +75,15 @@ fn designs() -> Vec<(String, Session)> { .unwrap() .flatten() .map(|e| e.path()) - .filter(|p| p.extension().is_some_and(|x| x == "solidcraft" || x == "json") && !p.to_string_lossy().ends_with(".expected.json")) + .filter(|p| { + (solidcraft_engine::io::is_design_container_path(p) || p.extension().is_some_and(|x| x == "json")) + && !p.to_string_lossy().ends_with(".expected.json") + }) .collect(); files.sort(); for p in files { let name = p.file_stem().unwrap_or_default().to_string_lossy().to_string(); - let s = if p.extension().is_some_and(|x| x == "solidcraft") { + let s = if solidcraft_engine::io::is_design_container_path(&p) { open(&p) } else { let mut s = Session::default(); @@ -150,7 +153,7 @@ fn pi_case_faces_per_step_at_both_heights() { const FACES: [(usize, usize); 13] = [(2, 6), (3, 10), (4, 19), (5, 19), (6, 25), (7, 43), (8, 43), (9, 55), (10, 55), (11, 59), (12, 59), (13, 63), (14, 79)]; let dir = scratch_dir("pi"); - let design: Value = serde_json::from_slice(&std::fs::read(root().join("tests/action_matrix/designs/pi-case.solidcraft")).unwrap()).unwrap(); + let design: Value = serde_json::from_slice(&std::fs::read(root().join("tests/action_matrix/designs/pi-case.sc")).unwrap()).unwrap(); let at = |height: &str, file: &str| { let mut d = design.clone(); for p in d["params"].as_array_mut().unwrap() { diff --git a/apps/solidcraft-cli/tests/run_results.rs b/apps/solidcraft-cli/tests/run_results.rs index 386aada99..4534a1ebb 100644 --- a/apps/solidcraft-cli/tests/run_results.rs +++ b/apps/solidcraft-cli/tests/run_results.rs @@ -145,7 +145,7 @@ fn eval_and_inspect_reject_invalid_options_before_script_execution_or_reporting( #[test] fn cli_loads_both_design_encodings_by_contents() { let dir = Scratch::new(); - for extension in ["solidcraft", "solvecraft", "json"] { + for extension in ["sc", "solidcraft", "solvecraft", "json"] { let saved = dir.0.join(format!("box.{extension}")); json_output(cli().arg("run").arg(dir.script()).arg("--save").arg(&saved).output().unwrap()); let bytes = std::fs::read(&saved).unwrap(); @@ -412,6 +412,11 @@ fn legacy_extension_and_format_tag_still_open() { assert_eq!(body_count(&resaved), 2); let reopened = solidcraft_engine::io::read_design(&std::fs::read(&resaved).unwrap()).unwrap(); assert!(reopened.to_json().contains("\"solidcraft/")); + // `.solidcraft` (before `.sc`) opens as `--in` and as the design to evaluate; `.sc` too. + let current = dir.0.join("current.sc"); + json_output(cli().args(["run", "--in"]).arg(&resaved).arg(dir.script()).arg("--save").arg(¤t).output().unwrap()); + assert_eq!(body_count(¤t), 3); + assert!(solidcraft_engine::io::is_design_container(&std::fs::read(¤t).unwrap()), "a .sc file is a design container"); } /// `snapshot` starts from `--in` as `run` does (its script runs on that design), and refuses an diff --git a/apps/solidcraft-cli/tests/straight_edges_after_cuts.rs b/apps/solidcraft-cli/tests/straight_edges_after_cuts.rs index a52a24a18..14a42c93d 100644 --- a/apps/solidcraft-cli/tests/straight_edges_after_cuts.rs +++ b/apps/solidcraft-cli/tests/straight_edges_after_cuts.rs @@ -1,5 +1,5 @@ //! Straight edges stay one edge after many cuts (#1049). The owner's design -//! (`tests/action_matrix/designs/crazy-geom-cuts.solidcraft`, saved by 0.10.0): five extrudes, +//! (`tests/action_matrix/designs/crazy-geom-cuts.sc`, saved by 0.10.0): five extrudes, //! joins and cuts, over four sketches, three of them on faces of the body with the faces' //! edges projected. Cuts used to leave the straight edges of the walls they sliced split at //! vertices nothing else used, so an edge that is one straight line was drawn (and lit on hover) @@ -14,7 +14,7 @@ use solidcraft_engine::doc::kernel::{FaceSurface, face_surface}; use solidcraft_engine::geom::Vec3; fn design() -> PathBuf { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/action_matrix/designs/crazy-geom-cuts.solidcraft") + Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/action_matrix/designs/crazy-geom-cuts.sc") } fn open(path: &Path) -> Session { diff --git a/apps/solidcraft-web/src/disk.rs b/apps/solidcraft-web/src/disk.rs index ef058f811..13089700b 100644 --- a/apps/solidcraft-web/src/disk.rs +++ b/apps/solidcraft-web/src/disk.rs @@ -169,10 +169,15 @@ pub fn upload_limit(extensions: &[&str]) -> Option { (!extensions.is_empty() && extensions.iter().all(image)).then_some(solidcraft_engine::doc::canvas::MAX_CANVAS_BYTES) } -/// The file type a Save As dialog offers for `name`: (description, MIME type, extension). -pub fn save_type(name: &str) -> (&'static str, &'static str, &'static str) { - let json = std::path::Path::new(name).extension().is_some_and(|e| e.eq_ignore_ascii_case("json")); - if json { ("Plain JSON design", "application/json", ".json") } else { ("SolidCraft design", "application/octet-stream", ".solidcraft") } +/// The file type a Save As dialog offers for `name`: (description, MIME type, extension). A +/// design is `.sc` unless the name already has an older design extension, which it keeps. +pub fn save_type(name: &str) -> (&'static str, &'static str, String) { + let ext = std::path::Path::new(name).extension().and_then(|e| e.to_str()).map(str::to_ascii_lowercase); + match ext.as_deref() { + Some("json") => ("Plain JSON design", "application/json", ".json".into()), + Some(e) if solidcraft_engine::io::is_design_ext(e) => ("SolidCraft design", "application/octet-stream", format!(".{e}")), + _ => ("SolidCraft design", "application/octet-stream", format!(".{}", solidcraft_engine::io::DESIGN_EXT)), + } } /// Is this a cancelled dialog (the browser's `AbortError`)? Not an error to show. @@ -264,7 +269,7 @@ mod web { let options = Object::new(); let _ = Reflect::set(&options, &"suggestedName".into(), &name.into()); let (description, mime, extension) = save_type(name); - let _ = Reflect::set(&options, &"types".into(), &types(description, mime, extension)); + let _ = Reflect::set(&options, &"types".into(), &types(description, mime, &extension)); options } @@ -349,7 +354,9 @@ mod web { let options = Object::new(); let _ = Reflect::set(&options, &"multiple".into(), &JsValue::FALSE); let extensions = Array::new(); - for e in [".solidcraft", ".solvecraft", ".json", ".step", ".stp", ".3mf", ".stl", ".obj", ".glb", ".gltf", ".fcstd", ".3dm", ".dxf", ".svg"] { + let designs = solidcraft_engine::io::DESIGN_EXTS.iter().map(|e| format!(".{e}")); + let others = [".json", ".step", ".stp", ".3mf", ".stl", ".obj", ".glb", ".gltf", ".fcstd", ".3dm", ".dxf", ".svg"].map(String::from); + for e in designs.chain(others) { extensions.push(&e.into()); } let accept = Object::new(); @@ -667,6 +674,7 @@ mod tests { #[test] fn only_design_opens_use_the_disk_dialog() { assert!(opens_design(&[])); + assert!(opens_design(&["sc"])); assert!(opens_design(&["solidcraft"])); assert!(opens_design(&["solvecraft"])); assert!(!opens_design(&["step", "stp"])); @@ -710,9 +718,11 @@ mod tests { #[test] fn the_save_dialog_offers_the_type_of_the_name() { - assert_eq!(save_type("Plate.solidcraft").2, ".solidcraft"); + assert_eq!(save_type("Plate.sc").2, ".sc"); assert_eq!(save_type("Plate.JSON").2, ".json"); - assert_eq!(save_type("Plate").2, ".solidcraft"); + assert_eq!(save_type("Plate").2, ".sc"); + // A design opened under an older extension keeps it. + assert_eq!(save_type("Plate.solidcraft").2, ".solidcraft"); } #[test] diff --git a/apps/solidcraft-web/src/files.rs b/apps/solidcraft-web/src/files.rs index 0f610567c..4e42f1d18 100644 --- a/apps/solidcraft-web/src/files.rs +++ b/apps/solidcraft-web/src/files.rs @@ -24,11 +24,13 @@ pub const OPFS: &str = disk::OPFS_PREFIX; pub const DOWNLOADS: &str = disk::DOWNLOADS_PREFIX; /// Files brought in from the computer. pub const UPLOAD: &str = "/upload/"; -/// The autosave of unsaved work (in OPFS: `recovery.solidcraft` and `recovery.json`). -const RECOVERY: &str = "recovery.solidcraft"; -/// The autosave earlier releases kept (compatibility shim, docs/compatibility.md): recovered -/// when there is no current one. -const LEGACY_RECOVERY: &str = "recovery.solvecraft"; +/// The autosave of unsaved work (in OPFS: `recovery.sc` and `recovery.json`), named with +/// `solidcraft_engine::io::DESIGN_EXT`. +const RECOVERY: &str = "recovery.sc"; +/// The autosaves earlier releases kept, newest first, one per entry of +/// `solidcraft_engine::io::LEGACY_DESIGN_EXTS` (compatibility shim, docs/compatibility.md): the +/// newest is recovered when there is no current one. +const LEGACY_RECOVERY: [&str; 2] = ["recovery.solidcraft", "recovery.solvecraft"]; const RECOVERY_META: &str = "recovery.json"; /// What to do with a file brought in from the computer. @@ -282,9 +284,10 @@ pub fn start(files: &Rc) { } let mut entries = Vec::new(); let has_recovery = all.iter().any(|(n, _, _)| n == RECOVERY); + let legacy = (!has_recovery).then(|| LEGACY_RECOVERY.into_iter().find(|l| all.iter().any(|(n, _, _)| n == l))).flatten(); for (name, bytes, modified) in all { - if name == LEGACY_RECOVERY { - if !has_recovery { + if LEGACY_RECOVERY.contains(&name.as_str()) { + if legacy == Some(name.as_str()) { vfs::insert(&format!("{OPFS}{RECOVERY}"), bytes); } continue; @@ -424,7 +427,9 @@ pub fn autosave(files: &Rc, doc: Option<(&solidcraft_engine::doc::Documen } None => spawn_local(async move { let _ = remove_file(RECOVERY).await; - let _ = remove_file(LEGACY_RECOVERY).await; + for legacy in LEGACY_RECOVERY { + let _ = remove_file(legacy).await; + } let _ = remove_file(RECOVERY_META).await; }), } diff --git a/apps/solidcraft-web/src/linked.rs b/apps/solidcraft-web/src/linked.rs index c1c46a841..24e073d5d 100644 --- a/apps/solidcraft-web/src/linked.rs +++ b/apps/solidcraft-web/src/linked.rs @@ -72,10 +72,10 @@ impl Download { } let Some((name, bytes)) = self.pending.take() else { return }; // The extension selects the design loader even when the URL has no extension. - let path = "/linked/design.solidcraft"; + let path = &format!("/linked/design.{}", solidcraft_engine::io::DESIGN_EXT); vfs::insert(path, bytes); app.open_path(path); - if app.session.path.as_deref() == Some(path) { + if app.session.path.as_deref() == Some(path.as_str()) { app.session.path = None; app.session.doc_mut().name = name; app.session.mark_unsaved(); @@ -90,9 +90,14 @@ async fn fetch(value: &str) -> Reply { let window = web_sys::window().ok_or("No browser window")?; let page_origin = window.location().origin().map_err(|_| "Cannot read page origin")?; let url = design_url(value, &page_origin)?; - let name = url.path_segments().and_then(|mut segments| segments.next_back()).filter(|name| !name.is_empty()).unwrap_or("Design.solidcraft"); + let name = url.path_segments().and_then(|mut segments| segments.next_back()).filter(|name| !name.is_empty()).unwrap_or("Design"); let decoded = js_sys::decode_uri_component(name).ok().and_then(|name| name.as_string()).unwrap_or_else(|| name.to_owned()); - let name: String = decoded.strip_suffix(".solidcraft").unwrap_or(&decoded).chars().take(255).collect(); + // `arm.sc` (or a legacy `arm.solidcraft`) is named `arm`. + let stem = match decoded.rsplit_once('.') { + Some((stem, ext)) if !stem.is_empty() && solidcraft_engine::io::is_design_ext(ext) => stem, + _ => decoded.as_str(), + }; + let name: String = stem.chars().take(255).collect(); let response = JsFuture::from(window.fetch_with_str(url.as_str())).await.map_err(|_| "Network request failed or the host refused CORS access")?; let response: web_sys::Response = response.dyn_into().map_err(|_| "Invalid download response")?; design_url(&response.url(), &page_origin).map_err(|_| "Design redirected to a URL that does not use HTTPS or the page's own origin")?; diff --git a/apps/solidcraft/src/main.rs b/apps/solidcraft/src/main.rs index fadaeb9e7..4b4f148cd 100644 --- a/apps/solidcraft/src/main.rs +++ b/apps/solidcraft/src/main.rs @@ -1,6 +1,6 @@ //! SolidCraft desktop app. //! -//! Usage: `solidcraft [--control ] [--sample] [--crash-log] [--safe-mode] [design.solidcraft | part.step]` +//! Usage: `solidcraft [--control ] [--sample] [--crash-log] [--safe-mode] [design.sc | part.step]` //! //! `--safe-mode` (or `SOLIDCRAFT_SAFE_MODE=1`) starts with default settings, no recovery offer and //! the software renderer; see `startup` and docs/book/src/guide/troubleshooting.md. @@ -778,7 +778,7 @@ fn main() -> eframe::Result { } "--help" | "-h" => { println!( - "usage: solidcraft [--control PORT] [--sample] [--theme-file THEME.json] [--crash-log] [--safe-mode] [design.solidcraft | part.step]" + "usage: solidcraft [--control PORT] [--sample] [--theme-file THEME.json] [--crash-log] [--safe-mode] [design.sc | part.step]" ); return Ok(()); } diff --git a/assets/locales/cs.json b/assets/locales/cs.json index 6264c3dbd..5f9b85109 100644 --- a/assets/locales/cs.json +++ b/assets/locales/cs.json @@ -903,7 +903,7 @@ "home.new_mm": "Nový návrh", "home.new_mm_hint": "Milimetry · otevře se v pracovním prostoru Návrh", "home.open": "Otevřít…", - "home.open_hint": "Návrh ve formátu .solidcraft ({shortcut})", + "home.open_hint": "Návrh ve formátu .sc ({shortcut})", "home.open_now": "Otevřít nyní", "home.opened_days_ago": "Před {count} dny", "home.opened_hours_ago": "Před {count} h", diff --git a/assets/locales/da.json b/assets/locales/da.json index d2c16ee77..f63a3c013 100644 --- a/assets/locales/da.json +++ b/assets/locales/da.json @@ -1106,7 +1106,7 @@ "home.new_mm": "Nyt design", "home.new_mm_hint": "Millimeter · åbner i Design", "home.open": "Åbn…", - "home.open_hint": "Et .solidcraft-design ({shortcut})", + "home.open_hint": "Et .sc-design ({shortcut})", "home.open_now": "Åbn nu", "home.opened_days_ago": "For {count} dage siden", "home.opened_hours_ago": "For {count} t siden", diff --git a/assets/locales/de.json b/assets/locales/de.json index a5c61e47c..e58f01e71 100644 --- a/assets/locales/de.json +++ b/assets/locales/de.json @@ -1229,7 +1229,7 @@ "home.new_mm": "Neuer Entwurf", "home.new_mm_hint": "Millimeter · öffnet sich im Arbeitsbereich Entwurf", "home.open": "Öffnen…", - "home.open_hint": "Ein .solidcraft-Entwurf ({shortcut})", + "home.open_hint": "Ein .sc-Entwurf ({shortcut})", "home.open_now": "Jetzt öffnen", "home.opened_days_ago": "Vor {count} Tagen", "home.opened_hours_ago": "Vor {count} Std.", diff --git a/assets/locales/en.json b/assets/locales/en.json index 9ee9821d4..d080c7cde 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -1291,7 +1291,7 @@ "home.new_mm": "New design", "home.new_mm_hint": "Millimetres · opens in Design", "home.open": "Open…", - "home.open_hint": "A .solidcraft design ({shortcut})", + "home.open_hint": "A .sc design ({shortcut})", "home.open_now": "Open now", "home.opened_days_ago": "{count} days ago", "home.opened_hours_ago": "{count} h ago", diff --git a/assets/locales/es.json b/assets/locales/es.json index 437e035a0..690e6d93f 100644 --- a/assets/locales/es.json +++ b/assets/locales/es.json @@ -944,7 +944,7 @@ "home.new_mm": "Nuevo diseño", "home.new_mm_hint": "Milímetros · se abre en Diseño", "home.open": "Abrir…", - "home.open_hint": "Un diseño .solidcraft ({shortcut})", + "home.open_hint": "Un diseño .sc ({shortcut})", "home.open_now": "Abrir ahora", "home.opened_days_ago": "Hace {count} días", "home.opened_hours_ago": "Hace {count} h", diff --git a/assets/locales/fr.json b/assets/locales/fr.json index f7c4d1d73..fe33975cb 100644 --- a/assets/locales/fr.json +++ b/assets/locales/fr.json @@ -1227,7 +1227,7 @@ "home.new_mm": "Nouvelle conception", "home.new_mm_hint": "Millimètres · ouvre l’espace Conception", "home.open": "Ouvrir…", - "home.open_hint": "Une conception .solidcraft ({shortcut})", + "home.open_hint": "Une conception .sc ({shortcut})", "home.open_now": "Ouvrir maintenant", "home.opened_days_ago": "Il y a {count} j", "home.opened_hours_ago": "Il y a {count} h", diff --git a/assets/locales/gl.json b/assets/locales/gl.json index 36fce7862..383d0b49a 100644 --- a/assets/locales/gl.json +++ b/assets/locales/gl.json @@ -900,7 +900,7 @@ "home.new_mm": "Novo deseño", "home.new_mm_hint": "Milímetros · ábrese en Deseño", "home.open": "Abrir…", - "home.open_hint": "Un deseño .solidcraft ({shortcut})", + "home.open_hint": "Un deseño .sc ({shortcut})", "home.open_now": "Abrir agora", "home.opened_days_ago": "Hai {count} días", "home.opened_hours_ago": "Hai {count} h", diff --git a/assets/locales/hu.json b/assets/locales/hu.json index bc80dcffd..ccbd20e17 100644 --- a/assets/locales/hu.json +++ b/assets/locales/hu.json @@ -899,7 +899,7 @@ "home.new_mm": "Új terv", "home.new_mm_hint": "Milliméter · a Tervezés munkaterületen nyílik meg", "home.open": "Megnyitás…", - "home.open_hint": "Egy .solidcraft terv ({shortcut})", + "home.open_hint": "Egy .sc terv ({shortcut})", "home.open_now": "Jelenleg megnyitva", "home.opened_days_ago": "{count} napja", "home.opened_hours_ago": "{count} órája", diff --git a/assets/locales/id.json b/assets/locales/id.json index c4c92ddc2..cf783d7b1 100644 --- a/assets/locales/id.json +++ b/assets/locales/id.json @@ -899,7 +899,7 @@ "home.new_mm": "Desain baru", "home.new_mm_hint": "Milimeter · terbuka di Desain", "home.open": "Buka…", - "home.open_hint": "Desain .solidcraft ({shortcut})", + "home.open_hint": "Desain .sc ({shortcut})", "home.open_now": "Sedang terbuka", "home.opened_days_ago": "{count} hari lalu", "home.opened_hours_ago": "{count} jam lalu", diff --git a/assets/locales/it.json b/assets/locales/it.json index f2de87899..8bdd33bb9 100644 --- a/assets/locales/it.json +++ b/assets/locales/it.json @@ -925,7 +925,7 @@ "home.new_mm": "Nuovo progetto", "home.new_mm_hint": "Millimetri · si apre in Progettazione", "home.open": "Apri…", - "home.open_hint": "Un progetto .solidcraft ({shortcut})", + "home.open_hint": "Un progetto .sc ({shortcut})", "home.open_now": "Apri ora", "home.opened_days_ago": "{count} giorni fa", "home.opened_hours_ago": "{count} h fa", diff --git a/assets/locales/ja.json b/assets/locales/ja.json index 408c56227..cf5fc021b 100644 --- a/assets/locales/ja.json +++ b/assets/locales/ja.json @@ -1291,7 +1291,7 @@ "home.new_mm": "新しいデザイン", "home.new_mm_hint": "ミリメートル · デザインで開きます", "home.open": "開く…", - "home.open_hint": ".solidcraft 形式のデザイン ({shortcut})", + "home.open_hint": ".sc 形式のデザイン ({shortcut})", "home.open_now": "今すぐ開く", "home.opened_days_ago": "{count} 日前", "home.opened_hours_ago": "{count} 時間前", diff --git a/assets/locales/ko.json b/assets/locales/ko.json index 0ba68fdfc..78d65df30 100644 --- a/assets/locales/ko.json +++ b/assets/locales/ko.json @@ -1092,7 +1092,7 @@ "home.new_mm": "새 설계", "home.new_mm_hint": "밀리미터 · 설계 작업 공간에서 열기", "home.open": "열기…", - "home.open_hint": ".solidcraft 설계 ({shortcut})", + "home.open_hint": ".sc 설계 ({shortcut})", "home.open_now": "지금 열기", "home.opened_days_ago": "{count}일 전", "home.opened_hours_ago": "{count}시간 전", diff --git a/assets/locales/ms.json b/assets/locales/ms.json index 349282cd4..5c7b908e8 100644 --- a/assets/locales/ms.json +++ b/assets/locales/ms.json @@ -900,7 +900,7 @@ "home.new_mm": "Reka bentuk baharu", "home.new_mm_hint": "Milimeter · dibuka dalam Reka Bentuk", "home.open": "Buka…", - "home.open_hint": "Reka bentuk .solidcraft ({shortcut})", + "home.open_hint": "Reka bentuk .sc ({shortcut})", "home.open_now": "Buka sekarang", "home.opened_days_ago": "{count} hari lalu", "home.opened_hours_ago": "{count} jam lalu", diff --git a/assets/locales/nb.json b/assets/locales/nb.json index d758cc12f..e2aaac972 100644 --- a/assets/locales/nb.json +++ b/assets/locales/nb.json @@ -1053,7 +1053,7 @@ "home.new_mm": "Nytt design", "home.new_mm_hint": "Millimeter · åpnes i Design", "home.open": "Åpne…", - "home.open_hint": "Et .solidcraft-design ({shortcut})", + "home.open_hint": "Et .sc-design ({shortcut})", "home.open_now": "Åpne nå", "home.opened_days_ago": "for {count} dager siden", "home.opened_hours_ago": "for {count} t siden", diff --git a/assets/locales/nl.json b/assets/locales/nl.json index 7a6e5181e..aa99457f3 100644 --- a/assets/locales/nl.json +++ b/assets/locales/nl.json @@ -899,7 +899,7 @@ "home.new_mm": "Nieuw ontwerp", "home.new_mm_hint": "Millimeters · opent in Ontwerp", "home.open": "Openen…", - "home.open_hint": "Een .solidcraft-ontwerp ({shortcut})", + "home.open_hint": "Een .sc-ontwerp ({shortcut})", "home.open_now": "Momenteel geopend", "home.opened_days_ago": "{count} dagen geleden", "home.opened_hours_ago": "{count} u geleden", diff --git a/assets/locales/pl.json b/assets/locales/pl.json index 2aed9f1fe..1a3a5264b 100644 --- a/assets/locales/pl.json +++ b/assets/locales/pl.json @@ -961,7 +961,7 @@ "home.new_mm": "Nowy projekt", "home.new_mm_hint": "Milimetry · otwiera w obszarze Projektowanie", "home.open": "Otwórz…", - "home.open_hint": "Projekt .solidcraft ({shortcut})", + "home.open_hint": "Projekt .sc ({shortcut})", "home.open_now": "Otwórz teraz", "home.opened_days_ago": "{count} dni temu", "home.opened_hours_ago": "{count} godz. temu", diff --git a/assets/locales/pt-BR.json b/assets/locales/pt-BR.json index 8545d4f20..b994732bd 100644 --- a/assets/locales/pt-BR.json +++ b/assets/locales/pt-BR.json @@ -1074,7 +1074,7 @@ "home.new_mm": "Novo projeto", "home.new_mm_hint": "Milímetros · abre em Projeto", "home.open": "Abrir…", - "home.open_hint": "Um projeto .solidcraft ({shortcut})", + "home.open_hint": "Um projeto .sc ({shortcut})", "home.open_now": "Abrir agora", "home.opened_days_ago": "Há {count} dias", "home.opened_hours_ago": "Há {count} h", diff --git a/assets/locales/ro.json b/assets/locales/ro.json index 345c8bd31..b3726458b 100644 --- a/assets/locales/ro.json +++ b/assets/locales/ro.json @@ -899,7 +899,7 @@ "home.new_mm": "Proiect nou", "home.new_mm_hint": "Milimetri · se deschide în Proiectare", "home.open": "Deschide…", - "home.open_hint": "Un proiect .solidcraft ({shortcut})", + "home.open_hint": "Un proiect .sc ({shortcut})", "home.open_now": "Deschis acum", "home.opened_days_ago": "Acum {count} zile", "home.opened_hours_ago": "Acum {count} h", diff --git a/assets/locales/ru.json b/assets/locales/ru.json index d7b3acf76..4951d5e08 100644 --- a/assets/locales/ru.json +++ b/assets/locales/ru.json @@ -899,7 +899,7 @@ "home.new_mm": "Новый проект", "home.new_mm_hint": "Миллиметры · откроется в рабочей области «Проектирование»", "home.open": "Открыть…", - "home.open_hint": "Проект .solidcraft ({shortcut})", + "home.open_hint": "Проект .sc ({shortcut})", "home.open_now": "Открыть сейчас", "home.opened_days_ago": "{count} дн. назад", "home.opened_hours_ago": "{count} ч назад", diff --git a/assets/locales/sv.json b/assets/locales/sv.json index 330f87132..9b35f1f4c 100644 --- a/assets/locales/sv.json +++ b/assets/locales/sv.json @@ -899,7 +899,7 @@ "home.new_mm": "Ny konstruktion", "home.new_mm_hint": "Millimeter · öppnas i Konstruktion", "home.open": "Öppna…", - "home.open_hint": "En .solidcraft-konstruktion ({shortcut})", + "home.open_hint": "En .sc-konstruktion ({shortcut})", "home.open_now": "Öppen nu", "home.opened_days_ago": "För {count} dagar sedan", "home.opened_hours_ago": "För {count} h sedan", diff --git a/assets/locales/tr.json b/assets/locales/tr.json index feeebe206..34d772a60 100644 --- a/assets/locales/tr.json +++ b/assets/locales/tr.json @@ -1252,7 +1252,7 @@ "home.new_mm": "Yeni tasarım", "home.new_mm_hint": "Milimetre · Tasarım alanında açılır", "home.open": "Aç…", - "home.open_hint": "Bir .solidcraft tasarımı ({shortcut})", + "home.open_hint": "Bir .sc tasarımı ({shortcut})", "home.open_now": "Şimdi aç", "home.opened_days_ago": "{count} gün önce", "home.opened_hours_ago": "{count} sa. önce", diff --git a/assets/locales/uk.json b/assets/locales/uk.json index 2b0fe22db..29ddf1fd9 100644 --- a/assets/locales/uk.json +++ b/assets/locales/uk.json @@ -1252,7 +1252,7 @@ "home.new_mm": "Новий проєкт", "home.new_mm_hint": "Міліметри · відкриється в робочому просторі «Проєктування»", "home.open": "Відкрити…", - "home.open_hint": "Проєкт .solidcraft ({shortcut})", + "home.open_hint": "Проєкт .sc ({shortcut})", "home.open_now": "Відкрити зараз", "home.opened_days_ago": "{count} дн. тому", "home.opened_hours_ago": "{count} год тому", diff --git a/assets/locales/vi.json b/assets/locales/vi.json index 2fc62d93e..f9b1cad73 100644 --- a/assets/locales/vi.json +++ b/assets/locales/vi.json @@ -1291,7 +1291,7 @@ "home.new_mm": "Thiết kế mới", "home.new_mm_hint": "Milimét · mở trong Thiết kế", "home.open": "Mở…", - "home.open_hint": "Một thiết kế .solidcraft ({shortcut})", + "home.open_hint": "Một thiết kế .sc ({shortcut})", "home.open_now": "Mở ngay", "home.opened_days_ago": "{count} ngày trước", "home.opened_hours_ago": "{count} giờ trước", diff --git a/assets/locales/zh-TW.json b/assets/locales/zh-TW.json index ea8ee893d..334e4da97 100644 --- a/assets/locales/zh-TW.json +++ b/assets/locales/zh-TW.json @@ -900,7 +900,7 @@ "home.new_mm": "新增設計", "home.new_mm_hint": "公釐 · 在設計工作區中開啟", "home.open": "開啟…", - "home.open_hint": ".solidcraft 設計檔案 ({shortcut})", + "home.open_hint": ".sc 設計檔案 ({shortcut})", "home.open_now": "目前開啟中", "home.opened_days_ago": "{count} 天前", "home.opened_hours_ago": "{count} 小時前", diff --git a/assets/locales/zh.json b/assets/locales/zh.json index a78f56385..f45f43fbb 100644 --- a/assets/locales/zh.json +++ b/assets/locales/zh.json @@ -1291,7 +1291,7 @@ "home.new_mm": "新建设计", "home.new_mm_hint": "毫米 · 在设计工作区中打开", "home.open": "打开…", - "home.open_hint": ".solidcraft 设计文件 ({shortcut})", + "home.open_hint": ".sc 设计文件 ({shortcut})", "home.open_now": "立即打开", "home.opened_days_ago": "{count} 天前", "home.opened_hours_ago": "{count} 小时前", diff --git a/assets/platforms/linux/io.tangencylabs.solidcraft.mime.xml b/assets/platforms/linux/io.tangencylabs.solidcraft.mime.xml index 4a03d2caf..796ec1ee4 100644 --- a/assets/platforms/linux/io.tangencylabs.solidcraft.mime.xml +++ b/assets/platforms/linux/io.tangencylabs.solidcraft.mime.xml @@ -6,8 +6,11 @@ SolidCraft design + + + - diff --git a/assets/platforms/macos/Info.plist.in b/assets/platforms/macos/Info.plist.in index 40a20f7d1..57047f1fa 100644 --- a/assets/platforms/macos/Info.plist.in +++ b/assets/platforms/macos/Info.plist.in @@ -45,8 +45,11 @@ CFBundleTypeName SolidCraft design CFBundleTypeExtensions - - solidcraftsolvecraft + + scsolidcraftsolvecraft + LSItemContentTypes + io.tangencylabs.solidcraft.design CFBundleTypeRole Editor LSHandlerRank @@ -63,5 +66,24 @@ Alternate + + UTExportedTypeDeclarations + + + UTTypeIdentifier + io.tangencylabs.solidcraft.design + UTTypeDescription + SolidCraft design + UTTypeConformsTo + public.datapublic.content + UTTypeTagSpecification + + public.filename-extension + scsolidcraftsolvecraft + public.mime-type + application/x-solidcraft + + + diff --git a/assets/platforms/macos/README.txt b/assets/platforms/macos/README.txt index a248ea47e..14d96ac29 100644 --- a/assets/platforms/macos/README.txt +++ b/assets/platforms/macos/README.txt @@ -11,6 +11,6 @@ Some earlier releases were installed as SolveCraft.app. Move that one to the Tra once SolidCraft.app is in Applications, and replace any Dock shortcut with the old name (open SolidCraft.app, then choose Options > Keep in Dock). -Designs saved as .solvecraft still open, and SolidCraft copies your settings -and recovery files from the old SolveCraft folder on its first launch. -New designs are saved as .solidcraft. +Designs saved as .solidcraft or .solvecraft still open, and SolidCraft copies +your settings and recovery files from the old SolveCraft folder on its first +launch. New designs are saved as .sc. diff --git a/assets/platforms/windows/solidcraft.wxs b/assets/platforms/windows/solidcraft.wxs index a47fac2d6..bd77c77a7 100644 --- a/assets/platforms/windows/solidcraft.wxs +++ b/assets/platforms/windows/solidcraft.wxs @@ -9,7 +9,7 @@ Per-machine install with a setup wizard: Welcome, install folder (Program Files\SolidCraft by default, remembered for upgrades), Ready, progress, and a Finish page with a ticked "Launch SolidCraft" box. Installs a Start Menu shortcut, solidcraft-cli (and adds its folder to the system PATH), the licence files (including - THIRD-PARTY-LICENSES.txt), makes SolidCraft the owner of `.solidcraft` (and of the pre-rename `.solvecraft`), and offers it under + THIRD-PARTY-LICENSES.txt), makes SolidCraft the owner of `.sc` (and of the older `.solidcraft` and pre-rename `.solvecraft`), and offers it under "Open with" for STEP, IGES, 3MF and STL. `msiexec /qn` installs silently. Adapted from PhotoCraft's (storytold/photocraft, Apache-2.0; see ATTRIBUTION.md). --> @@ -84,15 +84,17 @@ Icon="SolidcraftIcon.exe" IconIndex="0" /> - + - + - + + + @@ -108,6 +110,7 @@ + diff --git a/crates/engine/src/cmd/component_extract.rs b/crates/engine/src/cmd/component_extract.rs index 627dfca75..da2161ca8 100644 --- a/crates/engine/src/cmd/component_extract.rs +++ b/crates/engine/src/cmd/component_extract.rs @@ -555,8 +555,8 @@ pub(super) fn extract(s: &mut Session, p: &Value) -> Result { let sc = scope(s, comp, CMD)?; let given = str_(p, "path").filter(|x| !x.trim().is_empty() && x.len() < 4096).ok_or_else(|| bad(CMD, "`path` is required"))?; let file = absolute(Path::new(given)); - if !file.extension().and_then(|e| e.to_str()).is_some_and(|e| e.eq_ignore_ascii_case("solidcraft")) { - return Err(bad(CMD, "the new design must be a .solidcraft file")); + if !solidcraft_io::is_design_container_path(&file) { + return Err(bad(CMD, "the new design must be a .sc file")); } if s.path.as_deref().is_some_and(|own| absolute(Path::new(own)) == file) { return Err(bad(CMD, "choose another file than this design's own")); @@ -853,7 +853,7 @@ mod tests { }; refuse(&mut s, json!({"component": 0, "path": file}), "not the design"); refuse(&mut s, json!({"component": "Plate"}), "`path` is required"); - refuse(&mut s, json!({"component": "Plate", "path": dir.join("plate.step")}), ".solidcraft"); + refuse(&mut s, json!({"component": "Plate", "path": dir.join("plate.step")}), ".sc file"); // A joint from Plate's subcomponent to the rest of the design let pin_occ = s.doc.occurrences.iter().find(|o| o.name.starts_with("Pin")).map(|o| o.id).unwrap(); diff --git a/crates/engine/src/cmd/component_link.rs b/crates/engine/src/cmd/component_link.rs index 33bedf07a..1273507dd 100644 --- a/crates/engine/src/cmd/component_link.rs +++ b/crates/engine/src/cmd/component_link.rs @@ -30,7 +30,7 @@ mod relink_tests; pub static COMMANDS: &[CommandSpec] = &[ CommandSpec::new("component.insert_design", "Insert Design", insert_design).at("SOLID", "ASSEMBLE").icon("component").params( - "path: a .solidcraft design → a new component linked to it, holding its solid bodies as placed in that design and a copy of its design properties; \ + "path: a .sc design → a new component linked to it, holding its solid bodies as placed in that design and a copy of its design properties; \ name? (default: the design's name); parent?: component id or name (default: the active one); translate?: [x,y,z]; \ reuse?: bool (default false): insert a free occurrence, reusing an existing link to the same file when available", ), @@ -39,13 +39,13 @@ pub static COMMANDS: &[CommandSpec] = &[ → updated, unchanged, warnings (also joints whose faces are gone or that no longer solve)", ), CommandSpec::new("component.relink", "Relink Source", relink).icon("update").params( - "component: id or name of a linked component; path: a saved .solidcraft design — replaces the source and linked bodies for all its occurrences, preserving identities and placements; returns path, previous_path, warnings, joint_errors and joint_conflicts", + "component: id or name of a linked component; path: a saved .sc design — replaces the source and linked bodies for all its occurrences, preserving identities and placements; returns path, previous_path, warnings, joint_errors and joint_conflicts", ), CommandSpec::new("component.break_link", "Break Link", break_link) .icon("break") .params("component: id or name of a linked component — keeps its bodies as they are and forgets the design file"), CommandSpec::new("component.extract", "Extract to File", extract::extract).icon("export").params( - "component: id or name of a component that is not linked; path: the .solidcraft design to write → its history, subcomponents and their joints \ + "component: id or name of a component that is not linked; path: the .sc design to write → its history, subcomponents and their joints \ move to that design, and the component becomes linked to it (as component.insert_design makes it); returns path, file, feature, bodies, \ notices (what stays behind), warnings and copies (components that build the same bodies: see component.replace_with_link)", ), @@ -53,7 +53,7 @@ pub static COMMANDS: &[CommandSpec] = &[ "component: id or name of a linked component → copies: [{component, name}], the components not linked whose own history builds the same bodies", ), CommandSpec::new("component.replace_with_link", "Replace with Link", extract::replace_with_link).icon("chain").params( - "component or components: [ids or names] of components that are not linked; with: a linked component, or path: a .solidcraft design \ + "component or components: [ids or names] of components that are not linked; with: a linked component, or path: a .sc design \ (its link here, else a new linked component) → each component's history goes and its placements become placements of the linked \ component; refused when its bodies are not the same as the link's; returns component, name, replaced and warnings", ), @@ -367,8 +367,8 @@ fn relink(s: &mut Session, p: &Value) -> Result { } let given = str_(p, "path").filter(|x| !x.trim().is_empty() && x.len() < 4096).ok_or_else(|| bad(cmd, "`path` is required"))?; let file = absolute(Path::new(given)); - if !file.extension().and_then(|e| e.to_str()).is_some_and(|e| e.eq_ignore_ascii_case("solidcraft")) { - return Err(bad(cmd, "choose a saved .solidcraft design")); + if !solidcraft_io::is_design_container_path(&file) { + return Err(bad(cmd, "choose a saved .sc design")); } // A network or device path is judged from its text before the disk is asked anything. link_refused(s.path.as_deref(), given).map_err(|e| bad(cmd, e.to_string()))?; diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index dcd91a6f5..0cf82a860 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -27,7 +27,7 @@ pub static COMMANDS: &[CommandSpec] = &[ .icon("open") .key("Ctrl+O") .noundo() - .params("path: .solidcraft design, .dxf/.svg drawing (opens as a new, unsaved design with an XY sketch, using sketch.insert_dxf/sketch.insert_svg units and defaults), or a .step/.stp/.igs/.fcstd/.3dm/.3mf/.stl/.obj/.glb/.gltf file (STEP, IGES, FreeCAD, Rhino, 3MF, STL, OBJ or glTF; opens as a new design holding the file as a component named after it, as file.insert_step and file.insert_mesh make); up?: z|y for a STEP, IGES, FreeCAD, Rhino or glTF file (see file.insert_step and file.insert_mesh); names?: auto|solid|product|instance for a STEP, IGES, FreeCAD or Rhino file (see file.insert_step); read_only?: bool (a design: saving to its own file is refused, file.save_as keeps the changes elsewhere) → open_elsewhere: {host, user, app, opened} when another SolidCraft has the design open (its lock file is fresh)"), + .params("path: .sc design (or a .solidcraft design from an earlier release), .dxf/.svg drawing (opens as a new, unsaved design with an XY sketch, using sketch.insert_dxf/sketch.insert_svg units and defaults), or a .step/.stp/.igs/.fcstd/.3dm/.3mf/.stl/.obj/.glb/.gltf file (STEP, IGES, FreeCAD, Rhino, 3MF, STL, OBJ or glTF; opens as a new design holding the file as a component named after it, as file.insert_step and file.insert_mesh make); up?: z|y for a STEP, IGES, FreeCAD, Rhino or glTF file (see file.insert_step and file.insert_mesh); names?: auto|solid|product|instance for a STEP, IGES, FreeCAD or Rhino file (see file.insert_step); read_only?: bool (a design: saving to its own file is refused, file.save_as keeps the changes elsewhere) → open_elsewhere: {host, user, app, opened} when another SolidCraft has the design open (its lock file is fresh)"), CommandSpec::new("file.insert_step", "Insert STEP", insert_step) .at("SOLID", "INSERT") .icon("import") @@ -340,7 +340,7 @@ fn open(s: &mut Session, p: &Value) -> Result { /// The name a design never given one by its user is shown under. const DEFAULT_NAME: &str = "Untitled"; -/// A design still under the default name takes its file's name (`bracket.solidcraft` → +/// A design still under the default name takes its file's name (`bracket.sc` → /// "bracket"); a name the user chose is kept. `None` when nothing changes. fn default_name_for(name: &str, path: &str) -> Option { let name = name.trim(); @@ -953,6 +953,39 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); } + /// A `.solidcraft` design from an earlier release opens, takes its file's name, and `file.save` + /// writes it back to that same file (container format), never to a new `.sc` beside it. + #[test] + fn saving_an_opened_legacy_design_keeps_its_name() { + let dir = std::env::temp_dir().join(format!("solidcraft-legacy-ext-save-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let old = dir.join("Bracket.solidcraft"); + let mut first = Session::default(); + first.execute("solid.box", &json!({"length": 10, "width": 10, "height": 10})).unwrap(); + first.execute("file.save_as", &json!({"path": old.to_string_lossy()})).unwrap(); + let mut s = Session::default(); + s.execute("doc.open", &json!({"path": old.to_string_lossy()})).unwrap(); + assert_eq!(s.doc.name, "Bracket"); + s.execute("solid.box", &json!({"length": 5, "width": 5, "height": 5})).unwrap(); + s.execute("file.save", &json!({})).unwrap(); + assert_eq!(s.path.as_deref(), old.to_str()); + let names: Vec = std::fs::read_dir(&dir) + .unwrap() + .flatten() + .map(|e| e.file_name().to_string_lossy().into_owned()) + .filter(|n| !n.ends_with(".bak") && !n.ends_with(".lock")) + .collect(); + assert_eq!(names, ["Bracket.solidcraft"]); + let bytes = std::fs::read(&old).unwrap(); + assert!(solidcraft_io::is_design_container(&bytes)); + assert_eq!(solidcraft_io::read_design(&bytes).unwrap().features.len(), 2); + // Save As to the new extension leaves the old file as it was. + s.execute("file.save_as", &json!({"path": dir.join("Bracket.sc").to_string_lossy()})).unwrap(); + assert!(old.is_file() && dir.join("Bracket.sc").is_file()); + let _ = std::fs::remove_dir_all(&dir); + } + /// #5467: a script, the CLI or the control channel never gets a prompt. A Save over a file /// another program or computer changed since it was opened is refused with an error naming /// `overwrite`, which replaces it; a design opened read-only only saves to another file. diff --git a/crates/engine/src/cmd/sketch_face_tests.rs b/crates/engine/src/cmd/sketch_face_tests.rs index d7d720174..e0fd6a301 100644 --- a/crates/engine/src/cmd/sketch_face_tests.rs +++ b/crates/engine/src/cmd/sketch_face_tests.rs @@ -679,7 +679,7 @@ fn every_flat_face_of_one_sketch_extruded_up_and_down_takes_an_attached_sketch() assert_eq!(sketch_and_extrude_on_every_flat_face(&reopened, &dir, "synthetic-reopened"), 12); // The logo design as it was reported (format 17, with a removed shelled body before it). let mut logo = Session::default(); - run(&mut logo, "doc.open", json!({"path": root.join("logo-up-down-join.solidcraft").to_string_lossy()})); + run(&mut logo, "doc.open", json!({"path": root.join("logo-up-down-join.sc").to_string_lossy()})); assert_eq!(sketch_and_extrude_on_every_flat_face(&logo, &dir, "logo"), 12); let _ = std::fs::remove_dir_all(&dir); } diff --git a/crates/engine/src/crash.rs b/crates/engine/src/crash.rs index 65875180e..a56d2e089 100644 --- a/crates/engine/src/crash.rs +++ b/crates/engine/src/crash.rs @@ -3,7 +3,7 @@ //! //! - **Panics** are caught by a hook. One inside a command becomes a report with the design as //! it was before the command and the command itself, so `solidcraft-cli run replay.json --in -//! design.solidcraft` reproduces it. Panics the third-party kernel raises (and +//! design.sc` reproduces it. Panics the third-party kernel raises (and //! `solidcraft_kernel::guard` turns into errors) are reported the same way, marked recovered. //! - **Crashes no hook sees** (an abort, a stack overflow, a segfault, the process being killed) //! are found at the next start: every running app keeps a small, locked command journal; a @@ -26,7 +26,7 @@ //! into the unclean exit's report. //! //! Reports are folders `crashes/