179{
180
181 {
182 wxFile binaryFile;
183 if (!binaryFile.Open(filename))
184 return nullptr;
185
188
189 bool isTextFile = false;
190 const std::string lofToken("file");
191
192
193 if (count > (lofToken.length() + sizeof(' ') + 1))
194 {
195
196
197
198
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
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
225 if (IsUtf16_BE(buf) || IsUtf16_LE(buf) || IsUtf32_BE(buf) || IsUtf32_LE(buf))
226 {
227 isTextFile = true;
228 }
229
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
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 BINARY_FILE_CHECK_BUFFER_SIZE