-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFileIO.cpp
129 lines (99 loc) · 2.27 KB
/
FileIO.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**********************************************************************
Audacity: A Digital Audio Editor
FileIO.cpp
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);
if (mInputStream == NULL) {
wxPrintf(wxT("Couldn't get input stream: %s\n"), name.c_str());
return;
}
}
else {
mOutputStream = new wxFFileOutputStream(mName);
if (mOutputStream == NULL) {
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
void FileIO::SetCatalogInfo()
{
#ifdef __WXMAC__
if (!mOpen ) {
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);
#endif
return;
}
void FileIO::SetCatalogInfo(wxUint32 type)
{
#ifdef __WXMAC__
if (!mOpen ) {
return;
}
wxFileName fn(mName);
fn.MacSetTypeAndCreator(type, AUDACITY_CREATOR);
#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;
}
return mOutputStream->Write(buf, size);
}