| 342 | } |
| 343 | |
| 344 | bool FLACImportFileHandle::Init() |
| 345 | { |
| 346 | #ifdef LEGACY_FLAC |
| 347 | bool success = mFile->set_filename(OSINPUT(mFilename)); |
| 348 | if (!success) { |
| 349 | return false; |
| 350 | } |
| 351 | mFile->set_metadata_respond(FLAC__METADATA_TYPE_STREAMINFO); |
| 352 | mFile->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT); |
| 353 | FLAC::Decoder::File::State state = mFile->init(); |
| 354 | if (state != FLAC__FILE_DECODER_OK) { |
| 355 | return false; |
| 356 | } |
| 357 | #else |
| 358 | if (!mHandle.Open(GetFilename(), wxT("rb"))) { |
| 359 | return false; |
| 360 | } |
| 361 | |
| 362 | // Even though there is an init() method that takes a filename, use the one that |
| 363 | // takes a file handle because wxWidgets can open a file with a Unicode name and |
| 364 | // libflac can't (under Windows). |
| 365 | // |
| 366 | // Responsibility for closing the file is passed to libflac. |
| 367 | // (it happens when mFile->finish() is called) |
| 368 | bool result = mFile->init(mHandle.fp())?true:false; |
| 369 | mHandle.Detach(); |
| 370 | |
| 371 | if (result != FLAC__STREAM_DECODER_INIT_STATUS_OK) { |
| 372 | return false; |
| 373 | } |
| 374 | #endif |
| 375 | mFile->process_until_end_of_metadata(); |
| 376 | |
| 377 | #ifdef LEGACY_FLAC |
| 378 | state = mFile->get_state(); |
| 379 | if (state != FLAC__FILE_DECODER_OK) { |
| 380 | return false; |
| 381 | } |
| 382 | #else |
| 383 | // not necessary to check state, error callback will catch errors, but here's how: |
| 384 | if (mFile->get_state() > FLAC__STREAM_DECODER_READ_FRAME) { |
| 385 | return false; |
| 386 | } |
| 387 | #endif |
| 388 | |
| 389 | if (!mFile->is_valid() || mFile->get_was_error()) { |
| 390 | // This probably is not a FLAC file at all |
| 391 | return false; |
| 392 | } |
| 393 | return true; |
| 394 | } |
| 395 | |
| 396 | TranslatableString FLACImportFileHandle::GetFileDescription() |
| 397 | { |