00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00025 #include "cWebshots.h"
00026
00027 #include <iostream>
00028
00029 using namespace std;
00030 using namespace cWebshots;
00031
00032
00033 enum CLArgs
00034 {
00035 claUndefined,
00036 claInput,
00037 claOutputFormat,
00038 claOutputFileName,
00039 claOutputDirectory,
00040 claIdentify,
00041 claDefaultCategory,
00042 claDefaultAlbum,
00043 claDefaultAlbumID,
00044 claDefaultCredits,
00045 claDefaultSource
00046 };
00047
00048 int main(int argc, char* argv[])
00049 {
00050 CLArgs mode = claUndefined;
00051 int i;
00052 string commande;
00053
00054
00055 cWebshotsCollection Entree;
00056
00057
00058 cWebshotsCollection EntreeColl;
00059
00060
00061 Webshots_Formats Format = Unknown;
00062
00063
00064 string DossierSortie;
00065
00066
00067 string FichierSortie;
00068
00069
00070 bool Rename = false;
00071
00072
00073 string DefaultCategory = "cWebshots";
00074 string DefaultAlbum = "Converted files";
00075 string DefaultAlbumID = "0";
00076 string DefaultCredits = "cWebshots";
00077 string DefaultSource = "u";
00078
00079 cout << "UWC - Ultimate Webshots Converter" << endl
00080 << "Version 2.0 beta 6 - Console" << endl
00081 << "THIS IS A BETA VERSION, USE IT WITH CARE !" << endl
00082 << endl
00083 << "Use '--help' command for help." << endl
00084 << endl;
00085
00086 Entree.Title = "cWebshots - Converted Pictures";
00087 Entree.Topic = "cWebshots";
00088
00089 try
00090 {
00091
00092 for (i = 0 ; i < argc; i++)
00093 {
00094 commande.assign(argv[i]);
00095
00096
00097 if ((commande.compare("-i") == 0) || (commande.compare("--input") == 0))
00098 mode = claInput;
00099 else if ((commande.compare("-of") == 0) || (commande.compare("--output-format") == 0))
00100 mode = claOutputFormat;
00101 else if ((commande.compare("-ofn") == 0) || (commande.compare("--output-file-name") == 0))
00102 mode = claOutputFileName;
00103 else if ((commande.compare("-od") == 0) || (commande.compare("--output-directory") == 0))
00104 mode = claOutputDirectory;
00105 else if ((commande.compare("-r") == 0) || (commande.compare("--rename") == 0))
00106 Rename = true;
00107 else if ((commande.compare("-h") == 0) || (commande.compare("--help") == 0))
00108 {
00109 cout << "Usage :" << endl;
00110 cout << endl
00111 << "-i or --input (\"file\" | \"folder\") [(\"file\" | \"folder\") ...]" << endl
00112 << "-of or --output-format (WBC | JPG | WBZ | WB1)" << endl
00113 << "-ofn or --output-file-name \"file\"" << endl
00114 << "-od or --output-directory \"folder\"" << endl
00115 << "-r or --rename" << endl
00116 << "-id or --identify (file) *must be used alone*" << endl
00117 << "-dc or --default-category (category)" << endl
00118 << "-da or --default-album (album)" << endl
00119 << "-dai or --default-album-id (albumid)" << endl
00120 << "-dcr or --default-credits (credits)" << endl
00121 << "-ds or --default-source ( w | c | u )" << endl
00122 << endl
00123 << "If the output format is WBC or WBZ, the input pictures will be merged into one "
00124 << "collection, and saved in the file defined by --output-file-name, "
00125 << "in the directory defined with --output-directory." << endl
00126 << endl
00127 << "For the other formats, if there is only one input picture, it will be saved into the file defined "
00128 << "by --output-file-name in the directory defined with --output-directory." << endl
00129 << endl
00130 << "If there is more than one picture or if the --rename option is set, the name of the output file will be "
00131 << "the caption of the picture, and if not available, the original filename "
00132 << "of the picture will be used instead." << endl;
00133
00134 return 1;
00135 }
00136 else if ((commande.compare("-id") == 0) || (commande.compare("--identify") == 0))
00137 mode = claIdentify;
00138 else if ((commande.compare("-dc") == 0) || (commande.compare("--default-category") == 0))
00139 mode = claDefaultCategory;
00140 else if ((commande.compare("-da") == 0) || (commande.compare("--default-album") == 0))
00141 mode = claDefaultAlbum;
00142 else if ((commande.compare("-dai") == 0) || (commande.compare("--default-album-id") == 0))
00143 mode = claDefaultAlbumID;
00144 else if ((commande.compare("-dcr") == 0) || (commande.compare("--default-credits") == 0))
00145 mode = claDefaultCredits;
00146 else if ((commande.compare("-ds") == 0) || (commande.compare("--default-source") == 0))
00147 mode = claDefaultSource;
00148
00149 else
00150 {
00151
00152 if (mode == claInput)
00153 {
00154 cout << "Loading " << commande << " ... ";
00155 try
00156 {
00157 EntreeColl.LoadFromFile(commande);
00158 }
00159 catch (Exceptions::FileSystemError)
00160 {
00161 cout << "Error !" << endl
00162 << "Warning : This cannot be opened as a file, trying to open it as a folder ... ";
00163 EntreeColl.LoadFromFolder(commande);
00164 }
00165 cout << "Ok : " << EntreeColl.PictureCount() << " pictures loaded." << endl;
00166
00167 Entree += EntreeColl;
00168 EntreeColl.Clear();
00169 }
00170
00171 else if (mode == claOutputFormat)
00172 {
00173 if (commande == "JPG")
00174 Format = JPG;
00175 else if (commande == "WB1")
00176 Format = WB1;
00177 else if (commande == "WBZ")
00178 Format = WBZ;
00179 else if (commande == "WBC")
00180 Format = WBC;
00181 else if (commande == "FOLDER")
00182 Format = Folder;
00183 else
00184 {
00185 Exceptions::Exception error("Unknown output format : " + commande);
00186 throw error;
00187 }
00188 }
00189
00190 else if (mode == claOutputDirectory)
00191 DossierSortie = commande;
00192
00193 else if (mode == claOutputFileName)
00194 FichierSortie = commande;
00195
00196 else if (mode == claIdentify)
00197 {
00198 cout << "The file \"" << commande << "\" seems to be a ";
00199
00200 switch (IdentifyFile(commande))
00201 {
00202 case WB1:
00203 cout << "WB1 / JPG";
00204 break;
00205 case WBZ:
00206 cout << "WBZ";
00207 break;
00208 case WBC:
00209 cout << "WBC";
00210 break;
00211 case Unknown:
00212 cout << "unknown";
00213 }
00214
00215 cout << " file." << endl;
00216
00217 return 1;
00218 }
00219
00220 else if (mode == claDefaultAlbum)
00221 DefaultAlbum = commande;
00222 else if (mode == claDefaultAlbumID)
00223 DefaultAlbumID = commande;
00224 else if (mode == claDefaultCategory)
00225 DefaultCategory = commande;
00226 else if (mode == claDefaultCredits)
00227 DefaultCredits = commande;
00228 else if (mode == claDefaultSource)
00229 DefaultSource = commande;
00230 }
00231 }
00232
00233
00234
00235
00236 if (Entree.PictureCount() == 0)
00237 {
00238 Exceptions::Exception error("No input files, or no pictures in the input files");
00239 throw error;
00240 }
00241
00242 cout << endl;
00243
00244
00245 for (i = 0; i < Entree.PictureCount(); i++)
00246 {
00247 if (Entree[i].Title.length() == 0)
00248 {
00249 if (Entree[i].Original_Filename.length() > 0)
00250 {
00251 Entree[i].Title = Entree[i].Original_Filename;
00252 cout << "Warning : Picture " << i << " has no title. Filename will be used instead." << endl;
00253 }
00254 else
00255 {
00256 Entree[i].Title = "No title";
00257 cout << "Warning : Picture " << i << " has no title. Using default title." << endl;
00258 }
00259 }
00260
00261 if ((Entree[i].Category.length() == 0) && (Entree[i].Album.length() == 0))
00262 {
00263 Entree[i].Category = DefaultCategory;
00264 Entree[i].Album = DefaultAlbum;
00265 Entree[i].AlbumID = DefaultAlbumID;
00266 cout << "Warning : Picture " << i << " has no album and category. Using defaults." << endl;
00267 }
00268
00269 if (Entree[i].Credits.length() == 0)
00270 {
00271 Entree[i].Credits = DefaultCredits;
00272 cout << "Warning : Picture " << i << " has no credit. Using default." << endl;
00273 }
00274
00275 if (Entree[i].Source.length() == 0)
00276 {
00277 Entree[i].Source = DefaultSource;
00278 cout << "Warning : Picture " << i << " has no source. Using default." << endl;
00279 }
00280 }
00281
00282
00283 cout << endl << "List of the input pictures :" << endl
00284 << endl;
00285 for (i = 0; i < Entree.PictureCount(); i++)
00286 {
00287 cout << "[" << i << "] Title: " << Entree[i].Title << endl
00288 << " ID: " << Entree[i].ID << endl
00289 << " Caption: " << Entree[i].Caption << endl
00290 << " Original Filename: " << Entree[i].Original_Filename << endl
00291 << endl;
00292 }
00293
00294
00295
00296 if ((Format == JPG) || (Format == WB1))
00297 {
00298 string tmpFileName;
00299 string tmpExt;
00300
00301 switch (Format)
00302 {
00303 case JPG:
00304 tmpExt = ".jpg";
00305 break;
00306 case WB1:
00307 tmpExt = ".wb1";
00308 }
00309
00310
00311
00312 if (Entree.PictureCount() > 1)
00313 {
00314 cout << "Warning: There is more than one picture to save, and the format you selected contains only one picture per file. "
00315 << "Turning on the --rename option." << endl
00316 << endl;
00317
00318 Rename = true;
00319 }
00320
00321
00322 for (i = 0; i < Entree.PictureCount(); i++)
00323 {
00324 if (Rename)
00325 {
00326
00327 if (Entree[i].Title.length() != 0)
00328 tmpFileName = Entree[i].Title;
00329
00330 else if (Entree[i].Original_Filename.length() != 0)
00331 tmpFileName = Entree[i].Original_Filename;
00332 }
00333 else
00334 {
00335 tmpFileName = FichierSortie;
00336 tmpExt = "";
00337 }
00338
00339
00340 cout << "Saving " << DossierSortie << "\\" << tmpFileName << tmpExt << " ... ";
00341 Entree[i].SaveToFile(DossierSortie + "\\" + tmpFileName + tmpExt, Format);
00342 cout << "Ok." << endl;
00343 }
00344 }
00345
00346 else if ((Format == WBC) || (Format == WBZ))
00347 {
00348 cout << "Saving " << DossierSortie << "\\" << FichierSortie << " ... ";
00349
00350
00351 switch (Format)
00352 {
00353 case WBC:
00354 Entree.SaveToFile(DossierSortie + "\\" + FichierSortie, WBC);
00355 break;
00356
00357 case WBZ:
00358 Entree.SaveToFile(DossierSortie + "\\" + FichierSortie, WBZ);
00359 }
00360
00361 cout << "Ok." << endl;
00362 }
00363 else if (Format == Folder)
00364 {
00365 cout << "Saving the collection in " << DossierSortie << endl;
00366
00367
00368 Entree.SaveToFolder(DossierSortie);
00369 }
00370
00371
00372 }
00373 catch (Exceptions::Exception &Err)
00374 {
00375 cout << endl << "Error : " << Err.Description() << endl;
00376 }
00377
00378 return 1;
00379 }