2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
FileIO.cpp
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
Leland Lucius
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#include "Audacity.h"
|
|
|
|
|
|
|
|
#include <wx/defs.h>
|
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <wx/wfstream.h>
|
|
|
|
|
|
|
|
#include "FileIO.h"
|
|
|
|
|
|
|
|
FileIO::FileIO(const wxString name, FileIOMode mode)
|
|
|
|
: mName(name),
|
|
|
|
mMode(mode),
|
|
|
|
mInputStream(NULL),
|
|
|
|
mOutputStream(NULL),
|
|
|
|
mOpen(false)
|
|
|
|
{
|
|
|
|
wxString scheme;
|
|
|
|
|
|
|
|
if (mMode == FileIO::Input) {
|
|
|
|
mInputStream = new wxFFileInputStream(mName);
|
2014-12-06 12:06:48 +00:00
|
|
|
if (mInputStream == NULL || !mInputStream->IsOk()) {
|
2010-01-23 19:44:49 +00:00
|
|
|
wxPrintf(wxT("Couldn't get input stream: %s\n"), name.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mOutputStream = new wxFFileOutputStream(mName);
|
2014-12-06 12:06:48 +00:00
|
|
|
if (mOutputStream == NULL || !mOutputStream->IsOk()) {
|
2010-01-23 19:44:49 +00:00
|
|
|
wxPrintf(wxT("Couldn't get output stream: %s\n"), name.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mOpen = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileIO::~FileIO()
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileIO::IsOpened()
|
|
|
|
{
|
|
|
|
return mOpen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileIO::Close()
|
|
|
|
{
|
|
|
|
if (mOutputStream) {
|
|
|
|
delete mOutputStream;
|
|
|
|
mOutputStream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mInputStream) {
|
|
|
|
delete mInputStream;
|
|
|
|
mInputStream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCatalogInfo();
|
|
|
|
|
|
|
|
mOpen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// MacOS: set the file type/creator so that the OS knows it's an MP3
|
|
|
|
// file which was created by Audacity
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
void FileIO::SetCatalogInfo()
|
|
|
|
{
|
|
|
|
#ifdef __WXMAC__
|
2014-10-06 08:10:50 +00:00
|
|
|
#if !wxCHECK_VERSION(3, 0, 0)
|
2013-12-12 00:46:03 +00:00
|
|
|
if (!mOpen ) {
|
2010-01-23 19:44:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxUint32 type;
|
|
|
|
wxFileName fn(mName);
|
|
|
|
wxString ext = fn.GetExt().MakeUpper() + wxT(" ");
|
|
|
|
|
|
|
|
type = (ext[0] & 0xff) << 24 |
|
|
|
|
(ext[1] & 0xff) << 16 |
|
|
|
|
(ext[2] & 0xff) << 8 |
|
|
|
|
(ext[3] & 0xff);
|
|
|
|
|
|
|
|
SetCatalogInfo(type);
|
2014-10-06 08:10:50 +00:00
|
|
|
#endif
|
2010-01-23 19:44:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-15 21:51:02 +00:00
|
|
|
#if defined(__WXMAC__)
|
2013-08-26 18:08:30 +00:00
|
|
|
void FileIO::SetCatalogInfo(wxUint32 type)
|
2014-12-15 21:51:02 +00:00
|
|
|
#else
|
|
|
|
void FileIO::SetCatalogInfo(wxUint32 WXUNUSED(type))
|
|
|
|
#endif
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
#ifdef __WXMAC__
|
2014-10-06 08:10:50 +00:00
|
|
|
#if !wxCHECK_VERSION(3, 0, 0)
|
2013-12-12 00:46:03 +00:00
|
|
|
if (!mOpen ) {
|
2010-01-23 19:44:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFileName fn(mName);
|
|
|
|
|
|
|
|
fn.MacSetTypeAndCreator(type, AUDACITY_CREATOR);
|
2014-10-06 08:10:50 +00:00
|
|
|
#endif
|
2010-01-23 19:44:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxInputStream & FileIO::Read(void *buf, size_t size)
|
|
|
|
{
|
|
|
|
if (mInputStream == NULL) {
|
|
|
|
return *mInputStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mInputStream->Read(buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxOutputStream & FileIO::Write(const void *buf, size_t size)
|
|
|
|
{
|
|
|
|
if (mOutputStream == NULL) {
|
|
|
|
return *mOutputStream;
|
|
|
|
}
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
return mOutputStream->Write(buf, size);
|
|
|
|
}
|