Improve speed of category tab title updates
[amule.git] / src / OtherFunctions.cpp
blob443338a3bfe523f65167b6ef8daf63e228a9ad8f
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 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.
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.
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
26 // The backtrace functions contain modified code from libYaMa, (c) Venkatesha Murthy G.
27 // You can check libYaMa at http://personal.pavanashree.org/libyama/
29 #include <tags/FileTags.h>
31 #include <wx/filename.h> // Needed for wxFileName
32 #include <wx/log.h> // Needed for wxLogNull
34 #ifdef HAVE_CONFIG_H
35 #include "config.h" // Needed for a number of defines
36 #endif
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
47 #include "OtherFunctions.h" // Interface declarations
49 #include <map>
51 #ifdef __WXBASE__
52 #include <cerrno>
53 #else
54 #include <wx/utils.h>
55 #endif
58 wxString GetMuleVersion()
60 wxString ver(wxT(VERSION));
62 ver += wxT(" compiled with ");
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
87 ver += CFormat(wxT(" v%d.%d.%d")) % wxMAJOR_VERSION % wxMINOR_VERSION % wxRELEASE_NUMBER;
89 #ifdef __WXDEBUG__
90 ver += wxT(" (Debugging)");
91 #endif
93 #ifdef SVNDATE
94 ver += CFormat(wxT(" (Snapshot: %s)")) % wxT(SVNDATE);
95 #endif
97 return ver;
101 // Formats a filesize in bytes to make it suitable for displaying
102 wxString CastItoXBytes( uint64 count )
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") ;
118 wxString CastItoIShort(uint64 count)
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");
134 wxString CastItoSpeed(uint32 bytes)
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");
145 // Make a time value in seconds suitable for displaying
146 wxString CastSecondsToHM(uint32 count, uint16 msecs)
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");
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");
169 // Examines a filename and determines the filetype
170 FileType GetFiletype(const CPath& filename)
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;
186 // Returns the (translated) description assosiated with a FileType
187 wxString GetFiletypeDesc(FileType type, bool translated)
189 switch ( type ) {
190 case ftVideo:
191 if (translated) {
192 return _("Videos");
193 } else {
194 return wxT("Videos");
196 break;
197 case ftAudio:
198 if (translated) {
199 return _("Audio");
200 } else {
201 return wxT("Audio");
203 break;
204 case ftArchive:
205 if (translated) {
206 return _("Archives");
207 } else {
208 return wxT("Archives");
210 break;
211 case ftCDImage:
212 if (translated) {
213 return _("CD-Images");
214 } else {
215 return wxT("CD-Images");
217 break;
218 case ftPicture:
219 if (translated) {
220 return _("Pictures");
221 } else {
222 return wxT("Pictures");
224 break;
225 case ftText:
226 if (translated) {
227 return _("Texts");
228 } else {
229 return wxT("Texts");
231 break;
232 case ftProgram:
233 if (translated) {
234 return _("Programs");
235 } else {
236 return wxT("Programs");
238 break;
239 default:
240 if (translated) {
241 return _("Any");
242 } else {
243 return wxT("Any");
245 break;
249 // Returns the Typename, examining the extention of the given filename
251 wxString GetFiletypeByName(const CPath& filename, bool translated)
253 return GetFiletypeDesc(GetFiletype(filename), translated);
257 // Return the text associated with a rating of a file
258 wxString GetRateString(uint16 rate)
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");
273 * Return the size in bytes of the given size-type
275 * @param type The type (as an int) where: 0 = Byte, 1 = KB, 2 = MB, 3 = GB
277 * @return The amount of Bytes the provided size-type represents
279 * Values over GB aren't handled since the amount of Bytes 1TB represents
280 * is over the uint32 capacity
282 uint32 GetTypeSize(uint8 type)
284 enum {Bytes, KB, MB, GB};
285 int size;
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;
294 return size;
298 // Base16 chars for encode an decode functions
299 static wxChar base16Chars[17] = wxT("0123456789ABCDEF");
300 static wxChar base32Chars[33] = wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");
301 #define BASE16_LOOKUP_MAX 23
302 static 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 }
329 // Returns a BASE16 encoded byte array
331 // [In]
332 // buffer: Pointer to byte array
333 // bufLen: Lenght of buffer array
335 // [Return]
336 // wxString object with BASE16 encoded byte array
337 wxString EncodeBase16(const unsigned char* buffer, unsigned int bufLen)
339 wxString Base16Buff;
341 for(unsigned int i = 0; i < bufLen; ++i) {
342 Base16Buff += base16Chars[buffer[i] >> 4];
343 Base16Buff += base16Chars[buffer[i] & 0xf];
346 return Base16Buff;
350 // Decodes a BASE16 string into a byte array
352 // [In]
353 // base16Buffer: String containing BASE16
354 // base16BufLen: Lenght BASE16 coded string's length
356 // [Out]
357 // buffer: byte array containing decoded string
358 unsigned int DecodeBase16(const wxString &base16Buffer, unsigned int base16BufLen, byte *buffer)
360 if (base16BufLen & 1) {
361 return 0;
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);
375 return ret;
379 // Returns a BASE32 encoded byte array
381 // [In]
382 // buffer: Pointer to byte array
383 // bufLen: Lenght of buffer array
385 // [Return]
386 // wxString object with BASE32 encoded byte array
387 wxString EncodeBase32(const unsigned char* buffer, unsigned int bufLen)
389 wxString Base32Buff;
390 unsigned int i, index;
391 unsigned char word;
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);
402 ++i;
403 } else {
404 word = (buffer[i] >> (8 - (index + 5))) & 0x1F;
405 index = (index + 5) % 8;
406 if (index == 0) {
407 ++i;
410 Base32Buff += (char) base32Chars[word];
413 return Base32Buff;
417 // Decodes a BASE32 string into a byte array
419 // [In]
420 // base32Buffer: String containing BASE32
421 // base32BufLen: Lenght BASE32 coded string's length
423 // [Out]
424 // buffer: byte array containing decoded string
425 // [Return]
426 // nDecodeLen:
427 unsigned int DecodeBase32(const wxString &base32Buffer, unsigned int base32BufLen, unsigned char *buffer)
429 size_t nInputLen = base32Buffer.Length();
430 uint32 nDecodeLen = (nInputLen * 5) / 8;
431 if ((nInputLen * 5) % 8 > 0) {
432 ++nDecodeLen;
434 if (base32BufLen == 0) {
435 return nDecodeLen;
437 if (nDecodeLen > base32BufLen) {
438 return 0;
441 uint32 nBits = 0;
442 int nCount = 0;
443 for (size_t i = 0; i < nInputLen; ++i)
445 if (base32Buffer[i] >= wxT('A') && base32Buffer[i] <= wxT('Z')) {
446 nBits |= ( base32Buffer[i] - wxT('A') );
448 else if (base32Buffer[i] >= wxT('a') && base32Buffer[i] <= wxT('z')) {
449 nBits |= ( base32Buffer[i] - wxT('a') );
451 else if (base32Buffer[i] >= wxT('2') && base32Buffer[i] <= wxT('7')) {
452 nBits |= ( base32Buffer[i] - wxT('2') + 26 );
453 } else {
454 return 0;
456 nCount += 5;
457 if (nCount >= 8)
459 *buffer++ = (byte)( nBits >> (nCount - 8) );
460 nCount -= 8;
462 nBits <<= 5;
465 return nDecodeLen;
470 * base64.c
472 * Base64 encoding/decoding command line filter
474 * Copyright (c) 2002-2008 Matthias Gaertner
475 * Adapted to use wxWidgets by
476 * Copyright (c) 2005-2008 Marcelo Roberto Jimenez ( phoenix@amule.org )
479 static const wxString to_b64(
480 /* 0000000000111111111122222222223333333333444444444455555555556666 */
481 /* 0123456789012345678901234567890123456789012345678901234567890123 */
482 wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"));
485 /* Option variables */
486 static bool g_fUseCRLF = false;
487 static unsigned int g_nCharsPerLine = 72;
488 static wxString strHeaderLine;
491 wxString EncodeBase64(const char *pbBufferIn, unsigned int bufLen)
493 wxString pbBufferOut;
494 wxString strHeader;
496 if( !strHeaderLine.IsEmpty() ) {
497 strHeader = wxT("-----BEGIN ") + strHeaderLine + wxT("-----");
498 if( g_fUseCRLF ) {
499 strHeader += wxT("\r");
501 strHeader += wxT("\n");
504 unsigned long nDiv = ((unsigned long)bufLen) / 3;
505 unsigned long nRem = ((unsigned long)bufLen) % 3;
506 unsigned int NewLineSize = g_fUseCRLF ? 2 : 1;
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;
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");
531 pbBufferOut += wxT("\n");
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");
546 pbBufferOut += wxT("\n");
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");
560 pbBufferOut += wxT("\n");
562 break;
565 if( nRem > 0 ) {
566 if( nChars > 0 ) {
567 if( g_fUseCRLF ) {
568 pbBufferOut += wxT("\r");
570 pbBufferOut += wxT("\n");
574 if( !strHeaderLine.IsEmpty() ) {
575 pbBufferOut = wxT("-----END ") + strHeaderLine + wxT("-----");
576 if( g_fUseCRLF ) {
577 pbBufferOut += wxT("\r");
579 pbBufferOut += wxT("\n");
582 return pbBufferOut;
586 unsigned int DecodeBase64(const wxString &base64Buffer, unsigned int base64BufLen, unsigned char *buffer)
588 int z = 0; // 0 Normal, 1 skip MIME separator (---) to end of line
589 unsigned int nData = 0;
590 unsigned int i = 0;
592 if (base64BufLen == 0) {
593 *buffer = 0;
594 nData = 1;
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;
605 else if(c >= wxT('A') && c <= wxT('Z')) {
606 bits = c - wxT('A');
608 else if(c >= wxT('a') && c <= wxT('z')) {
609 bits = c - wxT('a') + (wxChar)26;
611 else if(c >= wxT('0') && c <= wxT('9')) {
612 bits = c - wxT('0') + (wxChar)52;
614 else if(c == wxT('+')) {
615 bits = (wxChar)62;
617 else if(c == wxT('/')) {
618 bits = (wxChar)63;
620 else if(c == wxT('-')) {
621 z = 1;
623 else if(c == wxT('=')) {
624 break;
625 } else {
626 bits = wxT('y');
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;
648 if (nData == 4) {
649 nData = 0;
650 i += 3;
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;
663 return i + nData;
667 // Returns the text assosiated with a category type
668 wxString GetCatTitle(AllCategoryFilter cat)
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("?");
692 typedef std::map<wxString, EED2KFileTypeClass> SED2KFileTypeMap;
693 typedef SED2KFileTypeMap::value_type SED2KFileTypeMapElement;
694 static SED2KFileTypeMap ED2KFileTypesMap;
697 class CED2KFileTypes{
698 public:
699 CED2KFileTypes()
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
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(".pva"), ED2KFT_VIDEO)); // MPEG Video File
794 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".qt"), ED2KFT_VIDEO)); // QuickTime Movie
795 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ram"), ED2KFT_VIDEO)); // Real Audio Media
796 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ratdvd"),ED2KFT_VIDEO)); // RatDVD Disk Image
797 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rm"), ED2KFT_VIDEO)); // Real Media File
798 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmm"), ED2KFT_VIDEO)); // Real Media File
799 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmvb"), ED2KFT_VIDEO)); // Real Video Variable Bit Rate File
800 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rv"), ED2KFT_VIDEO)); // Real Video File
801 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rv9"), ED2KFT_VIDEO));
802 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".smil"), ED2KFT_VIDEO)); // SMIL Presentation File
803 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".smk"), ED2KFT_VIDEO)); // Smacker Compressed Movie File
804 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".swf"), ED2KFT_VIDEO)); // Macromedia Flash Movie
805 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tp"), ED2KFT_VIDEO)); // Video Transport Stream File
806 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ts"), ED2KFT_VIDEO)); // Video Transport Stream File
807 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vid"), ED2KFT_VIDEO)); // General Video File
808 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".video"), ED2KFT_VIDEO)); // General Video File
809 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vivo"), ED2KFT_VIDEO)); // VivoActive Video File
810 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vob"), ED2KFT_VIDEO)); // DVD Video Object File
811 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vp6"), ED2KFT_VIDEO)); // TrueMotion VP6 Video File
812 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wm"), ED2KFT_VIDEO)); // Windows Media Video File
813 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmv"), ED2KFT_VIDEO)); // Windows Media Video File
814 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xvid"), ED2KFT_VIDEO)); // Xvid-Encoded Video File
816 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bmp"), ED2KFT_IMAGE)); // Bitmap Image File
817 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dcx"), ED2KFT_IMAGE)); // FAXserve Fax Document
818 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".emf"), ED2KFT_IMAGE)); // Enhanced Windows Metafile
819 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".gif"), ED2KFT_IMAGE)); // Graphical Interchange Format File
820 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ico"), ED2KFT_IMAGE)); // Icon File
821 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jfif"), ED2KFT_IMAGE)); // JPEG File Interchange Format
822 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpe"), ED2KFT_IMAGE)); // JPEG Image File
823 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpeg"), ED2KFT_IMAGE)); // JPEG Image File
824 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpg"), ED2KFT_IMAGE)); // JPEG Image File
825 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pct"), ED2KFT_IMAGE)); // PICT Picture File
826 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pcx"), ED2KFT_IMAGE)); // Paintbrush Bitmap Image File
827 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pic"), ED2KFT_IMAGE)); // PICT Picture File
828 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pict"), ED2KFT_IMAGE)); // PICT Picture File
829 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".png"), ED2KFT_IMAGE)); // Portable Network Graphic
830 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psd"), ED2KFT_IMAGE)); // Photoshop Document
831 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psp"), ED2KFT_IMAGE)); // Paint Shop Pro Image File
832 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tga"), ED2KFT_IMAGE)); // Targa Graphic
833 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tif"), ED2KFT_IMAGE)); // Tagged Image File
834 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tiff"), ED2KFT_IMAGE)); // Tagged Image File
835 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmf"), ED2KFT_IMAGE)); // Windows Metafile
836 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmp"), ED2KFT_IMAGE)); // Windows Media Photo File
837 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xif"), ED2KFT_IMAGE)); // ScanSoft Pagis Extended Image Format File
838 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xpm"), ED2KFT_IMAGE)); // X-Windows Pixmap
840 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".7z"), ED2KFT_ARCHIVE)); // 7-Zip Compressed File
841 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ace"), ED2KFT_ARCHIVE)); // WinAce Compressed File
842 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".alz"), ED2KFT_ARCHIVE)); // ALZip Archive
843 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".arc"), ED2KFT_ARCHIVE)); // Compressed File Archive
844 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".arj"), ED2KFT_ARCHIVE)); // ARJ Compressed File Archive
845 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bz2"), ED2KFT_ARCHIVE)); // Bzip Compressed File
846 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cab"), ED2KFT_ARCHIVE)); // Cabinet File
847 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cbr"), ED2KFT_ARCHIVE)); // Comic Book RAR Archive
848 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cbz"), ED2KFT_ARCHIVE)); // Comic Book ZIP Archive
849 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".gz"), ED2KFT_ARCHIVE)); // Gnu Zipped File
850 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hqx"), ED2KFT_ARCHIVE)); // BinHex 4.0 Encoded File
851 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".lha"), ED2KFT_ARCHIVE)); // LHARC Compressed Archive
852 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".lzh"), ED2KFT_ARCHIVE)); // LZH Compressed File
853 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".msi"), ED2KFT_ARCHIVE)); // Microsoft Installer File
854 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pak"), ED2KFT_ARCHIVE)); // PAK (Packed) File
855 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".par"), ED2KFT_ARCHIVE)); // Parchive Index File
856 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".par2"), ED2KFT_ARCHIVE)); // Parchive 2 Index File
857 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rar"), ED2KFT_ARCHIVE)); // WinRAR Compressed Archive
858 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sea"), ED2KFT_ARCHIVE)); // Self-Extracting Archive (Mac)
859 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sit"), ED2KFT_ARCHIVE)); // Stuffit Archive
860 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sitx"), ED2KFT_ARCHIVE)); // Stuffit X Archive
861 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tar"), ED2KFT_ARCHIVE)); // Consolidated Unix File Archive
862 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tbz2"), ED2KFT_ARCHIVE)); // Tar BZip 2 Compressed File
863 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tgz"), ED2KFT_ARCHIVE)); // Gzipped Tar File
864 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".uc2"), ED2KFT_ARCHIVE)); // UltraCompressor 2 Archive
865 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xpi"), ED2KFT_ARCHIVE)); // Mozilla Installer Package
866 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".z"), ED2KFT_ARCHIVE)); // Unix Compressed File
867 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".zip"), ED2KFT_ARCHIVE)); // Zipped File
869 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bat"), ED2KFT_PROGRAM)); // Batch File
870 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cmd"), ED2KFT_PROGRAM)); // Command File
871 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".com"), ED2KFT_PROGRAM)); // COM File
872 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".exe"), ED2KFT_PROGRAM)); // Executable File
873 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hta"), ED2KFT_PROGRAM)); // HTML Application
874 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".js"), ED2KFT_PROGRAM)); // Java Script
875 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jse"), ED2KFT_PROGRAM)); // Encoded Java Script
876 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".msc"), ED2KFT_PROGRAM)); // Microsoft Common Console File
877 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vbe"), ED2KFT_PROGRAM)); // Encoded Visual Basic Script File
878 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vbs"), ED2KFT_PROGRAM)); // Visual Basic Script File
879 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wsf"), ED2KFT_PROGRAM)); // Windows Script File
880 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wsh"), ED2KFT_PROGRAM)); // Windows Scripting Host File
882 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bin"), ED2KFT_CDIMAGE)); // CD Image
883 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwa"), ED2KFT_CDIMAGE)); // BlindWrite Disk Information File
884 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwi"), ED2KFT_CDIMAGE)); // BlindWrite CD/DVD Disc Image
885 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bws"), ED2KFT_CDIMAGE)); // BlindWrite Sub Code File
886 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwt"), ED2KFT_CDIMAGE)); // BlindWrite 4 Disk Image
887 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ccd"), ED2KFT_CDIMAGE)); // CloneCD Disk Image
888 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cue"), ED2KFT_CDIMAGE)); // Cue Sheet File
889 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmg"), ED2KFT_CDIMAGE)); // Mac OS X Disk Image
890 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmz"), ED2KFT_CDIMAGE));
891 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".img"), ED2KFT_CDIMAGE)); // Disk Image Data File
892 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".iso"), ED2KFT_CDIMAGE)); // Disc Image File
893 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mdf"), ED2KFT_CDIMAGE)); // Media Disc Image File
894 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mds"), ED2KFT_CDIMAGE)); // Media Descriptor File
895 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nrg"), ED2KFT_CDIMAGE)); // Nero CD/DVD Image File
896 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sub"), ED2KFT_CDIMAGE)); // Subtitle File
897 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".toast"), ED2KFT_CDIMAGE)); // Toast Disc Image
899 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".chm"), ED2KFT_DOCUMENT)); // Compiled HTML Help File
900 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".css"), ED2KFT_DOCUMENT)); // Cascading Style Sheet
901 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".diz"), ED2KFT_DOCUMENT)); // Description in Zip File
902 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".doc"), ED2KFT_DOCUMENT)); // Document File
903 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dot"), ED2KFT_DOCUMENT)); // Document Template File
904 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hlp"), ED2KFT_DOCUMENT)); // Help File
905 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".htm"), ED2KFT_DOCUMENT)); // HTML File
906 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".html"), ED2KFT_DOCUMENT)); // HTML File
907 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nfo"), ED2KFT_DOCUMENT)); // Warez Information File
908 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pdf"), ED2KFT_DOCUMENT)); // Portable Document Format File
909 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pps"), ED2KFT_DOCUMENT)); // PowerPoint Slide Show
910 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ppt"), ED2KFT_DOCUMENT)); // PowerPoint Presentation
911 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ps"), ED2KFT_DOCUMENT)); // PostScript File
912 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rtf"), ED2KFT_DOCUMENT)); // Rich Text Format File
913 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".text"), ED2KFT_DOCUMENT)); // General Text File
914 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".txt"), ED2KFT_DOCUMENT)); // Text File
915 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wri"), ED2KFT_DOCUMENT)); // Windows Write Document
916 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xls"), ED2KFT_DOCUMENT)); // Microsoft Excel Spreadsheet
917 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xlt"), ED2KFT_DOCUMENT)); // Microsoft Excel Template
918 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xml"), ED2KFT_DOCUMENT)); // XML File
923 // get the list initialized *before* any code is accessing it
924 CED2KFileTypes theED2KFileTypes;
926 EED2KFileType GetED2KFileTypeID(const CPath& fileName)
928 const wxString ext = fileName.GetExt().Lower();
929 if (ext.IsEmpty()) {
930 return ED2KFT_ANY;
933 SED2KFileTypeMap::iterator it = ED2KFileTypesMap.find(wxT(".") + ext);
934 if (it != ED2KFileTypesMap.end()) {
935 return it->second.GetType();
936 } else {
937 return ED2KFT_ANY;
942 // Retuns the ed2k file type term which is to be used in server searches
943 wxString GetED2KFileTypeSearchTerm(EED2KFileType iFileID)
945 if (iFileID == ED2KFT_AUDIO) return ED2KFTSTR_AUDIO;
946 if (iFileID == ED2KFT_VIDEO) return ED2KFTSTR_VIDEO;
947 if (iFileID == ED2KFT_IMAGE) return ED2KFTSTR_IMAGE;
948 if (iFileID == ED2KFT_DOCUMENT) return ED2KFTSTR_DOCUMENT;
949 if (iFileID == ED2KFT_PROGRAM) return ED2KFTSTR_PROGRAM;
950 // NOTE: Archives and CD-Images are published with file type "Pro"
951 if (iFileID == ED2KFT_ARCHIVE) return ED2KFTSTR_PROGRAM;
952 if (iFileID == ED2KFT_CDIMAGE) return ED2KFTSTR_PROGRAM;
954 return wxEmptyString;
958 // Returns a file type which is used eMule internally only, examining the extention of the given filename
959 wxString GetFileTypeByName(const CPath& fileName)
961 EED2KFileType iFileType = GetED2KFileTypeID(fileName);
962 switch (iFileType) {
963 case ED2KFT_AUDIO: return ED2KFTSTR_AUDIO;
964 case ED2KFT_VIDEO: return ED2KFTSTR_VIDEO;
965 case ED2KFT_IMAGE: return ED2KFTSTR_IMAGE;
966 case ED2KFT_DOCUMENT: return ED2KFTSTR_DOCUMENT;
967 case ED2KFT_PROGRAM: return ED2KFTSTR_PROGRAM;
968 case ED2KFT_ARCHIVE: return ED2KFTSTR_ARCHIVE;
969 case ED2KFT_CDIMAGE: return ED2KFTSTR_CDIMAGE;
970 default: return wxEmptyString;
975 // Retuns the ed2k file type integer ID which is to be used for publishing+searching
976 EED2KFileType GetED2KFileTypeSearchID(EED2KFileType iFileID)
978 switch (iFileID) {
979 case ED2KFT_AUDIO: return ED2KFT_AUDIO;
980 case ED2KFT_VIDEO: return ED2KFT_VIDEO;
981 case ED2KFT_IMAGE: return ED2KFT_IMAGE;
982 case ED2KFT_DOCUMENT: return ED2KFT_DOCUMENT;
983 case ED2KFT_PROGRAM: return ED2KFT_PROGRAM;
984 // NOTE: Archives and CD-Images are published+searched with file type "Pro"
985 // NOTE: If this gets changed, the function 'GetED2KFileTypeSearchTerm' also needs to get updated!
986 case ED2KFT_ARCHIVE: return ED2KFT_PROGRAM;
987 case ED2KFT_CDIMAGE: return ED2KFT_PROGRAM;
988 default: return ED2KFT_ANY;
994 * Dumps a buffer to a wxString
996 wxString DumpMemToStr(const void *buff, int n, const wxString& msg, bool ok)
998 const unsigned char *p = (const unsigned char *)buff;
999 int lines = (n + 15)/ 16;
1001 wxString result;
1002 // Allocate aproximetly what is needed
1003 result.Alloc( ( lines + 1 ) * 80 );
1004 if ( !msg.IsEmpty() ) {
1005 result += msg + wxT(" - ok=") + ( ok ? wxT("true, ") : wxT("false, ") );
1008 result += CFormat(wxT("%d bytes\n")) % n;
1009 for ( int i = 0; i < lines; ++i) {
1010 // Show address
1011 result += CFormat(wxT("%08x ")) % (i * 16);
1013 // Show two columns of hex-values
1014 for ( int j = 0; j < 2; ++j) {
1015 for ( int k = 0; k < 8; ++k) {
1016 int pos = 16 * i + 8 * j + k;
1018 if ( pos < n ) {
1019 result += CFormat(wxT("%02x ")) % p[pos];
1020 } else {
1021 result += wxT(" ");
1024 result += wxT(" ");
1026 result += wxT("|");
1027 // Show a column of ascii-values
1028 for ( int k = 0; k < 16; ++k) {
1029 int pos = 16 * i + k;
1031 if ( pos < n ) {
1032 if ( isspace( p[pos] ) ) {
1033 result += wxT(" ");
1034 } else if ( !isgraph( p[pos] ) ) {
1035 result += wxT(".");
1036 } else {
1037 result += (wxChar)p[pos];
1039 } else {
1040 result += wxT(" ");
1043 result += wxT("|\n");
1045 result.Shrink();
1047 return result;
1052 * Dumps a buffer to stdout
1054 void DumpMem(const void *buff, int n, const wxString& msg, bool ok)
1056 printf("%s\n", (const char*)unicode2char(DumpMemToStr( buff, n, msg, ok )) );
1061 // Dump mem in dword format
1062 void DumpMem_DW(const uint32 *ptr, int count)
1064 for(int i = 0; i < count; i++) {
1065 printf("%08x ", ptr[i]);
1066 if ( (i % 4) == 3) printf("\n");
1068 printf("\n");
1072 wxString GetConfigDir(const wxString &configFileBase)
1074 // Cache the path.
1075 static wxString configPath;
1077 if (configPath.IsEmpty()) {
1078 // "Portable aMule" - Use aMule from an external USB drive
1079 // Check for ./config/amule.conf (or whatever gets passed as configFile)
1080 // and use this configuration if found
1081 const wxString configDir = JoinPaths(wxFileName::GetCwd(), wxT("config"));
1082 const wxString configFile = JoinPaths(configDir, configFileBase);
1084 if (CPath::DirExists(configDir) && CPath::FileExists(configFile)) {
1085 AddLogLineN(CFormat(_("Using config dir: %s")) % configDir);
1087 configPath = configDir;
1088 } else {
1089 configPath = wxStandardPaths::Get().GetUserDataDir();
1092 configPath += wxFileName::GetPathSeparator();
1095 return configPath;
1099 /*************************** Locale specific stuff ***************************/
1101 #ifndef __WXMSW__
1102 # define SETWINLANG(LANG, SUBLANG)
1103 #else
1104 # define SETWINLANG(LANG, SUBLANG) \
1105 info.WinLang = LANG; \
1106 info.WinSublang = SUBLANG;
1107 #endif
1109 #define CUSTOMLANGUAGE(wxid, iso, winlang, winsublang, dir, desc) \
1110 info.Language = wxid; \
1111 info.CanonicalName = wxT(iso); \
1112 info.LayoutDirection = dir; \
1113 info.Description = wxT(desc); \
1114 SETWINLANG(winlang, winsublang) \
1115 wxLocale::AddLanguage(info);
1117 void InitCustomLanguages()
1119 wxLanguageInfo info;
1121 #if !wxCHECK_VERSION(2, 9, 0)
1122 CUSTOMLANGUAGE(wxLANGUAGE_ASTURIAN, "ast", 0, 0, wxLayout_LeftToRight, "Asturian");
1123 #endif
1127 void InitLocale(wxLocale& locale, int language)
1129 locale.Init(language, wxLOCALE_LOAD_DEFAULT);
1131 #if defined(__WXMAC__) || defined(__WXMSW__)
1132 locale.AddCatalogLookupPathPrefix(JoinPaths(wxStandardPaths::Get().GetDataDir(), wxT("locale")));
1133 #endif
1134 locale.AddCatalog(wxT(PACKAGE));
1138 int StrLang2wx(const wxString& language)
1140 // get rid of possible encoding and modifier
1141 wxString lang(language.BeforeFirst('.').BeforeFirst('@'));
1143 if (!lang.IsEmpty()) {
1144 const wxLanguageInfo *lng = wxLocale::FindLanguageInfo(lang);
1145 if (lng) {
1146 int langID = lng->Language;
1147 // Traditional Chinese: original Chinese, used in Taiwan, Hong Kong and Macau.
1148 // Simplified Chinese: simplified Chinese characters used in Mainland China since 1950s, and in some other places such as Singapore and Malaysia.
1150 // Chinese (Traditional) contains zh_TW, zh_HK and zh_MO (but there are differences in some words).
1151 // Because of most Traditional Chinese user are in Taiwan, zh_TW becomes the representation of Traditional Chinese.
1152 // Chinese (Simplified) contains zh_CN, zh_SG and zh_MY. In the same reason, zh_CN becomes the representation of Simplified Chinese.
1153 // (see http://forum.amule.org/index.php?topic=13208.msg98043#msg98043 )
1155 // wx maps "Traditional Chinese" to "Chinese" however. This must me corrected:
1156 if (langID == wxLANGUAGE_CHINESE) {
1157 langID = wxLANGUAGE_CHINESE_TRADITIONAL;
1159 return langID;
1160 } else {
1161 return wxLANGUAGE_DEFAULT;
1163 } else {
1164 return wxLANGUAGE_DEFAULT;
1169 wxString wxLang2Str(const int lang)
1171 if (lang != wxLANGUAGE_DEFAULT) {
1172 const wxLanguageInfo *lng = wxLocale::GetLanguageInfo(lang);
1173 if (lng) {
1174 return lng->CanonicalName;
1175 } else {
1176 return wxEmptyString;
1178 } else {
1179 return wxEmptyString;
1183 /*****************************************************************************/
1185 wxString GetPassword() {
1186 wxString pass_plain;
1187 CMD4Hash password;
1188 #ifndef __WXMSW__
1189 pass_plain = char2unicode(getpass("Enter password for mule connection: "));
1190 #else
1191 //#warning This way, pass enter is not hidden on windows. Bad thing.
1192 char temp_str[512];
1193 fflush(stdin);
1194 printf("Enter password for mule connection: \n");
1195 fflush(stdout);
1196 fgets(temp_str, 512, stdin);
1197 temp_str[strlen(temp_str)-1] = '\0';
1198 pass_plain = char2unicode(temp_str);
1199 #endif
1200 wxCHECK2(password.Decode(MD5Sum(pass_plain).GetHash()), /* Do nothing. */ );
1201 // MD5 hash for an empty string, according to rfc1321.
1202 if (password.Encode() == wxT("D41D8CD98F00B204E9800998ECF8427E")) {
1203 printf("No empty password allowed.\n");
1204 return GetPassword();
1208 return password.Encode();
1212 const uint8 BitVector::s_posMask[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
1213 const uint8 BitVector::s_negMask[] = {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F};
1215 // File_checked_for_headers