-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[53] Allow selection of Unraid OS Language within the USB creator #62
base: main
Are you sure you want to change the base?
Conversation
@jlre249 is this good to review? |
src/downloadextractthread.cpp
Outdated
if(oldData == dataText) | ||
{ | ||
// if this string wasn't found for replacement, just add it | ||
dataText += "locale=\"" + unraidLangCode + "\""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make sure we put this locale= block under the "[display]" section - you may want to use an XML parser to parse the file and add a new section, I believe that you may want to parse this as XML
#include <QDomDocument>
#include <QString>
#include <QDebug>
void addLocaleToDisplaySection(QString& dataText, const QString& unraidLangCode) {
QDomDocument doc;
QString errorMsg;
int errorLine, errorColumn;
// Load the dataText as an XML document
if (!doc.setContent(dataText, &errorMsg, &errorLine, &errorColumn)) {
qDebug() << "Error parsing XML at line" << errorLine << "column" << errorColumn << ":" << errorMsg;
return;
}
// Find the [display] section
QDomElement root = doc.documentElement(); // Get the root element
QDomNodeList displaySections = root.elementsByTagName("display");
if (!displaySections.isEmpty()) {
QDomElement display = displaySections.at(0).toElement(); // Assuming only one [display] section
if (!display.isNull()) {
// Check if "locale" attribute exists
if (display.hasAttribute("locale")) {
display.setAttribute("locale", unraidLangCode);
} else {
// Add "locale" attribute if not present
display.setAttribute("locale", unraidLangCode);
}
}
} else {
// Add a new [display] section with the locale attribute
QDomElement newDisplay = doc.createElement("display");
newDisplay.setAttribute("locale", unraidLangCode);
root.appendChild(newDisplay);
}
// Convert the modified XML back to a string
QString newXml;
QTextStream stream(&newXml);
doc.save(stream, 4); // Indent with 4 spaces
dataText = newXml;
}
@jlre249 - left a comment about your mechanism of parsing the display config. Let's change this to use a proper XML parser. |
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Closes #53
A few things to be aware of:
For some reason, when using the regular DownloadThread to download the JSON and XML files, it automatically pads the files with extra null characters out to 1 MB. I suspect this has something to do with how the buffer is being written to file. I added a quick & dirty workaround for it, but it's possible we might want to look more into how DownloadThread is conducting its business.
The unraid zip I was pulling didn't actually have anything in the dynamix.cfg, so the behavior right now is to add that 'locale=""' line if it wasn't found for replacement. Hopefully this is the behavior we want.