diff --git a/Source/AboutEditorForm.resx b/Source/AboutEditorForm.resx index 9b4a25f..fa6a06a 100644 --- a/Source/AboutEditorForm.resx +++ b/Source/AboutEditorForm.resx @@ -130,13 +130,13 @@ 280, 9 - 78, 19 + 89, 19 1 - Version 1.2 + Version 1.2.1 MiddleCenter diff --git a/Source/Editor.cs b/Source/Editor.cs index 1c8c754..1e40e91 100644 --- a/Source/Editor.cs +++ b/Source/Editor.cs @@ -22,6 +22,7 @@ public partial class Editor : Form public delegate void UpdateProgressBar(double num); public UpdateProgressBar updateProgressBar; public DataTable dataTable; + public bool isTextChanged = false; public Editor() { @@ -81,6 +82,7 @@ private void button1_Click(object sender, EventArgs e) dataTable.Rows.Clear(); dataTable = tempDataTable.Copy(); } + isTextChanged = true; Close(); } diff --git a/Source/MainUI.cs b/Source/MainUI.cs index 7407eee..201532a 100644 --- a/Source/MainUI.cs +++ b/Source/MainUI.cs @@ -52,6 +52,8 @@ public MainUI() private string publicPath = string.Empty; private bool pathOpened = false; + private bool canAlsoSave = false; + private bool isTextChanged = false; private void exitToolStripMenuItem_Click(object sender, EventArgs e) { @@ -132,13 +134,15 @@ private void savePackageToolStripMenuItem_Click(object sender, EventArgs e) { if (pathOpened) SaveSTBLFile(false); - else if (!pathOpened && dataGridView1.Rows.Count > 0) + else if (canAlsoSave) SaveSTBLFile(true); + isTextChanged = false; } private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { SaveSTBLFile(true); + isTextChanged = false; } private void aboutToolStripMenuItem1_Click(object sender, EventArgs e) @@ -291,31 +295,18 @@ private void button3_Click(object sender, EventArgs e) XMLToDataGridView(tempList, xmlFilePath); - switch (Thread.CurrentThread.CurrentUICulture.ThreeLetterWindowsLanguageName) - { - case "CHS": - case "ZHI": - MessageBox.Show("导入成功!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - case "CHT": - case "ZHH": - case "ZHM": - MessageBox.Show("匯入成功!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - default: - MessageBox.Show("Successfully Imported!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - } - UseWaitCursor = false; progressBar1.Visible = false; + if (!pathOpened) + canAlsoSave = true; + isTextChanged = true; } private void closeToolStripMenuItem_Click(object sender, EventArgs e) { - if (pathOpened) + if (isTextChanged && pathOpened) SaveSTBLFile(false); - else if (dataGridView1.Rows.Count > 0) + else if (isTextChanged && dataGridView1.Rows.Count > 0) SaveSTBLFile(true); dataGridView1.DataSource = null; @@ -340,6 +331,8 @@ private void closeToolStripMenuItem_Click(object sender, EventArgs e) } publicPath = string.Empty; pathOpened = false; + canAlsoSave = false; + isTextChanged = false; } } } diff --git a/Source/TS4 STBL Editor.v12.suo b/Source/TS4 STBL Editor.v12.suo index 955edab..c402d19 100644 Binary files a/Source/TS4 STBL Editor.v12.suo and b/Source/TS4 STBL Editor.v12.suo differ diff --git a/Source/Tools.cs b/Source/Tools.cs index d5ce7b9..eaba542 100644 --- a/Source/Tools.cs +++ b/Source/Tools.cs @@ -191,7 +191,7 @@ public string WriteSTBLFile(ArrayList mainArrayList, bool isSaveAs, string stblF binaryWriter.Write(((string)textString[i]).ToCharArray()); } - if (isSaveAs) + if (isSaveAs || canAlsoSave) { SaveFileDialog SaveFile = new SaveFileDialog(); switch (Thread.CurrentThread.CurrentUICulture.ThreeLetterWindowsLanguageName) @@ -221,13 +221,18 @@ public string WriteSTBLFile(ArrayList mainArrayList, bool isSaveAs, string stblF if (SaveFile.ShowDialog() == DialogResult.OK) { stblFilePath = SaveFile.FileName; - FileStream stblStream = new FileStream(stblFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); - BinaryWriter stblFileWriter = new BinaryWriter(stblStream); - stblFileWriter.Write(stblMemoryStream.ToArray()); - stblStream.Dispose(); + } + else + { + stblMemoryStream.Dispose(); + return stblFilePath; } } + FileStream stblStream = new FileStream(stblFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); + BinaryWriter stblFileWriter = new BinaryWriter(stblStream); + stblFileWriter.Write(stblMemoryStream.ToArray()); + stblStream.Dispose(); stblMemoryStream.Dispose(); return stblFilePath; @@ -352,6 +357,7 @@ public void SaveSTBLFile(bool isSaveAs) publicPath = WriteSTBLFile(tempList, isSaveAs, publicPath); toolStripStatusLabel2.Text = publicPath; + pathOpened = true; } public void STBLToDataGridView(ArrayList tempList) @@ -426,14 +432,6 @@ public void XMLToDataGridView(ArrayList tempList, string xmlFilePath) dataGridView1.Columns.Clear(); dataGridView1.DataSource = dataTable; RestoreDataGridViewSettings(); - - //dataGridView1.Rows.Add(textString.Count); - /*for (int i = 0; i < textString.Count; i++) - { - dataGridView1.Rows[i].Cells[0].Value = "0x" + ((uint)textResourceID[i]).ToString("X8"); - dataGridView1.Rows[i].Cells[1].Value = textString[i]; - progressBar1.Value = progressBar1.Maximum * i / textString.Count; - }*/ } else { @@ -488,8 +486,6 @@ public void XMLToDataGridView(ArrayList tempList, string xmlFilePath) tempDataGridView.Rows[0].Cells[2].Selected = true; tempDataGridView.Sort(tempDataGridView.Columns[2], ListSortDirection.Ascending); - //dataGridView1.Rows.Clear(); - //dataGridView1.Rows.Add(tempDataGridView.Rows.Count); DataTable dataTable = new DataTable(); DataColumn dc; DataRow dr; @@ -510,14 +506,6 @@ public void XMLToDataGridView(ArrayList tempList, string xmlFilePath) dataGridView1.Columns.Clear(); dataGridView1.DataSource = dataTable; RestoreDataGridViewSettings(); - - - /*for (int i = 0; i < tempDataGridView.Rows.Count; i++) - { - dataGridView1.Rows[i].Cells[0].Value = "0x" + tempDataGridView.Rows[i].Cells[0].Value; - dataGridView1.Rows[i].Cells[1].Value = tempDataGridView.Rows[i].Cells[1].Value; - progressBar1.Value = lastProgressBarValue + progressBar1.Maximum / 4 * i / tempDataGridView.Rows.Count; - }*/ } foreach (DataGridViewRow row in dataGridView1.Rows)