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 ()
 
virtual TranslatableString FailureHint () const
 User visible message suggesting what to do when a file type isn't recognized; default empty string. More...
 
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 100 of file ImportLOF.cpp.

Constructor & Destructor Documentation

◆ LOFImportPlugin()

LOFImportPlugin::LOFImportPlugin ( )
inline

Definition at line 103 of file ImportLOF.cpp.

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

◆ ~LOFImportPlugin()

LOFImportPlugin::~LOFImportPlugin ( )
inline

Definition at line 108 of file ImportLOF.cpp.

108{ }

Member Function Documentation

◆ GetPluginFormatDescription()

TranslatableString LOFImportPlugin::GetPluginFormatDescription ( )
overridevirtual

Implements ImportPlugin.

Definition at line 178 of file ImportLOF.cpp.

179{
180 return DESC;
181}
#define DESC
Definition: ImportLOF.cpp:94

References DESC.

◆ GetPluginStringID()

wxString LOFImportPlugin::GetPluginStringID ( )
inlineoverridevirtual

Implements ImportPlugin.

Definition at line 110 of file ImportLOF.cpp.

110{ 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 183 of file ImportLOF.cpp.

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

References BINARY_FILE_CHECK_BUFFER_SIZE, Tuple::detail::npos(), and str.

Here is the call graph for this function:

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