Audacity 3.2.0
Public Member Functions | List of all members
LOFImportPlugin Class Referencefinal

An ImportPlugin for LOF data. More...

Inheritance diagram for LOFImportPlugin:
[legend]
Collaboration diagram for LOFImportPlugin:
[legend]

Public Member Functions

 LOFImportPlugin ()
 
 ~LOFImportPlugin ()
 
wxString GetPluginStringID () override
 
TranslatableString GetPluginFormatDescription () override
 
std::unique_ptr< ImportFileHandleOpen (const FilePath &Filename, AudacityProject *pProject) override
 
- Public Member Functions inherited from ImportPlugin
virtual wxString GetPluginStringID ()=0
 
virtual TranslatableString GetPluginFormatDescription ()=0
 
virtual FileExtensions GetSupportedExtensions ()
 
bool SupportsExtension (const FileExtension &extension)
 
virtual std::unique_ptr< ImportFileHandleOpen (const FilePath &Filename, AudacityProject *)=0
 
virtual ~ImportPlugin ()
 

Additional Inherited Members

- Protected Member Functions inherited from ImportPlugin
 ImportPlugin (FileExtensions supportedExtensions)
 
- Protected Attributes inherited from ImportPlugin
const FileExtensions mExtensions
 

Detailed Description

An ImportPlugin for LOF data.

Definition at line 101 of file ImportLOF.cpp.

Constructor & Destructor Documentation

◆ LOFImportPlugin()

LOFImportPlugin::LOFImportPlugin ( )
inline

Definition at line 104 of file ImportLOF.cpp.

105 : ImportPlugin( FileExtensions( exts.begin(), exts.end() ) )
106 {
107 }
wxArrayStringEx FileExtensions
Definition: Identifier.h:225
static const auto exts
Definition: ImportLOF.cpp:97
ImportPlugin(FileExtensions supportedExtensions)

◆ ~LOFImportPlugin()

LOFImportPlugin::~LOFImportPlugin ( )
inline

Definition at line 109 of file ImportLOF.cpp.

109{ }

Member Function Documentation

◆ GetPluginFormatDescription()

TranslatableString LOFImportPlugin::GetPluginFormatDescription ( )
overridevirtual

Implements ImportPlugin.

Definition at line 172 of file ImportLOF.cpp.

173{
174 return DESC;
175}
#define DESC
Definition: ImportLOF.cpp:95

References DESC.

◆ GetPluginStringID()

wxString LOFImportPlugin::GetPluginStringID ( )
inlineoverridevirtual

Implements ImportPlugin.

Definition at line 111 of file ImportLOF.cpp.

111{ return wxT("lof"); }
wxT("CloseDown"))

References wxT().

Here is the call graph for this function:

◆ Open()

std::unique_ptr< ImportFileHandle > LOFImportPlugin::Open ( const FilePath Filename,
AudacityProject pProject 
)
overridevirtual

Implements ImportPlugin.

Definition at line 177 of file ImportLOF.cpp.

179{
180 // Check if it is a text file.
181 {
182 wxFile binaryFile;
183 if (!binaryFile.Open(filename))
184 return nullptr; // File not found
185
187 int count = binaryFile.Read(buf, BINARY_FILE_CHECK_BUFFER_SIZE);
188
189 bool isTextFile = false;
190 const std::string lofToken("file");
191
192 // At least we should get a size more than: <token> + <space> + <filename>.
193 if (count > (lofToken.length() + sizeof(' ') + 1))
194 {
195 // Audacity can import list from LOF only with BOM or ASCII,
196 // each other text (like unicode without BOM, bin, etc) can't be recognized.
197
198 // UTF-16 BOM checker.
199 auto IsUtf16_BE = [](const char* str) -> bool
200 {
201 return str[0] == static_cast<char>(0xFE) && str[1] == static_cast<char>(0xFF);
202 };
203 auto IsUtf16_LE = [](const char* str) -> bool
204 {
205 return str[0] == static_cast<char>(0xFF) && str[1] == static_cast<char>(0xFE);
206 };
207
208 // UTF-32 BOM checker.
209 auto IsUtf32_BE = [](const char* str) -> bool
210 {
211 return str[0] == static_cast<char>(0x00) &&
212 str[1] == static_cast<char>(0x00) &&
213 str[2] == static_cast<char>(0xFE) &&
214 str[3] == static_cast<char>(0xFF);
215 };
216 auto IsUtf32_LE = [](const char* str) -> bool
217 {
218 return str[0] == static_cast<char>(0xFF) &&
219 str[1] == static_cast<char>(0xFE) &&
220 str[2] == static_cast<char>(0x00) &&
221 str[3] == static_cast<char>(0x00);
222 };
223
224 // Is unicode text file.
225 if (IsUtf16_BE(buf) || IsUtf16_LE(buf) || IsUtf32_BE(buf) || IsUtf32_LE(buf))
226 {
227 isTextFile = true;
228 }
229 // Try parse as ASCII and UTF-8 text as ASCII too.
230 else
231 {
232 buf[sizeof(buf) - 1] = '\0';
233
234 std::string importedText(buf);
235
236 if (importedText.find(lofToken) != std::string::npos)
237 isTextFile = true;
238 }
239 }
240
241 if (!isTextFile)
242 {
243 binaryFile.Close();
244 return nullptr;
245 }
246 }
247
248 // Now open the file again as text file
249 auto file = std::make_unique<wxTextFile>(filename);
250 file->Open();
251
252 if (!file->IsOpened())
253 return nullptr;
254
255 return std::make_unique<LOFImportFileHandle>(
256 pProject, filename, std::move(file));
257}
#define str(a)
#define BINARY_FILE_CHECK_BUFFER_SIZE
Definition: ImportLOF.cpp:93

References BINARY_FILE_CHECK_BUFFER_SIZE, and str.


The documentation for this class was generated from the following file: