diff --git a/CoH_BSC_Editor.pro b/CoH_BSC_Editor.pro new file mode 100644 index 0000000..d8a0d05 --- /dev/null +++ b/CoH_BSC_Editor.pro @@ -0,0 +1,67 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2019-08-05T12:25:36 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = BSCWorks +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +CONFIG += c++17 +QMAKE_CXXFLAGS += /std:c++17 + +SOURCES += \ + src/bsc.cpp \ + src/main.cpp \ + src/mainwindow.cpp \ + src/smc.cpp \ + src/smf.cpp \ + src/wav.cpp + +HEADERS += \ + resources.rc \ + src/bsc.h \ + src/mainwindow.h \ + src/smc.h \ + src/smf.h \ + src/version.h \ + src/wav.h + +FORMS += \ + src/mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + resources.qrc + +RC_FILE = resources.rc + +win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lqxtended_static_0_0_1_0_Qt_5_12_3 +else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lqxtended_static_0_0_1_0_Qt_5_12_3d + +INCLUDEPATH += $$PWD/include +DEPENDPATH += $$PWD/include + +win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/libqxtended_static_0_0_1_0_Qt_5_12_3.a +else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/libqxtended_static_0_0_1_0_Qt_5_12_3d.a +else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/qxtended_static_0_0_1_0_Qt_5_12_3.lib +else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/qxtended_static_0_0_1_0_Qt_5_12_3d.lib diff --git a/include/Windows_c++17_compat.h b/include/Windows_c++17_compat.h new file mode 100644 index 0000000..92ecc88 --- /dev/null +++ b/include/Windows_c++17_compat.h @@ -0,0 +1,36 @@ +/* ----------------- C++17 Compatible Windows.h Header ------------------ */ +/* In C++ 17 the type std::byte was added to act as a formal method + * to store raw, uninterpreted data so that the practice of using + * "unsigned char" would no longer be required and the "char" type + * would finally be used exclusively for the storage of 8-bit + * characters. This was a beneficial addition, but unfortunately + * caused compatability issues with the windows SDK (at least as of + * Windows 10 SDK 10.0.17763.132); the ancient header "rpcndr.h" that + * is part of "Windows.h" contains: + * + * typedef unsigned char byte; + * + * which adds a definition of "byte" to the global namespace instead + * of a Windows SDK specific namespace as it should have been. This + * clashes with "byte" and makes the type ambiguous when utilizing + * "using namespace std;". This can be worked around by only including + * the poritions of the Windows SDK that are required for a project + * instead of including "Windows.h" directly or stricly avoiding the + * use of "using namespace std;". + * + * If neither of these options are practical, this file can be substituted + * for "Windows.h" instead. This header uses a macro to change "byte" to + * "WIN_BYTE" during the inclusion of "Windows.h" only so that the Windows + * SDK still compiles correctly but no longer clashes with std::byte. + * + * - oblivioncth + */ + +#ifndef WINDOWS_C17_COMPAT_H +#define WINDOWS_C17_COMPAT_H + +#define byte WIN_BYTE +#include "Windows.h" +#undef byte + +#endif // WINDOWS_C17_COMPAT_H diff --git a/include/qx-io.h b/include/qx-io.h new file mode 100644 index 0000000..c1acd9a --- /dev/null +++ b/include/qx-io.h @@ -0,0 +1,141 @@ +#ifndef QXIO_H +#define QXIO_H + +#include +#include +#include +#include +#include +#include + +namespace Qx +{ +//-Classes-------------------------------------------------------------------------------------------------- +class IO +{ +//-Inner Class Forward Declarations--------------------------------------------------------------------------------------- +public: + class IOOpReport; + class TextPos; +//-Class Types------------------------------------------------------------------------------------------------------ +public: + enum IOOpType { IO_OP_READ, IO_OP_WRITE, IO_OP_ENUMERATE, IO_OP_INSPECT }; + enum IOOpResultType { IO_SUCCESS, IO_ERR_UNKNOWN, IO_ERR_ACCESS_DENIED, IO_ERR_NOT_A_FILE, IO_ERR_NOT_A_DIR, IO_ERR_OUT_OF_RES, + IO_ERR_READ, IO_ERR_WRITE, IO_ERR_FATAL, IO_ERR_OPEN, IO_ERR_ABORT, + IO_ERR_TIMEOUT, IO_ERR_REMOVE, IO_ERR_RENAME, IO_ERR_REPOSITION, + IO_ERR_RESIZE, IO_ERR_COPY, IO_ERR_FILE_DNE, IO_ERR_DIR_DNE, + IO_ERR_FILE_EXISTS, IO_ERR_CANT_MAKE_DIR, IO_ERR_FILE_SIZE_MISMATCH, IO_ERR_CURSOR_OOB}; + enum IOOpTargetType { IO_FILE, IO_DIR }; + +//-Class Variables------------------------------------------------------------------------------------------------- +public: + static inline QString ENDL = "\r\n"; //NOTE: Currently this is windows only + + //- Class Functions------------------------------------------------------------------------------------------------------------- + private: + static IOOpResultType parsedOpen(QFile& file, QIODevice::OpenMode openMode); + static IOOpResultType translateQFileDeviceError(QFileDevice::FileError fileError); + static IOOpResultType translateQTextStreamStatus(QTextStream::Status fileStatus); + static IOOpResultType fileCheck(QFile& file); + static IOOpResultType directoryCheck(QDir& dir); + + public: + // General: + static bool fileIsEmpty(QFile& file); + static bool fileIsEmpty(QFile& file, IOOpReport& reportBuffer); + // Text Based: + static IOOpReport findStringInFile(TextPos& returnBuffer, QFile& textFile, const QString& query, int hitsToSkip = 0); + static IOOpReport readTextFromFile(QString& returnBuffer, QFile& textFile, TextPos textPos, int characters = -1); + static IOOpReport readTextRangeFromFile(QString& returnBuffer, QFile& textFile, TextPos startPos, TextPos endPos = TextPos(-1,-1)); + static IOOpReport readAllTextFromFile(QString& returnBuffer, QFile& textFile); + static IOOpReport readAllTextFromFileByLine(QStringList& returnBuffer, QFile &textFile, int startLine, int endLine = -1); + static IOOpReport writeStringAsFile(QFile &textFile, const QString& text, bool overwriteIfExist = false, bool createDirs = true); + // Directory Based: + static IOOpReport getDirFileList(QStringList& returnBuffer, QDir directory, bool includeSubdirectories = false, QStringList extFilter = QStringList()); + static bool dirContainsFiles(QDir directory, bool includeSubdirectories = false); + static bool dirContainsFiles(QDir directory, IOOpReport& reportBuffer, bool includeSubdirectories = false); + // Integrity Based + static IOOpReport calculateFileChecksum(QByteArray& returnBuffer, QFile& file, QCryptographicHash::Algorithm hashAlgorithm); + // Raw Based + static IOOpReport readAllBytesFromFile(QByteArray& returnBuffer, QFile &file); + static IOOpReport readBytesFromFile(QByteArray& returnBuffer, QFile &file, long long start, long long end = -1); + static IOOpReport writeBytesAsFile(QFile &file, const QByteArray &byteArray, bool overwriteIfExist = false, bool createDirs = true); + +//-Inner Classes-------------------------------------------------------------------------------------------- +public: + class IOOpReport + { + //-Class Members---------------------------------------------------------------------------------------------------- + public: + static const inline QStringList TARGET_TYPES = {"file", "directory"}; + static const inline QString SUCCESS_TEMPLATE = "Succesfully %1 ""%3"""; + static const inline QString ERROR_TEMPLATE = "Error while %1 ""%3"""; + static const inline QStringList SUCCESS_VERBS = {"read", "wrote", "enumerated", "inspecting"}; + static const inline QStringList ERROR_VERBS = {"reading", "writing", "enumerating", "inspecting"}; + static const inline QStringList ERROR_INFO = {"An unknown error has occured.", "Access denied.", "Target is not a file.", "Target is not a directory.", "Out of resources.", + "General read error.", "General write error.", "A fatal error has occured.", "Could not open file.", "The opperation was aborted.", + "Request timed out.", "The file could not be removed.", "The file could not be renamed.", "The file could not be moved.", + "The file could not be resized.", "The file could not be copied.", "File does not exist.", "Directory does not exist.", + "The file already exists.", "The directory could not be created.", "File size mismatch.", "File data cursor has gone out of bounds."}; + + //-Instance Members------------------------------------------------------------------------------------------------- + private: + IOOpType mOperation; + IOOpResultType mResult; + IOOpTargetType mTargetType; + QString mTarget = QString(); + QString mOutcome = QString(); + QString mOutcomeInfo = QString(); + //-Constructor------------------------------------------------------------------------------------------------------- + public: + IOOpReport(); + IOOpReport(IOOpType op, IOOpResultType res, QFile& tar); + IOOpReport(IOOpType op, IOOpResultType res, QDir& tar); + + //-Instance Functions---------------------------------------------------------------------------------------------- + public: + IOOpType getOperation() const; + IOOpResultType getResult() const; + IOOpTargetType getTargetType() const; + QString getTarget() const; + QString getOutcome() const; + QString getOutcomeInfo() const; + bool wasSuccessful() const; + private: + void parseOutcome(); + }; + + class TextPos { + //-Class Types------------------------------------------------------------------------------------------------------ + public: + static const TextPos START; + static const TextPos END; + //-Instance Variables------------------------------------------------------------------------------------------------ + private: + int mLineNum; + int mCharNum; + //-Constructor------------------------------------------------------------------------------------------------------- + public: + TextPos(); + TextPos(int lineNum, int charNum); + + //-Instance Functions------------------------------------------------------------------------------------------------ + public: + int getLineNum(); + int getCharNum(); + void setLineNum(int lineNum); + void setCharNum(int charNum); + void setNull(); + bool isNull(); + + bool operator== (const TextPos &otherTextPos); + bool operator!= (const TextPos &otherTextPos); + bool operator> (const TextPos &otherTextPos); + bool operator>= (const TextPos &otherTextPos); + bool operator< (const TextPos &otherTextPos); + bool operator<= (const TextPos &otherTextPos); + }; +}; +} + +#endif // IO_H diff --git a/include/qx.h b/include/qx.h new file mode 100644 index 0000000..cd3dcbf --- /dev/null +++ b/include/qx.h @@ -0,0 +1,462 @@ +#ifndef QX_H +#define QX_H + +//#define REQUIRES(...) std::enable_if_t<__VA_ARGS__> // enable_if Macro; allows REQUIRES(std::is_arithmetic_v) for example +//TODO: Possibly remove this + +#include +#include +#include +#include +#include + +namespace Qx +{ +//-Class Forward Declarations--------------------------------------------------------------------------------------------- +template , int> = 0> +class NII; + +class Endian; + +//-Traits------------------------------------------------------------------------------------------------------- +template class Template> +struct is_specialization : std::false_type {}; + +template