185{
186
187 {
188 wxFile binaryFile;
189 if (!binaryFile.Open(filename))
190 return nullptr;
191
194
195 bool isTextFile = false;
196 const std::string lofToken("file");
197
198
199 if (count > (lofToken.length() + sizeof(' ') + 1))
200 {
201
202
203
204
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
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
231 if (IsUtf16_BE(buf) || IsUtf16_LE(buf) || IsUtf32_BE(buf) || IsUtf32_LE(buf))
232 {
233 isTextFile = true;
234 }
235
236 else
237 {
238 buf[sizeof(buf) - 1] = '\0';
239
240 std::string importedText(buf);
241
243 isTextFile = true;
244 }
245 }
246
247 if (!isTextFile)
248 {
249 binaryFile.Close();
250 return nullptr;
251 }
252 }
253
254
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 BINARY_FILE_CHECK_BUFFER_SIZE
constexpr size_t npos(-1)