Merge pull request #3 from meisme-dev/main

Fixed a few typos and removed an unessecary if statement, among other things
This commit is contained in:
Zastian Pretorius
2021-10-24 04:14:16 +02:00
committed by GitHub

View File

@@ -15,7 +15,7 @@ class typeAndPaths{
public: public:
std::string type; std::string type;
std::string path; std::string path;
std::vector<std::string> extentions; std::vector<std::string> extensions;
}; };
//this is just a basic function that will create a basic settings.conf file if it does not exist (it is called by readSettings in the case settings.conf does not exist) //this is just a basic function that will create a basic settings.conf file if it does not exist (it is called by readSettings in the case settings.conf does not exist)
@@ -36,22 +36,22 @@ std::vector<std::string> readSettings()
{ {
fs::create_directory(home + "/.config/fsorter/"); fs::create_directory(home + "/.config/fsorter/");
} }
std::ifstream settings(settingsPath); std::ifstream settingsFile(settingsPath);
std::vector<std::string> listOfPaths; std::vector<std::string> listOfPaths;
std::string setting; std::string setting;
// creates a default settins file // creates a default settins file
if(!settings) if(!settingsFile)
{ {
writeSettins(); writeSettins();
} }
if(settings) if(settingsFile)
{ {
while(getline(settings, setting)) while(getline(settingsFile, setting))
{ {
listOfPaths.push_back(setting); listOfPaths.push_back(setting);
} }
} }
settings.close(); settingsFile.close();
return listOfPaths; return listOfPaths;
} }
@@ -65,13 +65,13 @@ std::vector<typeAndPaths> declarePaths(std::vector<std::string> listOfPaths)
listOfPaths[i].pop_back(); listOfPaths[i].pop_back();
Paths.type = listOfPaths[i]; Paths.type = listOfPaths[i];
Paths.path = listOfPaths[i+1]; Paths.path = listOfPaths[i+1];
std::string stringExtentions = listOfPaths[i+2]; std::string stringextensions = listOfPaths[i+2];
std::vector<std::string> extentions; std::vector<std::string> extensions;
char temp;
std::string tempWord; std::string tempWord;
int counter = 0; int counter = 0;
for (int i = 0; i < stringExtentions.size(); i++) { i = 0;
temp = stringExtentions[i]; while (i < stringextensions.size()) {
char temp = stringextensions[i];
if(temp != ',') if(temp != ',')
{ {
@@ -79,13 +79,15 @@ std::vector<typeAndPaths> declarePaths(std::vector<std::string> listOfPaths)
} }
else else
{ {
extentions.push_back(tempWord); extensions.push_back(tempWord);
tempWord = ""; tempWord = "";
counter++; counter++;
} }
i++;
} }
Paths.extentions = extentions; Paths.extensions = extensions;
paths.push_back(Paths); paths.push_back(Paths);
} }
return paths; return paths;
} }
@@ -96,31 +98,28 @@ void checkSettingsPaths(std::vector<typeAndPaths> Paths)
{ {
for (int i = 0; i < Paths.size(); i++) for (int i = 0; i < Paths.size(); i++)
{ {
if(fs::exists(Paths[i].path)) if(!fs::exists(Paths[i].path))
{
}
else
{ {
bool valid = false; bool valid = false;
while (!valid) { while (!valid) {
char awnser; char answer;
std::cout << "would you like to create y=yes, n=no : " << Paths[i].path << "\t"; std::cout << "Would you like to create (y/n) : " << Paths[i].path << "? \t";
std::cin >> awnser; std::cin >> answer;
std::cout << '\n'; std::cout << '\n';
if(tolower(awnser) == 'y') if(tolower(answer) == 'y')
{ {
fs::create_directory(Paths[i].path); fs::create_directory(Paths[i].path);
std::cout << "Directorry " << Paths[i].path << " was created\n"; std::cout << "Directory " << Paths[i].path << " was created.\n";
valid = true; valid = true;
} }
else if (tolower(awnser) == 'n') else if (tolower(answer) == 'n')
{ {
std::cout << "Directory" << Paths[i].path <<" was not created\n"; std::cout << "Directory" << Paths[i].path <<" was not created!\n";
valid = true; valid = true;
} }
else else
{ {
std::cout << "pleas provide valid awnser" << std::endl; std::cout << "Please provide a valid answer!" << std::endl;
} }
} }
} }
@@ -136,8 +135,8 @@ void sortPath(std::string path, std::vector<typeAndPaths> Paths)
if(file.path().has_extension()) if(file.path().has_extension())
{ {
for (int i = 0; i < Paths.size(); i++) { for (int i = 0; i < Paths.size(); i++) {
for (int x = 0; x < Paths[i].extentions.size(); x++) { for (int x = 0; x < Paths[i].extensions.size(); x++) {
if(Paths[i].extentions[x] == file.path().extension()) if(Paths[i].extensions[x] == file.path().extension())
{ {
std::cout << file.path().string() << std::endl; std::cout << file.path().string() << std::endl;
fs::rename(file.path().string(), Paths[i].path + file.path().filename().string()); fs::rename(file.path().string(), Paths[i].path + file.path().filename().string());