rbutil: Use lang-enum.txt in voicestrings.zip if present

With this change, the code that looks for the VOICE_INVALID_VOICE_FILE
and VOICE_LANG_NAME to produce standalone clips will finally work.

Change-Id: I65ec592a1d3a6c83f92efadec72657c42552b41a
This commit is contained in:
Solomon Peachy 2026-01-12 20:22:43 -05:00
parent 55f2e2d5d5
commit d9289e7f5c

View file

@ -64,6 +64,7 @@ bool VoiceFileCreator::createVoiceFile()
m_voiceformat = info.voicefmt();
QString version = m_versionstring.left(m_versionstring.indexOf("-")).remove("r");
QMap<int, QString> enumstrings;
// check if voicefile is present on target
QString fn = m_mountpoint + "/.rockbox/langs/voicestrings.zip";
LOG_INFO() << "searching for zipped voicestrings at" << fn;
@ -72,14 +73,17 @@ bool VoiceFileCreator::createVoiceFile()
ZipUtil z(this);
if(z.open(fn)) {
QStringList contents = z.files();
int vindex = -1, cindex = -1;
int vindex = -1, cindex = -1, eindex = -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)
vindex = index;
if(QFileInfo(contents.at(index)).baseName() == "voice-corrections")
cindex = index;
if (vindex != -1 && cindex != -1)
if(QFileInfo(contents.at(index)).baseName() == "lang-enum")
eindex = index;
if (vindex != -1 && cindex != -1 && eindex != -1)
break;
}
if(cindex != -1) {
@ -98,6 +102,25 @@ bool VoiceFileCreator::createVoiceFile()
corrFile = &corrfile;
}
}
if(eindex != -1) {
LOG_INFO() << "extracting voice corrections file";
QTemporaryFile enumfileT;
enumfileT.open();
QTextStream in(&enumfileT);
QString cfn = enumfileT.fileName();
if(z.extractArchive(cfn, QFileInfo(contents.at(eindex)).fileName())) {
emit logItem(tr("Extracted language enumeration file from installation"), LOGINFO);
while(!in.atEnd()) {
QString line = in.readLine();
QStringList row = line.split(":");
int id = row[0].toInt(NULL, 0);
QString name = row[1];
enumstrings[id] = name;
}
enumfileT.close();
}
}
if(vindex != -1) {
LOG_INFO() << "extracting strings file from zip";
// extract strings
@ -142,9 +165,13 @@ bool VoiceFileCreator::createVoiceFile()
m_filename = voicefontlist.fileName();
for(auto key : voicestrings.keys()) {
QByteArray qba;
qba = QString("id: %1_%2\n")
.arg(key < 0x8000 ? "LANG" : "VOICE")
.arg(key).toUtf8();
if (enumstrings.contains(key)) {
qba = QString("id: %1\n").arg(enumstrings[key]).toUtf8();
} else {
qba = QString("id: %1_%2\n")
.arg(key < 0x8000 ? "LANG" : "VOICE")
.arg(key).toUtf8();
}
voicefontlist.write(qba);
qba = QString("voice: \"%1\"\n").arg(
voicestrings[key]).toUtf8();