Enable asyncio.library.
[AROS-Contrib.git] / FryingPan / DTLib / FileWriter.cpp
blob963f050121a028b77d0dac7fb184d1191a48ab27
1 /*
2 * FryingPan - Amiga CD/DVD Recording Software (User Interface and supporting Libraries only)
3 * Copyright (C) 2001-2011 Tomasz Wiszkowski Tomasz.Wiszkowski at gmail.com
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "FileWriter.h"
21 #include <libclass/dos.h>
22 #include <Optical/Optical.h>
23 #include <LibC/LibC.h>
24 #include <libclass/utility.h>
26 FileWriter::FileWriter(const char* sFName, EDtError &rc)
28 sFileName = sFName;
29 fh = 0;
30 isLE = true;
31 sectorSize = 2352;
33 fh = DOS->Open(const_cast<char*>(getFileName()), MODE_NEWFILE);
34 if (fh == 0)
35 rc = DT_UnableToOpenFile;
36 else
37 rc = DT_OK;
40 FileWriter::~FileWriter()
44 BPTR FileWriter::getFile()
46 return fh;
49 const char* FileWriter::getFileName()
51 return sFileName.Data();
54 bool FileWriter::writeData(void* buffer, int len)
56 ASSERT(buffer != 0);
57 ASSERT(fh != 0);
59 if (fh == 0)
60 return false;
62 if (NULL == buffer)
63 return false;
65 if (0 == len)
66 return false;
68 long k;
69 short *b = (short*)buffer;
71 if (false == isLE)
73 k = len * sectorSize;
74 while (k)
76 *b = ((*b&0xff00)>>8)|((*b&0xff)<<8);
77 b++;
78 k-=2;
82 k = DOS->Write(fh, buffer, len*sectorSize)/sectorSize;
84 if (k != len)
85 return false;
87 return true;
90 void FileWriter::setLittleEndian(bool isLittle)
92 isLE = isLittle;
95 bool FileWriter::setUp()
97 ASSERT(fh != 0);
98 if (fh == 0)
99 return false;
100 return true;
103 void FileWriter::cleanUp()
105 if (0 != fh)
106 DOS->Close(fh);
109 const char *FileWriter::getTrackName()
111 return getFileName();
114 void FileWriter::dispose()
116 delete this;
119 unsigned short FileWriter::getBlockSize()
121 return sectorSize;
124 unsigned long FileWriter::getBlockCount()
126 return sectorCount;
129 void FileWriter::setBlockSize(unsigned short size)
131 sectorSize = size;
134 void FileWriter::setBlockCount(unsigned long count)
136 sectorCount = count;
139 void FileWriter::deleteFiles()
141 if (fh != 0)
142 DOS->Close(fh);
143 fh = 0;
145 DOS->DeleteFile((char*)getFileName());
149 // vim: ts=3 et