rbutil: Pull voice-corrections.txt out of voicestrings.zip

If the corrections file is not present on the target, then
fall back to the (probably outdated) compile-time builtin version.

Change-Id: I9904b81b2f3737149fc8a905ecd03ff54782bbdf
This commit is contained in:
Solomon Peachy 2025-05-08 17:12:12 -04:00
parent bb20b5c6bf
commit 077f44ca41
6 changed files with 40 additions and 17 deletions

View file

@ -72,21 +72,40 @@ bool VoiceFileCreator::createVoiceFile()
ZipUtil z(this);
if(z.open(fn)) {
QStringList contents = z.files();
int index;
for(index = 0; index < contents.size(); ++index) {
int vindex = -1, cindex = -1;
for(int index = 0; index < contents.size(); ++index) {
// strip any path, we don't know the structure in the zip
if(QFileInfo(contents.at(index)).baseName() == m_lang) {
if(QFileInfo(contents.at(index)).baseName() == m_lang)
vindex = index;
if(QFileInfo(contents.at(index)).baseName() == "voice-corrections")
cindex = index;
if (vindex != -1 && cindex != -1)
break;
}
if(cindex != -1) {
LOG_INFO() << "extracting voice corrections file";
QTemporaryFile corrfileT;
corrfileT.open();
QString cfn = corrfileT.fileName();
if(z.extractArchive(cfn, QFileInfo(contents.at(cindex)).fileName())) {
emit logItem(tr("Extracted voice corrections file from installation"), LOGINFO);
corrFile = &corrfileT;
} else {
corrfileT.close();
emit logItem(tr("Using internal voice corrections file"), LOGINFO);
QFile corrfile(":/builtin/voice-corrections.txt");
corrfile.open(QIODevice::ReadOnly);
corrFile = &corrfile;
}
}
if(index < contents.size()) {
if(vindex != -1) {
LOG_INFO() << "extracting strings file from zip";
// extract strings
QTemporaryFile stringsfile;
stringsfile.open();
QString sfn = stringsfile.fileName();
// ZipUtil::extractArchive() only compares the filename.
if(z.extractArchive(sfn, QFileInfo(contents.at(index)).fileName())) {
if(z.extractArchive(sfn, QFileInfo(contents.at(vindex)).fileName())) {
emit logItem(tr("Extracted voice strings from installation"), LOGINFO);
stringsfile.seek(0);
@ -135,6 +154,8 @@ bool VoiceFileCreator::createVoiceFile()
// everything successful, now create the actual voice file.
create();
if (corrFile->isOpen())
corrFile->close();
return true;
}
@ -282,7 +303,7 @@ void VoiceFileCreator::create(void)
TalkGenerator generator(this);
// set language for string correction. If not set no correction will be made.
if(useCorrection)
generator.setLang(m_lang);
generator.setLang(m_lang, corrFile);
connect(&generator, &TalkGenerator::done, this, &VoiceFileCreator::done);
connect(&generator, &TalkGenerator::logItem, this, &VoiceFileCreator::logItem);
connect(&generator, &TalkGenerator::logProgress, this, &VoiceFileCreator::logProgress);