Always include the boost-package. Otherwise it won't get searched on a second run.
[amule.git] / src / OtherFunctions.cpp
blob582a60b6eac65d2afdf3b699b875dd163e5f40d0
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.
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.
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
33 #include "config.h" // Needed for a number of defines
35 #include <wx/stdpaths.h> // Do_not_auto_remove
36 #include <common/StringFunctions.h>
37 #include <common/ClientVersion.h>
38 #include <common/MD5Sum.h>
39 #include <common/Path.h>
40 #include "Logger.h"
41 #include "BitVector.h" // Needed for BitVector
43 #include "OtherFunctions.h" // Interface declarations
45 #include <map>
47 #ifdef __WXBASE__
48 #include <cerrno>
49 #else
50 #include <wx/utils.h>
51 #endif
56 // Formats a filesize in bytes to make it suitable for displaying
57 wxString CastItoXBytes( uint64 count )
60 if (count < 1024)
61 return CFormat(wxT("%u ")) % count + wxPLURAL("byte", "bytes", count) ;
62 else if (count < 1048576)
63 return CFormat(wxT("%u ")) % (count >> 10) + _("kB") ;
64 else if (count < 1073741824)
65 return CFormat(wxT("%.2f ")) % ((float)(uint32)count/1048576) + _("MB") ;
66 else if (count < 1099511627776LL)
67 return CFormat(wxT("%.3f ")) % ((float)((uint32)(count/1024))/1048576) + _("GB") ;
68 else
69 return CFormat(wxT("%.3f ")) % ((float)count/1099511627776LL) + _("TB") ;
73 wxString CastItoIShort(uint64 count)
76 if (count < 1000)
77 return CFormat(wxT("%u")) % count;
78 else if (count < 1000000)
79 return CFormat(wxT("%.0f")) % ((float)(uint32)count/1000) + _("k") ;
80 else if (count < 1000000000)
81 return CFormat(wxT("%.2f")) % ((float)(uint32)count/1000000) + _("M") ;
82 else if (count < 1000000000000LL)
83 return CFormat(wxT("%.2f")) % ((float)((uint32)(count/1000))/1000000) + _("G") ;
84 else
85 return CFormat(wxT("%.2f")) % ((float)count/1000000000000LL) + _("T");
89 wxString CastItoSpeed(uint32 bytes)
91 if (bytes < 1024)
92 return CFormat(wxT("%u ")) % bytes + wxPLURAL("byte/sec", "bytes/sec", bytes);
93 else if (bytes < 1048576)
94 return CFormat(wxT("%.2f ")) % (bytes / 1024.0) + _("kB/s");
95 else
96 return CFormat(wxT("%.2f ")) % (bytes / 1048576.0) + _("MB/s");
100 // Make a time value in seconds suitable for displaying
101 wxString CastSecondsToHM(uint32 count, uint16 msecs)
103 if (count < 60) {
104 if (!msecs) {
105 return CFormat(wxT("%02u %s")) % count % _("secs");
106 } else {
107 return CFormat(wxT("%.3f %s"))
108 % (count + ((float)msecs/1000)) % _("secs");
110 } else if (count < 3600) {
111 return CFormat(wxT("%u:%02u %s"))
112 % (count/60) % (count % 60) % _("mins");
113 } else if (count < 86400) {
114 return CFormat(wxT("%u:%02u %s"))
115 % (count/3600) % ((count % 3600)/60) % _("hours");
116 } else {
117 return CFormat(wxT("%u %s %02u:%02u %s"))
118 % (count/86400) % _("Days")
119 % ((count % 86400)/3600) % ((count % 3600)/60) % _("hours");
124 // Examines a filename and determines the filetype
125 FileType GetFiletype(const CPath& filename)
127 // FIXME: WTF do we have two such functions in the first place?
128 switch (GetED2KFileTypeID(filename)) {
129 case ED2KFT_AUDIO: return ftAudio;
130 case ED2KFT_VIDEO: return ftVideo;
131 case ED2KFT_IMAGE: return ftPicture;
132 case ED2KFT_PROGRAM: return ftProgram;
133 case ED2KFT_DOCUMENT: return ftText;
134 case ED2KFT_ARCHIVE: return ftArchive;
135 case ED2KFT_CDIMAGE: return ftCDImage;
136 default: return ftAny;
141 // Returns the (translated) description assosiated with a FileType
142 wxString GetFiletypeDesc(FileType type, bool translated)
144 switch ( type ) {
145 case ftVideo:
146 if (translated) {
147 return _("Videos");
148 } else {
149 return wxT("Videos");
151 break;
152 case ftAudio:
153 if (translated) {
154 return _("Audio");
155 } else {
156 return wxT("Audio");
158 break;
159 case ftArchive:
160 if (translated) {
161 return _("Archives");
162 } else {
163 return wxT("Archives");
165 break;
166 case ftCDImage:
167 if (translated) {
168 return _("CD-Images");
169 } else {
170 return wxT("CD-Images");
172 break;
173 case ftPicture:
174 if (translated) {
175 return _("Pictures");
176 } else {
177 return wxT("Pictures");
179 break;
180 case ftText:
181 if (translated) {
182 return _("Texts");
183 } else {
184 return wxT("Texts");
186 break;
187 case ftProgram:
188 if (translated) {
189 return _("Programs");
190 } else {
191 return wxT("Programs");
193 break;
194 default:
195 if (translated) {
196 return _("Any");
197 } else {
198 return wxT("Any");
200 break;
204 // Returns the Typename, examining the extention of the given filename
206 wxString GetFiletypeByName(const CPath& filename, bool translated)
208 return GetFiletypeDesc(GetFiletype(filename), translated);
212 // Return the text associated with a rating of a file
213 wxString GetRateString(uint16 rate)
215 switch ( rate ) {
216 case 0: return _("Not rated");
217 case 1: return _("Invalid / Corrupt / Fake");
218 case 2: return _("Poor");
219 case 3: return _("Fair");
220 case 4: return _("Good");
221 case 5: return _("Excellent");
222 default: return _("Not rated");
228 * Return the size in bytes of the given size-type
230 * @param type The type (as an int) where: 0 = Byte, 1 = KB, 2 = MB, 3 = GB
232 * @return The amount of Bytes the provided size-type represents
234 * Values over GB aren't handled since the amount of Bytes 1TB represents
235 * is over the uint32 capacity
237 uint32 GetTypeSize(uint8 type)
239 enum {Bytes, KB, MB, GB};
240 int size;
242 switch(type) {
243 case Bytes: size = 1; break;
244 case KB: size = 1024; break;
245 case MB: size = 1048576; break;
246 case GB: size = 1073741824; break;
247 default: size = -1; break;
249 return size;
253 // Base16 chars for encode an decode functions
254 static wxChar base16Chars[17] = wxT("0123456789ABCDEF");
255 static wxChar base32Chars[33] = wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");
256 #define BASE16_LOOKUP_MAX 23
257 static wxChar base16Lookup[BASE16_LOOKUP_MAX][2] = {
258 { wxT('0'), 0x0 },
259 { wxT('1'), 0x1 },
260 { wxT('2'), 0x2 },
261 { wxT('3'), 0x3 },
262 { wxT('4'), 0x4 },
263 { wxT('5'), 0x5 },
264 { wxT('6'), 0x6 },
265 { wxT('7'), 0x7 },
266 { wxT('8'), 0x8 },
267 { wxT('9'), 0x9 },
268 { wxT(':'), 0x9 },
269 { wxT(';'), 0x9 },
270 { wxT('<'), 0x9 },
271 { wxT('='), 0x9 },
272 { wxT('>'), 0x9 },
273 { wxT('?'), 0x9 },
274 { wxT('@'), 0x9 },
275 { wxT('A'), 0xA },
276 { wxT('B'), 0xB },
277 { wxT('C'), 0xC },
278 { wxT('D'), 0xD },
279 { wxT('E'), 0xE },
280 { wxT('F'), 0xF }
284 // Returns a BASE16 encoded byte array
286 // [In]
287 // buffer: Pointer to byte array
288 // bufLen: Lenght of buffer array
290 // [Return]
291 // wxString object with BASE16 encoded byte array
292 wxString EncodeBase16(const unsigned char* buffer, unsigned int bufLen)
294 wxString Base16Buff;
296 for(unsigned int i = 0; i < bufLen; ++i) {
297 Base16Buff += base16Chars[buffer[i] >> 4];
298 Base16Buff += base16Chars[buffer[i] & 0xf];
301 return Base16Buff;
305 // Decodes a BASE16 string into a byte array
307 // [In]
308 // base16Buffer: String containing BASE16
309 // base16BufLen: Lenght BASE16 coded string's length
311 // [Out]
312 // buffer: byte array containing decoded string
313 unsigned int DecodeBase16(const wxString &base16Buffer, unsigned int base16BufLen, uint8_t *buffer)
315 if (base16BufLen & 1) {
316 return 0;
318 unsigned int ret = base16BufLen >> 1;
319 memset( buffer, 0, ret);
320 for(unsigned int i = 0; i < base16BufLen; ++i) {
321 int lookup = toupper(base16Buffer[i]) - wxT('0');
322 // Check to make sure that the given word falls inside a valid range
323 uint8_t word = (lookup < 0 || lookup >= BASE16_LOOKUP_MAX) ?
324 0xFF : base16Lookup[lookup][1];
325 unsigned idx = i >> 1;
326 buffer[idx] = (i & 1) ? // odd or even?
327 (buffer[idx] | word) : (word << 4);
330 return ret;
334 // Returns a BASE32 encoded byte array
336 // [In]
337 // buffer: Pointer to byte array
338 // bufLen: Lenght of buffer array
340 // [Return]
341 // wxString object with BASE32 encoded byte array
342 wxString EncodeBase32(const unsigned char* buffer, unsigned int bufLen)
344 wxString Base32Buff;
345 unsigned int i, index;
346 unsigned char word;
348 for(i = 0, index = 0; i < bufLen;) {
349 // Is the current word going to span a byte boundary?
350 if (index > 3) {
351 word = (buffer[i] & (0xFF >> index));
352 index = (index + 5) % 8;
353 word <<= index;
354 if (i < bufLen - 1) {
355 word |= buffer[i + 1] >> (8 - index);
357 ++i;
358 } else {
359 word = (buffer[i] >> (8 - (index + 5))) & 0x1F;
360 index = (index + 5) % 8;
361 if (index == 0) {
362 ++i;
365 Base32Buff += (char) base32Chars[word];
368 return Base32Buff;
372 // Decodes a BASE32 string into a byte array
374 // [In]
375 // base32Buffer: String containing BASE32
376 // base32BufLen: Lenght BASE32 coded string's length
378 // [Out]
379 // buffer: byte array containing decoded string
380 // [Return]
381 // nDecodeLen:
382 unsigned int DecodeBase32(const wxString &base32Buffer, unsigned int base32BufLen, unsigned char *buffer)
384 size_t nInputLen = base32Buffer.Length();
385 uint32 nDecodeLen = (nInputLen * 5) / 8;
386 if ((nInputLen * 5) % 8 > 0) {
387 ++nDecodeLen;
389 if (base32BufLen == 0) {
390 return nDecodeLen;
392 if (nDecodeLen > base32BufLen) {
393 return 0;
396 uint32 nBits = 0;
397 int nCount = 0;
398 for (size_t i = 0; i < nInputLen; ++i)
400 if (base32Buffer[i] >= wxT('A') && base32Buffer[i] <= wxT('Z')) {
401 nBits |= ( base32Buffer[i] - wxT('A') );
403 else if (base32Buffer[i] >= wxT('a') && base32Buffer[i] <= wxT('z')) {
404 nBits |= ( base32Buffer[i] - wxT('a') );
406 else if (base32Buffer[i] >= wxT('2') && base32Buffer[i] <= wxT('7')) {
407 nBits |= ( base32Buffer[i] - wxT('2') + 26 );
408 } else {
409 return 0;
411 nCount += 5;
412 if (nCount >= 8)
414 *buffer++ = (uint8_t)( nBits >> (nCount - 8) );
415 nCount -= 8;
417 nBits <<= 5;
420 return nDecodeLen;
425 * base64.c
427 * Base64 encoding/decoding command line filter
429 * Copyright (c) 2002-2011 Matthias Gaertner
430 * Adapted to use wxWidgets by
431 * Copyright (c) 2005-2011 Marcelo Roberto Jimenez ( phoenix@amule.org )
434 static const wxString to_b64(
435 /* 0000000000111111111122222222223333333333444444444455555555556666 */
436 /* 0123456789012345678901234567890123456789012345678901234567890123 */
437 wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"));
440 /* Option variables */
441 static bool g_fUseCRLF = false;
442 static unsigned int g_nCharsPerLine = 72;
443 static wxString strHeaderLine;
446 wxString EncodeBase64(const char *pbBufferIn, unsigned int bufLen)
448 wxString pbBufferOut;
449 wxString strHeader;
451 if( !strHeaderLine.IsEmpty() ) {
452 strHeader = wxT("-----BEGIN ") + strHeaderLine + wxT("-----");
453 if( g_fUseCRLF ) {
454 strHeader += wxT("\r");
456 strHeader += wxT("\n");
459 unsigned long nDiv = ((unsigned long)bufLen) / 3;
460 unsigned long nRem = ((unsigned long)bufLen) % 3;
461 unsigned int NewLineSize = g_fUseCRLF ? 2 : 1;
463 // Allocate enough space in the output buffer to speed up things
464 pbBufferOut.Alloc(
465 strHeader.Len() * 2 + // header/footer
466 (bufLen * 4) / 3 + 1 + // Number of codes
467 nDiv * NewLineSize + // Number of new lines
468 (nRem ? 1 : 0) * NewLineSize ); // Last line
469 pbBufferOut = strHeader;
471 unsigned long nChars = 0;
472 const unsigned char *pIn = (unsigned char*)pbBufferIn;
473 while( nDiv > 0 ) {
474 pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
475 pbBufferOut += to_b64[((pIn[0] << 4) & 0x30) | ((pIn[1] >> 4) & 0xf)];
476 pbBufferOut += to_b64[((pIn[1] << 2) & 0x3c) | ((pIn[2] >> 6) & 0x3)];
477 pbBufferOut += to_b64[ pIn[2] & 0x3f];
478 pIn += 3;
479 nDiv--;
480 nChars += 4;
481 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
482 nChars = 0;
483 if( g_fUseCRLF ) {
484 pbBufferOut += wxT("\r");
486 pbBufferOut += wxT("\n");
489 switch( nRem ) {
490 case 2:
491 pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
492 pbBufferOut += to_b64[((pIn[0] << 4) & 0x30) | ((pIn[1] >> 4) & 0xf)];
493 pbBufferOut += to_b64[ (pIn[1] << 2) & 0x3c];
494 pbBufferOut += wxT("=");
495 nChars += 4;
496 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
497 nChars = 0;
498 if( g_fUseCRLF ) {
499 pbBufferOut += wxT("\r");
501 pbBufferOut += wxT("\n");
503 break;
504 case 1:
505 pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
506 pbBufferOut += to_b64[ (pIn[0] << 4) & 0x30];
507 pbBufferOut += wxT("=");
508 pbBufferOut += wxT("=");
509 nChars += 4;
510 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
511 nChars = 0;
512 if( g_fUseCRLF ) {
513 pbBufferOut += wxT("\r");
515 pbBufferOut += wxT("\n");
517 break;
520 if( nRem > 0 ) {
521 if( nChars > 0 ) {
522 if( g_fUseCRLF ) {
523 pbBufferOut += wxT("\r");
525 pbBufferOut += wxT("\n");
529 if( !strHeaderLine.IsEmpty() ) {
530 pbBufferOut = wxT("-----END ") + strHeaderLine + wxT("-----");
531 if( g_fUseCRLF ) {
532 pbBufferOut += wxT("\r");
534 pbBufferOut += wxT("\n");
537 return pbBufferOut;
541 unsigned int DecodeBase64(const wxString &base64Buffer, unsigned int base64BufLen, unsigned char *buffer)
543 int z = 0; // 0 Normal, 1 skip MIME separator (---) to end of line
544 unsigned int nData = 0;
545 unsigned int i = 0;
547 if (base64BufLen == 0) {
548 *buffer = 0;
549 nData = 1;
552 for(unsigned int j = 0; j < base64BufLen; ++j) {
553 wxChar c = base64Buffer[j];
554 wxChar bits = wxT('z');
555 if( z > 0 ) {
556 if(c == wxT('\n')) {
557 z = 0;
560 else if(c >= wxT('A') && c <= wxT('Z')) {
561 bits = c - wxT('A');
563 else if(c >= wxT('a') && c <= wxT('z')) {
564 bits = c - wxT('a') + (wxChar)26;
566 else if(c >= wxT('0') && c <= wxT('9')) {
567 bits = c - wxT('0') + (wxChar)52;
569 else if(c == wxT('+')) {
570 bits = (wxChar)62;
572 else if(c == wxT('/')) {
573 bits = (wxChar)63;
575 else if(c == wxT('-')) {
576 z = 1;
578 else if(c == wxT('=')) {
579 break;
580 } else {
581 bits = wxT('y');
584 // Skips anything that was not recognized
585 // as a base64 valid char ('y' or 'z')
586 if (bits < (wxChar)64) {
587 switch (nData++) {
588 case 0:
589 buffer[i+0] = (bits << 2) & 0xfc;
590 break;
591 case 1:
592 buffer[i+0] |= (bits >> 4) & 0x03;
593 buffer[i+1] = (bits << 4) & 0xf0;
594 break;
595 case 2:
596 buffer[i+1] |= (bits >> 2) & 0x0f;
597 buffer[i+2] = (bits << 6) & 0xc0;
598 break;
599 case 3:
600 buffer[i+2] |= bits & 0x3f;
601 break;
603 if (nData == 4) {
604 nData = 0;
605 i += 3;
609 if (nData == 1) {
610 // Syntax error or buffer was empty
611 *buffer = 0;
612 nData = 0;
613 i = 0;
614 } else {
615 buffer[i+nData] = 0;
618 return i + nData;
622 // Returns the text assosiated with a category type
623 wxString GetCatTitle(AllCategoryFilter cat)
625 switch (cat) {
626 case acfAll: return _("all");
627 case acfAllOthers: return _("all others");
628 case acfIncomplete: return _("Incomplete");
629 case acfCompleted: return _("Completed");
630 case acfWaiting: return _("Waiting");
631 case acfDownloading: return _("Downloading");
632 case acfErroneous: return _("Erroneous");
633 case acfPaused: return _("Paused");
634 case acfStopped: return _("Stopped");
635 case acfVideo: return _("Video");
636 case acfAudio: return _("Audio");
637 case acfArchive: return _("Archive");
638 case acfCDImages: return _("CD-Images");
639 case acfPictures: return _("Pictures");
640 case acfText: return _("Text");
641 case acfActive: return _("Active");
642 default: return wxT("?");
647 typedef std::map<wxString, EED2KFileTypeClass> SED2KFileTypeMap;
648 typedef SED2KFileTypeMap::value_type SED2KFileTypeMapElement;
649 static SED2KFileTypeMap ED2KFileTypesMap;
652 class CED2KFileTypes{
653 public:
654 CED2KFileTypes()
656 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".669"), ED2KFT_AUDIO)); // 8 channel tracker module
657 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aac"), ED2KFT_AUDIO)); // Advanced Audio Coding File
658 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ac3"), ED2KFT_AUDIO)); // Audio Codec 3 File
659 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aif"), ED2KFT_AUDIO)); // Audio Interchange File Format
660 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aifc"), ED2KFT_AUDIO)); // Audio Interchange File Format
661 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aiff"), ED2KFT_AUDIO)); // Audio Interchange File Format
662 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".amf"), ED2KFT_AUDIO)); // DSMI Advanced Module Format
663 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".amr"), ED2KFT_AUDIO)); // Adaptive Multi-Rate Codec File
664 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ams"), ED2KFT_AUDIO)); // Extreme Tracker Module
665 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ape"), ED2KFT_AUDIO)); // Monkey's Audio Lossless Audio File
666 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".au"), ED2KFT_AUDIO)); // Audio File (Sun, Unix)
667 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aud"), ED2KFT_AUDIO)); // General Audio File
668 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".audio"), ED2KFT_AUDIO)); // General Audio File
669 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cda"), ED2KFT_AUDIO)); // CD Audio Track
670 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dbm"), ED2KFT_AUDIO));
671 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmf"), ED2KFT_AUDIO)); // Delusion Digital Music File
672 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dsm"), ED2KFT_AUDIO)); // Digital Sound Module
673 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dts"), ED2KFT_AUDIO)); // DTS Encoded Audio File
674 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".far"), ED2KFT_AUDIO)); // Farandole Composer Module
675 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flac"), ED2KFT_AUDIO)); // Free Lossless Audio Codec File
676 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".it"), ED2KFT_AUDIO)); // Impulse Tracker Module
677 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m1a"), ED2KFT_AUDIO)); // MPEG-1 Audio File
678 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2a"), ED2KFT_AUDIO)); // MPEG-2 Audio File
679 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m4a"), ED2KFT_AUDIO)); // MPEG-4 Audio File
680 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mdl"), ED2KFT_AUDIO)); // DigiTrakker Module
681 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".med"), ED2KFT_AUDIO)); // Amiga MED Sound File
682 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mid"), ED2KFT_AUDIO)); // MIDI File
683 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".midi"), ED2KFT_AUDIO)); // MIDI File
684 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mka"), ED2KFT_AUDIO)); // Matroska Audio File
685 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mod"), ED2KFT_AUDIO)); // Amiga Music Module File
686 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mol"), ED2KFT_AUDIO));
687 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp1"), ED2KFT_AUDIO)); // MPEG-1 Audio File
688 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp2"), ED2KFT_AUDIO)); // MPEG-2 Audio File
689 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp3"), ED2KFT_AUDIO)); // MPEG-3 Audio File
690 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpa"), ED2KFT_AUDIO)); // MPEG Audio File
691 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpc"), ED2KFT_AUDIO)); // Musepack Compressed Audio File
692 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpp"), ED2KFT_AUDIO));
693 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mtm"), ED2KFT_AUDIO)); // MultiTracker Module
694 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nst"), ED2KFT_AUDIO)); // NoiseTracker
695 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ogg"), ED2KFT_AUDIO)); // Ogg Vorbis Compressed Audio File
696 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".okt"), ED2KFT_AUDIO)); // Oktalyzer Module (Amiga)
697 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psm"), ED2KFT_AUDIO)); // Protracker Studio Module
698 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ptm"), ED2KFT_AUDIO)); // PolyTracker Module
699 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ra"), ED2KFT_AUDIO)); // Real Audio File
700 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmi"), ED2KFT_AUDIO)); // MIDI File
701 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".s3m"), ED2KFT_AUDIO)); // Scream Tracker 3 Module
702 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".snd"), ED2KFT_AUDIO)); // Audio File (Sun, Unix)
703 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".stm"), ED2KFT_AUDIO)); // Scream Tracker 2 Module
704 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ult"), ED2KFT_AUDIO)); // UltraTracker
705 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".umx"), ED2KFT_AUDIO)); // Unreal Music Package
706 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wav"), ED2KFT_AUDIO)); // WAVE Audio File
707 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wma"), ED2KFT_AUDIO)); // Windows Media Audio File
708 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wow"), ED2KFT_AUDIO)); // Grave Composer audio tracker
709 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xm"), ED2KFT_AUDIO)); // Fasttracker 2 Extended Module
711 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3g2"), ED2KFT_VIDEO)); // 3GPP Multimedia File
712 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3gp"), ED2KFT_VIDEO)); // 3GPP Multimedia File
713 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3gp2"), ED2KFT_VIDEO)); // 3GPP Multimedia File
714 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3gpp"), ED2KFT_VIDEO)); // 3GPP Multimedia File
715 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".asf"), ED2KFT_VIDEO)); // Advanced Systems Format (MS)
716 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".amv"), ED2KFT_VIDEO)); // Anime Music Video File
717 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".asf"), ED2KFT_VIDEO)); // Advanced Systems Format File
718 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".avi"), ED2KFT_VIDEO)); // Audio Video Interleave File
719 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bik"), ED2KFT_VIDEO)); // BINK Video File
720 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".divx"), ED2KFT_VIDEO)); // DivX-Encoded Movie File
721 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dvr-ms"),ED2KFT_VIDEO)); // Microsoft Digital Video Recording
722 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flc"), ED2KFT_VIDEO)); // FLIC Video File
723 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".fli"), ED2KFT_VIDEO)); // FLIC Video File
724 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flic"), ED2KFT_VIDEO)); // FLIC Video File
725 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flv"), ED2KFT_VIDEO)); // Flash Video File
726 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hdmov"), ED2KFT_VIDEO)); // High-Definition QuickTime Movie
727 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ifo"), ED2KFT_VIDEO)); // DVD-Video Disc Information File
728 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m1v"), ED2KFT_VIDEO)); // MPEG-1 Video File
729 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2t"), ED2KFT_VIDEO)); // MPEG-2 Video Transport Stream
730 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2ts"), ED2KFT_VIDEO)); // MPEG-2 Video Transport Stream
731 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2v"), ED2KFT_VIDEO)); // MPEG-2 Video File
732 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m4b"), ED2KFT_VIDEO)); // MPEG-4 Video File
733 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m4v"), ED2KFT_VIDEO)); // MPEG-4 Video File
734 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mkv"), ED2KFT_VIDEO)); // Matroska Video File
735 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mov"), ED2KFT_VIDEO)); // QuickTime Movie File
736 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".movie"), ED2KFT_VIDEO)); // QuickTime Movie File
737 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp1v"), ED2KFT_VIDEO)); // QuickTime Movie File
738 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp2v"), ED2KFT_VIDEO)); // MPEG-1 Video File
739 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp4"), ED2KFT_VIDEO)); // MPEG-2 Video File
740 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpe"), ED2KFT_VIDEO)); // MPEG-4 Video File
741 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpeg"), ED2KFT_VIDEO)); // MPEG Video File
742 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpg"), ED2KFT_VIDEO)); // MPEG Video File
743 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mps"), ED2KFT_VIDEO)); // MPEG Video File
744 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv"), ED2KFT_VIDEO)); // MPEG Video File
745 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv1"), ED2KFT_VIDEO)); // MPEG-1 Video File
746 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv2"), ED2KFT_VIDEO)); // MPEG-2 Video File
747 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ogm"), ED2KFT_VIDEO)); // Ogg Media File
748 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ogv"), ED2KFT_VIDEO)); // Ogg Theora Video File
749 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pva"), ED2KFT_VIDEO)); // MPEG Video File
750 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".qt"), ED2KFT_VIDEO)); // QuickTime Movie
751 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ram"), ED2KFT_VIDEO)); // Real Audio Media
752 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ratdvd"),ED2KFT_VIDEO)); // RatDVD Disk Image
753 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rm"), ED2KFT_VIDEO)); // Real Media File
754 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmm"), ED2KFT_VIDEO)); // Real Media File
755 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmvb"), ED2KFT_VIDEO)); // Real Video Variable Bit Rate File
756 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rv"), ED2KFT_VIDEO)); // Real Video File
757 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rv9"), ED2KFT_VIDEO));
758 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".smil"), ED2KFT_VIDEO)); // SMIL Presentation File
759 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".smk"), ED2KFT_VIDEO)); // Smacker Compressed Movie File
760 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".swf"), ED2KFT_VIDEO)); // Macromedia Flash Movie
761 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tp"), ED2KFT_VIDEO)); // Video Transport Stream File
762 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ts"), ED2KFT_VIDEO)); // Video Transport Stream File
763 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vid"), ED2KFT_VIDEO)); // General Video File
764 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".video"), ED2KFT_VIDEO)); // General Video File
765 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vivo"), ED2KFT_VIDEO)); // VivoActive Video File
766 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vob"), ED2KFT_VIDEO)); // DVD Video Object File
767 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vp6"), ED2KFT_VIDEO)); // TrueMotion VP6 Video File
768 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".webm"), ED2KFT_VIDEO)); // WebM Video File
769 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wm"), ED2KFT_VIDEO)); // Windows Media Video File
770 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmv"), ED2KFT_VIDEO)); // Windows Media Video File
771 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xvid"), ED2KFT_VIDEO)); // Xvid-Encoded Video File
773 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bmp"), ED2KFT_IMAGE)); // Bitmap Image File
774 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dcx"), ED2KFT_IMAGE)); // FAXserve Fax Document
775 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".emf"), ED2KFT_IMAGE)); // Enhanced Windows Metafile
776 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".gif"), ED2KFT_IMAGE)); // Graphical Interchange Format File
777 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ico"), ED2KFT_IMAGE)); // Icon File
778 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jfif"), ED2KFT_IMAGE)); // JPEG File Interchange Format
779 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpe"), ED2KFT_IMAGE)); // JPEG Image File
780 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpeg"), ED2KFT_IMAGE)); // JPEG Image File
781 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpg"), ED2KFT_IMAGE)); // JPEG Image File
782 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pct"), ED2KFT_IMAGE)); // PICT Picture File
783 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pcx"), ED2KFT_IMAGE)); // Paintbrush Bitmap Image File
784 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pic"), ED2KFT_IMAGE)); // PICT Picture File
785 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pict"), ED2KFT_IMAGE)); // PICT Picture File
786 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".png"), ED2KFT_IMAGE)); // Portable Network Graphic
787 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psd"), ED2KFT_IMAGE)); // Photoshop Document
788 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psp"), ED2KFT_IMAGE)); // Paint Shop Pro Image File
789 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tga"), ED2KFT_IMAGE)); // Targa Graphic
790 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tif"), ED2KFT_IMAGE)); // Tagged Image File
791 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tiff"), ED2KFT_IMAGE)); // Tagged Image File
792 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wbmp"), ED2KFT_IMAGE)); // Wireless Application Protocol Bitmap Format
793 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".webp"), ED2KFT_IMAGE)); // Weppy Photo File
794 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmf"), ED2KFT_IMAGE)); // Windows Metafile
795 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmp"), ED2KFT_IMAGE)); // Windows Media Photo File
796 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xif"), ED2KFT_IMAGE)); // ScanSoft Pagis Extended Image Format File
797 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xpm"), ED2KFT_IMAGE)); // X-Windows Pixmap
799 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".7z"), ED2KFT_ARCHIVE)); // 7-Zip Compressed File
800 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ace"), ED2KFT_ARCHIVE)); // WinAce Compressed File
801 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".alz"), ED2KFT_ARCHIVE)); // ALZip Archive
802 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".arc"), ED2KFT_ARCHIVE)); // Compressed File Archive
803 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".arj"), ED2KFT_ARCHIVE)); // ARJ Compressed File Archive
804 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bz2"), ED2KFT_ARCHIVE)); // Bzip Compressed File
805 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cab"), ED2KFT_ARCHIVE)); // Cabinet File
806 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cbr"), ED2KFT_ARCHIVE)); // Comic Book RAR Archive
807 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cbt"), ED2KFT_ARCHIVE)); // Comic Book Tarball
808 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cbz"), ED2KFT_ARCHIVE)); // Comic Book ZIP Archive
809 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".gz"), ED2KFT_ARCHIVE)); // Gnu Zipped File
810 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hqx"), ED2KFT_ARCHIVE)); // BinHex 4.0 Encoded File
811 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".lha"), ED2KFT_ARCHIVE)); // LHARC Compressed Archive
812 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".lzh"), ED2KFT_ARCHIVE)); // LZH Compressed File
813 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".msi"), ED2KFT_ARCHIVE)); // Microsoft Installer File
814 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pak"), ED2KFT_ARCHIVE)); // PAK (Packed) File
815 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".par"), ED2KFT_ARCHIVE)); // Parchive Index File
816 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".par2"), ED2KFT_ARCHIVE)); // Parchive 2 Index File
817 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rar"), ED2KFT_ARCHIVE)); // WinRAR Compressed Archive
818 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sea"), ED2KFT_ARCHIVE)); // Self-Extracting Archive (Mac)
819 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sit"), ED2KFT_ARCHIVE)); // Stuffit Archive
820 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sitx"), ED2KFT_ARCHIVE)); // Stuffit X Archive
821 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tar"), ED2KFT_ARCHIVE)); // Consolidated Unix File Archive
822 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tbz2"), ED2KFT_ARCHIVE)); // Tar BZip 2 Compressed File
823 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tgz"), ED2KFT_ARCHIVE)); // Gzipped Tar File
824 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".uc2"), ED2KFT_ARCHIVE)); // UltraCompressor 2 Archive
825 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xpi"), ED2KFT_ARCHIVE)); // Mozilla Installer Package
826 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".z"), ED2KFT_ARCHIVE)); // Unix Compressed File
827 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".zip"), ED2KFT_ARCHIVE)); // Zipped File
828 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".zoo"), ED2KFT_ARCHIVE)); // Zoo Archive
830 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bat"), ED2KFT_PROGRAM)); // Batch File
831 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cmd"), ED2KFT_PROGRAM)); // Command File
832 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".com"), ED2KFT_PROGRAM)); // COM File
833 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".exe"), ED2KFT_PROGRAM)); // Executable File
834 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hta"), ED2KFT_PROGRAM)); // HTML Application
835 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".js"), ED2KFT_PROGRAM)); // Java Script
836 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jse"), ED2KFT_PROGRAM)); // Encoded Java Script
837 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".msc"), ED2KFT_PROGRAM)); // Microsoft Common Console File
838 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vbe"), ED2KFT_PROGRAM)); // Encoded Visual Basic Script File
839 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vbs"), ED2KFT_PROGRAM)); // Visual Basic Script File
840 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wsf"), ED2KFT_PROGRAM)); // Windows Script File
841 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wsh"), ED2KFT_PROGRAM)); // Windows Scripting Host File
843 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bin"), ED2KFT_CDIMAGE)); // CD Image
844 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwa"), ED2KFT_CDIMAGE)); // BlindWrite Disk Information File
845 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwi"), ED2KFT_CDIMAGE)); // BlindWrite CD/DVD Disc Image
846 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bws"), ED2KFT_CDIMAGE)); // BlindWrite Sub Code File
847 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwt"), ED2KFT_CDIMAGE)); // BlindWrite 4 Disk Image
848 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ccd"), ED2KFT_CDIMAGE)); // CloneCD Disk Image
849 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cue"), ED2KFT_CDIMAGE)); // Cue Sheet File
850 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmg"), ED2KFT_CDIMAGE)); // Mac OS X Disk Image
851 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmz"), ED2KFT_CDIMAGE));
852 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".img"), ED2KFT_CDIMAGE)); // Disk Image Data File
853 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".iso"), ED2KFT_CDIMAGE)); // Disc Image File
854 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mdf"), ED2KFT_CDIMAGE)); // Media Disc Image File
855 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mds"), ED2KFT_CDIMAGE)); // Media Descriptor File
856 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nrg"), ED2KFT_CDIMAGE)); // Nero CD/DVD Image File
857 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sub"), ED2KFT_CDIMAGE)); // Subtitle File
858 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".toast"), ED2KFT_CDIMAGE)); // Toast Disc Image
860 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".azw"), ED2KFT_DOCUMENT)); // EBook File
861 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".chm"), ED2KFT_DOCUMENT)); // Compiled HTML Help File
862 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".css"), ED2KFT_DOCUMENT)); // Cascading Style Sheet
863 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".diz"), ED2KFT_DOCUMENT)); // Description in Zip File
864 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".doc"), ED2KFT_DOCUMENT)); // Document File
865 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dot"), ED2KFT_DOCUMENT)); // Document Template File
866 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".epub"), ED2KFT_DOCUMENT)); // EBook File
867 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hlp"), ED2KFT_DOCUMENT)); // Help File
868 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".htm"), ED2KFT_DOCUMENT)); // HTML File
869 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".html"), ED2KFT_DOCUMENT)); // HTML File
870 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mobi"), ED2KFT_DOCUMENT)); // EBook File
871 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nfo"), ED2KFT_DOCUMENT)); // Warez Information File
872 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".odp"), ED2KFT_DOCUMENT)); // OpenDocument Presentation
873 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ods"), ED2KFT_DOCUMENT)); // OpenDocument Spreadsheet
874 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".odt"), ED2KFT_DOCUMENT)); // OpenDocument File
875 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".otp"), ED2KFT_DOCUMENT)); // OpenDocument Presentation Template
876 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ott"), ED2KFT_DOCUMENT)); // OpenDocument Template File
877 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ots"), ED2KFT_DOCUMENT)); // OpenDocument Spreadsheet Template
878 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pdf"), ED2KFT_DOCUMENT)); // Portable Document Format File
879 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pps"), ED2KFT_DOCUMENT)); // PowerPoint Slide Show
880 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ppt"), ED2KFT_DOCUMENT)); // PowerPoint Presentation
881 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ps"), ED2KFT_DOCUMENT)); // PostScript File
882 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rtf"), ED2KFT_DOCUMENT)); // Rich Text Format File
883 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".stc"), ED2KFT_DOCUMENT)); // OpenOffice.org 1.0 Spreadsheet Template
884 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sti"), ED2KFT_DOCUMENT)); // OpenOffice.org 1.0 Presentation Template
885 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".stw"), ED2KFT_DOCUMENT)); // OpenOffice.org 1.0 Document Template File
886 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sxc"), ED2KFT_DOCUMENT)); // OpenOffice.org 1.0 Spreadsheet
887 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sxi"), ED2KFT_DOCUMENT)); // OpenOffice.org 1.0 Presentation
888 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sxw"), ED2KFT_DOCUMENT)); // OpenOffice.org 1.0 Document File
889 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".text"), ED2KFT_DOCUMENT)); // General Text File
890 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".txt"), ED2KFT_DOCUMENT)); // Text File
891 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wri"), ED2KFT_DOCUMENT)); // Windows Write Document
892 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xls"), ED2KFT_DOCUMENT)); // Microsoft Excel Spreadsheet
893 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xlt"), ED2KFT_DOCUMENT)); // Microsoft Excel Template
894 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xml"), ED2KFT_DOCUMENT)); // XML File
899 // get the list initialized *before* any code is accessing it
900 CED2KFileTypes theED2KFileTypes;
902 EED2KFileType GetED2KFileTypeID(const CPath& fileName)
904 const wxString ext = fileName.GetExt().Lower();
905 if (ext.IsEmpty()) {
906 return ED2KFT_ANY;
909 SED2KFileTypeMap::iterator it = ED2KFileTypesMap.find(wxT(".") + ext);
910 if (it != ED2KFileTypesMap.end()) {
911 return it->second.GetType();
912 } else {
913 return ED2KFT_ANY;
918 // Retuns the ed2k file type term which is to be used in server searches
919 wxString GetED2KFileTypeSearchTerm(EED2KFileType iFileID)
921 if (iFileID == ED2KFT_AUDIO) return ED2KFTSTR_AUDIO;
922 if (iFileID == ED2KFT_VIDEO) return ED2KFTSTR_VIDEO;
923 if (iFileID == ED2KFT_IMAGE) return ED2KFTSTR_IMAGE;
924 if (iFileID == ED2KFT_DOCUMENT) return ED2KFTSTR_DOCUMENT;
925 if (iFileID == ED2KFT_PROGRAM) return ED2KFTSTR_PROGRAM;
926 // NOTE: Archives and CD-Images are published with file type "Pro"
927 if (iFileID == ED2KFT_ARCHIVE) return ED2KFTSTR_PROGRAM;
928 if (iFileID == ED2KFT_CDIMAGE) return ED2KFTSTR_PROGRAM;
930 return wxEmptyString;
934 // Returns a file type which is used eMule internally only, examining the extention of the given filename
935 wxString GetFileTypeByName(const CPath& fileName)
937 EED2KFileType iFileType = GetED2KFileTypeID(fileName);
938 switch (iFileType) {
939 case ED2KFT_AUDIO: return ED2KFTSTR_AUDIO;
940 case ED2KFT_VIDEO: return ED2KFTSTR_VIDEO;
941 case ED2KFT_IMAGE: return ED2KFTSTR_IMAGE;
942 case ED2KFT_DOCUMENT: return ED2KFTSTR_DOCUMENT;
943 case ED2KFT_PROGRAM: return ED2KFTSTR_PROGRAM;
944 case ED2KFT_ARCHIVE: return ED2KFTSTR_ARCHIVE;
945 case ED2KFT_CDIMAGE: return ED2KFTSTR_CDIMAGE;
946 default: return wxEmptyString;
951 // Retuns the ed2k file type integer ID which is to be used for publishing+searching
952 EED2KFileType GetED2KFileTypeSearchID(EED2KFileType iFileID)
954 switch (iFileID) {
955 case ED2KFT_AUDIO: return ED2KFT_AUDIO;
956 case ED2KFT_VIDEO: return ED2KFT_VIDEO;
957 case ED2KFT_IMAGE: return ED2KFT_IMAGE;
958 case ED2KFT_DOCUMENT: return ED2KFT_DOCUMENT;
959 case ED2KFT_PROGRAM: return ED2KFT_PROGRAM;
960 // NOTE: Archives and CD-Images are published+searched with file type "Pro"
961 // NOTE: If this gets changed, the function 'GetED2KFileTypeSearchTerm' also needs to get updated!
962 case ED2KFT_ARCHIVE: return ED2KFT_PROGRAM;
963 case ED2KFT_CDIMAGE: return ED2KFT_PROGRAM;
964 default: return ED2KFT_ANY;
970 * Dumps a buffer to a wxString
972 wxString DumpMemToStr(const void *buff, int n, const wxString& msg, bool ok)
974 const unsigned char *p = (const unsigned char *)buff;
975 int lines = (n + 15)/ 16;
977 wxString result;
978 // Allocate aproximetly what is needed
979 result.Alloc( ( lines + 1 ) * 80 );
980 if ( !msg.IsEmpty() ) {
981 result += msg + wxT(" - ok=") + ( ok ? wxT("true, ") : wxT("false, ") );
984 result += CFormat(wxT("%d bytes\n")) % n;
985 for ( int i = 0; i < lines; ++i) {
986 // Show address
987 result += CFormat(wxT("%08x ")) % (i * 16);
989 // Show two columns of hex-values
990 for ( int j = 0; j < 2; ++j) {
991 for ( int k = 0; k < 8; ++k) {
992 int pos = 16 * i + 8 * j + k;
994 if ( pos < n ) {
995 result += CFormat(wxT("%02x ")) % p[pos];
996 } else {
997 result += wxT(" ");
1000 result += wxT(" ");
1002 result += wxT("|");
1003 // Show a column of ascii-values
1004 for ( int k = 0; k < 16; ++k) {
1005 int pos = 16 * i + k;
1007 if ( pos < n ) {
1008 if ( isspace( p[pos] ) ) {
1009 result += wxT(" ");
1010 } else if ( !isgraph( p[pos] ) ) {
1011 result += wxT(".");
1012 } else {
1013 result += (wxChar)p[pos];
1015 } else {
1016 result += wxT(" ");
1019 result += wxT("|\n");
1021 result.Shrink();
1023 return result;
1028 * Dumps a buffer to stdout
1030 void DumpMem(const void *buff, int n, const wxString& msg, bool ok)
1032 printf("%s\n", (const char*)unicode2char(DumpMemToStr( buff, n, msg, ok )) );
1037 // Dump mem in dword format
1038 void DumpMem_DW(const uint32 *ptr, int count)
1040 for(int i = 0; i < count; i++) {
1041 printf("%08x ", ptr[i]);
1042 if ( (i % 4) == 3) printf("\n");
1044 printf("\n");
1048 wxString GetConfigDir(const wxString &configFileBase)
1050 wxString configPath;
1052 // "Portable aMule" - Use aMule from an external USB drive
1053 // Check for ./config/amule.conf (or whatever gets passed as configFile)
1054 // and use this configuration if found
1055 const wxString configDir = JoinPaths(wxFileName::GetCwd(), wxT("config"));
1056 const wxString configFile = JoinPaths(configDir, configFileBase);
1058 if (CPath::DirExists(configDir) && CPath::FileExists(configFile)) {
1059 AddLogLineN(CFormat(_("Using config dir: %s")) % configDir);
1061 configPath = configDir;
1062 } else {
1063 configPath = wxStandardPaths::Get().GetUserDataDir();
1066 configPath += wxFileName::GetPathSeparator();
1068 return configPath;
1072 /*************************** Locale specific stuff ***************************/
1074 #ifndef __WINDOWS__
1075 # define SETWINLANG(LANG, SUBLANG)
1076 #else
1077 # define SETWINLANG(LANG, SUBLANG) \
1078 info.WinLang = LANG; \
1079 info.WinSublang = SUBLANG;
1080 #endif
1082 #define CUSTOMLANGUAGE(wxid, iso, winlang, winsublang, dir, desc) \
1083 info.Language = wxid; \
1084 info.CanonicalName = wxT(iso); \
1085 info.LayoutDirection = dir; \
1086 info.Description = wxT(desc); \
1087 SETWINLANG(winlang, winsublang) \
1088 wxLocale::AddLanguage(info);
1090 void InitCustomLanguages()
1092 wxLanguageInfo info;
1094 #if !wxCHECK_VERSION(2, 9, 0)
1095 CUSTOMLANGUAGE(wxLANGUAGE_ASTURIAN, "ast", 0, 0, wxLayout_LeftToRight, "Asturian");
1096 #endif
1100 void InitLocale(wxLocale& locale, int language)
1102 locale.Init(language, wxLOCALE_LOAD_DEFAULT);
1104 #if defined(__WXMAC__) || defined(__WINDOWS__)
1105 locale.AddCatalogLookupPathPrefix(JoinPaths(wxStandardPaths::Get().GetDataDir(), wxT("locale")));
1106 #else
1107 #if (wxCHECK_VERSION(2,9,5) && !wxCHECK_VERSION(3,0,3)) || (wxCHECK_VERSION(3,1,0) && !wxCHECK_VERSION(3,1,1))
1108 // Add correct place to look for catalog files if we're using a wxWidgets version where it's broken
1109 // See also http://trac.wxwidgets.org/ticket/17740
1110 locale.AddCatalogLookupPathPrefix(JoinPaths(JoinPaths(wxStandardPaths::Get().GetInstallPrefix(), wxT("share")), wxT("locale")));
1111 #endif /* wxCHECK_VERSION(2,9,5)... */
1112 #endif /* (!)(defined(__WXMAC__) || defined(__WINDOWS__)) */
1114 locale.AddCatalog(wxT(PACKAGE));
1118 int StrLang2wx(const wxString& language)
1120 // get rid of possible encoding and modifier
1121 wxString lang(language.BeforeFirst('.').BeforeFirst('@'));
1123 if (!lang.IsEmpty()) {
1124 const wxLanguageInfo *lng = wxLocale::FindLanguageInfo(lang);
1125 if (lng) {
1126 int langID = lng->Language;
1127 // Traditional Chinese: original Chinese, used in Taiwan, Hong Kong and Macau.
1128 // Simplified Chinese: simplified Chinese characters used in Mainland China since 1950s, and in some other places such as Singapore and Malaysia.
1130 // Chinese (Traditional) contains zh_TW, zh_HK and zh_MO (but there are differences in some words).
1131 // Because of most Traditional Chinese user are in Taiwan, zh_TW becomes the representation of Traditional Chinese.
1132 // Chinese (Simplified) contains zh_CN, zh_SG and zh_MY. In the same reason, zh_CN becomes the representation of Simplified Chinese.
1133 // (see http://forum.amule.org/index.php?topic=13208.msg98043#msg98043 )
1135 // wx maps "Traditional Chinese" to "Chinese" however. This must me corrected:
1136 if (langID == wxLANGUAGE_CHINESE) {
1137 langID = wxLANGUAGE_CHINESE_TRADITIONAL;
1139 return langID;
1140 } else {
1141 return wxLANGUAGE_DEFAULT;
1143 } else {
1144 return wxLANGUAGE_DEFAULT;
1149 wxString wxLang2Str(const int lang)
1151 if (lang != wxLANGUAGE_DEFAULT) {
1152 const wxLanguageInfo *lng = wxLocale::GetLanguageInfo(lang);
1153 if (lng) {
1154 return lng->CanonicalName;
1155 } else {
1156 return wxEmptyString;
1158 } else {
1159 return wxEmptyString;
1163 /*****************************************************************************/
1165 CMD4Hash GetPassword(bool allowEmptyPassword)
1167 wxString pass_plain;
1168 CMD4Hash password;
1169 #ifndef __WINDOWS__
1170 pass_plain = char2unicode(getpass("Enter password for mule connection: "));
1171 #else
1172 //#warning This way, pass enter is not hidden on windows. Bad thing.
1173 char temp_str[512];
1174 // Though fflush() on an input stream is undefined behaviour by the standard,
1175 // the MSVCRT version does seem to clear the input buffers.
1176 // cppcheck-suppress fflushOnInputStream
1177 fflush(stdin);
1178 printf("Enter password for mule connection: \n");
1179 fflush(stdout);
1180 fgets(temp_str, 512, stdin);
1181 temp_str[strlen(temp_str)-1] = '\0';
1182 pass_plain = char2unicode(temp_str);
1183 #endif
1184 wxCHECK2(password.Decode(MD5Sum(pass_plain).GetHash()), /* Do nothing. */ );
1185 if (!allowEmptyPassword) {
1186 // MD5 hash for an empty string, according to rfc1321.
1187 if (password.Encode() == wxT("D41D8CD98F00B204E9800998ECF8427E")) {
1188 printf("No empty password allowed.\n");
1189 return GetPassword(false);
1193 return password;
1197 const uint8 BitVector::s_posMask[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
1198 const uint8 BitVector::s_negMask[] = {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F};
1200 // File_checked_for_headers