Skip to content

Commit

Permalink
Mainform: fix incorrect data for saving sound and rawdata.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagamia committed Oct 13, 2024
1 parent f88ff70 commit f766224
Showing 1 changed file with 6 additions and 54 deletions.
60 changes: 6 additions & 54 deletions WzComparerR2/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2283,11 +2283,11 @@ private void tsmi2SaveAs_Click(object sender, EventArgs e)
}
}
}
else if (item is Wz_Sound wzSound)
else if (item is IMapleStoryBlob blob)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = advTree3.SelectedNode.Text;
if (!dlg.FileName.Contains("."))
if (!dlg.FileName.Contains(".") && blob is Wz_Sound wzSound)
{
switch (wzSound.SoundType)
{
Expand All @@ -2300,60 +2300,12 @@ private void tsmi2SaveAs_Click(object sender, EventArgs e)
{
try
{
byte[] data = new byte[blob.Length];
blob.CopyTo(data, 0);
using (var f = File.Create(dlg.FileName))
{
wzSound.WzFile.FileStream.Seek(wzSound.Offset, SeekOrigin.Begin);
byte[] buffer = new byte[4096];
int bytes = wzSound.DataLength;
while (bytes > 0)
{
int count = wzSound.WzFile.FileStream.Read(buffer, 0, Math.Min(buffer.Length, bytes));
if (count > 0)
{
f.Write(buffer, 0, count);
bytes -= count;
}
else
{
break;
}
}
}
this.labelItemStatus.Text = "保存成功。";
}
catch (Exception ex)
{
MessageBoxEx.Show("文件保存失败。\r\n" + ex.ToString(), "提示");
}
}
}
else if (item is Wz_RawData rawData)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = advTree3.SelectedNode.Text;
dlg.Filter = "*.*|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
try
{
using (var f = File.Create(dlg.FileName))
{
rawData.WzFile.FileStream.Seek(rawData.Offset, SeekOrigin.Begin);
byte[] buffer = new byte[4096];
int bytes = rawData.Length;
while (bytes > 0)
{
int count = rawData.WzFile.FileStream.Read(buffer, 0, Math.Min(buffer.Length, bytes));
if (count > 0)
{
f.Write(buffer, 0, count);
bytes -= count;
}
else
{
break;
}
}
f.Write(data, 0, data.Length);
f.Flush();
}
this.labelItemStatus.Text = "保存成功。";
}
Expand Down

0 comments on commit f766224

Please sign in to comment.