Compare commits
2 Commits
dc5da0a7b7
...
d41b9da4e2
| Author | SHA1 | Date | |
|---|---|---|---|
| d41b9da4e2 | |||
| 0bef16e82c |
@@ -6,6 +6,7 @@ Description: Implementation file containing the method definitions of the
|
|||||||
Author: Trenser
|
Author: Trenser
|
||||||
Date:19-May-2026
|
Date:19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ComboPackage.h"
|
#include "ComboPackage.h"
|
||||||
#include "Controller.h"
|
#include "Controller.h"
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
|||||||
+41
-13
@@ -38,6 +38,15 @@ bool DataStore::initialize()
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!lockDataStore())
|
||||||
|
{
|
||||||
|
CloseHandle(m_globalMutex);
|
||||||
|
m_globalMutex = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool success = true;
|
||||||
|
do
|
||||||
|
{
|
||||||
util::ensureDirectoryExists(config::file::DIRECTORY);
|
util::ensureDirectoryExists(config::file::DIRECTORY);
|
||||||
m_users.fileName = config::file::USER_FILE;
|
m_users.fileName = config::file::USER_FILE;
|
||||||
m_users.recordSize = sizeof(SerializedUser);
|
m_users.recordSize = sizeof(SerializedUser);
|
||||||
@@ -63,53 +72,72 @@ bool DataStore::initialize()
|
|||||||
m_inventoryManagementObservers.recordSize = sizeof(SerializedObserver);
|
m_inventoryManagementObservers.recordSize = sizeof(SerializedObserver);
|
||||||
if (!SharedMemory::createOrOpenMapping(m_users))
|
if (!SharedMemory::createOrOpenMapping(m_users))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!SharedMemory::createOrOpenMapping(m_notifications))
|
if (!SharedMemory::createOrOpenMapping(m_notifications))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!SharedMemory::createOrOpenMapping(m_services))
|
if (!SharedMemory::createOrOpenMapping(m_services))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SharedMemory::createOrOpenMapping(m_comboPackages))
|
if (!SharedMemory::createOrOpenMapping(m_comboPackages))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!SharedMemory::createOrOpenMapping(m_inventoryItems))
|
if (!SharedMemory::createOrOpenMapping(m_inventoryItems))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!SharedMemory::createOrOpenMapping(m_serviceBookings))
|
if (!SharedMemory::createOrOpenMapping(m_serviceBookings))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!SharedMemory::createOrOpenMapping(m_jobCards))
|
if (!SharedMemory::createOrOpenMapping(m_jobCards))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!SharedMemory::createOrOpenMapping(m_invoices))
|
if (!SharedMemory::createOrOpenMapping(m_invoices))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!SharedMemory::createOrOpenMapping(m_payments))
|
if (!SharedMemory::createOrOpenMapping(m_payments))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!SharedMemory::createOrOpenMapping(m_serviceManagementObservers))
|
if (!SharedMemory::createOrOpenMapping(m_serviceManagementObservers))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!SharedMemory::createOrOpenMapping(m_paymentManagementObservers))
|
if (!SharedMemory::createOrOpenMapping(m_paymentManagementObservers))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!SharedMemory::createOrOpenMapping(m_inventoryManagementObservers))
|
if (!SharedMemory::createOrOpenMapping(m_inventoryManagementObservers))
|
||||||
{
|
{
|
||||||
return false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
} while (false);
|
||||||
|
unlockDataStore();
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
shutdown();
|
||||||
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+9
@@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
File: FileHeader.h
|
||||||
|
Description: Defines the FileHeader structure used to store
|
||||||
|
metadata for binary record files, including
|
||||||
|
record count and capacity.
|
||||||
|
Author: Trenser
|
||||||
|
Created: 10-June-2026
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
|||||||
+10
@@ -1,3 +1,13 @@
|
|||||||
|
/*
|
||||||
|
File: MappingInfo.h
|
||||||
|
Description: Defines the MappingInfo structure used for
|
||||||
|
managing Windows file mapping operations.
|
||||||
|
Stores handles, mapped view pointer,
|
||||||
|
file metadata, and capacity information.
|
||||||
|
Author: Trenser
|
||||||
|
Created: 10-June-2026
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
+9
@@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
File: RecordState.h
|
||||||
|
Description: Defines the RecordState enumeration used to
|
||||||
|
represent the state of a record in storage.
|
||||||
|
States include CLEAN, NEW_RECORD, and MODIFIED.
|
||||||
|
Author: Trenser
|
||||||
|
Created: 10-June-2026
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
enum class RecordState : int
|
enum class RecordState : int
|
||||||
|
|||||||
+12
@@ -1,3 +1,15 @@
|
|||||||
|
/*
|
||||||
|
File: SerializedRecords.h
|
||||||
|
Description: Defines serialized structures for persistent storage
|
||||||
|
and retrieval of system entities including User,
|
||||||
|
Notification, Service, ComboPackage, InventoryItem,
|
||||||
|
ServiceBooking, JobCard, Invoice, and Observer.
|
||||||
|
These structures use fixed-size character arrays
|
||||||
|
and primitive types for binary serialization.
|
||||||
|
Author: Trenser
|
||||||
|
Created: 10-June-2026
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
|||||||
+11
@@ -1,3 +1,14 @@
|
|||||||
|
/*
|
||||||
|
File: SharedMemory.cpp
|
||||||
|
Description: Implements shared memory utilities for managing
|
||||||
|
Windows file mapping operations. Provides functions
|
||||||
|
to create, open, resize, and close mappings, as well
|
||||||
|
as access headers, records, and ensure synchronization
|
||||||
|
across processes.
|
||||||
|
Author: Trenser
|
||||||
|
Created: 11-June-2026
|
||||||
|
*/
|
||||||
|
|
||||||
#include "SharedMemory.h"
|
#include "SharedMemory.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
|
|||||||
+11
@@ -1,3 +1,14 @@
|
|||||||
|
/*
|
||||||
|
File: SharedMemory.h
|
||||||
|
Description: Declares functions for managing Windows file
|
||||||
|
mapping and shared memory operations. Provides
|
||||||
|
utilities for creating, resizing, and closing
|
||||||
|
mappings, as well as accessing headers and
|
||||||
|
record data.
|
||||||
|
Author: Trenser
|
||||||
|
Created: 10-June-2026
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include "MappingInfo.h"
|
#include "MappingInfo.h"
|
||||||
|
|||||||
+10
@@ -1,3 +1,13 @@
|
|||||||
|
/*
|
||||||
|
File: TrackedRecord.h
|
||||||
|
Description: Defines the TrackedRecord template structure used
|
||||||
|
to manage objects with associated record state and
|
||||||
|
slot index. Supports tracking of CLEAN, NEW_RECORD,
|
||||||
|
and MODIFIED states for persistence and synchronization.
|
||||||
|
Author: Trenser
|
||||||
|
Created: 10-June-2026
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "RecordState.h"
|
#include "RecordState.h"
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ Author: Trenser
|
|||||||
Date: 19-May-2026
|
Date: 19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Description: Implementation file containing the method definitions of the
|
|||||||
Author: Trenser
|
Author: Trenser
|
||||||
Date:19-May-2026
|
Date:19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "SerializedRecords.h"
|
#include "SerializedRecords.h"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Description: Header file declaring the ServiceBooking class, which represents
|
|||||||
Author: Trenser
|
Author: Trenser
|
||||||
Date:19-May-2026
|
Date:19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
|
|||||||
+1
@@ -6,6 +6,7 @@ Description: Header file declaring the UserManagementService class, which manage
|
|||||||
Author: Trenser
|
Author: Trenser
|
||||||
Date:19-May-2026
|
Date:19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <conio.h>
|
||||||
|
|
||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
@@ -54,6 +55,48 @@ namespace util
|
|||||||
value = cleanedValue;
|
value = cleanedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function: readPassword
|
||||||
|
* Description: Reads a password from console without echoing characters;
|
||||||
|
* displays '*' for each character typed, handles backspace,
|
||||||
|
* and cleans commas from the result.
|
||||||
|
* Parameters:
|
||||||
|
* value - reference to a string where the password will be stored
|
||||||
|
* Returns:
|
||||||
|
* void - no return value
|
||||||
|
*/
|
||||||
|
inline void readPassword(std::string& value)
|
||||||
|
{
|
||||||
|
value.clear();
|
||||||
|
char currentCharacter;
|
||||||
|
while ((currentCharacter = _getch()) != '\r')
|
||||||
|
{
|
||||||
|
if (currentCharacter == '\b')
|
||||||
|
{
|
||||||
|
if (!value.empty())
|
||||||
|
{
|
||||||
|
value.pop_back();
|
||||||
|
std::cout << "\b \b";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value += currentCharacter;
|
||||||
|
std::cout << '*';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::string cleanedValue;
|
||||||
|
for (int iterator = 0; iterator < value.length(); iterator++)
|
||||||
|
{
|
||||||
|
if (value[iterator] != ',')
|
||||||
|
{
|
||||||
|
cleanedValue += value[iterator];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value = cleanedValue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function: pressEnter
|
* Function: pressEnter
|
||||||
* Description: Pauses execution until the user presses Enter.
|
* Description: Pauses execution until the user presses Enter.
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ Description: Displays the customer menu and handles user input until logout is s
|
|||||||
Parameter: None
|
Parameter: None
|
||||||
Return type: void
|
Return type: void
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void CustomerMenu::showMenu()
|
void CustomerMenu::showMenu()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
|
|||||||
@@ -914,7 +914,7 @@ inline void changePasswordHelper(Controller& controller)
|
|||||||
util::clear();
|
util::clear();
|
||||||
std::cout << "Change Password\n";
|
std::cout << "Change Password\n";
|
||||||
std::cout << "Enter new password: ";
|
std::cout << "Enter new password: ";
|
||||||
util::read(newPassword);
|
util::readPassword(newPassword);
|
||||||
if (!util::isPasswordValid(newPassword))
|
if (!util::isPasswordValid(newPassword))
|
||||||
{
|
{
|
||||||
std::cout << "Error: Password is not strong enough!\n";
|
std::cout << "Error: Password is not strong enough!\n";
|
||||||
@@ -928,7 +928,7 @@ inline void changePasswordHelper(Controller& controller)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::cout << "Confirm new password: ";
|
std::cout << "Confirm new password: ";
|
||||||
util::read(confirmedPassword);
|
util::readPassword(confirmedPassword);
|
||||||
if (confirmedPassword != newPassword)
|
if (confirmedPassword != newPassword)
|
||||||
{
|
{
|
||||||
std::cout << "Passwords are different. Try again\n";
|
std::cout << "Passwords are different. Try again\n";
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ void UserInterface::login()
|
|||||||
std::cout << "Enter username: ";
|
std::cout << "Enter username: ";
|
||||||
util::read(username);
|
util::read(username);
|
||||||
std::cout << "Enter password: ";
|
std::cout << "Enter password: ";
|
||||||
util::read(password);
|
util::readPassword(password);
|
||||||
if (m_controller.login(username, password))
|
if (m_controller.login(username, password))
|
||||||
{
|
{
|
||||||
const User* authenticatedUser = m_controller.getAuthenticatedUser();
|
const User* authenticatedUser = m_controller.getAuthenticatedUser();
|
||||||
@@ -167,7 +167,7 @@ void UserInterface::registerCustomer()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::cout << "Enter password: ";
|
std::cout << "Enter password: ";
|
||||||
util::read(password);
|
util::readPassword(password);
|
||||||
if (!util::isPasswordValid(password))
|
if (!util::isPasswordValid(password))
|
||||||
{
|
{
|
||||||
std::cout << "Error: Password is invalid!";
|
std::cout << "Error: Password is invalid!";
|
||||||
|
|||||||
Reference in New Issue
Block a user