diff --git a/OGF tool/Forms/Batch/AddDeleteData.cs b/OGF tool/Forms/Batch/AddDeleteData.cs index 37f4b3b..13af72a 100644 --- a/OGF tool/Forms/Batch/AddDeleteData.cs +++ b/OGF tool/Forms/Batch/AddDeleteData.cs @@ -16,12 +16,14 @@ public partial class AddDeleteData : Form private string folder; private Batch.BatchChunks Chunk; private bool delete; - public AddDeleteData(Batch.BatchChunks chunk, string ogf_folder_path, bool delete) + private Editor Editor; + public AddDeleteData(Editor editor, Batch.BatchChunks chunk, string ogf_folder_path, bool delete) { InitializeComponent(); folder = ogf_folder_path; Chunk = chunk; this.delete = delete; + Editor = editor; if (Chunk == Batch.BatchChunks.Lod) DataTextBox.Multiline = false; @@ -61,6 +63,8 @@ private void StartButton_Click(object sender, EventArgs e) { Model.SaveFile(files[i]); FilesCount++; + if (Model.FileName == Editor.Model.FileName) + Editor.ReloadModel(); } } } diff --git a/OGF tool/Forms/Batch/Batch.cs b/OGF tool/Forms/Batch/Batch.cs index 8fd2aee..437375e 100644 --- a/OGF tool/Forms/Batch/Batch.cs +++ b/OGF tool/Forms/Batch/Batch.cs @@ -46,7 +46,7 @@ static private bool SafeCheckLineExist(string[] arr, string chk_line) return false; } - static public bool ProcessReplace(XRay_Model Model, BatchChunks chunk, string replacer, string new_val, ref uint lines_counter) + static public bool ProcessReplace(XRay_Model Model, BatchChunks chunk, string replacer, string new_val, bool substring, ref uint lines_counter) { bool ret = false; switch (chunk) @@ -54,22 +54,46 @@ static public bool ProcessReplace(XRay_Model Model, BatchChunks chunk, string re case BatchChunks.Texture: foreach (var ch in Model.childs) { - if (ch.m_texture == replacer) + if (substring) { - ch.m_texture = new_val; - ret = true; - lines_counter++; + if (ch.m_texture.Contains(replacer)) + { + ch.m_texture = ch.m_texture.Replace(replacer, new_val); + ret = true; + lines_counter++; + } + } + else + { + if (ch.m_texture == replacer) + { + ch.m_texture = new_val; + ret = true; + lines_counter++; + } } } break; case BatchChunks.Shader: foreach (var ch in Model.childs) { - if (ch.m_shader == replacer) + if (substring) { - ch.m_shader = new_val; - ret = true; - lines_counter++; + if (ch.m_shader.Contains(replacer)) + { + ch.m_shader = ch.m_shader.Replace(replacer, new_val); + ret = true; + lines_counter++; + } + } + else + { + if (ch.m_shader == replacer) + { + ch.m_shader = new_val; + ret = true; + lines_counter++; + } } } break; @@ -80,14 +104,28 @@ static public bool ProcessReplace(XRay_Model Model, BatchChunks chunk, string re string userdata = ""; foreach (string line in Lines) { - if (RemoveSpacesAndNewLines(line) == RemoveSpacesAndNewLines(replacer)) + if (substring) { - userdata += new_val + "\r\n"; - ret = true; - lines_counter++; + if (line.Contains(replacer)) + { + userdata += line.Replace(replacer, new_val) + "\r\n"; + ret = true; + lines_counter++; + } + else + userdata += RemoveNewLines(line) + "\r\n"; } else - userdata += RemoveNewLines(line) + "\r\n"; + { + if (RemoveSpacesAndNewLines(line) == RemoveSpacesAndNewLines(replacer)) + { + userdata += new_val + "\r\n"; + ret = true; + lines_counter++; + } + else + userdata += RemoveNewLines(line) + "\r\n"; + } } if (ret) Model.userdata.userdata = userdata.TrimEnd(new char[] { '\r', '\n' }); @@ -100,23 +138,49 @@ static public bool ProcessReplace(XRay_Model Model, BatchChunks chunk, string re Model.motion_refs.refs.Clear(); foreach (string line in Lines) { - if (RemoveSpacesAndNewLines(line) == RemoveSpacesAndNewLines(replacer)) + if (substring) { - Model.motion_refs.refs.Add(new_val); - ret = true; - lines_counter++; + if (line.Contains(replacer)) + { + Model.motion_refs.refs.Add(line.Replace(replacer, new_val)); + ret = true; + lines_counter++; + } + else + Model.motion_refs.refs.Add(line); } else - Model.motion_refs.refs.Add(line); + { + if (RemoveSpacesAndNewLines(line) == RemoveSpacesAndNewLines(replacer)) + { + Model.motion_refs.refs.Add(new_val); + ret = true; + lines_counter++; + } + else + Model.motion_refs.refs.Add(line); + } } } break; case BatchChunks.Lod: - if (Model.lod != null && RemoveSpacesAndNewLines(Model.lod.lod_path) == RemoveSpacesAndNewLines(replacer)) + if (substring) { - Model.lod.lod_path = new_val; - ret = true; - lines_counter++; + if (Model.lod != null && Model.lod.lod_path.Contains(replacer)) + { + Model.lod.lod_path = Model.lod.lod_path.Replace(replacer, new_val); + ret = true; + lines_counter++; + } + } + else + { + if (Model.lod != null && RemoveSpacesAndNewLines(Model.lod.lod_path) == RemoveSpacesAndNewLines(replacer)) + { + Model.lod.lod_path = new_val; + ret = true; + lines_counter++; + } } break; } @@ -275,7 +339,7 @@ private void ProcessReplacer(BatchChunks chunk) { if (Directory.Exists(PathTextBox.Text)) { - ReplaceData textBoxReplacer = new ReplaceData(chunk, PathTextBox.Text); + ReplaceData textBoxReplacer = new ReplaceData(Editor, chunk, PathTextBox.Text); textBoxReplacer.Show(); } else @@ -286,7 +350,7 @@ private void ProcessAdd(BatchChunks chunk) { if (Directory.Exists(PathTextBox.Text)) { - AddDeleteData textBoxReplacer = new AddDeleteData(chunk, PathTextBox.Text, false); + AddDeleteData textBoxReplacer = new AddDeleteData(Editor, chunk, PathTextBox.Text, false); textBoxReplacer.Show(); } else @@ -297,7 +361,7 @@ private void ProcessDelete(BatchChunks chunk) { if (Directory.Exists(PathTextBox.Text)) { - AddDeleteData textBoxReplacer = new AddDeleteData(chunk, PathTextBox.Text, true); + AddDeleteData textBoxReplacer = new AddDeleteData(Editor, chunk, PathTextBox.Text, true); textBoxReplacer.Show(); } else diff --git a/OGF tool/Forms/Batch/ReplaceData.Designer.cs b/OGF tool/Forms/Batch/ReplaceData.Designer.cs index c464304..434942d 100644 --- a/OGF tool/Forms/Batch/ReplaceData.Designer.cs +++ b/OGF tool/Forms/Batch/ReplaceData.Designer.cs @@ -34,13 +34,14 @@ private void InitializeComponent() this.ReplacerTextBox = new System.Windows.Forms.TextBox(); this.Label_2 = new System.Windows.Forms.Label(); this.Label_1 = new System.Windows.Forms.Label(); + this.ReplaceSubstrings = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // StartButton // - this.StartButton.Location = new System.Drawing.Point(340, 12); + this.StartButton.Location = new System.Drawing.Point(340, 10); this.StartButton.Name = "StartButton"; - this.StartButton.Size = new System.Drawing.Size(89, 46); + this.StartButton.Size = new System.Drawing.Size(110, 24); this.StartButton.TabIndex = 9; this.StartButton.Text = "Start"; this.StartButton.UseVisualStyleBackColor = true; @@ -79,11 +80,22 @@ private void InitializeComponent() this.Label_1.TabIndex = 5; this.Label_1.Text = "Find what:"; // + // ReplaceSubstrings + // + this.ReplaceSubstrings.AutoSize = true; + this.ReplaceSubstrings.Location = new System.Drawing.Point(340, 41); + this.ReplaceSubstrings.Name = "ReplaceSubstrings"; + this.ReplaceSubstrings.Size = new System.Drawing.Size(116, 17); + this.ReplaceSubstrings.TabIndex = 10; + this.ReplaceSubstrings.Text = "Replace substrings"; + this.ReplaceSubstrings.UseVisualStyleBackColor = true; + // // ReplaceData // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(436, 67); + this.ClientSize = new System.Drawing.Size(455, 67); + this.Controls.Add(this.ReplaceSubstrings); this.Controls.Add(this.StartButton); this.Controls.Add(this.NewTextBox); this.Controls.Add(this.ReplacerTextBox); @@ -106,5 +118,6 @@ private void InitializeComponent() private System.Windows.Forms.TextBox ReplacerTextBox; private System.Windows.Forms.Label Label_2; private System.Windows.Forms.Label Label_1; + private System.Windows.Forms.CheckBox ReplaceSubstrings; } } \ No newline at end of file diff --git a/OGF tool/Forms/Batch/ReplaceData.cs b/OGF tool/Forms/Batch/ReplaceData.cs index 1b9f2b4..8a0c563 100644 --- a/OGF tool/Forms/Batch/ReplaceData.cs +++ b/OGF tool/Forms/Batch/ReplaceData.cs @@ -15,12 +15,14 @@ public partial class ReplaceData : Form { private string folder; private Batch.BatchChunks Chunk; - public ReplaceData(Batch.BatchChunks chunk, string ogf_folder_path) + private Editor Editor; + public ReplaceData(Editor editor, Batch.BatchChunks chunk, string ogf_folder_path) { InitializeComponent(); folder = ogf_folder_path; Chunk = chunk; Text = "Replace " + Batch.Capitalize(chunk.ToString()); + Editor = editor; BoxTextChanged(NewTextBox, null); } @@ -38,10 +40,12 @@ private void StartButton_Click(object sender, EventArgs e) XRay_Model Model = new XRay_Model(); if (Model.OpenFile(files[i])) { - if (Batch.ProcessReplace(Model, Chunk, ReplacerTextBox.Text, NewTextBox.Text, ref LinesCount)) + if (Batch.ProcessReplace(Model, Chunk, ReplacerTextBox.Text, NewTextBox.Text, ReplaceSubstrings.Checked, ref LinesCount)) { Model.SaveFile(files[i]); FilesCount++; + if (Model.FileName == Editor.Model.FileName) + Editor.ReloadModel(); } } } diff --git a/OGF tool/Forms/Editor.cs b/OGF tool/Forms/Editor.cs index 09247d7..7e6caf9 100644 --- a/OGF tool/Forms/Editor.cs +++ b/OGF tool/Forms/Editor.cs @@ -161,11 +161,9 @@ public Editor() if (Environment.GetCommandLineArgs().Length > 1) { - if (Model.OpenFile(Environment.GetCommandLineArgs()[1])) - { - Clear(); + Clear(); + if (Model.OpenFile(Environment.GetCommandLineArgs()[1])) AfterLoad(true); - } } else { @@ -989,16 +987,19 @@ private void CreateLodButton_Click(object sender, EventArgs e) private void reloadToolStripMenuItem_Click(object sender, EventArgs e) { - if (Model.FileName == "") return; + ReloadModel(); + } - string cur_fname = Model.FileName; - if (Model.OpenFile(cur_fname)) - { + public void ReloadModel() + { + if (Model.FileName == "") return; + + if (Model.OpenFile(Model.FileName)) + { Clear(); - Model.FileName = cur_fname; - AfterLoad(true); - } - } + AfterLoad(true); + } + } private void TabControl_SelectedIndexChanged(object sender, EventArgs e) {