From 169f3175ebac5febaad26187a67e18daf0e6ede1 Mon Sep 17 00:00:00 2001 From: Amr Shaheen Date: Thu, 25 Jan 2024 03:06:34 +0200 Subject: [PATCH] Changes for v2.6 --- UE4localizationsTool/App.config | 3 + UE4localizationsTool/Commands.cs | 37 ++- .../Controls/NDataGridView.cs | 26 +- UE4localizationsTool/Controls/NForm.cs | 83 +++++- UE4localizationsTool/Controls/NTextBox.cs | 4 +- .../Controls/SearchBox.Designer.cs | 211 +++++++++++--- UE4localizationsTool/Controls/SearchBox.cs | 261 ++++++++++++------ UE4localizationsTool/Controls/SearchBox.resx | 3 + UE4localizationsTool/Core/IoPackage.cs | 15 +- .../Core/locres/LocresNamespace.cs | 25 +- .../Forms/FrmLocresEntryEditor.cs | 14 +- .../Forms/FrmMain.Designer.cs | 25 +- UE4localizationsTool/Forms/FrmMain.cs | 88 +++--- UE4localizationsTool/Helper/CSVFile.cs | 111 ++++---- .../Properties/AssemblyInfo.cs | 4 +- .../Properties/Settings.Designer.cs | 14 +- .../Properties/Settings.settings | 3 + .../UE4localizationsTool.csproj | 12 +- UE4localizationsTool/UpdateInfo.txt | 4 +- UE4localizationsTool/packages.config | 4 + 20 files changed, 655 insertions(+), 292 deletions(-) create mode 100644 UE4localizationsTool/packages.config diff --git a/UE4localizationsTool/App.config b/UE4localizationsTool/App.config index 136e35f..09edec9 100644 --- a/UE4localizationsTool/App.config +++ b/UE4localizationsTool/App.config @@ -16,6 +16,9 @@ True + + False + diff --git a/UE4localizationsTool/Commands.cs b/UE4localizationsTool/Commands.cs index a949872..000020a 100644 --- a/UE4localizationsTool/Commands.cs +++ b/UE4localizationsTool/Commands.cs @@ -38,12 +38,14 @@ public Commands(string Options, string SourcePath, Args args) GetFilterValues(); } - if (Flags.HasFlag(Args.CSV)){ + if (Flags.HasFlag(Args.CSV)) + { TextFileExtension = ".csv"; } string[] Paths; string ConsoleText; + string[] rows; switch (Options.ToLower()) { case "export"://Single File @@ -87,7 +89,18 @@ public Commands(string Options, string SourcePath, Args args) throw new Exception("Invalid text file type: " + Path.GetFileName(SourcePath)); } - Import(Path.ChangeExtension(SourcePath, null), File.ReadAllLines(SourcePath), Options.ToLower()); + + + if (Flags.HasFlag(Args.CSV)) + { + rows = CSVFile.Instance.Load(SourcePath, Flags.HasFlag(Args.noname)); + } + else + { + rows = File.ReadAllLines(SourcePath); + } + + Import(Path.ChangeExtension(SourcePath, null), rows, Options.ToLower()); Console.ForegroundColor = ConsoleColor.Green; Console.Write("Done\n"); Console.ForegroundColor = ConsoleColor.White; @@ -104,7 +117,19 @@ public Commands(string Options, string SourcePath, Args args) throw new Exception("Invalid text file type: " + Path.GetFileName(SourcePath)); } - ImportFolder(Paths[0], File.ReadAllLines(Paths[1]), Options.ToLower()); + + + if (Flags.HasFlag(Args.CSV)) + { + rows = CSVFile.Instance.Load(Paths[1], Flags.HasFlag(Args.noname)); + } + else + { + rows = File.ReadAllLines(Paths[1]); + } + + + ImportFolder(Paths[0], rows, Options.ToLower()); break; default: throw new Exception("Invalid number of arguments.\n" + Program.commandlines); @@ -123,7 +148,7 @@ private void SaveTextFile(string FilePath) if (Flags.HasFlag(Args.CSV)) { - CSVFile.Instance.Save(Strings, FilePath); + CSVFile.Instance.Save(Strings, FilePath, Flags.HasFlag(Args.noname)); goto End; } @@ -151,7 +176,7 @@ private void SaveTextFile(string FilePath) i++; } File.WriteAllLines(FilePath, stringsArray); - End: + End: Console.ForegroundColor = ConsoleColor.Green; Console.Write("Done\n"); Console.ForegroundColor = ConsoleColor.White; @@ -301,7 +326,7 @@ private void Import(string FilePath, string[] Values, string Option) { var locres = new LocresFile(FilePath); var strings = locres.ExtractTexts(); - EditList(locres.ExtractTexts(), Values); + EditList(strings, Values); locres.ImportTexts(strings); if (Option == "-import") diff --git a/UE4localizationsTool/Controls/NDataGridView.cs b/UE4localizationsTool/Controls/NDataGridView.cs index 7848307..5917acb 100644 --- a/UE4localizationsTool/Controls/NDataGridView.cs +++ b/UE4localizationsTool/Controls/NDataGridView.cs @@ -29,6 +29,7 @@ struct DataRow [Browsable(true)] public event EventHandler RowCountChanged; + private bool _isFiltering = false; [Browsable(false)] @@ -124,28 +125,7 @@ protected void ClearUndoRedoStacks() } - //protected override void OnCellBeginEdit(DataGridViewCellCancelEventArgs e) - //{ - // // BackupDataUndo.Push(new DataRow() { cell = Rows[e.RowIndex].Cells[e.ColumnIndex], StringValue = Rows[e.RowIndex].Cells[e.ColumnIndex].Value, style = Rows[e.RowIndex].Cells[e.ColumnIndex].Style.Clone() }); - // base.OnCellBeginEdit(e); - //} - - //protected override void OnCellEndEdit(DataGridViewCellEventArgs e) - //{ - // base.OnCellEndEdit(e); - // if (BackupDataUndo.Count > 0) - // { - // if (!object.Equals(BackupDataUndo.Peek().StringValue, Rows[e.RowIndex].Cells[e.ColumnIndex].Value)) - // { - // BackupDataRedo.Clear(); - // UpdateBackColor(Rows[e.RowIndex].Cells[e.ColumnIndex]); - // } - // else - // { - // BackupDataUndo.Pop(); - // } - // } - //} + protected override void OnCellValidating(DataGridViewCellValidatingEventArgs e) { @@ -160,7 +140,7 @@ protected override void OnCellValidating(DataGridViewCellValidatingEventArgs e) } - public void SetValue(DataGridViewCell cell,object Value) + public void SetValue(DataGridViewCell cell, object Value) { if (!object.Equals(Value, cell.Value)) { diff --git a/UE4localizationsTool/Controls/NForm.cs b/UE4localizationsTool/Controls/NForm.cs index 8fba95c..125f2d4 100644 --- a/UE4localizationsTool/Controls/NForm.cs +++ b/UE4localizationsTool/Controls/NForm.cs @@ -12,6 +12,88 @@ protected override void CreateHandle() DarkMode(this); } +#if DEBUG + + protected override void OnLoad(System.EventArgs e) + { + GetAllControlNames(this, Name); + } + + private void GetAllControlNames(Control control, string parentName) + { + string controlName = parentName; + + if (control is TextBox || control is Label || control is Button || control is ComboBox + || control is ListBox || control is DataGridView || control is CheckBox) + { + controlName += $".{control.Name}"; + //control.GetType().GetProperty("Text", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SetValue(column, "amr"); + Console.WriteLine(controlName); + + if (control is DataGridView) + { + foreach (DataGridViewColumn column in ((DataGridView)control).Columns) + { + Console.WriteLine(controlName + "." + column.Name); + //column.HeaderText = "amr"; + // column.GetType().GetProperty("HeaderText", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SetValue(column, "amr"); + } + } + + } + else if (control is ToolStripMenuItem) + { + controlName += $".{control.Name}"; + //control.GetType().GetProperty("Text", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SetValue(column, "amr"); + Console.WriteLine(controlName); + } + + foreach (Control childControl in control.Controls) + { + GetAllControlNames(childControl, controlName); + } + + if (control.ContextMenuStrip != null) + { + foreach (ToolStripMenuItem toolStripItem in control.ContextMenuStrip.Items) + { + GetAllContextMenuNames(toolStripItem, controlName); + } + } + + if (control is MenuStrip) + { + foreach (var toolStripItem in ((MenuStrip)control).Items) + { + if (toolStripItem is ToolStripMenuItem) + GetAllContextMenuNames((ToolStripMenuItem)toolStripItem, controlName); + } + } + } + + private void GetAllContextMenuNames(ToolStripMenuItem control, string parentName) + { + string controlName = parentName; + + if (control is ToolStripMenuItem) + { + controlName += $".{(control as ToolStripMenuItem).Name}"; + //control.GetType().GetProperty("Text", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SetValue(column, "amr"); + Console.WriteLine(controlName); + } + + // Recursively call the method for child controls + foreach (ToolStripItem childControl in control.DropDownItems) + { + if (childControl is ToolStripMenuItem) + { + GetAllContextMenuNames(childControl as ToolStripMenuItem, controlName); + } + } + } + +#endif + public void DarkMode(Control control) { if (control == null) return; @@ -77,7 +159,6 @@ public void DarkMode(Control control) button.BackColor = Color.FromArgb(40, 40, 40); button.ForeColor = Color.White; button.FlatStyle = FlatStyle.Flat; - button.FlatAppearance.BorderSize = 1; button.FlatAppearance.BorderColor = Color.FromArgb(60, 60, 60); button.FlatAppearance.MouseOverBackColor = Color.FromArgb(60, 60, 60); } diff --git a/UE4localizationsTool/Controls/NTextBox.cs b/UE4localizationsTool/Controls/NTextBox.cs index 94cc922..d534ce6 100644 --- a/UE4localizationsTool/Controls/NTextBox.cs +++ b/UE4localizationsTool/Controls/NTextBox.cs @@ -43,11 +43,11 @@ private void UpdatePlaceholderText() protected override void OnKeyPress(KeyPressEventArgs e) { - if (Multiline&&StopEnterKey && e.KeyChar == '\r'|| StopEnterKey && e.KeyChar == '\n') + if (Multiline && StopEnterKey && e.KeyChar == '\r' || StopEnterKey && e.KeyChar == '\n') { e.Handled = true; } - + base.OnKeyPress(e); } diff --git a/UE4localizationsTool/Controls/SearchBox.Designer.cs b/UE4localizationsTool/Controls/SearchBox.Designer.cs index c2c30e3..0f1bea2 100644 --- a/UE4localizationsTool/Controls/SearchBox.Designer.cs +++ b/UE4localizationsTool/Controls/SearchBox.Designer.cs @@ -31,28 +31,35 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.searchcount = new System.Windows.Forms.Label(); this.SearchHide = new System.Windows.Forms.Label(); this.FindPrevious = new System.Windows.Forms.Button(); this.FindNext = new System.Windows.Forms.Button(); - this.InputSearch = new UE4localizationsTool.Controls.NTextBox(); this.label1 = new System.Windows.Forms.Label(); + this.panel1 = new System.Windows.Forms.Panel(); + this.FindAll = new System.Windows.Forms.Button(); + this.Replacepanel = new System.Windows.Forms.Panel(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.Replace = new System.Windows.Forms.Button(); + this.colorDialog1 = new System.Windows.Forms.ColorDialog(); + this.listView1 = new System.Windows.Forms.ListView(); + this.RowIndex = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.CellValue = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.txtReplace = new UE4localizationsTool.Controls.NTextBox(); + this.InputSearch = new UE4localizationsTool.Controls.NTextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.ReplaceAll = new System.Windows.Forms.Button(); + this.panel1.SuspendLayout(); + this.Replacepanel.SuspendLayout(); this.SuspendLayout(); // - // searchcount - // - this.searchcount.Location = new System.Drawing.Point(423, 7); - this.searchcount.Name = "searchcount"; - this.searchcount.Size = new System.Drawing.Size(211, 18); - this.searchcount.TabIndex = 6; - // // SearchHide // this.SearchHide.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.SearchHide.AutoSize = true; this.SearchHide.Cursor = System.Windows.Forms.Cursors.Hand; this.SearchHide.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold); - this.SearchHide.Location = new System.Drawing.Point(665, 7); + this.SearchHide.Location = new System.Drawing.Point(670, 9); this.SearchHide.Name = "SearchHide"; this.SearchHide.Size = new System.Drawing.Size(18, 17); this.SearchHide.TabIndex = 5; @@ -61,9 +68,9 @@ private void InitializeComponent() // // FindPrevious // - this.FindPrevious.Location = new System.Drawing.Point(331, 4); + this.FindPrevious.Location = new System.Drawing.Point(311, 5); this.FindPrevious.Name = "FindPrevious"; - this.FindPrevious.Size = new System.Drawing.Size(86, 23); + this.FindPrevious.Size = new System.Drawing.Size(92, 23); this.FindPrevious.TabIndex = 4; this.FindPrevious.Text = "Find Previous"; this.FindPrevious.UseVisualStyleBackColor = true; @@ -71,57 +78,197 @@ private void InitializeComponent() // // FindNext // - this.FindNext.Location = new System.Drawing.Point(250, 4); + this.FindNext.Location = new System.Drawing.Point(231, 5); this.FindNext.Name = "FindNext"; - this.FindNext.Size = new System.Drawing.Size(75, 23); + this.FindNext.Size = new System.Drawing.Size(76, 23); this.FindNext.TabIndex = 3; this.FindNext.Text = "Find Next"; this.FindNext.UseVisualStyleBackColor = true; this.FindNext.Click += new System.EventHandler(this.FindNext_Click); // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(4, 11); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(31, 13); + this.label1.TabIndex = 1; + this.label1.Text = "Find:"; + // + // panel1 + // + this.panel1.Controls.Add(this.label2); + this.panel1.Controls.Add(this.FindAll); + this.panel1.Controls.Add(this.InputSearch); + this.panel1.Controls.Add(this.label1); + this.panel1.Controls.Add(this.SearchHide); + this.panel1.Controls.Add(this.FindNext); + this.panel1.Controls.Add(this.FindPrevious); + this.panel1.Dock = System.Windows.Forms.DockStyle.Top; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(695, 33); + this.panel1.TabIndex = 0; + // + // FindAll + // + this.FindAll.Location = new System.Drawing.Point(407, 5); + this.FindAll.Name = "FindAll"; + this.FindAll.Size = new System.Drawing.Size(64, 23); + this.FindAll.TabIndex = 7; + this.FindAll.Text = "All"; + this.FindAll.UseVisualStyleBackColor = true; + this.FindAll.Click += new System.EventHandler(this.FindAll_Click); + // + // Replacepanel + // + this.Replacepanel.Controls.Add(this.ReplaceAll); + this.Replacepanel.Controls.Add(this.txtReplace); + this.Replacepanel.Controls.Add(this.label3); + this.Replacepanel.Controls.Add(this.label4); + this.Replacepanel.Controls.Add(this.Replace); + this.Replacepanel.Dock = System.Windows.Forms.DockStyle.Top; + this.Replacepanel.Location = new System.Drawing.Point(0, 33); + this.Replacepanel.Name = "Replacepanel"; + this.Replacepanel.Size = new System.Drawing.Size(695, 34); + this.Replacepanel.TabIndex = 1; + this.Replacepanel.Visible = false; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(4, 11); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(49, 13); + this.label3.TabIndex = 1; + this.label3.Text = "Replace:"; + // + // label4 + // + this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label4.AutoSize = true; + this.label4.Cursor = System.Windows.Forms.Cursors.Hand; + this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold); + this.label4.Location = new System.Drawing.Point(670, 9); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(18, 17); + this.label4.TabIndex = 5; + this.label4.Text = "X"; + this.label4.Click += new System.EventHandler(this.label4_Click); + // + // Replace + // + this.Replace.Location = new System.Drawing.Point(231, 5); + this.Replace.Name = "Replace"; + this.Replace.Size = new System.Drawing.Size(76, 23); + this.Replace.TabIndex = 3; + this.Replace.Text = "Replace"; + this.Replace.UseVisualStyleBackColor = true; + this.Replace.Click += new System.EventHandler(this.Replace_Click); + // + // listView1 + // + this.listView1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.RowIndex, + this.CellValue}); + this.listView1.Dock = System.Windows.Forms.DockStyle.Top; + this.listView1.FullRowSelect = true; + this.listView1.HideSelection = false; + this.listView1.Location = new System.Drawing.Point(0, 67); + this.listView1.MultiSelect = false; + this.listView1.Name = "listView1"; + this.listView1.Size = new System.Drawing.Size(695, 124); + this.listView1.TabIndex = 3; + this.listView1.UseCompatibleStateImageBehavior = false; + this.listView1.View = System.Windows.Forms.View.Details; + this.listView1.Visible = false; + this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged); + // + // RowIndex + // + this.RowIndex.Text = "Row Index"; + this.RowIndex.Width = 100; + // + // CellValue + // + this.CellValue.Text = "Value"; + this.CellValue.Width = 593; + // + // txtReplace + // + this.txtReplace.Location = new System.Drawing.Point(65, 7); + this.txtReplace.Name = "txtReplace"; + this.txtReplace.PlaceholderText = "Type your replace value here..."; + this.txtReplace.Size = new System.Drawing.Size(162, 20); + this.txtReplace.StopEnterKey = false; + this.txtReplace.TabIndex = 0; + // // InputSearch // - this.InputSearch.Location = new System.Drawing.Point(79, 5); + this.InputSearch.Location = new System.Drawing.Point(65, 7); this.InputSearch.Name = "InputSearch"; this.InputSearch.PlaceholderText = "Type your search here..."; this.InputSearch.Size = new System.Drawing.Size(162, 20); + this.InputSearch.StopEnterKey = false; this.InputSearch.TabIndex = 0; this.InputSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.InputSearch_KeyDown); // - // label1 + // label2 // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(7, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(56, 13); - this.label1.TabIndex = 1; - this.label1.Text = "Find what:"; + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(478, 11); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(0, 13); + this.label2.TabIndex = 8; + // + // ReplaceAll + // + this.ReplaceAll.Location = new System.Drawing.Point(311, 5); + this.ReplaceAll.Name = "ReplaceAll"; + this.ReplaceAll.Size = new System.Drawing.Size(64, 23); + this.ReplaceAll.TabIndex = 6; + this.ReplaceAll.Text = "All"; + this.ReplaceAll.UseVisualStyleBackColor = true; + this.ReplaceAll.Click += new System.EventHandler(this.ReplaceAll_Click); // // SearchBox // + this.AutoSize = true; this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.Controls.Add(this.searchcount); - this.Controls.Add(this.SearchHide); - this.Controls.Add(this.FindPrevious); - this.Controls.Add(this.FindNext); - this.Controls.Add(this.label1); - this.Controls.Add(this.InputSearch); + this.Controls.Add(this.listView1); + this.Controls.Add(this.Replacepanel); + this.Controls.Add(this.panel1); this.Location = new System.Drawing.Point(155, 23); this.Name = "SearchBox"; - this.Size = new System.Drawing.Size(689, 30); + this.Size = new System.Drawing.Size(695, 192); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.Replacepanel.ResumeLayout(false); + this.Replacepanel.PerformLayout(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - - private System.Windows.Forms.Label searchcount; private System.Windows.Forms.Label SearchHide; private System.Windows.Forms.Button FindPrevious; private System.Windows.Forms.Button FindNext; private System.Windows.Forms.Label label1; public NTextBox InputSearch; + private Panel panel1; + private Button FindAll; + private Panel Replacepanel; + public NTextBox txtReplace; + private Label label3; + private Label label4; + private Button Replace; + private ColorDialog colorDialog1; + private ListView listView1; + private ColumnHeader RowIndex; + private ColumnHeader CellValue; + private Label label2; + private Button ReplaceAll; } } diff --git a/UE4localizationsTool/Controls/SearchBox.cs b/UE4localizationsTool/Controls/SearchBox.cs index 70f85cf..dea45a2 100644 --- a/UE4localizationsTool/Controls/SearchBox.cs +++ b/UE4localizationsTool/Controls/SearchBox.cs @@ -1,11 +1,15 @@ using System; using System.ComponentModel; +using System.Text.RegularExpressions; using System.Windows.Forms; namespace UE4localizationsTool.Controls { public partial class SearchBox : UserControl { + + private string ColumnName = "Text value"; + [Browsable(true)] public NDataGridView DataGridView { get; set; } int CurrentRowIndex = -1; @@ -26,6 +30,8 @@ public SearchBox(NDataGridView dataGrid) private void SearchHide_Click(object sender, System.EventArgs e) { Hide(); + listView1.Visible = false; + label2.Text = string.Empty; } private bool IsMatch(string value) @@ -38,114 +44,96 @@ private bool IsMatch(string value) return value.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) > -1; } - private void FindNext_Click(object sender, EventArgs e) + private bool IsMatch(string value, string match) { - bool found = false; - - for (int rowIndex = CurrentRowIndex; rowIndex < DataGridView.Rows.Count; rowIndex++) + if (string.IsNullOrWhiteSpace(match)) + return false; + + return value.IndexOf(match, StringComparison.OrdinalIgnoreCase) > -1; + } + + + private DataGridViewCell FindCell(int startRowIndex, int endRowIndex, string columnName, string value, bool endToTop = false, bool returnNullIfNotFound = false) + { + int step = endToTop ? -1 : 1; + + for (int rowIndex = startRowIndex; endToTop ? rowIndex > endRowIndex : rowIndex < endRowIndex; rowIndex += step) { - for (int colIndex = CurrentColumnIndex + 1; colIndex < DataGridView.Columns.Count; colIndex++) + if (DataGridView.Columns.Contains(columnName)) { - if (rowIndex >= 0 && rowIndex < DataGridView.Rows.Count && colIndex >= 0 && colIndex < DataGridView.Columns.Count) + DataGridViewCell cell = DataGridView.Rows[rowIndex].Cells[columnName]; + if (cell.Value != null && IsMatch(cell.Value.ToString(), value)) { - DataGridViewCell cell = DataGridView.Rows[rowIndex].Cells[colIndex]; - if (cell.Value != null && IsMatch(cell.Value.ToString())) - { - SelectCell(rowIndex, colIndex); - found = true; - break; - } + return cell; } } + } + + if (returnNullIfNotFound) + { + return null; + } + + return FindCell(endToTop ? DataGridView.Rows.Count - 1 : 0, endToTop ? startRowIndex : endRowIndex, columnName, value, endToTop, true); + } - if (found) - break; - - CurrentColumnIndex = -1; + private void FindNext_Click(object sender, EventArgs e) + { + if (DataGridView.Rows.Count == 0) + { + MessageBox.Show("No data found.", "Search Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; } - if (!found) + var selectedCell = DataGridView.SelectedCells.Count > 0 ? DataGridView.SelectedCells[0] : DataGridView.Rows[0].Cells[ColumnName]; + + var cell = FindCell(selectedCell.RowIndex + 1, DataGridView.Rows.Count, ColumnName, InputSearch.Text); + + if (cell != null) { - - for (int rowIndex = 0; rowIndex < DataGridView.Rows.Count; rowIndex++) - { - for (int colIndex = 0; colIndex < DataGridView.Columns.Count; colIndex++) - { - if (rowIndex >= 0 && rowIndex < DataGridView.Rows.Count && colIndex >= 0 && colIndex < DataGridView.Columns.Count) - { - DataGridViewCell cell = DataGridView.Rows[rowIndex].Cells[colIndex]; - if (cell.Value != null && IsMatch(cell.Value.ToString())) - { - SelectCell(rowIndex, colIndex); - found = true; - break; - } - } - } - if (found) - break; + if (object.ReferenceEquals(cell, DataGridView.SelectedCells[0])) + { + MessageBox.Show("No more matches found.", "Search Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; } + + SelectCell(cell.RowIndex, cell.ColumnIndex); } - if (!found) + else { Failedmessage(); } + } private void FindPrevious_Click(object sender, EventArgs e) { - bool found = false; - for (int rowIndex = CurrentRowIndex; rowIndex >= 0; rowIndex--) + if (DataGridView.Rows.Count == 0) { - for (int colIndex = CurrentColumnIndex - 1; colIndex >= 0; colIndex--) - { - if (rowIndex >= 0 && rowIndex < DataGridView.Rows.Count && colIndex >= 0 && colIndex < DataGridView.Columns.Count) - { - DataGridViewCell cell = DataGridView.Rows[rowIndex].Cells[colIndex]; - if (cell.Value != null && IsMatch(cell.Value.ToString())) - { - SelectCell(rowIndex, colIndex); - found = true; - break; - } - } - } + MessageBox.Show("No data found.", "Search Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } - if (found) - break; + var selectedCell = DataGridView.SelectedCells.Count > 0 ? DataGridView.SelectedCells[0] : DataGridView.Rows[0].Cells[ColumnName]; - - CurrentColumnIndex = DataGridView.Columns.Count; - } + var cell = FindCell(selectedCell.RowIndex - 1, -1, ColumnName, InputSearch.Text, true); - if (!found) + if (cell != null) { - for (int rowIndex = DataGridView.Rows.Count - 1; rowIndex >= 0; rowIndex--) - { - for (int colIndex = DataGridView.Columns.Count - 1; colIndex >= 0; colIndex--) - { - if (rowIndex >= 0 && rowIndex < DataGridView.Rows.Count && colIndex >= 0 && colIndex < DataGridView.Columns.Count) - { - DataGridViewCell cell = DataGridView.Rows[rowIndex].Cells[colIndex]; - if (cell.Value != null && IsMatch(cell.Value.ToString())) - { - SelectCell(rowIndex, colIndex); - found = true; - break; - } - } - } - if (found) - break; + if (object.ReferenceEquals(cell, DataGridView.SelectedCells[0])) + { + MessageBox.Show("No more matches found.", "Search Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; } - } - if (!found) + SelectCell(cell.RowIndex, cell.ColumnIndex); + } + else { Failedmessage(); } @@ -187,14 +175,23 @@ private void InputSearch_KeyDown(object sender, KeyEventArgs e) public new void Show() { - if (DataGridView.CurrentCell!=null) + if (DataGridView.CurrentCell != null) { InputSearch.Text = DataGridView.CurrentCell.Value.ToString(); } InputSearch.Focus(); + + label2.Text = string.Empty; base.Show(); } + public void ShowReplacePanel() + { + Replacepanel.Visible = true; + Show(); + txtReplace.Focus(); + } + public int CountTotalMatches() { int totalMatches = 0; @@ -217,5 +214,113 @@ public int CountTotalMatches() return totalMatches; } + string ButtonText; + bool IsFindAll = false; + + private void FindAll_Click(object sender, EventArgs e) + { + Replacepanel.Visible = false; + + if (DataGridView.Rows.Count == 0) + { + MessageBox.Show("No data found.", "Search Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } + + listView1.Items.Clear(); + + foreach (DataGridViewRow row in DataGridView.Rows) + { + if (DataGridView.Columns.Contains(ColumnName)) + { + if (row.Cells[ColumnName].Value != null && IsMatch(row.Cells[ColumnName].Value.ToString())) + { + ListViewItem item = new ListViewItem(); + item.Text = (row.Index + 1).ToString(); + item.SubItems.Add(row.Cells[ColumnName].Value.ToString()); + item.Tag = row; + listView1.Items.Add(item); + } + } + } + listView1.Visible = true; + label2.Text = $"Total matches: {listView1.Items.Count}"; + + } + + + private void Replace_Click(object sender, EventArgs e) + { + + void ReplaceCell(DataGridViewCell Cell) + { + + + DataGridView.SetValue(Cell, Regex.Replace(Cell.Value.ToString(), InputSearch.Text, txtReplace.Text, RegexOptions.IgnoreCase)); + + } + + var selectedCell = DataGridView.SelectedCells.Count > 0 ? DataGridView.SelectedCells[0] : DataGridView.Rows[0].Cells[ColumnName]; + + + + if (IsMatch(selectedCell.Value.ToString())) + { + ReplaceCell(selectedCell); + return; + } + + var cell = FindCell(selectedCell.RowIndex + 1, DataGridView.Rows.Count, ColumnName, InputSearch.Text); + + if (cell != null) + { + SelectCell(cell.RowIndex, cell.ColumnIndex); + ReplaceCell(cell); + } + else + { + Failedmessage(); + } + } + + private void label4_Click(object sender, EventArgs e) + { + Replacepanel.Visible = false; + } + + private void listView1_SelectedIndexChanged(object sender, EventArgs e) + { + if (this.listView1.SelectedItems.Count == 0) + return; + var cell = (listView1.SelectedItems[0].Tag as DataGridViewRow).Cells[ColumnName]; + + SelectCell(cell.RowIndex, cell.ColumnIndex); + } + + private void ReplaceAll_Click(object sender, EventArgs e) + { + if (DataGridView.Rows.Count == 0) + { + MessageBox.Show("No data found.", "Search Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } + + + int totalMatches = 0; + foreach (DataGridViewRow row in DataGridView.Rows) + { + if (DataGridView.Columns.Contains(ColumnName)) + { + if (row.Cells[ColumnName].Value != null && IsMatch(row.Cells[ColumnName].Value.ToString())) + { + DataGridView.SetValue(row.Cells[ColumnName], Regex.Replace(row.Cells[ColumnName].Value.ToString(), InputSearch.Text, txtReplace.Text, RegexOptions.IgnoreCase)); + totalMatches++; + } + } + } + + + MessageBox.Show($"Total matches replaced: {totalMatches}", "Search Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } diff --git a/UE4localizationsTool/Controls/SearchBox.resx b/UE4localizationsTool/Controls/SearchBox.resx index 1af7de1..aa0ca0f 100644 --- a/UE4localizationsTool/Controls/SearchBox.resx +++ b/UE4localizationsTool/Controls/SearchBox.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/UE4localizationsTool/Core/IoPackage.cs b/UE4localizationsTool/Core/IoPackage.cs index acbac08..30c4721 100644 --- a/UE4localizationsTool/Core/IoPackage.cs +++ b/UE4localizationsTool/Core/IoPackage.cs @@ -26,7 +26,7 @@ public class IoPackage : IUasset public MemoryList UassetFile { get; set; } public bool IOFile { get; set; } = true; public bool IsNotUseUexp { get; set; } - public bool UseFromStruct { get; set; } + public bool UseFromStruct { get; set; } = true; public bool AutoVersion { get; set; } public bool UseMethod2 { get; set; } @@ -47,8 +47,19 @@ public IoPackage(string FilePath) //Todo IsNotUseUexp = true; + UassetFile.MemoryListPosition = 0; + ConsoleMode.Print("Reading Uasset Header..."); + Console.WriteLine(UassetFile.GetIntValue(false, 4)); - if (UassetFile.GetIntValue(false, 4) == 0) + + + UassetFile.Seek(UassetFile.GetIntValue(false, 24), SeekOrigin.Begin); + + string path = UassetFile.GetStringUES(); + UassetFile.Seek(0, SeekOrigin.Begin); + + + if (path.StartsWith("/")) { EngineVersion = UEVersions.VER_UE4_16; //?! UE4Header(); diff --git a/UE4localizationsTool/Core/locres/LocresNamespace.cs b/UE4localizationsTool/Core/locres/LocresNamespace.cs index 84a9c8d..ae2ad87 100644 --- a/UE4localizationsTool/Core/locres/LocresNamespace.cs +++ b/UE4localizationsTool/Core/locres/LocresNamespace.cs @@ -2,7 +2,6 @@ using Helper.MemoryList; using System; using System.Collections.Generic; -using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; @@ -21,7 +20,7 @@ public HashTable() { } - public HashTable(uint NameHash, uint KeyHash=0, uint ValueHash=0) + public HashTable(uint NameHash, uint KeyHash = 0, uint ValueHash = 0) { this.NameHash = NameHash; this.KeyHash = KeyHash; @@ -351,10 +350,10 @@ private void Save() locresData.SetUIntValue(Table.keyHash); } } - + locresData.SetStringUE(Table.key); - if(Table.ValueHash == 0) + if (Table.ValueHash == 0) { locresData.SetUIntValue(Table.Value.StrCrc32()); } @@ -476,7 +475,7 @@ public uint Optimized_CityHash64_UTF16Hash(string value) var Hash = CityHash.Init.CityHash64(Encoding.Unicode.GetBytes(value)); return (uint)Hash + ((uint)(Hash >> 32) * 23); } - + public void AddItemsToDataGridView(DataGridView dataGrid) { @@ -488,14 +487,14 @@ public void AddItemsToDataGridView(DataGridView dataGrid) dataTable.Columns.Add("Name", typeof(string)); dataTable.Columns.Add("Text value", typeof(string)); dataTable.Columns.Add("Hash Table", typeof(HashTable)); - + foreach (var names in this) { foreach (var table in names) { string name = string.IsNullOrEmpty(names.Name) ? table.key : names.Name + "::" + table.key; string textValue = table.Value; - dataTable.Rows.Add(name, textValue,new HashTable(names.NameHash,table.keyHash,table.ValueHash)); + dataTable.Rows.Add(name, textValue, new HashTable(names.NameHash, table.keyHash, table.ValueHash)); } } @@ -513,21 +512,21 @@ public void LoadFromDataGridView(DataGridView dataGrid) //1-> Key var items = row.Cells["Name"].Value.ToString().Split(new string[] { "::" }, StringSplitOptions.None); - string NameSpaceStr=""; - string KeyStr=""; - + string NameSpaceStr = ""; + string KeyStr = ""; + if (items.Length == 2) { NameSpaceStr = items[0]; KeyStr = items[1]; - + } else { KeyStr = items[0]; } - var HashTable= row.Cells["Hash Table"].Value as HashTable; + var HashTable = row.Cells["Hash Table"].Value as HashTable; @@ -547,7 +546,7 @@ public List> ExtractTexts() if (!string.IsNullOrEmpty(names.Name)) strings.Add(new List() { names.Name + "::" + table.key, table.Value }); else - strings.Add(new List() { names.Name, table.Value }); + strings.Add(new List() { table.key, table.Value }); } } diff --git a/UE4localizationsTool/Forms/FrmLocresEntryEditor.cs b/UE4localizationsTool/Forms/FrmLocresEntryEditor.cs index ffd761a..8e556e8 100644 --- a/UE4localizationsTool/Forms/FrmLocresEntryEditor.cs +++ b/UE4localizationsTool/Forms/FrmLocresEntryEditor.cs @@ -1,7 +1,6 @@ using System; using System.Data; using System.Drawing; -using System.Text; using System.Windows.Forms; using UE4localizationsTool.Controls; using UE4localizationsTool.Core.Hash; @@ -59,7 +58,7 @@ public FrmLocresEntryEditor(NDataGridView gridView, LocresFile asset) Value = gridView.CurrentCell.OwningRow.Cells["Text value"].Value.ToString(); } - var Hashs= gridView.CurrentCell.OwningRow.Cells["Hash Table"].Value as HashTable; + var Hashs = gridView.CurrentCell.OwningRow.Cells["Hash Table"].Value as HashTable; txtNameSapceHash.Text = Hashs.NameHash.ToString(); txtKeyHash.Text = Hashs.KeyHash.ToString(); @@ -67,11 +66,12 @@ public FrmLocresEntryEditor(NDataGridView gridView, LocresFile asset) Print(); } - public FrmLocresEntryEditor(Form form) + public FrmLocresEntryEditor(Form form, LocresFile asset) { InitializeComponent(); this.Location = new Point(form.Location.X + (form.Width - this.Width) / 2, form.Location.Y + (form.Height - this.Height) / 2); Apply.Text = "Add"; + this.asset = asset; } private void Print() @@ -102,7 +102,7 @@ public void AddRow(NDataGridView gridView) // throw new Exception("this NameSpace and Key already exists in the table."); //} - dt.Rows.Add(RowName, Value,HashTable); + dt.Rows.Add(RowName, Value, HashTable); } @@ -150,18 +150,18 @@ private void BtnKey_Click(object sender, EventArgs e) private void BtnValue_Click(object sender, EventArgs e) { - txtValueHash.Text=txtValue.Text.StrCrc32().ToString(); + txtValueHash.Text = txtValue.Text.StrCrc32().ToString(); } private void Apply_Click(object sender, EventArgs e) { - if(string.IsNullOrEmpty(txtNameSapceHash.Text)|| string.IsNullOrEmpty(txtKeyHash.Text)|| string.IsNullOrEmpty(txtValueHash.Text)) + if (string.IsNullOrEmpty(txtNameSapceHash.Text) || string.IsNullOrEmpty(txtKeyHash.Text) || string.IsNullOrEmpty(txtValueHash.Text)) { MessageBox.Show("NameSpace or Key or Value is empty"); return; } - if(!uint.TryParse(txtNameSapceHash.Text,out uint temp)|| !uint.TryParse(txtKeyHash.Text, out uint temp1) || !uint.TryParse(txtValueHash.Text, out uint temp2)) + if (!uint.TryParse(txtNameSapceHash.Text, out uint temp) || !uint.TryParse(txtKeyHash.Text, out uint temp1) || !uint.TryParse(txtValueHash.Text, out uint temp2)) { MessageBox.Show("NameSpace or Key or Value is not a number"); return; diff --git a/UE4localizationsTool/Forms/FrmMain.Designer.cs b/UE4localizationsTool/Forms/FrmMain.Designer.cs index 5a2319f..f51b957 100644 --- a/UE4localizationsTool/Forms/FrmMain.Designer.cs +++ b/UE4localizationsTool/Forms/FrmMain.Designer.cs @@ -47,6 +47,7 @@ private void InitializeComponent() this.importAllTextToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.find = new System.Windows.Forms.ToolStripMenuItem(); + this.replaceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.filterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.clearFilterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sortToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -158,6 +159,7 @@ private void InitializeComponent() this.importAllTextToolStripMenuItem, this.toolStripSeparator1, this.find, + this.replaceToolStripMenuItem, this.filterToolStripMenuItem, this.clearFilterToolStripMenuItem, this.sortToolStripMenuItem, @@ -236,6 +238,14 @@ private void InitializeComponent() this.find.Text = "Find"; this.find.Click += new System.EventHandler(this.find_Click); // + // replaceToolStripMenuItem + // + this.replaceToolStripMenuItem.Name = "replaceToolStripMenuItem"; + this.replaceToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.H))); + this.replaceToolStripMenuItem.Size = new System.Drawing.Size(229, 22); + this.replaceToolStripMenuItem.Text = "Replace"; + this.replaceToolStripMenuItem.Click += new System.EventHandler(this.replaceToolStripMenuItem_Click); + // // filterToolStripMenuItem // this.filterToolStripMenuItem.Enabled = false; @@ -530,15 +540,10 @@ private void InitializeComponent() this.dataGridView1.RowHeadersVisible = false; this.dataGridView1.RowHeadersWidth = 51; this.dataGridView1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.dataGridView1.Size = new System.Drawing.Size(689, 396); + this.dataGridView1.Size = new System.Drawing.Size(689, 390); this.dataGridView1.TabIndex = 1; this.dataGridView1.FilterApplied += new System.EventHandler(this.dataGridView1_FilterApplied); this.dataGridView1.FilterCleared += new System.EventHandler(this.dataGridView1_FilterCleared); - this.dataGridView1.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dataGridView1_CellFormatting); - this.dataGridView1.CellValidated += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellValidated); - this.dataGridView1.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView1_CellValidating); - this.dataGridView1.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellValueChanged); - this.dataGridView1.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.dataGridView1_CellValuePushed); this.dataGridView1.Sorted += new System.EventHandler(this.dataGridView1_Sorted); // // TextName @@ -578,12 +583,13 @@ private void InitializeComponent() // // searchBox // + this.searchBox.AutoSize = true; this.searchBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.searchBox.DataGridView = this.dataGridView1; this.searchBox.Dock = System.Windows.Forms.DockStyle.Bottom; - this.searchBox.Location = new System.Drawing.Point(0, 420); + this.searchBox.Location = new System.Drawing.Point(0, 414); this.searchBox.Name = "searchBox"; - this.searchBox.Size = new System.Drawing.Size(689, 30); + this.searchBox.Size = new System.Drawing.Size(689, 36); this.searchBox.TabIndex = 2; this.searchBox.Visible = false; // @@ -607,7 +613,7 @@ private void InitializeComponent() this.StatusText.AutoSize = true; this.StatusText.Location = new System.Drawing.Point(106, 65); this.StatusText.Name = "StatusText"; - this.StatusText.Size = new System.Drawing.Size(28, 13); + this.StatusText.Size = new System.Drawing.Size(35, 13); this.StatusText.TabIndex = 2; this.StatusText.Text = "-------"; // @@ -722,6 +728,7 @@ private void InitializeComponent() private PictureBox pictureBox2; private Panel StatusBlock; private ToolStripMenuItem mergeUassetFileToolStripMenuItem; + private ToolStripMenuItem replaceToolStripMenuItem; } } diff --git a/UE4localizationsTool/Forms/FrmMain.cs b/UE4localizationsTool/Forms/FrmMain.cs index 33201d0..7f13a17 100644 --- a/UE4localizationsTool/Forms/FrmMain.cs +++ b/UE4localizationsTool/Forms/FrmMain.cs @@ -53,39 +53,39 @@ public async void LoadFile(string filePath) ResetControls(); ControlsMode(false); - try - { - StatusMessage("loading File...", "loading File, please wait."); + //try + //{ + StatusMessage("loading File...", "loading File, please wait."); - if (filePath.ToLower().EndsWith(".locres")) - { - Asset = await Task.Run(() => new LocresFile(filePath)); - locresOprationsToolStripMenuItem.Visible = true; - CreateBackupList(); - } - else if (filePath.ToLower().EndsWith(".uasset") || filePath.ToLower().EndsWith(".umap")) - { - IUasset Uasset = await Task.Run(() => Uexp.GetUasset(filePath)); - Uasset.UseMethod2 = Uasset.UseMethod2 ? Uasset.UseMethod2 : Method2.Checked; - Asset = await Task.Run(() => new Uexp(Uasset)); - CreateBackupList(); - if (!Asset.IsGood) - { - StateLabel.Text = "Warning: This file is't fully parsed and may not contain some text."; - } - } - - this.FilePath = filePath; - this.Text = ToolName + " - " + Path.GetFileName(FilePath); - ControlsMode(true); - CloseFromState(); + if (filePath.ToLower().EndsWith(".locres")) + { + Asset = await Task.Run(() => new LocresFile(filePath)); + locresOprationsToolStripMenuItem.Visible = true; + CreateBackupList(); } - catch (Exception ex) + else if (filePath.ToLower().EndsWith(".uasset") || filePath.ToLower().EndsWith(".umap")) { - CloseFromState(); - MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + IUasset Uasset = await Task.Run(() => Uexp.GetUasset(filePath)); + Uasset.UseMethod2 = Uasset.UseMethod2 ? Uasset.UseMethod2 : Method2.Checked; + Asset = await Task.Run(() => new Uexp(Uasset)); + CreateBackupList(); + if (!Asset.IsGood) + { + StateLabel.Text = "Warning: This file is't fully parsed and may not contain some text."; + } } + this.FilePath = filePath; + this.Text = ToolName + " - " + Path.GetFileName(FilePath); + ControlsMode(true); + CloseFromState(); + //} + //catch (Exception ex) + //{ + // CloseFromState(); + // MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + //} + } private void CreateBackupList() @@ -411,6 +411,13 @@ private void FrmMain_Load(object sender, EventArgs e) ); } + + if (!UE4localizationsTool.Properties.Settings.Default.GoodByeMessage) + { + MessageBox.Show("Hello, I hope my tool has been helpful to you. This will be the final version. I apologize for any inconvenience.", "Good bye!", MessageBoxButtons.OK, MessageBoxIcon.Warning); + UE4localizationsTool.Properties.Settings.Default.GoodByeMessage = true; + UE4localizationsTool.Properties.Settings.Default.Save(); + } } private void noNamesToolStripMenuItem_Click(object sender, EventArgs e) @@ -625,7 +632,7 @@ private void editSelectedRowToolStripMenuItem_Click(object sender, EventArgs e) private void addNewRowToolStripMenuItem_Click(object sender, EventArgs e) { - var EntryEditor = new FrmLocresEntryEditor(this); + var EntryEditor = new FrmLocresEntryEditor(this, (LocresFile)Asset); if (EntryEditor.ShowDialog() == DialogResult.OK) { @@ -753,28 +760,9 @@ private void mergeUassetFileToolStripMenuItem_Click(object sender, EventArgs e) } } - private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) - { - - } - - private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) - { - - } - - private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e) - { - - } - - private void dataGridView1_CellValuePushed(object sender, DataGridViewCellValueEventArgs e) - { - - } - - private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) + private void replaceToolStripMenuItem_Click(object sender, EventArgs e) { + searchBox.ShowReplacePanel(); } } } diff --git a/UE4localizationsTool/Helper/CSVFile.cs b/UE4localizationsTool/Helper/CSVFile.cs index 0f1c4b1..fc274a4 100644 --- a/UE4localizationsTool/Helper/CSVFile.cs +++ b/UE4localizationsTool/Helper/CSVFile.cs @@ -1,6 +1,7 @@ -using Microsoft.VisualBasic.FileIO; +using Csv; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Windows.Forms; namespace UE4localizationsTool.Helper @@ -14,101 +15,85 @@ public class CSVFile public void Load(NDataGridView dataGrid, string filePath) { - - using (TextFieldParser parser = new TextFieldParser(filePath)) + int i = -1; + using (var textReader = new StreamReader(filePath)) { - parser.TextFieldType = FieldType.Delimited; - parser.SetDelimiters(Delimiter.ToString()); - - int i = -1; - if (!HasHeader) i++; - - while (!parser.EndOfData) + var options = new CsvOptions() { AllowNewLineInEnclosedFieldValues = true }; + foreach (var line in CsvReader.Read(textReader, options)) { - - string[] fields = parser.ReadFields(); - - if (HasHeader && i == -1) - { - i++; + ++i; + if (line.ColumnCount < 3) continue; - } - if (fields.Length >= 3 && !string.IsNullOrEmpty(fields[2])) - { - - dataGrid.SetValue(dataGrid.Rows[i].Cells["Text value"], fields[2]); - } - i++; + if (!string.IsNullOrEmpty(line[2])) + dataGrid.SetValue(dataGrid.Rows[i].Cells["Text value"], line[2]); } } + } public void Save(DataGridView dataGrid, string filePath) { using (var writer = new StreamWriter(filePath)) { - writer.WriteLine("Key,Source,Translation"); + var rows = new List(); foreach (DataGridViewRow row in dataGrid.Rows) { - writer.WriteLine("\"" + FixedString(row.Cells["Name"].Value) + "\"" + Delimiter.ToString() + "\"" + FixedString(row.Cells["Text value"].Value) + "\"" + Delimiter.ToString() + "\"" + "\""); + rows.Add(new[] { row.Cells["Name"].Value.ToString(), row.Cells["Text value"].Value.ToString(), "" }); } + CsvWriter.Write(writer, new string[] { "key", "source", "Translation" }, rows); } } - public void Load(List> Strings, string filePath) + public string[] Load(string filePath, bool NoNames = false) { - using (TextFieldParser parser = new TextFieldParser(filePath)) + var list = new List(); + using (var textReader = new StreamReader(filePath)) { - parser.TextFieldType = FieldType.Delimited; - parser.SetDelimiters(Delimiter.ToString()); - - int i = -1; - if (!HasHeader) i++; - - while (!parser.EndOfData) + var options = new CsvOptions() { AllowNewLineInEnclosedFieldValues = true }; + foreach (var line in CsvReader.Read(textReader, options)) { - - string[] fields = parser.ReadFields(); - - if (HasHeader && i == -1) - { - i++; - continue; - } - - if (fields.Length >= 3 && !string.IsNullOrEmpty(fields[2])) - { - Strings[i][1] = fields[2]; } - i++; + list.Add(Merge(line.Values, NoNames)); } } + + return list.ToArray(); } - public void Save(List> Strings,string filePath) + private string Merge(string[] strings, bool NoNames = false) { - - using (var writer = new StreamWriter(filePath)) + int i = 0; + int CollsCount = !NoNames ? 2 : 3; + string text = ""; + if (!NoNames && strings[i++] != "[~PATHFile~]") { - writer.WriteLine("Key,Source,Translation"); - foreach (var row in Strings) - { - if (row[0] == "[~PATHFile~]") - { - writer.WriteLine("\"" + FixedString(row[1]) + "\""); - continue; - } + text += strings[i - 1] + "="; + } + else + { + return strings[i]; + } - writer.WriteLine("\"" + FixedString(row[0]) + "\"" + Delimiter.ToString() + "\"" + FixedString(row[1]) + "\"" + Delimiter.ToString() + "\"" + "\""); - } + if (strings.Length < CollsCount || string.IsNullOrEmpty(strings.LastOrDefault())) + { + text += strings[i++]; } + else + { + text += strings.LastOrDefault(); + } + + return text; } - public static string FixedString(object str,bool returnValue =true) + public void Save(List> Strings, string filePath, bool NoNames = true) { - if (returnValue ) return str.ToString(); - return str.ToString().Replace("\"", "\"\""); + using (var writer = new StreamWriter(filePath)) + { + var rows = Strings.Select(x => NoNames ? new string[] { x[1], "" } : new string[] { x[0], x[1], "" }); + CsvWriter.Write(writer, NoNames ? new string[] { "source", "Translation" } : new string[] { "key", "source", "Translation" }, rows); + } } } diff --git a/UE4localizationsTool/Properties/AssemblyInfo.cs b/UE4localizationsTool/Properties/AssemblyInfo.cs index 7044330..9398a52 100644 --- a/UE4localizationsTool/Properties/AssemblyInfo.cs +++ b/UE4localizationsTool/Properties/AssemblyInfo.cs @@ -6,9 +6,9 @@ [assembly: AssemblyDescription("Simple tool to edit engine texts")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Arabic Subtitles")] -[assembly: AssemblyProduct("UE4 localizations Tool Beta")] +[assembly: AssemblyProduct("UE4 localizations Tool Final Version")] [assembly: AssemblyCopyright("Copyright © 2022 - By Amr Shaheen")] [assembly: AssemblyTrademark("amr shaheen")] [assembly: ComVisible(false)] [assembly: AssemblyVersion("1.0")] -[assembly: AssemblyFileVersion("2.5")] +[assembly: AssemblyFileVersion("2.6")] diff --git a/UE4localizationsTool/Properties/Settings.Designer.cs b/UE4localizationsTool/Properties/Settings.Designer.cs index c26a767..ebc190a 100644 --- a/UE4localizationsTool/Properties/Settings.Designer.cs +++ b/UE4localizationsTool/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace UE4localizationsTool.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.8.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -46,5 +46,17 @@ public bool CheckForUpdates { this["CheckForUpdates"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool GoodByeMessage { + get { + return ((bool)(this["GoodByeMessage"])); + } + set { + this["GoodByeMessage"] = value; + } + } } } diff --git a/UE4localizationsTool/Properties/Settings.settings b/UE4localizationsTool/Properties/Settings.settings index 7a6f0b1..29a20b9 100644 --- a/UE4localizationsTool/Properties/Settings.settings +++ b/UE4localizationsTool/Properties/Settings.settings @@ -8,5 +8,8 @@ True + + False + \ No newline at end of file diff --git a/UE4localizationsTool/UE4localizationsTool.csproj b/UE4localizationsTool/UE4localizationsTool.csproj index 89b6776..c63f36b 100644 --- a/UE4localizationsTool/UE4localizationsTool.csproj +++ b/UE4localizationsTool/UE4localizationsTool.csproj @@ -34,7 +34,7 @@ AnyCPU true full - true + false bin\Debug\ TRACE;DEBUG prompt @@ -54,6 +54,8 @@ TRACE prompt 4 + true + false @@ -184,6 +186,7 @@ Resources.resx True + SettingsSingleFileGenerator @@ -215,6 +218,13 @@ + + ..\packages\Csv.2.0.93\lib\net40\Csv.dll + False + False + True + + diff --git a/UE4localizationsTool/UpdateInfo.txt b/UE4localizationsTool/UpdateInfo.txt index 3404c44..0bb20fd 100644 --- a/UE4localizationsTool/UpdateInfo.txt +++ b/UE4localizationsTool/UpdateInfo.txt @@ -1,3 +1,3 @@ UpdateFile -Tool_UpdateVer = 2.5 -Tool_UpdateSite = https://github.com/amrshaheen61/UE4LocalizationsTool/releases/tag/v2.5 \ No newline at end of file +Tool_UpdateVer = 2.6 +Tool_UpdateSite = https://github.com/amrshaheen61/UE4LocalizationsTool/releases/tag/v2.6 \ No newline at end of file diff --git a/UE4localizationsTool/packages.config b/UE4localizationsTool/packages.config new file mode 100644 index 0000000..c625967 --- /dev/null +++ b/UE4localizationsTool/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file