diff --git a/TombIDE/TombIDE.Shared/NewStructure/Bases/GameProjectBase.cs b/TombIDE/TombIDE.Shared/NewStructure/Bases/GameProjectBase.cs
index aa65ace7eb..136ad475a8 100644
--- a/TombIDE/TombIDE.Shared/NewStructure/Bases/GameProjectBase.cs
+++ b/TombIDE/TombIDE.Shared/NewStructure/Bases/GameProjectBase.cs
@@ -35,6 +35,11 @@ public abstract class GameProjectBase : IGameProject
public string Name { get; protected set; }
public string DirectoryPath { get; protected set; }
+ ///
+ /// The file name (not path) of the .trproj file. (e.g. "MyProject.trproj")
+ ///
+ public string TrprojFileName { get; set; }
+
protected string CustomScriptDirectoryPath { get; set; }
public string LevelsDirectoryPath { get; set; }
@@ -51,6 +56,7 @@ public GameProjectBase(TrprojFile trproj, Version targetTrprojVersion)
Name = trproj.ProjectName;
DirectoryPath = Path.GetDirectoryName(trproj.FilePath);
+ TrprojFileName = Path.GetFileName(trproj.FilePath);
LevelsDirectoryPath = trproj.LevelSourcingDirectory;
@@ -70,6 +76,7 @@ public GameProjectBase(string name, string directoryPath, string levelsDirectory
{
Name = name;
DirectoryPath = directoryPath;
+ TrprojFileName = name + ".trproj";
LevelsDirectoryPath = levelsDirectoryPath;
if (SupportsCustomScriptPaths)
@@ -80,7 +87,7 @@ public GameProjectBase(string name, string directoryPath, string levelsDirectory
}
public virtual string GetTrprojFilePath()
- => Path.Combine(DirectoryPath, Path.GetFileNameWithoutExtension(GetEngineExecutableFilePath()) + ".trproj");
+ => Path.Combine(DirectoryPath, TrprojFileName);
public virtual string GetLauncherFilePath()
{
@@ -154,7 +161,7 @@ public virtual LevelProject[] GetAllValidLevelProjects()
return result.ToArray();
}
- public virtual void Rename(string newName, bool renameDirectory)
+ public virtual void Rename(string newName, bool renameDirectory, bool renameTrprojFile = false)
{
if (renameDirectory)
{
@@ -179,6 +186,9 @@ public virtual void Rename(string newName, bool renameDirectory)
}
Name = newName;
+
+ if (renameTrprojFile)
+ TrprojFileName = newName + ".trproj";
}
public virtual bool IsValid(out string errorMessage)
diff --git a/TombIDE/TombIDE.Shared/NewStructure/IGameProject.cs b/TombIDE/TombIDE.Shared/NewStructure/IGameProject.cs
index e671f74ff4..3a5dcee3fb 100644
--- a/TombIDE/TombIDE.Shared/NewStructure/IGameProject.cs
+++ b/TombIDE/TombIDE.Shared/NewStructure/IGameProject.cs
@@ -56,7 +56,7 @@ public interface IGameProject : IProject
List GameLanguageNames { get; }
///
- /// .trproj file name = game's .exe file name (tomb4, PCTomb5, ...) + ".trproj"
+ /// Returns the full path to the project's .trproj file.
///
string GetTrprojFilePath();
diff --git a/TombIDE/TombIDE.Shared/NewStructure/IProject.cs b/TombIDE/TombIDE.Shared/NewStructure/IProject.cs
index 64a0dfa420..febd4e9c47 100644
--- a/TombIDE/TombIDE.Shared/NewStructure/IProject.cs
+++ b/TombIDE/TombIDE.Shared/NewStructure/IProject.cs
@@ -20,7 +20,7 @@ public interface IProject
///
/// Renames the project and its directory if specified.
///
- void Rename(string newName, bool renameDirectory = false);
+ void Rename(string newName, bool renameDirectory = false, bool renameTrprojFile = false);
///
/// Saves the project's settings.
diff --git a/TombIDE/TombIDE.Shared/NewStructure/Implementations/LevelProject.cs b/TombIDE/TombIDE.Shared/NewStructure/Implementations/LevelProject.cs
index 832f08a8b5..715e0d34ac 100644
--- a/TombIDE/TombIDE.Shared/NewStructure/Implementations/LevelProject.cs
+++ b/TombIDE/TombIDE.Shared/NewStructure/Implementations/LevelProject.cs
@@ -80,7 +80,7 @@ public bool IsValid(out string errorMessage)
public bool IsExternal(string relativeToLevelsDirectoryPath)
=> !DirectoryPath.StartsWith(relativeToLevelsDirectoryPath, StringComparison.OrdinalIgnoreCase);
- public void Rename(string newName, bool renameDirectory = false)
+ public void Rename(string newName, bool renameDirectory = false, bool renameTrprojFile = false)
{
if (renameDirectory)
{
diff --git a/TombIDE/TombIDE/Forms/FormRenameProject.Designer.cs b/TombIDE/TombIDE/Forms/FormRenameProject.Designer.cs
index 6bc7a3def9..ea09bdc548 100644
--- a/TombIDE/TombIDE/Forms/FormRenameProject.Designer.cs
+++ b/TombIDE/TombIDE/Forms/FormRenameProject.Designer.cs
@@ -20,6 +20,7 @@ private void InitializeComponent()
this.button_Apply = new DarkUI.Controls.DarkButton();
this.button_Cancel = new DarkUI.Controls.DarkButton();
this.checkBox_RenameDirectory = new DarkUI.Controls.DarkCheckBox();
+ this.checkBox_RenameTrproj = new DarkUI.Controls.DarkCheckBox();
this.panel_02 = new System.Windows.Forms.Panel();
this.label = new DarkUI.Controls.DarkLabel();
this.textBox_NewName = new DarkUI.Controls.DarkTextBox();
@@ -36,7 +37,7 @@ private void InitializeComponent()
this.button_Apply.Margin = new System.Windows.Forms.Padding(3, 9, 0, 0);
this.button_Apply.Name = "button_Apply";
this.button_Apply.Size = new System.Drawing.Size(75, 23);
- this.button_Apply.TabIndex = 1;
+ this.button_Apply.TabIndex = 2;
this.button_Apply.Text = "Apply";
this.button_Apply.Click += new System.EventHandler(this.button_Apply_Click);
//
@@ -48,7 +49,7 @@ private void InitializeComponent()
this.button_Cancel.Margin = new System.Windows.Forms.Padding(3, 9, 0, 0);
this.button_Cancel.Name = "button_Cancel";
this.button_Cancel.Size = new System.Drawing.Size(75, 23);
- this.button_Cancel.TabIndex = 2;
+ this.button_Cancel.TabIndex = 3;
this.button_Cancel.Text = "Cancel";
//
// checkBox_RenameDirectory
@@ -60,15 +61,27 @@ private void InitializeComponent()
this.checkBox_RenameDirectory.TabIndex = 0;
this.checkBox_RenameDirectory.Text = "Rename project directory as well";
//
+ // checkBox_RenameTrproj
+ //
+ this.checkBox_RenameTrproj.Checked = true;
+ this.checkBox_RenameTrproj.CheckState = System.Windows.Forms.CheckState.Checked;
+ this.checkBox_RenameTrproj.Location = new System.Drawing.Point(6, 34);
+ this.checkBox_RenameTrproj.Margin = new System.Windows.Forms.Padding(3, 0, 3, 0);
+ this.checkBox_RenameTrproj.Name = "checkBox_RenameTrproj";
+ this.checkBox_RenameTrproj.Size = new System.Drawing.Size(185, 23);
+ this.checkBox_RenameTrproj.TabIndex = 1;
+ this.checkBox_RenameTrproj.Text = "Rename .trproj file as well";
+ //
// panel_02
//
this.panel_02.Controls.Add(this.checkBox_RenameDirectory);
+ this.panel_02.Controls.Add(this.checkBox_RenameTrproj);
this.panel_02.Controls.Add(this.button_Cancel);
this.panel_02.Controls.Add(this.button_Apply);
this.panel_02.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel_02.Location = new System.Drawing.Point(0, 55);
this.panel_02.Name = "panel_02";
- this.panel_02.Size = new System.Drawing.Size(464, 42);
+ this.panel_02.Size = new System.Drawing.Size(464, 62);
this.panel_02.TabIndex = 2;
//
// label
@@ -108,7 +121,7 @@ private void InitializeComponent()
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.button_Cancel;
- this.ClientSize = new System.Drawing.Size(464, 97);
+ this.ClientSize = new System.Drawing.Size(464, 117);
this.Controls.Add(this.panel_01);
this.Controls.Add(this.panel_02);
this.FlatBorder = true;
@@ -132,6 +145,7 @@ private void InitializeComponent()
private DarkUI.Controls.DarkButton button_Apply;
private DarkUI.Controls.DarkButton button_Cancel;
private DarkUI.Controls.DarkCheckBox checkBox_RenameDirectory;
+ private DarkUI.Controls.DarkCheckBox checkBox_RenameTrproj;
private System.Windows.Forms.Panel panel_02;
private DarkUI.Controls.DarkLabel label;
private DarkUI.Controls.DarkTextBox textBox_NewName;
diff --git a/TombIDE/TombIDE/Forms/FormRenameProject.cs b/TombIDE/TombIDE/Forms/FormRenameProject.cs
index b933549ce4..e3397efcbc 100644
--- a/TombIDE/TombIDE/Forms/FormRenameProject.cs
+++ b/TombIDE/TombIDE/Forms/FormRenameProject.cs
@@ -42,25 +42,27 @@ private void button_Apply_Click(object sender, EventArgs e)
throw new ArgumentException("Invalid name.");
bool renameDirectory = checkBox_RenameDirectory.Checked;
+ bool renameTrprojFile = checkBox_RenameTrproj.Checked;
- if (newName == _targetProject.Name)
+ if (newName == _targetProject.Name && !renameDirectory && !renameTrprojFile)
{
- // If the name hasn't changed, but the directory name is different and the user wants to rename it
- if (Path.GetFileName(_targetProject.DirectoryPath) != newName && renameDirectory)
- {
- if (!Path.GetFileName(_targetProject.DirectoryPath).Equals(newName, StringComparison.OrdinalIgnoreCase))
- {
- string newDirectory = Path.Combine(Path.GetDirectoryName(_targetProject.DirectoryPath), newName);
+ DialogResult = DialogResult.Cancel;
+ return;
+ }
- if (Directory.Exists(newDirectory))
- throw new ArgumentException("A directory with the same name already exists in the parent directory.");
- }
+ if (newName == _targetProject.Name && !renameDirectory)
+ {
+ // Only renaming the .trproj file
+ }
+ else if (newName == _targetProject.Name && renameDirectory)
+ {
+ if (!Path.GetFileName(_targetProject.DirectoryPath).Equals(newName, StringComparison.OrdinalIgnoreCase))
+ {
+ string newDirectory = Path.Combine(Path.GetDirectoryName(_targetProject.DirectoryPath), newName);
- _targetProject.Rename(newName, true);
- _targetProject.Save();
+ if (Directory.Exists(newDirectory))
+ throw new ArgumentException("A directory with the same name already exists in the parent directory.");
}
- else
- DialogResult = DialogResult.Cancel;
}
else
{
@@ -68,9 +70,22 @@ private void button_Apply_Click(object sender, EventArgs e)
if (renameDirectory && Directory.Exists(newDirectory) && !newDirectory.Equals(_targetProject.DirectoryPath, StringComparison.OrdinalIgnoreCase))
throw new ArgumentException("A directory with the same name already exists in the parent directory.");
+ }
+
+ string oldTrprojFilePath = _targetProject.GetTrprojFilePath();
+
+ _targetProject.Rename(newName, renameDirectory, renameTrprojFile);
+ _targetProject.Save();
+
+ // Clean up old .trproj file after successful save
+ if (renameTrprojFile)
+ {
+ // After a directory rename, the old file is now inside the new directory
+ string oldTrprojFileName = Path.GetFileName(oldTrprojFilePath);
+ string oldTrprojPathAfterRename = Path.Combine(_targetProject.DirectoryPath, oldTrprojFileName);
- _targetProject.Rename(newName, renameDirectory);
- _targetProject.Save();
+ if (File.Exists(oldTrprojPathAfterRename) && !oldTrprojPathAfterRename.Equals(_targetProject.GetTrprojFilePath(), StringComparison.OrdinalIgnoreCase))
+ File.Delete(oldTrprojPathAfterRename);
}
}
catch (Exception ex)