From 804a55ba641d7be7f6d42763f65fb4a8601d6232 Mon Sep 17 00:00:00 2001 From: Nikolaj Schlej Date: Tue, 5 Jul 2016 16:18:55 +0200 Subject: [PATCH] UString integration done - now UString works for both Qt (uses QString) and non-Qt (uses modified CBString) builds --- UEFIExtract/ffsdumper.cpp | 2 +- UEFIExtract/uefiextract_main.cpp | 16 ++++++++-------- bstrlib/bstrwrap.cpp | 2 +- bstrlib/bstrwrap.h | 5 ++++- common/ffsparser.cpp | 4 ++-- common/treemodel.cpp | 4 ++-- common/ustring.cpp | 2 +- common/ustring.h | 4 +--- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/UEFIExtract/ffsdumper.cpp b/UEFIExtract/ffsdumper.cpp index ceaf719..7f60612 100644 --- a/UEFIExtract/ffsdumper.cpp +++ b/UEFIExtract/ffsdumper.cpp @@ -79,7 +79,7 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path if (!file.open(QFile::Text | QFile::WriteOnly)) return U_FILE_OPEN; - file.write(info); + file.write(info.toLocal8Bit()); file.close(); dumped = true; } diff --git a/UEFIExtract/uefiextract_main.cpp b/UEFIExtract/uefiextract_main.cpp index 3fa8d08..d80a3af 100644 --- a/UEFIExtract/uefiextract_main.cpp +++ b/UEFIExtract/uefiextract_main.cpp @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) // Show ffsParser's messages std::vector > messages = ffsParser.getMessages(); for (size_t i = 0; i < messages.size(); i++) { - std::cout << messages[i].first << std::endl; + std::cout << (const char*)messages[i].first.toLocal8Bit() << std::endl; } // Get last VTF @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) // Show fitParser's messages std::vector > fitMessages = fitParser.getMessages(); for (size_t i = 0; i < fitMessages.size(); i++) { - std::cout << fitMessages[i].first << std::endl; + std::cout << (const char*)fitMessages[i].first.toLocal8Bit() << std::endl; } // Show FIT table @@ -86,11 +86,11 @@ int main(int argc, char *argv[]) std::cout << " Address | Size | Ver | Type | CS " << std::endl; std::cout << "-------------------------------------------------------------------" << std::endl; for (size_t i = 0; i < fitTable.size(); i++) { - std::cout << fitTable[i][0] << " | " - << fitTable[i][1] << " | " - << fitTable[i][2] << " | " - << fitTable[i][3] << " | " - << fitTable[i][4] << std::endl; + std::cout << (const char*)fitTable[i][0].toLocal8Bit() << " | " + << (const char*)fitTable[i][1].toLocal8Bit() << " | " + << (const char*)fitTable[i][2].toLocal8Bit() << " | " + << (const char*)fitTable[i][3].toLocal8Bit() << " | " + << (const char*)fitTable[i][4].toLocal8Bit() << std::endl; } } } @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) std::ofstream ofs; ofs.open("report.txt", std::ofstream::out); for (size_t i = 0; i < report.size(); i++) { - ofs << report[i] << std::endl; + ofs << (const char*)report[i].toLocal8Bit() << std::endl; } ofs.close(); } diff --git a/bstrlib/bstrwrap.cpp b/bstrlib/bstrwrap.cpp index ce77f17..2ec38c1 100644 --- a/bstrlib/bstrwrap.cpp +++ b/bstrlib/bstrwrap.cpp @@ -903,7 +903,7 @@ struct tagbstring t; return bninchrr ((bstring) this, pos, &t); } -const CBString CBString::midstr (int left, int len) const { +CBString CBString::midstr (int left, int len) const { struct tagbstring t; if (left < 0) { len += left; diff --git a/bstrlib/bstrwrap.h b/bstrlib/bstrwrap.h index dcb0ecc..4a785a9 100644 --- a/bstrlib/bstrwrap.h +++ b/bstrlib/bstrwrap.h @@ -317,7 +317,7 @@ struct CBString : public tagbstring { void findreplacecaseless (const char * find, const char * repl, int pos = 0); // Extraction method. - const CBString midstr (int left, int len) const; + CBString midstr (int left, int len) const; // Standard manipulation methods. void setsubstr (int pos, const CBString& b, unsigned char fill = ' '); @@ -362,8 +362,11 @@ struct CBString : public tagbstring { int read (bNread readPtr, void * parm); // QString compatibility methods + CBString toLocal8Bit() { return *this; } bool isEmpty() const { return slen == 0; } void clear() { *this = ""; } + CBString left(int len) { return midstr(0, len); } + CBString mid(int pos, int len) { return midstr(pos, len); } static CBString fromUtf16(const ushort* str) { // Naive implementation assuming that only ASCII part of UCS2 is used CBString msg; while (*str) { msg += *(char*)str; str++; } return msg; } diff --git a/common/ffsparser.cpp b/common/ffsparser.cpp index 0c2cf52..b91a09c 100644 --- a/common/ffsparser.cpp +++ b/common/ffsparser.cpp @@ -4137,8 +4137,8 @@ USTATUS FfsParser::parseSlicMarkerHeader(const UByteArray & store, const UINT32 markerHeader->Size, markerHeader->Size, header.size(), header.size(), markerHeader->Version, - (const char*)UString((const char*)&(markerHeader->OemId), 6), - (const char*)UString((const char*)&(markerHeader->OemTableId), 8), + (const char*)UString((const char*)&(markerHeader->OemId)).left(6).toLocal8Bit(), + (const char*)UString((const char*)&(markerHeader->OemTableId)).left(8).toLocal8Bit(), markerHeader->SlicVersion); // Add correct offset diff --git a/common/treemodel.cpp b/common/treemodel.cpp index df0e03f..00f695e 100644 --- a/common/treemodel.cpp +++ b/common/treemodel.cpp @@ -44,9 +44,9 @@ QVariant TreeModel::data(const UModelIndex &index, int role) const TreeItem *item = static_cast(index.internalPointer()); if (role == Qt::DisplayRole) - return (const char*)item->data(index.column()); + return (const char*)item->data(index.column()).toLocal8Bit(); else - return (const char*)item->info(); + return (const char*)item->info().toLocal8Bit(); } Qt::ItemFlags TreeModel::flags(const UModelIndex &index) const diff --git a/common/ustring.cpp b/common/ustring.cpp index 94b75fe..8c85c76 100644 --- a/common/ustring.cpp +++ b/common/ustring.cpp @@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. //TODO: modify properly -#ifndef QT_CORE_LIB +#if defined(QT_CORE_LIB) && defined (U_USE_QSTRING) UString usprintf(const char* fmt, ...) { UString msg; diff --git a/common/ustring.h b/common/ustring.h index 345917a..de15135 100644 --- a/common/ustring.h +++ b/common/ustring.h @@ -13,9 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #ifndef USTRING_H #define USTRING_H -//TODO: modify properly - -#ifndef QT_CORE_LIB +#if defined (QT_CORE_LIB) && defined(U_USE_QSTRING) // Use Qt class, if Qt is available #include #define UString QString