Upstream tarball 9440
[amule.git] / src / OtherFunctions.cpp
blobfc712abf90dadb2a3c08ffd2ac328636895ac874
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(uint64 count, uint16 msecs)
154 if (count < 60) {
155 if (!msecs) {
156 return wxString::Format(
157 wxT("%02") wxLongLongFmtSpec wxT("u "),
158 count) + _("secs");
159 } else {
160 return wxString::Format(
161 wxT("%.3f"),
162 (count + ((float)msecs/1000))) + _("secs");
164 } else if (count < 3600) {
165 return wxString::Format(
166 wxT("%")
167 wxLongLongFmtSpec wxT("u:%02")
168 wxLongLongFmtSpec wxT("u "),
169 count/60,
170 (count % 60)) + _("mins");
171 } else if (count < 86400) {
172 return wxString::Format(
173 wxT("%")
174 wxLongLongFmtSpec wxT("u:%02")
175 wxLongLongFmtSpec wxT("u "),
176 count/3600,
177 (count % 3600)/60) + _("hours");
178 } else {
179 return wxString::Format(
180 wxT("%")
181 wxLongLongFmtSpec wxT("u %s %02")
182 wxLongLongFmtSpec wxT("u:%02")
183 wxLongLongFmtSpec wxT("u "),
184 count/86400,
185 _("Days"),
186 (count % 86400)/3600,
187 (count % 3600)/60) + _("hours");
192 // Examines a filename and determines the filetype
193 FileType GetFiletype(const CPath& filename)
195 // FIXME: WTF do we have two such functions in the first place?
196 switch (GetED2KFileTypeID(filename)) {
197 case ED2KFT_AUDIO: return ftAudio;
198 case ED2KFT_VIDEO: return ftVideo;
199 case ED2KFT_IMAGE: return ftPicture;
200 case ED2KFT_PROGRAM: return ftProgram;
201 case ED2KFT_DOCUMENT: return ftText;
202 case ED2KFT_ARCHIVE: return ftArchive;
203 case ED2KFT_CDIMAGE: return ftCDImage;
204 default: return ftAny;
209 // Returns the (translated) description assosiated with a FileType
210 wxString GetFiletypeDesc(FileType type, bool translated)
212 switch ( type ) {
213 case ftVideo:
214 if (translated) {
215 return _("Videos");
216 } else {
217 return wxT("Videos");
219 break;
220 case ftAudio:
221 if (translated) {
222 return _("Audio");
223 } else {
224 return wxT("Audio");
226 break;
227 case ftArchive:
228 if (translated) {
229 return _("Archives");
230 } else {
231 return wxT("Archives");
233 break;
234 case ftCDImage:
235 if (translated) {
236 return _("CD-Images");
237 } else {
238 return wxT("CD-Images");
240 break;
241 case ftPicture:
242 if (translated) {
243 return _("Pictures");
244 } else {
245 return wxT("Pictures");
247 break;
248 case ftText:
249 if (translated) {
250 return _("Texts");
251 } else {
252 return wxT("Texts");
254 break;
255 case ftProgram:
256 if (translated) {
257 return _("Programs");
258 } else {
259 return wxT("Programs");
261 break;
262 default:
263 if (translated) {
264 return _("Any");
265 } else {
266 return wxT("Any");
268 break;
272 // Returns the Typename, examining the extention of the given filename
274 wxString GetFiletypeByName(const CPath& filename, bool translated)
276 return GetFiletypeDesc(GetFiletype(filename), translated);
280 // Return the text associated with a rating of a file
281 wxString GetRateString(uint16 rate)
283 switch ( rate ) {
284 case 0: return _("Not rated");
285 case 1: return _("Invalid / Corrupt / Fake");
286 case 2: return _("Poor");
287 case 3: return _("Fair");
288 case 4: return _("Good");
289 case 5: return _("Excellent");
290 default: return _("Not rated");
296 * Return the size in bytes of the given size-type
298 * @param type The type (as an int) where: 0 = Byte, 1 = KB, 2 = MB, 3 = GB
300 * @return The amount of Bytes the provided size-type represents
302 * Values over GB aren't handled since the amount of Bytes 1TB represents
303 * is over the uint32 capacity
305 uint32 GetTypeSize(uint8 type)
307 enum {Bytes, KB, MB, GB};
308 int size;
310 switch(type) {
311 case Bytes: size = 1; break;
312 case KB: size = 1024; break;
313 case MB: size = 1048576; break;
314 case GB: size = 1073741824; break;
315 default: size = -1; break;
317 return size;
321 // Base16 chars for encode an decode functions
322 static wxChar base16Chars[17] = wxT("0123456789ABCDEF");
323 static wxChar base32Chars[33] = wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");
324 #define BASE16_LOOKUP_MAX 23
325 static wxChar base16Lookup[BASE16_LOOKUP_MAX][2] = {
326 { wxT('0'), 0x0 },
327 { wxT('1'), 0x1 },
328 { wxT('2'), 0x2 },
329 { wxT('3'), 0x3 },
330 { wxT('4'), 0x4 },
331 { wxT('5'), 0x5 },
332 { wxT('6'), 0x6 },
333 { wxT('7'), 0x7 },
334 { wxT('8'), 0x8 },
335 { wxT('9'), 0x9 },
336 { wxT(':'), 0x9 },
337 { wxT(';'), 0x9 },
338 { wxT('<'), 0x9 },
339 { wxT('='), 0x9 },
340 { wxT('>'), 0x9 },
341 { wxT('?'), 0x9 },
342 { wxT('@'), 0x9 },
343 { wxT('A'), 0xA },
344 { wxT('B'), 0xB },
345 { wxT('C'), 0xC },
346 { wxT('D'), 0xD },
347 { wxT('E'), 0xE },
348 { wxT('F'), 0xF }
352 // Returns a BASE16 encoded byte array
354 // [In]
355 // buffer: Pointer to byte array
356 // bufLen: Lenght of buffer array
358 // [Return]
359 // wxString object with BASE16 encoded byte array
360 wxString EncodeBase16(const unsigned char* buffer, unsigned int bufLen)
362 wxString Base16Buff;
364 for(unsigned int i = 0; i < bufLen; ++i) {
365 Base16Buff += base16Chars[buffer[i] >> 4];
366 Base16Buff += base16Chars[buffer[i] & 0xf];
369 return Base16Buff;
373 // Decodes a BASE16 string into a byte array
375 // [In]
376 // base16Buffer: String containing BASE16
377 // base16BufLen: Lenght BASE16 coded string's length
379 // [Out]
380 // buffer: byte array containing decoded string
381 unsigned int DecodeBase16(const wxString &base16Buffer, unsigned int base16BufLen, byte *buffer)
383 if (base16BufLen & 1) {
384 return 0;
386 unsigned int ret = base16BufLen >> 1;
387 memset( buffer, 0, ret);
388 for(unsigned int i = 0; i < base16BufLen; ++i) {
389 int lookup = toupper(base16Buffer[i]) - wxT('0');
390 // Check to make sure that the given word falls inside a valid range
391 byte word = (lookup < 0 || lookup >= BASE16_LOOKUP_MAX) ?
392 0xFF : base16Lookup[lookup][1];
393 unsigned idx = i >> 1;
394 buffer[idx] = (i & 1) ? // odd or even?
395 (buffer[idx] | word) : (word << 4);
398 return ret;
402 // Returns a BASE32 encoded byte array
404 // [In]
405 // buffer: Pointer to byte array
406 // bufLen: Lenght of buffer array
408 // [Return]
409 // wxString object with BASE32 encoded byte array
410 wxString EncodeBase32(const unsigned char* buffer, unsigned int bufLen)
412 wxString Base32Buff;
413 unsigned int i, index;
414 unsigned char word;
416 for(i = 0, index = 0; i < bufLen;) {
417 // Is the current word going to span a byte boundary?
418 if (index > 3) {
419 word = (buffer[i] & (0xFF >> index));
420 index = (index + 5) % 8;
421 word <<= index;
422 if (i < bufLen - 1) {
423 word |= buffer[i + 1] >> (8 - index);
425 ++i;
426 } else {
427 word = (buffer[i] >> (8 - (index + 5))) & 0x1F;
428 index = (index + 5) % 8;
429 if (index == 0) {
430 ++i;
433 Base32Buff += (char) base32Chars[word];
436 return Base32Buff;
440 // Decodes a BASE32 string into a byte array
442 // [In]
443 // base32Buffer: String containing BASE32
444 // base32BufLen: Lenght BASE32 coded string's length
446 // [Out]
447 // buffer: byte array containing decoded string
448 // [Return]
449 // nDecodeLen:
450 unsigned int DecodeBase32(const wxString &base32Buffer, unsigned int base32BufLen, unsigned char *buffer)
452 size_t nInputLen = base32Buffer.Length();
453 uint32 nDecodeLen = (nInputLen * 5) / 8;
454 if ((nInputLen * 5) % 8 > 0) {
455 ++nDecodeLen;
457 if (base32BufLen == 0) {
458 return nDecodeLen;
460 if (nDecodeLen > base32BufLen) {
461 return 0;
464 uint32 nBits = 0;
465 int nCount = 0;
466 for (size_t i = 0; i < nInputLen; ++i)
468 if (base32Buffer[i] >= wxT('A') && base32Buffer[i] <= wxT('Z')) {
469 nBits |= ( base32Buffer[i] - wxT('A') );
471 else if (base32Buffer[i] >= wxT('a') && base32Buffer[i] <= wxT('z')) {
472 nBits |= ( base32Buffer[i] - wxT('a') );
474 else if (base32Buffer[i] >= wxT('2') && base32Buffer[i] <= wxT('7')) {
475 nBits |= ( base32Buffer[i] - wxT('2') + 26 );
476 } else {
477 return 0;
479 nCount += 5;
480 if (nCount >= 8)
482 *buffer++ = (byte)( nBits >> (nCount - 8) );
483 nCount -= 8;
485 nBits <<= 5;
488 return nDecodeLen;
493 * base64.c
495 * Base64 encoding/decoding command line filter
497 * Copyright (c) 2002-2008 Matthias Gaertner
498 * Adapted to use wxWidgets by
499 * Copyright (c) 2005-2008 Marcelo Roberto Jimenez ( phoenix@amule.org )
502 static const wxString to_b64(
503 /* 0000000000111111111122222222223333333333444444444455555555556666 */
504 /* 0123456789012345678901234567890123456789012345678901234567890123 */
505 wxT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"));
508 /* Option variables */
509 static bool g_fUseCRLF = false;
510 static unsigned int g_nCharsPerLine = 72;
511 static wxString strHeaderLine;
514 wxString EncodeBase64(const char *pbBufferIn, unsigned int bufLen)
516 wxString pbBufferOut;
517 wxString strHeader;
519 if( !strHeaderLine.IsEmpty() ) {
520 strHeader = wxT("-----BEGIN ") + strHeaderLine + wxT("-----");
521 if( g_fUseCRLF ) {
522 strHeader += wxT("\r");
524 strHeader += wxT("\n");
527 unsigned long nDiv = ((unsigned long)bufLen) / 3;
528 unsigned long nRem = ((unsigned long)bufLen) % 3;
529 unsigned int NewLineSize = g_fUseCRLF ? 2 : 1;
531 // Allocate enough space in the output buffer to speed up things
532 pbBufferOut.Alloc(
533 strHeader.Len() * 2 + // header/footer
534 (bufLen * 4) / 3 + 1 + // Number of codes
535 nDiv * NewLineSize + // Number of new lines
536 (nRem ? 1 : 0) * NewLineSize ); // Last line
537 pbBufferOut = strHeader;
539 unsigned long nChars = 0;
540 const unsigned char *pIn = (unsigned char*)pbBufferIn;
541 while( nDiv > 0 ) {
542 pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
543 pbBufferOut += to_b64[((pIn[0] << 4) & 0x30) | ((pIn[1] >> 4) & 0xf)];
544 pbBufferOut += to_b64[((pIn[1] << 2) & 0x3c) | ((pIn[2] >> 6) & 0x3)];
545 pbBufferOut += to_b64[ pIn[2] & 0x3f];
546 pIn += 3;
547 nDiv--;
548 nChars += 4;
549 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
550 nChars = 0;
551 if( g_fUseCRLF ) {
552 pbBufferOut += wxT("\r");
554 pbBufferOut += wxT("\n");
557 switch( nRem ) {
558 case 2:
559 pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
560 pbBufferOut += to_b64[((pIn[0] << 4) & 0x30) | ((pIn[1] >> 4) & 0xf)];
561 pbBufferOut += to_b64[ (pIn[1] << 2) & 0x3c];
562 pbBufferOut += wxT("=");
563 nChars += 4;
564 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
565 nChars = 0;
566 if( g_fUseCRLF ) {
567 pbBufferOut += wxT("\r");
569 pbBufferOut += wxT("\n");
571 break;
572 case 1:
573 pbBufferOut += to_b64[ (pIn[0] >> 2) & 0x3f];
574 pbBufferOut += to_b64[ (pIn[0] << 4) & 0x30];
575 pbBufferOut += wxT("=");
576 pbBufferOut += wxT("=");
577 nChars += 4;
578 if( nChars >= g_nCharsPerLine && g_nCharsPerLine != 0 ) {
579 nChars = 0;
580 if( g_fUseCRLF ) {
581 pbBufferOut += wxT("\r");
583 pbBufferOut += wxT("\n");
585 break;
588 if( nRem > 0 ) {
589 if( nChars > 0 ) {
590 if( g_fUseCRLF ) {
591 pbBufferOut += wxT("\r");
593 pbBufferOut += wxT("\n");
597 if( !strHeaderLine.IsEmpty() ) {
598 pbBufferOut = wxT("-----END ") + strHeaderLine + wxT("-----");
599 if( g_fUseCRLF ) {
600 pbBufferOut += wxT("\r");
602 pbBufferOut += wxT("\n");
605 return pbBufferOut;
609 unsigned int DecodeBase64(const wxString &base64Buffer, unsigned int base64BufLen, unsigned char *buffer)
611 int z = 0; // 0 Normal, 1 skip MIME separator (---) to end of line
612 unsigned int nData = 0;
613 unsigned int i = 0;
615 if (base64BufLen == 0) {
616 *buffer = 0;
617 nData = 1;
620 for(unsigned int j = 0; j < base64BufLen; ++j) {
621 wxChar c = base64Buffer[j];
622 wxChar bits = wxT('z');
623 if( z > 0 ) {
624 if(c == wxT('\n')) {
625 z = 0;
628 else if(c >= wxT('A') && c <= wxT('Z')) {
629 bits = c - wxT('A');
631 else if(c >= wxT('a') && c <= wxT('z')) {
632 bits = c - wxT('a') + (wxChar)26;
634 else if(c >= wxT('0') && c <= wxT('9')) {
635 bits = c - wxT('0') + (wxChar)52;
637 else if(c == wxT('+')) {
638 bits = (wxChar)62;
640 else if(c == wxT('/')) {
641 bits = (wxChar)63;
643 else if(c == wxT('-')) {
644 z = 1;
646 else if(c == wxT('=')) {
647 break;
648 } else {
649 bits = wxT('y');
652 // Skips anything that was not recognized
653 // as a base64 valid char ('y' or 'z')
654 if (bits < (wxChar)64) {
655 switch (nData++) {
656 case 0:
657 buffer[i+0] = (bits << 2) & 0xfc;
658 break;
659 case 1:
660 buffer[i+0] |= (bits >> 4) & 0x03;
661 buffer[i+1] = (bits << 4) & 0xf0;
662 break;
663 case 2:
664 buffer[i+1] |= (bits >> 2) & 0x0f;
665 buffer[i+2] = (bits << 6) & 0xc0;
666 break;
667 case 3:
668 buffer[i+2] |= bits & 0x3f;
669 break;
671 if (nData == 4) {
672 nData = 0;
673 i += 3;
677 if (nData == 1) {
678 // Syntax error or buffer was empty
679 *buffer = 0;
680 nData = 0;
681 i = 0;
682 } else {
683 buffer[i+nData] = 0;
686 return i + nData;
690 // Returns the text assosiated with a category type
691 wxString GetCatTitle(int catid)
693 switch (catid) {
694 case 0: return _("all");
695 case 1: return _("all others");
696 case 2: return _("Incomplete");
697 case 3: return _("Completed");
698 case 4: return _("Waiting");
699 case 5: return _("Downloading");
700 case 6: return _("Erroneous");
701 case 7: return _("Paused");
702 case 8: return _("Stopped");
703 case 9: return _("Video");
704 case 10: return _("Audio");
705 case 11: return _("Archive");
706 case 12: return _("CD-Images");
707 case 13: return _("Pictures");
708 case 14: return _("Text");
709 case 15: return _("Active");
710 default: return wxT("?");
715 typedef std::map<wxString, EED2KFileTypeClass> SED2KFileTypeMap;
716 typedef SED2KFileTypeMap::value_type SED2KFileTypeMapElement;
717 static SED2KFileTypeMap ED2KFileTypesMap;
720 class CED2KFileTypes{
721 public:
722 CED2KFileTypes()
724 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".669"), ED2KFT_AUDIO));
725 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aac"), ED2KFT_AUDIO));
726 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aif"), ED2KFT_AUDIO));
727 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".aiff"), ED2KFT_AUDIO));
728 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".amf"), ED2KFT_AUDIO));
729 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ams"), ED2KFT_AUDIO));
730 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ape"), ED2KFT_AUDIO));
731 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".au"), ED2KFT_AUDIO));
732 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dbm"), ED2KFT_AUDIO));
733 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmf"), ED2KFT_AUDIO));
734 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dsm"), ED2KFT_AUDIO));
735 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".far"), ED2KFT_AUDIO));
736 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flac"), ED2KFT_AUDIO));
737 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".it"), ED2KFT_AUDIO));
738 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mdl"), ED2KFT_AUDIO));
739 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".med"), ED2KFT_AUDIO));
740 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mid"), ED2KFT_AUDIO));
741 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".midi"), ED2KFT_AUDIO));
742 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mod"), ED2KFT_AUDIO));
743 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mol"), ED2KFT_AUDIO));
744 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp1"), ED2KFT_AUDIO));
745 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp2"), ED2KFT_AUDIO));
746 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp3"), ED2KFT_AUDIO));
747 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp4"), ED2KFT_AUDIO));
748 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpa"), ED2KFT_AUDIO));
749 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpc"), ED2KFT_AUDIO));
750 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpp"), ED2KFT_AUDIO));
751 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mtm"), ED2KFT_AUDIO));
752 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nst"), ED2KFT_AUDIO));
753 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ogg"), ED2KFT_AUDIO));
754 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".okt"), ED2KFT_AUDIO));
755 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psm"), ED2KFT_AUDIO));
756 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ptm"), ED2KFT_AUDIO));
757 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ra"), ED2KFT_AUDIO));
758 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rmi"), ED2KFT_AUDIO));
759 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".s3m"), ED2KFT_AUDIO));
760 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".stm"), ED2KFT_AUDIO));
761 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ult"), ED2KFT_AUDIO));
762 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".umx"), ED2KFT_AUDIO));
763 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wav"), ED2KFT_AUDIO));
764 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wma"), ED2KFT_AUDIO));
765 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wow"), ED2KFT_AUDIO));
766 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xm"), ED2KFT_AUDIO));
768 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".asf"), ED2KFT_VIDEO));
769 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".avi"), ED2KFT_VIDEO));
770 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".divx"), ED2KFT_VIDEO));
771 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m1v"), ED2KFT_VIDEO));
772 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".m2v"), ED2KFT_VIDEO));
773 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mkv"), ED2KFT_VIDEO));
774 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mov"), ED2KFT_VIDEO));
775 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp1v"), ED2KFT_VIDEO));
776 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mp2v"), ED2KFT_VIDEO));
777 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpe"), ED2KFT_VIDEO));
778 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpeg"), ED2KFT_VIDEO));
779 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpg"), ED2KFT_VIDEO));
780 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mps"), ED2KFT_VIDEO));
781 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv"), ED2KFT_VIDEO));
782 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv1"), ED2KFT_VIDEO));
783 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mpv2"), ED2KFT_VIDEO));
784 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ogm"), ED2KFT_VIDEO));
785 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".qt"), ED2KFT_VIDEO));
786 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ram"), ED2KFT_VIDEO));
787 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rm"), ED2KFT_VIDEO));
788 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rv"), ED2KFT_VIDEO));
789 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rv9"), ED2KFT_VIDEO));
790 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ts"), ED2KFT_VIDEO));
791 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vivo"), ED2KFT_VIDEO));
792 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".vob"), ED2KFT_VIDEO));
793 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmv"), ED2KFT_VIDEO));
794 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xvid"), ED2KFT_VIDEO));
795 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".flv"), ED2KFT_VIDEO));
797 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bmp"), ED2KFT_IMAGE));
798 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dcx"), ED2KFT_IMAGE));
799 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".emf"), ED2KFT_IMAGE));
800 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".gif"), ED2KFT_IMAGE));
801 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ico"), ED2KFT_IMAGE));
802 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpeg"), ED2KFT_IMAGE));
803 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".jpg"), ED2KFT_IMAGE));
804 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pct"), ED2KFT_IMAGE));
805 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pcx"), ED2KFT_IMAGE));
806 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pic"), ED2KFT_IMAGE));
807 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pict"), ED2KFT_IMAGE));
808 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".png"), ED2KFT_IMAGE));
809 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psd"), ED2KFT_IMAGE));
810 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".psp"), ED2KFT_IMAGE));
811 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tga"), ED2KFT_IMAGE));
812 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tif"), ED2KFT_IMAGE));
813 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tiff"), ED2KFT_IMAGE));
814 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wmf"), ED2KFT_IMAGE));
815 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xif"), ED2KFT_IMAGE));
817 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".7z"), ED2KFT_ARCHIVE));
818 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ace"), ED2KFT_ARCHIVE));
819 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".arj"), ED2KFT_ARCHIVE));
820 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bz2"), ED2KFT_ARCHIVE));
821 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cab"), ED2KFT_ARCHIVE));
822 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".gz"), ED2KFT_ARCHIVE));
823 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hqx"), ED2KFT_ARCHIVE));
824 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".lha"), ED2KFT_ARCHIVE));
825 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".msi"), ED2KFT_ARCHIVE));
826 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rar"), ED2KFT_ARCHIVE));
827 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sea"), ED2KFT_ARCHIVE));
828 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sit"), ED2KFT_ARCHIVE));
829 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tar"), ED2KFT_ARCHIVE));
830 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".tgz"), ED2KFT_ARCHIVE));
831 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".uc2"), ED2KFT_ARCHIVE));
832 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".zip"), ED2KFT_ARCHIVE));
834 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bat"), ED2KFT_PROGRAM));
835 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cmd"), ED2KFT_PROGRAM));
836 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".com"), ED2KFT_PROGRAM));
837 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".exe"), ED2KFT_PROGRAM));
839 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bin"), ED2KFT_CDIMAGE));
840 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwa"), ED2KFT_CDIMAGE));
841 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwi"), ED2KFT_CDIMAGE));
842 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bws"), ED2KFT_CDIMAGE));
843 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".bwt"), ED2KFT_CDIMAGE));
844 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ccd"), ED2KFT_CDIMAGE));
845 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".cue"), ED2KFT_CDIMAGE));
846 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmg"), ED2KFT_CDIMAGE));
847 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dmz"), ED2KFT_CDIMAGE));
848 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".img"), ED2KFT_CDIMAGE));
849 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".iso"), ED2KFT_CDIMAGE));
850 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mdf"), ED2KFT_CDIMAGE));
851 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".mds"), ED2KFT_CDIMAGE));
852 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nrg"), ED2KFT_CDIMAGE));
853 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".sub"), ED2KFT_CDIMAGE));
854 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".toast"), ED2KFT_CDIMAGE));
856 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".chm"), ED2KFT_DOCUMENT));
857 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".css"), ED2KFT_DOCUMENT));
858 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".diz"), ED2KFT_DOCUMENT));
859 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".doc"), ED2KFT_DOCUMENT));
860 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".dot"), ED2KFT_DOCUMENT));
861 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".hlp"), ED2KFT_DOCUMENT));
862 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".htm"), ED2KFT_DOCUMENT));
863 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".html"), ED2KFT_DOCUMENT));
864 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".nfo"), ED2KFT_DOCUMENT));
865 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pdf"), ED2KFT_DOCUMENT));
866 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".pps"), ED2KFT_DOCUMENT));
867 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ppt"), ED2KFT_DOCUMENT));
868 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".ps"), ED2KFT_DOCUMENT));
869 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".rtf"), ED2KFT_DOCUMENT));
870 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".wri"), ED2KFT_DOCUMENT));
871 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".txt"), ED2KFT_DOCUMENT));
872 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xls"), ED2KFT_DOCUMENT));
873 ED2KFileTypesMap.insert(SED2KFileTypeMapElement(wxT(".xlt"), ED2KFT_DOCUMENT));
878 // get the list initialized *before* any code is accessing it
879 CED2KFileTypes theED2KFileTypes;
881 EED2KFileType GetED2KFileTypeID(const CPath& fileName)
883 const wxString ext = fileName.GetExt().Lower();
884 if (ext.IsEmpty()) {
885 return ED2KFT_ANY;
888 SED2KFileTypeMap::iterator it = ED2KFileTypesMap.find(wxT(".") + ext);
889 if (it != ED2KFileTypesMap.end()) {
890 return it->second.GetType();
891 } else {
892 return ED2KFT_ANY;
897 // Retuns the ed2k file type term which is to be used in server searches
898 wxString GetED2KFileTypeSearchTerm(EED2KFileType iFileID)
900 if (iFileID == ED2KFT_AUDIO) return ED2KFTSTR_AUDIO;
901 if (iFileID == ED2KFT_VIDEO) return ED2KFTSTR_VIDEO;
902 if (iFileID == ED2KFT_IMAGE) return ED2KFTSTR_IMAGE;
903 if (iFileID == ED2KFT_DOCUMENT) return ED2KFTSTR_DOCUMENT;
904 if (iFileID == ED2KFT_PROGRAM) return ED2KFTSTR_PROGRAM;
905 // NOTE: Archives and CD-Images are published with file type "Pro"
906 if (iFileID == ED2KFT_ARCHIVE) return ED2KFTSTR_PROGRAM;
907 if (iFileID == ED2KFT_CDIMAGE) return ED2KFTSTR_PROGRAM;
909 return wxEmptyString;
913 // Returns a file type which is used eMule internally only, examining the extention of the given filename
914 wxString GetFileTypeByName(const CPath& fileName)
916 EED2KFileType iFileType = GetED2KFileTypeID(fileName);
917 switch (iFileType) {
918 case ED2KFT_AUDIO: return ED2KFTSTR_AUDIO;
919 case ED2KFT_VIDEO: return ED2KFTSTR_VIDEO;
920 case ED2KFT_IMAGE: return ED2KFTSTR_IMAGE;
921 case ED2KFT_DOCUMENT: return ED2KFTSTR_DOCUMENT;
922 case ED2KFT_PROGRAM: return ED2KFTSTR_PROGRAM;
923 case ED2KFT_ARCHIVE: return ED2KFTSTR_ARCHIVE;
924 case ED2KFT_CDIMAGE: return ED2KFTSTR_CDIMAGE;
925 default: return wxEmptyString;
930 // Retuns the ed2k file type integer ID which is to be used for publishing+searching
931 EED2KFileType GetED2KFileTypeSearchID(EED2KFileType iFileID)
933 switch (iFileID) {
934 case ED2KFT_AUDIO: return ED2KFT_AUDIO;
935 case ED2KFT_VIDEO: return ED2KFT_VIDEO;
936 case ED2KFT_IMAGE: return ED2KFT_IMAGE;
937 case ED2KFT_DOCUMENT: return ED2KFT_DOCUMENT;
938 case ED2KFT_PROGRAM: return ED2KFT_PROGRAM;
939 // NOTE: Archives and CD-Images are published+searched with file type "Pro"
940 // NOTE: If this gets changed, the function 'GetED2KFileTypeSearchTerm' also needs to get updated!
941 case ED2KFT_ARCHIVE: return ED2KFT_PROGRAM;
942 case ED2KFT_CDIMAGE: return ED2KFT_PROGRAM;
943 default: return ED2KFT_ANY;
949 * Dumps a buffer to a wxString
951 wxString DumpMemToStr(const void *buff, int n, const wxString& msg, bool ok)
953 const unsigned char *p = (const unsigned char *)buff;
954 int lines = (n + 15)/ 16;
956 wxString result;
957 // Allocate aproximetly what is needed
958 result.Alloc( ( lines + 1 ) * 80 );
959 if ( !msg.IsEmpty() ) {
960 result += msg + wxT(" - ok=") + ( ok ? wxT("true, ") : wxT("false, ") );
963 result += wxString::Format( wxT("%d bytes\n"), n );
964 for ( int i = 0; i < lines; ++i) {
965 // Show address
966 result += wxString::Format( wxT("%08x "), i * 16 );
968 // Show two columns of hex-values
969 for ( int j = 0; j < 2; ++j) {
970 for ( int k = 0; k < 8; ++k) {
971 int pos = 16 * i + 8 * j + k;
973 if ( pos < n ) {
974 result += wxString::Format( wxT("%02x "), p[pos] );
975 } else {
976 result += wxT(" ");
979 result += wxT(" ");
981 result += wxT("|");
982 // Show a column of ascii-values
983 for ( int k = 0; k < 16; ++k) {
984 int pos = 16 * i + k;
986 if ( pos < n ) {
987 if ( isspace( p[pos] ) ) {
988 result += wxT(" ");
989 } else if ( !isgraph( p[pos] ) ) {
990 result += wxT(".");
991 } else {
992 result += (wxChar)p[pos];
994 } else {
995 result += wxT(" ");
998 result += wxT("|\n");
1000 result.Shrink();
1002 return result;
1007 * Dumps a buffer to stdout
1009 void DumpMem(const void *buff, int n, const wxString& msg, bool ok)
1011 printf("%s\n", (const char*)unicode2char(DumpMemToStr( buff, n, msg, ok )) );
1016 // Dump mem in dword format
1017 void DumpMem_DW(const uint32 *ptr, int count)
1019 for(int i = 0; i < count; i++) {
1020 printf("%08x ", ptr[i]);
1021 if ( (i % 4) == 3) printf("\n");
1023 printf("\n");
1027 wxString GetConfigDir()
1029 // Cache the path.
1030 static wxString configPath;
1032 if (configPath.IsEmpty()) {
1033 #ifndef EC_REMOTE
1034 // "Portable aMule" - Use aMule from an external USB drive
1035 // Check for ./config/amule.conf and use this configuration if found
1036 const wxString configDir = JoinPaths(wxFileName::GetCwd(), wxT("config"));
1037 const wxString configFile = JoinPaths(configDir, wxT("amule.conf"));
1039 if (CPath::DirExists(configDir) && CPath::FileExists(configFile)) {
1040 AddLogLineM(true, CFormat(wxT("Using configDir: %s")) % configDir);
1042 configPath = configDir;
1043 } else {
1044 configPath = wxStandardPaths::Get().GetUserDataDir();
1046 #else
1047 configPath = wxStandardPaths::Get().GetUserDataDir();
1048 #endif
1050 configPath += wxFileName::GetPathSeparator();
1053 return configPath;
1057 /*************************** Locale specific stuff ***************************/
1059 #ifndef __WXMSW__
1060 # define SETWINLANG(LANG, SUBLANG)
1061 #else
1062 # define SETWINLANG(LANG, SUBLANG) \
1063 info.WinLang = LANG; \
1064 info.WinSublang = SUBLANG;
1065 #endif
1067 #define CUSTOMLANGUAGE(wxid, iso, winlang, winsublang, dir, desc) \
1068 info.Language = wxid; \
1069 info.CanonicalName = wxT(iso); \
1070 info.LayoutDirection = dir; \
1071 info.Description = wxT(desc); \
1072 SETWINLANG(winlang, winsublang) \
1073 wxLocale::AddLanguage(info);
1075 void InitCustomLanguages()
1077 wxLanguageInfo info;
1079 CUSTOMLANGUAGE(wxLANGUAGE_ASTURIAN, "ast", 0, 0, wxLayout_LeftToRight, "Asturian");
1083 void InitLocale(wxLocale& locale, int language)
1085 locale.Init(language, wxLOCALE_LOAD_DEFAULT);
1087 #if defined(__WXMAC__) || defined(__WXMSW__)
1088 locale.AddCatalogLookupPathPrefix(JoinPaths(wxStandardPaths::Get().GetDataDir(), wxT("locale")));
1089 #endif
1090 locale.AddCatalog(wxT(PACKAGE));
1094 int StrLang2wx(const wxString& language)
1096 // get rid of possible encoding and modifier
1097 wxString lang(language.BeforeFirst('.').BeforeFirst('@'));
1099 if (!lang.IsEmpty()) {
1100 const wxLanguageInfo *lng = wxLocale::FindLanguageInfo(lang);
1101 if (lng) {
1102 return lng->Language;
1103 } else {
1104 return wxLANGUAGE_DEFAULT;
1106 } else {
1107 return wxLANGUAGE_DEFAULT;
1112 wxString wxLang2Str(const int lang)
1114 if (lang != wxLANGUAGE_DEFAULT) {
1115 const wxLanguageInfo *lng = wxLocale::GetLanguageInfo(lang);
1116 if (lng) {
1117 return lng->CanonicalName;
1118 } else {
1119 return wxEmptyString;
1121 } else {
1122 return wxEmptyString;
1126 /*****************************************************************************/
1128 wxString GetPassword() {
1129 wxString pass_plain;
1130 CMD4Hash password;
1131 #ifndef __WXMSW__
1132 pass_plain = char2unicode(getpass("Enter password for mule connection: "));
1133 #else
1134 //#warning This way, pass enter is not hidden on windows. Bad thing.
1135 char temp_str[512];
1136 fflush(stdin);
1137 printf("Enter password for mule connection: \n");
1138 fflush(stdout);
1139 fgets(temp_str, 512, stdin);
1140 temp_str[strlen(temp_str)-1] = '\0';
1141 pass_plain = char2unicode(temp_str);
1142 #endif
1143 wxCHECK2(password.Decode(MD5Sum(pass_plain).GetHash()), /* Do nothing. */ );
1144 // MD5 hash for an empty string, according to rfc1321.
1145 if (password.Encode() == wxT("D41D8CD98F00B204E9800998ECF8427E")) {
1146 printf("No empty password allowed.\n");
1147 return GetPassword();
1151 return password.Encode();
1154 // File_checked_for_headers