All Classes Files Functions Variables Enumerations Enumerator Macros
initlists.cpp
Go to the documentation of this file.
1 #include "initlists.hpp"
12 
14 // Default constructor
16 {};
17 
19 // Default destructor
21 {};
22 
27 {
28  // Create an input file stream object
29  ifstream infile;
30  // Set a showlist counter and set to 0
31  int tmpCount = 0;
32  // Create an error flag and set to false
33  bool errorFlag = 0;
34 
35  // Create an array of possible locations for the showlist file
36  string location[4] = { confOpt->getOptions( confOpt->ShowListLocation_opt ), LOC1"showlist", LOC2"showlist", LOC3"showlist" };
37 
38  // Check each of the 4 possible locations for the showlist file
39  for( int i = 0; i < 4; i++ )
40  {
41  // Set the char array to one of the locations
42  const char *cList = location[i].c_str();
43  // Attempt to open the file
44  infile.open( cList );
45  // If the file doesn't exist at the location
46  if( !infile.is_open() )
47  {
48  // Set the error flag to true
49  errorFlag = 1;
50  }
51  // If the the file does exist at the location
52  else
53  {
54  // Set showList to the location showlist was found
55  confOpt->setOptions( confOpt->ShowListLocation_opt, location[i] );
56  // Set the error flag to false
57  errorFlag = 0;
58  // Stop searching for the showlist file
59  break;
60  }
61  }
62 
63  // If the error flag is set to true
64  if( errorFlag )
65  {
66  cout << "Error: No showlist file found" << endl;
67  // Return 1 = failure
68  return 1;
69  }
70 
71  while( !infile.eof() )
72  {
73  // Create a temporary line holder
74  string tmpLine;
75  // Read a line from the showlist file and store in the temporary holder
76  getline( infile, tmpLine );
77  // If the line isn't commented out and more than 0 characters
78  if( tmpLine[0] != '#' && tmpLine.length() > 0 )
79  {
80  // Create a temporary vector for string storage
81  vector<string> tmpString;
82  // Find the position of the first delimiter
83  int firstDelim = tmpLine.find( confOpt->getOptions( confOpt->ShowListDelimiter_opt )[0] );
84  // If there are any characters before the first delimiter
85  if( tmpLine.substr( 0, firstDelim ).length() > 0 )
86  {
87  // Save as the best name
88  tmpString.push_back ( tmpLine.substr( 0, firstDelim ) );
89  }
90  // Move to the next character
91  firstDelim++;
92 
93  // Find the position of the last delimiter
94  int lastDelim = tmpLine.find( confOpt->getOptions( confOpt->ShowListDelimiter_opt )[2] );
95  // If more than one character exists between the first and last delimiters
96  if( tmpLine.substr( firstDelim, lastDelim-firstDelim ).length() > 1 )
97  {
98  // Save as the list of names to search as
99  tmpString.push_back ( tmpLine.substr( firstDelim, lastDelim-firstDelim ) );
100  }
101  // Move to the next character
102  lastDelim++;
103 
104  // If there is more than one character past the last delimeter
105  if( tmpLine.substr( lastDelim ).length() > 1 )
106  {
107  // Save as the parent directory
108  tmpString.push_back ( tmpLine.substr( lastDelim ) );
109  }
110  // Save the three strings ( 'best name', 'names to search', 'parent directory' )
111  confOpt->v_showList.push_back ( tmpString );
112  }
113  // Delete all the data in the temporary holder
114  tmpLine.clear();
115  // Move to the next line in the showlist
116  tmpCount++;
117  }
118 
119  if( infile.is_open() )
120  {
121  // Close the file
122  infile.close();
123  }
124 
125  // If there are no lines counted
126  if( tmpCount == 0 )
127  {
128  cout << "Warning: Empty showlist file" << endl;
129  // Return 1 = failure
130  return 1;
131  }
132 
133  // Return 0 = success
134  return errorFlag;
135 };
136 
141 // Loads the contents of the blacklist file into an array
143 {
144  // Create an input file stream object
145  ifstream infile;
146  // Create an error flag and set to false
147  bool errorFlag = 0;
148 
149  // Create an array of possible locations for the blacklist file
150  string location[4] = { confOpt->getOptions( confOpt->BlackListLocation_opt ), LOC1"blacklist", LOC2"blacklist", LOC3"blacklist" };
151 
152  // Check each of the 4 possible locations for the showlist file
153  for( int i = 0; i < 4; i++ )
154  {
155  // Set the char array to one of the locations
156  const char *cList = location[i].c_str();
157  // Attempt to open the file
158  infile.open( cList );
159  // If the file doesn't exist at the location
160  if( !infile.is_open() )
161  {
162  // Set the error flag to true
163  errorFlag = 1;
164  }
165  else
166  {
167  // Set the error flag to true
168  errorFlag = 0;
169  // Stop searching for the blacklist file
170  break;
171  }
172  }
173 
174  // If the error flag is set to true
175  if( errorFlag )
176  {
177  cout << "Warning: No blacklist file found" << endl;
178  }
179  else
180  {
181  // Read the blacklist file until EOF
182  while( !infile.eof() )
183  {
184  // Create a temporary line holder
185  string tmpLine;
186  // Read a line from the blacklist file and store in the temporary holder
187  getline( infile, tmpLine );
188  // If the line isn't commented out and more than 0 characters
189  if( tmpLine[0] != '#' && tmpLine.length() > 0 )
190  {
191  // Count the line
192  confOpt->v_blackList.push_back ( tmpLine );
193  }
194  }
195 
196  if( infile.is_open() )
197  {
198  // Close the file
199  infile.close();
200  }
201 
202  // If there are no lines counted
203  if( confOpt->v_blackList.size() == 0 )
204  {
205  cout << "Warning: Empty blacklist file" << endl;
206  }
207  }
208 
209  // Return 0 = success
210  return 0;
211 };
#define LOC3
Definition: options.hpp:35
the location of the blacklist file
Definition: options.hpp:70
static vector< vector< string > > v_showList
A vector of vectors the will store a list of shows and a list of their episodes.
Definition: options.hpp:140
static string getOptions(optionValue)
Retrieves the user configuration options from an array.
Definition: mainPublic.cpp:129
#define LOC1
Definition: options.hpp:33
the delimiters used to parse showlist lines
Definition: options.hpp:72
#define LOC2
Definition: options.hpp:34
The InitLists class loads the showlist and blacklist files into arrays.
~InitLists()
Default destructor.
Definition: initlists.cpp:20
static bool initBlacklist(ConfigOpts *)
Loads the contents of the blacklist file into an array.
Definition: initlists.cpp:142
InitLists()
Default constructor.
Definition: initlists.cpp:15
Stores all config options, settings, and flags for clerk.
Definition: options.hpp:60
static vector< string > v_blackList
A vector that holds a list of tags to be removed from each file's name.
Definition: options.hpp:141
the location of the showlist file
Definition: options.hpp:71
static bool initShowlist(ConfigOpts *)
Loads the contents of the showlist file into an array.
Definition: initlists.cpp:26
static void setOptions(optionValue, string)
Sets the user configuration options into an array.
Definition: mainPublic.cpp:105