Subversion Repositories spk

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#include "spkprogress.h"
2
 
3
#ifndef _INCLUDE7ZIP
4
#include <ansi7zip/7Decoder.h>
5
#endif
6
 
7
#include <MultiSpkFile.h>
4 cycrow 8
#include "../../HiP/HiP.h"
7 cycrow 9
#include <Logging/log.h>
1 cycrow 10
 
11
 
12
#ifdef _DEBUG
13
#define CLEANUP fclose ( id ); if ( data ) delete data; if ( uncomprData ) delete uncomprData; if ( !removeFile.Empty() ) remove ( removeFile.c_str() ); char pause; printf ( "Press Enter to Close\n" ); scanf ( "%c", &pause );
14
#else
15
#define CLEANUP fclose ( id ); if ( data ) delete data; if ( uncomprData ) delete uncomprData; if ( !removeFile.Empty() ) remove ( removeFile.c_str() ); 
16
#endif
17
 
4 cycrow 18
char *ReadNextLine ( char *data, long *len, CyString *str )
1 cycrow 19
{
20
	int pos = 0;
21
	bool end = false;
22
	while ( pos < *len )
23
	{
24
		if ( data[pos] == '\n' )
25
			break;
26
		if ( data[pos] == '\0' )
27
		{
28
			end = true;
29
			break;
30
		}
31
		++pos;
32
	}
33
 
34
	if ( end )
35
	{
36
		*len = 0;
37
		*str = data;
38
		return NULL;
39
	}
40
 
41
	data[pos] = '\0';
42
	*str = data;
43
	data[pos] = '\n';
44
	*len -= (pos + 1);
45
 
46
	return data + (pos + 1);
47
}
48
 
4 cycrow 49
char *LineByLineRead ( char *data, long *len, CyString end, CyString *readData )
1 cycrow 50
{
4 cycrow 51
	CyString line;
1 cycrow 52
	while ( true )
53
	{
54
		data = ReadNextLine ( data, len, &line );
55
 
56
		if ( line == end )
57
			break;
58
		*readData += (line + "\n");
59
	}
60
 
61
	return data;
62
}
63
 
64
int main ( int argc, char **argv )
65
{
7 cycrow 66
	CConsoleLog::create();
67
 
8 cycrow 68
	Utils::String filename ( argv[0] );
69
	filename = filename.tokens("\\", -1, -1);
1 cycrow 70
 
71
	printf ( "SPKConvert V1.10 (SPK VERSION %.2f) 28/07/2007 by Cycrow\n", FILEVERSION );
72
 
73
	if ( argc < 3 )
74
	{
75
		printf ( "Syntax, %s <oldspkfile> <newspkfile>\n", filename.c_str() );
76
		exit ( 1 );
77
	}
78
 
8 cycrow 79
	Utils::String oldfile(argv[1]);
80
	Utils::String newfile(argv[2]);
1 cycrow 81
 
4 cycrow 82
 
83
	int ret = CBaseFile::CheckFile ( oldfile );
84
	if ( ret != SPKFILE_INVALID && ret != SPKFILE_OLD )
1 cycrow 85
	{
86
		printf ( "Spk file is already in the new format, unable to convert\n" );
87
		exit ( 1 );
88
	}
89
 
90
	// firstcheck if the file exists
91
	FILE *id = fopen ( argv[1], "rb" );
92
	if ( !id )
93
	{
94
		printf ( "Unable to open file: %s\n", argv[1] );
95
		exit ( 0 );
96
	}
97
 
7 cycrow 98
	// convert the old file
99
	CSpkFile newspkfile;
100
	newspkfile.convertOld(oldfile);
1 cycrow 101
 
102
	MyProgress *progress = new MyProgress ( 0 );
4 cycrow 103
 
1 cycrow 104
	// now save the spk file
105
	printf ( "\nStarting to write new spk file\n" );
7 cycrow 106
 
107
	//TODO: add multispk support
108
	/*
1 cycrow 109
	if ( mspk )
110
	{
111
		for ( SMultiSpkFile *it = mspk->GetFileList()->First(); it; it = mspk->GetFileList()->Next() )
112
		{
4 cycrow 113
			for ( C_File *f = it->pFile->GetFileList()->First(); f; f = it->pFile->GetFileList()->Next() )
1 cycrow 114
			{
115
				printf ( "* Compressing %s...\n\t>", f->GetNameDirectory(it->pFile).c_str() );
116
				if ( f->CompressData ( spkfile->GetDataCompression(), progress ) )
117
				{
118
					progress->PrintDone();
119
					printf ( "< (Done)\n" );
120
				}
121
				else
122
				{
123
					progress->Reset();
124
					printf ( "< (Error)\n" );
125
				}
126
			}
127
 
128
			FILE *id = tmpfile();
129
			if ( id )
130
			{
131
				it->pFile->WriteData ( id, NULL );
132
				it->lSize = ftell ( id );
133
				fclose ( id );
134
			}
135
		}
136
	}
137
	else
138
	{
7 cycrow 139
	*/
140
		for ( C_File *f = newspkfile.GetFileList()->First(); f; f = newspkfile.GetFileList()->Next() )
1 cycrow 141
		{
7 cycrow 142
			printf ( "* Compressing %s...\n\t>", f->GetNameDirectory(&newspkfile).c_str() );
143
			if ( f->CompressData ( newspkfile.GetDataCompression(), progress ) )
1 cycrow 144
			{
145
				progress->PrintDone();
146
				printf ( "< (Done)\n" );
147
			}
148
			else
149
			{
150
				progress->Reset();
151
				printf ( "< (Error)\n" );
152
			}
153
		}
7 cycrow 154
	//}
1 cycrow 155
 
156
	printf ( "* Writing to %s... ", argv[2] );
7 cycrow 157
	/*
1 cycrow 158
	if ( mspk )
159
	{
4 cycrow 160
		if ( mspk->WriteFile ( CyString(argv[2]) ) )
1 cycrow 161
			printf ( "(Done)\n" );
162
		else
163
			printf ( "(Error)\n" );
164
	}
165
	else
7 cycrow 166
	{*/
167
		newspkfile.WriteFile ( CyString(argv[2]) );
1 cycrow 168
		printf ( "(Done)\n" );
7 cycrow 169
	//}
1 cycrow 170
 
171
	printf ( "SPK file has been converted successfully\n" );
7 cycrow 172
//	CLEANUP
1 cycrow 173
 
174
	return 1;
175
}