2 // This file is part of the aMule Project.
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 )
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
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
35 #include "config.h" // Needed for a number of defines
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>
46 #include "OtherFunctions.h" // Interface declarations
57 wxString
GetMuleVersion()
59 wxString
ver(wxT(VERSION
));
61 ver
+= wxT(" using ");
64 // Figure out the wx build-type
71 #elif defined(__WXMAC__)
73 #elif defined(__WXMSW__)
75 #elif defined(__WXCOCOA__)
76 ver
+= wxT("wxCocoa");
79 ver
+= wxString::Format(wxT(" v%d.%d.%d"), wxMAJOR_VERSION
, wxMINOR_VERSION
, wxRELEASE_NUMBER
);
81 #if defined(__WXDEBUG__)
82 ver
+= wxT(" (Debugging)");
86 ver
+= wxString::Format( wxT(" (Snapshot: %s)"), wxT(SVNDATE
));
93 wxString
GetFullMuleVersion()
96 wxString app
= wxT("aMuled");
97 #elif defined(CLIENT_GUI)
98 wxString app
= wxT("Remote aMule-GUI");
100 wxString app
= wxT("aMule");
103 return app
+ wxT(" ") + GetMuleVersion();
107 // Formats a filesize in bytes to make it suitable for displaying
108 wxString
CastItoXBytes( uint64 count
)
112 return wxString::Format( wxT("%u "), (unsigned)count
) + wxPLURAL("byte", "bytes", count
) ;
113 else if (count
< 1048576)
114 return wxString::Format( wxT("%u "), (unsigned)count
>> 10) + _("kB") ;
115 else if (count
< 1073741824)
116 return wxString::Format( wxT("%.2f "), (float)(uint32
)count
/1048576) + _("MB") ;
117 else if (count
< 1099511627776LL)
118 return wxString::Format( wxT("%.2f "), (float)((uint32
)(count
/1024))/1048576) + _("GB") ;
120 return wxString::Format( wxT("%.3f "), (float)count
/1099511627776LL) + _("TB") ;
124 wxString
CastItoIShort(uint64 count
)
128 return wxString::Format(wxT("%u"), (uint32
)count
);
129 else if (count
< 1000000)
130 return wxString::Format(wxT("%.0f"),(float)(uint32
)count
/1000) + _("k") ;
131 else if (count
< 1000000000)
132 return wxString::Format(wxT("%.2f"),(float)(uint32
)count
/1000000) + _("M") ;
133 else if (count
< 1000000000000LL)
134 return wxString::Format(wxT("%.2f"),(float)((uint32
)(count
/1000))/1000000) + _("G") ;
136 return wxString::Format(wxT("%.2f"),(float)count
/1000000000000LL) + _("T");
140 wxString
CastItoSpeed(uint32 bytes
)
143 return wxString::Format(wxT("%u "), bytes
) + wxPLURAL("byte/sec", "bytes/sec", bytes
);
144 else if (bytes
< 1048576)
145 return wxString::Format(wxT("%.2f "), bytes
/ 1024.0) + _("kB/s");
147 return wxString::Format(wxT("%.2f "), bytes
/ 1048576.0) + _("MB/s");
151 // Make a time value in seconds suitable for displaying
152 wxString
CastSecondsToHM(uint32 count
, uint16 msecs
)
156 return wxString::Format(
157 wxT("%02u %s"), count
, _("secs"));
159 return wxString::Format(
161 (count
+ ((float)msecs
/1000)), _("secs"));
163 } else if (count
< 3600) {
164 return wxString::Format(
169 } else if (count
< 86400) {
170 return wxString::Format(
176 return wxString::Format(
177 wxT("%u %s %02u:%02u %s"),
180 (count
% 86400)/3600,
187 // Examines a filename and determines the filetype
188 FileType
GetFiletype(const CPath
& filename
)
190 // FIXME: WTF do we have two such functions in the first place?
191 switch (GetED2KFileTypeID(filename
)) {
192 case ED2KFT_AUDIO
: return ftAudio
;
193 case ED2KFT_VIDEO
: return ftVideo
;
194 case ED2KFT_IMAGE
: return ftPicture
;
195 case ED2KFT_PROGRAM
: return ftProgram
;
196 case ED2KFT_DOCUMENT
: return ftText
;
197 case ED2KFT_ARCHIVE
: return ftArchive
;
198 case ED2KFT_CDIMAGE
: return ftCDImage
;
199 default: return ftAny
;
204 // Returns the (translated) description assosiated with a FileType
205 wxString
GetFiletypeDesc(FileType type
, bool translated
)
212 return wxT("Videos");
224 return _("Archives");
226 return wxT("Archives");
231 return _("CD-Images");
233 return wxT("CD-Images");
238 return _("Pictures");
240 return wxT("Pictures");
252 return _("Programs");
254 return wxT("Programs");
267 // Returns the Typename, examining the extention of the given filename
269 wxString
GetFiletypeByName(const CPath
& filename
, bool translated
)
271 return GetFiletypeDesc(GetFiletype(filename
), translated
);
275 // Return the text associated with a rating of a file
276 wxString
GetRateString(uint16 rate
)
279 case 0: return _("Not rated");
280 case 1: return _("Invalid / Corrupt / Fake");
281 case 2: return _("Poor");
282 case 3: return _("Fair");
283 case 4: return _("Good");
284 case 5: return _("Excellent");
285 default: return _("Not rated");
291 * Return the size in bytes of the given size-type
293 * @param type The type (as an int) where: 0 = Byte, 1 = KB, 2 = MB, 3 = GB
295 * @return The amount of Bytes the provided size-type represents
297 * Values over GB aren't handled since the amount of Bytes 1TB represents
298 * is over the uint32 capacity
300 uint32
GetTypeSize(uint8 type
)
302 enum {Bytes
, KB
, MB
, GB
};
306 case Bytes
: size
= 1; break;
307 case KB
: size
= 1024; break;
308 case MB
: size
= 1048576; break;
309 case GB
: size
= 1073741824; break;
310 default: size
= -1; break;
316 // Base16 chars for encode an decode functions
317 static wxChar base16Chars
[17] = wxT("0123456789ABCDEF");
318 static wxChar base32Chars
[33] = wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");
319 #define BASE16_LOOKUP_MAX 23
320 static wxChar base16Lookup
[BASE16_LOOKUP_MAX
][2] = {
347 // Returns a BASE16 encoded byte array
350 // buffer: Pointer to byte array
351 // bufLen: Lenght of buffer array
354 // wxString object with BASE16 encoded byte array
355 wxString
EncodeBase16(const unsigned char* buffer
, unsigned int bufLen
)
359 for(unsigned int i
= 0; i
< bufLen
; ++i
) {
360 Base16Buff
+= base16Chars
[buffer
[i
] >> 4];
361 Base16Buff
+= base16Chars
[buffer
[i
] & 0xf];
368 // Decodes a BASE16 string into a byte array
371 // base16Buffer: String containing BASE16
372 // base16BufLen: Lenght BASE16 coded string's length
375 // buffer: byte array containing decoded string
376 unsigned int DecodeBase16(const wxString
&base16Buffer
, unsigned int base16BufLen
, byte
*buffer
)
378 if (base16BufLen
& 1) {
381 unsigned int ret
= base16BufLen
>> 1;
382 memset( buffer
, 0, ret
);
383 for(unsigned int i
= 0; i
< base16BufLen
; ++i
) {
384 int lookup
= toupper(base16Buffer
[i
]) - wxT('0');
385 // Check to make sure that the given word falls inside a valid range
386 byte word
= (lookup
< 0 || lookup
>= BASE16_LOOKUP_MAX
) ?
387 0xFF : base16Lookup
[lookup
][1];
388 unsigned idx
= i
>> 1;
389 buffer
[idx
] = (i
& 1) ? // odd or even?
390 (buffer
[idx
] | word
) : (word
<< 4);
397 // Returns a BASE32 encoded byte array
400 // buffer: Pointer to byte array
401 // bufLen: Lenght of buffer array
404 // wxString object with BASE32 encoded byte array
405 wxString
EncodeBase32(const unsigned char* buffer
, unsigned int bufLen
)
408 unsigned int i
, index
;
411 for(i
= 0, index
= 0; i
< bufLen
;) {
412 // Is the current word going to span a byte boundary?
414 word
= (buffer
[i
] & (0xFF >> index
));
415 index
= (index
+ 5) % 8;
417 if (i
< bufLen
- 1) {
418 word
|= buffer
[i
+ 1] >> (8 - index
);
422 word
= (buffer
[i
] >> (8 - (index
+ 5))) & 0x1F;
423 index
= (index
+ 5) % 8;
428 Base32Buff
+= (char) base32Chars
[word
];
435 // Decodes a BASE32 string into a byte array
438 // base32Buffer: String containing BASE32
439 // base32BufLen: Lenght BASE32 coded string's length
442 // buffer: byte array containing decoded string
445 unsigned int DecodeBase32(const wxString
&base32Buffer
, unsigned int base32BufLen
, unsigned char *buffer
)
447 size_t nInputLen
= base32Buffer
.Length();
448 uint32 nDecodeLen
= (nInputLen
* 5) / 8;
449 if ((nInputLen
* 5) % 8 > 0) {
452 if (base32BufLen
== 0) {
455 if (nDecodeLen
> base32BufLen
) {
461 for (size_t i
= 0; i
< nInputLen
; ++i
)
463 if (base32Buffer
[i
] >= wxT('A') && base32Buffer
[i
] <= wxT('Z')) {
464 nBits
|= ( base32Buffer
[i
] - wxT('A') );
466 else if (base32Buffer
[i
] >= wxT('a') && base32Buffer
[i
] <= wxT('z')) {
467 nBits
|= ( base32Buffer
[i
] - wxT('a') );
469 else if (base32Buffer
[i
] >= wxT('2') && base32Buffer
[i
] <= wxT('7')) {
470 nBits
|= ( base32Buffer
[i
] - wxT('2') + 26 );
477 *buffer
++ = (byte
)( nBits
>> (nCount
- 8) );
490 * Base64 encoding/decoding command line filter
492 * Copyright (c) 2002-2008 Matthias Gaertner
493 * Adapted to use wxWidgets by
494 * Copyright (c) 2005-2008 Marcelo Roberto Jimenez ( phoenix@amule.org )
497 static const wxString
to_b64(
498 /* 0000000000111111111122222222223333333333444444444455555555556666 */
499 /* 0123456789012345678901234567890123456789012345678901234567890123 */
500 wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"));
503 /* Option variables */
504 static bool g_fUseCRLF
= false;
505 static unsigned int g_nCharsPerLine
= 72;
506 static wxString strHeaderLine
;
509 wxString
EncodeBase64(const char *pbBufferIn
, unsigned int bufLen
)
511 wxString pbBufferOut
;
514 if( !strHeaderLine
.IsEmpty() ) {
515 strHeader
= wxT("-----BEGIN ") + strHeaderLine
+ wxT("-----");
517 strHeader
+= wxT("\r");
519 strHeader
+= wxT("\n");
522 unsigned long nDiv
= ((unsigned long)bufLen
) / 3;
523 unsigned long nRem
= ((unsigned long)bufLen
) % 3;
524 unsigned int NewLineSize
= g_fUseCRLF
? 2 : 1;
526 // Allocate enough space in the output buffer to speed up things
528 strHeader
.Len() * 2 + // header/footer
529 (bufLen
* 4) / 3 + 1 + // Number of codes
530 nDiv
* NewLineSize
+ // Number of new lines
531 (nRem
? 1 : 0) * NewLineSize
); // Last line
532 pbBufferOut
= strHeader
;
534 unsigned long nChars
= 0;
535 const unsigned char *pIn
= (unsigned char*)pbBufferIn
;
537 pbBufferOut
+= to_b64
[ (pIn
[0] >> 2) & 0x3f];
538 pbBufferOut
+= to_b64
[((pIn
[0] << 4) & 0x30) | ((pIn
[1] >> 4) & 0xf)];
539 pbBufferOut
+= to_b64
[((pIn
[1] << 2) & 0x3c) | ((pIn
[2] >> 6) & 0x3)];
540 pbBufferOut
+= to_b64
[ pIn
[2] & 0x3f];
544 if( nChars
>= g_nCharsPerLine
&& g_nCharsPerLine
!= 0 ) {
547 pbBufferOut
+= wxT("\r");
549 pbBufferOut
+= wxT("\n");
554 pbBufferOut
+= to_b64
[ (pIn
[0] >> 2) & 0x3f];
555 pbBufferOut
+= to_b64
[((pIn
[0] << 4) & 0x30) | ((pIn
[1] >> 4) & 0xf)];
556 pbBufferOut
+= to_b64
[ (pIn
[1] << 2) & 0x3c];
557 pbBufferOut
+= wxT("=");
559 if( nChars
>= g_nCharsPerLine
&& g_nCharsPerLine
!= 0 ) {
562 pbBufferOut
+= wxT("\r");
564 pbBufferOut
+= wxT("\n");
568 pbBufferOut
+= to_b64
[ (pIn
[0] >> 2) & 0x3f];
569 pbBufferOut
+= to_b64
[ (pIn
[0] << 4) & 0x30];
570 pbBufferOut
+= wxT("=");
571 pbBufferOut
+= wxT("=");
573 if( nChars
>= g_nCharsPerLine
&& g_nCharsPerLine
!= 0 ) {
576 pbBufferOut
+= wxT("\r");
578 pbBufferOut
+= wxT("\n");
586 pbBufferOut
+= wxT("\r");
588 pbBufferOut
+= wxT("\n");
592 if( !strHeaderLine
.IsEmpty() ) {
593 pbBufferOut
= wxT("-----END ") + strHeaderLine
+ wxT("-----");
595 pbBufferOut
+= wxT("\r");
597 pbBufferOut
+= wxT("\n");
604 unsigned int DecodeBase64(const wxString
&base64Buffer
, unsigned int base64BufLen
, unsigned char *buffer
)
606 int z
= 0; // 0 Normal, 1 skip MIME separator (---) to end of line
607 unsigned int nData
= 0;
610 if (base64BufLen
== 0) {
615 for(unsigned int j
= 0; j
< base64BufLen
; ++j
) {
616 wxChar c
= base64Buffer
[j
];
617 wxChar bits
= wxT('z');
623 else if(c
>= wxT('A') && c
<= wxT('Z')) {
626 else if(c
>= wxT('a') && c
<= wxT('z')) {
627 bits
= c
- wxT('a') + (wxChar
)26;
629 else if(c
>= wxT('0') && c
<= wxT('9')) {
630 bits
= c
- wxT('0') + (wxChar
)52;
632 else if(c
== wxT('+')) {
635 else if(c
== wxT('/')) {
638 else if(c
== wxT('-')) {
641 else if(c
== wxT('=')) {
647 // Skips anything that was not recognized
648 // as a base64 valid char ('y' or 'z')
649 if (bits
< (wxChar
)64) {
652 buffer
[i
+0] = (bits
<< 2) & 0xfc;
655 buffer
[i
+0] |= (bits
>> 4) & 0x03;
656 buffer
[i
+1] = (bits
<< 4) & 0xf0;
659 buffer
[i
+1] |= (bits
>> 2) & 0x0f;
660 buffer
[i
+2] = (bits
<< 6) & 0xc0;
663 buffer
[i
+2] |= bits
& 0x3f;
673 // Syntax error or buffer was empty
685 // Returns the text assosiated with a category type
686 wxString
GetCatTitle(int catid
)
689 case 0: return _("all");
690 case 1: return _("all others");
691 case 2: return _("Incomplete");
692 case 3: return _("Completed");
693 case 4: return _("Waiting");
694 case 5: return _("Downloading");
695 case 6: return _("Erroneous");
696 case 7: return _("Paused");
697 case 8: return _("Stopped");
698 case 9: return _("Video");
699 case 10: return _("Audio");
700 case 11: return _("Archive");
701 case 12: return _("CD-Images");
702 case 13: return _("Pictures");
703 case 14: return _("Text");
704 case 15: return _("Active");
705 default: return wxT("?");
710 typedef std::map
<wxString
, EED2KFileTypeClass
> SED2KFileTypeMap
;
711 typedef SED2KFileTypeMap::value_type SED2KFileTypeMapElement
;
712 static SED2KFileTypeMap ED2KFileTypesMap
;
715 class CED2KFileTypes
{
719 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".669"), ED2KFT_AUDIO
));
720 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".aac"), ED2KFT_AUDIO
));
721 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".aif"), ED2KFT_AUDIO
));
722 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".aiff"), ED2KFT_AUDIO
));
723 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".amf"), ED2KFT_AUDIO
));
724 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ams"), ED2KFT_AUDIO
));
725 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ape"), ED2KFT_AUDIO
));
726 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".au"), ED2KFT_AUDIO
));
727 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".dbm"), ED2KFT_AUDIO
));
728 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".dmf"), ED2KFT_AUDIO
));
729 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".dsm"), ED2KFT_AUDIO
));
730 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".far"), ED2KFT_AUDIO
));
731 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".flac"), ED2KFT_AUDIO
));
732 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".it"), ED2KFT_AUDIO
));
733 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mdl"), ED2KFT_AUDIO
));
734 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".med"), ED2KFT_AUDIO
));
735 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mid"), ED2KFT_AUDIO
));
736 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".midi"), ED2KFT_AUDIO
));
737 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mod"), ED2KFT_AUDIO
));
738 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mol"), ED2KFT_AUDIO
));
739 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mp1"), ED2KFT_AUDIO
));
740 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mp2"), ED2KFT_AUDIO
));
741 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mp3"), ED2KFT_AUDIO
));
742 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mp4"), ED2KFT_AUDIO
));
743 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mpa"), ED2KFT_AUDIO
));
744 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mpc"), ED2KFT_AUDIO
));
745 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mpp"), ED2KFT_AUDIO
));
746 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mtm"), ED2KFT_AUDIO
));
747 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".nst"), ED2KFT_AUDIO
));
748 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ogg"), ED2KFT_AUDIO
));
749 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".okt"), ED2KFT_AUDIO
));
750 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".psm"), ED2KFT_AUDIO
));
751 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ptm"), ED2KFT_AUDIO
));
752 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ra"), ED2KFT_AUDIO
));
753 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".rmi"), ED2KFT_AUDIO
));
754 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".s3m"), ED2KFT_AUDIO
));
755 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".stm"), ED2KFT_AUDIO
));
756 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ult"), ED2KFT_AUDIO
));
757 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".umx"), ED2KFT_AUDIO
));
758 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".wav"), ED2KFT_AUDIO
));
759 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".wma"), ED2KFT_AUDIO
));
760 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".wow"), ED2KFT_AUDIO
));
761 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".xm"), ED2KFT_AUDIO
));
763 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".asf"), ED2KFT_VIDEO
));
764 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".avi"), ED2KFT_VIDEO
));
765 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".divx"), ED2KFT_VIDEO
));
766 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".m1v"), ED2KFT_VIDEO
));
767 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".m2v"), ED2KFT_VIDEO
));
768 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mkv"), ED2KFT_VIDEO
));
769 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mov"), ED2KFT_VIDEO
));
770 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mp1v"), ED2KFT_VIDEO
));
771 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mp2v"), ED2KFT_VIDEO
));
772 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mpe"), ED2KFT_VIDEO
));
773 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mpeg"), ED2KFT_VIDEO
));
774 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mpg"), ED2KFT_VIDEO
));
775 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mps"), ED2KFT_VIDEO
));
776 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mpv"), ED2KFT_VIDEO
));
777 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mpv1"), ED2KFT_VIDEO
));
778 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mpv2"), ED2KFT_VIDEO
));
779 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ogm"), ED2KFT_VIDEO
));
780 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".qt"), ED2KFT_VIDEO
));
781 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ram"), ED2KFT_VIDEO
));
782 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".rm"), ED2KFT_VIDEO
));
783 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".rv"), ED2KFT_VIDEO
));
784 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".rv9"), ED2KFT_VIDEO
));
785 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ts"), ED2KFT_VIDEO
));
786 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".vivo"), ED2KFT_VIDEO
));
787 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".vob"), ED2KFT_VIDEO
));
788 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".wmv"), ED2KFT_VIDEO
));
789 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".xvid"), ED2KFT_VIDEO
));
790 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".flv"), ED2KFT_VIDEO
));
792 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".bmp"), ED2KFT_IMAGE
));
793 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".dcx"), ED2KFT_IMAGE
));
794 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".emf"), ED2KFT_IMAGE
));
795 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".gif"), ED2KFT_IMAGE
));
796 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ico"), ED2KFT_IMAGE
));
797 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".jpeg"), ED2KFT_IMAGE
));
798 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".jpg"), ED2KFT_IMAGE
));
799 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".pct"), ED2KFT_IMAGE
));
800 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".pcx"), ED2KFT_IMAGE
));
801 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".pic"), ED2KFT_IMAGE
));
802 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".pict"), ED2KFT_IMAGE
));
803 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".png"), ED2KFT_IMAGE
));
804 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".psd"), ED2KFT_IMAGE
));
805 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".psp"), ED2KFT_IMAGE
));
806 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".tga"), ED2KFT_IMAGE
));
807 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".tif"), ED2KFT_IMAGE
));
808 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".tiff"), ED2KFT_IMAGE
));
809 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".wmf"), ED2KFT_IMAGE
));
810 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".xif"), ED2KFT_IMAGE
));
812 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".7z"), ED2KFT_ARCHIVE
));
813 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ace"), ED2KFT_ARCHIVE
));
814 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".arj"), ED2KFT_ARCHIVE
));
815 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".bz2"), ED2KFT_ARCHIVE
));
816 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".cab"), ED2KFT_ARCHIVE
));
817 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".gz"), ED2KFT_ARCHIVE
));
818 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".hqx"), ED2KFT_ARCHIVE
));
819 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".lha"), ED2KFT_ARCHIVE
));
820 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".msi"), ED2KFT_ARCHIVE
));
821 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".rar"), ED2KFT_ARCHIVE
));
822 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".sea"), ED2KFT_ARCHIVE
));
823 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".sit"), ED2KFT_ARCHIVE
));
824 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".tar"), ED2KFT_ARCHIVE
));
825 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".tgz"), ED2KFT_ARCHIVE
));
826 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".uc2"), ED2KFT_ARCHIVE
));
827 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".zip"), ED2KFT_ARCHIVE
));
829 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".bat"), ED2KFT_PROGRAM
));
830 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".cmd"), ED2KFT_PROGRAM
));
831 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".com"), ED2KFT_PROGRAM
));
832 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".exe"), ED2KFT_PROGRAM
));
834 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".bin"), ED2KFT_CDIMAGE
));
835 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".bwa"), ED2KFT_CDIMAGE
));
836 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".bwi"), ED2KFT_CDIMAGE
));
837 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".bws"), ED2KFT_CDIMAGE
));
838 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".bwt"), ED2KFT_CDIMAGE
));
839 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ccd"), ED2KFT_CDIMAGE
));
840 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".cue"), ED2KFT_CDIMAGE
));
841 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".dmg"), ED2KFT_CDIMAGE
));
842 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".dmz"), ED2KFT_CDIMAGE
));
843 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".img"), ED2KFT_CDIMAGE
));
844 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".iso"), ED2KFT_CDIMAGE
));
845 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mdf"), ED2KFT_CDIMAGE
));
846 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".mds"), ED2KFT_CDIMAGE
));
847 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".nrg"), ED2KFT_CDIMAGE
));
848 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".sub"), ED2KFT_CDIMAGE
));
849 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".toast"), ED2KFT_CDIMAGE
));
851 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".chm"), ED2KFT_DOCUMENT
));
852 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".css"), ED2KFT_DOCUMENT
));
853 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".diz"), ED2KFT_DOCUMENT
));
854 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".doc"), ED2KFT_DOCUMENT
));
855 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".dot"), ED2KFT_DOCUMENT
));
856 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".hlp"), ED2KFT_DOCUMENT
));
857 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".htm"), ED2KFT_DOCUMENT
));
858 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".html"), ED2KFT_DOCUMENT
));
859 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".nfo"), ED2KFT_DOCUMENT
));
860 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".pdf"), ED2KFT_DOCUMENT
));
861 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".pps"), ED2KFT_DOCUMENT
));
862 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ppt"), ED2KFT_DOCUMENT
));
863 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".ps"), ED2KFT_DOCUMENT
));
864 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".rtf"), ED2KFT_DOCUMENT
));
865 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".wri"), ED2KFT_DOCUMENT
));
866 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".txt"), ED2KFT_DOCUMENT
));
867 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".xls"), ED2KFT_DOCUMENT
));
868 ED2KFileTypesMap
.insert(SED2KFileTypeMapElement(wxT(".xlt"), ED2KFT_DOCUMENT
));
873 // get the list initialized *before* any code is accessing it
874 CED2KFileTypes theED2KFileTypes
;
876 EED2KFileType
GetED2KFileTypeID(const CPath
& fileName
)
878 const wxString ext
= fileName
.GetExt().Lower();
883 SED2KFileTypeMap::iterator it
= ED2KFileTypesMap
.find(wxT(".") + ext
);
884 if (it
!= ED2KFileTypesMap
.end()) {
885 return it
->second
.GetType();
892 // Retuns the ed2k file type term which is to be used in server searches
893 wxString
GetED2KFileTypeSearchTerm(EED2KFileType iFileID
)
895 if (iFileID
== ED2KFT_AUDIO
) return ED2KFTSTR_AUDIO
;
896 if (iFileID
== ED2KFT_VIDEO
) return ED2KFTSTR_VIDEO
;
897 if (iFileID
== ED2KFT_IMAGE
) return ED2KFTSTR_IMAGE
;
898 if (iFileID
== ED2KFT_DOCUMENT
) return ED2KFTSTR_DOCUMENT
;
899 if (iFileID
== ED2KFT_PROGRAM
) return ED2KFTSTR_PROGRAM
;
900 // NOTE: Archives and CD-Images are published with file type "Pro"
901 if (iFileID
== ED2KFT_ARCHIVE
) return ED2KFTSTR_PROGRAM
;
902 if (iFileID
== ED2KFT_CDIMAGE
) return ED2KFTSTR_PROGRAM
;
904 return wxEmptyString
;
908 // Returns a file type which is used eMule internally only, examining the extention of the given filename
909 wxString
GetFileTypeByName(const CPath
& fileName
)
911 EED2KFileType iFileType
= GetED2KFileTypeID(fileName
);
913 case ED2KFT_AUDIO
: return ED2KFTSTR_AUDIO
;
914 case ED2KFT_VIDEO
: return ED2KFTSTR_VIDEO
;
915 case ED2KFT_IMAGE
: return ED2KFTSTR_IMAGE
;
916 case ED2KFT_DOCUMENT
: return ED2KFTSTR_DOCUMENT
;
917 case ED2KFT_PROGRAM
: return ED2KFTSTR_PROGRAM
;
918 case ED2KFT_ARCHIVE
: return ED2KFTSTR_ARCHIVE
;
919 case ED2KFT_CDIMAGE
: return ED2KFTSTR_CDIMAGE
;
920 default: return wxEmptyString
;
925 // Retuns the ed2k file type integer ID which is to be used for publishing+searching
926 EED2KFileType
GetED2KFileTypeSearchID(EED2KFileType iFileID
)
929 case ED2KFT_AUDIO
: return ED2KFT_AUDIO
;
930 case ED2KFT_VIDEO
: return ED2KFT_VIDEO
;
931 case ED2KFT_IMAGE
: return ED2KFT_IMAGE
;
932 case ED2KFT_DOCUMENT
: return ED2KFT_DOCUMENT
;
933 case ED2KFT_PROGRAM
: return ED2KFT_PROGRAM
;
934 // NOTE: Archives and CD-Images are published+searched with file type "Pro"
935 // NOTE: If this gets changed, the function 'GetED2KFileTypeSearchTerm' also needs to get updated!
936 case ED2KFT_ARCHIVE
: return ED2KFT_PROGRAM
;
937 case ED2KFT_CDIMAGE
: return ED2KFT_PROGRAM
;
938 default: return ED2KFT_ANY
;
944 * Dumps a buffer to a wxString
946 wxString
DumpMemToStr(const void *buff
, int n
, const wxString
& msg
, bool ok
)
948 const unsigned char *p
= (const unsigned char *)buff
;
949 int lines
= (n
+ 15)/ 16;
952 // Allocate aproximetly what is needed
953 result
.Alloc( ( lines
+ 1 ) * 80 );
954 if ( !msg
.IsEmpty() ) {
955 result
+= msg
+ wxT(" - ok=") + ( ok
? wxT("true, ") : wxT("false, ") );
958 result
+= wxString::Format( wxT("%d bytes\n"), n
);
959 for ( int i
= 0; i
< lines
; ++i
) {
961 result
+= wxString::Format( wxT("%08x "), i
* 16 );
963 // Show two columns of hex-values
964 for ( int j
= 0; j
< 2; ++j
) {
965 for ( int k
= 0; k
< 8; ++k
) {
966 int pos
= 16 * i
+ 8 * j
+ k
;
969 result
+= wxString::Format( wxT("%02x "), p
[pos
] );
977 // Show a column of ascii-values
978 for ( int k
= 0; k
< 16; ++k
) {
979 int pos
= 16 * i
+ k
;
982 if ( isspace( p
[pos
] ) ) {
984 } else if ( !isgraph( p
[pos
] ) ) {
987 result
+= (wxChar
)p
[pos
];
993 result
+= wxT("|\n");
1002 * Dumps a buffer to stdout
1004 void DumpMem(const void *buff
, int n
, const wxString
& msg
, bool ok
)
1006 printf("%s\n", (const char*)unicode2char(DumpMemToStr( buff
, n
, msg
, ok
)) );
1011 // Dump mem in dword format
1012 void DumpMem_DW(const uint32
*ptr
, int count
)
1014 for(int i
= 0; i
< count
; i
++) {
1015 printf("%08x ", ptr
[i
]);
1016 if ( (i
% 4) == 3) printf("\n");
1022 wxString
GetConfigDir()
1025 static wxString configPath
;
1027 if (configPath
.IsEmpty()) {
1029 // "Portable aMule" - Use aMule from an external USB drive
1030 // Check for ./config/amule.conf and use this configuration if found
1031 const wxString configDir
= JoinPaths(wxFileName::GetCwd(), wxT("config"));
1032 const wxString configFile
= JoinPaths(configDir
, wxT("amule.conf"));
1034 if (CPath::DirExists(configDir
) && CPath::FileExists(configFile
)) {
1035 AddLogLineM(true, CFormat(wxT("Using configDir: %s")) % configDir
);
1037 configPath
= configDir
;
1039 configPath
= wxStandardPaths::Get().GetUserDataDir();
1042 configPath
= wxStandardPaths::Get().GetUserDataDir();
1045 configPath
+= wxFileName::GetPathSeparator();
1052 /*************************** Locale specific stuff ***************************/
1055 # define SETWINLANG(LANG, SUBLANG)
1057 # define SETWINLANG(LANG, SUBLANG) \
1058 info.WinLang = LANG; \
1059 info.WinSublang = SUBLANG;
1062 #define CUSTOMLANGUAGE(wxid, iso, winlang, winsublang, dir, desc) \
1063 info.Language = wxid; \
1064 info.CanonicalName = wxT(iso); \
1065 info.LayoutDirection = dir; \
1066 info.Description = wxT(desc); \
1067 SETWINLANG(winlang, winsublang) \
1068 wxLocale::AddLanguage(info);
1070 void InitCustomLanguages()
1072 wxLanguageInfo info
;
1074 #if !wxCHECK_VERSION(2, 9, 0)
1075 CUSTOMLANGUAGE(wxLANGUAGE_ASTURIAN
, "ast", 0, 0, wxLayout_LeftToRight
, "Asturian");
1080 void InitLocale(wxLocale
& locale
, int language
)
1082 locale
.Init(language
, wxLOCALE_LOAD_DEFAULT
);
1084 #if defined(__WXMAC__) || defined(__WXMSW__)
1085 locale
.AddCatalogLookupPathPrefix(JoinPaths(wxStandardPaths::Get().GetDataDir(), wxT("locale")));
1087 locale
.AddCatalog(wxT(PACKAGE
));
1091 int StrLang2wx(const wxString
& language
)
1093 // get rid of possible encoding and modifier
1094 wxString
lang(language
.BeforeFirst('.').BeforeFirst('@'));
1096 if (!lang
.IsEmpty()) {
1097 const wxLanguageInfo
*lng
= wxLocale::FindLanguageInfo(lang
);
1099 return lng
->Language
;
1101 return wxLANGUAGE_DEFAULT
;
1104 return wxLANGUAGE_DEFAULT
;
1109 wxString
wxLang2Str(const int lang
)
1111 if (lang
!= wxLANGUAGE_DEFAULT
) {
1112 const wxLanguageInfo
*lng
= wxLocale::GetLanguageInfo(lang
);
1114 return lng
->CanonicalName
;
1116 return wxEmptyString
;
1119 return wxEmptyString
;
1123 /*****************************************************************************/
1125 wxString
GetPassword() {
1126 wxString pass_plain
;
1129 pass_plain
= char2unicode(getpass("Enter password for mule connection: "));
1131 //#warning This way, pass enter is not hidden on windows. Bad thing.
1134 printf("Enter password for mule connection: \n");
1136 fgets(temp_str
, 512, stdin
);
1137 temp_str
[strlen(temp_str
)-1] = '\0';
1138 pass_plain
= char2unicode(temp_str
);
1140 wxCHECK2(password
.Decode(MD5Sum(pass_plain
).GetHash()), /* Do nothing. */ );
1141 // MD5 hash for an empty string, according to rfc1321.
1142 if (password
.Encode() == wxT("D41D8CD98F00B204E9800998ECF8427E")) {
1143 printf("No empty password allowed.\n");
1144 return GetPassword();
1148 return password
.Encode();
1151 // File_checked_for_headers