From b83287b76801db50c30bf473cebbfdd6b1cb167c Mon Sep 17 00:00:00 2001 From: amazing-username Date: Sun, 6 Aug 2017 21:24:09 -0500 Subject: [PATCH] Added the feature of having a working application directory --- Conversions.cpp | 23 +++++++++++++++++ FolderStructure.cpp | 17 +++++++++++++ FolderStructure.h | 16 ++++++++++++ GenerateKeys.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++--- GenerateKeys.h | 3 +-- Main.cpp | 6 ++++- MainWindow.cpp | 4 +++ MainWindow.h | 1 + encryptedstart.sh | 43 ++++++++++++++++++++++++++++++++ 9 files changed, 166 insertions(+), 7 deletions(-) create mode 100644 Conversions.cpp create mode 100644 FolderStructure.cpp create mode 100644 FolderStructure.h create mode 100755 encryptedstart.sh diff --git a/Conversions.cpp b/Conversions.cpp new file mode 100644 index 0000000..e703c63 --- /dev/null +++ b/Conversions.cpp @@ -0,0 +1,23 @@ +#include"Conversions.h" + +using std::string; +using std::stringstream; + +string Conversions::cstringToString(const char tmp[], const int size) +{ + string tmpString{}; + stringstream cToS{}; + for (auto index=0; index!=size; ++index) + cToS<> tmpString; + return tmpString; +} +char Conversions::stringToChar(const string& tmp) +{ + char tmpChar{}; + stringstream sToC{}; + for (auto tmpElements:tmp) + sToC << tmpElements; + sToC>>tmpChar; + return tmpChar; +} diff --git a/FolderStructure.cpp b/FolderStructure.cpp new file mode 100644 index 0000000..69a3644 --- /dev/null +++ b/FolderStructure.cpp @@ -0,0 +1,17 @@ +#include"FolderStructure.h" + +std::string FolderStructure::rootDirectory{}; +std::string FolderStructure::keyDirectory{}; +std::string FolderStructure::passwordDirectory{}; +std::string FolderStructure::settingDirectory{}; + +void FolderStructure::setupPaths(const char* rootPath) +{ + rootDirectory.assign(rootPath); + keyDirectory.assign(rootPath); + passwordDirectory.assign(rootPath); + settingDirectory.assign(rootPath); + keyDirectory.append("/keys/"); + passwordDirectory.append("/passwords/"); + settingDirectory.append("/settings/"); +} diff --git a/FolderStructure.h b/FolderStructure.h new file mode 100644 index 0000000..280437e --- /dev/null +++ b/FolderStructure.h @@ -0,0 +1,16 @@ +#ifndef FOLDERSTRUCTURE_H_ +#define FOLDERSTRUCTURE_H_ + +#include + +struct FolderStructure +{ + static std::string rootDirectory; + static std::string keyDirectory; + static std::string passwordDirectory; + static std::string settingDirectory; + + void setupPaths(const char*); +}; + +#endif diff --git a/GenerateKeys.cpp b/GenerateKeys.cpp index 8c2f6f9..c70bb87 100644 --- a/GenerateKeys.cpp +++ b/GenerateKeys.cpp @@ -1,11 +1,16 @@ #include +#include +#include #include #include #include +#include #include"GenerateKeys.h" +#include"FolderStructure.h" GenerateKeys::GenerateKeys() { + srand(time(0)); populateSymbols(); populateNumbers(); populateLetters(); @@ -14,8 +19,10 @@ GenerateKeys::GenerateKeys() addToCentralContainer(numbers); addToCentralContainer(letters); - populateDecryptedValues(); - populateEncryptedValues(); + generatedFileName(); + + //populateDecryptedValues(); + //populateEncryptedValues(); } void GenerateKeys::populateDecryptedValues() @@ -45,6 +52,51 @@ void GenerateKeys::populateEncryptedValues() readKeys.close(); } +void GenerateKeys::generatedFileName() +{ + time_t epochTime = time(0); + tm* currentTime = localtime(&epochTime); + + auto year = 1900+currentTime->tm_year; + auto month = 1+currentTime->tm_mon; + auto dayOfmonth = currentTime->tm_mday; + + if (month<10 && dayOfmonth<10) + { + defaultKeyFileName.assign(std::to_string(year)); + defaultKeyFileName.append("0"+std::to_string(month)); + defaultKeyFileName.append("0"+std::to_string(dayOfmonth)); + } + else if (month<10 && dayOfmonth>=10) + { + defaultKeyFileName.assign(std::to_string(year)); + defaultKeyFileName.append("0"+std::to_string(month)); + defaultKeyFileName.append(std::to_string(dayOfmonth)); + } + else if (month>=10 && dayOfmonth<10) + { + defaultKeyFileName.assign(std::to_string(year)); + defaultKeyFileName.append(std::to_string(month)); + defaultKeyFileName.append("0"+std::to_string(dayOfmonth)); + } + else + { + defaultKeyFileName.assign(std::to_string(year)); + defaultKeyFileName.append(std::to_string(month)); + defaultKeyFileName.append(std::to_string(dayOfmonth)); + } + for (auto index=0; index!=8; ++index) + { + if (index==0) defaultKeyFileName.append("_"); + else + { + auto randomInteger = rand()%10; + defaultKeyFileName.append(std::to_string(randomInteger)); + } + } + defaultKeyFileName.append(".txt"); + std::cout<&); - std::vector keys{}; std::vector symbols; std::vector numbers; diff --git a/Main.cpp b/Main.cpp index 85c0aba..31aabec 100644 --- a/Main.cpp +++ b/Main.cpp @@ -1,9 +1,13 @@ +#include +#include #include - #include"MainWindow.h" +#include"FolderStructure.h" int main(int argc, char* argv[]) { + FolderStructure fs; + fs.setupPaths(*(argv+1)); QApplication app(argc, argv); MainWindow stuff{}; diff --git a/MainWindow.cpp b/MainWindow.cpp index e55970a..318e987 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -1,3 +1,4 @@ +#include #include #include"MainWindow.h" #include"Encryption.h" @@ -41,6 +42,7 @@ void MainWindow::setupMainWindow() setWindowTitle("Encryption Decryption Messaging"); setFixedHeight(windowHeight); setFixedWidth(windowWidth); + actionButton.get()->setEnabled(false); connections(); } void MainWindow::createMenus() @@ -65,6 +67,7 @@ void MainWindow::connections() QObject::connect(closeApplication.get(), SIGNAL(triggered()), this, SLOT(exitApplication())); QObject::connect(keyEdit.get(), SIGNAL(triggered()), this, SLOT(keyManagementWindow())); QObject::connect(passwordManage.get(), SIGNAL(triggered()), this, SLOT(passwordManageWindow())); + QObject::connect(actionButton.get(), SIGNAL(clicked()), this, SLOT(test())); } @@ -107,3 +110,4 @@ std::string MainWindow::grabCryptionText() return placeHolder.toStdString(); } +void MainWindow::test() { std::cout<<"Action button Works"<