Skip to content

Commit cf07a98

Browse files
Bugfixes in QC for commit 7c9a8c9:
fixed OptionSelectEngine invalid centring time when using simple option select fixed issues with cardodge left/right moving checker (in MoveUserCarLeft/Right), and positioning of bottomRight.X variable across the whole game Fixed incorrect error messages or error messages not showing up in FileCryptor command Consistency: add newlines to success messages in FileCryptor command Consistency: add success messages for Windows encryption/decryption Fix error checking not working in delete command Fix issues with configuration file formatting under Windows 7 Fix ZeeTerminal crashing when cancel pressed in filecryptor or delete command Colour change for Windows Dialogue instructions for Delete and FileCryptor commands Make CarDodge front screen more spatious in terms of decorative cars being more spaced out from the main menu text, to better properly support the old OptionSelectEngine.
1 parent 7c9a8c9 commit cf07a98

File tree

7 files changed

+106
-55
lines changed

7 files changed

+106
-55
lines changed

CommandFiles/CommandsFiles/CommandsFile_51to60.cpp

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ bool commands::Commands51To60(const std::string sCommand, char* cCommandArgs, co
155155

156156
// Encryption and decryption both require only keys and file/folderpath
157157
if (sFileName == "") {
158-
std::cout << wordWrap("Type in \"*open\" for Windows File Dialogue, or \"*openfolder\" for Windows Folder Dialogue.\n");
158+
colour(LCYN, ConfigObjMain.sColourGlobalBack);
159+
std::cout << wordWrap("Type in \"*open\" for Windows File Dialogue, or \"*openfolder\" for Windows Folder Dialogue.\n\n");
160+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
159161
sFileName = StrInput("Please input path to desired file/folder (0 to exit): > ");
160162
if (sFileName == "0") {
161163
Exiting();
@@ -170,6 +172,10 @@ bool commands::Commands51To60(const std::string sCommand, char* cCommandArgs, co
170172
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
171173
FileCryptorOpen.FileOpenDialogue("Open a File For Encryption", false);
172174
sFileName = FileCryptorOpen.GetRetrievedPathName();
175+
if (sFileName == "") {
176+
Exiting();
177+
return true;
178+
}
173179
}
174180
else if (sFileName == "*openfolder") {
175181
FileOpenGUIEngine FileCryptorOpen;
@@ -178,6 +184,10 @@ bool commands::Commands51To60(const std::string sCommand, char* cCommandArgs, co
178184
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
179185
FileCryptorOpen.FileOpenDialogue("Open a Folder For Encryption", true);
180186
sFileName = FileCryptorOpen.GetRetrievedPathName();
187+
if (sFileName == "") {
188+
Exiting();
189+
return true;
190+
}
181191
}
182192

183193
if (bUseWindowsEncryption == false && rKey1 == 0) {
@@ -199,7 +209,11 @@ bool commands::Commands51To60(const std::string sCommand, char* cCommandArgs, co
199209
if (!EncryptFileA(sFileName.c_str())) {
200210
VerbosityDisplay("In Commands(): ERROR - EncryptFileA() function failed, with error code " + std::to_string(GetLastError()) + ".\n");
201211
UserErrorDisplay("ERROR - An error occured when encrypting data. Failed with error code " + std::to_string(GetLastError()) + ".\n");
202-
return true;
212+
}
213+
else {
214+
colour(LGRN, ConfigObjMain.sColourGlobalBack);
215+
std::cout << CentreText("File/folder encryption successful!") << "\n";
216+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
203217
}
204218
}
205219
else {
@@ -221,8 +235,12 @@ bool commands::Commands51To60(const std::string sCommand, char* cCommandArgs, co
221235

222236
}
223237
else {
224-
FileCryptorObj.EncryptFile(sFileName, rKey1, rKey2);
238+
if (!FileCryptorObj.EncryptFile(sFileName, rKey1, rKey2)) {
239+
UserErrorDisplay("When encrypting " + sFileName + ": ERROR - " + FileCryptorObj.GetErrorLevelInfo() + "\n");
240+
nNumberOfFailedFiles++;
241+
}
225242
}
243+
226244
std::chrono::steady_clock::time_point TimePointEnd = std::chrono::steady_clock::now();
227245
std::chrono::duration<long double> ElapsedSeconds = TimePointEnd - TimePointStart;
228246

@@ -231,17 +249,21 @@ bool commands::Commands51To60(const std::string sCommand, char* cCommandArgs, co
231249
std::cout << "File/folder encryption complete!\n" << nNumberOfFailedFiles << " files have not been encrypted due to an error. Errors have been displayed above.\nElapsed Time: " << ElapsedSeconds.count() << " seconds.\n\n";
232250
}
233251
else {
234-
std::cout << "File/folder encryption successfully completed!\nElapsed Time: " << ElapsedSeconds.count();
252+
std::cout << "File/folder encryption successfully completed!\nElapsed Time: " << ElapsedSeconds.count() << " seconds.\n\n";
235253
}
236254
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
237255
}
238256
}
239257
else if (nOption == 2) {
240258
if (bUseWindowsEncryption) {
241-
if (DecryptFileA(sFileName.c_str(), NULL)) {
259+
if (!DecryptFileA(sFileName.c_str(), NULL)) {
242260
VerbosityDisplay("In Commands(): ERROR - DecryptFileA() function failed, with error code " + std::to_string(GetLastError()) + ".\n");
243261
UserErrorDisplay("ERROR - An error occured when decrypting data. Failed with error code " + std::to_string(GetLastError()) + ".\n");
244-
return true;
262+
}
263+
else {
264+
colour(LGRN, ConfigObjMain.sColourGlobalBack);
265+
std::cout << CentreText("File/folder decryption successful!") << "\n";
266+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
245267
}
246268
}
247269
else {
@@ -263,7 +285,10 @@ bool commands::Commands51To60(const std::string sCommand, char* cCommandArgs, co
263285

264286
}
265287
else {
266-
FileCryptorObj.DecryptFile(sFileName, rKey1, rKey2);
288+
if (!FileCryptorObj.DecryptFile(sFileName, rKey1, rKey2)) {
289+
UserErrorDisplay("When decrypting " + sFileName + ": ERROR - " + FileCryptorObj.GetErrorLevelInfo() + "\n");
290+
nNumberOfFailedFiles++;
291+
}
267292
}
268293
std::chrono::steady_clock::time_point TimePointEnd = std::chrono::steady_clock::now();
269294
std::chrono::duration<long double> ElapsedSeconds = TimePointEnd - TimePointStart;
@@ -273,7 +298,7 @@ bool commands::Commands51To60(const std::string sCommand, char* cCommandArgs, co
273298
std::cout << "File/folder decryption complete!\n" << nNumberOfFailedFiles << " files have not been decrypted due to an error. Errors have been displayed above.\nElapsed Time: " << ElapsedSeconds.count() << " seconds.\n\n";
274299
}
275300
else {
276-
std::cout << "File/folder decryption successfully completed!\nElapsed Time: " << ElapsedSeconds.count();
301+
std::cout << "File/folder decryption successfully completed!\nElapsed Time: " << ElapsedSeconds.count() << " seconds.\n\n";
277302
}
278303
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
279304
}
@@ -302,21 +327,29 @@ bool commands::Commands51To60(const std::string sCommand, char* cCommandArgs, co
302327
// Output title, prompt input
303328
CentreColouredText(" ___DELETE___ ", 1);
304329

305-
std::cout << wordWrap("\n\nThis command allows you to delete files or folders permanently.\nType in \"*open\" for Windows File Dialogue, or \"*openfolder\" for Windows Folder Dialogue.\n\n");
330+
std::cout << wordWrap("\n\nThis command allows you to delete files or folders permanently.\n");
331+
colour(LCYN, ConfigObjMain.sColourGlobalBack);
332+
std::cout << wordWrap("Type in \"*open\" for Windows File Dialogue, or \"*openfolder\" for Windows Folder Dialogue.\n\n");
333+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
306334
sFileName = StrInput("Please input the path to the file/folder you want to delete (0 to exit): > ");
307335
if (sFileName == "0") {
308336
Exiting();
309337
return true;
310338
}
311339
}
312340

341+
313342
if (sFileName == "*open") {
314343
FileOpenGUIEngine DeleteOpen;
315344
colour(YLW, ConfigObjMain.sColourGlobalBack);
316345
std::cout << "Opening the Windows File Dialogue...\n";
317346
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
318347
DeleteOpen.FileOpenDialogue("Open a File For Encryption", false);
319348
sFileName = DeleteOpen.GetRetrievedPathName();
349+
if (sFileName == "") {
350+
Exiting();
351+
return true;
352+
}
320353
}
321354
else if (sFileName == "*openfolder") {
322355
FileOpenGUIEngine DeleteOpen;
@@ -325,27 +358,37 @@ bool commands::Commands51To60(const std::string sCommand, char* cCommandArgs, co
325358
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
326359
DeleteOpen.FileOpenDialogue("Open a Folder For Encryption", true);
327360
sFileName = DeleteOpen.GetRetrievedPathName();
361+
if (sFileName == "") {
362+
Exiting();
363+
return true;
364+
}
328365
}
329366

330367
// Delete file/folder
331-
std::error_code ecDelete{};
332368
try {
333-
std::filesystem::remove_all(sFileName, ecDelete);
369+
std::error_code ecDelete{};
370+
uintmax_t nReturnCode = std::filesystem::remove_all(sFileName, ecDelete);
371+
372+
// 0 means no files have been deleted
373+
if (nReturnCode == 0) {
374+
VerbosityDisplay("In Commands(): ERROR - Failed to delete file/folder. Error code: 2. Error info: File/folder not found.\n");
375+
UserErrorDisplay("ERROR - An error occured when deleting file/folder. Error info: File/folder not found.\n");
376+
return true;
377+
}
378+
// -1 means error
379+
else if (nReturnCode == -1) {
380+
VerbosityDisplay("In Commands(): ERROR - Failed to delete file/folder. Error code: " + std::to_string(ecDelete.value()) + ". Error info: " + ecDelete.message() + ".\n");
381+
UserErrorDisplay("ERROR - An error occured when deleting file/folder. Error code: " + std::to_string(ecDelete.value()) + ".\n");
382+
return true;
383+
}
334384
}
335385

336-
catch (std::bad_alloc) {
386+
catch (std::bad_alloc&) {
337387
VerbosityDisplay("In Commands(): ERROR - Memory allocation failed for std::filesystem::remove_all().\n");
338388
UserErrorDisplay("ERROR - Failed to allocate memory. Please try again later.\n");
339389
return true;
340390
}
341391

342-
// Get error messages
343-
if (ecDelete) {
344-
VerbosityDisplay("In Commands(): ERROR - Failed to delete file/folder. Error code: " + std::to_string(ecDelete.value()) + ". Error info: " + ecDelete.message() + ".\n");
345-
UserErrorDisplay("ERROR - An error occured when deleting file/folder. Info: " + ecDelete.message() + ".\n");
346-
return true;
347-
}
348-
349392
colour(LGRN, ConfigObjMain.sColourGlobalBack);
350393
std::cout << '\n' << CentreText("File/folder deletion successful!") << "\n";
351394
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);

Engine/ConfigFile-System/ConfigFile-System.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,20 @@ ConfigFileSystem::~ConfigFileSystem() {
107107
bool ConfigFileSystem::CreateConfigFile()
108108
{
109109
// 1. Attempt to create config file in user-defined location
110-
std::ofstream CreateConfigOut(sConfigFileUserLocation, std::ios::binary);
110+
std::ofstream CreateConfigOut(sConfigFileUserLocation);
111111

112112
// 2. Check if open successful; if not, use default location; if not, return false
113113
if (CreateConfigOut.fail() == true) {
114114
VerbosityDisplay("In ConfigFileSystem::CreateConfigFile(): Warning - User file location cannot be opened. Attempting to create config file in default location.\n", nObjectID);
115-
CreateConfigOut.open(sConfigFileDefaultLocation, std::ios::binary);
115+
CreateConfigOut.open(sConfigFileDefaultLocation);
116116
if (CreateConfigOut.fail() == true) {
117117
VerbosityDisplay("In ConfigFileSystem::CreateConfigFile(): ERROR - Default location could not be opened. Configuration file creation failed.", nObjectID);
118118
return false;
119119
}
120120
else {
121121
// Point to new file
122122
sConfigFileUserLocation = sConfigFileDefaultLocation;
123-
CreateConfigOut.open(sConfigFileUserLocation, std::ios::binary);
123+
CreateConfigOut.open(sConfigFileUserLocation);
124124
}
125125
}
126126

@@ -142,13 +142,13 @@ bool ConfigFileSystem::WriteConfigFile() {
142142
std::string sConfigFinalLocation = "";
143143

144144
// 2. Create test file stream
145-
std::ifstream TestStreamIn(sConfigFileUserLocation, std::ios::binary);
145+
std::ifstream TestStreamIn(sConfigFileUserLocation);
146146

147147
// 3. Test for file existence in user-set location and ZeeTerminal folder
148148
if (TestStreamIn.fail() == true) {
149149
VerbosityDisplay("In ConfigFileSystem::WriteConfigFile(): Warning- User-defined file seems to be nonexistent. Attempting to write to default location.\n", nObjectID);
150150
TestStreamIn.clear();
151-
TestStreamIn.open(sConfigFileDefaultLocation, std::ios::binary);
151+
TestStreamIn.open(sConfigFileDefaultLocation);
152152

153153
if (TestStreamIn.fail() == true) {
154154
VerbosityDisplay("In ConfigFileSystem::WriteConfigFile(): Warning - Default location file not found. Attempting to create new configuration file.\n", nObjectID);
@@ -167,7 +167,7 @@ bool ConfigFileSystem::WriteConfigFile() {
167167
TestStreamIn.close();
168168

169169
// 5. Open main file stream; post message that write operation has began.
170-
std::ofstream MainStreamOut(sConfigFinalLocation, std::ios::binary);
170+
std::ofstream MainStreamOut(sConfigFinalLocation);
171171

172172
// Unexpected failure - just exit
173173
if (MainStreamOut.fail()) {
@@ -209,13 +209,13 @@ bool ConfigFileSystem::ReadConfigFile()
209209
std::string sConfigFinalLocation = "";
210210

211211
// 2. Create test file stream
212-
std::ifstream TestStreamIn(sConfigFileUserLocation, std::ios::binary);
212+
std::ifstream TestStreamIn(sConfigFileUserLocation);
213213

214214
// 3. Test for file existence in user-set location and ZeeTerminal folder
215215
if (TestStreamIn.fail() == true) {
216216
VerbosityDisplay("In ConfigFileSystem::ReadConfigFile(): Warning- User-defined file seems to be nonexistent. Attempting to read from default location.\n", nObjectID);
217217
TestStreamIn.clear();
218-
TestStreamIn.open(sConfigFileDefaultLocation, std::ios::binary);
218+
TestStreamIn.open(sConfigFileDefaultLocation);
219219

220220
if (TestStreamIn.fail() == true) {
221221
VerbosityDisplay("In ConfigFileSystem::ReadConfigFile(): Warning - Default location file not found. Attempting to create new configuration file.\n", nObjectID);
@@ -234,7 +234,7 @@ bool ConfigFileSystem::ReadConfigFile()
234234
TestStreamIn.close();
235235

236236
// 5. Create new main file stream
237-
std::ifstream MainStreamIn(sConfigFinalLocation, std::ios::binary);
237+
std::ifstream MainStreamIn(sConfigFinalLocation);
238238

239239
// Unexpected failure - just exit
240240
if (MainStreamIn.fail()) {
@@ -283,7 +283,7 @@ bool ConfigFileSystem::ReadConfigFile()
283283
}
284284

285285
// 10. Parse final contents and put into value string
286-
std::getline(LineStream, sValueBuffer, '\r');
286+
std::getline(LineStream, sValueBuffer, '\n');
287287

288288
// Check if anything is in the value string
289289
if (sValueBuffer == "") {

Engine/FileOpenGUIEngine/FileOpenGUIEngine.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool FileOpenGUIEngine::FileOpenDialogue(std::string sTitle, bool bSelectFolder)
5757
IFileOpenDialog* pFileOpen = NULL;
5858
IShellItem* pItem = NULL;
5959

60-
LPWSTR pwszFilePath = (LPWSTR)L"";
60+
LPWSTR pwszFilePath = 0;
6161

6262
// Initialise COM libraries
6363
hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
@@ -144,7 +144,9 @@ bool FileOpenGUIEngine::FileOpenDialogue(std::string sTitle, bool bSelectFolder)
144144

145145
done:
146146

147-
CoTaskMemFree(pwszFilePath);
147+
if (pwszFilePath) {
148+
CoTaskMemFree(pwszFilePath);
149+
}
148150

149151
if (pItem)
150152
{

Engine/OptionSelectEngine/OptionSelectEngine.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ int OptionSelectEngine::SimpleOptionSelect(std::string sPrompt, std::string sTit
101101
while (true) {
102102
// Input centred when options are centred - avoids overcomplication
103103
std::string sInputPrompt = "Please input a desired option number (input 0 to exit): > ";
104-
MoveCursorToXCoord(((csbiOptionSelect.srWindow.Right - csbiOptionSelect.srWindow.Left) - sInputPrompt.length()) / 2);
104+
105+
// Move prompt to centre if centring prompt is enabled
106+
if (bCentrePrompt) {
107+
MoveCursorToXCoord(((csbiOptionSelect.srWindow.Right - csbiOptionSelect.srWindow.Left) - sInputPrompt.length()) / 2);
108+
}
105109
nInput = NumInputi(sInputPrompt);
106110

107111
if (nInput == 0) {

GameFiles/CarDodge/CarDodge.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,47 +132,42 @@ inline void RenderMainMenuCars() {
132132
ciMainMenuEnemyCar.CarStyle = Style.EnemyCar;
133133

134134
// Set up left side of main menu
135-
ciMainMenuUserCar.bottomLeft = { short(nDirectionsTextLeftColumn - 7), 14 };
136-
ciMainMenuUserCar.bottomRight = { short(ciMainMenuUserCar.bottomLeft.X + 4), ciMainMenuUserCar.bottomLeft.Y };
137-
138-
ciMainMenuEnemyCar.bottomLeft = { short(nDirectionsTextLeftColumn - 10), 9 };
139-
ciMainMenuEnemyCar.bottomRight = { short(ciMainMenuEnemyCar.bottomLeft.X + 4), ciMainMenuEnemyCar.bottomLeft.Y };
135+
ciMainMenuUserCar.bottomLeft = { short(nDirectionsTextLeftColumn - 10), 14 };
136+
ciMainMenuEnemyCar.bottomLeft = { short(nDirectionsTextLeftColumn - 13), 9 };
140137

141138
// Render left side of main menu
142139
colour(LYLW, sMenuColourBack);
143140
RenderCar(ciMainMenuEnemyCar);
144141
RenderCar(ciMainMenuUserCar);
145142

146143
// Set up right side of main menu
147-
ciMainMenuUserCar.bottomLeft = { short(nDirectionsTextRightColumn + 3), 14 };
148-
ciMainMenuUserCar.bottomRight = { short(ciMainMenuUserCar.bottomLeft.X + 4), ciMainMenuUserCar.bottomLeft.Y };
144+
ciMainMenuUserCar.bottomLeft = { short(nDirectionsTextRightColumn + 6), 14 };
149145
ciMainMenuUserCar.CarStyle = Style.XtraAero;
150146

151-
ciMainMenuEnemyCar.bottomLeft = { short(nDirectionsTextRightColumn + 8), 11 };
152-
ciMainMenuEnemyCar.bottomRight = { short(ciMainMenuEnemyCar.bottomLeft.X + 4), ciMainMenuEnemyCar.bottomLeft.Y };
147+
ciMainMenuEnemyCar.bottomLeft = { short(nDirectionsTextRightColumn + 11), 11 };
153148

154149
// Render left side of main menu
155150
RenderCar(ciMainMenuEnemyCar);
156151
RenderCar(ciMainMenuUserCar);
157152

158153
// Render annotations for the cars on both sides of the main menu
159154
colour(LGRN, sMenuColourBack);
160-
SetCursorPosition(nDirectionsTextRightColumn + 9, 13);
155+
SetCursorPosition(nDirectionsTextRightColumn + 12, 13);
161156
std::cout << "||";
162-
SetCursorPosition(nDirectionsTextRightColumn + 9, 14);
157+
SetCursorPosition(nDirectionsTextRightColumn + 12, 14);
163158
std::cout << "VV";
164159

165-
SetCursorPosition(nDirectionsTextRightColumn + 4, 8);
160+
SetCursorPosition(nDirectionsTextRightColumn + 7, 8);
166161
std::cout << "^^";
167-
SetCursorPosition(nDirectionsTextRightColumn + 4, 9);
162+
SetCursorPosition(nDirectionsTextRightColumn + 7, 9);
168163
std::cout << "||";
169164

170165
colour(LMAG, sMenuColourBack);
171-
SetCursorPosition(nDirectionsTextLeftColumn, 9);
166+
SetCursorPosition(nDirectionsTextLeftColumn - 3, 9);
172167
std::cout << "\\/";
173-
SetCursorPosition(nDirectionsTextLeftColumn, 11);
168+
SetCursorPosition(nDirectionsTextLeftColumn - 3, 11);
174169
std::cout << "/\\";
175-
SetCursorPosition(nDirectionsTextLeftColumn - 6, 10);
170+
SetCursorPosition(nDirectionsTextLeftColumn - 9, 10);
176171
std::cout << "<-- CRASH";
177172

178173
// Set colours back to normal
@@ -205,11 +200,13 @@ void CarDodgeMainMenu()
205200
// Ensure that terminal is suitable for playing the game
206201
if (!VerifyIfGameIsRunnable(true, true)) {
207202
std::cout << "Take your time to resize the main menu window. The CarDodge main menu will reappear when the window is resized.\nPress any key to exit the game.\n";
203+
bool bExitGame = false;
208204
while (true) {
209205
// Check if user inputted anything
210206
if (_kbhit()) {
211207
_getch();
212-
return;
208+
bExitGame = true;
209+
break;
213210
}
214211

215212
// Check window size repeatedly
@@ -221,6 +218,9 @@ void CarDodgeMainMenu()
221218
sleep(1);
222219
}
223220

221+
// Game needs to be exited as user pressed a key - break out of main while loop
222+
if (bExitGame) break;
223+
224224
// Clear screen to start terminal afresh from any error messages
225225
cls();
226226
}

0 commit comments

Comments
 (0)