Ticket #9134: compress_sword1_layout_improvements.patch
File compress_sword1_layout_improvements.patch, 10.2 KB (added by , 15 years ago) |
---|
-
engines/sword1/compress_sword1.h
50 50 void guessEndianness(int16 *data, int16 length); 51 51 52 52 private: 53 bool _useOutputMusicSubdir; 54 53 55 bool _macVersion; 54 56 55 57 enum Endianness { BigEndian , LittleEndian , UnknownEndian } ; 56 58 Endianness _speechEndianness; 57 59 }; -
engines/sword1/compress_sword1.cpp
463 463 void CompressSword1::compressSpeech(const Common::Filename *inpath, const Common::Filename *outpath) { 464 464 Common::File clu, cl3; 465 465 int i; 466 char cluName[256], outName[256] ;466 char cluName[256], outName[256], outFileName[12]; 467 467 468 468 if (_speechEndianness != UnknownEndian) 469 469 setRawAudioType(_speechEndianness == LittleEndian, false, 16); … … 476 476 try { 477 477 clu.open(cluName, "rb"); 478 478 } catch (Common::FileException &) { 479 print("Unable to open \"SPEECH%d.CLU\".\n", i); 480 print("Please copy the \"SPEECH.CLU\" from CD %d\nand rename it to \"SPEECH%d.CLU\".\n", i, i); 481 continue; 479 // Not found in SPEECH sub-directory. 480 // Looking for the file at the root of the input directory. 481 sprintf(cluName, "%s/SPEECH%d.CLU", inpath->getPath().c_str(), i); 482 try { 483 clu.open(cluName, "rb"); 484 } catch (Common::FileException &) { 485 print("Unable to open \"SPEECH%d.CLU\".\n", i); 486 print("Please copy the \"SPEECH.CLU\" from CD %d\nand rename it to \"SPEECH%d.CLU\".\n", i, i); 487 continue; 488 } 482 489 } 483 490 484 491 switch (_format) { 485 case AUDIO_MP3:486 sprintf(outName, "%s/SPEECH/SPEECH%d.%s", outpath->getPath().c_str(), i, "CL3");487 break;488 case AUDIO_VORBIS:489 sprintf(outName, "%s/SPEECH/SPEECH%d.%s", outpath->getPath().c_str(), i, "CLV");490 break;491 case AUDIO_FLAC:492 sprintf(outName, "%s/SPEECH/SPEECH%d.%s", outpath->getPath().c_str(), i, "CLF");493 break;494 default:495 error("Unknown encoding method");492 case AUDIO_MP3: 493 sprintf(outFileName, "SPEECH%d.%s", i, "CL3"); 494 break; 495 case AUDIO_VORBIS: 496 sprintf(outFileName, "SPEECH%d.%s", i, "CLV"); 497 break; 498 case AUDIO_FLAC: 499 sprintf(outFileName, "SPEECH%d.%s", i, "CLF"); 500 break; 501 default: 502 error("Unknown encoding method"); 496 503 } 497 498 cl3.open(outName, "wb"); 499 if (!cl3.isOpen()) { 504 505 // Try opening in SPEECH sub-directory 506 sprintf(outName, "%s/SPEECH/%s", outpath->getPath().c_str(), outFileName); 507 try { 508 cl3.open(outName, "wb"); 509 } catch (Common::FileException &) { 510 // Try opening at root of output directory 500 511 print("Unable to create file \"%s\".\n", outName); 501 print("Please make sure you've got write permission in this directory.\n"); 502 } else { 503 print("Converting CD %d...\n", i); 504 convertClu(clu, cl3); 512 sprintf(outName, "%s/%s", outpath->getPath().c_str(), outFileName); 513 print("Trying \"%s\".\n", outName); 514 try { 515 cl3.open(outName, "wb"); 516 } catch (Common::FileException &) { 517 print("Unable to create file \"%s\".\n", outName); 518 print("Please make sure you've got write permission in this directory or its \"MUSIC\" sub-directory.\n"); 519 continue; 520 } 505 521 } 522 print("Converting CD %d...\n", i); 523 convertClu(clu, cl3); 506 524 } 507 525 unlink(TEMP_RAW); 508 526 unlink(_audioOuputFilename.c_str()); … … 510 528 511 529 void CompressSword1::compressMusic(const Common::Filename *inpath, const Common::Filename *outpath) { 512 530 int i; 513 char fNameIn[256], fNameOut[256]; 531 char inName[256], outName[256], inFileName[12], outFileName[12]; 532 533 // check if output music directory exist and if we can create files in it 534 sprintf(outName, "%s/MUSIC/compress_sword1_test_file", outpath->getPath().c_str()); 535 try { 536 Common::File outf(outName, "wb"); 537 outf.close(); 538 unlink(outName); 539 } catch(Common::FileException& err) { 540 _useOutputMusicSubdir = false; 541 print("Cannot create files in %s/MUSIC/; will try in %s/\n", outpath->getPath().c_str(), outpath->getPath().c_str()); 542 } 514 543 515 544 for (i = 0; i < TOTAL_TUNES; i++) { 516 545 // Update the progress bar, we add 2 if we compress speech to, for those files 517 546 updateProgress(i, TOTAL_TUNES +(_compSpeech? 2 : 0)); 518 547 548 // Get name of input file 519 549 if (!_macVersion) 520 sprintf( fNameIn, "%s/MUSIC/%s.WAV", inpath->getPath().c_str(), musicNames[i].fileName);550 sprintf(inFileName, "%s.WAV", musicNames[i].fileName); 521 551 else 522 sprintf(fNameIn, "%s/MUSIC/%s.AIF", inpath->getPath().c_str(), musicNames[i].fileName); 552 sprintf(inFileName, "%s.AIF", musicNames[i].fileName); 553 554 Common::File inf; 555 556 // Trying to find input file in MUSIC sub-directory first 557 sprintf(inName, "%s/MUSIC/%s", inpath->getPath().c_str(), inFileName); 523 558 try { 524 Common::File inf(fNameIn, "rb"); 525 526 switch (_format) { 527 case AUDIO_MP3: 528 sprintf(fNameOut, "%s/MUSIC/%s.%s", outpath->getPath().c_str(), musicNames[i].fileName, "MP3"); 529 break; 530 case AUDIO_VORBIS: 531 sprintf(fNameOut, "%s/MUSIC/%s.%s", outpath->getPath().c_str(), musicNames[i].fileName, "OGG"); 532 break; 533 case AUDIO_FLAC: 534 sprintf(fNameOut, "%s/MUSIC/%s.%s", outpath->getPath().c_str(), musicNames[i].fileName, "FLA"); 535 break; 536 default: 537 error("Unknown encoding method"); 559 inf.open(inName, "rb"); 560 } catch (Common::FileException& err) { 561 // Try at root of input directory 562 print(err.what()); 563 sprintf(inName, "%s/%s", inpath->getPath().c_str(), inFileName); 564 print(", trying %s\n", inName); 565 try { 566 inf.open(inName, "rb"); 567 } catch (Common::FileException& err2) { 568 print("%s\n", err2.what()); 569 continue; 538 570 } 571 } 539 572 540 print("encoding file (%3d/%d) %s -> %s\n", i + 1, TOTAL_TUNES, musicNames[i].fileName, fNameOut); 573 // Get name of output file 574 switch (_format) { 575 case AUDIO_MP3: 576 sprintf(outFileName, "%s.%s", musicNames[i].fileName, "MP3"); 577 break; 578 case AUDIO_VORBIS: 579 sprintf(outFileName, "%s.%s", musicNames[i].fileName, "OGG"); 580 break; 581 case AUDIO_FLAC: 582 sprintf(outFileName, "%s.%s", musicNames[i].fileName, "FLA"); 583 break; 584 default: 585 error("Unknown encoding method"); 586 } 587 588 if (_useOutputMusicSubdir) 589 sprintf(outName, "%s/MUSIC/%s", outpath->getPath().c_str(), outFileName); 590 else 591 sprintf(outName, "%s/%s", outpath->getPath().c_str(), outFileName); 592 593 print("encoding file (%3d/%d) %s -> %s\n", i + 1, TOTAL_TUNES, musicNames[i].fileName, outName); 594 595 try { 541 596 if (!_macVersion) 542 encodeAudio( fNameIn, false, -1, fNameOut, _format);597 encodeAudio(inName, false, -1, outName, _format); 543 598 else 544 extractAndEncodeAIFF( fNameIn, fNameOut, _format);599 extractAndEncodeAIFF(inName, outName, _format); 545 600 } catch (Common::FileException& err) { 546 print( err.what());601 print("%s\n", err.what()); 547 602 } 548 603 } 549 604 } … … 556 611 557 612 if (checkSpeech) { 558 613 for (i = 1; i <= 2; i++) { 614 // Try first in SPEECH sub-directory 559 615 sprintf(fileName, "%s/SPEECH/SPEECH%d.CLU", inpath->getPath().c_str(), i); 560 616 testFile = fopen(fileName, "rb"); 561 617 562 618 if (testFile){ 563 619 speechFound = true; 564 620 fclose(testFile); 621 break; 565 622 } 623 624 // Then try at the root of the input directory 625 sprintf(fileName, "%s/SPEECH%d.CLU", inpath->getPath().c_str(), i); 626 testFile = fopen(fileName, "rb"); 627 628 if (testFile){ 629 speechFound = true; 630 fclose(testFile); 631 break; 632 } 566 633 } 567 634 568 635 if (!speechFound) { 569 636 print("Unable to find speech files.\n"); 570 637 print("Please copy the SPEECH.CLU files from Broken Sword CD1 and CD2\n"); 571 print("into the \"SPEECH\" subdirectory and rename them to\n");572 print(" SPEECH1.CLU and SPEECH2.CLU\n\n");638 print("into the game directory on your disk or into a \"SPEECH\" subdirectory\n"); 639 print("and rename them to SPEECH1.CLU and SPEECH2.CLU\n\n"); 573 640 print("If your OS is case-sensitive, make sure the filenames\n"); 574 641 print("and directorynames are all upper-case.\n\n"); 575 642 } … … 584 651 if (checkMusic) { 585 652 for (i = 0; i < 20; i++) { /* Check the first 20 music files */ 586 653 // Check WAV file 654 // Try first in MUSIC sub-directory 587 655 sprintf(fileName, "%s/MUSIC/%s.WAV", inpath->getPath().c_str(), musicNames[i].fileName); 588 656 testFile = fopen(fileName, "rb"); 589 657 … … 592 660 fclose(testFile); 593 661 break; 594 662 } 663 664 // Then try at root of input directory 665 sprintf(fileName, "%s/%s.WAV", inpath->getPath().c_str(), musicNames[i].fileName); 666 testFile = fopen(fileName, "rb"); 595 667 668 if (testFile) { 669 musicFound = true; 670 fclose(testFile); 671 break; 672 } 673 596 674 // Check AIF file 675 // Try first in MUSIC sub-directory 597 676 sprintf(fileName, "%s/MUSIC/%s.AIF", inpath->getPath().c_str(), musicNames[i].fileName); 598 677 testFile = fopen(fileName, "rb"); 678 679 if (testFile) { 680 musicFound = true; 681 _macVersion = true; 682 _speechEndianness = UnknownEndian; 683 fclose(testFile); 684 break; 685 } 686 687 // Then try at root of input directory 688 sprintf(fileName, "%s/%s.AIF", inpath->getPath().c_str(), musicNames[i].fileName); 689 testFile = fopen(fileName, "rb"); 599 690 600 691 if (testFile) { 601 692 musicFound = true; … … 604 695 fclose(testFile); 605 696 break; 606 697 } 698 607 699 } 608 700 609 701 if (!musicFound) { 610 702 print("Unable to find music files.\n"); 611 703 print("Please copy the music files from Broken Sword CD1 and CD2\n"); 612 print("into the \"MUSIC\" subdirectory.\n");704 print("into the game directory on your disk or into a \"MUSIC\" subdirectory.\n"); 613 705 print("If your OS is case-sensitive, make sure the filenames\n"); 614 706 print("and directorynames are all upper-case.\n"); 615 707 } … … 628 720 // This is the reason why this function is reimplemented there. 629 721 if ( 630 722 scumm_stricmp(filename.getExtension().c_str(), "clu") == 0 || 631 scumm_stricmp(filename.getExtension().c_str(), "clm") == 0 723 scumm_stricmp(filename.getExtension().c_str(), "clm") == 0 || 724 scumm_stricmp(filename.getFullName().c_str(), "swordres.rif") == 0 632 725 ) 633 726 return IMATCH_PERFECT; 634 727 return IMATCH_AWFUL; … … 637 730 CompressSword1::CompressSword1(const std::string &name) : CompressionTool(name, TOOLTYPE_COMPRESSION) { 638 731 _compSpeech = true; 639 732 _compMusic = true; 733 _useOutputMusicSubdir = true; 640 734 _macVersion = false; 641 735 _speechEndianness = LittleEndian; 642 736