|
1 | 1 | use std::path::Path;
|
2 | 2 |
|
3 | 3 | use crate::{
|
4 |
| - changes::{Change, RenameFile, ReplaceInFile}, |
| 4 | + changes::{AppendIniEntry, Change, RenameFile, ReplaceInFile}, |
5 | 5 | unreal::Plugin,
|
6 | 6 | };
|
7 | 7 |
|
@@ -36,6 +36,8 @@ pub fn generate_changeset(context: &Context) -> Vec<Change> {
|
36 | 36 | old_name,
|
37 | 37 | new_name,
|
38 | 38 | ));
|
| 39 | + changeset.push(update_existing_redirects(project_root, old_name, new_name)); |
| 40 | + changeset.push(append_plugin_redirect(project_root, old_name, new_name)); |
39 | 41 |
|
40 | 42 | changeset
|
41 | 43 | }
|
@@ -84,3 +86,29 @@ fn rename_plugin_references_in_plugin(plugin: &Plugin, old_name: &str, new_name:
|
84 | 86 | format!(r#""{new_name}""#),
|
85 | 87 | ))
|
86 | 88 | }
|
| 89 | + |
| 90 | +fn update_existing_redirects(project_root: &Path, old_name: &str, new_name: &str) -> Change { |
| 91 | + Change::ReplaceInFile(ReplaceInFile::new( |
| 92 | + project_root.join("Config").join("DefaultEngine.ini"), |
| 93 | + format!( |
| 94 | + r#"\(OldName="/(?P<old>.+?)/",\s*NewName="/{}/",\s*MatchSubstring=true\)"#, |
| 95 | + old_name |
| 96 | + ), |
| 97 | + format!( |
| 98 | + r#"(OldName="/$old/",NewName="/{}/",MatchSubstring=true)"#, |
| 99 | + new_name |
| 100 | + ), |
| 101 | + )) |
| 102 | +} |
| 103 | + |
| 104 | +fn append_plugin_redirect(project_root: &Path, old_name: &str, new_name: &str) -> Change { |
| 105 | + Change::AppendIniEntry(AppendIniEntry::new( |
| 106 | + project_root.join("Config").join("DefaultEngine.ini"), |
| 107 | + "CoreRedirects", |
| 108 | + "+PackageRedirects", |
| 109 | + format!( |
| 110 | + r#"(OldName="/{}/",NewName="/{}/",MatchSubstring=true)"#, |
| 111 | + old_name, new_name |
| 112 | + ), |
| 113 | + )) |
| 114 | +} |
0 commit comments