File: datafile_compiler.cpp

package info (click to toggle)
clanlib 0.5.4-1-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 10,320 kB
  • ctags: 10,893
  • sloc: cpp: 76,056; xml: 3,281; sh: 2,961; perl: 1,204; asm: 837; makefile: 775
file content (83 lines) | stat: -rw-r--r-- 2,581 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
	$Id: datafile_compiler.cpp,v 1.16 2002/01/16 01:45:43 mbn Exp $

	------------------------------------------------------------------------
	ClanLib, the platform independent game SDK.

	This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
	version 2. See COPYING for details.

	For a total list of contributers see CREDITS.

	------------------------------------------------------------------------
*/

#include "Core/precomp.h" // visual c++: precompiled header file MUST be mentioned FIRST.

#include <iostream>
#include <string>
#include <stdio.h>

#ifdef BORLAND
#pragma hdrstop
//This will speed up the Borland compile when using PCH
#endif

#include <Core/Resources/resource_manager_file.h>
#include <API/Core/System/clanstring.h>
#include <API/Core/IOData/inputsource.h>
#include <API/Core/IOData/inputsource_provider.h>
#include <API/Core/IOData/inputsource_provider_file.h>
#include "API/Core/Resources/datafile_compiler.h"
#include "datafile_writer.h"

void CL_DatafileCompiler::write(
	const std::string &scr_file,
	const std::string &dat_file)
{
	std::cout << std::endl << "ClanLib Datafile Compiler" << std::endl << std::endl;

  	CL_String input_file(scr_file);
	CL_String output_file(dat_file);
			
	std::cout << "Input file: " << input_file.get_string() << ", output file: " << output_file.get_string() << std::endl;
	CL_ResourceManager *manager = new CL_ResourceManager(input_file, false);

	OutputSourceProvider_Datafile output(output_file.get_string());

	// Write the config-file to the datafile
	{
		CL_OutputSource *config_osource = output.open_source(default_scriptfile_id);

		CL_InputSourceProvider *file_provider = CL_InputSourceProvider::create_file_provider("");
		CL_InputSource *config_file = file_provider->open_source(input_file);

		int total_size = config_file->size();
		char *config_file_data = new char[total_size];
		config_file->read(config_file_data, total_size);
		config_osource->write(config_file_data, total_size);

		delete file_provider;
		delete config_file;
		delete config_osource;
	}

	std::list<std::string> *resource_list = manager->get_all_resources();
	for (
		std::list<std::string>::iterator it = resource_list->begin();
		it != resource_list->end();
		it++)
	{
		CL_Resource res = manager->get_resource(*it);

		if (res.get_options().exists("uncompressed")) output.set_compression(false);
		else output.set_compression();

		std::cout << "Writing resource '" << it->c_str() << "'" << std::endl;
		res.load();
		res.save_datafile(&output);
		res.unload();
	}
	delete resource_list;
	delete manager;
}