Subversion Repositories spk

Rev

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