Upstream tarball 9622
[amule.git] / src / OtherFunctions.cpp
blob56a4c441f0b56590d46019ef649a33340e10889f
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 #ifdef __WXGTK__
66 #ifdef __WXGTK20__
67 ver += wxT("wxGTK2");
68 #else
69 ver += wxT("wxGTK1");
70 #endif
71 #elif defined(__WXMAC__)
72 ver += wxT("wxMac");
73 #elif defined(__WXMSW__)
74 ver += wxT("wxMSW");
75 #elif defined(__WXCOCOA__)
76 ver += wxT("wxCocoa");
77 #endif
79 ver += wxString::Format(wxT(" v%d.%d.%d"), wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER );
81 #if defined(__WXDEBUG__)
82 ver += wxT(" (Debugging)");
83 #endif
85 #ifdef SVNDATE
86 ver += wxString::Format( wxT(" (Snapshot: %s)"), wxT(SVNDATE));
87 #endif
89 return ver;
93 wxString GetFullMuleVersion()
95 #ifdef AMULE_DAEMON
96 wxString app = wxT("aMuled");
97 #elif defined(CLIENT_GUI)
98 wxString app = wxT("Remote aMule-GUI");
99 #else
100 wxString app = wxT("aMule");
101 #endif
103 return app + wxT(" ") + GetMuleVersion();
107 // Formats a filesize in bytes to make it suitable for displaying
108 wxString CastItoXBytes( uint64 count )
111 if (count < 1024)
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") ;
119 else
120 return wxString::Format( wxT("%.3f "), (float)count/1099511627776LL) + _("TB") ;
124 wxString CastItoIShort(uint64 count)
127 if (count < 1000)
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") ;
135 else
136 return wxString::Format(wxT("%.2f"),(float)count/1000000000000LL) + _("T");
140 wxString CastItoSpeed(uint32 bytes)
142 if (bytes < 1024)
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");
146 else
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)
154 if (count < 60) {
155 if (!msecs) {
156 return wxString::Format(
157 wxT("%02u %s"), count, _("secs"));
158 } else {
159 return wxString::Format(
160 wxT("%.3f %s"),
161 (count + ((float)msecs/1000)), _("secs"));
163 } else if (count < 3600) {
164 return wxString::Format(
165 wxT("%u:%02u %s"),
166 count/60,
167 (count % 60),
168 _("mins"));
169 } else if (count < 86400) {
170 return wxString::Format(
171 wxT("%u:%02u %s"),
172 count/3600,
173 (count % 3600)/60,
174 _("hours"));
175 } else {
176 return wxString::Format(
177 wxT("%u %s %02u:%02u %s"),
178 count/86400,
179 _("Days"),
180 (count % 86400)/3600,
181 (count % 3600)/60,
182 _("hours"));
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)
207 switch ( type ) {
208 case ftVideo:
209 if (translated) {
210 return _("Videos");
211 } else {
212 return wxT("Videos");
214 break;
215 case ftAudio:
216 if (translated) {
217 return _("Audio");
218 } else {
219 return wxT("Audio");
221 break;
222 case ftArchive:
223 if (translated) {
224 return _("Archives");
225 } else {
226 return wxT("Archives");
228 break;
229 case ftCDImage:
230 if (translated) {
231 return _("CD-Images");
232 } else {
233 return wxT("CD-Images");
235 break;
236 case ftPicture:
237 if (translated) {
238 return _("Pictures");
239 } else {
240 return wxT("Pictures");
242 break;
243 case ftText:
244 if (translated) {
245 return _("Texts");
246 } else {
247 return wxT("Texts");
249 break;
250 case ftProgram:
251 if (translated) {
252 return _("Programs");
253 } else {
254 return wxT("Programs");
256 break;
257 default:
258 if (translated) {
259 return _("Any");
260 } else {
261 return wxT("Any");
263 break;
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)
278 switch ( 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};
303 int size;
305 switch(type) {
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;
312 return size;
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] = {
321 { wxT('0'), 0x0 },
322 { wxT('1'), 0x1 },
323 { wxT('2'), 0x2 },
324 { wxT('3'), 0x3 },
325 { wxT('4'), 0x4 },
326 { wxT('5'), 0x5 },
327 { wxT('6'), 0x6 },
328 { wxT('7'), 0x7 },
329 { wxT('8'), 0x8 },
330 { wxT('9'), 0x9 },
331 { wxT(':'), 0x9 },
332 { wxT(';'), 0x9 },
333 { wxT('<'), 0x9 },
334 { wxT('='), 0x9 },
335 { wxT('>'), 0x9 },
336 { wxT('?'), 0x9 },
337 { wxT('@'), 0x9 },
338 { wxT('A'), 0xA },
339 { wxT('B'), 0xB },
340 { wxT('C'), 0xC },
341 { wxT('D'), 0xD },
342 { wxT('E'), 0xE },
343 { wxT('F'), 0xF }
347 // Returns a BASE16 encoded byte array
349 // [In]
350 // buffer: Pointer to byte array
351 // bufLen: Lenght of buffer array
353 // [Return]
354 // wxString object with BASE16 encoded byte array
355 wxString EncodeBase16(const unsigned char* buffer, unsigned int bufLen)
357 wxString Base16Buff;
359 for(unsigned int i = 0; i < bufLen; ++i) {
360 Base16Buff += base16Chars[buffer[i] >> 4];
361 Base16Buff += base16Chars[buffer[i] & 0xf];
364 return Base16Buff;
368 // Decodes a BASE16 string into a byte array
370 // [In]
371 // base16Buffer: String containing BASE16
372 // base16BufLen: Lenght BASE16 coded string's length
374 // [Out]
375 // buffer: byte array containing decoded string
376 unsigned int DecodeBase16(const wxString &base16Buffer, unsigned int base16BufLen, byte *buffer)
378 if (base16BufLen & 1) {
379 return 0;
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);
393 return ret;
397 // Returns a BASE32 encoded byte array
399 // [In]
400 // buffer: Pointer to byte array
401 // bufLen: Lenght of buffer array
403 // [Return]
404 // wxString object with BASE32 encoded byte array
405 wxString EncodeBase32(const unsigned char* buffer, unsigned int bufLen)
407 wxString Base32Buff;
408 unsigned int i, index;
409 unsigned char word;
411 for(i = 0, index = 0; i < bufLen;) {
412 // Is the current word going to span a byte boundary?
413 if (index > 3) {
414 word = (buffer[i] & (0xFF >> index));
415 index = (index + 5) % 8;
416 word <<= index;
417 if (i < bufLen - 1) {
418 word |= buffer[i + 1] >> (8 - index);
420 ++i;
421 } else {
422 word = (buffer[i] >> (8 - (index + 5))) & 0x1F;
423 index = (index + 5) % 8;
424 if (index == 0) {
425 ++i;
428 Base32Buff += (char) base32Chars[word];
431 return Base32Buff;
435 // Decodes a BASE32 string into a byte array
437 // [In]
438 // base32Buffer: String containing BASE32
439 // base32BufLen: Lenght BASE32 coded string's length
441 // [Out]
442 // buffer: byte array containing decoded string
443 // [Return]
444 // nDecodeLen:
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) {
450 ++nDecodeLen;
452 if (base32BufLen == 0) {
453 return nDecodeLen;
455 if (nDecodeLen > base32BufLen) {
456 return 0;
459 uint32 nBits = 0;
460 int nCount = 0;
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 );
471 } else {
472 return 0;
474 nCount += 5;
475 if (nCount >= 8)
477 *buffer++ = (byte)( nBits >> (nCount - 8) );
478 nCount -= 8;
480 nBits <<= 5;
483 return nDecodeLen;
488 * base64.c
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;
512 wxString strHeader;
514 if( !strHeaderLine.IsEmpty() ) {
515 strHeader = wxT("-----BEGIN ") + strHeaderLine + wxT("-----");
516 if( g_fUseCRLF ) {
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
527 pbBufferOut.Alloc(
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;
536 while( nDiv > 0 ) {
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];
541 pIn += 3;
542 nDiv--;
543 nChars += 4;
544 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
545 nChars = 0;
546 if( g_fUseCRLF ) {
547 pbBufferOut += wxT("\r");
549 pbBufferOut += wxT("\n");
552 switch( nRem ) {
553 case 2:
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("=");
558 nChars += 4;
559 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
560 nChars = 0;
561 if( g_fUseCRLF ) {
562 pbBufferOut += wxT("\r");
564 pbBufferOut += wxT("\n");
566 break;
567 case 1:
568 pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
569 pbBufferOut += to_b64[ (pIn[0] << 4) & 0x30];
570 pbBufferOut += wxT("=");
571 pbBufferOut += wxT("=");
572 nChars += 4;
573 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
574 nChars = 0;
575 if( g_fUseCRLF ) {
576 pbBufferOut += wxT("\r");
578 pbBufferOut += wxT("\n");
580 break;
583 if( nRem > 0 ) {
584 if( nChars > 0 ) {
585 if( g_fUseCRLF ) {
586 pbBufferOut += wxT("\r");
588 pbBufferOut += wxT("\n");
592 if( !strHeaderLine.IsEmpty() ) {
593 pbBufferOut = wxT("-----END ") + strHeaderLine + wxT("-----");
594 if( g_fUseCRLF ) {
595 pbBufferOut += wxT("\r");
597 pbBufferOut += wxT("\n");
600 return pbBufferOut;
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;
608 unsigned int i = 0;
610 if (base64BufLen == 0) {
611 *buffer = 0;
612 nData = 1;
615 for(unsigned int j = 0; j < base64BufLen; ++j) {
616 wxChar c = base64Buffer[j];
617 wxChar bits = wxT('z');
618 if( z > 0 ) {
619 if(c == wxT('\n')) {
620 z = 0;
623 else if(c >= wxT('A') && c <= wxT('Z')) {
624 bits = c - wxT('A');
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('+')) {
633 bits = (wxChar)62;
635 else if(c == wxT('/')) {
636 bits = (wxChar)63;
638 else if(c == wxT('-')) {
639 z = 1;
641 else if(c == wxT('=')) {
642 break;
643 } else {
644 bits = wxT('y');
647 // Skips anything that was not recognized
648 // as a base64 valid char ('y' or 'z')
649 if (bits < (wxChar)64) {
650 switch (nData++) {
651 case 0:
652 buffer[i+0] = (bits << 2) & 0xfc;
653 break;
654 case 1:
655 buffer[i+0] |= (bits >> 4) & 0x03;
656 buffer[i+1] = (bits << 4) & 0xf0;
657 break;
658 case 2:
659 buffer[i+1] |= (bits >> 2) & 0x0f;
660 buffer[i+2] = (bits << 6) & 0xc0;
661 break;
662 case 3:
663 buffer[i+2] |= bits & 0x3f;
664 break;
666 if (nData == 4) {
667 nData = 0;
668 i += 3;
672 if (nData == 1) {
673 // Syntax error or buffer was empty
674 *buffer = 0;
675 nData = 0;
676 i = 0;
677 } else {
678 buffer[i+nData] = 0;
681 return i + nData;
685 // Returns the text assosiated with a category type
686 wxString GetCatTitle(int catid)
688 switch (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{
716 public:
717 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();
879 if (ext.IsEmpty()) {
880 return ED2KFT_ANY;
883 SED2KFileTypeMap::iterator it = ED2KFileTypesMap.find(wxT(".") + ext);
884 if (it != ED2KFileTypesMap.end()) {
885 return it->second.GetType();
886 } else {
887 return ED2KFT_ANY;
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);
912 switch (iFileType) {
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)
928 switch (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;
951 wxString result;
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) {
960 // Show address
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;
968 if ( pos < n ) {
969 result += wxString::Format( wxT("%02x "), p[pos] );
970 } else {
971 result += wxT(" ");
974 result += wxT(" ");
976 result += wxT("|");
977 // Show a column of ascii-values
978 for ( int k = 0; k < 16; ++k) {
979 int pos = 16 * i + k;
981 if ( pos < n ) {
982 if ( isspace( p[pos] ) ) {
983 result += wxT(" ");
984 } else if ( !isgraph( p[pos] ) ) {
985 result += wxT(".");
986 } else {
987 result += (wxChar)p[pos];
989 } else {
990 result += wxT(" ");
993 result += wxT("|\n");
995 result.Shrink();
997 return result;
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");
1018 printf("\n");
1022 wxString GetConfigDir()
1024 // Cache the path.
1025 static wxString configPath;
1027 if (configPath.IsEmpty()) {
1028 #ifndef EC_REMOTE
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;
1038 } else {
1039 configPath = wxStandardPaths::Get().GetUserDataDir();
1041 #else
1042 configPath = wxStandardPaths::Get().GetUserDataDir();
1043 #endif
1045 configPath += wxFileName::GetPathSeparator();
1048 return configPath;
1052 /*************************** Locale specific stuff ***************************/
1054 #ifndef __WXMSW__
1055 # define SETWINLANG(LANG, SUBLANG)
1056 #else
1057 # define SETWINLANG(LANG, SUBLANG) \
1058 info.WinLang = LANG; \
1059 info.WinSublang = SUBLANG;
1060 #endif
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");
1076 #endif
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")));
1086 #endif
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);
1098 if (lng) {
1099 return lng->Language;
1100 } else {
1101 return wxLANGUAGE_DEFAULT;
1103 } else {
1104 return wxLANGUAGE_DEFAULT;
1109 wxString wxLang2Str(const int lang)
1111 if (lang != wxLANGUAGE_DEFAULT) {
1112 const wxLanguageInfo *lng = wxLocale::GetLanguageInfo(lang);
1113 if (lng) {
1114 return lng->CanonicalName;
1115 } else {
1116 return wxEmptyString;
1118 } else {
1119 return wxEmptyString;
1123 /*****************************************************************************/
1125 wxString GetPassword() {
1126 wxString pass_plain;
1127 CMD4Hash password;
1128 #ifndef __WXMSW__
1129 pass_plain = char2unicode(getpass("Enter password for mule connection: "));
1130 #else
1131 //#warning This way, pass enter is not hidden on windows. Bad thing.
1132 char temp_str[512];
1133 fflush(stdin);
1134 printf("Enter password for mule connection: \n");
1135 fflush(stdout);
1136 fgets(temp_str, 512, stdin);
1137 temp_str[strlen(temp_str)-1] = '\0';
1138 pass_plain = char2unicode(temp_str);
1139 #endif
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