Added the feature of having a working application directory

This commit is contained in:
amazing-username
2017-08-06 21:24:09 -05:00
parent 4b7c0ea173
commit b83287b768
9 changed files with 166 additions and 7 deletions
+23
View File
@@ -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<<tmp[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;
}
+17
View File
@@ -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/");
}
+16
View File
@@ -0,0 +1,16 @@
#ifndef FOLDERSTRUCTURE_H_
#define FOLDERSTRUCTURE_H_
#include<string>
struct FolderStructure
{
static std::string rootDirectory;
static std::string keyDirectory;
static std::string passwordDirectory;
static std::string settingDirectory;
void setupPaths(const char*);
};
#endif
+56 -4
View File
@@ -1,11 +1,16 @@
#include<iostream> #include<iostream>
#include<cstdlib>
#include<ctime>
#include<sstream> #include<sstream>
#include<fstream> #include<fstream>
#include<ios> #include<ios>
#include<ctime>
#include"GenerateKeys.h" #include"GenerateKeys.h"
#include"FolderStructure.h"
GenerateKeys::GenerateKeys() GenerateKeys::GenerateKeys()
{ {
srand(time(0));
populateSymbols(); populateSymbols();
populateNumbers(); populateNumbers();
populateLetters(); populateLetters();
@@ -14,8 +19,10 @@ GenerateKeys::GenerateKeys()
addToCentralContainer(numbers); addToCentralContainer(numbers);
addToCentralContainer(letters); addToCentralContainer(letters);
populateDecryptedValues(); generatedFileName();
populateEncryptedValues();
//populateDecryptedValues();
//populateEncryptedValues();
} }
void GenerateKeys::populateDecryptedValues() void GenerateKeys::populateDecryptedValues()
@@ -45,6 +52,51 @@ void GenerateKeys::populateEncryptedValues()
readKeys.close(); 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<<defaultKeyFileName<<std::endl;
}
void GenerateKeys::populateSymbols() void GenerateKeys::populateSymbols()
{ {
addRange(symbols, 10, 10); addRange(symbols, 10, 10);
@@ -96,7 +148,6 @@ void GenerateKeys::keyMove()
{ {
std::string tmpKey{}; std::string tmpKey{};
generateKey(tmpKey, keySize); generateKey(tmpKey, keySize);
std::cout << "Generated Key: " << tmpKey << std::endl;
keys.push_back(tmpKey); keys.push_back(tmpKey);
} }
if (isThereRepetition()) if (isThereRepetition())
@@ -132,10 +183,11 @@ bool GenerateKeys::isThereRepetition()
void GenerateKeys::keyDump() void GenerateKeys::keyDump()
{ {
std::fstream dump{}; std::fstream dump{};
dump.open(defaultKeyFileName, std::ios::out); dump.open(FolderStructure::keyDirectory+defaultKeyFileName, std::ios::out);
for (auto index = 0u; index!=keys.size(); ++index) for (auto index = 0u; index!=keys.size(); ++index)
dump << keys[index] << '\n'; dump << keys[index] << '\n';
dump.close(); dump.close();
std::cout<<"dumped in: "<<FolderStructure::keyDirectory<<std::endl;
} }
+1 -2
View File
@@ -20,7 +20,7 @@ public:
friend class Decryption; friend class Decryption;
friend class KeyManagementWindow; friend class KeyManagementWindow;
private: private:
void generatedFileName();
void populateSymbols(); void populateSymbols();
void populateNumbers(); void populateNumbers();
void populateLetters(); void populateLetters();
@@ -33,7 +33,6 @@ private:
char getChar(std::vector<int>&); char getChar(std::vector<int>&);
std::vector<std::string> keys{}; std::vector<std::string> keys{};
std::vector<int> symbols; std::vector<int> symbols;
std::vector<int> numbers; std::vector<int> numbers;
+5 -1
View File
@@ -1,9 +1,13 @@
#include<iostream>
#include<string>
#include<QApplication> #include<QApplication>
#include"MainWindow.h" #include"MainWindow.h"
#include"FolderStructure.h"
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
FolderStructure fs;
fs.setupPaths(*(argv+1));
QApplication app(argc, argv); QApplication app(argc, argv);
MainWindow stuff{}; MainWindow stuff{};
+4
View File
@@ -1,3 +1,4 @@
#include<iostream>
#include<QString> #include<QString>
#include"MainWindow.h" #include"MainWindow.h"
#include"Encryption.h" #include"Encryption.h"
@@ -41,6 +42,7 @@ void MainWindow::setupMainWindow()
setWindowTitle("Encryption Decryption Messaging"); setWindowTitle("Encryption Decryption Messaging");
setFixedHeight(windowHeight); setFixedHeight(windowHeight);
setFixedWidth(windowWidth); setFixedWidth(windowWidth);
actionButton.get()->setEnabled(false);
connections(); connections();
} }
void MainWindow::createMenus() void MainWindow::createMenus()
@@ -65,6 +67,7 @@ void MainWindow::connections()
QObject::connect(closeApplication.get(), SIGNAL(triggered()), this, SLOT(exitApplication())); QObject::connect(closeApplication.get(), SIGNAL(triggered()), this, SLOT(exitApplication()));
QObject::connect(keyEdit.get(), SIGNAL(triggered()), this, SLOT(keyManagementWindow())); QObject::connect(keyEdit.get(), SIGNAL(triggered()), this, SLOT(keyManagementWindow()));
QObject::connect(passwordManage.get(), SIGNAL(triggered()), this, SLOT(passwordManageWindow())); 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(); return placeHolder.toStdString();
} }
void MainWindow::test() { std::cout<<"Action button Works"<<std::endl; }
+1
View File
@@ -32,6 +32,7 @@ private slots:
void keyManagementWindow(); void keyManagementWindow();
void passwordManageWindow(); void passwordManageWindow();
void exitApplication(); void exitApplication();
void test();
private: private:
void setupMainWindow(); void setupMainWindow();
void createMenus(); void createMenus();
+43
View File
@@ -0,0 +1,43 @@
user=`whoami`
userhome=$HOME
#echo $user
#echo $userhome
if [ -d $userhome/.config/PEM ]; then
echo "PEM directory exists"
else
echo "PEM directory does not exist"
mkdir $userhome/.config/PEM
fi
if [ -d $userhome/.config/PEM/keys ]; then
echo "Key directory exists"
else
echo Key directory does not exist
mkdir $userhome/.config/PEM/keys
fi
if [ -d $userhome/.config/PEM/passwords ]; then
echo "Password directory exists"
else
echo "Password directory does not exist"
mkdir $userhome/.config/PEM/passwords
fi
if [ -d $userhome/.config/PEM/settings ]; then
echo "Setting directory exists"
else
echo "Setting directory does not exist"
mkdir $userhome/.config/PEM/settings
fi
rootprojectdirectory=$userhome/.config/PEM
keydirectory=$rootprojectdirectory/keys
passworddirectory=$rootprojectdirectory/passwords
settingdirectory=$rootprojectdirectory/settings
#echo $rootprojectdirectory
#echo $keydirectory
#echo $passworddirectory
#echo $settingdirectory
echo ""
./encryptedmessaging $rootprojectdirectory