From 844bd870e0988dc5c34986fdd6b149b5f82bd509 Mon Sep 17 00:00:00 2001 From: Zastian Pretorius Date: Sat, 23 Oct 2021 00:36:08 +0200 Subject: [PATCH] make type, extentions and paths dynamic --- main.cpp | 101 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 72 insertions(+), 29 deletions(-) diff --git a/main.cpp b/main.cpp index 49a7c4e..974674b 100644 --- a/main.cpp +++ b/main.cpp @@ -4,24 +4,25 @@ #include //#include #include - +std::string musicTypes[] = {".mp3",".wav"}; +std::string pictureType[] = {".jpg","jpeg","png"}; namespace fs = std::filesystem; std::string settingsPath = "settings.conf"; -class paths{ +std::string home = getenv("HOME"); +class typeAndPaths{ public: - std::string Picturs; - std::string Music; - std::string Vidios; - std::string Arcives; + std::string type; + std::string path; + std::vector extentions; }; void writeSettins() { std::ofstream settings(settingsPath); - settings << "Picture=\n$HOME/Pictures" << std::endl; - settings << "Music=\n$HOME/Music" << std::endl; - settings << "Video=\n$HOME/Videos" << std::endl; - settings << "Arcive=\n$HOME/Documents/Compressed" << std::endl; + settings << "Picture=\n"+ home +"/Pictures\n.jpg,.jpeg,.png" << std::endl; + settings << "Music=\n"+home+"/Music\n.mp3,.wav" << std::endl; + settings << "Video=\n"+home+"/Videos\n.mp4" << std::endl; + settings << "Arcive=\n"+home+"/Documents/Compressed\n.zip,.rar,.7z" << std::endl; settings.close(); } @@ -42,39 +43,81 @@ std::vector readSettings() listOfPaths.push_back(setting); } } + settings.close(); return listOfPaths; } -paths declarePaths(std::vector listOfPaths) +std::vector declarePaths(std::vector listOfPaths) { - paths Paths; - for (int i = 0; i < listOfPaths.size(); i+=2) + typeAndPaths Paths; + std::vector paths; + for (int i = 0; i < listOfPaths.size(); i+=3) { listOfPaths[i].pop_back(); - std::string type = listOfPaths[i]; - std::string path = listOfPaths[i+1]; - if(type == "Picture") - { - Paths.Picturs = path; + Paths.type = listOfPaths[i]; + Paths.path = listOfPaths[i+1]; + std::string stringExtentions = listOfPaths[i+2]; + std::vector extentions; + char temp; + std::string tempWord; + int counter = 0; + for (int i = 0; i < stringExtentions.size(); i++) { + temp = stringExtentions[i]; + if(temp != ',') + { + + tempWord.push_back(temp); + } + else + { + extentions.push_back(tempWord); + tempWord = ""; + counter++; + } } - else if (type == "Music") + Paths.extentions = extentions; + paths.push_back(Paths); + } + return paths; +} +void checkSettingsPaths(std::vector Paths) +{ + for (int i = 0; i < Paths.size(); i++) + { + if(fs::exists(Paths[i].path)) { - Paths.Music = path; + std::cout << "Yes\n"; } - else if (type == "Video") + else { - Paths.Vidios = path; - } - else if (type == "Arcive") - { - Paths.Arcives = path; + bool valid = false; + while (!valid) { + char awnser; + std::cout << "would you like to create y=yes, n=no : " << Paths[i].path << "\t"; + std::cin >> awnser; + std::cout << '\n'; + if(tolower(awnser) == 'y') + { + fs::create_directory(Paths[i].path); + valid = true; + } + else if (tolower(awnser) == 'n') + { + std::cout << "Directory was not created\n"; + valid = true; + } + else + { + std::cout << "pleas provide valid awnser" << std::endl; + } + } } } - return Paths; } + int main() { std::vector listOfPaths = readSettings(); - paths Paths = declarePaths(listOfPaths); - std::cout << Paths.Picturs << std::endl; + std::vector Paths = declarePaths(listOfPaths); + checkSettingsPaths(Paths); return 0; }