|
| 1 | +use std::path::Path; |
| 2 | + |
| 3 | +use crate::{ |
| 4 | + changes::{Change, RenameFile, SetIniEntry}, |
| 5 | + workflows::rename_project::context::Context, |
| 6 | +}; |
| 7 | + |
| 8 | +/// Generate a changeset to rename an Unreal Engine project. |
| 9 | +pub fn generate_changeset(context: &Context) -> Vec<Change> { |
| 10 | + let Context { |
| 11 | + project_root, |
| 12 | + project_name: old_name, |
| 13 | + target_name: new_name, |
| 14 | + } = context; |
| 15 | + |
| 16 | + vec![ |
| 17 | + add_game_name_to_engine_config(project_root, new_name), |
| 18 | + add_project_name_to_game_config(project_root, new_name), |
| 19 | + rename_project_descriptor(project_root, old_name, new_name), |
| 20 | + rename_project_root(project_root, new_name), |
| 21 | + ] |
| 22 | +} |
| 23 | + |
| 24 | +fn rename_project_descriptor(project_root: &Path, old_name: &str, new_name: &str) -> Change { |
| 25 | + Change::RenameFile(RenameFile::new( |
| 26 | + project_root.join(old_name).with_extension("uproject"), |
| 27 | + project_root.join(new_name).with_extension("uproject"), |
| 28 | + )) |
| 29 | +} |
| 30 | + |
| 31 | +fn add_game_name_to_engine_config(project_root: &Path, new_name: &str) -> Change { |
| 32 | + Change::SetIniEntry(SetIniEntry::new( |
| 33 | + project_root.join("Config/DefaultEngine.ini"), |
| 34 | + "URL", |
| 35 | + "GameName", |
| 36 | + new_name, |
| 37 | + )) |
| 38 | +} |
| 39 | + |
| 40 | +fn add_project_name_to_game_config(project_root: &Path, new_name: &str) -> Change { |
| 41 | + Change::SetIniEntry(SetIniEntry::new( |
| 42 | + project_root.join("Config/DefaultGame.ini"), |
| 43 | + "/Script/EngineSettings.GeneralProjectSettings", |
| 44 | + "ProjectName", |
| 45 | + new_name, |
| 46 | + )) |
| 47 | +} |
| 48 | + |
| 49 | +fn rename_project_root(project_root: &Path, new_name: &str) -> Change { |
| 50 | + Change::RenameFile(RenameFile::new( |
| 51 | + &project_root, |
| 52 | + project_root.with_file_name(new_name), |
| 53 | + )) |
| 54 | +} |
0 commit comments