All Classes Files Functions Variables Enumerations Enumerator Macros
main.cpp
Go to the documentation of this file.
1 
17 #include "options.hpp"
18 #include "initlists.hpp"
19 #include "findfiles.hpp"
20 #include "parser.hpp"
21 #include "handler.hpp"
22 #include "output.hpp"
23 #include "library.hpp"
24 
25 using namespace std;
26 
56 int main(int argc, char *argv[])
57 {
58  // Create a pointer to a ConfigOpts object
59  ConfigOpts *confObj = new ConfigOpts;
60 
61  // Read the config file/command line arguments and set flags and options
62  if( confObj->Configure( argc, argv-1 ) )
63  {
64  // Return 1 = Failure
65  return 1;
66  }
67 
68  // Create a pointer to an InitLists object
69  InitLists *loadFile = new InitLists;
70 
71  // Check if initShowlist exists and load to an array
72  if( loadFile->initShowlist( confObj ) )
73  {
74  // Return 1 = Failure
75  return 1;
76  }
77 
78  // Check if initBlacklist exists and load to an array
79  if( loadFile->initBlacklist( confObj ) )
80  {
81  // Return 1 = Failure
82  return 1;
83  }
84 
85  // Create a pointer to a FindFiles object array
86  FindFiles *getShows = new FindFiles;
87 
88  // Check if input is a file or directory and set flags
89  if( getShows->readInput( confObj ) )
90  {
91  // Return 1 = Failure
92  return 1;
93  }
94 
95  // Check if input is a file
96  if( confObj->getFlags( confObj->ReadFromFile_flag ) )
97  {
98  // Check if input file can be read and read all files within
99  if( getShows->readFile( confObj ) )
100  {
101  // Return 1 = Failure
102  return 1;
103  }
104  }
105 
106  // Check if input is a directory
107  if( confObj->getFlags( confObj->ReadFromDirectory_flag ) )
108  {
109  // Check if input directory can be read and read all files within
110  if ( getShows->readDir( confObj->getOptions( confObj->InputSourceArgument_opt ), confObj ) )
111  {
112  // Return 1 = Failure
113  return 1;
114  }
115  }
116 
117  // Create a Library object
118  Library catalogue;
119 
120  // Create a vector of ErrorHandler objects
121  vector<ErrorHandler> failed;
122 
123  // For each file found
124  for( unsigned int i = 0; i < confObj->v_fileList.size(); i++ )
125  {
126  // Create a temporary Parser object
127  Parser parse;
128  // Send file to parse method
129  parse.parseShow( confObj->v_fileList[i], confObj );
130  // Check if there was a parsing error
131  if( parse.getError() )
132  {
133  // Store the error information in the error handler
134  failed.push_back ( ErrorHandler( parse.getOldDir() + parse.getOldFile(), parse.getErrorData() ) );
135  }
136  else
137  {
138  // Send parse data to Library object for final storage
139  catalogue.addEpisode( parse.getShowNameIndex(),
140  parse.getSeason(),
141  parse.getEpisode(),
142  parse.getXEpisode(),
143  parse.getPEpisode(),
144  parse.getTitle(),
145  parse.getShow(),
146  parse.getDir(),
147  parse.getOldFile(),
148  parse.getOldDir(),
149  failed,
150  confObj );
151  }
152  }
153 
154  // Send array to output method
155  OutPut outPut( &catalogue, failed, confObj );
156 
157  // Clean up
158  delete confObj;
159  delete loadFile;
160  delete getShows;
161 
162  // Return 0 = Success
163  return 0;
164 };
void parseShow(string, ConfigOpts *)
Parses the filename.
Definition: showParser.cpp:66
The OutPut class prints summary and error information from objects.
static bool getFlags(flagValue)
Retrieves the user configuration flags from an array.
Definition: mainPublic.cpp:280
string getOldFile() const
Definition: showParser.cpp:344
bool addEpisode(int, int, int, int, string, string, string, string, string, string, vector< ErrorHandler > &, ConfigOpts *)
Saves the info required to describe a particular episode.
Definition: library.cpp:38
static bool readDir(string, ConfigOpts *)
Counts and records files from an input directory.
Definition: findfiles.cpp:105
Auto-detects whether input is a file or directory.
Definition: findfiles.hpp:23
read input from a directory
Definition: options.hpp:97
The Library class stores all info required to describe all shows.
bool getError() const
Definition: showParser.cpp:421
string getPEpisode() const
Definition: showParser.cpp:393
Creates an object for each input file and parses file and folder names.
Definition: parser.hpp:23
static bool Configure(int, char **)
Reads all arguments into their appropriate variables.
Definition: mainPublic.cpp:66
string getShow() const
Definition: showParser.cpp:358
ConfigOpts::errorType getErrorData() const
Definition: showParser.cpp:428
int getSeason() const
Definition: showParser.cpp:372
static string getOptions(optionValue)
Retrieves the user configuration options from an array.
Definition: mainPublic.cpp:129
int getEpisode() const
Definition: showParser.cpp:379
static bool readFile(ConfigOpts *)
Counts and records files from an input file.
Definition: findfiles.cpp:169
read input from a file
Definition: options.hpp:96
static bool readInput(ConfigOpts *)
Detect if input is a file or a directory.
Definition: findfiles.cpp:70
int getShowNameIndex() const
Definition: showParser.cpp:365
The Parser class creates an object for each input file and parses file and folder names...
string getDir() const
Definition: showParser.cpp:351
The ErrorHandler class stores an error as it occurs.
string getOldDir() const
Definition: showParser.cpp:337
Prints summary and error information from objects.
Definition: output.hpp:28
static vector< string > v_fileList
A vector that contains the list of input files to be parsed.
Definition: options.hpp:142
The FindFiles class auto-detects whether input is a file or directory.
The InitLists class loads the showlist and blacklist files into arrays.
The ConfigOpts class stores all config options, settings, and flags for clerk.
static bool initBlacklist(ConfigOpts *)
Loads the contents of the blacklist file into an array.
Definition: initlists.cpp:142
string getTitle() const
Definition: showParser.cpp:400
input directory/file from args
Definition: options.hpp:79
Stores all config options, settings, and flags for clerk.
Definition: options.hpp:60
The ErrorHandler class stores an error as it occurs.
Definition: handler.hpp:17
int main(int argc, char *argv[])
Definition: main.cpp:56
Loads the showlist and blacklist files into arrays.
Definition: initlists.hpp:21
int getXEpisode() const
Definition: showParser.cpp:386
static bool initShowlist(ConfigOpts *)
Loads the contents of the showlist file into an array.
Definition: initlists.cpp:26
Stores all info required to describe all shows.
Definition: library.hpp:30