Subversion Repositories spk

Rev

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