Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Total number of coded lines: 1349
- /*This source code is compatible with my Source Code Collector Program, which can automatically parse and separate this text file into all of the header/cpp files necessary to create and compile the project. The program can be found at:
- http://sourceforge.net/projects/selectivedataba/files/Source%20Code%20Text%20Collector.exe/download
- */
- \\common.cpp begin==================================================================
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <conio.h>
- #include <windows.h>
- #include "common.h"
- using namespace std;
- void cls()
- {
- system("CLS");
- }
- void cl()
- {
- Sleep(5);
- while(_kbhit()) _getch();
- }
- void wait()
- {
- cout<< endl<< endl<< endl<< endl;
- cout<< "Press any key to continue..."<< endl;
- cl();
- if(_getch())
- {
- }
- cl();
- }
- char gkey()
- {
- char ch;
- cl();
- ch = _getch();
- cl();
- if(is_letter(ch) == true)
- {
- if(isupper(ch) == true)
- {
- ch = tolower(ch);
- }
- }
- return ch;
- }
- string letters()
- {
- return "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
- }
- string specials()
- {
- return "`~!@#$%^&*()-_=+[{]}\\|;:\"\',<.>/? ";
- }
- string numbers()
- {
- return "1234567890";
- }
- bool char_match(char ch, string s = "")
- {
- for(unsigned int x = 0; x < s.size(); x++)
- {
- if(s[x] == ch)
- {
- s.clear();
- return true;
- }
- }
- s.clear();
- return false;
- }
- bool is_special(char ch)
- {
- return char_match(ch, specials());
- }
- bool is_letter(char ch)
- {
- return char_match(ch, letters());
- }
- bool is_number(char ch)
- {
- return char_match(ch, numbers());
- }
- bool is_sure(string message)
- {
- int x = 0;
- char ch;
- while(x == 0)
- {
- cls();
- cout<< message<< endl<< endl;
- cout<< " Y/N"<< endl;
- ch = gkey();
- if(ch == 'y')
- {
- return true;
- }
- if(ch == 'n')
- {
- return false;
- }
- }
- return false;
- }
- bool string_is_number(string s)
- {
- if(s.size() == 0)
- {
- return false;
- }
- for(unsigned int x = 0; x < s.size(); x++)
- {
- if(is_number(s[x]) == false)
- {
- s.clear();
- return false;
- }
- }
- s.clear();
- return true;
- }
- int conv_str(string s)
- {
- stringstream ss;
- int x = 0;
- ss.clear();
- ss<< s;
- ss>> x;
- return x;
- }
- string conv_int(int x)
- {
- stringstream ss;
- ss.clear();
- ss<< x;
- return ss.str();
- }
- bool str_match(string s1, string s2)
- {
- string temps = "";
- for(unsigned int x = 0; x < s2.size(); x++)
- {
- temps.clear();
- for(unsigned int y = x; y < (x + s1.size()); y++)
- {
- if(y < s2.size())
- {
- temps = (temps + s2[y]);
- }
- }
- if(temps == s1)
- {
- temps.clear();
- s1.clear();
- return true;
- }
- }
- return false;
- }
- bool is_header_or_cpp(string name = "")
- {
- if(name == "")
- {
- return false;
- }
- vector<string> extensions = {
- ".h",
- ".cpp"
- };
- bool dotmet = false;
- string ext, fname;
- ext.clear();
- fname.clear();
- for(unsigned int x = 0; x < name.size(); x++)
- {
- if(name[x] == '.')
- {
- dotmet = true;
- }
- if(dotmet == false)
- {
- fname = (fname + name[x]);
- }
- if(dotmet == true)
- {
- ext = (ext + name[x]);
- }
- }
- if(dotmet == false)
- {
- return false;
- }
- for(unsigned int x = 0; x < fname.size(); x++)
- {
- if(fname[x] == '\\')
- {
- return false;
- }
- }
- for(unsigned int x = 0; x < ext.size(); x++)
- {
- if(ext[x] == '\\')
- {
- return false;
- }
- }
- dotmet = false;
- for(unsigned int x = 0; x < extensions.size(); x++)
- {
- if(ext == extensions[x])
- {
- dotmet = true;
- }
- }
- if(dotmet == true)
- {
- return true;
- }
- return false;
- }
- //checks if it qualifies as a headerfooter
- bool line_is_headerfooter(string line)
- {
- if(line.size() == 0)
- {
- return false;
- }
- string name = "";
- bool dotmet = false;
- if(line.size() > 2)
- {
- if((line[0] == '\\') && (line[1] == '\\'))
- {
- if(line.size() > 2)
- {
- for(unsigned int x = 2; x < line.size(); x++)
- {
- if(line[x] == '.')
- {
- dotmet = true;
- }
- if((line[x] == ' ') && (dotmet == true))
- {
- break;
- }
- if((is_letter(line[x]) == true) || (line[x] == '.'))
- {
- name.push_back(line[x]);
- }
- }
- dotmet = false;
- if(is_header_or_cpp(name) == false)
- {
- return false;
- }
- if((str_match(" begin==================================================================", line) == false) && (str_match(" END==================================================================", line) == false))
- {
- return false;
- }
- return true;
- }
- }
- }
- return false;
- }
- //returns the filename associated with the headerfooter
- string get_headerfooter_name(string line)
- {
- if(line_is_headerfooter(line) == false)
- {
- return "ERROR";
- }
- bool dotmet = false;
- string name = "";
- for(unsigned int x = 2; x < line.size(); x++)
- {
- if((line[x] == ' ') && (dotmet == true))
- {
- break;
- }
- if(line[x] == '.')
- {
- dotmet = true;
- }
- name = (name + line[x]);
- }
- return name;
- }
- \\common.cpp END==================================================================
- \\common.h begin==================================================================
- #ifndef COMMON_H_INCLUDED
- #define COMMON_H_INCLUDED
- #include <string>
- #include <vector>
- using namespace std;
- void cls();
- void cl();
- void wait();
- char gkey();
- bool is_special(char ch = char());
- bool is_letter(char ch = char());
- bool is_number(char ch = char());
- bool is_sure(string message = "Are you sure?");
- bool string_is_number(string s = "");
- int conv_str(string s = "");
- string conv_int(int x = 0);
- bool line_is_headerfooter(string line = "");
- bool str_match(string s1 = "", string s2 = "");
- string get_headerfooter_name(string line = "");
- #endif // COMMON_H_INCLUDED
- \\common.h END==================================================================
- \\directory_mod.cpp begin==================================================================
- #include <iostream>
- #include "fsys.h"
- #include "common.h"
- #include "pdata.h"
- #include <string>
- #include <fstream>
- #include <vector>
- #include "load.h"
- using namespace std;
- /*Options should include:
- - Target directory (where to save the text files)
- */
- string remove_extension(string name = "")
- {
- string newname = "";
- for(unsigned int x = 0; x < name.size(); x++)
- {
- if(name[x] == '.')
- {
- break;
- }
- newname = (newname + name[x]);
- }
- return newname;
- }
- void unpack_project(const pdata& dat)
- {
- string temps = "", line, file_chosen;
- bool fbegin = false;
- file_chosen = choose_file_to_unpack(dat.options.txt_file_directory);
- temps = file_chosen;
- if(temps == "xcancel")
- {
- return;
- }
- if(is_file(file_chosen) == false)
- {
- cls();
- cout<< "ERROR: File \""<< file_chosen<< "\" could not be located!"<< endl;
- wait();
- return;
- }
- ifstream in;
- ofstream out;
- vector<string> file = vector<string>();
- vector<file_data> vfiles = vector<file_data>();
- in.open(temps.c_str(), ios::in);
- while(in.good())
- {
- getline(in, line);
- file.push_back(line);
- }
- in.close();
- vfiles.clear();
- for(unsigned int x = 0; x < file.size(); x++)
- {
- if((line_is_headerfooter(file[x]) == true) && (fbegin == false))
- {
- fbegin = true;
- vfiles.push_back(file_data());
- vfiles[(vfiles.size() - 1)].name = get_headerfooter_name(file[x]);
- x++; //skiping the implied balnk line
- continue; //and going to the next one.
- }
- if(fbegin == true)
- {
- //check if it's a header, if not, then keep going
- if(line_is_headerfooter(file[x]) == true)
- {
- temps.clear();
- fbegin = false;
- continue;
- }
- if(line_is_headerfooter(file[x]) == false)
- {
- vfiles[(vfiles.size() - 1)].text.push_back(file[x]);
- }
- }
- }
- //now we have a vector of the files represented by each instance of file_data in vector vfiles.
- //lets now create the project folder.
- create_folder(remove_extension(file_chosen));
- /*if the user decides not to over-write and existing folder,
- we should not write to it, because it may contain stuff.*/
- if(is_folder(remove_extension(file_chosen)) == false)
- {
- cls();
- cout<< "ERROR: Folder could not be found."<< endl;
- wait();
- return;
- }
- //now we are ready to start creating the .cpp and .h file!!! YAY
- file_chosen = remove_extension(file_chosen);
- if(is_folder(file_chosen) == true)
- {
- temps.clear();
- for(unsigned int x = 0; x < vfiles.size(); x++)
- {
- //construct directory to the new file
- temps = (file_chosen + "\\" + vfiles[x].name);
- out.open(temps.c_str(), ios::out);
- for(unsigned int y = 0; y < vfiles[x].text.size(); y++)
- {
- out<< vfiles[x].text[y];
- if(y < (vfiles[x].text.size() - 1))
- {
- out<< endl;
- }
- }
- out.close();
- }
- }
- cls();
- cout<< "Project successfully reconstructed!"<< endl;
- wait();
- }
- vector<string> add_file_to_vector(file_data file, vector<string> text = vector<string>())
- {
- text.push_back("");
- text.push_back("\\\\");
- text[(text.size() - 1)] = (text[(text.size() - 1)] + file.name + " begin==================================================================");
- text.push_back("");
- for(unsigned int x = 0; x < file.text.size(); x++)
- {
- text.push_back(file.text[x]);
- }
- text.push_back("");
- text.push_back("\\\\");
- text[(text.size() - 1)] = (text[(text.size() - 1)] + file.name + " END==================================================================");
- return text;
- }
- bool project_has_text(vector<file_data> files)
- {
- int number_of_lines = 0;
- for(unsigned int x = 0; x < files.size(); x++)
- {
- for(unsigned int y = 0; y < files[x].text.size(); y++)
- {
- if(files[x].text[y] > "")
- {
- number_of_lines++;
- }
- }
- }
- if(number_of_lines == 0)
- {
- return false;
- }
- if(number_of_lines > 0)
- {
- return true;
- }
- return false;
- }
- int total_number_of_coded_lines(vector<string> f)
- {
- if(f.size() == 0)
- {
- return 0;
- }
- int number_of_lines = 0;
- for(unsigned int x = 0; x < f.size(); x++)
- {
- if(f[x] > "")
- {
- number_of_lines++;
- }
- }
- return number_of_lines;
- }
- /*CreateSourceText:
- Return values-
- 1: invalid id
- 2: folder does not exist
- 3: No text
- 0: fine*/
- int CreateSourceText(const pdata& dat, int id = -1)
- {
- if((unsigned(id) > (dat.projects.size() - 1)) || (id < 0))
- {
- return 1;
- }
- if(is_folder(dat.options.txt_file_directory) == false)
- {
- return 2;
- }
- if(project_has_text(dat.projects[id].files) == false)
- {
- return 3;
- }
- cls();
- cout<< "Creating text file. Please be patient."<< endl;
- vector<string> file_text;
- string savename = "";
- savename = (dat.options.txt_file_directory + "\\" + dat.projects[id].name + ".txt");
- ofstream out;
- file_text.clear();
- for(unsigned int x = 0; x < dat.projects[id].files.size(); x++)
- {
- file_text = add_file_to_vector(dat.projects[id].files[x], file_text);
- }
- out.open(savename.c_str(), ios::out);
- out<< "Total number of coded lines: "<< total_number_of_coded_lines(file_text)<< endl;
- for(unsigned int x = 0; x < file_text.size(); x++)
- {
- out<< file_text[x];
- if(x < (file_text.size() - 1))
- {
- out<< endl;
- }
- }
- out.close();
- file_text.clear();
- savename.clear();
- cls();
- cout<< "Text file completed."<< endl;
- wait();
- return 0;
- }
- bool directory_already_added(const pdata& dat, string dir = "")
- {
- if(dat.projects.size() == 0)
- {
- return false;
- }
- for(unsigned int x = 0; x < dat.projects.size(); x++)
- {
- if(dat.projects[x].directory == dir)
- {
- return true;
- }
- }
- return false;
- }
- /*dirtarg: 0, project directories; 1, target directory; 2 modify existing*/
- string modify_directory(const pdata& dat, int dirtarg = 0)
- {
- string newdir = "";
- while(newdir == "")
- {
- cls();
- cout<< "Enter 'X' to cancel"<< endl;
- if(dirtarg == 2)
- {
- cout<< "Enter 'D' to delete"<< endl;
- }
- cout<< endl<< endl<< endl;
- if(dirtarg == 0)
- {
- cout<< "New Directory: ";
- }
- if(dirtarg == 1)
- {
- cout<< "Target Directory: ";
- }
- if(dirtarg == 2)
- {
- cout<< "Directory: ";
- }
- cout.flush();
- getline(cin, newdir);
- if(newdir.size() == 1)
- {
- if(tolower(newdir[0]) == 'x')
- {
- return "xcancel";
- }
- if(dirtarg == 2)
- {
- if(tolower(newdir[0]) == 'd')
- {
- return "deletedir";
- }
- }
- }
- if((dirtarg == 0) || (dirtarg == 2))
- {
- if(directory_already_added(dat, newdir) == true)
- {
- newdir.clear();
- cls();
- cout<< "That directory is already in the list!"<< endl;
- wait();
- cls();
- continue;
- }
- }
- if(is_folder(newdir) == false)
- {
- if(dirtarg == 1)
- {
- newdir = get_current_directory();
- return newdir;
- }
- cls();
- cout<< "That is an invalid folder name!"<< endl;
- wait();
- newdir.clear();
- continue;
- }
- if((dirtarg == 1) || (dirtarg == 2))
- {
- if(folder_empty(newdir) == false)
- {
- if(is_sure("WARNING: That directory contains files that may be over-written! I recommend you choose an empty directory!\n\n\n Do you really want to use this directory?") == true)
- {
- return newdir;
- }
- newdir.clear();
- }
- }
- }
- if(is_folder(newdir) == true)
- {
- return newdir;
- }
- return "xcancel";
- }
- void delete_project(vector<project_data>& projects, int id = -1)
- {
- if((unsigned(id) > (projects.size() - 1)) || (id < 0))
- {
- return;
- }
- vector<project_data> temp;
- temp = projects;
- projects.clear();
- for(unsigned int x = 0; x < temp.size(); x++)
- {
- if(signed(x) != id)
- {
- projects.push_back(temp[x]);
- }
- }
- temp.clear();
- }
- void mod_or_create(pdata& dat, int mod = 0, int project_number = -1, string name = "")
- {
- int x = 0, sourcetxt = 0;
- char ch;
- string temps;
- bool sure = false;
- if(project_number == -1)
- {
- temps = modify_directory(dat, mod);
- if(temps != "xcancel")
- {
- dat.projects.push_back(project_data());
- dat.projects[(dat.projects.size() - 1)].directory = temps;
- load_project_data(dat.projects[(dat.projects.size() - 1)]);
- }
- return;
- }
- while(x == 0)
- {
- temps.clear();
- cls();
- cout<< " \""<< name<< "\" -- Choose:"<< endl<< endl<< endl<< endl;
- cout<< " 1 - Modify This Directory"<< endl;
- cout<< " 2 - Construct a Project Text File"<< endl;
- cout<< " q - Done"<< endl;
- ch = gkey();
- if(ch == '1')
- {
- temps = modify_directory(dat, mod);
- if(temps == "deletedir")
- {
- sure = is_sure("Are you absolutely sure you want to delete this project?");
- if(sure == true)
- {
- delete_project(dat.projects, project_number);
- }
- if(sure == false)
- {
- continue;
- }
- return;
- }
- if((temps != "xcancel") && (temps != "deletedir"))
- {
- dat.projects[project_number].directory = temps;
- dat.projects[project_number].name.clear();
- dat.projects[project_number].files.clear();
- load_project_data(dat.projects[project_number]);
- }
- return;
- }
- if(ch == '2')
- {
- sourcetxt = CreateSourceText(dat, project_number);
- if(sourcetxt == 1)
- {
- cls();
- cout<< "ERROR: FUNCTION::int CreateSourceText(const pdata& dat, int id = -1) \"INVALID ID!\""<< endl;
- wait();
- }
- if(sourcetxt == 2)
- {
- cls();
- cout<< "ERROR: Invalid Folder path!"<< endl;
- wait();
- }
- if(sourcetxt == 3)
- {
- cls();
- cout<< "Nothing was created because there was no text."<< endl;
- wait();
- }
- continue;
- }
- if(ch == 'q')
- {
- return ;
- }
- }
- }
- void modify_user_project_directories(pdata& dat)
- {
- int x = 0, choice = 0;
- string s_choice = "", temps = "";
- while(x == 0)
- {
- s_choice.clear();
- choice = 0;
- cls();
- cout<< " Projects"<< endl<< endl<< endl<< endl;
- for(unsigned int y = 0; y < dat.projects.size(); y++)
- {
- cout<< " "<< (y + 1)<< " - "<< folder_name(dat.projects[y].directory)<< endl;
- }
- cout<< endl<< endl;
- cout<< " a - Add new directory"<< endl;
- cout<< " w - Target Directory: "<< dat.options.txt_file_directory<< endl;
- cout<< endl;
- cout<< " s - Unpack a Text file project (must have been made by this program)"<< endl;
- cout<< " q - Exit"<< endl;
- cout.flush();
- getline(cin, s_choice);
- if(string_is_number(s_choice) == true)
- {
- if(s_choice.size() < 11)
- {
- choice = conv_str(s_choice);
- if((unsigned(choice) <= dat.projects.size()) && (choice > 0))
- {
- choice--;
- mod_or_create(dat, 2, choice, dat.projects[choice].name);
- }
- }
- }
- if(string_is_number(s_choice) == false)
- {
- if(s_choice.size() == 1)
- {
- s_choice[0] = tolower(s_choice[0]);
- if(s_choice[0] == 'w')
- {
- temps = modify_directory(dat, 1);
- if(temps != "xcancel")
- {
- dat.options.txt_file_directory = temps;
- }
- }
- if(s_choice[0] == 's')
- {
- unpack_project(dat);
- }
- if(s_choice[0] == 'a')
- {
- temps = modify_directory(dat);
- if(temps != "xcancel")
- {
- dat.projects.push_back(project_data());
- dat.projects[(dat.projects.size() - 1)].directory = temps;
- load_project_data(dat.projects[(dat.projects.size() - 1)]);
- save_everything(dat);
- }
- }
- if(s_choice[0] == 'q')
- {
- save_everything(dat);
- return;
- }
- }
- }
- }
- }
- \\directory_mod.cpp END==================================================================
- \\directory_mod.h begin==================================================================
- #ifndef DIRECTORY_MOD_H_INCLUDED
- #define DIRECTORY_MOD_H_INCLUDED
- #include <string>
- #include <vector>
- #include "pdata.h"
- using namespace std;
- void modify_user_project_directories(pdata& dat);
- #endif // DIRECTORY_MOD_H_INCLUDED
- \\directory_mod.h END==================================================================
- \\fsys.cpp begin==================================================================
- #include <iostream>
- #include <string>
- #include <vector>
- #include "common.h"
- #include <boost/filesystem.hpp>
- #include "fsys.h"
- using namespace std;
- bool is_file(string s)
- {
- boost::filesystem::path p;
- p = s;
- if(boost::filesystem::is_regular_file(p) == true)
- {
- s.clear();
- p.clear();
- return true;
- }
- s.clear();
- p.clear();
- return false;
- }
- bool is_folder(string s)
- {
- boost::filesystem::path p;
- p = s;
- if(boost::filesystem::is_directory(p) == true)
- {
- s.clear();
- p.clear();
- return true;
- }
- s.clear();
- p.clear();
- return false;
- }
- bool data_there(string f)
- {
- if(is_file(f) == false)
- {
- return false;
- }
- ifstream in;
- string line;
- int number_of_lines = 0;
- in.open(f.c_str(), ios::in);
- while(in.good())
- {
- getline(in, line);
- if(line > "")
- {
- number_of_lines++;
- }
- }
- in.close();
- if(number_of_lines == 0)
- {
- return false;
- }
- if(number_of_lines > 0)
- {
- return true;
- }
- return false;
- }
- string get_current_directory()
- {
- boost::filesystem::path p;
- p.clear();
- p = boost::filesystem::current_path();
- p = (p.string() + "\\");
- return p.string();
- }
- string file_name(string path)
- {
- if(is_file(path) == false)
- {
- return "ERROR";
- }
- boost::filesystem::path p;
- p = path;
- return p.filename().string();
- }
- string folder_name(string folder)
- {
- if(is_folder(folder) == false)
- {
- return "ERROR";
- }
- boost::filesystem::path p;
- p = folder;
- return p.filename().string();
- }
- bool folder_empty(string f)
- {
- boost::filesystem::path p;
- if(is_folder(f) == false)
- {
- return true;
- }
- p = f;
- vector<boost::filesystem::directory_entry> directories = vector<boost::filesystem::directory_entry>();
- copy(boost::filesystem::directory_iterator(p), boost::filesystem::directory_iterator(), back_inserter(directories));
- if(directories.size() > 0)
- {
- directories.clear();
- return false;
- }
- if(directories.size() == 0)
- {
- directories.clear();
- return true;
- }
- return true;
- }
- string extension(string name = "")
- {
- bool dotmet = false;
- string ext = "";
- for(unsigned int x = 0; x < name.size(); x++)
- {
- if(name[x] == '.')
- {
- dotmet = true;
- }
- if(dotmet == true)
- {
- ext = (ext + name[x]);
- }
- }
- return ext;
- }
- //creates a menu to choose the text file you want to "unpack"
- //returns the entire directory
- string choose_file_to_unpack(string folder)
- {
- if(is_folder(folder) == false)
- {
- return "xcancel";
- }
- boost::filesystem::path p;
- p = folder;
- vector<boost::filesystem::directory_entry> directories = vector<boost::filesystem::directory_entry>(), fils = vector<boost::filesystem::directory_entry>();
- copy(boost::filesystem::directory_iterator(p), boost::filesystem::directory_iterator(), back_inserter(directories));
- if(directories.size() == 0)
- {
- cls();
- cout<< "I could not find anything!"<< endl;
- wait();
- return "xcancel";
- }
- //filtering out everything but text files
- for(unsigned int x = 0; x < directories.size(); x++)
- {
- if(is_file(directories[x].path().string()) == true)
- {
- if(extension(directories[x].path().filename().string()) == ".txt")
- {
- fils.push_back(directories[x]);
- }
- }
- }
- directories = fils;
- fils.clear();
- int x = 0, choice;
- string s_choice;
- while(x == 0)
- {
- s_choice.clear();
- choice = 0;
- cls();
- cout<< " \"Unpack\" a text-compiled Source code"<< endl;
- cout<< "These are the text files I found in your target directory:";
- cout<< endl<< endl<< endl<< endl;
- for(unsigned int y = 0; y < directories.size(); y++)
- {
- cout<< " "<< (y + 1)<< " - "<< directories[y].path().filename().string()<< endl;
- }
- cout<< endl<< endl;
- cout<< " x - Cancel"<< endl;
- cout.flush();
- getline(cin, s_choice);
- if(string_is_number(s_choice) == true)
- {
- if(s_choice.size() < 11)
- {
- choice = conv_str(s_choice);
- if((choice > 0) && (unsigned(choice) <= directories.size()))
- {
- choice--;
- return directories[choice].path().string();
- }
- }
- }
- if(string_is_number(s_choice) == false)
- {
- if(s_choice.size() == 1)
- {
- s_choice[0] = tolower(s_choice[0]);
- if(s_choice[0] == 'x')
- {
- return "xcancel";
- }
- }
- }
- }
- return "xcancel";
- }
- //This is now universal. This is for special operations where a folder needs to be created, and a file/folder-system is created within it.
- void create_folder(string name)
- {
- boost::filesystem::path p;
- p = name;
- if(boost::filesystem::is_directory(p) == true)
- {
- name.clear();
- name = ("There is already a directory named \"" + p.string() + "\"! Are you sure you want to over-write it? (all contents in the folder will be deleted!)");
- if(is_sure(name) == false)
- {
- return;
- }
- boost::filesystem::remove_all(p);
- }
- boost::filesystem::create_directories(p);
- }
- \\fsys.cpp END==================================================================
- \\fsys.h begin==================================================================
- #ifndef FSYS_H_INCLUDED
- #define FSYS_H_INCLUDED
- #include <string>
- #include <vector>
- using namespace std;
- bool is_file(string s = "");
- bool is_folder(string s = "");
- string get_current_directory();
- string file_name(string path = "");
- string folder_name(string folder = "");
- bool folder_empty(string f = "");
- bool data_there(string f = "");
- string choose_file_to_unpack(string folder = "");
- void create_folder(string name = "");
- #endif // FSYS_H_INCLUDED
- \\fsys.h END==================================================================
- \\load.cpp begin==================================================================
- #include <iostream>
- #include <fstream>
- #include <boost/filesystem.hpp>
- #include <string>
- #include <vector>
- #include "pdata.h"
- #include "load.h"
- #include "fsys.h"
- using namespace std;
- string get_ext(string f = "")
- {
- string temps = "";
- //reverse the string
- for(unsigned int x = (f.size() - 1); x >= 0; x--)
- {
- temps = (temps + f[x]);
- if(x == 0)
- {
- break;
- }
- }
- f = temps;
- temps.clear();
- /*Adding each character until we hit "."*/
- for(unsigned int x = 0; x < f.size(); x++)
- {
- temps = (temps + f[x]);
- if(f[x] == '.')
- {
- break;
- }
- }
- //now we got an extention, lets re-reverse it back to normal
- f = temps;
- temps.clear();
- for(unsigned int x = (f.size() - 1); x >= 0; x--)
- {
- temps = (temps + f[x]);
- if(x == 0)
- {
- break;
- }
- }
- f = temps;
- temps.clear();
- /*So, now we got a file extension.*/
- return f;
- }
- string file_extension(string fullpath)
- {
- boost::filesystem::path p;
- p = fullpath;
- if(boost::filesystem::is_regular_file(p) == false)
- {
- fullpath.clear();
- return "";
- }
- return get_ext(p.filename().string());
- }
- void create_program_folders(const pdata& dat)
- {
- boost::filesystem::path p;
- p.clear();
- p = (p.string() + dat.curdir + dat.project_saves_folder_name);
- if(boost::filesystem::is_directory(p) == false)
- {
- boost::filesystem::create_directory(p);
- }
- p.clear();
- }
- bool is_project_extension(string ext = "")
- {
- /*This is so that I can easily add new extensions if I need to.*/
- vector<string> extensions = {
- ".cpp",
- ".h"
- };
- if(ext == "")
- {
- return false;
- }
- for(unsigned int x = 0; x < extensions.size(); x++)
- {
- if(ext == extensions[x])
- {
- ext.clear();
- extensions.clear();
- return true;
- }
- }
- ext.clear();
- extensions.clear();
- return false;
- }
- void load_file(file_data& filex, string directory = "")
- {
- if(is_file(directory) == false)
- {
- return;
- }
- boost::filesystem::path p;
- p = directory;
- ifstream in;
- string line;
- filex.text.clear();
- in.open(directory.c_str(), ios::in);
- while(in.good())
- {
- getline(in, line);
- filex.text.push_back(line);
- }
- in.close();
- filex.name = p.filename().string();
- line.clear();
- directory.clear();
- p.clear();
- }
- /*Loads a project based on the directory it is located.*/
- void load_project_data(project_data& project)
- {
- project.files.clear();
- if(is_folder(project.directory) == false)
- {
- project.directory = "ERROR: NO_ID";
- return;
- }
- boost::filesystem::path p;
- p = project.directory;
- project.name = p.filename().string();
- vector<boost::filesystem::directory_entry> directories = vector<boost::filesystem::directory_entry>();
- copy(boost::filesystem::directory_iterator(p), boost::filesystem::directory_iterator(), back_inserter(directories));
- for(unsigned int x = 0; x < directories.size(); x++)
- {
- //if it is a project extension (contains code)
- if(is_project_extension(file_extension(directories[x].path().string())) == true)
- {
- //add a clean new data structure to the vector
- project.files.push_back(file_data());
- //load the data into it
- load_file(project.files[(project.files.size() - 1)], directories[x].path().string());
- }
- }
- p.clear();
- directories.clear();
- }
- void load_project_saves(pdata& dat)
- {
- dat.projects.clear();
- ifstream in;
- string line, save_file_path;
- save_file_path = (dat.curdir + dat.project_saves_folder_name + "\\" + dat.projects_file_name);
- if(is_file(save_file_path) == false)
- {
- return;
- }
- in.open(save_file_path.c_str(), ios::in);
- while(in.good())
- {
- getline(in, line);
- if(is_folder(line) == false)
- {
- continue;
- }
- dat.projects.push_back(project_data());
- dat.projects[(dat.projects.size() - 1)].directory = line;
- }
- in.close();
- /*I chose to load outside of the while loop to
- minimize the ammount of time the file is open.*/
- for(unsigned int x = 0; x < dat.projects.size(); x++)
- {
- //loading up all of the projects now.
- load_project_data(dat.projects[x]);
- }
- line.clear();
- save_file_path.clear();
- }
- void load_options(pdata& dat)
- {
- string options_file;
- options_file = (dat.curdir + dat.project_saves_folder_name + "\\Options for YoU.jon");
- if((is_file(options_file) == false) || (data_there(options_file) == false))
- {
- return;
- }
- dat.options.txt_file_directory.clear();
- ifstream in;
- string line;
- vector<string> f = vector<string>();
- in.open(options_file.c_str(), ios::in);
- while(in.good())
- {
- getline(in, line);
- f.push_back(line);
- }
- in.close();
- if(f.size() == 0)
- {
- return;
- }
- if(f.size() >= 1)
- {
- dat.options.txt_file_directory = f[0];
- }
- f.clear();
- line.clear();
- }
- void load_everything(pdata& dat)
- {
- cout.flush();
- create_program_folders(dat);
- //load all the projects
- load_project_saves(dat);
- //loading options
- load_options(dat);
- }
- void save_everything(const pdata& dat)
- {
- create_program_folders(dat);
- string projects_file = "", options_file = "";
- ofstream out;
- projects_file = (dat.curdir + dat.project_saves_folder_name + "\\" + dat.projects_file_name);
- options_file = (dat.curdir + dat.project_saves_folder_name + "\\" + dat.options_file_name);
- out.open(projects_file.c_str(), ios::out);
- for(unsigned int x = 0; x < dat.projects.size(); x++)
- {
- out<< dat.projects[x].directory;
- if(x < (dat.projects.size() - 1))
- {
- out<< endl;
- }
- }
- out.close();
- out.open(options_file.c_str(), ios::out);
- out<< dat.options.txt_file_directory;
- out.close();
- cout.flush();
- }
- \\load.cpp END==================================================================
- \\load.h begin==================================================================
- #ifndef LOAD_H_INCLUDED
- #define LOAD_H_INCLUDED
- #include <string>
- #include <vector>
- #include "pdata.h"
- using namespace std;
- string file_extension(string fullpath = "");
- void load_project_data(project_data& project);
- void load_everything(pdata& dat);
- void save_everything(const pdata& dat);
- #endif // LOAD_H_INCLUDED
- \\load.h END==================================================================
- \\main.cpp begin==================================================================
- #include <iostream>
- #include "load.h"
- #include "pdata.h"
- #include "directory_mod.h"
- using namespace std;
- int main()
- {
- pdata dat;
- load_everything(dat);
- modify_user_project_directories(dat);
- return 0;
- }
- \\main.cpp END==================================================================
- \\pdata.h begin==================================================================
- #ifndef PDATA_H_INCLUDED
- #define PDATA_H_INCLUDED
- #include <string>
- #include <vector>
- #include "fsys.h"
- using namespace std;
- struct file_data{
- string name = "No_Name";
- vector<string> text = vector<string>();
- };
- struct project_data{
- vector<file_data> files = vector<file_data>();
- string directory = "";
- string name = "No Name";
- };
- struct options_data{
- string txt_file_directory = get_current_directory();
- };
- struct pdata{
- //includes the terminating slash.
- string curdir = get_current_directory();
- //For easy modification in case of conflictions
- string project_saves_folder_name = "Saved Projects";
- string projects_file_name = "Project Directories.jon";
- string options_file_name = "Options for YoU.jon";
- //projects
- vector<project_data> projects = vector<project_data>();
- //options
- options_data options = options_data();
- };
- #endif // PDATA_H_INCLUDED
- \\pdata.h END==================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement