Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

datafile_compiler.cpp

Go to the documentation of this file.
00001 
00002 #include "Core/precomp.h" // visual c++: precompiled header file MUST be mentioned FIRST.
00003 
00004 #include <iostream>
00005 #include <string>
00006 #include <stdio.h>
00007 
00008 #ifdef BORLAND
00009 #pragma hdrstop
00010 //This will speed up the Borland compile when using PCH
00011 #endif
00012 
00013 #include <Core/Resources/resource_manager_file.h>
00014 #include <API/Core/System/clanstring.h>
00015 #include <API/Core/IOData/inputsource.h>
00016 #include "API/Core/Resources/datafile_compiler.h"
00017 #include "datafile_writer.h"
00018 
00019 
00020 
00021 extern void redirect_to_console(const char *title);
00022 
00023 void CL_DatafileCompiler::write(
00024         const std::string &scr_file,
00025         const std::string &dat_file)
00026 {
00027         redirect_to_console("ClanLib Datafile Compiler"); // <-- create a console window under Win32.
00028         std::cout << std::endl << "ClanLib Datafile Compiler" << std::endl << std::endl;
00029 
00030 //      bool found_inputfile = false, found_outputfile = false;
00031         bool use_scriptfilename = false;
00032 
00033         CL_String input_file(scr_file);
00034         CL_String output_file(dat_file);
00035                         
00036 /*      try
00037         {*/
00038                 std::cout << "Input file: " << input_file << ", output file: " << output_file << std::endl;
00039                 CL_ResourceManager *manager = CL_ResourceManager::create(input_file, NULL, true);
00040 
00041                 std::list<std::string> *resource_list = manager->get_all_resources();
00042 
00043                 OutputSourceProvider_Datafile output(output_file.get_string());
00044 
00045                 // Write the config-file to the datafile
00046                 {
00047                         // open the section with either input_file or default_scriptfile_id
00048                         CL_OutputSource *config_osource;
00049 
00050                         if( use_scriptfilename )
00051                         {
00052                                 config_osource = output.open_source(input_file);
00053                                 std::cout << "Using " << input_file << " as sectionname for scriptfile." << std::endl;
00054                         }
00055                         else // use default_scriptfile_id for id
00056                         {
00057                                 config_osource = output.open_source(default_scriptfile_id);
00058 //                              std::cout << "Using " << default_scriptfile_id << " as sectionname for scriptfile." << endl;
00059                         }
00060         
00061                         CL_InputSourceProvider *file_provider = CL_InputSourceProvider::create_file_provider("");
00062                         CL_InputSource *config_file = file_provider->open_source(input_file);
00063 
00064                         int total_size = config_file->size();
00065                         char *config_file_data = new char[total_size];
00066                         config_file->read(config_file_data, total_size);
00067                         config_osource->write(config_file_data, total_size);
00068 
00069                         delete file_provider;
00070                         delete config_file;
00071                         delete config_osource;
00072                 }
00073         
00074                 for (
00075                         std::list<std::string>::iterator it = resource_list->begin();
00076                         it != resource_list->end();
00077                         it++)
00078                 {
00079                         CL_OutputSource *osource = output.open_source((*it).c_str());
00080 
00081                         CL_Resource *res = manager->get_resource(*it);
00082                         if (res != NULL)
00083                         {
00084                                 std::cout << "Writing resource '" << it->c_str() << "'" << std::endl;
00085                                 res->serialize_save(osource);
00086                         }
00087                         delete osource;
00088                 }
00089                 delete resource_list;
00090                 delete manager;
00091 /*      }
00092         catch (CL_Error err)
00093         {
00094                 std::cout << "Error occured: " << err.message.c_str() << std::endl;
00095                 
00096                 remove (output_file.get_string());
00097         }*/
00098 }
00099 
00100 
00101 
00102 

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001