#include "AppRunSettings.h" AppRunSettings::AppRunSettings(int argc, char * argv[]) { if (SetDefaults()) // Set the runtime defaults { IsValid = ValidateParameters(argc, argv); // Validate and capture the parameters } if (IsValid) { if (LogLevel > LOGLEVEL_NORMAL) { // Show the current parameter settings ShowSettings(); } } } AppRunSettings::~AppRunSettings(void) { } bool AppRunSettings::SetDefaults(void) { // Set the default values for all settings szRepServer[0] = '\0'; // Repository server defaults to local szManifestURL[0] = '\0'; // Default to no URL RunningAsAddin = false; // Running as server Addin Task NoAppLog = true; // No Application Event Logging EchoLog = true; // Force Echo to the console CreateRepository = true; // Create the repository UpdateDesign = false; // Update the design return true; } bool AppRunSettings::ValidateParameters(int argc, char* argv[]) { bool bFlagIsValid; int iIndex; char szFlag[MAX_FLAG]; char szLocalMsg[MAX_MSG]; // Validate and capture the runtime parameters AllowExecution = true; // Allow request to display program usage if ((argc == 2) && (strcmp(argv[1], "-?") == 0)) { ShowUsage(); AllowExecution = false; return true; } if (argc < 4) { std::cout << MSG_CDB0050E << std::endl; ShowUsage(); return false; } // Copy the positional parameter strcpy_s(szRepServer, MAX_SERVER, argv[1]); strcpy_s(szRepDb, MAX_DATABASE, argv[2]); strcpy_s(szManifestURL, MAX_URL, argv[3]); // Check that we have sufficient positional parameters before trying to parse them if (szRepServer[0] == '-') { std::cout << MSG_CDB0050E << std::endl; ShowUsage(); return false; } if (szRepDb[0] == '-') { std::cout << MSG_CDB0050E << std::endl; ShowUsage(); return false; } if (szManifestURL[0] == '-') { std::cout << MSG_CDB0050E << std::endl; ShowUsage(); return false; } // Parse any switches that were supplied if (argc > 4) { for (iIndex = 4; iIndex < argc; iIndex++) { bFlagIsValid = false; strcpy_s(szFlag, MAX_FLAG, argv[iIndex]); if (memcmp(szFlag, "-", 1) == 0) { // Parameter is a switch if (memcmp(szFlag + 1, "?", 1) == 0) { // Show Usage - do not run the application ShowUsage(); AllowExecution = false; return true; } if ((memcmp(szFlag + 1, "V", 1) == 0) || (memcmp(szFlag + 1, "v", 1) == 0)) { // Verbose logging LogLevel = LOGLEVEL_VERBOSE; bFlagIsValid = true; } if ((memcmp(szFlag + 1, "D", 1) == 0) || (memcmp(szFlag + 1, "d", 1) == 0)) { // Debug logging LogLevel = LOGLEVEL_DEBUG; bFlagIsValid = true; } if ((memcmp(szFlag + 1, "T", 1) == 0) || (memcmp(szFlag + 1, "t", 1) == 0)) { // Verbose logging LogLevel = LOGLEVEL_TRACE; bFlagIsValid = true; } if ((memcmp(szFlag + 1, "U", 1) == 0) || (memcmp(szFlag + 1, "u", 1) == 0)) { // Update the repository database design CreateRepository = false; UpdateDesign = true; bFlagIsValid = true; } if (!bFlagIsValid) { // Invalid switch sprintf_s(szLocalMsg, MAX_MSG, MSG_CDB0052E, szFlag); std::cout << szLocalMsg << std::endl; } } else { // Allow an "=" switch (override default ini file search on notes initialisation) if (memcmp(szFlag, "=", 1) != 0) { // Invalid parameter sprintf_s(szLocalMsg, MAX_MSG, MSG_CDB0051E, szFlag); std::cout << szLocalMsg << std::endl; } } } } return true; } void AppRunSettings::ShowUsage(void) { // Show program usage std::cout << MSG_USAGE1 << std::endl; std::cout << MSG_USAGE2 << std::endl; std::cout << MSG_USAGE3 << std::endl; std::cout << MSG_USAGE4 << std::endl; std::cout << MSG_USAGE5 << std::endl; std::cout << MSG_USAGE6 << std::endl; std::cout << MSG_USAGE7 << std::endl; std::cout << MSG_USAGE8 << std::endl; } void AppRunSettings::ShowSettings(void) { // Show the current Run Settings char szLocalMsg[MAX_MSG]; if (LogLevel == LOGLEVEL_NORMAL) { sprintf_s(szLocalMsg, MAX_MSG, MSG_CDB0053I, "Normal"); } else { if (LogLevel == LOGLEVEL_VERBOSE) { sprintf_s(szLocalMsg, MAX_MSG, MSG_CDB0053I, "Verbose"); } else { if (LogLevel == LOGLEVEL_TRACE) { sprintf_s(szLocalMsg, MAX_MSG, MSG_CDB0053I, "Trace"); } else { sprintf_s(szLocalMsg, MAX_MSG, MSG_CDB0053I, "Debug"); } } } std::cout << szLocalMsg << std::endl; if (UpdateDesign) { std::cout << MSG_CDB0054I << std::endl; } }