00001
00002 #include "Core/precomp.h"
00003
00004 #include <iostream>
00005 #include <string>
00006 #include <stdio.h>
00007
00008 #ifdef BORLAND
00009 #pragma hdrstop
00010
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");
00028 std::cout << std::endl << "ClanLib Datafile Compiler" << std::endl << std::endl;
00029
00030
00031 bool use_scriptfilename = false;
00032
00033 CL_String input_file(scr_file);
00034 CL_String output_file(dat_file);
00035
00036
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
00046 {
00047
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
00056 {
00057 config_osource = output.open_source(default_scriptfile_id);
00058
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
00093
00094
00095
00096
00097
00098 }
00099
00100
00101
00102