Upstream tarball 10013
[amule.git] / src / OtherFunctions.cpp
blob89d413a7759495ceaf135157ea05a22b125061ce
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"
46 #include "OtherFunctions.h" // Interface declarations
48 #include <map>
50 #ifdef __WXBASE__
51 #include <cerrno>
52 #else
53 #include <wx/utils.h>
54 #endif
57 wxString GetMuleVersion()
59 wxString ver(wxT(VERSION));
61 ver += wxT(" using ");
64 // Figure out the wx build-type
65 #if defined(__WXGTK20__)
66 ver += wxT("wxGTK2");
67 #elif defined(__WXGTK__)
68 ver += wxT("wxGTK1");
69 // 2.9 has different builds for OSX: Carbon and Cocoa
70 #elif defined(__WXOSX_CARBON__)
71 ver += wxT("wxOSX Carbon");
72 #elif defined(__WXOSX_COCOA__)
73 ver += wxT("wxOSX Cocoa");
74 // different Cocoa port, "not been updated very actively since beginning 2008"
75 #elif defined(__WXCOCOA__)
76 ver += wxT("wxCocoa");
77 // 2.8 Mac
78 #elif defined(__WXMAC__)
79 ver += wxT("wxMac");
80 #elif defined(__WXMSW__) && defined(__VISUALC__)
81 ver += wxT("wxMSW VC");
82 #elif defined(__WXMSW__)
83 ver += wxT("wxMSW");
84 #endif
86 ver += wxString::Format(wxT(" v%d.%d.%d"), wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER );
88 #if defined(__WXDEBUG__)
89 ver += wxT(" (Debugging)");
90 #endif
92 #ifdef SVNDATE
93 ver += wxString::Format( wxT(" (Snapshot: %s)"), wxT(SVNDATE));
94 #endif
96 return ver;
100 // Formats a filesize in bytes to make it suitable for displaying
101 wxString CastItoXBytes( uint64 count )
104 if (count < 1024)
105 return wxString::Format( wxT("%u "), (unsigned)count) + wxPLURAL("byte", "bytes", count) ;
106 else if (count < 1048576)
107 return wxString::Format( wxT("%u "), (unsigned)count >> 10) + _("kB") ;
108 else if (count < 1073741824)
109 return wxString::Format( wxT("%.2f "), (float)(uint32)count/1048576) + _("MB") ;
110 else if (count < 1099511627776LL)
111 return wxString::Format( wxT("%.3f "), (float)((uint32)(count/1024))/1048576) + _("GB") ;
112 else
113 return wxString::Format( wxT("%.3f "), (float)count/1099511627776LL) + _("TB") ;
117 wxString CastItoIShort(uint64 count)
120 if (count < 1000)
121 return wxString::Format(wxT("%u"), (uint32)count);
122 else if (count < 1000000)
123 return wxString::Format(wxT("%.0f"),(float)(uint32)count/1000) + _("k") ;
124 else if (count < 1000000000)
125 return wxString::Format(wxT("%.2f"),(float)(uint32)count/1000000) + _("M") ;
126 else if (count < 1000000000000LL)
127 return wxString::Format(wxT("%.2f"),(float)((uint32)(count/1000))/1000000) + _("G") ;
128 else
129 return wxString::Format(wxT("%.2f"),(float)count/1000000000000LL) + _("T");
133 wxString CastItoSpeed(uint32 bytes)
135 if (bytes < 1024)
136 return wxString::Format(wxT("%u "), bytes) + wxPLURAL("byte/sec", "bytes/sec", bytes);
137 else if (bytes < 1048576)
138 return wxString::Format(wxT("%.2f "), bytes / 1024.0) + _("kB/s");
139 else
140 return wxString::Format(wxT("%.2f "), bytes / 1048576.0) + _("MB/s");
144 // Make a time value in seconds suitable for displaying
145 wxString CastSecondsToHM(uint32 count, uint16 msecs)
147 if (count < 60) {
148 if (!msecs) {
149 return wxString::Format(
150 wxT("%02u %s"), count, _("secs"));
151 } else {
152 return wxString::Format(
153 wxT("%.3f %s"),
154 (count + ((float)msecs/1000)), _("secs"));
156 } else if (count < 3600) {
157 return wxString::Format(
158 wxT("%u:%02u %s"),
159 count/60,
160 (count % 60),
161 _("mins"));
162 } else if (count < 86400) {
163 return wxString::Format(
164 wxT("%u:%02u %s"),
165 count/3600,
166 (count % 3600)/60,
167 _("hours"));
168 } else {
169 return wxString::Format(
170 wxT("%u %s %02u:%02u %s"),
171 count/86400,
172 _("Days"),
173 (count % 86400)/3600,
174 (count % 3600)/60,
175 _("hours"));
180 // Examines a filename and determines the filetype
181 FileType GetFiletype(const CPath& filename)
183 // FIXME: WTF do we have two such functions in the first place?
184 switch (GetED2KFileTypeID(filename)) {
185 case ED2KFT_AUDIO: return ftAudio;
186 case ED2KFT_VIDEO: return ftVideo;
187 case ED2KFT_IMAGE: return ftPicture;
188 case ED2KFT_PROGRAM: return ftProgram;
189 case ED2KFT_DOCUMENT: return ftText;
190 case ED2KFT_ARCHIVE: return ftArchive;
191 case ED2KFT_CDIMAGE: return ftCDImage;
192 default: return ftAny;
197 // Returns the (translated) description assosiated with a FileType
198 wxString GetFiletypeDesc(FileType type, bool translated)
200 switch ( type ) {
201 case ftVideo:
202 if (translated) {
203 return _("Videos");
204 } else {
205 return wxT("Videos");
207 break;
208 case ftAudio:
209 if (translated) {
210 return _("Audio");
211 } else {
212 return wxT("Audio");
214 break;
215 case ftArchive:
216 if (translated) {
217 return _("Archives");
218 } else {
219 return wxT("Archives");
221 break;
222 case ftCDImage:
223 if (translated) {
224 return _("CD-Images");
225 } else {
226 return wxT("CD-Images");
228 break;
229 case ftPicture:
230 if (translated) {
231 return _("Pictures");
232 } else {
233 return wxT("Pictures");
235 break;
236 case ftText:
237 if (translated) {
238 return _("Texts");
239 } else {
240 return wxT("Texts");
242 break;
243 case ftProgram:
244 if (translated) {
245 return _("Programs");
246 } else {
247 return wxT("Programs");
249 break;
250 default:
251 if (translated) {
252 return _("Any");
253 } else {
254 return wxT("Any");
256 break;
260 // Returns the Typename, examining the extention of the given filename
262 wxString GetFiletypeByName(const CPath& filename, bool translated)
264 return GetFiletypeDesc(GetFiletype(filename), translated);
268 // Return the text associated with a rating of a file
269 wxString GetRateString(uint16 rate)
271 switch ( rate ) {
272 case 0: return _("Not rated");
273 case 1: return _("Invalid / Corrupt / Fake");
274 case 2: return _("Poor");
275 case 3: return _("Fair");
276 case 4: return _("Good");
277 case 5: return _("Excellent");
278 default: return _("Not rated");
284 * Return the size in bytes of the given size-type
286 * @param type The type (as an int) where: 0 = Byte, 1 = KB, 2 = MB, 3 = GB
288 * @return The amount of Bytes the provided size-type represents
290 * Values over GB aren't handled since the amount of Bytes 1TB represents
291 * is over the uint32 capacity
293 uint32 GetTypeSize(uint8 type)
295 enum {Bytes, KB, MB, GB};
296 int size;
298 switch(type) {
299 case Bytes: size = 1; break;
300 case KB: size = 1024; break;
301 case MB: size = 1048576; break;
302 case GB: size = 1073741824; break;
303 default: size = -1; break;
305 return size;
309 // Base16 chars for encode an decode functions
310 static wxChar base16Chars[17] = wxT("0123456789ABCDEF");
311 static wxChar base32Chars[33] = wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");
312 #define BASE16_LOOKUP_MAX 23
313 static wxChar base16Lookup[BASE16_LOOKUP_MAX][2] = {
314 { wxT('0'), 0x0 },
315 { wxT('1'), 0x1 },
316 { wxT('2'), 0x2 },
317 { wxT('3'), 0x3 },
318 { wxT('4'), 0x4 },
319 { wxT('5'), 0x5 },
320 { wxT('6'), 0x6 },
321 { wxT('7'), 0x7 },
322 { wxT('8'), 0x8 },
323 { wxT('9'), 0x9 },
324 { wxT(':'), 0x9 },
325 { wxT(';'), 0x9 },
326 { wxT('<'), 0x9 },
327 { wxT('='), 0x9 },
328 { wxT('>'), 0x9 },
329 { wxT('?'), 0x9 },
330 { wxT('@'), 0x9 },
331 { wxT('A'), 0xA },
332 { wxT('B'), 0xB },
333 { wxT('C'), 0xC },
334 { wxT('D'), 0xD },
335 { wxT('E'), 0xE },
336 { wxT('F'), 0xF }
340 // Returns a BASE16 encoded byte array
342 // [In]
343 // buffer: Pointer to byte array
344 // bufLen: Lenght of buffer array
346 // [Return]
347 // wxString object with BASE16 encoded byte array
348 wxString EncodeBase16(const unsigned char* buffer, unsigned int bufLen)
350 wxString Base16Buff;
352 for(unsigned int i = 0; i < bufLen; ++i) {
353 Base16Buff += base16Chars[buffer[i] >> 4];
354 Base16Buff += base16Chars[buffer[i] & 0xf];
357 return Base16Buff;
361 // Decodes a BASE16 string into a byte array
363 // [In]
364 // base16Buffer: String containing BASE16
365 // base16BufLen: Lenght BASE16 coded string's length
367 // [Out]
368 // buffer: byte array containing decoded string
369 unsigned int DecodeBase16(const wxString &base16Buffer, unsigned int base16BufLen, byte *buffer)
371 if (base16BufLen & 1) {
372 return 0;
374 unsigned int ret = base16BufLen >> 1;
375 memset( buffer, 0, ret);
376 for(unsigned int i = 0; i < base16BufLen; ++i) {
377 int lookup = toupper(base16Buffer[i]) - wxT('0');
378 // Check to make sure that the given word falls inside a valid range
379 byte word = (lookup < 0 || lookup >= BASE16_LOOKUP_MAX) ?
380 0xFF : base16Lookup[lookup][1];
381 unsigned idx = i >> 1;
382 buffer[idx] = (i & 1) ? // odd or even?
383 (buffer[idx] | word) : (word << 4);
386 return ret;
390 // Returns a BASE32 encoded byte array
392 // [In]
393 // buffer: Pointer to byte array
394 // bufLen: Lenght of buffer array
396 // [Return]
397 // wxString object with BASE32 encoded byte array
398 wxString EncodeBase32(const unsigned char* buffer, unsigned int bufLen)
400 wxString Base32Buff;
401 unsigned int i, index;
402 unsigned char word;
404 for(i = 0, index = 0; i < bufLen;) {
405 // Is the current word going to span a byte boundary?
406 if (index > 3) {
407 word = (buffer[i] & (0xFF >> index));
408 index = (index + 5) % 8;
409 word <<= index;
410 if (i < bufLen - 1) {
411 word |= buffer[i + 1] >> (8 - index);
413 ++i;
414 } else {
415 word = (buffer[i] >> (8 - (index + 5))) & 0x1F;
416 index = (index + 5) % 8;
417 if (index == 0) {
418 ++i;
421 Base32Buff += (char) base32Chars[word];
424 return Base32Buff;
428 // Decodes a BASE32 string into a byte array
430 // [In]
431 // base32Buffer: String containing BASE32
432 // base32BufLen: Lenght BASE32 coded string's length
434 // [Out]
435 // buffer: byte array containing decoded string
436 // [Return]
437 // nDecodeLen:
438 unsigned int DecodeBase32(const wxString &base32Buffer, unsigned int base32BufLen, unsigned char *buffer)
440 size_t nInputLen = base32Buffer.Length();
441 uint32 nDecodeLen = (nInputLen * 5) / 8;
442 if ((nInputLen * 5) % 8 > 0) {
443 ++nDecodeLen;
445 if (base32BufLen == 0) {
446 return nDecodeLen;
448 if (nDecodeLen > base32BufLen) {
449 return 0;
452 uint32 nBits = 0;
453 int nCount = 0;
454 for (size_t i = 0; i < nInputLen; ++i)
456 if (base32Buffer[i] >= wxT('A') && base32Buffer[i] <= wxT('Z')) {
457 nBits |= ( base32Buffer[i] - wxT('A') );
459 else if (base32Buffer[i] >= wxT('a') && base32Buffer[i] <= wxT('z')) {
460 nBits |= ( base32Buffer[i] - wxT('a') );
462 else if (base32Buffer[i] >= wxT('2') && base32Buffer[i] <= wxT('7')) {
463 nBits |= ( base32Buffer[i] - wxT('2') + 26 );
464 } else {
465 return 0;
467 nCount += 5;
468 if (nCount >= 8)
470 *buffer++ = (byte)( nBits >> (nCount - 8) );
471 nCount -= 8;
473 nBits <<= 5;
476 return nDecodeLen;
481 * base64.c
483 * Base64 encoding/decoding command line filter
485 * Copyright (c) 2002-2008 Matthias Gaertner
486 * Adapted to use wxWidgets by
487 * Copyright (c) 2005-2008 Marcelo Roberto Jimenez ( phoenix@amule.org )
490 static const wxString to_b64(
491 /* 0000000000111111111122222222223333333333444444444455555555556666 */
492 /* 0123456789012345678901234567890123456789012345678901234567890123 */
493 wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"));
496 /* Option variables */
497 static bool g_fUseCRLF = false;
498 static unsigned int g_nCharsPerLine = 72;
499 static wxString strHeaderLine;
502 wxString EncodeBase64(const char *pbBufferIn, unsigned int bufLen)
504 wxString pbBufferOut;
505 wxString strHeader;
507 if( !strHeaderLine.IsEmpty() ) {
508 strHeader = wxT("-----BEGIN ") + strHeaderLine + wxT("-----");
509 if( g_fUseCRLF ) {
510 strHeader += wxT("\r");
512 strHeader += wxT("\n");
515 unsigned long nDiv = ((unsigned long)bufLen) / 3;
516 unsigned long nRem = ((unsigned long)bufLen) % 3;
517 unsigned int NewLineSize = g_fUseCRLF ? 2 : 1;
519 // Allocate enough space in the output buffer to speed up things
520 pbBufferOut.Alloc(
521 strHeader.Len() * 2 + // header/footer
522 (bufLen * 4) / 3 + 1 + // Number of codes
523 nDiv * NewLineSize + // Number of new lines
524 (nRem ? 1 : 0) * NewLineSize ); // Last line
525 pbBufferOut = strHeader;
527 unsigned long nChars = 0;
528 const unsigned char *pIn = (unsigned char*)pbBufferIn;
529 while( nDiv > 0 ) {
530 pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
531 pbBufferOut += to_b64[((pIn[0] << 4) & 0x30) | ((pIn[1] >> 4) & 0xf)];
532 pbBufferOut += to_b64[((pIn[1] << 2) & 0x3c) | ((pIn[2] >> 6) & 0x3)];
533 pbBufferOut += to_b64[ pIn[2] & 0x3f];
534 pIn += 3;
535 nDiv--;
536 nChars += 4;
537 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
538 nChars = 0;
539 if( g_fUseCRLF ) {
540 pbBufferOut += wxT("\r");
542 pbBufferOut += wxT("\n");
545 switch( nRem ) {
546 case 2:
547 pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
548 pbBufferOut += to_b64[((pIn[0] << 4) & 0x30) | ((pIn[1] >> 4) & 0xf)];
549 pbBufferOut += to_b64[ (pIn[1] << 2) & 0x3c];
550 pbBufferOut += wxT("=");
551 nChars += 4;
552 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
553 nChars = 0;
554 if( g_fUseCRLF ) {
555 pbBufferOut += wxT("\r");
557 pbBufferOut += wxT("\n");
559 break;
560 case 1:
561 pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
562 pbBufferOut += to_b64[ (pIn[0] << 4) & 0x30];
563 pbBufferOut += wxT("=");
564 pbBufferOut += wxT("=");
565 nChars += 4;
566 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
567 nChars = 0;
568 if( g_fUseCRLF ) {
569 pbBufferOut += wxT("\r");
571 pbBufferOut += wxT("\n");
573 break;
576 if( nRem > 0 ) {
577 if( nChars > 0 ) {
578 if( g_fUseCRLF ) {
579 pbBufferOut += wxT("\r");
581 pbBufferOut += wxT("\n");
585 if( !strHeaderLine.IsEmpty() ) {
586 pbBufferOut = wxT("-----END ") + strHeaderLine + wxT("-----");
587 if( g_fUseCRLF ) {
588 pbBufferOut += wxT("\r");
590 pbBufferOut += wxT("\n");
593 return pbBufferOut;
597 unsigned int DecodeBase64(const wxString &base64Buffer, unsigned int base64BufLen, unsigned char *buffer)
599 int z = 0; // 0 Normal, 1 skip MIME separator (---) to end of line
600 unsigned int nData = 0;
601 unsigned int i = 0;
603 if (base64BufLen == 0) {
604 *buffer = 0;
605 nData = 1;
608 for(unsigned int j = 0; j < base64BufLen; ++j) {
609 wxChar c = base64Buffer[j];
610 wxChar bits = wxT('z');
611 if( z > 0 ) {
612 if(c == wxT('\n')) {
613 z = 0;
616 else if(c >= wxT('A') && c <= wxT('Z')) {
617 bits = c - wxT('A');
619 else if(c >= wxT('a') && c <= wxT('z')) {
620 bits = c - wxT('a') + (wxChar)26;
622 else if(c >= wxT('0') && c <= wxT('9')) {
623 bits = c - wxT('0') + (wxChar)52;
625 else if(c == wxT('+')) {
626 bits = (wxChar)62;
628 else if(c == wxT('/')) {
629 bits = (wxChar)63;
631 else if(c == wxT('-')) {
632 z = 1;
634 else if(c == wxT('=')) {
635 break;
636 } else {
637 bits = wxT('y');
640 // Skips anything that was not recognized
641 // as a base64 valid char ('y' or 'z')
642 if (bits < (wxChar)64) {
643 switch (nData++) {
644 case 0:
645 buffer[i+0] = (bits << 2) & 0xfc;
646 break;
647 case 1:
648 buffer[i+0] |= (bits >> 4) & 0x03;
649 buffer[i+1] = (bits << 4) & 0xf0;
650 break;
651 case 2:
652 buffer[i+1] |= (bits >> 2) & 0x0f;
653 buffer[i+2] = (bits << 6) & 0xc0;
654 break;
655 case 3:
656 buffer[i+2] |= bits & 0x3f;
657 break;
659 if (nData == 4) {
660 nData = 0;
661 i += 3;
665 if (nData == 1) {
666 // Syntax error or buffer was empty
667 *buffer = 0;
668 nData = 0;
669 i = 0;
670 } else {
671 buffer[i+nData] = 0;
674 return i + nData;
678 // Returns the text assosiated with a category type
679 wxString GetCatTitle(int catid)
681 switch (catid) {
682 case 0: return _("all");
683 case 1: return _("all others");
684 case 2: return _("Incomplete");
685 case 3: return _("Completed");
686 case 4: return _("Waiting");
687 case 5: return _("Downloading");
688 case 6: return _("Erroneous");
689 case 7: return _("Paused");
690 case 8: return _("Stopped");
691 case 9: return _("Video");
692 case 10: return _("Audio");
693 case 11: return _("Archive");
694 case 12: return _("CD-Images");
695 case 13: return _("Pictures");
696 case 14: return _("Text");
697 case 15: return _("Active");
698 default: return wxT("?");
703 typedef std::map<wxString, EED2KFileTypeClass> SED2KFileTypeMap;
704 typedef SED2KFileTypeMap::value_type SED2KFileTypeMapElement;
705 static SED2KFileTypeMap ED2KFileTypesMap;
708 class CED2KFileTypes{
709 public:
710 CED2KFileTypes()
712 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".669"), ED2KFT_AUDIO)); // 8 channel tracker module
713 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aac"), ED2KFT_AUDIO)); // Advanced Audio Coding File
714 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ac3"), ED2KFT_AUDIO)); // Audio Codec 3 File
715 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aif"), ED2KFT_AUDIO)); // Audio Interchange File Format
716 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aifc"), ED2KFT_AUDIO)); // Audio Interchange File Format
717 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aiff"), ED2KFT_AUDIO)); // Audio Interchange File Format
718 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".amf"), ED2KFT_AUDIO)); // DSMI Advanced Module Format
719 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".amr"), ED2KFT_AUDIO)); // Adaptive Multi-Rate Codec File
720 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ams"), ED2KFT_AUDIO)); // Extreme Tracker Module
721 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ape"), ED2KFT_AUDIO)); // Monkey's Audio Lossless Audio File
722 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".au"), ED2KFT_AUDIO)); // Audio File (Sun, Unix)
723 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aud"), ED2KFT_AUDIO)); // General Audio File
724 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".audio"), ED2KFT_AUDIO)); // General Audio File
725 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cda"), ED2KFT_AUDIO)); // CD Audio Track
726 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dbm"), ED2KFT_AUDIO));
727 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmf"), ED2KFT_AUDIO)); // Delusion Digital Music File
728 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dsm"), ED2KFT_AUDIO)); // Digital Sound Module
729 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dts"), ED2KFT_AUDIO)); // DTS Encoded Audio File
730 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".far"), ED2KFT_AUDIO)); // Farandole Composer Module
731 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flac"), ED2KFT_AUDIO)); // Free Lossless Audio Codec File
732 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".it"), ED2KFT_AUDIO)); // Impulse Tracker Module
733 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m1a"), ED2KFT_AUDIO)); // MPEG-1 Audio File
734 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2a"), ED2KFT_AUDIO)); // MPEG-2 Audio File
735 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m4a"), ED2KFT_AUDIO)); // MPEG-4 Audio File
736 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mdl"), ED2KFT_AUDIO)); // DigiTrakker Module
737 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".med"), ED2KFT_AUDIO)); // Amiga MED Sound File
738 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mid"), ED2KFT_AUDIO)); // MIDI File
739 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".midi"), ED2KFT_AUDIO)); // MIDI File
740 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mka"), ED2KFT_AUDIO)); // Matroska Audio File
741 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mod"), ED2KFT_AUDIO)); // Amiga Music Module File
742 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mol"), ED2KFT_AUDIO));
743 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp1"), ED2KFT_AUDIO)); // MPEG-1 Audio File
744 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp2"), ED2KFT_AUDIO)); // MPEG-2 Audio File
745 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp3"), ED2KFT_AUDIO)); // MPEG-3 Audio File
746 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpa"), ED2KFT_AUDIO)); // MPEG Audio File
747 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpc"), ED2KFT_AUDIO)); // Musepack Compressed Audio File
748 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpp"), ED2KFT_AUDIO));
749 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mtm"), ED2KFT_AUDIO)); // MultiTracker Module
750 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nst"), ED2KFT_AUDIO)); // NoiseTracker
751 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ogg"), ED2KFT_AUDIO)); // Ogg Vorbis Compressed Audio File
752 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".okt"), ED2KFT_AUDIO)); // Oktalyzer Module (Amiga)
753 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psm"), ED2KFT_AUDIO)); // Protracker Studio Module
754 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ptm"), ED2KFT_AUDIO)); // PolyTracker Module
755 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ra"), ED2KFT_AUDIO)); // Real Audio File
756 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmi"), ED2KFT_AUDIO)); // MIDI File
757 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".s3m"), ED2KFT_AUDIO)); // Scream Tracker 3 Module
758 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".snd"), ED2KFT_AUDIO)); // Audio File (Sun, Unix)
759 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".stm"), ED2KFT_AUDIO)); // Scream Tracker 2 Module
760 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ult"), ED2KFT_AUDIO)); // UltraTracker
761 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".umx"), ED2KFT_AUDIO)); // Unreal Music Package
762 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wav"), ED2KFT_AUDIO)); // WAVE Audio File
763 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wma"), ED2KFT_AUDIO)); // Windows Media Audio File
764 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wow"), ED2KFT_AUDIO)); // Grave Composer audio tracker
765 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xm"), ED2KFT_AUDIO)); // Fasttracker 2 Extended Module
767 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3g2"), ED2KFT_VIDEO)); // 3GPP Multimedia File
768 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3gp"), ED2KFT_VIDEO)); // 3GPP Multimedia File
769 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3gp2"), ED2KFT_VIDEO)); // 3GPP Multimedia File
770 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".3gpp"), ED2KFT_VIDEO)); // 3GPP Multimedia File
771 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".asf"), ED2KFT_VIDEO)); // Advanced Systems Format (MS)
772 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".amv"), ED2KFT_VIDEO)); // Anime Music Video File
773 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".asf"), ED2KFT_VIDEO)); // Advanced Systems Format File
774 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".avi"), ED2KFT_VIDEO)); // Audio Video Interleave File
775 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bik"), ED2KFT_VIDEO)); // BINK Video File
776 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".divx"), ED2KFT_VIDEO)); // DivX-Encoded Movie File
777 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dvr-ms"),ED2KFT_VIDEO)); // Microsoft Digital Video Recording
778 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flc"), ED2KFT_VIDEO)); // FLIC Video File
779 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".fli"), ED2KFT_VIDEO)); // FLIC Video File
780 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flic"), ED2KFT_VIDEO)); // FLIC Video File
781 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flv"), ED2KFT_VIDEO)); // Flash Video File
782 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hdmov"), ED2KFT_VIDEO)); // High-Definition QuickTime Movie
783 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ifo"), ED2KFT_VIDEO)); // DVD-Video Disc Information File
784 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m1v"), ED2KFT_VIDEO)); // MPEG-1 Video File
785 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2t"), ED2KFT_VIDEO)); // MPEG-2 Video Transport Stream
786 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2ts"), ED2KFT_VIDEO)); // MPEG-2 Video Transport Stream
787 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2v"), ED2KFT_VIDEO)); // MPEG-2 Video File
788 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m4b"), ED2KFT_VIDEO)); // MPEG-4 Video File
789 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m4v"), ED2KFT_VIDEO)); // MPEG-4 Video File
790 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mkv"), ED2KFT_VIDEO)); // Matroska Video File
791 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mov"), ED2KFT_VIDEO)); // QuickTime Movie File
792 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".movie"), ED2KFT_VIDEO)); // QuickTime Movie File
793 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp1v"), ED2KFT_VIDEO)); // QuickTime Movie File
794 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp2v"), ED2KFT_VIDEO)); // MPEG-1 Video File
795 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp4"), ED2KFT_VIDEO)); // MPEG-2 Video File
796 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpe"), ED2KFT_VIDEO)); // MPEG-4 Video File
797 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpeg"), ED2KFT_VIDEO)); // MPEG Video File
798 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpg"), ED2KFT_VIDEO)); // MPEG Video File
799 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mps"), ED2KFT_VIDEO)); // MPEG Video File
800 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv"), ED2KFT_VIDEO)); // MPEG Video File
801 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv1"), ED2KFT_VIDEO)); // MPEG-1 Video File
802 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv2"), ED2KFT_VIDEO)); // MPEG-2 Video File
803 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ogm"), ED2KFT_VIDEO)); // Ogg Media File
804 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pva"), ED2KFT_VIDEO)); // MPEG Video File
805 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".qt"), ED2KFT_VIDEO)); // QuickTime Movie
806 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ram"), ED2KFT_VIDEO)); // Real Audio Media
807 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ratdvd"),ED2KFT_VIDEO)); // RatDVD Disk Image
808 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rm"), ED2KFT_VIDEO)); // Real Media File
809 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmm"), ED2KFT_VIDEO)); // Real Media File
810 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmvb"), ED2KFT_VIDEO)); // Real Video Variable Bit Rate File
811 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rv"), ED2KFT_VIDEO)); // Real Video File
812 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rv9"), ED2KFT_VIDEO));
813 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".smil"), ED2KFT_VIDEO)); // SMIL Presentation File
814 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".smk"), ED2KFT_VIDEO)); // Smacker Compressed Movie File
815 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".swf"), ED2KFT_VIDEO)); // Macromedia Flash Movie
816 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tp"), ED2KFT_VIDEO)); // Video Transport Stream File
817 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ts"), ED2KFT_VIDEO)); // Video Transport Stream File
818 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vid"), ED2KFT_VIDEO)); // General Video File
819 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".video"), ED2KFT_VIDEO)); // General Video File
820 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vivo"), ED2KFT_VIDEO)); // VivoActive Video File
821 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vob"), ED2KFT_VIDEO)); // DVD Video Object File
822 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vp6"), ED2KFT_VIDEO)); // TrueMotion VP6 Video File
823 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wm"), ED2KFT_VIDEO)); // Windows Media Video File
824 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmv"), ED2KFT_VIDEO)); // Windows Media Video File
825 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xvid"), ED2KFT_VIDEO)); // Xvid-Encoded Video File
827 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bmp"), ED2KFT_IMAGE)); // Bitmap Image File
828 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dcx"), ED2KFT_IMAGE)); // FAXserve Fax Document
829 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".emf"), ED2KFT_IMAGE)); // Enhanced Windows Metafile
830 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".gif"), ED2KFT_IMAGE)); // Graphical Interchange Format File
831 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ico"), ED2KFT_IMAGE)); // Icon File
832 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jfif"), ED2KFT_IMAGE)); // JPEG File Interchange Format
833 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpe"), ED2KFT_IMAGE)); // JPEG Image File
834 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpeg"), ED2KFT_IMAGE)); // JPEG Image File
835 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpg"), ED2KFT_IMAGE)); // JPEG Image File
836 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pct"), ED2KFT_IMAGE)); // PICT Picture File
837 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pcx"), ED2KFT_IMAGE)); // Paintbrush Bitmap Image File
838 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pic"), ED2KFT_IMAGE)); // PICT Picture File
839 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pict"), ED2KFT_IMAGE)); // PICT Picture File
840 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".png"), ED2KFT_IMAGE)); // Portable Network Graphic
841 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psd"), ED2KFT_IMAGE)); // Photoshop Document
842 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psp"), ED2KFT_IMAGE)); // Paint Shop Pro Image File
843 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tga"), ED2KFT_IMAGE)); // Targa Graphic
844 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tif"), ED2KFT_IMAGE)); // Tagged Image File
845 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tiff"), ED2KFT_IMAGE)); // Tagged Image File
846 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmf"), ED2KFT_IMAGE)); // Windows Metafile
847 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmp"), ED2KFT_IMAGE)); // Windows Media Photo File
848 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xif"), ED2KFT_IMAGE)); // ScanSoft Pagis Extended Image Format File
849 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xpm"), ED2KFT_IMAGE)); // X-Windows Pixmap
851 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".7z"), ED2KFT_ARCHIVE)); // 7-Zip Compressed File
852 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ace"), ED2KFT_ARCHIVE)); // WinAce Compressed File
853 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".alz"), ED2KFT_ARCHIVE)); // ALZip Archive
854 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".arc"), ED2KFT_ARCHIVE)); // Compressed File Archive
855 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".arj"), ED2KFT_ARCHIVE)); // ARJ Compressed File Archive
856 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bz2"), ED2KFT_ARCHIVE)); // Bzip Compressed File
857 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cab"), ED2KFT_ARCHIVE)); // Cabinet File
858 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cbr"), ED2KFT_ARCHIVE)); // Comic Book RAR Archive
859 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cbz"), ED2KFT_ARCHIVE)); // Comic Book ZIP Archive
860 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".gz"), ED2KFT_ARCHIVE)); // Gnu Zipped File
861 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hqx"), ED2KFT_ARCHIVE)); // BinHex 4.0 Encoded File
862 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".lha"), ED2KFT_ARCHIVE)); // LHARC Compressed Archive
863 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".lzh"), ED2KFT_ARCHIVE)); // LZH Compressed File
864 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".msi"), ED2KFT_ARCHIVE)); // Microsoft Installer File
865 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pak"), ED2KFT_ARCHIVE)); // PAK (Packed) File
866 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".par"), ED2KFT_ARCHIVE)); // Parchive Index File
867 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".par2"), ED2KFT_ARCHIVE)); // Parchive 2 Index File
868 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rar"), ED2KFT_ARCHIVE)); // WinRAR Compressed Archive
869 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sea"), ED2KFT_ARCHIVE)); // Self-Extracting Archive (Mac)
870 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sit"), ED2KFT_ARCHIVE)); // Stuffit Archive
871 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sitx"), ED2KFT_ARCHIVE)); // Stuffit X Archive
872 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tar"), ED2KFT_ARCHIVE)); // Consolidated Unix File Archive
873 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tbz2"), ED2KFT_ARCHIVE)); // Tar BZip 2 Compressed File
874 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tgz"), ED2KFT_ARCHIVE)); // Gzipped Tar File
875 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".uc2"), ED2KFT_ARCHIVE)); // UltraCompressor 2 Archive
876 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xpi"), ED2KFT_ARCHIVE)); // Mozilla Installer Package
877 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".z"), ED2KFT_ARCHIVE)); // Unix Compressed File
878 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".zip"), ED2KFT_ARCHIVE)); // Zipped File
880 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bat"), ED2KFT_PROGRAM)); // Batch File
881 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cmd"), ED2KFT_PROGRAM)); // Command File
882 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".com"), ED2KFT_PROGRAM)); // COM File
883 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".exe"), ED2KFT_PROGRAM)); // Executable File
884 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hta"), ED2KFT_PROGRAM)); // HTML Application
885 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".js"), ED2KFT_PROGRAM)); // Java Script
886 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jse"), ED2KFT_PROGRAM)); // Encoded Java Script
887 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".msc"), ED2KFT_PROGRAM)); // Microsoft Common Console File
888 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vbe"), ED2KFT_PROGRAM)); // Encoded Visual Basic Script File
889 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vbs"), ED2KFT_PROGRAM)); // Visual Basic Script File
890 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wsf"), ED2KFT_PROGRAM)); // Windows Script File
891 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wsh"), ED2KFT_PROGRAM)); // Windows Scripting Host File
893 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bin"), ED2KFT_CDIMAGE)); // CD Image
894 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwa"), ED2KFT_CDIMAGE)); // BlindWrite Disk Information File
895 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwi"), ED2KFT_CDIMAGE)); // BlindWrite CD/DVD Disc Image
896 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bws"), ED2KFT_CDIMAGE)); // BlindWrite Sub Code File
897 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwt"), ED2KFT_CDIMAGE)); // BlindWrite 4 Disk Image
898 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ccd"), ED2KFT_CDIMAGE)); // CloneCD Disk Image
899 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cue"), ED2KFT_CDIMAGE)); // Cue Sheet File
900 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmg"), ED2KFT_CDIMAGE)); // Mac OS X Disk Image
901 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmz"), ED2KFT_CDIMAGE));
902 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".img"), ED2KFT_CDIMAGE)); // Disk Image Data File
903 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".iso"), ED2KFT_CDIMAGE)); // Disc Image File
904 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mdf"), ED2KFT_CDIMAGE)); // Media Disc Image File
905 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mds"), ED2KFT_CDIMAGE)); // Media Descriptor File
906 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nrg"), ED2KFT_CDIMAGE)); // Nero CD/DVD Image File
907 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sub"), ED2KFT_CDIMAGE)); // Subtitle File
908 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".toast"), ED2KFT_CDIMAGE)); // Toast Disc Image
910 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".chm"), ED2KFT_DOCUMENT)); // Compiled HTML Help File
911 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".css"), ED2KFT_DOCUMENT)); // Cascading Style Sheet
912 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".diz"), ED2KFT_DOCUMENT)); // Description in Zip File
913 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".doc"), ED2KFT_DOCUMENT)); // Document File
914 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dot"), ED2KFT_DOCUMENT)); // Document Template File
915 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hlp"), ED2KFT_DOCUMENT)); // Help File
916 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".htm"), ED2KFT_DOCUMENT)); // HTML File
917 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".html"), ED2KFT_DOCUMENT)); // HTML File
918 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nfo"), ED2KFT_DOCUMENT)); // Warez Information File
919 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pdf"), ED2KFT_DOCUMENT)); // Portable Document Format File
920 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pps"), ED2KFT_DOCUMENT)); // PowerPoint Slide Show
921 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ppt"), ED2KFT_DOCUMENT)); // PowerPoint Presentation
922 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ps"), ED2KFT_DOCUMENT)); // PostScript File
923 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rtf"), ED2KFT_DOCUMENT)); // Rich Text Format File
924 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".text"), ED2KFT_DOCUMENT)); // General Text File
925 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".txt"), ED2KFT_DOCUMENT)); // Text File
926 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wri"), ED2KFT_DOCUMENT)); // Windows Write Document
927 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xls"), ED2KFT_DOCUMENT)); // Microsoft Excel Spreadsheet
928 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xlt"), ED2KFT_DOCUMENT)); // Microsoft Excel Template
929 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xml"), ED2KFT_DOCUMENT)); // XML File
934 // get the list initialized *before* any code is accessing it
935 CED2KFileTypes theED2KFileTypes;
937 EED2KFileType GetED2KFileTypeID(const CPath& fileName)
939 const wxString ext = fileName.GetExt().Lower();
940 if (ext.IsEmpty()) {
941 return ED2KFT_ANY;
944 SED2KFileTypeMap::iterator it = ED2KFileTypesMap.find(wxT(".") + ext);
945 if (it != ED2KFileTypesMap.end()) {
946 return it->second.GetType();
947 } else {
948 return ED2KFT_ANY;
953 // Retuns the ed2k file type term which is to be used in server searches
954 wxString GetED2KFileTypeSearchTerm(EED2KFileType iFileID)
956 if (iFileID == ED2KFT_AUDIO) return ED2KFTSTR_AUDIO;
957 if (iFileID == ED2KFT_VIDEO) return ED2KFTSTR_VIDEO;
958 if (iFileID == ED2KFT_IMAGE) return ED2KFTSTR_IMAGE;
959 if (iFileID == ED2KFT_DOCUMENT) return ED2KFTSTR_DOCUMENT;
960 if (iFileID == ED2KFT_PROGRAM) return ED2KFTSTR_PROGRAM;
961 // NOTE: Archives and CD-Images are published with file type "Pro"
962 if (iFileID == ED2KFT_ARCHIVE) return ED2KFTSTR_PROGRAM;
963 if (iFileID == ED2KFT_CDIMAGE) return ED2KFTSTR_PROGRAM;
965 return wxEmptyString;
969 // Returns a file type which is used eMule internally only, examining the extention of the given filename
970 wxString GetFileTypeByName(const CPath& fileName)
972 EED2KFileType iFileType = GetED2KFileTypeID(fileName);
973 switch (iFileType) {
974 case ED2KFT_AUDIO: return ED2KFTSTR_AUDIO;
975 case ED2KFT_VIDEO: return ED2KFTSTR_VIDEO;
976 case ED2KFT_IMAGE: return ED2KFTSTR_IMAGE;
977 case ED2KFT_DOCUMENT: return ED2KFTSTR_DOCUMENT;
978 case ED2KFT_PROGRAM: return ED2KFTSTR_PROGRAM;
979 case ED2KFT_ARCHIVE: return ED2KFTSTR_ARCHIVE;
980 case ED2KFT_CDIMAGE: return ED2KFTSTR_CDIMAGE;
981 default: return wxEmptyString;
986 // Retuns the ed2k file type integer ID which is to be used for publishing+searching
987 EED2KFileType GetED2KFileTypeSearchID(EED2KFileType iFileID)
989 switch (iFileID) {
990 case ED2KFT_AUDIO: return ED2KFT_AUDIO;
991 case ED2KFT_VIDEO: return ED2KFT_VIDEO;
992 case ED2KFT_IMAGE: return ED2KFT_IMAGE;
993 case ED2KFT_DOCUMENT: return ED2KFT_DOCUMENT;
994 case ED2KFT_PROGRAM: return ED2KFT_PROGRAM;
995 // NOTE: Archives and CD-Images are published+searched with file type "Pro"
996 // NOTE: If this gets changed, the function 'GetED2KFileTypeSearchTerm' also needs to get updated!
997 case ED2KFT_ARCHIVE: return ED2KFT_PROGRAM;
998 case ED2KFT_CDIMAGE: return ED2KFT_PROGRAM;
999 default: return ED2KFT_ANY;
1005 * Dumps a buffer to a wxString
1007 wxString DumpMemToStr(const void *buff, int n, const wxString& msg, bool ok)
1009 const unsigned char *p = (const unsigned char *)buff;
1010 int lines = (n + 15)/ 16;
1012 wxString result;
1013 // Allocate aproximetly what is needed
1014 result.Alloc( ( lines + 1 ) * 80 );
1015 if ( !msg.IsEmpty() ) {
1016 result += msg + wxT(" - ok=") + ( ok ? wxT("true, ") : wxT("false, ") );
1019 result += wxString::Format( wxT("%d bytes\n"), n );
1020 for ( int i = 0; i < lines; ++i) {
1021 // Show address
1022 result += wxString::Format( wxT("%08x "), i * 16 );
1024 // Show two columns of hex-values
1025 for ( int j = 0; j < 2; ++j) {
1026 for ( int k = 0; k < 8; ++k) {
1027 int pos = 16 * i + 8 * j + k;
1029 if ( pos < n ) {
1030 result += wxString::Format( wxT("%02x "), p[pos] );
1031 } else {
1032 result += wxT(" ");
1035 result += wxT(" ");
1037 result += wxT("|");
1038 // Show a column of ascii-values
1039 for ( int k = 0; k < 16; ++k) {
1040 int pos = 16 * i + k;
1042 if ( pos < n ) {
1043 if ( isspace( p[pos] ) ) {
1044 result += wxT(" ");
1045 } else if ( !isgraph( p[pos] ) ) {
1046 result += wxT(".");
1047 } else {
1048 result += (wxChar)p[pos];
1050 } else {
1051 result += wxT(" ");
1054 result += wxT("|\n");
1056 result.Shrink();
1058 return result;
1063 * Dumps a buffer to stdout
1065 void DumpMem(const void *buff, int n, const wxString& msg, bool ok)
1067 printf("%s\n", (const char*)unicode2char(DumpMemToStr( buff, n, msg, ok )) );
1072 // Dump mem in dword format
1073 void DumpMem_DW(const uint32 *ptr, int count)
1075 for(int i = 0; i < count; i++) {
1076 printf("%08x ", ptr[i]);
1077 if ( (i % 4) == 3) printf("\n");
1079 printf("\n");
1083 wxString GetConfigDir(const wxString &configFileBase)
1085 // Cache the path.
1086 static wxString configPath;
1088 if (configPath.IsEmpty()) {
1089 // "Portable aMule" - Use aMule from an external USB drive
1090 // Check for ./config/amule.conf (or whatever gets passed as configFile)
1091 // and use this configuration if found
1092 const wxString configDir = JoinPaths(wxFileName::GetCwd(), wxT("config"));
1093 const wxString configFile = JoinPaths(configDir, configFileBase);
1095 if (CPath::DirExists(configDir) && CPath::FileExists(configFile)) {
1096 AddLogLineN(CFormat(wxT("Using configDir: %s")) % configDir);
1098 configPath = configDir;
1099 } else {
1100 configPath = wxStandardPaths::Get().GetUserDataDir();
1103 configPath += wxFileName::GetPathSeparator();
1106 return configPath;
1110 /*************************** Locale specific stuff ***************************/
1112 #ifndef __WXMSW__
1113 # define SETWINLANG(LANG, SUBLANG)
1114 #else
1115 # define SETWINLANG(LANG, SUBLANG) \
1116 info.WinLang = LANG; \
1117 info.WinSublang = SUBLANG;
1118 #endif
1120 #define CUSTOMLANGUAGE(wxid, iso, winlang, winsublang, dir, desc) \
1121 info.Language = wxid; \
1122 info.CanonicalName = wxT(iso); \
1123 info.LayoutDirection = dir; \
1124 info.Description = wxT(desc); \
1125 SETWINLANG(winlang, winsublang) \
1126 wxLocale::AddLanguage(info);
1128 void InitCustomLanguages()
1130 wxLanguageInfo info;
1132 #if !wxCHECK_VERSION(2, 9, 0)
1133 CUSTOMLANGUAGE(wxLANGUAGE_ASTURIAN, "ast", 0, 0, wxLayout_LeftToRight, "Asturian");
1134 #endif
1138 void InitLocale(wxLocale& locale, int language)
1140 locale.Init(language, wxLOCALE_LOAD_DEFAULT);
1142 #if defined(__WXMAC__) || defined(__WXMSW__)
1143 locale.AddCatalogLookupPathPrefix(JoinPaths(wxStandardPaths::Get().GetDataDir(), wxT("locale")));
1144 #endif
1145 locale.AddCatalog(wxT(PACKAGE));
1149 int StrLang2wx(const wxString& language)
1151 // get rid of possible encoding and modifier
1152 wxString lang(language.BeforeFirst('.').BeforeFirst('@'));
1154 if (!lang.IsEmpty()) {
1155 const wxLanguageInfo *lng = wxLocale::FindLanguageInfo(lang);
1156 if (lng) {
1157 return lng->Language;
1158 } else {
1159 return wxLANGUAGE_DEFAULT;
1161 } else {
1162 return wxLANGUAGE_DEFAULT;
1167 wxString wxLang2Str(const int lang)
1169 if (lang != wxLANGUAGE_DEFAULT) {
1170 const wxLanguageInfo *lng = wxLocale::GetLanguageInfo(lang);
1171 if (lng) {
1172 return lng->CanonicalName;
1173 } else {
1174 return wxEmptyString;
1176 } else {
1177 return wxEmptyString;
1181 /*****************************************************************************/
1183 wxString GetPassword() {
1184 wxString pass_plain;
1185 CMD4Hash password;
1186 #ifndef __WXMSW__
1187 pass_plain = char2unicode(getpass("Enter password for mule connection: "));
1188 #else
1189 //#warning This way, pass enter is not hidden on windows. Bad thing.
1190 char temp_str[512];
1191 fflush(stdin);
1192 printf("Enter password for mule connection: \n");
1193 fflush(stdout);
1194 fgets(temp_str, 512, stdin);
1195 temp_str[strlen(temp_str)-1] = '\0';
1196 pass_plain = char2unicode(temp_str);
1197 #endif
1198 wxCHECK2(password.Decode(MD5Sum(pass_plain).GetHash()), /* Do nothing. */ );
1199 // MD5 hash for an empty string, according to rfc1321.
1200 if (password.Encode() == wxT("D41D8CD98F00B204E9800998ECF8427E")) {
1201 printf("No empty password allowed.\n");
1202 return GetPassword();
1206 return password.Encode();
1209 // File_checked_for_headers