00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "cWebshots.h"
00027
00028 #include <cstdio>
00029
00030 using namespace std;
00031
00032 namespace cWebshots
00033 {
00037 cWebshotsTXT::cWebshotsTXT(void)
00038 {
00039 Count = 0;
00040 }
00041
00047 cWebshotsTXT::cWebshotsTXT(string directory)
00048 {
00049 Count = 0;
00050 Load(directory);
00051 }
00052
00056 cWebshotsTXT::~cWebshotsTXT(void)
00057 {
00058 if (Count > 0)
00059 delete[] Pictures;
00060 }
00061
00062
00068 void cWebshotsTXT::Load(string directory)
00069 {
00070
00071 ifstream in_file;
00072 string file;
00073
00074
00075 char buffer[500];
00076 string line;
00077
00078
00079 string field, value;
00080 int index;
00081
00082
00083 size_t separator;
00084
00085
00086
00087 if (Count > 0)
00088 delete[] Pictures;
00089
00090
00091
00092 file = directory + "album.txt";
00093
00094 in_file.open(file.c_str(), ios_base::in);
00095
00096
00097 if (in_file.is_open())
00098 {
00099
00100 if (!in_file.eof())
00101 {
00102
00103 in_file.getline(buffer,500,'\n');
00104 line = buffer;
00105
00106
00107 if ((line.length() > 0) && (separator = line.find("||")))
00108 {
00109
00110 field = line.substr(0,separator);
00111 value = line.substr(separator + 2);
00112
00113 if (field == "count")
00114 Count = atoi(value.c_str());
00115 else
00116 Count = 0;
00117 }
00118 else
00119 Count = 0;
00120 }
00121 else
00122 Count = 0;
00123
00124
00125
00126 if (Count == 1)
00127 {
00128
00129 while (!in_file.eof())
00130 {
00131
00132 in_file.getline(buffer,500,'\n');
00133 line = buffer;
00134
00135
00136 if ((line.length() > 0) && (separator = line.find("||")))
00137 {
00138
00139 field = line.substr(0,separator);
00140 value = line.substr(separator + 2);
00141
00142
00143 field = field.substr(0,field.rfind("_"));
00144
00145 if (field == "ID")
00146 Album.id = value;
00147 else if (field == "TITLE")
00148 Album.title = value;
00149 else if (field == "IN_USE")
00150 Album.in_use = (atoi(value.c_str()) == 1);
00151 else if (field == "DESCRIPTION")
00152 Album.description = value;
00153 else if (field == "TOPIC_NAME")
00154 Album.topic_name = value;
00155 else if (field == "CREATE_DATE")
00156 Album.create_date = atol(value.c_str());
00157 else if (field == "EDIT_DATE")
00158 Album.edit_date = atol(value.c_str());
00159 else if (field == "PHOTO_COUNT")
00160 Album.photo_count = atoi(value.c_str());
00161 }
00162 }
00163 }
00164
00165 in_file.close();
00166 }
00167
00168
00169
00170 file = directory + "photos.txt";
00171
00172 in_file.clear();
00173 in_file.open(file.c_str(), ios_base::in);
00174
00175
00176 if (in_file.is_open())
00177 {
00178
00179 if (!in_file.eof())
00180 {
00181
00182 in_file.getline(buffer,500,'\n');
00183 line = buffer;
00184
00185
00186 if ((line.length() > 0) && (separator = line.find("||")))
00187 {
00188
00189 field = line.substr(0,separator);
00190 value = line.substr(separator + 2);
00191
00192 if (field == "count")
00193 Count = atoi(value.c_str());
00194 else
00195 Count = 0;
00196 }
00197 else
00198 Count = 0;
00199 }
00200 else
00201 Count = 0;
00202
00203
00204
00205 if (Count > 0)
00206 {
00207 Pictures = new sPhotosTXT[Count];
00208
00209
00210 while (!in_file.eof())
00211 {
00212
00213 in_file.getline(buffer,500,'\n');
00214 line = buffer;
00215
00216
00217 if ((line.length() > 0) && (separator = line.find("||")))
00218 {
00219
00220 field = line.substr(0,separator);
00221 value = line.substr(separator + 2);
00222
00223
00224 index = atoi(field.substr(field.rfind("_") + 1).c_str());
00225
00226
00227 field = field.substr(0,field.rfind("_"));
00228
00229 if (field == "ID")
00230 Pictures[index].id = atol(value.c_str());
00231 else if (field == "POSITION")
00232 Pictures[index].position = value;
00233 else if (field == "TITLE")
00234 Pictures[index].title = value;
00235 else if (field == "CAPTION")
00236 Pictures[index].caption = value;
00237 else if (field == "CREDIT")
00238 Pictures[index].credit = value;
00239 else if (field == "URL_PHOTO")
00240 Pictures[index].url_photo = value;
00241 else if (field == "URL_THUMB")
00242 Pictures[index].url_thumb = value;
00243 else if (field == "SOURCE")
00244 Pictures[index].source = value;
00245 }
00246 }
00247 }
00248
00249 in_file.close();
00250 }
00251 }
00252
00253
00261 sPhotosTXT& cWebshotsTXT::Picture(int index)
00262 {
00263 return Pictures[index];
00264 }
00265
00271 int cWebshotsTXT::PictureCount()
00272 {
00273 return Count;
00274 }
00275
00286 int cWebshotsTXT::IndexFromFileName(string filename, bool case_sensitive)
00287 {
00288 int i;
00289
00290 for (i = 0; i < Count; i++)
00291 {
00292 if (case_sensitive)
00293 {
00294 if (Pictures[i].url_photo == filename)
00295 return i;
00296 }
00297 else
00298 {
00299
00300 if (Pictures[i].url_photo == filename)
00301 return i;
00302 }
00303 }
00304
00305 return IndexNotFound;
00306 }
00307
00308 }