Skip to content

Commit

Permalink
Add Save To functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
julianxhokaxhiu committed Sep 26, 2020
1 parent 4525c0d commit 268550a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/Entry.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 47 additions & 1 deletion src/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Entry()
ret.Close();
}

private void parseAudioFile(string audioDat, string audioFmt)
private bool parseAudioFile(string audioDat, string audioFmt)
{
audioList = new AudioFile[750];

Expand Down Expand Up @@ -74,6 +74,33 @@ private void parseAudioFile(string audioDat, string audioFmt)

fileFmt.Close();
fileDat.Close();

return true;
}

private bool dumpAudioFile(string audioDat, string audioFmt)
{
FileStream fileFmt = File.OpenWrite(audioFmt);
FileStream fileDat = File.OpenWrite(audioDat);

for (int idx = 0; idx < audioList.Length; ++idx)
{
AudioFile audioFile = audioList[idx];

// Write fmt header
fileFmt.WriteStruct<FmtFileHeader>(audioFile.fmtHeader);

// Write ADPCM data
fileFmt.WriteStruct<ADPCMWAVEFORMAT>(audioFile.formatChunk.ADPCM);

// Write audio data
if (audioFile.Data != null) fileDat.Write(audioFile.Data, 0, audioFile.Data.Length);
}

fileFmt.Close();
fileDat.Close();

return true;
}

private void getWaveStream(Stream stream, int idx)
Expand Down Expand Up @@ -177,5 +204,24 @@ private void Entry_KeyUp(object sender, KeyEventArgs e)
}
}
}

private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();

saveFileDialog.Filter = "FF7 Sound file (audio.dat)|audio.dat|All files (*.*)|*.*";
saveFileDialog.DefaultExt = "dat";
saveFileDialog.FileName = "audio.dat";
if (FF7Dir != string.Empty) saveFileDialog.InitialDirectory = FF7Dir;

if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string audioDat = saveFileDialog.FileName;
string audioFmt = Path.ChangeExtension(audioDat, "fmt");

if (dumpAudioFile(audioDat, audioFmt))
MessageBox.Show("Audio files were successfully saved in:\n\n" + audioFmt + "\n" + audioDat, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}

0 comments on commit 268550a

Please sign in to comment.