181{
182
183 {
184 wxFile binaryFile;
185 if (!binaryFile.Open(filename))
186 return nullptr;
187
190
191 bool isTextFile = false;
192 const std::string lofToken("file");
193
194
195 if (count > (lofToken.length() + sizeof(' ') + 1))
196 {
197
198
199
200
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
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
227 if (IsUtf16_BE(buf) || IsUtf16_LE(buf) || IsUtf32_BE(buf) || IsUtf32_LE(buf))
228 {
229 isTextFile = true;
230 }
231
232 else
233 {
234 buf[sizeof(buf) - 1] = '\0';
235
236 std::string importedText(buf);
237
239 isTextFile = true;
240 }
241 }
242
243 if (!isTextFile)
244 {
245 binaryFile.Close();
246 return nullptr;
247 }
248 }
249
250
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 BINARY_FILE_CHECK_BUFFER_SIZE
constexpr size_t npos(-1)