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 96 of file ImportLOF.cpp.

Constructor & Destructor Documentation

◆ LOFImportPlugin()

LOFImportPlugin::LOFImportPlugin ( )
inline

Definition at line 99 of file ImportLOF.cpp.

100 : ImportPlugin( FileExtensions( exts.begin(), exts.end() ) )
101 {
102 }
wxArrayStringEx FileExtensions
Definition: Identifier.h:225
static const auto exts
Definition: ImportLOF.cpp:92
ImportPlugin(FileExtensions supportedExtensions)

◆ ~LOFImportPlugin()

LOFImportPlugin::~LOFImportPlugin ( )
inline

Definition at line 104 of file ImportLOF.cpp.

104{ }

Member Function Documentation

◆ GetPluginFormatDescription()

TranslatableString LOFImportPlugin::GetPluginFormatDescription ( )
overridevirtual

Implements ImportPlugin.

Definition at line 174 of file ImportLOF.cpp.

175{
176 return DESC;
177}
#define DESC
Definition: ImportLOF.cpp:90

References DESC.

◆ GetPluginStringID()

wxString LOFImportPlugin::GetPluginStringID ( )
inlineoverridevirtual

Implements ImportPlugin.

Definition at line 106 of file ImportLOF.cpp.

106{ 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 179 of file ImportLOF.cpp.

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