1//
2// This file is part of the aMule Project.
3//
4// Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5// Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6//
7// Any parts of this program derived from the xMule, lMule or eMule project,
8// or contributed by third-party developers are copyrighted by their
9// respective authors.
10//
11// This program is free software; you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation; either version 2 of the License, or
14// (at your option) any later version.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
24//
25
26// The backtrace functions contain modified code from libYaMa, (c) Venkatesha Murthy G.
27// You can check libYaMa at http://personal.pavanashree.org/libyama/
28
29#include <tags/FileTags.h>
30
31#include <wx/filename.h>	// Needed for wxFileName
32#include <wx/log.h>		// Needed for wxLogNull
33
34#ifdef HAVE_CONFIG_H
35#include "config.h"		// Needed for a number of defines
36#endif
37
38#include <wx/stdpaths.h> // Do_not_auto_remove
39#include <common/StringFunctions.h>
40#include <common/ClientVersion.h>
41#include <common/MD5Sum.h>
42#include <common/Path.h>
43#include "MD4Hash.h"
44#include "Logger.h"
45#include "BitVector.h"		// Needed for BitVector
46
47#include "OtherFunctions.h"	// Interface declarations
48
49#include <map>
50
51#ifdef __WXBASE__
52	#include <cerrno>
53#else
54	#include <wx/utils.h>
55#endif
56
57
58wxString GetMuleVersion()
59{
60	wxString ver(wxT(VERSION));
61
62	ver += wxT(" compiled with ");
63
64
65	// Figure out the wx build-type
66	#if   defined(__WXGTK20__)
67		ver += wxT("wxGTK2");
68	#elif defined(__WXGTK__)
69		ver += wxT("wxGTK1");
70	// 2.9 has different builds for OSX: Carbon and Cocoa
71	#elif defined(__WXOSX_CARBON__)
72		ver += wxT("wxOSX Carbon");
73	#elif defined(__WXOSX_COCOA__)
74		ver += wxT("wxOSX Cocoa");
75	// different Cocoa port, "not been updated very actively since beginning 2008"
76	#elif defined(__WXCOCOA__)
77		ver += wxT("wxCocoa");
78	// 2.8 Mac
79	#elif defined(__WXMAC__)
80		ver += wxT("wxMac");
81	#elif defined(__WXMSW__) && defined(__VISUALC__)
82		ver += wxT("wxMSW VC");
83	#elif defined(__WXMSW__)
84		ver += wxT("wxMSW");
85	#endif
86
87	ver += CFormat(wxT(" v%d.%d.%d")) % wxMAJOR_VERSION % wxMINOR_VERSION % wxRELEASE_NUMBER;
88
89#ifdef __DEBUG__
90	ver += wxT(" (Debugging)");
91#endif
92
93#ifdef SVNDATE
94	ver += CFormat(wxT(" (Snapshot: %s)")) % wxT(SVNDATE);
95#endif
96
97	return ver;
98}
99
100
101// Formats a filesize in bytes to make it suitable for displaying
102wxString CastItoXBytes( uint64 count )
103{
104
105	if (count < 1024)
106		return CFormat(wxT("%u ")) % count + wxPLURAL("byte", "bytes", count) ;
107	else if (count < 1048576)
108		return CFormat(wxT("%u ")) % (count >> 10) + _("kB") ;
109	else if (count < 1073741824)
110		return CFormat(wxT("%.2f ")) % ((float)(uint32)count/1048576) + _("MB") ;
111	else if (count < 1099511627776LL)
112		return CFormat(wxT("%.3f ")) % ((float)((uint32)(count/1024))/1048576) + _("GB") ;
113	else
114		return CFormat(wxT("%.3f ")) % ((float)count/1099511627776LL) + _("TB") ;
115}
116
117
118wxString CastItoIShort(uint64 count)
119{
120
121	if (count < 1000)
122		return CFormat(wxT("%u")) % count;
123	else if (count < 1000000)
124		return CFormat(wxT("%.0f")) % ((float)(uint32)count/1000) + _("k") ;
125	else if (count < 1000000000)
126		return CFormat(wxT("%.2f")) % ((float)(uint32)count/1000000) + _("M") ;
127	else if (count < 1000000000000LL)
128		return CFormat(wxT("%.2f")) % ((float)((uint32)(count/1000))/1000000) + _("G") ;
129	else
130		return CFormat(wxT("%.2f")) % ((float)count/1000000000000LL) + _("T");
131}
132
133
134wxString CastItoSpeed(uint32 bytes)
135{
136	if (bytes < 1024)
137		return CFormat(wxT("%u ")) % bytes + wxPLURAL("byte/sec", "bytes/sec", bytes);
138	else if (bytes < 1048576)
139		return CFormat(wxT("%.2f ")) % (bytes / 1024.0) + _("kB/s");
140	else
141		return CFormat(wxT("%.2f ")) % (bytes / 1048576.0) + _("MB/s");
142}
143
144
145// Make a time value in seconds suitable for displaying
146wxString CastSecondsToHM(uint32 count, uint16 msecs)
147{
148	if (count < 60) {
149		if (!msecs) {
150			return CFormat(wxT("%02u %s")) % count % _("secs");
151		} else {
152			return CFormat(wxT("%.3f %s"))
153				% (count + ((float)msecs/1000)) % _("secs");
154		}
155	} else if (count < 3600) {
156		return CFormat(wxT("%u:%02u %s"))
157			% (count/60) % (count % 60) % _("mins");
158	} else if (count < 86400) {
159		return CFormat(wxT("%u:%02u %s"))
160			% (count/3600) % ((count % 3600)/60) % _("hours");
161	} else {
162		return CFormat(wxT("%u %s %02u:%02u %s"))
163			% (count/86400) % _("Days")
164			% ((count % 86400)/3600) % ((count % 3600)/60) % _("hours");
165	}
166}
167
168
169// Examines a filename and determines the filetype
170FileType GetFiletype(const CPath& filename)
171{
172	// FIXME: WTF do we have two such functions in the first place?
173	switch (GetED2KFileTypeID(filename)) {
174		case ED2KFT_AUDIO:	return ftAudio;
175		case ED2KFT_VIDEO:	return ftVideo;
176		case ED2KFT_IMAGE:	return ftPicture;
177		case ED2KFT_PROGRAM:	return ftProgram;
178		case ED2KFT_DOCUMENT:	return ftText;
179		case ED2KFT_ARCHIVE:	return ftArchive;
180		case ED2KFT_CDIMAGE:	return ftCDImage;
181		default:		return ftAny;
182	}
183}
184
185
186// Returns the (translated) description assosiated with a FileType
187wxString GetFiletypeDesc(FileType type, bool translated)
188{
189	switch ( type ) {
190		case ftVideo:
191			if (translated) {
192				return _("Videos");
193			} else {
194				return wxT("Videos");
195			}
196			break;
197		case ftAudio:
198			if (translated) {
199				return _("Audio");
200			} else {
201				return wxT("Audio");
202			}
203			break;
204		case ftArchive:
205			if (translated) {
206				return _("Archives");
207			} else {
208				return wxT("Archives");
209			}
210			break;
211		case ftCDImage:
212			if (translated) {
213				return _("CD-Images");
214			} else {
215				return wxT("CD-Images");
216			}
217			break;
218		case ftPicture:
219			if (translated) {
220				return _("Pictures");
221			} else {
222				return wxT("Pictures");
223			}
224			break;
225		case ftText:
226			if (translated) {
227				return _("Texts");
228			} else {
229				return wxT("Texts");
230			}
231			break;
232		case ftProgram:
233			if (translated) {
234				return _("Programs");
235			} else {
236				return wxT("Programs");
237			}
238			break;
239		default:
240			if (translated) {
241				return _("Any");
242			} else {
243				return wxT("Any");
244			}
245			break;
246	}
247}
248
249// Returns the Typename, examining the extention of the given filename
250
251wxString GetFiletypeByName(const CPath& filename, bool translated)
252{
253	return GetFiletypeDesc(GetFiletype(filename), translated);
254}
255
256
257// Return the text associated with a rating of a file
258wxString GetRateString(uint16 rate)
259{
260	switch ( rate ) {
261		case 0: return _("Not rated");
262		case 1: return _("Invalid / Corrupt / Fake");
263		case 2: return _("Poor");
264		case 3: return _("Fair");
265		case 4: return _("Good");
266		case 5: return _("Excellent");
267		default: return _("Not rated");
268	}
269}
270
271
272/**
273 * Return the size in bytes of the given size-type
274 *
275 * @param type The type (as an int) where: 0 = Byte, 1 = KB, 2 = MB, 3 = GB
276 *
277 * @return The amount of Bytes the provided size-type represents
278 *
279 * Values over GB aren't handled since the amount of Bytes 1TB represents
280 * is over the uint32 capacity
281 */
282uint32 GetTypeSize(uint8 type)
283{
284	enum {Bytes, KB, MB, GB};
285	int size;
286
287	switch(type) {
288		case Bytes: size = 1; break;
289		case KB: size = 1024; break;
290		case MB: size = 1048576; break;
291		case GB: size = 1073741824; break;
292		default: size = -1; break;
293	}
294	return size;
295}
296
297
298// Base16 chars for encode an decode functions
299static wxChar base16Chars[17] = wxT("0123456789ABCDEF");
300static wxChar base32Chars[33] = wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");
301#define BASE16_LOOKUP_MAX 23
302static wxChar base16Lookup[BASE16_LOOKUP_MAX][2] = {
303	{ wxT('0'), 0x0 },
304	{ wxT('1'), 0x1 },
305	{ wxT('2'), 0x2 },
306	{ wxT('3'), 0x3 },
307	{ wxT('4'), 0x4 },
308	{ wxT('5'), 0x5 },
309	{ wxT('6'), 0x6 },
310	{ wxT('7'), 0x7 },
311	{ wxT('8'), 0x8 },
312	{ wxT('9'), 0x9 },
313	{ wxT(':'), 0x9 },
314	{ wxT(';'), 0x9 },
315	{ wxT('<'), 0x9 },
316	{ wxT('='), 0x9 },
317	{ wxT('>'), 0x9 },
318	{ wxT('?'), 0x9 },
319	{ wxT('@'), 0x9 },
320	{ wxT('A'), 0xA },
321	{ wxT('B'), 0xB },
322	{ wxT('C'), 0xC },
323	{ wxT('D'), 0xD },
324	{ wxT('E'), 0xE },
325	{ wxT('F'), 0xF }
326};
327
328
329// Returns a BASE16 encoded byte array
330//
331// [In]
332//   buffer: Pointer to byte array
333//   bufLen: Lenght of buffer array
334//
335// [Return]
336//   wxString object with BASE16 encoded byte array
337wxString EncodeBase16(const unsigned char* buffer, unsigned int bufLen)
338{
339	wxString Base16Buff;
340
341	for(unsigned int i = 0; i < bufLen; ++i) {
342		Base16Buff += base16Chars[buffer[i] >> 4];
343		Base16Buff += base16Chars[buffer[i] & 0xf];
344	}
345
346	return Base16Buff;
347}
348
349
350// Decodes a BASE16 string into a byte array
351//
352// [In]
353//   base16Buffer: String containing BASE16
354//   base16BufLen: Lenght BASE16 coded string's length
355//
356// [Out]
357//   buffer: byte array containing decoded string
358unsigned int DecodeBase16(const wxString &base16Buffer, unsigned int base16BufLen, byte *buffer)
359{
360	if (base16BufLen & 1) {
361		return 0;
362	}
363	unsigned int ret = base16BufLen >> 1;
364	memset( buffer, 0,  ret);
365	for(unsigned int i = 0; i < base16BufLen; ++i) {
366		int lookup = toupper(base16Buffer[i]) - wxT('0');
367		// Check to make sure that the given word falls inside a valid range
368		byte word = (lookup < 0 || lookup >= BASE16_LOOKUP_MAX) ?
369			0xFF : base16Lookup[lookup][1];
370		unsigned idx = i >> 1;
371		buffer[idx] = (i & 1) ? // odd or even?
372			(buffer[idx] | word) : (word << 4);
373	}
374
375	return ret;
376}
377
378
379// Returns a BASE32 encoded byte array
380//
381// [In]
382//   buffer: Pointer to byte array
383//   bufLen: Lenght of buffer array
384//
385// [Return]
386//   wxString object with BASE32 encoded byte array
387wxString EncodeBase32(const unsigned char* buffer, unsigned int bufLen)
388{
389	wxString Base32Buff;
390	unsigned int i, index;
391	unsigned char word;
392
393	for(i = 0, index = 0; i < bufLen;) {
394		// Is the current word going to span a byte boundary?
395		if (index > 3) {
396			word = (buffer[i] & (0xFF >> index));
397			index = (index + 5) % 8;
398			word <<= index;
399			if (i < bufLen - 1) {
400				word |= buffer[i + 1] >> (8 - index);
401			}
402			++i;
403		} else {
404			word = (buffer[i] >> (8 - (index + 5))) & 0x1F;
405			index = (index + 5) % 8;
406			if (index == 0) {
407				++i;
408			}
409		}
410		Base32Buff += (char) base32Chars[word];
411	}
412
413	return Base32Buff;
414}
415
416
417// Decodes a BASE32 string into a byte array
418//
419// [In]
420//   base32Buffer: String containing BASE32
421//   base32BufLen: Lenght BASE32 coded string's length
422//
423// [Out]
424//   buffer: byte array containing decoded string
425// [Return]
426//   nDecodeLen:
427unsigned int DecodeBase32(const wxString &base32Buffer, unsigned int base32BufLen, unsigned char *buffer)
428{
429	size_t nInputLen = base32Buffer.Length();
430	uint32 nDecodeLen = (nInputLen * 5) / 8;
431	if ((nInputLen * 5) % 8 > 0) {
432		++nDecodeLen;
433	}
434	if (base32BufLen == 0) {
435		return nDecodeLen;
436	}
437	if (nDecodeLen > base32BufLen) {
438		return 0;
439	}
440
441	uint32 nBits = 0;
442	int nCount = 0;
443	for (size_t i = 0; i < nInputLen; ++i)
444	{
445		if (base32Buffer[i] >= wxT('A') && base32Buffer[i] <= wxT('Z')) {
446			nBits |= ( base32Buffer[i] - wxT('A') );
447		}
448		else if (base32Buffer[i] >= wxT('a') && base32Buffer[i] <= wxT('z')) {
449			nBits |= ( base32Buffer[i] - wxT('a') );
450		}
451		else if (base32Buffer[i] >= wxT('2') && base32Buffer[i] <= wxT('7')) {
452			nBits |= ( base32Buffer[i] - wxT('2') + 26 );
453		} else {
454			return 0;
455		}
456		nCount += 5;
457		if (nCount >= 8)
458		{
459			*buffer++ = (byte)( nBits >> (nCount - 8) );
460			nCount -= 8;
461		}
462		nBits <<= 5;
463	}
464
465	return nDecodeLen;
466}
467
468
469/*
470 * base64.c
471 *
472 * Base64 encoding/decoding command line filter
473 *
474 * Copyright (c) 2002-2011 Matthias Gaertner
475 * Adapted to use wxWidgets by
476 * Copyright (c) 2005-2011 Marcelo Roberto Jimenez ( phoenix@amule.org )
477 *
478 */
479static const wxString to_b64(
480	/*   0000000000111111111122222222223333333333444444444455555555556666 */
481	/*   0123456789012345678901234567890123456789012345678901234567890123 */
482	wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"));
483
484
485/* Option variables */
486static bool g_fUseCRLF = false;
487static unsigned int g_nCharsPerLine = 72;
488static wxString strHeaderLine;
489
490
491wxString EncodeBase64(const char *pbBufferIn, unsigned int bufLen)
492{
493	wxString pbBufferOut;
494	wxString strHeader;
495
496	if( !strHeaderLine.IsEmpty() ) {
497		strHeader = wxT("-----BEGIN ") + strHeaderLine + wxT("-----");
498		if( g_fUseCRLF ) {
499			strHeader += wxT("\r");
500		}
501		strHeader += wxT("\n");
502	}
503
504	unsigned long nDiv = ((unsigned long)bufLen) / 3;
505	unsigned long nRem = ((unsigned long)bufLen) % 3;
506	unsigned int NewLineSize = g_fUseCRLF ? 2 : 1;
507
508	// Allocate enough space in the output buffer to speed up things
509	pbBufferOut.Alloc(
510		strHeader.Len() * 2 +		// header/footer
511		(bufLen * 4) / 3 + 1 + 		// Number of codes
512		nDiv           * NewLineSize + 	// Number of new lines
513		(nRem ? 1 : 0) * NewLineSize );	// Last line
514	pbBufferOut = strHeader;
515
516	unsigned long nChars = 0;
517	const unsigned char *pIn = (unsigned char*)pbBufferIn;
518	while( nDiv > 0 ) {
519		pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
520		pbBufferOut += to_b64[((pIn[0] << 4) & 0x30) | ((pIn[1] >> 4) & 0xf)];
521		pbBufferOut += to_b64[((pIn[1] << 2) & 0x3c) | ((pIn[2] >> 6) & 0x3)];
522		pbBufferOut += to_b64[  pIn[2] & 0x3f];
523		pIn += 3;
524		nDiv--;
525		nChars += 4;
526		if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
527			nChars = 0;
528			if( g_fUseCRLF ) {
529				pbBufferOut += wxT("\r");
530			}
531			pbBufferOut += wxT("\n");
532		}
533	}
534	switch( nRem ) {
535	case 2:
536		pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
537		pbBufferOut += to_b64[((pIn[0] << 4) & 0x30) | ((pIn[1] >> 4) & 0xf)];
538		pbBufferOut += to_b64[ (pIn[1] << 2) & 0x3c];
539		pbBufferOut += wxT("=");
540		nChars += 4;
541		if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
542			nChars = 0;
543			if( g_fUseCRLF ) {
544				pbBufferOut += wxT("\r");
545			}
546			pbBufferOut += wxT("\n");
547		}
548		break;
549	case 1:
550		pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
551		pbBufferOut += to_b64[ (pIn[0] << 4) & 0x30];
552		pbBufferOut += wxT("=");
553		pbBufferOut += wxT("=");
554		nChars += 4;
555		if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
556			nChars = 0;
557			if( g_fUseCRLF ) {
558				pbBufferOut += wxT("\r");
559			}
560			pbBufferOut += wxT("\n");
561		}
562		break;
563	}
564
565	if( nRem > 0 ) {
566		if( nChars > 0 ) {
567			if( g_fUseCRLF ) {
568				pbBufferOut += wxT("\r");
569			}
570			pbBufferOut += wxT("\n");
571		}
572	}
573
574	if( !strHeaderLine.IsEmpty() ) {
575		pbBufferOut = wxT("-----END ") + strHeaderLine + wxT("-----");
576		if( g_fUseCRLF ) {
577			pbBufferOut += wxT("\r");
578		}
579		pbBufferOut += wxT("\n");
580	}
581
582	return pbBufferOut;
583}
584
585
586unsigned int DecodeBase64(const wxString &base64Buffer, unsigned int base64BufLen, unsigned char *buffer)
587{
588	int z = 0;  // 0 Normal, 1 skip MIME separator (---) to end of line
589	unsigned int nData = 0;
590	unsigned int i = 0;
591
592	if (base64BufLen == 0) {
593		*buffer = 0;
594		nData = 1;
595	}
596
597	for(unsigned int j = 0; j < base64BufLen; ++j) {
598		wxChar c = base64Buffer[j];
599		wxChar bits = wxT('z');
600		if( z > 0 ) {
601			if(c == wxT('\n')) {
602				z = 0;
603			}
604		}
605		else if(c >= wxT('A') && c <= wxT('Z')) {
606			bits = c - wxT('A');
607		}
608		else if(c >= wxT('a') && c <= wxT('z')) {
609			bits = c - wxT('a') + (wxChar)26;
610		}
611		else if(c >= wxT('0') && c <= wxT('9')) {
612			bits = c - wxT('0') + (wxChar)52;
613		}
614		else if(c == wxT('+')) {
615			bits = (wxChar)62;
616		}
617		else if(c == wxT('/')) {
618			bits = (wxChar)63;
619		}
620		else if(c == wxT('-')) {
621			z = 1;
622		}
623		else if(c == wxT('=')) {
624			break;
625		} else {
626			bits = wxT('y');
627		}
628
629		// Skips anything that was not recognized
630		// as a base64 valid char ('y' or 'z')
631		if (bits < (wxChar)64) {
632			switch (nData++) {
633			case 0:
634				buffer[i+0] = (bits << 2) & 0xfc;
635				break;
636			case 1:
637				buffer[i+0] |= (bits >> 4) & 0x03;
638				buffer[i+1] = (bits << 4) & 0xf0;
639				break;
640			case 2:
641				buffer[i+1] |= (bits >> 2) & 0x0f;
642				buffer[i+2] = (bits << 6) & 0xc0;
643				break;
644			case 3:
645				buffer[i+2] |= bits & 0x3f;
646				break;
647			}
648			if (nData == 4) {
649				nData = 0;
650				i += 3;
651			}
652		}
653	}
654	if (nData == 1) {
655		// Syntax error or buffer was empty
656		*buffer = 0;
657		nData = 0;
658		i = 0;
659	} else {
660		buffer[i+nData] = 0;
661	}
662
663	return i + nData;
664}
665
666
667// Returns the text assosiated with a category type
668wxString GetCatTitle(AllCategoryFilter cat)
669{
670	switch (cat) {
671		case acfAll:	 	 return _("all");
672		case acfAllOthers:   return _("all others");
673		case acfIncomplete:	 return _("Incomplete");
674		case acfCompleted:	 return _("Completed");
675		case acfWaiting:	 return _("Waiting");
676		case acfDownloading: return _("Downloading");
677		case acfErroneous:	 return _("Erroneous");
678		case acfPaused:		 return _("Paused");
679		case acfStopped:	 return _("Stopped");
680		case acfVideo:		 return _("Video");
681		case acfAudio:		 return _("Audio");
682		case acfArchive:	 return _("Archive");
683		case acfCDImages:	 return _("CD-Images");
684		case acfPictures:	 return _("Pictures");
685		case acfText:		 return _("Text");
686		case acfActive:		 return _("Active");
687		default: return wxT("?");
688	}
689}
690
691
692typedef std::map<wxString, EED2KFileTypeClass> SED2KFileTypeMap;
693typedef SED2KFileTypeMap::value_type SED2KFileTypeMapElement;
694static SED2KFileTypeMap ED2KFileTypesMap;
695
696
697class CED2KFileTypes{
698public:
699	CED2KFileTypes()
700	{
701		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".669"),   ED2KFT_AUDIO));		// 8 channel tracker module
702		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aac"),   ED2KFT_AUDIO));		// Advanced Audio Coding File
703		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ac3"),   ED2KFT_AUDIO));		// Audio Codec 3 File
704		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aif"),   ED2KFT_AUDIO));		// Audio Interchange File Format
705		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aifc"),  ED2KFT_AUDIO));		// Audio Interchange File Format
706		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aiff"),  ED2KFT_AUDIO));		// Audio Interchange File Format
707		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".amf"),   ED2KFT_AUDIO));		// DSMI Advanced Module Format
708		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".amr"),   ED2KFT_AUDIO));		// Adaptive Multi-Rate Codec File
709		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ams"),   ED2KFT_AUDIO));		// Extreme Tracker Module
710		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ape"),   ED2KFT_AUDIO));		// Monkey's Audio Lossless Audio File
711		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".au"),    ED2KFT_AUDIO));		// Audio File (Sun, Unix)
712		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aud"),   ED2KFT_AUDIO));		// General Audio File
713		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".audio"), ED2KFT_AUDIO));		// General Audio File
714		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cda"),   ED2KFT_AUDIO));		// CD Audio Track
715		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dbm"),   ED2KFT_AUDIO));
716		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmf"),   ED2KFT_AUDIO));		// Delusion Digital Music File
717		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dsm"),   ED2KFT_AUDIO));		// Digital Sound Module
718		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dts"),   ED2KFT_AUDIO));		// DTS Encoded Audio File
719		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".far"),   ED2KFT_AUDIO));		// Farandole Composer Module
720		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flac"),  ED2KFT_AUDIO));		// Free Lossless Audio Codec File
721		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".it"),    ED2KFT_AUDIO));		// Impulse Tracker Module
722		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m1a"),   ED2KFT_AUDIO));		// MPEG-1 Audio File
723		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2a"),   ED2KFT_AUDIO));		// MPEG-2 Audio File
724		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m4a"),   ED2KFT_AUDIO));		// MPEG-4 Audio File
725		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mdl"),   ED2KFT_AUDIO));		// DigiTrakker Module
726		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".med"),   ED2KFT_AUDIO));		// Amiga MED Sound File
727		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mid"),   ED2KFT_AUDIO));		// MIDI File
728		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".midi"),  ED2KFT_AUDIO));		// MIDI File
729		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mka"),   ED2KFT_AUDIO));		// Matroska Audio File
730		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mod"),   ED2KFT_AUDIO));		// Amiga Music Module File
731		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mol"),   ED2KFT_AUDIO));
732		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp1"),   ED2KFT_AUDIO));		// MPEG-1 Audio File
733		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp2"),   ED2KFT_AUDIO));		// MPEG-2 Audio File
734		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp3"),   ED2KFT_AUDIO));		// MPEG-3 Audio File
735		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpa"),   ED2KFT_AUDIO));		// MPEG Audio File
736		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpc"),   ED2KFT_AUDIO));		// Musepack Compressed Audio File
737		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpp"),   ED2KFT_AUDIO));
738		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mtm"),   ED2KFT_AUDIO));		// MultiTracker Module
739		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nst"),   ED2KFT_AUDIO));		// NoiseTracker
740		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ogg"),   ED2KFT_AUDIO));		// Ogg Vorbis Compressed Audio File
741		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".okt"),   ED2KFT_AUDIO));		// Oktalyzer Module (Amiga)
742		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psm"),   ED2KFT_AUDIO));		// Protracker Studio Module
743		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ptm"),   ED2KFT_AUDIO));		// PolyTracker Module
744		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ra"),    ED2KFT_AUDIO));		// Real Audio File
745		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmi"),   ED2KFT_AUDIO));		// MIDI File
746		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".s3m"),   ED2KFT_AUDIO));		// Scream Tracker 3 Module
747		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".snd"),   ED2KFT_AUDIO));		// Audio File (Sun, Unix)
748		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".stm"),   ED2KFT_AUDIO));		// Scream Tracker 2 Module
749		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ult"),   ED2KFT_AUDIO));		// UltraTracker
750		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".umx"),   ED2KFT_AUDIO));		// Unreal Music Package
751		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wav"),   ED2KFT_AUDIO));		// WAVE Audio File
752		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wma"),   ED2KFT_AUDIO));		// Windows Media Audio File
753		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wow"),   ED2KFT_AUDIO));		// Grave Composer audio tracker
754		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xm"),    ED2KFT_AUDIO));		// Fasttracker 2 Extended Module
755
756		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3g2"),   ED2KFT_VIDEO));		// 3GPP Multimedia File
757		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3gp"),   ED2KFT_VIDEO));		// 3GPP Multimedia File
758		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3gp2"),  ED2KFT_VIDEO));		// 3GPP Multimedia File
759		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3gpp"),  ED2KFT_VIDEO));		// 3GPP Multimedia File
760		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".asf"),   ED2KFT_VIDEO));		// Advanced Systems Format (MS)
761		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".amv"),   ED2KFT_VIDEO));		// Anime Music Video File
762		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".asf"),   ED2KFT_VIDEO));		// Advanced Systems Format File
763		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".avi"),   ED2KFT_VIDEO));		// Audio Video Interleave File
764		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bik"),   ED2KFT_VIDEO));		// BINK Video File
765		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".divx"),  ED2KFT_VIDEO));		// DivX-Encoded Movie File
766		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dvr-ms"),ED2KFT_VIDEO));		// Microsoft Digital Video Recording
767		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flc"),   ED2KFT_VIDEO));		// FLIC Video File
768		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".fli"),   ED2KFT_VIDEO));		// FLIC Video File
769		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flic"),  ED2KFT_VIDEO));		// FLIC Video File
770		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flv"),   ED2KFT_VIDEO));		// Flash Video File
771		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hdmov"), ED2KFT_VIDEO));		// High-Definition QuickTime Movie
772		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ifo"),   ED2KFT_VIDEO));		// DVD-Video Disc Information File
773		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m1v"),   ED2KFT_VIDEO));		// MPEG-1 Video File
774		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2t"),   ED2KFT_VIDEO));		// MPEG-2 Video Transport Stream
775		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2ts"),  ED2KFT_VIDEO));		// MPEG-2 Video Transport Stream
776		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2v"),   ED2KFT_VIDEO));		// MPEG-2 Video File
777		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m4b"),   ED2KFT_VIDEO));		// MPEG-4 Video File
778		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m4v"),   ED2KFT_VIDEO));		// MPEG-4 Video File
779		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mkv"),   ED2KFT_VIDEO));		// Matroska Video File
780		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mov"),   ED2KFT_VIDEO));		// QuickTime Movie File
781		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".movie"), ED2KFT_VIDEO));		// QuickTime Movie File
782		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp1v"),  ED2KFT_VIDEO));		// QuickTime Movie File
783		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp2v"),  ED2KFT_VIDEO));		// MPEG-1 Video File
784		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp4"),   ED2KFT_VIDEO));		// MPEG-2 Video File
785		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpe"),   ED2KFT_VIDEO));		// MPEG-4 Video File
786		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpeg"),  ED2KFT_VIDEO));		// MPEG Video File
787		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpg"),   ED2KFT_VIDEO));		// MPEG Video File
788		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mps"),   ED2KFT_VIDEO));		// MPEG Video File
789		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv"),   ED2KFT_VIDEO));		// MPEG Video File
790		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv1"),  ED2KFT_VIDEO));		// MPEG-1 Video File
791		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv2"),  ED2KFT_VIDEO));		// MPEG-2 Video File
792		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ogm"),   ED2KFT_VIDEO));		// Ogg Media File
793		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ogv"),   ED2KFT_VIDEO));		// Ogg Theora Video File
794		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pva"),   ED2KFT_VIDEO));		// MPEG Video File
795		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".qt"),    ED2KFT_VIDEO));		// QuickTime Movie
796		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ram"),   ED2KFT_VIDEO));		// Real Audio Media
797		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ratdvd"),ED2KFT_VIDEO));		// RatDVD Disk Image
798		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rm"),    ED2KFT_VIDEO));		// Real Media File
799		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmm"),   ED2KFT_VIDEO));		// Real Media File
800		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmvb"),  ED2KFT_VIDEO));		// Real Video Variable Bit Rate File
801		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rv"),    ED2KFT_VIDEO));		// Real Video File
802		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rv9"),   ED2KFT_VIDEO));
803		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".smil"),  ED2KFT_VIDEO));		// SMIL Presentation File
804		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".smk"),   ED2KFT_VIDEO));		// Smacker Compressed Movie File
805		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".swf"),   ED2KFT_VIDEO));		// Macromedia Flash Movie
806		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tp"),    ED2KFT_VIDEO));		// Video Transport Stream File
807		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ts"),    ED2KFT_VIDEO));		// Video Transport Stream File
808		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vid"),   ED2KFT_VIDEO));		// General Video File
809		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".video"), ED2KFT_VIDEO));		// General Video File
810		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vivo"),  ED2KFT_VIDEO));		// VivoActive Video File
811		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vob"),   ED2KFT_VIDEO));		// DVD Video Object File
812		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vp6"),   ED2KFT_VIDEO));		// TrueMotion VP6 Video File
813		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".webm"),  ED2KFT_VIDEO));		// WebM Video File
814		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wm"),    ED2KFT_VIDEO));		// Windows Media Video File
815		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmv"),   ED2KFT_VIDEO));		// Windows Media Video File
816		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xvid"),  ED2KFT_VIDEO));		// Xvid-Encoded Video File
817
818		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bmp"),   ED2KFT_IMAGE));		// Bitmap Image File
819		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dcx"),   ED2KFT_IMAGE));		// FAXserve Fax Document
820		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".emf"),   ED2KFT_IMAGE));		// Enhanced Windows Metafile
821		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".gif"),   ED2KFT_IMAGE));		// Graphical Interchange Format File
822		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ico"),   ED2KFT_IMAGE));		// Icon File
823		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jfif"),  ED2KFT_IMAGE));		// JPEG File Interchange Format
824		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpe"),   ED2KFT_IMAGE));		// JPEG Image File
825		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpeg"),  ED2KFT_IMAGE));		// JPEG Image File
826		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpg"),   ED2KFT_IMAGE));		// JPEG Image File
827		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pct"),   ED2KFT_IMAGE));		// PICT Picture File
828		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pcx"),   ED2KFT_IMAGE));		// Paintbrush Bitmap Image File
829		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pic"),   ED2KFT_IMAGE));		// PICT Picture File
830		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pict"),  ED2KFT_IMAGE));		// PICT Picture File
831		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".png"),   ED2KFT_IMAGE));		// Portable Network Graphic
832		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psd"),   ED2KFT_IMAGE));		// Photoshop Document
833		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psp"),   ED2KFT_IMAGE));		// Paint Shop Pro Image File
834		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tga"),   ED2KFT_IMAGE));		// Targa Graphic
835		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tif"),   ED2KFT_IMAGE));		// Tagged Image File
836		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tiff"),  ED2KFT_IMAGE));		// Tagged Image File
837		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wbmp"),  ED2KFT_IMAGE));		// Wireless Application Protocol Bitmap Format
838		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".webp"),  ED2KFT_IMAGE));		// Weppy Photo File
839		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmf"),   ED2KFT_IMAGE));		// Windows Metafile
840		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmp"),   ED2KFT_IMAGE));		// Windows Media Photo File
841		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xif"),   ED2KFT_IMAGE));		// ScanSoft Pagis Extended Image Format File
842		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xpm"),   ED2KFT_IMAGE));		// X-Windows Pixmap
843
844		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".7z"),    ED2KFT_ARCHIVE));	// 7-Zip Compressed File
845		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ace"),   ED2KFT_ARCHIVE));	// WinAce Compressed File
846		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".alz"),   ED2KFT_ARCHIVE));	// ALZip Archive
847		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".arc"),   ED2KFT_ARCHIVE));	// Compressed File Archive
848		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".arj"),   ED2KFT_ARCHIVE));	// ARJ Compressed File Archive
849		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bz2"),   ED2KFT_ARCHIVE));	// Bzip Compressed File
850		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cab"),   ED2KFT_ARCHIVE));	// Cabinet File
851		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cbr"),   ED2KFT_ARCHIVE));	// Comic Book RAR Archive
852		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cbt"),   ED2KFT_ARCHIVE));	// Comic Book Tarball
853		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cbz"),   ED2KFT_ARCHIVE));	// Comic Book ZIP Archive
854		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".gz"),    ED2KFT_ARCHIVE));	// Gnu Zipped File
855		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hqx"),   ED2KFT_ARCHIVE));	// BinHex 4.0 Encoded File
856		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".lha"),   ED2KFT_ARCHIVE));	// LHARC Compressed Archive
857		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".lzh"),   ED2KFT_ARCHIVE));	// LZH Compressed File
858		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".msi"),   ED2KFT_ARCHIVE));	// Microsoft Installer File
859		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pak"),   ED2KFT_ARCHIVE));	// PAK (Packed) File
860		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".par"),   ED2KFT_ARCHIVE));	// Parchive Index File
861		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".par2"),  ED2KFT_ARCHIVE));	// Parchive 2 Index File
862		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rar"),   ED2KFT_ARCHIVE));	// WinRAR Compressed Archive
863		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sea"),   ED2KFT_ARCHIVE));	// Self-Extracting Archive (Mac)
864		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sit"),   ED2KFT_ARCHIVE));	// Stuffit Archive
865		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sitx"),  ED2KFT_ARCHIVE));	// Stuffit X Archive
866		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tar"),   ED2KFT_ARCHIVE));	// Consolidated Unix File Archive
867		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tbz2"),  ED2KFT_ARCHIVE));	// Tar BZip 2 Compressed File
868		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tgz"),   ED2KFT_ARCHIVE));	// Gzipped Tar File
869		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".uc2"),   ED2KFT_ARCHIVE));	// UltraCompressor 2 Archive
870		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xpi"),   ED2KFT_ARCHIVE));	// Mozilla Installer Package
871		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".z"),     ED2KFT_ARCHIVE));	// Unix Compressed File
872		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".zip"),   ED2KFT_ARCHIVE));	// Zipped File
873		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".zoo"),   ED2KFT_ARCHIVE));	// Zoo Archive
874
875		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bat"),   ED2KFT_PROGRAM));	// Batch File
876		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cmd"),   ED2KFT_PROGRAM));	// Command File
877		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".com"),   ED2KFT_PROGRAM));	// COM File
878		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".exe"),   ED2KFT_PROGRAM));	// Executable File
879		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hta"),   ED2KFT_PROGRAM));	// HTML Application
880		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".js"),    ED2KFT_PROGRAM));	// Java Script
881		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jse"),   ED2KFT_PROGRAM));	// Encoded  Java Script
882		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".msc"),   ED2KFT_PROGRAM));	// Microsoft Common Console File
883		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vbe"),   ED2KFT_PROGRAM));	// Encoded Visual Basic Script File
884		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vbs"),   ED2KFT_PROGRAM));	// Visual Basic Script File
885		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wsf"),   ED2KFT_PROGRAM));	// Windows Script File
886		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wsh"),   ED2KFT_PROGRAM));	// Windows Scripting Host File
887
888		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bin"),   ED2KFT_CDIMAGE));	// CD Image
889		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwa"),   ED2KFT_CDIMAGE));	// BlindWrite Disk Information File
890		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwi"),   ED2KFT_CDIMAGE));	// BlindWrite CD/DVD Disc Image
891		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bws"),   ED2KFT_CDIMAGE));	// BlindWrite Sub Code File
892		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwt"),   ED2KFT_CDIMAGE));	// BlindWrite 4 Disk Image
893		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ccd"),   ED2KFT_CDIMAGE));	// CloneCD Disk Image
894		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cue"),   ED2KFT_CDIMAGE));	// Cue Sheet File
895		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmg"),   ED2KFT_CDIMAGE));	// Mac OS X Disk Image
896		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmz"),   ED2KFT_CDIMAGE));
897		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".img"),   ED2KFT_CDIMAGE));	// Disk Image Data File
898		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".iso"),   ED2KFT_CDIMAGE));	// Disc Image File
899		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mdf"),   ED2KFT_CDIMAGE));	// Media Disc Image File
900		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mds"),   ED2KFT_CDIMAGE));	// Media Descriptor File
901		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nrg"),   ED2KFT_CDIMAGE));	// Nero CD/DVD Image File
902		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sub"),   ED2KFT_CDIMAGE));	// Subtitle File
903		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".toast"), ED2KFT_CDIMAGE));	// Toast Disc Image
904
905		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".chm"),   ED2KFT_DOCUMENT));	// Compiled HTML Help File
906		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".css"),   ED2KFT_DOCUMENT));	// Cascading Style Sheet
907		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".diz"),   ED2KFT_DOCUMENT));	// Description in Zip File
908		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".doc"),   ED2KFT_DOCUMENT));	// Document File
909		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dot"),   ED2KFT_DOCUMENT));	// Document Template File
910		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hlp"),   ED2KFT_DOCUMENT));	// Help File
911		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".htm"),   ED2KFT_DOCUMENT));	// HTML File
912		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".html"),  ED2KFT_DOCUMENT));	// HTML File
913		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nfo"),   ED2KFT_DOCUMENT));	// Warez Information File
914		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".odp"),   ED2KFT_DOCUMENT));	// OpenDocument Presentation
915		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ods"),   ED2KFT_DOCUMENT));	// OpenDocument Spreadsheet
916		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".odt"),   ED2KFT_DOCUMENT));	// OpenDocument File
917		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".otp"),   ED2KFT_DOCUMENT));	// OpenDocument Presentation Template
918		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ott"),   ED2KFT_DOCUMENT));	// OpenDocument Template File
919		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ots"),   ED2KFT_DOCUMENT));	// OpenDocument Spreadsheet Template
920		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pdf"),   ED2KFT_DOCUMENT));	// Portable Document Format File
921		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pps"),   ED2KFT_DOCUMENT));	// PowerPoint Slide Show
922		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ppt"),   ED2KFT_DOCUMENT));	// PowerPoint Presentation
923		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ps"),    ED2KFT_DOCUMENT));	// PostScript File
924		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rtf"),   ED2KFT_DOCUMENT));	// Rich Text Format File
925		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".stc"),   ED2KFT_DOCUMENT));	// OpenOffice.org 1.0 Spreadsheet Template
926		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sti"),   ED2KFT_DOCUMENT));	// OpenOffice.org 1.0 Presentation Template
927		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".stw"),   ED2KFT_DOCUMENT));	// OpenOffice.org 1.0 Document Template File
928		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sxc"),   ED2KFT_DOCUMENT));	// OpenOffice.org 1.0 Spreadsheet
929		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sxi"),   ED2KFT_DOCUMENT));	// OpenOffice.org 1.0 Presentation
930		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sxw"),   ED2KFT_DOCUMENT));	// OpenOffice.org 1.0 Document File
931		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".text"),  ED2KFT_DOCUMENT));	// General Text File
932		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".txt"),   ED2KFT_DOCUMENT));	// Text File
933		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wri"),   ED2KFT_DOCUMENT));	// Windows Write Document
934		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xls"),   ED2KFT_DOCUMENT));	// Microsoft Excel Spreadsheet
935		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xlt"),   ED2KFT_DOCUMENT));	// Microsoft Excel Template
936		ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xml"),   ED2KFT_DOCUMENT));	// XML File
937	}
938};
939
940
941// get the list initialized *before* any code is accessing it
942CED2KFileTypes theED2KFileTypes;
943
944EED2KFileType GetED2KFileTypeID(const CPath& fileName)
945{
946	const wxString ext = fileName.GetExt().Lower();
947	if (ext.IsEmpty()) {
948		return ED2KFT_ANY;
949	}
950
951	SED2KFileTypeMap::iterator it = ED2KFileTypesMap.find(wxT(".") + ext);
952	if (it != ED2KFileTypesMap.end()) {
953		return it->second.GetType();
954	} else {
955		return ED2KFT_ANY;
956	}
957}
958
959
960// Retuns the ed2k file type term which is to be used in server searches
961wxString GetED2KFileTypeSearchTerm(EED2KFileType iFileID)
962{
963	if (iFileID == ED2KFT_AUDIO)		return ED2KFTSTR_AUDIO;
964	if (iFileID == ED2KFT_VIDEO)		return ED2KFTSTR_VIDEO;
965	if (iFileID == ED2KFT_IMAGE)		return ED2KFTSTR_IMAGE;
966	if (iFileID == ED2KFT_DOCUMENT)		return ED2KFTSTR_DOCUMENT;
967	if (iFileID == ED2KFT_PROGRAM)		return ED2KFTSTR_PROGRAM;
968	// NOTE: Archives and CD-Images are published with file type "Pro"
969	if (iFileID == ED2KFT_ARCHIVE)		return ED2KFTSTR_PROGRAM;
970	if (iFileID == ED2KFT_CDIMAGE)		return ED2KFTSTR_PROGRAM;
971
972	return wxEmptyString;
973}
974
975
976// Returns a file type which is used eMule internally only, examining the extention of the given filename
977wxString GetFileTypeByName(const CPath& fileName)
978{
979	EED2KFileType iFileType = GetED2KFileTypeID(fileName);
980	switch (iFileType) {
981		case ED2KFT_AUDIO:	return ED2KFTSTR_AUDIO;
982		case ED2KFT_VIDEO:	return ED2KFTSTR_VIDEO;
983		case ED2KFT_IMAGE:	return ED2KFTSTR_IMAGE;
984		case ED2KFT_DOCUMENT:	return ED2KFTSTR_DOCUMENT;
985		case ED2KFT_PROGRAM:	return ED2KFTSTR_PROGRAM;
986		case ED2KFT_ARCHIVE:	return ED2KFTSTR_ARCHIVE;
987		case ED2KFT_CDIMAGE:	return ED2KFTSTR_CDIMAGE;
988		default:		return wxEmptyString;
989	}
990}
991
992
993// Retuns the ed2k file type integer ID which is to be used for publishing+searching
994EED2KFileType GetED2KFileTypeSearchID(EED2KFileType iFileID)
995{
996	switch (iFileID) {
997		case ED2KFT_AUDIO:	return ED2KFT_AUDIO;
998		case ED2KFT_VIDEO:	return ED2KFT_VIDEO;
999		case ED2KFT_IMAGE:	return ED2KFT_IMAGE;
1000		case ED2KFT_DOCUMENT:	return ED2KFT_DOCUMENT;
1001		case ED2KFT_PROGRAM:	return ED2KFT_PROGRAM;
1002		// NOTE: Archives and CD-Images are published+searched with file type "Pro"
1003		// NOTE: If this gets changed, the function 'GetED2KFileTypeSearchTerm' also needs to get updated!
1004		case ED2KFT_ARCHIVE:	return ED2KFT_PROGRAM;
1005		case ED2KFT_CDIMAGE:	return ED2KFT_PROGRAM;
1006		default:		return  ED2KFT_ANY;
1007	}
1008}
1009
1010
1011/**
1012 * Dumps a buffer to a wxString
1013 */
1014wxString DumpMemToStr(const void *buff, int n, const wxString& msg, bool ok)
1015{
1016	const unsigned char *p = (const unsigned char *)buff;
1017	int lines = (n + 15)/ 16;
1018
1019	wxString result;
1020	// Allocate aproximetly what is needed
1021	result.Alloc( ( lines + 1 ) * 80 );
1022	if ( !msg.IsEmpty() ) {
1023		result += msg + wxT(" - ok=") + ( ok ? wxT("true, ") : wxT("false, ") );
1024	}
1025
1026	result += CFormat(wxT("%d bytes\n")) % n;
1027	for ( int i = 0; i < lines; ++i) {
1028		// Show address
1029		result += CFormat(wxT("%08x  ")) % (i * 16);
1030
1031		// Show two columns of hex-values
1032		for ( int j = 0; j < 2; ++j) {
1033			for ( int k = 0; k < 8; ++k) {
1034				int pos = 16 * i + 8 * j + k;
1035
1036				if ( pos < n ) {
1037					result += CFormat(wxT("%02x ")) % p[pos];
1038				} else {
1039					result += wxT("   ");
1040				}
1041			}
1042			result += wxT(" ");
1043		}
1044		result += wxT("|");
1045		// Show a column of ascii-values
1046		for ( int k = 0; k < 16; ++k) {
1047			int pos = 16 * i + k;
1048
1049			if ( pos < n ) {
1050				if ( isspace( p[pos] ) ) {
1051					result += wxT(" ");
1052				} else if ( !isgraph( p[pos] ) ) {
1053					result += wxT(".");
1054				} else {
1055					result += (wxChar)p[pos];
1056				}
1057			} else {
1058				result += wxT(" ");
1059			}
1060		}
1061		result += wxT("|\n");
1062	}
1063	result.Shrink();
1064
1065	return result;
1066}
1067
1068
1069/**
1070 * Dumps a buffer to stdout
1071 */
1072void DumpMem(const void *buff, int n, const wxString& msg, bool ok)
1073{
1074	printf("%s\n", (const char*)unicode2char(DumpMemToStr( buff, n, msg, ok )) );
1075}
1076
1077
1078//
1079// Dump mem in dword format
1080void DumpMem_DW(const uint32 *ptr, int count)
1081{
1082	for(int i = 0; i < count; i++) {
1083		printf("%08x ", ptr[i]);
1084		if ( (i % 4) == 3) printf("\n");
1085	}
1086	printf("\n");
1087}
1088
1089
1090wxString GetConfigDir(const wxString &configFileBase)
1091{
1092	// Cache the path.
1093	static wxString configPath;
1094
1095	if (configPath.IsEmpty()) {
1096		// "Portable aMule" - Use aMule from an external USB drive
1097		// Check for ./config/amule.conf (or whatever gets passed as configFile)
1098		// and use this configuration if found
1099		const wxString configDir = JoinPaths(wxFileName::GetCwd(), wxT("config"));
1100		const wxString configFile = JoinPaths(configDir, configFileBase);
1101
1102		if (CPath::DirExists(configDir) && CPath::FileExists(configFile)) {
1103			AddLogLineN(CFormat(_("Using config dir: %s")) % configDir);
1104
1105			configPath = configDir;
1106		} else {
1107			configPath = wxStandardPaths::Get().GetUserDataDir();
1108		}
1109
1110		configPath += wxFileName::GetPathSeparator();
1111	}
1112
1113	return configPath;
1114}
1115
1116
1117/*************************** Locale specific stuff ***************************/
1118
1119#ifndef __WXMSW__
1120#	define	SETWINLANG(LANG, SUBLANG)
1121#else
1122#	define	SETWINLANG(LANG, SUBLANG) \
1123	info.WinLang = LANG; \
1124	info.WinSublang = SUBLANG;
1125#endif
1126
1127#define CUSTOMLANGUAGE(wxid, iso, winlang, winsublang, dir, desc) \
1128	info.Language = wxid;		\
1129	info.CanonicalName = wxT(iso);	\
1130	info.LayoutDirection = dir;	\
1131	info.Description = wxT(desc);	\
1132	SETWINLANG(winlang, winsublang)	\
1133	wxLocale::AddLanguage(info);
1134
1135void InitCustomLanguages()
1136{
1137	wxLanguageInfo info;
1138
1139#if !wxCHECK_VERSION(2, 9, 0)
1140	CUSTOMLANGUAGE(wxLANGUAGE_ASTURIAN,	"ast",	0,	0,	wxLayout_LeftToRight,	"Asturian");
1141#endif
1142}
1143
1144
1145void InitLocale(wxLocale& locale, int language)
1146{
1147	locale.Init(language, wxLOCALE_LOAD_DEFAULT);
1148
1149#if defined(__WXMAC__) || defined(__WXMSW__)
1150	locale.AddCatalogLookupPathPrefix(JoinPaths(wxStandardPaths::Get().GetDataDir(), wxT("locale")));
1151#endif
1152	locale.AddCatalog(wxT(PACKAGE));
1153}
1154
1155
1156int StrLang2wx(const wxString& language)
1157{
1158	// get rid of possible encoding and modifier
1159	wxString lang(language.BeforeFirst('.').BeforeFirst('@'));
1160
1161	if (!lang.IsEmpty()) {
1162		const wxLanguageInfo *lng = wxLocale::FindLanguageInfo(lang);
1163		if (lng) {
1164			int langID = lng->Language;
1165			// Traditional Chinese: original Chinese, used in Taiwan, Hong Kong and Macau.
1166			// Simplified Chinese: simplified Chinese characters used in Mainland China since 1950s, and in some other places such as Singapore and Malaysia.
1167			//
1168			// Chinese (Traditional) contains zh_TW, zh_HK and zh_MO (but there are differences in some words).
1169			// Because of most Traditional Chinese user are in Taiwan, zh_TW becomes the representation of Traditional Chinese.
1170			// Chinese (Simplified) contains zh_CN, zh_SG and zh_MY. In the same reason, zh_CN becomes the representation of Simplified Chinese.
1171			// (see http://forum.amule.org/index.php?topic=13208.msg98043#msg98043 )
1172			//
1173			// wx maps "Traditional Chinese" to "Chinese" however. This must me corrected:
1174			if (langID == wxLANGUAGE_CHINESE) {
1175				langID = wxLANGUAGE_CHINESE_TRADITIONAL;
1176			}
1177			return langID;
1178		} else {
1179			return wxLANGUAGE_DEFAULT;
1180		}
1181	} else {
1182		return wxLANGUAGE_DEFAULT;
1183	}
1184}
1185
1186
1187wxString wxLang2Str(const int lang)
1188{
1189	if (lang != wxLANGUAGE_DEFAULT) {
1190		const wxLanguageInfo *lng = wxLocale::GetLanguageInfo(lang);
1191		if (lng) {
1192			return lng->CanonicalName;
1193		} else {
1194			return wxEmptyString;
1195		}
1196	} else {
1197		return wxEmptyString;
1198	}
1199}
1200
1201/*****************************************************************************/
1202
1203wxString GetPassword() {
1204wxString pass_plain;
1205CMD4Hash password;
1206		#ifndef __WXMSW__
1207			pass_plain = char2unicode(getpass("Enter password for mule connection: "));
1208		#else
1209			//#warning This way, pass enter is not hidden on windows. Bad thing.
1210			char temp_str[512];
1211			fflush(stdin);
1212			printf("Enter password for mule connection: \n");
1213			fflush(stdout);
1214			fgets(temp_str, 512, stdin);
1215			temp_str[strlen(temp_str)-1] = '\0';
1216			pass_plain = char2unicode(temp_str);
1217		#endif
1218		wxCHECK2(password.Decode(MD5Sum(pass_plain).GetHash()), /* Do nothing. */ );
1219		// MD5 hash for an empty string, according to rfc1321.
1220		if (password.Encode() == wxT("D41D8CD98F00B204E9800998ECF8427E")) {
1221			printf("No empty password allowed.\n");
1222			return GetPassword();
1223		}
1224
1225
1226return password.Encode();
1227}
1228
1229
1230const uint8 BitVector::s_posMask[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
1231const uint8 BitVector::s_negMask[] = {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F};
1232
1233// File_checked_for_headers
1234