X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=blobdiff_plain;f=source%2Ftools%2Fbitmapcode.cpp;h=4425062ac1f57b717660f6118facd0df6afe96a2;hp=b5e6cf8d641b14601d5cea362c989f1707dbb01f;hb=3ef806261b5482a584e05dc8311c8d7633f146b4;hpb=e57ec1d198abf22f89385424d891cd432bad06bb diff --git a/source/tools/bitmapcode.cpp b/source/tools/bitmapcode.cpp index b5e6cf8..4425062 100644 --- a/source/tools/bitmapcode.cpp +++ b/source/tools/bitmapcode.cpp @@ -1,29 +1,32 @@ -//------------------------------------------------------------------- -// bitmapcode: Helper application which coverts PNG files into -// C++ code outputting binary code. +// bitmapcode.cpp - Bitmap code helper. // -// This application also is a simple test if the wxWidgets & Boost -// header files and library files are there. +// (c) 2012-2015 Xestia Software Development. // -// This file is licenced under the GNU General Public License -// version 3 only. (GPLv3 only). -//------------------------------------------------------------------- +// This file is part of Xestia Address Book. +// +// Xestia Address Book is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by the +// Free Software Foundation, version 3 of the license. +// +// Xestia Address Book is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with Xestia Address Book. If not, see #include #include #include #include +#include -/*#include -#include -#include */ #include #include #include -#include using namespace std; -//namespace boostfs = boost::filesystem; void CreateCPPFile(wxString dirfilename, wxString PNGFilename, int* counter) { @@ -34,15 +37,10 @@ void CreateCPPFile(wxString dirfilename, wxString PNGFilename, int* counter) // filename wxString of the filename. // counter Pointer to a integer counter. //------------------------------------------------------------------- - char pngfile_char; - int pageseek = 0; - /*boostfs::path PNGFilename(filename.c_str()); - boostfs::path CPPFilename = PNGFilename; - boostfs::path CPPFilenameOnly(CPPFilename.filename()); - boostfs::path DirFilename(dirfilename.c_str()); - boostfs::path DirFilenameOnly(DirFilename.filename()); - CPPFilename.replace_extension(".cpp");*/ - wxString outname; + + char pngfile_char; + int pageseek = 0; + wxString outname; wxString CPPFilename; CPPFilename = PNGFilename; CPPFilename.RemoveLast(4); @@ -77,46 +75,46 @@ void CreateCPPFile(wxString dirfilename, wxString PNGFilename, int* counter) } - // Setup the PNG file reading and cpp file. + // Setup the PNG file reading and cpp file. - fstream cppfile, pngfile; + fstream cppfile, pngfile; #if defined(__WIN32__) - pngfile.open(PNGFilename.wc_str(), ios::in | ios::binary ); - cppfile.open(CPPFilename.wc_str(), ios::out | ios::trunc ); + pngfile.open(PNGFilename.wc_str(), ios::in | ios::binary ); + cppfile.open(CPPFilename.wc_str(), ios::out | ios::trunc ); # else - pngfile.open(PNGFilename.c_str(), ios::in | ios::binary ); - cppfile.open(CPPFilename.c_str(), ios::out | ios::trunc ); + pngfile.open(PNGFilename.c_str(), ios::in | ios::binary ); + cppfile.open(CPPFilename.c_str(), ios::out | ios::trunc ); #endif - outname.Append(wxString::FromUTF8(DirFilenameOnly.c_str())); - outname.Append(wxT("_")); - outname.Append(wxString::FromUTF8(CPPFilenameOnly.c_str())); - outname.MakeUpper(); + outname.Append(wxString::FromUTF8(DirFilenameOnly.c_str())); + outname.Append(wxT("_")); + outname.Append(wxString::FromUTF8(CPPFilenameOnly.c_str())); + outname.MakeUpper(); outname.RemoveLast(4); - // Setup the inclusion guard. + // Setup the inclusion guard. - cppfile << "#include " << endl << endl; - cppfile << "#ifndef " << outname.c_str() << "_CPP" << endl; - cppfile << "#define " << outname.c_str() << "_CPP" << endl << endl; + cppfile << "#include " << endl << endl; + cppfile << "#ifndef " << outname.ToStdString() << "_CPP" << endl; + cppfile << "#define " << outname.ToStdString() << "_CPP" << endl << endl; - outname.Clear(); - outname.Append(wxString::FromUTF8(DirFilenameOnly.c_str())); - outname.Append(wxT("_")); - outname.Append(wxString::FromUTF8(CPPFilenameOnly.c_str())); + outname.Clear(); + outname.Append(wxString::FromUTF8(DirFilenameOnly.c_str())); + outname.Append(wxT("_")); + outname.Append(wxString::FromUTF8(CPPFilenameOnly.c_str())); outname.RemoveLast(4); outname.Append(wxT("_png")); - outname.MakeLower(); + outname.MakeLower(); - // Convert the PNG file into an unsigned char array. + // Convert the PNG file into an unsigned char array. - cppfile << "static unsigned char " << outname.c_str() << - "[] = {" << endl; + cppfile << "static unsigned char " << outname.ToStdString() << + "[] = {" << endl; while (pngfile){ pngfile.get(pngfile_char); @@ -144,16 +142,15 @@ void CreateCPPFile(wxString dirfilename, wxString PNGFilename, int* counter) } - // End the file, close it and increment the counter. + // End the file, close it and increment the counter. - cppfile << "};" << endl << endl; - cppfile << "#endif" << endl << endl; - cppfile.close(); + cppfile << "};" << endl << endl; + cppfile << "#endif" << endl << endl; + cppfile.close(); - cout << "CPP\t" << CPPFilename.c_str() << endl; - - ++*counter; + cout << "CPP\t" << CPPFilename.ToStdString() << endl; + ++*counter; } void CreateHPPFileDir(wxString dirfilename, wxArrayString filelist, @@ -168,17 +165,12 @@ void CreateHPPFileDir(wxString dirfilename, wxArrayString filelist, // filelist wxArrayString of the directory filelist. // counter Pointer to a integer counter. //------------------------------------------------------------------- - /* boostfs::path HPPFilename(dirfilename.c_str()); - boostfs::path CPPFile; - boostfs::path CPPFileOnly(CPPFile.filename()); - boostfs::path DirFilename(dirfilename.c_str()); - boostfs::path DirFilenameOnly(DirFilename.filename()); - HPPFilename.replace_extension(".h");*/ - fstream hppfile; + + fstream hppfile; - bool fmatch = FALSE; - wxString finaldirname; - wxString HPPFilename = dirfilename.c_str(); + bool fmatch = FALSE; + wxString finaldirname; + wxString HPPFilename = dirfilename.ToStdString(); wxString DirFilenameOnly; wxString HPPFilenameOnly; @@ -208,34 +200,34 @@ void CreateHPPFileDir(wxString dirfilename, wxArrayString filelist, } - // Make the directory filename upper case for writing to the - // header file. + // Make the directory filename upper case for writing to the + // header file. wxString CPPFileOnly; - finaldirname.Append(wxString::FromUTF8(DirFilenameOnly.c_str())); - finaldirname.MakeUpper(); + finaldirname.Append(wxString::FromUTF8(DirFilenameOnly.c_str())); + finaldirname.MakeUpper(); - // Write out the header file inclusion guard. + // Write out the header file inclusion guard. HPPFilename.Append(wxT(".h")); #if defined(__WIN32__) - hppfile.open(HPPFilename.wc_str(), ios::out | ios::trunc ); + hppfile.open(HPPFilename.wc_str(), ios::out | ios::trunc ); #else - hppfile.open(HPPFilename.c_str(), ios::out | ios::trunc ); + hppfile.open(HPPFilename.c_str(), ios::out | ios::trunc ); #endif - hppfile << "#include " << endl << endl; - hppfile << "#ifndef " << finaldirname.c_str() << "_H" << endl; - hppfile << "#define " << finaldirname.c_str() << "_H" << endl << endl; - hppfile << "// List all CPP files in the directory." << endl << endl; + hppfile << "#include " << endl << endl; + hppfile << "#ifndef " << finaldirname.ToStdString() << "_H" << endl; + hppfile << "#define " << finaldirname.ToStdString() << "_H" << endl << endl; + hppfile << "// List all CPP files in the directory." << endl << endl; - // Write each CPP file into the header file. + // Write each CPP file into the header file. for (int f = 0; f < filelist.GetCount() ; f++){ @@ -262,53 +254,34 @@ void CreateHPPFileDir(wxString dirfilename, wxArrayString filelist, CPPFileOnly.RemoveLast(4); CPPFileOnly.Append(wxT(".cpp")); - hppfile << "#include \"" << DirFilenameOnly.c_str() << - "/" << CPPFileOnly.c_str() << "\"" << endl; + hppfile << "#include \"" << DirFilenameOnly.ToStdString() << + "/" << CPPFileOnly.ToStdString() << "\"" << endl; } - - /*for (int f = 0; f < filelist.GetCount(); f++){ - boostfs::path CPPFile(filelist[f].c_str()); - boostfs::path CPPFileOnly(CPPFile.filename()); - CPPFileOnly.replace_extension(".cpp"); - - for (boostfs::path::iterator filet = CPPFile.begin(); - filet != CPPFile.end(); ++filet){ - if (*filet == DirFilename.filename()){ - fmatch = TRUE; - - } - if (fmatch == TRUE){ - - } - } - - hppfile << "#include \"" << DirFilenameOnly.c_str() << - "/" << CPPFileOnly.c_str() << "\"" << endl; - }*/ - // Write the end if and close the file. + // Write the end if and close the file. - hppfile << endl << "#endif" << endl << endl; - hppfile.close(); + hppfile << endl << "#endif" << endl << endl; + hppfile.close(); - // Increment the HPP file counter. + // Increment the HPP file counter. - cout << "HPPDIR\t" << HPPFilename.c_str() << endl; - ++*counter; + cout << "HPPDIR\t" << HPPFilename.ToStdString() << endl; + ++*counter; } int main(int argc, char *argv[]) { - int fp = 0; - int cppg = 0; - int hppg = 0; + + int fp = 0; + int cppg = 0; + int hppg = 0; - wxArrayString dirlist; - wxArrayString filelist; + wxArrayString dirlist; + wxArrayString filelist; wxString BitmapHeaderFilename; - wxString DirFilenameWxS; + wxString DirFilenameWxS; // Check if completed file exists before doing anything // else and write an error message if it does exist. @@ -323,17 +296,17 @@ int main(int argc, char *argv[]) } - fstream finalhppfile; + fstream finalhppfile; if (!argv[1]){ std::cout << "Error: No directory name given!" << std::endl; return -1; } - // Look in the subdirectories of the bitmaps directory and - // collect the names of the directories. + // Look in the subdirectories of the bitmaps directory and + // collect the names of the directories. - std::cout << "Working out directories in bitmaps directory..." << + std::cout << "Working out directories in bitmaps directory..." << std::endl; const char *dirarg = argv[1]; @@ -354,12 +327,7 @@ int main(int argc, char *argv[]) #endif - /*boostfs::path BitmapsDir(argv[1]); - boostfs::path BitmapsDirSubName; - boostfs::path BitmapsFilename; - boostfs::directory_iterator dir_end;*/ - - if ( wxDirExists(BitmapDirName) ){ + if ( wxDirExists(BitmapDirName) ){ wxDir BitmapDir(BitmapDirName); @@ -398,55 +366,40 @@ int main(int argc, char *argv[]) BitmapSubDirFull.Clear(); } - - /*for (boostfs::directory_iterator bitmapsidr_iter(BitmapsDir); - bitmapsidr_iter != dir_end; ++bitmapsidr_iter){ - - if (boostfs::is_directory(bitmapsidr_iter->status())){ - - BitmapsDirSubName = boostfs::path(bitmapsidr_iter->path()).filename(); - DirFilenameWxS.Append(wxString::FromUTF8(argv[1])); - DirFilenameWxS.Append(wxString::FromUTF8(BitmapsDirSubName.c_str())); - dirlist.Add(DirFilenameWxS, 1); - DirFilenameWxS = wxT(""); - - } - - }*/ } else { std::cout << "Error: Bitmaps Directory doesn't exist!" << std::endl; return 1; } - // Process each directory, generating a .cpp and .hpp file - // for each image and then a final .hpp for the directory - // containing the .hpp's for the directories. + // Process each directory, generating a .cpp and .hpp file + // for each image and then a final .hpp for the directory + // containing the .hpp's for the directories. if (dirlist.GetCount() == 0){ cout << "Error: No directories in the bitmaps folder. Unexpected behaviour!" << endl; return 1; } - std::cout << "Looking in bitmaps folder for PNGs..." << std::endl; + std::cout << "Looking in bitmaps folder for PNGs..." << std::endl; - DirFilenameWxS.Empty(); + DirFilenameWxS.Empty(); - std::cout << BitmapHeaderFilename.c_str() << std::endl; + std::cout << BitmapHeaderFilename.ToStdString() << std::endl; #if defined(__WIN32__) - finalhppfile.open(BitmapHeaderFilename.wc_str(), ios::out | ios::trunc); + finalhppfile.open(BitmapHeaderFilename.wc_str(), ios::out | ios::trunc); #else - finalhppfile.open(BitmapHeaderFilename.c_str(), ios::out | ios::trunc); + finalhppfile.open(BitmapHeaderFilename.c_str(), ios::out | ios::trunc); #endif - finalhppfile << "#include " << endl << endl; - finalhppfile << "#ifndef BITMAPS_H" << endl; - finalhppfile << "#define BITMAPS_H" << endl << endl; + finalhppfile << "#include " << endl << endl; + finalhppfile << "#ifndef BITMAPS_H" << endl; + finalhppfile << "#define BITMAPS_H" << endl << endl; for (int bi = 0; bi < dirlist.GetCount(); bi++) { @@ -460,6 +413,7 @@ int main(int argc, char *argv[]) while (ContinueProcess){ if (BitmapFilename.Right(4) == wxT(".PNG") || + BitmapFilename.Right(4) == wxT(".png")){ #if defined(__HAIKU__) @@ -490,37 +444,19 @@ int main(int argc, char *argv[]) } - /*boostfs::path BitmapsSubDir(dirlist[bi].c_str()); - for (boostfs::directory_iterator bitmapsidr_iter(BitmapsSubDir); - bitmapsidr_iter != dir_end; - ++bitmapsidr_iter){ - - if (boostfs::path(bitmapsidr_iter->path()).extension() == ".png" || - boostfs::path(bitmapsidr_iter->path()).extension() == ".PNG"){ - - BitmapsFilename = boostfs::path(bitmapsidr_iter->path()).filename(); - DirFilenameWxS.Append(wxString::FromUTF8(dirlist[bi].mb_str())); - DirFilenameWxS.Append(wxString::FromUTF8("/")); - DirFilenameWxS.Append(wxString::FromUTF8(BitmapsFilename.c_str())); - - filelist.Add(DirFilenameWxS, 1); - DirFilenameWxS = wxT(""); - - - - } - - }*/ - for (int fi = 0; fi < filelist.GetCount(); fi++) { - CreateCPPFile(dirlist[bi].wc_str(), filelist[fi].wc_str(), &cppg); + + CreateCPPFile(dirlist[bi].ToStdString(), filelist[fi].ToStdString(), &cppg); fp++; + } if (filelist.GetCount() > 0) { + CreateHPPFileDir(dirlist[bi].wc_str(), filelist, &hppg); + } filelist.Clear(); @@ -550,32 +486,31 @@ int main(int argc, char *argv[]) #elif defined(__WIN32__) - finalhppfile << "#include \"bitmaps\\" << DirNameSplit.c_str() << + finalhppfile << "#include \"bitmaps\\" << DirNameSplit.ToStdString() << ".h\"" << endl; #else - finalhppfile << "#include \"bitmaps/" << DirNameSplit.c_str() << + finalhppfile << "#include \"bitmaps/" << DirNameSplit.ToStdString() << ".h\"" << endl; #endif } - finalhppfile << endl << "#endif" << endl; - finalhppfile.close(); - ++hppg; + finalhppfile << endl << "#endif" << endl; + finalhppfile.close(); + ++hppg; - // Print out the results. + // Print out the results. - std::cout << "Finished processing PNGs into code." << std::endl; - std::cout << fp << " files processed." << std::endl; - std::cout << cppg << " .cpp files generated." << std::endl; - std::cout << hppg << " .hpp files generated." << std::endl; + std::cout << "Finished processing PNGs into code." << std::endl; + std::cout << fp << " files processed." << std::endl; + std::cout << cppg << " .cpp files generated." << std::endl; + std::cout << hppg << " .hpp files generated." << std::endl; // Write a success flag so that future runs won't take - // place thus speeding up the compilation process as - // required. + // place thus speeding up the compilation process as required. fstream bitmapflag; @@ -583,6 +518,6 @@ int main(int argc, char *argv[]) bitmapflag << "Bitmaps as code generated. To recreate, simply delete this file and run the bitmap code generation tool again." << endl; bitmapflag.close(); - return 0; + return 0; }