| 125 | .expect("required value must be present") |
| 126 | .root |
| 127 | .as_deref() |
| 128 | .cloned() |
| 129 | .expect("Project root not set") |
| 130 | } |
| 131 | |
| 132 | /// Parse and atomically install a project root and its archive backing. |
| 133 | pub fn try_set_project_root(root: ProjectRoot) -> io::Result<()> { |
| 134 | let archive = match &root { |
| 135 | ProjectRoot::PerroAssets { data, .. } => { |
| 136 | Some(Arc::new(PerroAssetsArchive::open_from_bytes(data)?)) |
| 137 | } |
| 138 | ProjectRoot::Disk { .. } => None, |
| 139 | }; |
| 140 | // One stat here replaces one per `res://` resolve. |
| 141 | let has_res_dir = match &root { |
| 142 | ProjectRoot::Disk { root, .. } => root.join("res").is_dir(), |
| 143 | ProjectRoot::PerroAssets { .. } => false, |
| 144 | }; |
| 145 | |
| 146 | let mut state = PROJECT_ASSET_STATE |
| 147 | .write() |
| 148 | .expect("required value must be present"); |
| 149 | state.root = Some(Arc::new(root)); |
| 150 | state.root_has_res_dir = has_res_dir; |
| 151 | state.archive = archive; |
| 152 | Ok(()) |