Skip to content

Commit

Permalink
Added bounds checking for auto-reselection of list based container
Browse files Browse the repository at this point in the history
contents to prevent a crash from occuring when the item at index 0 is
removed for a given list
  • Loading branch information
oblivioncth committed Apr 1, 2020
1 parent 575b752 commit fff45a8
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 16 deletions.
12 changes: 6 additions & 6 deletions CoH_BSC_Editor.pro
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ RESOURCES += \

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
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lQx_static32_0-0-1-1_Qt_5-14-0
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lQx_static32_0-0-1-1_Qt_5-14-0d

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
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/libQx_static32_0-0-1-1_Qt_5-14-0.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/libQx_static32_0-0-1-1_Qt_5-14-0d.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/Qx_static32_0-0-1-1_Qt_5-14-0.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/Qx_static32_0-0-1-1_Qt_5-14-0d.lib
7 changes: 5 additions & 2 deletions include/qx-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ class IO
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 getLineCountOfFile(long long& returnBuffer, QFile& textFile);
static IOOpReport findStringInFile(TextPos& returnBuffer, QFile& textFile, const QString& query, int hitsToSkip = 0, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive);
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 readTextFromFileByLine(QStringList& returnBuffer, QFile &textFile, int startLine = 0, int endLine = -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);
static IOOpReport writeStringToEndOfFile(QFile &textFile, const QString& text, bool ensureNewLine = false, bool createIfDNE = false, bool createDirs = true); // Consider making function just writeStringToFile and use TextPos with bool for overwrite vs insert
static IOOpReport deleteTextRangeFromFile(QFile &textFile, TextPos startPos, TextPos endPos);
// Directory Based:
static IOOpReport getDirFileList(QStringList& returnBuffer, QDir directory, bool includeSubdirectories = false, QStringList extFilter = QStringList());
static bool dirContainsFiles(QDir directory, bool includeSubdirectories = false);
Expand Down
34 changes: 34 additions & 0 deletions include/qx-reg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef QXREG_H
#define QXREG_H
#include "qx.h"
#include "Windows_c++17_compat.h"

namespace Qx
{
//===============================================================================================================
// REG
//===============================================================================================================

class Reg
{
//-Inner Classes------------------------------------------------------------------------------------------------
class RegOpReport
{
//-Class Functions----------------------------------------------------------------------------------------------

};

//-Class Functions----------------------------------------------------------------------------------------------
public:
enum RegHive {HKCR, HKCU, HKLM, HKU, HKCC};
static QString readRegString(RegHive valueHive, const QString &valueKey, const QString &valueName);

private:
static HKEY resolveHiveEnum(RegHive regHive);
static LONG getStringRegKey(HKEY hKey, const std::wstring &strValueName, std::wstring &strValue);
static LONG getDWORDRegKey(HKEY hKey, const std::wstring &strValueName, DWORD &nValue, DWORD nDefaultValue);
static LONG getBoolRegKey(HKEY hKey, const std::wstring &strValueName, bool &bValue, bool bDefaultValue);
};

}
#endif // REG_H
14 changes: 14 additions & 0 deletions include/qx.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,21 @@ class List
return nullptr;
}

template<typename T> static QList<T> subtractAB(QList<T> &listA, QList<T> &listB)
{
// Difference list to fill
QList<T> differenceList;

for(T entry : listA)
{
if(!listB.contains(entry))
differenceList << entry;
}
return differenceList;
}

static QWidgetList objectListToWidgetList(QObjectList list);

};

class MMRB
Expand Down
Binary file added lib/Qx_static32_0-0-1-1_Qt_5-14-0.lib
Binary file not shown.
Binary file added lib/Qx_static32_0-0-1-1_Qt_5-14-0d.lib
Binary file not shown.
Binary file added lib/Qx_static32_0-0-1-1_Qt_5-14-0d.pdb
Binary file not shown.
Binary file removed lib/qxtended_static_0_0_1_0_Qt_5_12_3.lib
Binary file not shown.
Binary file removed lib/qxtended_static_0_0_1_0_Qt_5_12_3d.lib
Binary file not shown.
7 changes: 4 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QStatusBar>
#include <QProgressDialog>
#include <QMimeData>
#include <math.h>

//===============================================================================================================
// MAIN WINDOW
Expand Down Expand Up @@ -2136,7 +2137,7 @@ void MainWindow::all_on_toolButton_clicked()
getSelectedPlaylist()->removeInterpretedEffectBehavior(selectedIndex);
updateEffectBehaviors();
if(ui->tableWidget_effectBehaviors->rowCount() > 0)
ui->tableWidget_effectBehaviors->setCurrentCell(selectedIndex - 1, 0);
ui->tableWidget_effectBehaviors->setCurrentCell(std::max(0,selectedIndex - 1), 0);
}
else if(senderToolbutton == ui->toolButton_effectBehaviorsCopy)
{
Expand Down Expand Up @@ -2195,7 +2196,7 @@ void MainWindow::all_on_toolButton_clicked()
getSelectedPlaylist()->removeSoundContainer(selectedIndex);
updateSoundContainers();
if(ui->comboBox_soundContainer->count() > 0)
ui->comboBox_soundContainer->setCurrentIndex(selectedIndex - 1);
ui->comboBox_soundContainer->setCurrentIndex(std::max(0, selectedIndex - 1));

updateSoundContainerGroup(); // Must call manually to ensure update since the above may have moved the selected index
// to the desired index so using "setCurrentIndex()" on the same index won't trigger the corresponding slot
Expand Down Expand Up @@ -2267,7 +2268,7 @@ void MainWindow::all_on_toolButton_clicked()
currentSoundContainer->removeInterpretedLinkedFile(selectedIndex);
updateLinkedFiles();
if(ui->tableWidget_linkedFiles->rowCount() > 0)
ui->tableWidget_linkedFiles->setCurrentCell(selectedIndex - 1, 0);
ui->tableWidget_linkedFiles->setCurrentCell(std::max(0,selectedIndex - 1), 0);
}
else if(senderToolbutton == ui->toolButton_linkedFilesCopy)
{
Expand Down
10 changes: 5 additions & 5 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef VERSION_H
#define VERSION_H

#define VER_FILEVERSION 0,1,3,0
#define VER_FILEVERSION_STR "0.1.3.0"
#define VER_FILEVERSION 0,1,4,0
#define VER_FILEVERSION_STR "0.1.4.0"

#define VER_PRODUCTVERSION 0,1,3,0
#define VER_PRODUCTVERSION_STR "0.1.3.0"
#define VER_PRODUCTVERSION 0,1,4,0
#define VER_PRODUCTVERSION_STR "0.1.4.0"

#define VER_COMPANYNAME_STR "Obby Apps"
#define VER_FILEDESCRIPTION_STR "BSCWorks (CoH:v14)"
#define VER_INTERNALNAME_STR "CoH: BSC Editor"
#define VER_LEGALCOPYRIGHT_STR "Copyright © 2019 Obby Apps"
#define VER_LEGALCOPYRIGHT_STR "Copyright © 2020 Obby Apps"
#define VER_LEGALTRADEMARKS1_STR "All Rights Reserved"
#define VER_LEGALTRADEMARKS2_STR "GNU GPL V3"
#define VER_ORIGINALFILENAME_STR "BSCWorks.exe"
Expand Down

0 comments on commit fff45a8

Please sign in to comment.