home *** CD-ROM | disk | FTP | other *** search
Wrap
char *V = "$VER: Gallery 37.0 (02.02.97)"; #include <GUIC_Classes/all.hpp> #define COPYRIGHT "<SMALL> index file created with 'Gallery', (c) 1997 by <A HREF=\"http://www.student.uni-kl.de/~hillenbr\">Markus Hillenbrand</A> </SMALL>" #define FILEFILTER "#?.(jpeg|jpg|gif|iff|ilbm|iff24|png)" GUIC_LibraryC IntuitionBase("intuition.library",37); // Just to check the version of the system GUIC_ListC errorList; int lastDay=0,lastMonth=0,lastYear=0; class GalleryEntryC : public GUIC_ObjectC { public: GalleryEntryC(STRPTR f, LONG s, int d, int m, int y) { fileName=f; size=s; day=d; month=m; year=y; } String fileName; int day,month,year; LONG size; }; String MakeThumbnail (GUIC_FileExamineC &file) { String fileName = file.GetName(); int i = fileName.length(); while (--i) if (fileName[i] == '.') break; String thumbName = fileName.left(i); thumbName+="_.jpg"; try { GUIC_FileExamineC f(thumbName); if (f.Newer(file)) return thumbName; } catch (GUIC_SystemX &e) { } String args = "<>NIL: " + fileName + " TO " + thumbName + " FORMAT JPEG QUALITY 90 BOXFIT 100 100"; cout << " - creating thumbnail for file '" << fileName << "' ... " << flush; BOOL result = GUIC_SystemC::RunProgram("GfxCon_68020", 100000, args); if (result) cout << "done." << endl; else cout << "error occured." << endl; return thumbName; } void CreateGallery (GUIC_ListC &fileList, STRPTR pattern) { GalleryEntryC *key = (GalleryEntryC *)fileList.ObjectAt(1); GUIC_FileExamineC firstFile(key->fileName); String currentDir = firstFile.GetPathPart(); GUIC_FileC indexFile(currentDir, "index.html", GUIC_Write); GUIC_FileExamineC directoryName(currentDir); cout << "Creating gallery in directory '" << currentDir << "' " << endl; indexFile.WriteLn("<HTML>"); indexFile.WriteLn("<HEAD>"); indexFile.Write("<TITLE> "); indexFile.Write(directoryName.GetFilePart()); indexFile.WriteLn(" </TITLE>"); indexFile.WriteLn("</HEAD>"); indexFile.Write("<BODY"); if (pattern) { indexFile.Write(" Background=\""); indexFile.Write(pattern); indexFile.Write("\""); } indexFile.WriteLn("><CENTER>"); indexFile.WriteLn("<HR>"); indexFile.Write("<H1>"); indexFile.Write(directoryName.GetFilePart()); indexFile.WriteLn("</H1>"); indexFile.WriteLn("<TABLE Border=4 CellSpacing=4 CellPadding=4>"); int count = 0; for (int i=1; i<=fileList.Length(); i++) { key = (GalleryEntryC *)fileList.ObjectAt(i); try { GUIC_FileExamineC file(key->fileName); String thumbName = MakeThumbnail(file); GUIC_FileExamineC thumb (thumbName); // Check the date GUIC_DateC oldDate(lastDay,lastMonth,lastYear),*fileDate = file.GetDate();; if (fileDate->Greater(oldDate) ) { lastDay = fileDate->GetDay(); lastMonth = fileDate->GetMonth(); lastYear = fileDate->GetYear(); } // Check if there are 4 entries per line in the table if (count++ % 4 == 0) indexFile.Write("<TR> "); indexFile.Write("<TD> <CENTER> <IMG SRC=\""); indexFile.Write(thumb.GetFilePart()); indexFile.Write("\"> <BR> <A HREF=\""); indexFile.Write(file.GetFilePart()); indexFile.Write("\"> "); indexFile.Write(file.GetFilePart()); indexFile.Write(" </A> <BR> Size: "); indexFile.Write(key->size); indexFile.Write(" <BR> Date: "); indexFile.Write(key->day); indexFile.Write("."); indexFile.Write(key->month); indexFile.Write("."); indexFile.Write(key->year); indexFile.WriteLn("</TD>"); } catch (GUIC_SystemX &e) { GalleryEntryC *s = new GalleryEntryC(key->fileName,0,0,0,0); errorList.AddTail(*s); } } indexFile.WriteLn("</TABLE>"); indexFile.WriteLn("<HR>"); indexFile.WriteLn(COPYRIGHT); indexFile.WriteLn("</BODY>"); indexFile.WriteLn("</HTML>"); } void CreateHTML (GUIC_ListC &fileList, STRPTR pattern) { GalleryEntryC *key = (GalleryEntryC *)fileList.ObjectAt(1); GUIC_FileExamineC firstFile(key->fileName); STRPTR currentDir = firstFile.GetPathPart(); GUIC_FileC indexFile(currentDir, "index.html", GUIC_Write); GUIC_FileExamineC directoryName(currentDir); String titleString = directoryName.GetFilePart(); if (titleString == String("") ) titleString = directoryName.GetName(); cout << "Creating file '" << indexFile.GetName() << "'" << endl; indexFile.WriteLn("<HTML>"); indexFile.WriteLn("<HEAD>"); indexFile.Write("<TITLE> "); indexFile.Write(titleString); indexFile.WriteLn(" </TITLE>"); indexFile.WriteLn("</HEAD>"); indexFile.Write("<BODY"); if (pattern) { indexFile.Write(" Background=\""); indexFile.Write(pattern); indexFile.Write("\""); } indexFile.WriteLn("><CENTER>"); indexFile.WriteLn("<HR>"); indexFile.Write("<H1>"); indexFile.Write(titleString); indexFile.WriteLn("</H1><BR>"); indexFile.WriteLn("<TABLE Border=4 CellSpacing=4 CellPadding=4>"); indexFile.WriteLn("<TR> <TD> <CENTER> <H3> Gallery Name </H3> </TD> <TD> <CENTER> <H3> Entries </H3> </TD> <TD> <CENTER> <H3> Last Update </H3> </TD>"); for (int i=1; i<=fileList.Length(); i++) { key = (GalleryEntryC *)fileList.ObjectAt(i); GUIC_FileExamineC file (key->fileName); indexFile.Write("<TR> <TD> <CENTER> <A HREF=\""); indexFile.Write(file.GetFilePart()); indexFile.Write("/index.html\""); indexFile.Write("> "); indexFile.Write(file.GetFilePart()); indexFile.Write(" </A> </TD> <TD> <CENTER> "); indexFile.Write(key->size); indexFile.Write(" </TD> <TD> <CENTER> "); if (key->day) { indexFile.Write(key->day); indexFile.Write("."); indexFile.Write(key->month); indexFile.Write("."); indexFile.Write(key->year); } else indexFile.Write("(Directory)"); indexFile.WriteLn(" </TD>"); } indexFile.WriteLn("</TABLE>"); indexFile.WriteLn("<HR>"); indexFile.WriteLn(COPYRIGHT); indexFile.WriteLn("</BODY>"); indexFile.WriteLn("</HTML>"); } int ScanDir (STRPTR startDir, STRPTR pattern) { GUIC_ListC fileList,dirList; GalleryEntryC *key = 0; GUIC_FileExamineC *filex = 0; int entries = 0; GUIC_FileExamineC *examine = new GUIC_FileExamineC(startDir); if (!examine->IsDirectory()) throw GUIC_SystemX("Error in function ScanDir (directory name expected)."); String dirName = examine->GetName(); delete examine; examine=0; GUIC_DirectoryExamineC *direx= new GUIC_DirectoryExamineC(dirName); BOOL hasSubDirs = direx->HasSubdirectory(); if (!hasSubDirs) direx->SetFilter(FILEFILTER); try { while ( (filex = direx->ExamineNext()) ) { String fileName = filex->GetName(); GUIC_DateC *date = filex->GetDate(); if (filex->IsDirectory()) { String newPattern = String("../") + String(pattern); int entriesInDir = ScanDir(fileName, newPattern); if (entriesInDir) { key = new GalleryEntryC(fileName, entriesInDir, lastDay, lastMonth, lastYear); if (!key) throw GUIC_MemoryX("Can't allocate memory for key."); dirList.AddTail(*key); entries+=entriesInDir; } lastDay=0; lastMonth=0; lastYear=0; } else if (! hasSubDirs && (fileName.right(5) != String("_.jpg") ) ) { key = new GalleryEntryC(fileName, filex->GetSize(), date->GetDay(), date->GetMonth(), date->GetYear() ); if (!key) throw GUIC_MemoryX("Can't allocate memory for key."); fileList.AddTail(*key); entries++; } } } catch (GUIC_SystemX &e) { cerr << "Exception caught while processing directory '" << direx->GetName() << "': " << e.GetMessage() << " from file " << filex->GetName() << "." << endl; } delete direx;direx=0; /* Damit der lock auf das Verzeichnis freigegeben wird ! */ if (dirList.Length() ) CreateHTML(dirList,pattern); if (fileList.Length()) CreateGallery(fileList,pattern); while (fileList.Length()) delete (GalleryEntryC *)fileList.Delete(1); while ( dirList.Length()) delete (GalleryEntryC *) dirList.Delete(1); return entries; } void main (int argc, char **argv) { try { LONG result[2] = { 0,0 }; GUIC_ProgramArgsC args; if (! args.Fit("STARTDIR,BGPATTERN",result)) { PrintFault(IoErr(),NULL); GUIC_SystemC::exit(GUIC_ExitError); } ScanDir((STRPTR)result[0], (STRPTR)result[1]); if (errorList.Length()) { cerr << "The following files could not be converted to a thumbnail:" << endl; while (errorList.Length()) { GalleryEntryC *s = (GalleryEntryC *)errorList.Delete(1); cerr << "- " << s->fileName << endl; delete s; } cerr << "Please check them and run 'Gallery' again." << endl; } } catch (GUIC_MemoryX m) { cerr << "MemoryX() caught: " << m.GetMessage() << endl; } catch (GUIC_GadgetX g) { cerr << "GadgetX() caught: " << g.GetMessage() << endl; } catch (GUIC_WindowX w) { cerr << "WindowX() caught: " << w.GetMessage() << endl; } catch (GUIC_ScreenX s) { cerr << "ScreenX() caught: " << s.GetMessage() << endl; } catch (GUIC_EventX e) { cerr << "EventX() caught: " << e.GetMessage() << endl; } catch (GUIC_ConvertX c) { cerr << "ConvertX() caught: " << c.GetMessage() << endl; } catch (GUIC_SystemX s) { cerr << "SystemX() caught: " << s.GetMessage() << endl; } }