From c3c14b08155a0341e059ddd24172afd5bd6ff6c6 Mon Sep 17 00:00:00 2001 From: Amar Takhar Date: Wed, 3 Mar 2010 00:44:17 +0000 Subject: [PATCH] Change how libresrc is built: * Instead of putting code into the .(c|h) files place it into two new files libresrc.(c|h) * Bitmaps now go into bitmaps.(c|h) * Default configs into default_config.(c|h) With this approach we can easily embed any resources by simply calling it with common-respack and not having to do anything else. Originally committed to SVN as r4169. --- aegisub/src/libresrc/Makefile.am | 20 ++++++++++++++++---- aegisub/src/libresrc/default_mru.json | 5 +++++ aegisub/src/libresrc/libresrc.cpp | 12 ++++++++++++ aegisub/src/libresrc/libresrc.h | 14 ++++++++++++++ aegisub/tools/common-respack.cpp | 24 ++++++++---------------- 5 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 aegisub/src/libresrc/default_mru.json create mode 100644 aegisub/src/libresrc/libresrc.cpp create mode 100644 aegisub/src/libresrc/libresrc.h diff --git a/aegisub/src/libresrc/Makefile.am b/aegisub/src/libresrc/Makefile.am index 1d8b54b62..661fcc57e 100644 --- a/aegisub/src/libresrc/Makefile.am +++ b/aegisub/src/libresrc/Makefile.am @@ -1,9 +1,21 @@ noinst_LIBRARIES = libresrc.a -nodist_libresrc_a_SOURCES = libresrc.cpp +libresrc_a_SOURCES = libresrc.cpp libresrc.h +nodist_libresrc_a_SOURCES = bitmap.cpp bitmap.h default_config.cpp default_config.h libresrc_a_CPPFLAGS = @WX_CPPFLAGS@ -libresrc.cpp: ../../tools/common-respack - ../../tools/common-respack libresrc.cpp ../bitmaps/16 ../bitmaps/24 ../bitmaps/misc/splash.png ../bitmaps/misc/wxicon.png +BUILT_SOURCES = bitmap.cpp default_config.cpp -CLEANFILES= libresrc.cpp libresrc.h +bitmap.cpp: ../../tools/common-respack + ../../tools/common-respack bitmap.cpp ../bitmaps/16 ../bitmaps/24 ../bitmaps/misc/splash.png ../bitmaps/misc/wxicon.png + +default_config.cpp: ../../tools/common-respack + ../../tools/common-respack default_config.cpp ./default_mru.json + +EXTRA_DIST = mru.json + +CLEANFILES= \ + bitmap.cpp \ + bitmap.h \ + default_config.cpp \ + default_config.h diff --git a/aegisub/src/libresrc/default_mru.json b/aegisub/src/libresrc/default_mru.json new file mode 100644 index 000000000..4a4e3f42b --- /dev/null +++ b/aegisub/src/libresrc/default_mru.json @@ -0,0 +1,5 @@ +{ + "Audio" : [], + "Video" : [], + "Scripts" : [], +} diff --git a/aegisub/src/libresrc/libresrc.cpp b/aegisub/src/libresrc/libresrc.cpp new file mode 100644 index 000000000..3e9423f60 --- /dev/null +++ b/aegisub/src/libresrc/libresrc.cpp @@ -0,0 +1,12 @@ +#include "libresrc.h" + +wxBitmap libresrc_getimage(const unsigned char *buff, size_t size) { + wxMemoryInputStream mem(buff, size); + wxImage image(mem); + return wxBitmap(image); +} + +const std::string libresrc_getconfig(const char *config, size_t size) { + std::string str(config, size); + return str; +} diff --git a/aegisub/src/libresrc/libresrc.h b/aegisub/src/libresrc/libresrc.h new file mode 100644 index 000000000..31722668a --- /dev/null +++ b/aegisub/src/libresrc/libresrc.h @@ -0,0 +1,14 @@ +#include +#include +#include + +#include + +#include "bitmap.h" +#include "default_config.h" + +wxBitmap libresrc_getimage(const unsigned char *image, size_t size); +#define GETIMAGE(a) libresrc_getimage(a, sizeof(a)) + +const std::string libresrc_getconfig(const char *config, size_t size); +#define CET_DEFAULT_CONFIG(a) libresrc_getconfig(a, sizeof(a)) diff --git a/aegisub/tools/common-respack.cpp b/aegisub/tools/common-respack.cpp index bce26543c..5ab2b0a9c 100644 --- a/aegisub/tools/common-respack.cpp +++ b/aegisub/tools/common-respack.cpp @@ -113,21 +113,6 @@ int main(int argc, const char *argv[]) { ofstream outH(headerFileName.GetFullPath().char_str()); ofstream outC(argv[1]); - outC << "/* This is an automatically generated file and should not be modified directly */" << endl - << "#include \"" << headerFileName.GetFullName() << "\"" << endl - << "wxBitmap " << headerFileName.GetName() << "_getimage(const unsigned char *buff, size_t size) {" << endl - << " wxMemoryInputStream mem(buff, size);" << endl - << " wxImage image(mem);" << endl - << " return wxBitmap(image);" << endl - << "}" << endl; - - outH << "/* This is an automatically generated file and should not be modified directly */" << endl - << "#include " << endl - << "#include " << endl - << "#include " << endl - << "wxBitmap " << headerFileName.GetName() << "_getimage(const unsigned char *image, size_t size);" << endl - << "#define GETIMAGE(a) " << headerFileName.GetName() << "_getimage(a, sizeof(a))" << endl; - wxRegEx nameCleaner("[^A-Za-z_0-9]"); wxString filename; FileIterator iter(argc, argv); @@ -139,9 +124,16 @@ int main(int argc, const char *argv[]) { infile.seekg(0, ios::beg); wxFileName file(filename); - wxString identifier = file.GetName() + "_" + file.GetDirs().Last(); + + wxString identifier = file.GetName(); + + // Hack to work around inserting files in the current directory + if (file.GetDirs().Last() != ".") + identifier.Append("_" + file.GetDirs().Last()); + nameCleaner.ReplaceAll(&identifier, "_"); + outC << "#include \"libresrc.h\"" << endl; outC << "const unsigned char " << identifier << "[] = {"; bool first = true; char c[1];