diff -ur xmule/ChangeLog xmule.new/ChangeLog --- xmule/ChangeLog 2004-05-31 16:40:55.000000000 -0700 +++ xmule.new/ChangeLog 2004-06-16 13:18:42.257136000 -0700 @@ -1,5 +1,19 @@ Please read the IMPORTANT NOTE on xMule's versioning system below! For changes to the UNSTABLE branch, see ChangeLog-UNSTABLE. +Version 1.8.2d +-------------- +*New in 1.8.2d + *ADDED: Dynamic Partfiles (named as x.pnew and x.pnew.met instead of x.part and x.part.met) + This type of partfiles needs only as much space on disk as downloaded, not as the filesize tells + Its possible, to use both types with the some xmule at the same time (to finish older downloads) + *ADDED: Renewable Clienthash on startup (to increase security) (to activate look at FlowChart + *ADDED: Configureoption "--enable-cryptopp" to use the original library instead of the far more + compact CryptoXMpp for compatibility reasons (on 64-Bitsystems and other than i386). +*Bugfixes + *FIXED: Corrected version-information for xmule (Thanks to Kry from aMule team to inform us + about that!) for CT_VERSION_MOD on SendHelloTypePacket in BaseClient.cpp. + *FIXED: Clienthash now saved and loaded + Version 1.8.2c -------------- 2004-06-01 diff -ur xmule/INSTALL xmule.new/INSTALL --- xmule/INSTALL 2004-05-26 13:25:19.000000000 -0700 +++ xmule.new/INSTALL 2004-06-16 13:18:42.265135000 -0700 @@ -56,3 +56,193 @@ Otherwise, you will miss some popup-menues inside the FlowChart-Window, which are needed to enable functions like "source-exchange" and "securehash/ident/creditfiles". +=========================================================================================================== +NEW: Overview to install all needed libs from scratch under problematic conditions (suse/mandrake/fc2/etc): +=========================================english=========================================================== +You will need: + +autoconf-2.59 (min. see autoconf --version) +gettext-0.11.5 (min. see gettext --version) +automake-1.7.9 (min. see automake --version) +glib-1.2.10 +gtk-1.2.10 +wxGTK-2.4.2 (no unicode, to configure with --with-gtk +--disable-gtk2) +xMule-1.8.2c + + +To download: + +cd /usr/src +wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.59.tar.gz +wget ftp://ftp.gnu.org/gnu/gettext/gettext-0.11.5.tar.gz +wget ftp://ftp.gnu.org/gnu/automake/automake-1.7.9.tar.gz +wget ftp://ftp.nctu.edu.tw/UNIX/gtk/v1.2/glib-1.2.10.tar.gz +wget ftp://ftp.nctu.edu.tw/UNIX/gtk/v1.2/gtk+-1.2.10.tar.gz +wget +http://heanet.dl.sourceforge.net/sourceforge/wxwindows/wxGTK-2.4.2.tar.gz +wget http://download.gna.org/xmule/xmule-1.8.2c.tar.gz + +To install: + +cd /usr/src +tar zxvf autoconf*.gz +tar zxvf gettext*.gz +tar zxvf automake*.gz +tar zxvf glib*.gz +tar zxvf gtk*.gz +tar zxvf wxGTK*.gz +tar zxvf xmule*.gz + +cd /usr/src/autoconf*9 +./configure +make +make install + +cd /usr/src/gettext*5 +./configure +make +make install + +cd /usr/src/automake*9 +./configure +make +make install + +vi /etc/ld.so.conf +>>>>insert the following lines if not exist: +/usr/local/lib +/usr/local/lib/glib-1.2 +/usr/local/lib/gtk-1.2 + +cd /usr/src/glib*10 +./configure +make +make install +ldconfig + +cd /usr/src/gtk*10 +./configure +make +make install +ldconfig + +cd /usr/src/wxGTK*2 +./configure --with-gtk --disable-gtk2 +make +make install +ldconfig + +cd /usr/src/xmule*2c +./configure --enable-debug +make +cp /usr/src/xmule*2c/src/xmule /usr/bin +chmod 755 /usr/bin/xmule + +For every user-account ($HOME) you wish to use xMule, you +have to do the following: + +mkdir $HOME/.xMule +chmod 777 $HOME/.xMule +cp -R /usr/src/xmule*2c/src/resource $HOME/.xMule +chmod 755 $HOME/.xMule/resource + +That's all! +=========================================================================================================== +NEW: Übersicht um alle benötigten Libraries zu installieren unter erschwerten Bedingungen/ohne Kentnisse: +=========================================deutsch=========================================================== +Benötigt dazu werden nur (alle selbst zu kompilieren, in dieser Reihenfolge - in 30 Minuten erledigt): + +autoconf-2.59 (mindestens, siehe autoconf --version) +gettext-0.11.5 (mindestens, siehe gettext --version) +automake-1.7.9 (mindestens, siehe automake --version) +glib-1.2.10 +gtk-1.2.10 +wxGTK-2.4.2 (kein Unicode, configured mit --with-gtk --disable-gtk2) +xMule-1.8.2c + +Zur Vorbereitung: + +Yast2 starten, Software installieren/deinstallieren, Suche: + +glib -> eventuell installierte Pakete glib-1.2.10 & -devel löschen +gtk -> eventuell installierte Pakete gtk+-1.2.10 & -devel löschen +wxGTK-2.4.1 -> falls installiert, löschen + +Yast2 verlassen. + +Zum Download: + +cd /usr/src +wget +wget +wget +wget +wget +wget +wget + +Zur Installation: + +cd /usr/src +tar zxvf autoconf*.gz +tar zxvf gettext*.gz +tar zxvf automake*.gz +tar zxvf glib*.gz +tar zxvf gtk*.gz +tar zxvf wxGTK*.gz +tar zxvf xmule*.gz + +cd /usr/src/autoconf*9 +./configure +make +make install + +cd /usr/src/gettext*5 +./configure +make +make install + +cd /usr/src/automake*9 +./configure +make +make install + +vi /etc/ld.so.conf +>>>>folgende Zeilen eintragen (falls keine solche vorhanden) +/usr/local/lib +/usr/local/lib/glib-1.2 +/usr/local/lib/gtk-1.2 + +cd /usr/src/glib*10 +./configure +make +make install +ldconfig + +cd /usr/src/gtk*10 +./configure +make +make install +ldconfig + +cd /usr/src/wxGTK*2 +./configure --with-gtk --disable-gtk2 +make +make install +ldconfig + +cd /usr/src/xmule*2c +./configure --enable-debug +make +cp /usr/src/xmule*2c/src/xmule /usr/bin +chmod 755 /usr/bin/xmule + +Für jeden Benutzeraccount ($HOME) notwendig, für den man xMule verwenden möchte: + +mkdir $HOME/.xMule +chmod 777 $HOME/.xMule +cp -R /usr/src/xmule*2c/src/resource $HOME/.xMule +chmod 755 $HOME/.xMule/resource + +Das war alles! diff -ur xmule/TODO xmule.new/TODO --- xmule/TODO 2004-04-05 12:31:50.000000000 -0700 +++ xmule.new/TODO 2004-06-16 13:18:42.272134000 -0700 @@ -1,10 +1,27 @@ -V1.8.0 TODO: +v1.8.x TODO: ------------ -DONE: Fixing Bug that Files <9mb are not downloadable -DONE: Fixing UDP-Port CPU-idle Bug -DONE: Fix the m4 file missing problem -DONE: Make listctrl events work with GTK2 -DONE: Changing Version Number to 1.8.0 -DONE: Only one file seems to download at a time, unless 2 files start downloading within 1 minute of each other. -DONE:Fixing crashes caused by CClientReqSocket::ProcessPacket OP_EMULEINFOANSWER 02,76 and other - +priority,status,info +1,open: new functions to convert partfiles from and to new-format +1,open: serverless-runmode for xmule +2,open: priorities-bugfix & optimization for downloadtable +3,open: xmule-icon-only instead of minimized in toolbar & icon at the same time +3,open: encryption of partfiles and sharedfiles for only being decrypted while xmule is running with the +.......correct privatekey. publickey will be endless (for every byte/character enother encoding-base) +.......so only who knows the privatekey is able to decrypt the encrypted date and this only while xmule +.......is running - so no further filesystem-encryption will be needed after xmule encrypted all files +.......in itself on disk. +.......the encrypted files could be burned to dvd or cd - the length of the files will be the same +.......(encrypted or decrypted) +.......encrypted files on dvd/cdr will be usable/accessible after an additional decryption over xmule to disk +....... +.......the private key will not be stored anywhere +.......the private key will be the key to enter xmule in the future - everyone can define the privatekey for +.......itself on every start. if the privatekey on start is another than on the last start of xmule, +.......all files not encrypted with the actual privatekey will not be accessible/usable +....... +.......the encryption-algorithm will be a completely new one - never used before. so there will be no +.......other program at the moment which will be able to decrypt the files encrypted by xmule other than +.......xmule itself +....... +.......this means: you should never forget your privatekey, otherwise all files encrypted with this key +...................will be lost forever diff -ur xmule/configure xmule.new/configure --- xmule/configure 2004-05-31 16:36:02.000000000 -0700 +++ xmule.new/configure 2004-06-16 13:35:36.028020024 -0700 @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.59 for xMule 1.8.2c. +# Generated by GNU Autoconf 2.59 for xMule 1.8.2d. # # Report bugs to . # @@ -269,8 +269,8 @@ # Identity of this package. PACKAGE_NAME='xMule' PACKAGE_TARNAME='xmule' -PACKAGE_VERSION='1.8.2c' -PACKAGE_STRING='xMule 1.8.2c' +PACKAGE_VERSION='1.8.2d' +PACKAGE_STRING='xMule 1.8.2d' PACKAGE_BUGREPORT='http://xmule.hopto.org/board/' ac_unique_file="src/SharedFileList.h" @@ -788,7 +788,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures xMule 1.8.2c to adapt to many kinds of systems. +\`configure' configures xMule 1.8.2d to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -849,7 +849,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of xMule 1.8.2c:";; + short | recursive ) echo "Configuration of xMule 1.8.2d:";; esac cat <<\_ACEOF @@ -862,6 +862,7 @@ --disable-gtktest Do not try to compile and run a test GTK program --enable-debug Enable additional debugging output --disable-debug-syms Disable debugging information + --enable-cryptopp Enable use of libcryptopp.a instead of CryptoXMpp --enable-optimise Enable code optimising --enable-profile Enable code profiling --disable-gtk Disable pure GTK code in xmule @@ -994,7 +995,7 @@ test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -xMule configure 1.8.2c +xMule configure 1.8.2d generated by GNU Autoconf 2.59 Copyright (C) 2003 Free Software Foundation, Inc. @@ -1008,7 +1009,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by xMule $as_me 1.8.2c, which was +It was created by xMule $as_me 1.8.2d, which was generated by GNU Autoconf 2.59. Invocation command line was $ $0 $@ @@ -1345,8 +1346,11 @@ + ac_config_headers="$ac_config_headers config.h" + ac_config_commands="$ac_config_commands default-1" + # BEGIN COMPAT VARIABLES @@ -1356,11 +1360,11 @@ cat >>confdefs.h <<\_ACEOF -#define VERSION "1.8.2c" +#define VERSION "1.8.2d" _ACEOF PACKAGE="xmule" -VERSION="1.8.2c" +VERSION="1.8.2d" # END COMPAT VARIABLES @@ -3216,7 +3220,7 @@ rm -f messages.po fi - ac_config_commands="$ac_config_commands default-1" + ac_config_commands="$ac_config_commands default-2" # Make sure we can run config.sub. @@ -8535,6 +8539,12 @@ USE_DEBUG_SYMS="yes" fi; +# Check whether --enable-cryptopp or --disable-cryptopp was given. +if test "${enable_cryptopp+set}" = set; then + enableval="$enable_cryptopp" + +fi; + # Check whether --enable-optimise or --disable-optimise was given. if test "${enable_optimise+set}" = set; then enableval="$enable_optimise" @@ -10222,6 +10232,15 @@ esac fi +if test -n "$enable_cryptopp"; then + enable_cryptopp=no + CRDEFS="-D__CRPP__" + LIBCRPP="-lcryptopp" +else + CRDEFS="" +fi + + if test -n "$enable_gtk"; then enable_stripgtk=no GTK_DEFS="-D__NOGTK__" @@ -10248,8 +10267,9 @@ # we have it anyway by now -LIBS="$LIBS $WX_LIBS $ZLIB_LIBS $LIBM" +LIBS="$LIBS $WX_LIBS $ZLIB_LIBS $LIBM $LIBCRPP" +GTK_CFLAGS="$GTK_CFLAGS $CRDEFS" PCHFLAGS="$PCHFLAGS $DEBUG_FLAGS $GTK_CFLAGS -I. $DEFS $WX_CXXFLAGS" @@ -10258,7 +10278,7 @@ XRCFLAGS="-Isrc" CXXFLAGS="$CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS $WX_CXXFLAGS $GTK_CFLAGS $XRCFLAGS $ZLIB_CFLAGSx" -CFLAGS="$GTK_DEFS $CFLAGS $CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS" +CFLAGS="$GTK_DEFS $CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS" LDFLAGS="$EXPORT_DYN_FLAGS $PROFILE_FLAGS $LDFLAGS" ac_config_files="$ac_config_files src/Makefile intl/Makefile po/Makefile.in src/wx/xrc/Makefile Makefile Compilation.flags" @@ -10625,7 +10645,7 @@ } >&5 cat >&5 <<_CSEOF -This file was extended by xMule $as_me 1.8.2c, which was +This file was extended by xMule $as_me 1.8.2d, which was generated by GNU Autoconf 2.59. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -10688,7 +10708,7 @@ cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -xMule config.status 1.8.2c +xMule config.status 1.8.2d configured by $0, generated by GNU Autoconf 2.59, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" @@ -10787,6 +10807,7 @@ # INIT-COMMANDS section. # + # Capture the value of obsolete ALL_LINGUAS because we need it to compute # POFILES, GMOFILES, UPDATEPOFILES, DUMMYPOFILES, CATALOGS. But hide it # from automake. @@ -10811,6 +10832,7 @@ "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; "Compilation.flags" ) CONFIG_FILES="$CONFIG_FILES Compilation.flags" ;; "default-1" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; + "default-2" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-2" ;; "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} @@ -11547,7 +11569,8 @@ { echo "$as_me:$LINENO: executing $ac_dest commands" >&5 echo "$as_me: executing $ac_dest commands" >&6;} case $ac_dest in - default-1 ) + default-1 ) test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h ;; + default-2 ) for ac_file in $CONFIG_FILES; do # Support "outfile[:infile[:infile...]]" case "$ac_file" in diff -ur xmule/configure.in xmule.new/configure.in --- xmule/configure.in 2004-05-31 16:35:17.000000000 -0700 +++ xmule.new/configure.in 2004-06-16 13:18:42.276133000 -0700 @@ -1,13 +1,13 @@ # Process this file with autoconf to produce a configure script. -AC_INIT([xMule],[1.8.2c],[http://xmule.hopto.org/board/]) +AC_INIT([xMule],[1.8.2d],[http://xmule.hopto.org/board/]) AC_CONFIG_SRCDIR([src/SharedFileList.h]) AM_CONFIG_HEADER([config.h]) # BEGIN COMPAT VARIABLES AC_DEFINE(PACKAGE, ["xmule"], [Description]) -AC_DEFINE(VERSION, ["1.8.2c"], [Description]) +AC_DEFINE(VERSION, ["1.8.2d"], [Description]) PACKAGE="xmule" -VERSION="1.8.2c" +VERSION="1.8.2d" AC_SUBST(PACKAGE) AC_SUBST(VERSION) # END COMPAT VARIABLES @@ -64,6 +64,8 @@ AC_ARG_ENABLE(debug, [ --disable-debug-syms Disable debugging information], USE_DEBUG_SYMS="$disableval", USE_DEBUG_SYMS="yes") +AC_ARG_ENABLE(cryptopp, [ --enable-cryptopp Enable use of libcryptopp.a instead of CryptoXMpp]) + AC_ARG_ENABLE(optimise,[ --enable-optimise Enable code optimising], USE_OPTIMISE="$enableval", USE_OPTIMISE="no") @@ -146,6 +148,15 @@ esac fi +if test -n "$enable_cryptopp"; then + enable_cryptopp=no + CRDEFS="-D__CRPP__" + LIBCRPP="-lcryptopp" +else + CRDEFS="" +fi + + if test -n "$enable_gtk"; then enable_stripgtk=no GTK_DEFS="-D__NOGTK__" @@ -168,8 +179,9 @@ AC_DEFINE_UNQUOTED(LOCALEDIR, "`eval echo $datadir/locale`", [Define where the locales are.]) # we have it anyway by now -LIBS="$LIBS $WX_LIBS $ZLIB_LIBS $LIBM" +LIBS="$LIBS $WX_LIBS $ZLIB_LIBS $LIBM $LIBCRPP" +GTK_CFLAGS="$GTK_CFLAGS $CRDEFS" PCHFLAGS="$PCHFLAGS $DEBUG_FLAGS $GTK_CFLAGS -I. $DEFS $WX_CXXFLAGS" AC_SUBST(GTK_DEFS) @@ -178,7 +190,7 @@ AC_SUBST(MAKE_PRECOMP) XRCFLAGS="-Isrc" CXXFLAGS="$CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS $WX_CXXFLAGS $GTK_CFLAGS $XRCFLAGS $ZLIB_CFLAGSx" -CFLAGS="$GTK_DEFS $CFLAGS $CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS" +CFLAGS="$GTK_DEFS $CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS" LDFLAGS="$EXPORT_DYN_FLAGS $PROFILE_FLAGS $LDFLAGS" AC_CONFIG_FILES([src/Makefile intl/Makefile po/Makefile.in src/wx/xrc/Makefile Makefile Compilation.flags]) diff -ur xmule/src/AddFileThread.cpp xmule.new/src/AddFileThread.cpp --- xmule/src/AddFileThread.cpp 2004-04-30 14:13:17.000000000 -0700 +++ xmule.new/src/AddFileThread.cpp 2004-06-16 13:18:42.279133000 -0700 @@ -23,6 +23,7 @@ # include "KnownFile.h" # include "opcodes.h" # include "otherfunctions.h" +# include "PartFile.h" # include "types.h" # include "xmule.h" # include "xmuleDlg.h" @@ -59,9 +60,6 @@ void CAddFileThread:: Shutdown() { m_lockWaitingForHashList.Lock(); -#if defined(__DEBUG__) - printf("Signaling hashing thread to terminate\n"); -#endif // Tell the thread to exit m_endWaitingForHashList = 1; // Signal the thread there is something to do @@ -101,9 +99,8 @@ UnknownFile_Struct *hashfile = m_sWaitingForHashList.RemoveHead(); m_lockWaitingForHashList.Unlock(); CKnownFile *newrecord = new CKnownFile(); - printf("Sharing %s/%s\n", hashfile -> directory, hashfile -> name); - // TODO: What we are supposed to do if the following does fail? - newrecord -> CreateFromFile(hashfile -> directory, hashfile -> name, &m_endWaitingForHashList); + newrecord -> CreateFromFile(hashfile->owner,hashfile -> directory, hashfile -> name, + &m_endWaitingForHashList); if (!m_endWaitingForHashList) { wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, TM_FINISHEDHASHING); diff -ur xmule/src/BaseClient.cpp xmule.new/src/BaseClient.cpp --- xmule/src/BaseClient.cpp 2004-05-25 15:06:32.000000000 -0700 +++ xmule.new/src/BaseClient.cpp 2004-06-16 13:18:42.315127000 -0700 @@ -805,15 +805,6 @@ void CUpDownClient:: SendHelloTypePacket(CMemFile *data) { -/* -unsigned char *uh; -uh=(unsigned char *)theApp.glob_prefs->GetUserHash(); -for(int i=0;i<16;i++) { -printf(" %02x",uh[i]); -} -printf("\n"); -*/ - data -> Write(theApp.glob_prefs -> GetUserHash(), 16); uint32 clientid = theApp.serverconnect -> GetClientID(); data -> Write( &clientid, 4); @@ -881,8 +872,15 @@ tagVersion.WriteTagToFile(data); CTag tagUDPports(CT_EMULE_UDPPORTS, (uint32) theApp.glob_prefs -> GetUDPPort()); tagUDPports.WriteTagToFile(data); - CTag tagMuleVersion(CT_EMULE_VERSION, SO_XMULE << 24); + if(!newprefs01_opt[3]) { + CTag tagMuleVersion(CT_EMULE_VERSION, + (SO_XMULE << 24)|(VERSION_MJR<<17)|(VERSION_MIN<<10)|(VERSION_UPDATE<<7)); + tagMuleVersion.WriteTagToFile(data); + } else { + CTag tagMuleVersion(CT_EMULE_VERSION, + (SO_EMULE << 24)|(0<<17)|(42<<10)|(VERSION_UPDATE<<4)); tagMuleVersion.WriteTagToFile(data); + } const uint32 uUdpVer = 4; const uint32 uDataCompVer = 1; const uint32 uSupportSecIdent = theApp.clientcredits -> CryptoAvailable() ?3: 0; @@ -1300,14 +1298,17 @@ int CUpDownClient:: GetHashType() { - if (m_achUserHash[5] == 13 &&m_achUserHash[14] == 110) - return SO_OLDEMULE; - else if(m_achUserHash[5] == 14 &&m_achUserHash[14] == 111) - return SO_EMULE; - else if(m_achUserHash[5] == 'M' &&m_achUserHash[14] == 'L') - return SO_MLDONKEY; - else - return SO_UNKNOWN; + int retcode=0; + if (m_achUserHash[5] == 13 &&m_achUserHash[14] == 110) { + retcode=SO_OLDEMULE; + } else if(m_achUserHash[5] == 14 &&m_achUserHash[14] == 111) { + retcode=SO_EMULE; + } else if(m_achUserHash[5] == 'M' &&m_achUserHash[14] == 'L') { + retcode=SO_MLDONKEY; + } else { + retcode=SO_UNKNOWN; + } + return retcode; } void CUpDownClient:: SetUserName(char *pszNewName) diff -ur xmule/src/ClientCredits.cpp xmule.new/src/ClientCredits.cpp --- xmule/src/ClientCredits.cpp 2004-05-31 15:02:46.000000000 -0700 +++ xmule.new/src/ClientCredits.cpp 2004-06-16 13:18:42.322126000 -0700 @@ -19,8 +19,7 @@ //along with this program; if not, write to the Free Software //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -//#ifdef PRECOMP -#if 1 +#ifdef PRECOMP # include "xmule-headers.h" #else # include "ClientCredits.h" @@ -42,7 +41,7 @@ #include #include -#if 1 +#ifndef __CRPP__ # include "CryptoXMpp.h" #else # include diff -ur xmule/src/ClientCredits.h xmule.new/src/ClientCredits.h --- xmule/src/ClientCredits.h 2004-05-25 15:06:32.000000000 -0700 +++ xmule.new/src/ClientCredits.h 2004-06-16 13:18:42.325126000 -0700 @@ -26,12 +26,12 @@ #include "Preferences.h" #include "MapKey.h" -#if 1 -# include "CryptoXMpp.h" -#else +#ifdef __CRPP__ # include # include #define CryptoXMpp CryptoPP +#else +# include "CryptoXMpp.h" #endif /* winemaker: #pragma pack(1) */ diff -ur xmule/src/CryptoXMpp.cpp xmule.new/src/CryptoXMpp.cpp --- xmule/src/CryptoXMpp.cpp 2004-05-25 15:06:32.000000000 -0700 +++ xmule.new/src/CryptoXMpp.cpp 2004-06-16 13:18:42.400114000 -0700 @@ -59,6 +59,7 @@ only the for xmule needed parts taken from cryptopp in 2004 by upload2010 */ +#ifndef __CRPP__ #include #include #include @@ -9371,4 +9372,4 @@ } } - +#endif diff -ur xmule/src/CryptoXMpp.h xmule.new/src/CryptoXMpp.h --- xmule/src/CryptoXMpp.h 2004-05-26 10:58:54.000000000 -0700 +++ xmule.new/src/CryptoXMpp.h 2004-06-16 13:18:42.451107000 -0700 @@ -72,6 +72,7 @@ only the for xmule needed parts taken from cryptopp in 2004 by upload2010 */ +#ifndef __CRPP__ #ifndef CRYPTOPP_CONFIG_H #define CRYPTOPP_CONFIG_H @@ -9440,3 +9441,4 @@ } #endif +#endif diff -ur xmule/src/DownloadClient.cpp xmule.new/src/DownloadClient.cpp --- xmule/src/DownloadClient.cpp 2004-04-30 14:13:17.000000000 -0700 +++ xmule.new/src/DownloadClient.cpp 2004-06-16 13:18:42.465105000 -0700 @@ -47,9 +47,9 @@ extern int newprefs03_opt[]; -CBarShader CUpDownClient:: s_StatusBar(16); +CBarShader CUpDownClient::s_StatusBar(16); -void CUpDownClient:: DrawStatusBar(wxMemoryDC *dc, wxRect rect, bool onlygreyrect, bool bFlat) +void CUpDownClient::DrawStatusBar(wxMemoryDC * dc, wxRect rect, bool onlygreyrect, bool bFlat) { DWORD crBoth; DWORD crNeither; @@ -79,7 +79,7 @@ // Barry - was only showing one part from client, even when reserved bits from 2 parts wxString gettingParts; ShowDownloadingParts(gettingParts); - if (!onlygreyrect &&reqfile &&m_abyPartStatus) + if (!onlygreyrect && reqfile && m_abyPartStatus) { for (uint32 i = 0 ; i != m_nPartCount ; i++) { @@ -90,32 +90,32 @@ uEnd = reqfile -> GetFileSize(); else uEnd = PARTSIZE * (i + 1); - if (reqfile -> IsComplete(PARTSIZE *i, PARTSIZE * (i + 1) - 1)) - s_StatusBar.FillRange(PARTSIZE *i, uEnd, crBoth); - else if(m_nDownloadState == DS_DOWNLOADING &&m_nLastBlockOffset < uEnd && - m_nLastBlockOffset >= PARTSIZE *i) - s_StatusBar.FillRange(PARTSIZE *i, uEnd, crPending); + if (reqfile -> IsComplete(PARTSIZE * i, PARTSIZE * (i + 1) - 1)) + s_StatusBar.FillRange(PARTSIZE * i, uEnd, crBoth); + else if(m_nDownloadState == DS_DOWNLOADING && m_nLastBlockOffset < uEnd && + m_nLastBlockOffset >= PARTSIZE * i) + s_StatusBar.FillRange(PARTSIZE * i, uEnd, crPending); else if(gettingParts.GetChar(i) == 'Y') - s_StatusBar.FillRange(PARTSIZE *i, uEnd, crNextPending); + s_StatusBar.FillRange(PARTSIZE * i, uEnd, crNextPending); else - s_StatusBar.FillRange(PARTSIZE *i, uEnd, crClientOnly); + s_StatusBar.FillRange(PARTSIZE * i, uEnd, crClientOnly); } } } s_StatusBar.Draw(dc, rect.x, rect.y, bFlat); } -bool CUpDownClient:: Compare(CUpDownClient *tocomp) +bool CUpDownClient::Compare(CUpDownClient * tocomp) { - if (HasValidHash() &&tocomp -> HasValidHash()) + if (HasValidHash() && tocomp -> HasValidHash()) return !memcmp(this -> GetUserHash(), tocomp -> GetUserHash(), 16); if (HasLowID()) return((this -> GetUserID() == tocomp -> GetUserID()) && (GetServerIP() == tocomp -> GetServerIP())); else - return(this -> GetUserID() == tocomp -> GetUserID() || (this -> GetIP() &&this -> GetIP() == tocomp -> GetIP())); + return(this -> GetUserID() == tocomp -> GetUserID() || (this -> GetIP() && this -> GetIP() == tocomp -> GetIP())); } -void CUpDownClient:: AskForDownload() +void CUpDownClient::AskForDownload() { int rank = GetRemoteQueueRank(); if (GetDownloadState() == DS_CONNECTING) @@ -126,8 +126,8 @@ { m_cFailed = 0; } - bool hotrank = (rank &&rank < 5); - if (theApp.listensocket -> TooManySockets(hotrank) && ! (socket &&socket -> IsConnected())) + bool hotrank = (rank && rank < 5); + if (theApp.listensocket -> TooManySockets(hotrank) && ! (socket && socket -> IsConnected())) { if (GetDownloadState() != DS_TOOMANYCONNS) { @@ -141,7 +141,7 @@ socket -> hotrank = hotrank; } m_bUDPPending = false; - m_dwLastAskedTime =:: GetTickCount(); + m_dwLastAskedTime =::GetTickCount(); if (m_cFailed < 3) { SetDownloadState(DS_CONNECTING); @@ -156,15 +156,15 @@ } } -bool CUpDownClient:: IsSourceRequestAllowed() +bool CUpDownClient::IsSourceRequestAllowed() { - DWORD dwTickCount =:: GetTickCount() + CONNECTION_LATENCY; + DWORD dwTickCount =::GetTickCount() + CONNECTION_LATENCY; int nTimePassedClient = dwTickCount - GetLastSrcAnswerTime(); int nTimePassedFile = dwTickCount - reqfile -> GetLastAnsweredTime(); bool bNeverAskedBefore = GetLastSrcReqTime() == 0; return( //if client has the correct extended protocol - ExtProtocolAvailable() &&m_bySourceExchangeVer >= 1 && + ExtProtocolAvailable() && m_bySourceExchangeVer >= 1 && //AND if we need more sources theApp.glob_prefs -> GetMaxSourcePerFileSoft() > reqfile -> GetSourceCount() && //AND if... @@ -172,25 +172,25 @@ //source is not complete and file is rare, allow once every 10 minutes (!m_bCompleteSource && (reqfile -> GetSourceCount() - reqfile -> GetValidSourcesCount() <= RARE_FILE / 4 || - reqfile -> GetSourceCount() <= RARE_FILE *2 + reqfile -> GetSourceCount() <= RARE_FILE * 2 ) && (bNeverAskedBefore || nTimePassedClient > SOURCECLIENTREASK) ) || // otherwise, allow every 90 minutes, but only if we haven't // asked someone else in last 10 minutes - ((bNeverAskedBefore || nTimePassedClient > SOURCECLIENTREASK *reqfile -> GetCommonFilePenalty()) && + ((bNeverAskedBefore || nTimePassedClient > SOURCECLIENTREASK * reqfile -> GetCommonFilePenalty()) && (nTimePassedFile > SOURCECLIENTREASK) ) ) ); } -void CUpDownClient:: SendFileRequest() +void CUpDownClient::SendFileRequest() { if (reqfile) { AddAskedCountDown(); - CSafeMemFile *dataFileReq; + CSafeMemFile * dataFileReq; if (newprefs02_opt[1]) { dataFileReq = new CSafeMemFile(32); @@ -221,7 +221,7 @@ { CSafeMemFile dataSetReqFileID(16); dataSetReqFileID.Write(reqfile -> GetFileHash(), 16); - NewSocket_SendPacketOPdata(2, OP_SETREQFILEID, &dataSetReqFileID, (wxUint32) this, 0); + NewSocket_SendPacketOPdata(2, OP_SETREQFILEID, & dataSetReqFileID, (wxUint32) this, 0); } if (IsEmuleClient()) { @@ -233,7 +233,7 @@ if (IsSourceRequestAllowed()) { reqfile -> SetLastAnsweredTimeTimeout(); - Packet *packet = new Packet(OP_REQUESTSOURCES, 16, OP_EMULEPROT); + Packet * packet = new Packet(OP_REQUESTSOURCES, 16, OP_EMULEPROT); md4cpy(packet -> pBuffer, reqfile -> GetFileHash()); NewSocket_SendPacketOP(2, OP_REQUESTSOURCES, packet, (wxUint32) this, 0); SetLastAskedForSources(); @@ -242,14 +242,15 @@ } } -void CUpDownClient:: ProcessFileInfo(char *packet, uint32 size) +void CUpDownClient::ProcessFileInfo(char * packet, uint32 size) { - CSafeMemFile *data = new CSafeMemFile((BYTE *) packet, size); + CSafeMemFile * data = new CSafeMemFile((BYTE *) packet, size); uchar cfilehash[16]; data -> Read(cfilehash, 16); uint16 namelength; - data -> Read( &namelength, 2); - if (m_pszClientFilename) { + data -> Read( & namelength, 2); + if (m_pszClientFilename) + { delete[] m_pszClientFilename; } m_pszClientFilename = new char[namelength + 1]; @@ -260,14 +261,14 @@ delete data; } -void CUpDownClient:: ProcessFileStatus(char *packet, uint32 size) +void CUpDownClient::ProcessFileStatus(char * packet, uint32 size) { - CSafeMemFile *data = new CSafeMemFile((BYTE *) packet, size); + CSafeMemFile * data = new CSafeMemFile((BYTE *) packet, size); uchar cfilehash[16]; data -> Read(cfilehash, 16); - if ((reqfile) && (! memcmp(cfilehash, reqfile -> GetFileHash(), 16))) + if ((reqfile) && (!memcmp(cfilehash, reqfile -> GetFileHash(), 16))) { - data -> Read( &m_nPartCount, 2); + data -> Read( & m_nPartCount, 2); if (m_abyPartStatus) { delete[] m_abyPartStatus; @@ -292,11 +293,11 @@ while (done != m_nPartCount) { uint8 toread; - data -> Read( &toread, 1); + data -> Read( & toread, 1); for (sint32 i = 0 ; i != 8 ; i++) { - m_abyPartStatus[done] = ((toread >> i) &1) ? 1: 0; - if (m_abyPartStatus[done] && !reqfile -> IsComplete(done *PARTSIZE, ((done + 1) *PARTSIZE) - 1)) + m_abyPartStatus[done] = ((toread >> i) & 1) ? 1: 0; + if (m_abyPartStatus[done] && !reqfile -> IsComplete(done * PARTSIZE, ((done + 1) * PARTSIZE) - 1)) bPartsNeeded = true; done++; if (done == m_nPartCount) @@ -311,10 +312,13 @@ if (!bPartsNeeded) { SetDownloadState(DS_NONEEDEDPARTS); + if(reqfile->GetDownPriority()==PR_LOW) { + SwapToAnotherFile(); + } } else if(reqfile -> hashsetneeded) { - Packet *packet = new Packet(OP_HASHSETREQUEST, 16); + Packet * packet = new Packet(OP_HASHSETREQUEST, 16); memcpy(packet -> pBuffer, reqfile -> GetFileHash(), 16); NewSocket_SendPacketOP(2, OP_HASHSETREQUEST, packet, (wxUint32) this, 0); SetDownloadState(DS_REQHASHSET); @@ -334,7 +338,7 @@ delete data; } -bool CUpDownClient:: AddRequestForAnotherFile(CPartFile *file) +bool CUpDownClient::AddRequestForAnotherFile(CPartFile * file) { for (POSITION pos = m_OtherNoNeeded_list.GetHeadPosition() ; pos != 0 ; m_OtherNoNeeded_list.GetNext(pos)) { @@ -352,7 +356,7 @@ return true; } -void CUpDownClient:: SetDownloadState(uint8 byNewState) +void CUpDownClient::SetDownloadState(uint8 byNewState) { if (m_nDownloadState != byNewState) { @@ -371,14 +375,14 @@ m_nDownloadState = byNewState; for (POSITION pos = m_DownloadBlocks_list.GetHeadPosition() ; pos != 0 ; m_DownloadBlocks_list.GetNext(pos)) { - Requested_Block_Struct *cur_block = m_DownloadBlocks_list.GetAt(pos); + Requested_Block_Struct * cur_block = m_DownloadBlocks_list.GetAt(pos); reqfile -> RemoveBlockFromList(cur_block -> StartOffset, cur_block -> EndOffset); delete m_DownloadBlocks_list.GetAt(pos); } m_DownloadBlocks_list.RemoveAll(); for (POSITION pos = m_PendingBlocks_list.GetHeadPosition() ; pos != 0 ; m_PendingBlocks_list.GetNext(pos)) { - Pending_Block_Struct *pending = m_PendingBlocks_list.GetAt(pos); + Pending_Block_Struct * pending = m_PendingBlocks_list.GetAt(pos); if (reqfile) reqfile -> RemoveBlockFromList(pending -> block -> StartOffset, pending -> block -> EndOffset); delete pending -> block; @@ -398,7 +402,7 @@ delete[] m_abyPartStatus; m_abyPartStatus = 0; } - if (socket &&byNewState != DS_ERROR) + if (socket && byNewState != DS_ERROR) socket -> DisableDownloadLimit(); } m_nDownloadState = byNewState; @@ -422,14 +426,14 @@ } } -void CUpDownClient:: ProcessHashSet(unsigned char *packet, uint32 size) +void CUpDownClient::ProcessHashSet(unsigned char * packet, uint32 size) { if (reqfile && (!memcmp(packet, reqfile -> GetFileHash(), 16))) { if (m_bHashsetRequested) { m_bHashsetRequested = false; - CSafeMemFile *data = new CSafeMemFile((BYTE *) packet, size); + CSafeMemFile * data = new CSafeMemFile((BYTE *) packet, size); if (reqfile -> LoadHashsetFromFile(data, true)) { SetDownloadState(DS_ONQUEUE); @@ -447,17 +451,17 @@ } } -void CUpDownClient:: SendBlockRequests() +void CUpDownClient::SendBlockRequests() { - m_dwLastBlockReceived =:: GetTickCount(); + m_dwLastBlockReceived =::GetTickCount(); if (reqfile) { if (m_DownloadBlocks_list.IsEmpty()) { // Barry - instead of getting 3, just get how many is needed uint16 count = 3 - m_PendingBlocks_list.GetCount(); - Requested_Block_Struct **toadd = new Requested_Block_Struct *[count]; - if (reqfile -> GetNextRequestedBlock(this, toadd, &count)) + Requested_Block_Struct ** toadd = new Requested_Block_Struct *[count]; + if (reqfile -> GetNextRequestedBlock(this, toadd, & count)) { for (int i = 0 ; i != count ; i++) m_DownloadBlocks_list.AddTail(toadd[i]); @@ -467,7 +471,7 @@ // Barry - Why are unfinished blocks requested again, not just new ones? while (m_PendingBlocks_list.GetCount() < 3 && !m_DownloadBlocks_list.IsEmpty()) { - Pending_Block_Struct *pblock = new Pending_Block_Struct; + Pending_Block_Struct * pblock = new Pending_Block_Struct; pblock -> block = m_DownloadBlocks_list.RemoveHead(); pblock -> zStream = NULL; pblock -> totalUnzipped = 0; @@ -478,25 +482,28 @@ { NewSocket_SendPacketOPdata(2, OP_CANCELTRANSFER, NULL, (wxUint32) this, 0); SetDownloadState(DS_NONEEDEDPARTS); + if(reqfile->GetDownPriority()==PR_LOW) { + SwapToAnotherFile(); + } } else { - CMemFile *data = new CMemFile(40); + CMemFile * data = new CMemFile(40); data -> Write(reqfile -> GetFileHash(), 16); POSITION pos = m_PendingBlocks_list.GetHeadPosition(); uint32 null = 0; - Requested_Block_Struct *block; + Requested_Block_Struct * block; for (uint32 i = 0 ; i != 3 ; i++) { if (pos) { block = m_PendingBlocks_list.GetAt(pos) -> block; m_PendingBlocks_list.GetNext(pos); - data -> Write( &block -> StartOffset, 4); + data -> Write( & block -> StartOffset, 4); } else { - data -> Write( &null, 4); + data -> Write( & null, 4); } } pos = m_PendingBlocks_list.GetHeadPosition(); @@ -507,11 +514,11 @@ block = m_PendingBlocks_list.GetAt(pos) -> block; m_PendingBlocks_list.GetNext(pos); uint32 endpos = block -> EndOffset + 1; - data -> Write( &endpos, 4); + data -> Write( & endpos, 4); } else { - data -> Write( &null, 4); + data -> Write( & null, 4); } } NewSocket_SendPacketOPdata(2, OP_REQUESTPARTS, data, (wxUint32) this, 0); @@ -519,90 +526,76 @@ } } -void CUpDownClient:: ProcessBlockPacket(char *packet, uint32 size, bool packed) +void CUpDownClient::ProcessBlockPacket(char * packet, uint32 size, bool packed) { // Ignore if no data required - if (! (GetDownloadState() == DS_DOWNLOADING || GetDownloadState() == DS_NONEEDEDPARTS)) - return; + if (GetDownloadState() == DS_DOWNLOADING || GetDownloadState() == DS_NONEEDEDPARTS) + { const int HEADER_SIZE = 24; - // Update stats - m_dwLastBlockReceived =:: GetTickCount(); - // Read data from packet - CSafeMemFile *data = new CSafeMemFile((BYTE *) packet, size); + m_dwLastBlockReceived =::GetTickCount(); + CSafeMemFile * data = new CSafeMemFile((BYTE *) packet, size); uchar fileID[16]; data -> Read(fileID, 16); - // Check that this data is for the correct file - if (reqfile && (! memcmp(packet, reqfile -> GetFileHash(), 16))) + if (reqfile && (!memcmp(packet, reqfile -> GetFileHash(), 16))) { - // Find the start & end positions, and size of this chunk of data uint32 nStartPos; uint32 nEndPos; uint32 nBlockSize = 0; - data -> Read( &nStartPos, 4); + data -> Read( & nStartPos, 4); if (packed) { - data -> Read( &nBlockSize, 4); + data -> Read( & nBlockSize, 4); nEndPos = nStartPos + (size - HEADER_SIZE); usedcompressiondown = true; } else { - data -> Read( &nEndPos, 4); + data -> Read( & nEndPos, 4); } // Check that packet size matches the declared data size + header size (24) if (size == ((nEndPos - nStartPos) + HEADER_SIZE)) { - // Move end back one, should be inclusive theApp.UpdateReceivedBytes(size - HEADER_SIZE); m_nDownDataRateMS += size - HEADER_SIZE; credits -> AddDownloaded(size - HEADER_SIZE, GetIP()); nEndPos--; - // Loop through to find the reserved block that this is within - Pending_Block_Struct *cur_block; - for (POSITION pos = m_PendingBlocks_list.GetHeadPosition() ; pos != NULL ; m_PendingBlocks_list.GetNext(pos)) + Pending_Block_Struct * cur_block; + for (POSITION pos = m_PendingBlocks_list.GetHeadPosition() ; + pos != NULL ; m_PendingBlocks_list.GetNext(pos)) { cur_block = m_PendingBlocks_list.GetAt(pos); - if ((cur_block -> block -> StartOffset <= nStartPos) && (cur_block -> block -> EndOffset >= nStartPos)) + if ((cur_block -> block -> StartOffset <= nStartPos) && + (cur_block -> block -> EndOffset >= nStartPos)) { - // Found reserved block if (cur_block -> bZStreamError) { theApp.xmuledlg -> AddDebugLogLine(false, _T("Ignoring %u bytes of block %u-%u because of errornous zstream state for file \"%s\""), size - HEADER_SIZE, nStartPos, nEndPos, reqfile -> GetFileName()); reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset, cur_block -> block -> EndOffset); return; } - // Remember this start pos, used to draw part downloading in list m_nLastBlockOffset = nStartPos; - // Occasionally packets are duplicated, no point writing it twice - // This will be 0 in these cases, or the length written otherwise uint32 lenWritten = 0; - // Handle differently depending on whether packed or not if (!packed) { - // Write to disk (will be buffered in part file class) lenWritten = reqfile -> WriteToBuffer(size - HEADER_SIZE, (BYTE *)(packet + HEADER_SIZE), nStartPos, nEndPos, cur_block -> block); - // Packed: } else { - // Create space to store unzipped data, the size is only an initial guess, will be resized in unzip() if not big enough - uint32 lenUnzipped = (size *2); - // Don't get too big + uint32 lenUnzipped = (size * 2); if (lenUnzipped > (GAPBLOCKSIZE + 300)) + { lenUnzipped = (GAPBLOCKSIZE + 300); - BYTE *unzipped = new BYTE[lenUnzipped]; - // Try to unzip the packet - int result = unzip(cur_block, (BYTE *)(packet + HEADER_SIZE), (size - HEADER_SIZE), &unzipped, &lenUnzipped); + } + BYTE * unzipped = new BYTE[lenUnzipped]; + int result = unzip(cur_block, (BYTE *)(packet + HEADER_SIZE), (size - HEADER_SIZE), & unzipped, & lenUnzipped); if (result == Z_OK) { - // Write any unzipped data to disk if (lenUnzipped > 0) { - // Use the current start and end positions for the uncompressed data nStartPos = cur_block -> block -> StartOffset + cur_block -> totalUnzipped - lenUnzipped; nEndPos = cur_block -> block -> StartOffset + cur_block -> totalUnzipped - 1; if (nStartPos > cur_block -> block -> EndOffset || nEndPos > cur_block -> block -> EndOffset) @@ -612,7 +605,6 @@ } else { - // Write uncompressed data to file lenWritten = reqfile -> WriteToBuffer(size - HEADER_SIZE, unzipped, nStartPos, @@ -624,35 +616,30 @@ else { CString strZipError; - if (cur_block -> zStream &&cur_block -> zStream -> msg) + if (cur_block -> zStream && cur_block -> zStream -> msg) strZipError.Format(_T(" - %s"), cur_block -> zStream -> msg); - theApp.xmuledlg -> AddDebugLogLine(false, GetResString(IDS_ERR_CORRUPTCOMPRPKG) + strZipError, reqfile -> GetFileName(), result); - reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset, cur_block -> block -> EndOffset); - // If we had an zstream error, there is no chance that we could recover from it nor that we - // could use the current zstream (which is in error state) any longer. + theApp.xmuledlg -> AddDebugLogLine(false, GetResString(IDS_ERR_CORRUPTCOMPRPKG) + + strZipError, reqfile -> GetFileName(), result); + reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset, + cur_block -> block -> EndOffset); if (cur_block -> zStream) { inflateEnd(cur_block -> zStream); delete cur_block -> zStream; cur_block -> zStream = NULL; } - // Although we can't further use the current zstream, there is no need to disconnect the sending - // client because the next zstream (a series of 10K-blocks which build a 180K-block) could be - // valid again. Just ignore all further blocks for the current zstream. cur_block -> bZStreamError = true; } delete [] unzipped; } - // These checks only need to be done if any data was written if (lenWritten > 0) { m_nTransferedDown += lenWritten; - // If finished reserved block if (nEndPos == cur_block -> block -> EndOffset) { - reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset, cur_block -> block -> EndOffset); + reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset, + cur_block -> block -> EndOffset); delete cur_block -> block; - // Not always allocated if (cur_block -> zStream) { inflateEnd(cur_block -> zStream); @@ -660,26 +647,25 @@ } delete cur_block; m_PendingBlocks_list.RemoveAt(pos); - // Request next block SendBlockRequests(); } } - // Stop looping and exit method return; } } } } delete data; + } } -int CUpDownClient:: unzip(Pending_Block_Struct *block, BYTE *zipped, uint32 lenZipped, BYTE **unzipped, uint32 *lenUnzipped, bool recursive) +int CUpDownClient::unzip(Pending_Block_Struct * block, BYTE * zipped, uint32 lenZipped, BYTE ** unzipped, uint32 * lenUnzipped, bool recursive) { int err = Z_DATA_ERROR; try { // Save some typing - z_stream *zS = block -> zStream; + z_stream * zS = block -> zStream; // Is this the first time this block has been unzipped if (zS == NULL) { @@ -691,8 +677,8 @@ zS -> zfree = (free_func) 0; zS -> opaque = (voidpf) 0; // Set output data streams, do this here to avoid overwriting on recursive calls - zS -> next_out = ( *unzipped); - zS -> avail_out = ( *lenUnzipped); + zS -> next_out = ( * unzipped); + zS -> avail_out = ( * lenUnzipped); // Initialise the z_stream err = inflateInit(zS); if (err != Z_OK) @@ -704,8 +690,8 @@ // Only set the output if not being called recursively if (!recursive) { - zS -> next_out = ( *unzipped); - zS -> avail_out = ( *lenUnzipped); + zS -> next_out = ( * unzipped); + zS -> avail_out = ( * lenUnzipped); } // Try to unzip the data err = inflate(zS, Z_SYNC_FLUSH); @@ -717,25 +703,25 @@ if (err != Z_OK) return err; // Got a good result, set the size to the amount unzipped in this call (including all recursive calls) - ( *lenUnzipped) = (zS -> total_out - block -> totalUnzipped); + ( * lenUnzipped) = (zS -> total_out - block -> totalUnzipped); block -> totalUnzipped = zS -> total_out; } else if((err == Z_OK) && (zS -> avail_out == 0)) { // Output array was not big enough, call recursively until there is enough space // What size should we try next - uint32 newLength = ( *lenUnzipped) *= 2; + uint32 newLength = ( * lenUnzipped) *= 2; if (newLength == 0) - newLength = lenZipped *2; + newLength = lenZipped * 2; // Copy any data that was successfully unzipped to new array - BYTE *temp = new BYTE[newLength]; - memcpy(temp, ( *unzipped), (zS -> total_out - block -> totalUnzipped)); - delete [] ( *unzipped); - ( *unzipped) = temp; - ( *lenUnzipped) = newLength; + BYTE * temp = new BYTE[newLength]; + memcpy(temp, ( * unzipped), (zS -> total_out - block -> totalUnzipped)); + delete [] ( * unzipped); + ( * unzipped) = temp; + ( * lenUnzipped) = newLength; // Position stream output to correct place in new array - zS -> next_out = ( *unzipped) + (zS -> total_out - block -> totalUnzipped); - zS -> avail_out = ( *lenUnzipped) - (zS -> total_out - block -> totalUnzipped); + zS -> next_out = ( * unzipped) + (zS -> total_out - block -> totalUnzipped); + zS -> avail_out = ( * lenUnzipped) - (zS -> total_out - block -> totalUnzipped); // Try again err = unzip(block, zS -> next_in, zS -> avail_in, unzipped, lenUnzipped, true); } @@ -743,7 +729,7 @@ { // All available input has been processed, everything ok. // Set the size to the amount unzipped in this call (including all recursive calls) - ( *lenUnzipped) = (zS -> total_out - block -> totalUnzipped); + ( * lenUnzipped) = (zS -> total_out - block -> totalUnzipped); block -> totalUnzipped = zS -> total_out; } else @@ -753,7 +739,7 @@ // DebugBreak(); I removed this so that we could let the client run for more the five minutes.. Barry needs to see if there is or isn't a preoblem here.. } if (err != Z_OK) - ( *lenUnzipped) = 0; + ( * lenUnzipped) = 0; } catch(...) { @@ -761,7 +747,7 @@ return err; } -uint32 CUpDownClient:: CalculateDownloadRate() +uint32 CUpDownClient::CalculateDownloadRate() { m_AvarageDDR_list.AddTail(m_nDownDataRateMS); m_nSumForAvgDownDataRate += m_nDownDataRateMS; @@ -769,17 +755,16 @@ m_nSumForAvgDownDataRate -= m_AvarageDDR_list.RemoveHead(); m_nDownDataRateMS = 0; if (m_AvarageDDR_list.GetCount() > 10) - m_nDownDatarate = 10 *m_nSumForAvgDownDataRate / m_AvarageDDR_list.GetCount(); + m_nDownDatarate = 10 * m_nSumForAvgDownDataRate / m_AvarageDDR_list.GetCount(); else m_nDownDatarate = 0; m_cShowDR++; if (m_cShowDR == 30) { m_cShowDR = 0; - //theApp.xmuledlg->transferwnd.downloadlistctrl.UpdateItem(this); UpdateDisplayedInfo(); } - if ((:: GetTickCount() - m_dwLastBlockReceived) > DOWNLOADTIMEOUT) + if ((::GetTickCount() - m_dwLastBlockReceived) > DOWNLOADTIMEOUT) { NewSocket_SendPacketOPdata(2, OP_CANCELTRANSFER, NULL, (wxUint32) this, 1); SetDownloadState(DS_ONQUEUE); @@ -787,7 +772,7 @@ return m_nDownDatarate; } -uint16 CUpDownClient:: GetAvailablePartCount() +uint16 CUpDownClient::GetAvailablePartCount() { uint16 result = 0; for (int i = 0 ; i != m_nPartCount ; i++) @@ -798,20 +783,20 @@ return result; } -void CUpDownClient:: SetRemoteQueueRank(uint16 nr) +void CUpDownClient::SetRemoteQueueRank(uint16 nr) { m_nRemoteQueueRank = nr; theApp.xmuledlg -> transferwnd -> downloadlistctrl -> UpdateItem(this); } -void CUpDownClient:: UDPReaskACK(uint16 nNewQR) +void CUpDownClient::UDPReaskACK(uint16 nNewQR) { m_bUDPPending = false; SetRemoteQueueRank(nNewQR); - m_dwLastAskedTime =:: GetTickCount(); + m_dwLastAskedTime =::GetTickCount(); } -void CUpDownClient:: UDPReaskFNF() +void CUpDownClient::UDPReaskFNF() { m_bUDPPending = false; theApp.downloadqueue -> RemoveSource(this); @@ -821,13 +806,13 @@ } } -void CUpDownClient:: UDPReaskForDownload() +void CUpDownClient::UDPReaskForDownload() { if (reqfile && (!m_bUDPPending)) { //the line "m_bUDPPending = true;" use to be here - if (m_nUDPPort != 0 &&theApp.glob_prefs -> GetUDPPort() != 0 && - !theApp.serverconnect -> IsLowID() && !HasLowID() && ! (socket &&socket -> IsConnected())) + if (m_nUDPPort != 0 && theApp.glob_prefs -> GetUDPPort() != 0 && + !theApp.serverconnect -> IsLowID() && !HasLowID() && ! (socket && socket -> IsConnected())) { //don't use udp to ask for sources if (IsSourceRequestAllowed()) @@ -842,13 +827,13 @@ { packetsize = 16; } - Packet *response = new Packet(OP_REASKFILEPING, packetsize, OP_EMULEPROT); + Packet * response = new Packet(OP_REASKFILEPING, packetsize, OP_EMULEPROT); md4cpy(response -> pBuffer, reqfile -> GetFileHash()); // #zegzav:completesrc (modify): if (GetUDPVersion() >= 3) { uint16 completecount = reqfile -> m_nCompleteSourcesCount; - memcpy(response -> pBuffer + 16, &completecount, 2); + memcpy(response -> pBuffer + 16, & completecount, 2); } NewSocket_SendPacketOP(1, OP_REASKFILEPING, response, GetIP(), GetUDPPort()); } @@ -857,9 +842,9 @@ } // Barry - Sets string to show parts downloading, eg NNNYNNNNYYNYN -void CUpDownClient:: ShowDownloadingParts(wxString &partsYN) +void CUpDownClient::ShowDownloadingParts(wxString & partsYN) { - Requested_Block_Struct *cur_block; + Requested_Block_Struct * cur_block; unsigned int x; partsYN.Alloc(m_nPartCount + 1); for (x = 0 ; x <= m_nPartCount ; x++) partsYN.SetChar(x, 'N'); @@ -871,18 +856,13 @@ { partsYN.SetChar(x, 'Y'); } - else - { - //printf("CUpDownClient::ShowDownloadingParts x(%ld) > partsYN.Len()(%ld) pc=%ld\n", - //x, partsYN.Len(), m_nPartCount); - } } } -void CUpDownClient:: UpdateDisplayedInfo(bool force) +void CUpDownClient::UpdateDisplayedInfo(bool force) { - DWORD curTick =:: GetTickCount(); - if (force || curTick - m_lastRefreshedDLDisplay > MINWAIT_BEFORE_DLDISPLAY_WINDOWUPDATE + (uint32)(rand() / (RAND_MAX/1000))) + DWORD curTick =::GetTickCount(); + if (force || curTick - m_lastRefreshedDLDisplay > MINWAIT_BEFORE_DLDISPLAY_WINDOWUPDATE + (uint32)(rand() / (RAND_MAX/ 1000))) { theApp.xmuledlg -> transferwnd -> downloadlistctrl -> UpdateItem(this); m_lastRefreshedDLDisplay = curTick; @@ -892,7 +872,7 @@ /* Razor 1a - Modif by MikaelB SwapToThisFile function */ -void CUpDownClient:: SwapToThisFile(CPartFile *file) +void CUpDownClient::SwapToThisFile(CPartFile * file) { // Get the position of the file in other requests' list POSITION position = this -> m_OtherRequests_list.Find(file); @@ -904,7 +884,7 @@ // Add file at the head of other requests' list this -> m_OtherRequests_list.AddHead(file); // Some files - CPartFile *SwapFile, *TempFile, *RequestedFile; + CPartFile * SwapFile, * TempFile, * RequestedFile; TempFile = this -> m_OtherRequests_list.GetHead(); RequestedFile = this -> reqfile; // If the file at the head of other requests' list isn't the requested file @@ -931,94 +911,70 @@ // if position isn't null... if (position) { - // Remove source at position from the sources list of requested file RequestedFile -> srclists[this -> sourcesslot].RemoveAt(position); - // Remove source of this client from requested file in the download list theApp.xmuledlg -> transferwnd -> downloadlistctrl -> RemoveSource(this, RequestedFile); - // Add this source in the A4AF sources list of the requested file RequestedFile -> A4AFSourcesList.AddTail(this); - // Add the requested file in the other requests' list this -> m_OtherRequests_list.AddTail(RequestedFile); - // Add source of requested file from this client in the download list theApp.xmuledlg -> transferwnd -> downloadlistctrl -> AddSource(RequestedFile, this, true); - // Update requested file's sources infos RequestedFile -> NewSrcPartsInfo(); - // Update requested file's parts counts RequestedFile -> UpdateAvailablePartsCount(); - // Set download state of this client to no this -> SetDownloadState(DS_NONE); - // Set requested file to 0 RequestedFile = 0; - // Set remote queue rank to 0 this -> m_nRemoteQueueRank = 0; - // If abyPartStatus isn't null if (this -> m_abyPartStatus) { - // Delete abyPartStatus delete[] this -> m_abyPartStatus; - // Set it to null this -> m_abyPartStatus = 0; } - // Set part count to this -> m_nPartCount = 0; - // Set last asked time to 0 this -> m_dwLastAskedTime = 0; - // set irate to 0 this -> m_iRate = 0; - // Set comment to "" this -> m_strComment = ""; - // If pszClientFilename isn't null if (this -> m_pszClientFilename) { - // Delete pszClientFilename delete this -> m_pszClientFilename; - // Set it to 0 this -> m_pszClientFilename = 0; } - // Set requested file to swapped file this -> reqfile = SwapFile; - // Add this source in the sources list of swapped file SwapFile -> srclists[this -> sourcesslot].AddTail(this); - // Add source of swapped file from this client to download list theApp.xmuledlg -> transferwnd -> downloadlistctrl -> AddSource(SwapFile, this, false); } } // Else if swapped file isn't null... else if(SwapFile) { - // Add it to other requests' list this -> m_OtherRequests_list.AddHead(SwapFile); - // Add this source to A4AF sources list of swapped file this -> m_OtherRequests_list.GetHead() -> A4AFSourcesList.AddHead(this); } - // Else... else - // Add this source to A4AF sources list of swapped file + { this -> m_OtherRequests_list.GetHead() -> A4AFSourcesList.AddHead(this); } - // Else... + } else - // Add this source to A4AF sources lisy of file + { file -> A4AFSourcesList.AddHead(this); + } } /* Razor 1a - Modif by MikaelB Made some changes in SwapToAnoterFile function */ -bool CUpDownClient:: SwapToAnotherFile() +bool CUpDownClient::SwapToAnotherFile() { - if (this -> GetDownloadState() == DS_DOWNLOADING) + if (this -> GetDownloadState() == DS_DOWNLOADING) { return false; + } if (!this -> m_OtherRequests_list.IsEmpty()) { - CPartFile *SwapTo = NULL; + CPartFile * SwapTo = NULL; POSITION pos, pos1, pos2; for (pos1 = this -> m_OtherRequests_list.GetHeadPosition() ; (pos2 = pos1) != NULL ;) { this -> m_OtherRequests_list.GetNext(pos1); - CPartFile *cur_file = this -> m_OtherRequests_list.GetAt(pos2); + CPartFile * cur_file = this -> m_OtherRequests_list.GetAt(pos2); if (cur_file != this -> reqfile - &&theApp.downloadqueue -> IsPartFile(cur_file) + && theApp.downloadqueue -> IsPartFile(cur_file) && !cur_file -> IsStopped() && (cur_file -> GetStatus(false) == PS_READY || cur_file -> GetStatus(false) == PS_EMPTY)) { @@ -1080,7 +1036,7 @@ /* End modif */ -void CUpDownClient:: SetDownloadFile(CPartFile *part) +void CUpDownClient::SetDownloadFile(CPartFile * part) { delete[] m_abyPartStatus; m_abyPartStatus = NULL; diff -ur xmule/src/DownloadListCtrl.cpp xmule.new/src/DownloadListCtrl.cpp --- xmule/src/DownloadListCtrl.cpp 2004-04-30 14:13:17.000000000 -0700 +++ xmule.new/src/DownloadListCtrl.cpp 2004-06-16 13:18:42.500099000 -0700 @@ -109,6 +109,8 @@ EVT_MENU(MP_CANCEL,CDownloadListCtrl::OnMCancel) */ +int fireup=0; + void preloadImages(wxImageList *imgs) { imgs -> Add(wxBitmap(client0_ICO)); @@ -193,11 +195,18 @@ if ((isShift || isCtrl || isAlt) && (cl -> GetDownloadFile() == toCollapse)) { uint8 ds = cl -> GetDownloadState(); + if(fireup==30002) { + if(ds!=DS_NONEEDEDPARTS) { +printf("fireup: %u\n",(uint32)cl); + continue; + } + } else { if ((isShift &&ds == DS_DOWNLOADING) || (isCtrl &&cl -> GetRemoteQueueRank() > 0) || (isAlt &&ds != DS_NONEEDEDPARTS)) { continue; } } + } item -> dwUpdated = 0; //item->status.DeleteObject(); if (item -> status) @@ -383,6 +392,7 @@ menu -> Append(MP_CANCEL, GetResString(IDS_MAIN_BTN_CANCEL)); menu -> Append(MP_STOP, GetResString(IDS_DL_STOP)); menu -> Append(MP_PAUSE, GetResString(IDS_DL_PAUSE)); + menu -> Append(30002, "Sourcecrunching"); menu -> Append(MP_RESUME, GetResString(IDS_DL_RESUME)); menu -> AppendSeparator(); /* Razor 1a - Modif by MikaelB @@ -446,7 +456,7 @@ menu -> Enable(MP_RESUME, ((file -> GetStatus() == PS_PAUSED) ? MF_ENABLED: MF_GRAYED)); //<<--9/21/02: menu -> Enable(MP_OPEN, ((file -> GetStatus() == PS_COMPLETE) ? MF_ENABLED: MF_GRAYED)); - menu -> SetLabel(MP_PREVIEW, wxString:: Format(_("Preview [%s]"), file -> GetPartMetFileName())); + menu -> SetLabel(MP_PREVIEW, wxString:: Format(_("Preview [%s]"), file -> GetPartMetFileName().GetData())); menu -> Enable(MP_PREVIEW, ((file -> PreviewAvailable()) ? MF_ENABLED: MF_GRAYED)); /* Razor 1a - Modif by MikaelB Set menu items' state for : @@ -2052,6 +2062,7 @@ file -> SavePartFile(); break; case MP_STOP: + fireup=0; if (selectedCount > 1) { Freeze(); @@ -2059,14 +2070,33 @@ { CPartFile *selected = selectedList.GetHead(); HideSources(selected); - selected -> StopFile(); + selected -> StopFile(0); selectedList.RemoveHead(); } Thaw(); + } else { + HideSources(file); + file -> StopFile(0); + } break; + case 30002: + fireup=30002; + if (selectedCount > 1) + { + // Freeze(); + while (!selectedList.IsEmpty()) + { + CPartFile *selected = selectedList.GetHead(); + //HideSources(selected); + selected -> RemoveAllSources(fireup,true); + selectedList.RemoveHead(); } - HideSources(file); - file -> StopFile(); + // Thaw(); + } else { + //HideSources(file); + file -> RemoveAllSources(fireup,true); + } + fireup=0; break; case MP_CLEARCOMPLETED: Freeze(); diff -ur xmule/src/DownloadQueue.cpp xmule.new/src/DownloadQueue.cpp --- xmule/src/DownloadQueue.cpp 2004-05-16 09:42:25.000000000 -0700 +++ xmule.new/src/DownloadQueue.cpp 2004-06-16 13:18:42.519096000 -0700 @@ -159,8 +159,14 @@ wxFileName myFileName(fileName); printf("Loading %s... ", myFileName.GetFullName() .GetData()); CPartFile *toadd = new CPartFile(); - if (toadd -> LoadPartFile(app_prefs -> GetTempDir(), (char *) myFileName.GetFullName() .GetData())) + if (toadd -> LoadPartFile(count0,app_prefs -> GetTempDir(), (char *) myFileName.GetFullName() .GetData())) { + switch(count0) { + case 0: + toadd->SetIsDynamic(false);break; + case 1: + toadd->SetIsDynamic(true);break; + } count++; printf("Done.\n"); filelist.AddTail(toadd); @@ -980,7 +986,7 @@ cur_file -> PauseFile(); break; case MP_STOP: - cur_file -> StopFile(); + cur_file -> StopFile(0); break; case MP_RESUME: if (cur_file -> GetStatus() == PS_PAUSED) diff -ur xmule/src/FlowChart.cpp xmule.new/src/FlowChart.cpp --- xmule/src/FlowChart.cpp 2004-05-31 15:02:46.000000000 -0700 +++ xmule.new/src/FlowChart.cpp 2004-06-16 13:18:42.530095000 -0700 @@ -110,6 +110,7 @@ wxMenu *pop_oldprefs09; int newprefs01_opt[101]; +wxString newprefs01_alpha[101]; wxString newprefs01info[256]; @@ -172,7 +173,13 @@ void Load_NewPrefs01() { - for (int i = 0 ; i < 7 ; i++) + int i=0; + for (i = 1 ; i <= 100 ; i++) + { + newprefs01_opt[i] = 0; + newprefs01_alpha[i] = ""; + } + for (i = 0 ; i < 7 ; i++) { switch(i) { case 3: @@ -204,7 +211,7 @@ (void) fread( &byte, 1, 1, newprefs01_fd); line += (wxChar) byte[0]; } - for (int i = 0 ; i < 7 ; i++) + for (i = 0 ; i < 7 ; i++) { if (i *4 <= line.Len()) { @@ -212,10 +219,36 @@ } } (void) fclose(newprefs01_fd); + newprefs01_filename = wxString:: Format("%s/.xMule/", getenv("HOME")) + wxT("newprefs01.alp"); + newprefs01_fd = fopen(newprefs01_filename, "r"); + if (newprefs01_fd == NULL) + { + newprefs01_fd = fopen(newprefs01_filename, "w"); + (void) fclose(newprefs01_fd); + newprefs01_fd = fopen(newprefs01_filename, "r"); + } + line = ""; + long v; + while (!feof(newprefs01_fd)) + { + (void) fread( &byte, 1, 1, newprefs01_fd); + switch(byte[0]) { + case 10: + line.Mid(1,3).ToLong(&v); + newprefs01_alpha[v]=line.Mid(4); + case 13:break; + case 0:break; + default: + line += (wxChar) byte[0]; + break; + } + } + (void) fclose(newprefs01_fd); } void Save_NewPrefs01() { + int i=0; FILE *newprefs01_fd; wxString line; wxString newprefs01_filename = wxString:: Format("%s/.xMule/", getenv("HOME")) + wxT("newprefs01.dat"); @@ -223,12 +256,27 @@ if (newprefs01_fd != NULL) { line = ""; - for (int i = 0 ; i < 7 ; i++) + for (i = 0 ; i < 7 ; i++) { line += " "; memcpy((void *)(((const char *) line) + i *4), &newprefs01_opt[i], 4); } - (void) fwrite(((const char *) line), 1, line.Len(), newprefs01_fd); + (void) fwrite((const char *) line, 1, line.Len(), newprefs01_fd); + (void) fclose(newprefs01_fd); + } + newprefs01_filename = wxString:: Format("%s/.xMule/", getenv("HOME")) + wxT("newprefs01.alp"); + newprefs01_fd = fopen(newprefs01_filename, "w"); + if (newprefs01_fd != NULL) + { + for (i = 0 ; i < 100 ; i++) + { + if(newprefs01_alpha[i].Len()) { + line=wxString::Format("%03d:",i); + (void) fwrite((const char *) line, 1, 4, newprefs01_fd); + (void) fwrite((const char *) newprefs01_alpha[i], 1, newprefs01_alpha[i].Len(), newprefs01_fd); + (void) fwrite("\n", 1, 1, newprefs01_fd); + } + } (void) fclose(newprefs01_fd); } } @@ -239,11 +287,9 @@ #define WXOBEF (wxObjectEventFunction)&CFlowChart for (int i = 1 ; i <= 100 ; i++) { - newprefs01_opt[i] = 0; newprefs03_opt[i] = 0; newprefs04_opt[i] = 0; } - //Save_NewPrefs01(); DARK_WHITE = new wxColour(0xef, 0xef, 0xef); Load_NewPrefs01(); ReadOldPrefs(); @@ -362,8 +408,8 @@ wxBoxSizer *root = new wxBoxSizer(wxVERTICAL); this -> SetAutoLayout(TRUE); this -> SetSizer(root); - root -> Fit(this); root -> SetSizeHints(this); + root -> Fit(this); root -> Show(this, TRUE); Connect( - 1, wxEVT_MOTION, SDMOUSEEVT:: OnMouseMove); Connect( - 1, wxEVT_PAINT, SDPAINTEVT:: OnPaint); @@ -480,6 +526,7 @@ CFlowChart:: ~CFlowChart() { + Save_NewPrefs01(); } void CFlowChart:: Popup_NewPrefs(wxMouseEvent &event) @@ -536,6 +583,13 @@ { if (x > 25 &&x < 130) { + int p=0;wxString ps; + ps=pop_newprefs01 -> GetLabel(20107); + p=ps.Find(":"); + if(p) { + ps=ps.Left(p+1); + } + pop_newprefs01 -> SetLabel(20107, ps+" "+newprefs01_alpha[7]); PopupMenu(pop_newprefs01, event.GetPosition()); } else if(x > 141 &&x < 236) @@ -564,6 +618,7 @@ case 20104: case 20105: case 20106: + case 20107: if (pop_newprefs01 -> IsChecked(eventid)) { newprefs01_opt[eventid - 20100] = 1; diff -ur xmule/src/KnownFile.cpp xmule.new/src/KnownFile.cpp --- xmule/src/KnownFile.cpp 2004-05-16 09:42:25.000000000 -0700 +++ xmule.new/src/KnownFile.cpp 2004-06-16 13:18:42.567089000 -0700 @@ -26,8 +26,10 @@ # include "ini2.h" # include "KnownFile.h" # include "KnownFileList.h" +# include "NewFunctions.h" # include "opcodes.h" # include "otherfunctions.h" +# include "PartFile.h" # include "Preferences.h" # include "SharedFileList.h" # include "SharedFilesWnd.h" @@ -40,23 +42,8 @@ #include #include -// constants for MD4Transform -#define S11 3 -#define S12 7 -#define S13 11 -#define S14 19 -#define S21 3 -#define S22 5 -#define S23 9 -#define S24 13 -#define S31 3 -#define S32 9 -#define S33 11 -#define S34 15 - -static void MD4Transform(uint32 Hash[4], uint32 x[16]); - -void CFileStatistic:: AddRequest() +// Adde by Tarod [Juanjo] +void CFileStatistic::AddRequest() { requested++; alltimerequested++; @@ -64,7 +51,7 @@ theApp.sharedfiles -> UpdateItem(fileParent); } -void CFileStatistic:: AddAccepted() +void CFileStatistic::AddAccepted() { accepted++; alltimeaccepted++; @@ -72,7 +59,7 @@ theApp.sharedfiles -> UpdateItem(fileParent); } -void CFileStatistic:: AddTransferred(uint64 bytes) +void CFileStatistic::AddTransferred(uint64 bytes) { transfered += bytes; alltimetransfered += bytes; @@ -80,7 +67,7 @@ theApp.sharedfiles -> UpdateItem(fileParent); } -CKnownFile:: CKnownFile() +CKnownFile::CKnownFile() { m_iFileType = 2; directory = NULL; @@ -106,7 +93,7 @@ m_iPartCount = 0; } -CKnownFile:: ~CKnownFile() +CKnownFile::~ CKnownFile() { for (int i = 0 ; i != hashlist.GetSize() ; i++) if (hashlist[i]) @@ -120,30 +107,10 @@ m_AvailPartFrequency.RemoveAll(); } -CBarShader CKnownFile:: s_ShareStatusBar(16); +CBarShader CKnownFile::s_ShareStatusBar(16); -void CKnownFile:: DrawShareStatusBar(wxDC *dc, wxRect rect, bool onlygreyrect, bool bFlat) +void CKnownFile::DrawShareStatusBar(wxDC * dc, wxRect rect, bool onlygreyrect, bool bFlat) { - /* - DWORD crBoth; - DWORD crNeither; - DWORD crClientOnly; - DWORD crPending; - DWORD crNextPending; - if(bFlat) { - crBoth = RGB(0, 150, 0); - crNeither = RGB(224, 224, 224); - crClientOnly = RGB(0, 0, 0); - crPending = RGB(255,208,0); - crNextPending = RGB(255,255,100); - } else { - crBoth = RGB(0, 192, 0); - crNeither = RGB(240, 240, 240); - crClientOnly = RGB(104, 104, 104); - crPending = RGB(255, 208, 0); - crNextPending = RGB(255,255,100); - } - */ s_ShareStatusBar.SetFileSize(GetFileSize()); s_ShareStatusBar.SetHeight(rect.GetHeight()); s_ShareStatusBar.SetWidth(rect.GetWidth()); @@ -162,7 +129,7 @@ s_ShareStatusBar.Draw(dc, rect.GetLeft(), rect.GetTop(), bFlat); } -void CKnownFile:: NewAvailPartsInfo() +void CKnownFile::NewAvailPartsInfo() { // Cache part count uint16 partcount = GetPartCount(); @@ -173,7 +140,7 @@ { m_AvailPartFrequency.Add(0); } - CUpDownClient *cur_src; + CUpDownClient * cur_src; if (this -> IsPartFile()) cur_src = NULL; for (POSITION pos = m_ClientUploadList.GetHeadPosition() ; pos != 0 ;) @@ -188,7 +155,7 @@ theApp.xmuledlg -> sharedfileswnd -> sharedfilesctrl -> UpdateItem(this); } -void CKnownFile:: AddUploadingClient(CUpDownClient *client) +void CKnownFile::AddUploadingClient(CUpDownClient * client) { // to be sure: POSITION pos = m_ClientUploadList.Find(client); @@ -198,7 +165,7 @@ } } -void CKnownFile:: RemoveUploadingClient(CUpDownClient *client) +void CKnownFile::RemoveUploadingClient(CUpDownClient * client) { // to be sure: POSITION pos = m_ClientUploadList.Find(client); @@ -208,92 +175,120 @@ } } -void CKnownFile:: SetPath(char *path) +void CKnownFile::SetPath(char * path) { if (directory) delete[] directory; directory = nstrdup(path); } -bool CKnownFile:: CreateFromFile(char *in_directory, char *in_filename, volatile int const *notify) +bool CKnownFile::CreateFromFile(void * pf0, char * in_directory, char * in_filename, volatile int const * notify) { - // TODO Errorhandling - //first create the filehashset - // open file + CPartFile *pf; + pf=(CPartFile *)pf0; + m_isDynamic = 0; + printf("CKnownFile::CreateFromFile: %s %s\n",in_directory, in_filename); directory = nstrdup(in_directory); - char *namebuffer = new char[strlen(in_directory) + strlen(in_filename) + 2]; + char * namebuffer = new char[strlen(in_directory) + strlen(in_filename) + 2]; sprintf(namebuffer, "%s/%s", in_directory, in_filename); - FILE *file = fopen(namebuffer, "r"); + FILE * file = fopen(namebuffer, "r"); delete[] namebuffer; - if (!file) + if (file) { - printf("%s/%s ei aukea\n", in_directory, in_filename); - return false; - } - // set filesize + name + long curpos=0; + printf("%s/%s curpos=%u\n", in_directory, in_filename, curpos); m_pszFileName = nstrdup(in_filename); - //filesize =_filelength(file->_file); - long curpos = ftell(file); + if (pf != NULL) + { + m_isDynamic = pf -> IsDynamic(); + m_nFileSize = pf -> m_nFileSize; + pf->Seek(curpos); + } + else + { + curpos = ftell(file); fseek(file, 0, SEEK_END); m_nFileSize = ftell(file); fseek(file, curpos, SEEK_SET); + } m_AvailPartFrequency.SetSize(GetPartCount()); for (uint32 i = 0 ; i != GetPartCount() ; i++) + { m_AvailPartFrequency.Add(0); + } // create hashset uint32 togo = m_nFileSize; - uint16 hashcount; - for (hashcount = 0 ; togo >= PARTSIZE ;) + uint16 hashcount=0; + while(togo >= PARTSIZE) + { + uchar * newhash = new uchar[16]; + if (pf != NULL) + { + pf -> CreateHash(PARTSIZE, newhash); + } + else { - uchar *newhash = new uchar[16]; CreateHashFromFile(file, PARTSIZE, newhash); + } hashlist.Add(newhash); togo -= PARTSIZE; hashcount++; - if (notify && *notify) + if (notify && * notify) + { + if (pf == NULL) { fclose(file); + } return false; } } - uchar *lasthash = new uchar[16]; + uchar * lasthash = new uchar[16]; memset(lasthash, 0, 16); - CreateHashFromFile(file, togo, lasthash); + if (pf != NULL) + { + pf -> CreateHash(togo, lasthash); + } + else + { + CreateHashFromFile( file, togo, lasthash); + } if (!hashcount) { memcpy(m_abyFileHash, lasthash, 16); - // i_a: memleak: delete[] lasthash; } else { hashlist.Add(lasthash); - uchar *buffer = new uchar[hashlist.GetCount() *16]; + uchar * buffer = new uchar[hashlist.GetCount() * 16]; for (int i = 0 ; i != hashlist.GetCount() ; i++) - memcpy(buffer + (i *16), hashlist[i], 16); - CreateHashFromString(buffer, hashlist.GetCount() *16, m_abyFileHash); + { + memcpy(buffer + (i * 16), hashlist[i], 16); + } + CreateHashFromString(buffer, hashlist.GetCount() * 16, m_abyFileHash); delete[] buffer; } - // TODO: Add filetags - // set lastwrite date struct stat fileinfo; - fstat(fileno(file), &fileinfo); + fstat(fileno(file), & fileinfo); date = fileinfo.st_mtime; - //finished fclose(file); return true; + } + else + { + return false; + } } -// needed for memfiles. its probably better to switch everything to CFile... -bool CKnownFile:: LoadHashsetFromFile(CFile *file, bool checkhash) +bool CKnownFile::LoadHashsetFromFile(CFile * file, bool checkhash) { uchar checkid[16]; - file -> Read( &checkid, 16); + file -> Read( & checkid, 16); uint16 parts; - file -> Read( &parts, 2); + file -> Read( & parts, 2); for (int i = 0 ; i != parts ; i++) { - uchar *cur_hash = new uchar[16]; + uchar * cur_hash = new uchar[16]; file -> Read(cur_hash, 16); hashlist.Add(cur_hash); } @@ -305,12 +300,12 @@ // trust noone ;-) if (!hashlist.IsEmpty()) { - uchar *buffer = new uchar[hashlist.GetCount() *16]; + uchar * buffer = new uchar[hashlist.GetCount() * 16]; for (int i = 0 ; i != hashlist.GetCount() ; i++) { - memcpy(buffer + (i *16), hashlist[i], 16); + memcpy(buffer + (i * 16), hashlist[i], 16); } - CreateHashFromString(buffer, hashlist.GetCount() *16, checkid); + CreateHashFromString(buffer, hashlist.GetCount() * 16, checkid); delete[] buffer; } if (!memcmp(m_abyFileHash, checkid, 16)) @@ -326,18 +321,18 @@ } } -bool CKnownFile:: LoadTagsFromFile(CFile *file) +bool CKnownFile::LoadTagsFromFile(CFile * file) { try { uint32 tagcount; - if (4 != file -> Read( &tagcount, 4)) + if (4 != file -> Read( & tagcount, 4)) throw CInvalidPacket("short file reading tag count"); for (uint32 j = 0 ; j < tagcount ; j++) { try { - CTag *newtag = new CTag(file); + CTag * newtag = new CTag(file); switch (newtag -> tag -> specialtag) { case FT_FILENAME: @@ -416,31 +411,31 @@ return true; } -bool CKnownFile:: LoadDateFromFile(CFile *file) +bool CKnownFile::LoadDateFromFile(CFile * file) { - return(4 == file -> Read( &date, 4)); + return(4 == file -> Read( & date, 4)); } -bool CKnownFile:: LoadFromFile(CFile *file) +bool CKnownFile::LoadFromFile(CFile * file) { - return(LoadDateFromFile(file) &&LoadHashsetFromFile(file, false) &&LoadTagsFromFile(file)); + return(LoadDateFromFile(file) && LoadHashsetFromFile(file, false) && LoadTagsFromFile(file)); } -bool CKnownFile:: WriteToFile(FILE *file) +bool CKnownFile::WriteToFile(FILE * file) { // date - fwrite( &date, 4, 1, file); + fwrite( & date, 4, 1, file); // hashset - fwrite( &m_abyFileHash, 16, 1, file); + fwrite( & m_abyFileHash, 16, 1, file); uint16 parts = hashlist.GetCount(); - fwrite( &parts, 2, 1, file); + fwrite( & parts, 2, 1, file); for (int i = 0 ; i != parts ; i++) fwrite(hashlist[i], 16, 1, file); //tags #define NR_TAGS 10 uint32 tagcount = taglist.GetCount() + NR_TAGS; // standard tags - fwrite( &tagcount, 4, 1, file); + fwrite( & tagcount, 4, 1, file); CTag(FT_FILENAME, m_pszFileName) .WriteTagToFile(file); CTag(FT_FILESIZE, m_nFileSize) .WriteTagToFile(file); // statistic @@ -461,7 +456,63 @@ #undef NR_TAGS } -void CKnownFile:: CreateHashFromInput(FILE *file, CFile *file2, int Length, uchar *Output, uchar *in_string) +void CKnownFile::CreateHashFromFile( FILE * file, int Length, uchar * Output) +{ + if (file != NULL) + { + bool PaddingStarted = false; + uint32 Hash[4]; + Hash[0] = 0x67452301; + Hash[1] = 0xEFCDAB89; + Hash[2] = 0x98BADCFE; + Hash[3] = 0x10325476; + uint32 Required = Length; + uchar X[64 * 128]; + while (Required >= 64) + { + uint32 len = Required / 64; + if (len > sizeof(X) / (64 * sizeof(X[0]))) + { + len = sizeof(X) / (64 * sizeof(X[0])); + } + fread( & X, len * 64, 1, file); + for (uint32 i = 0 ; i < len ; i++) + { + MD4Transform(Hash, (uint32 *)(X + i * 64)); + } + Required -= len * 64; + } + // bytes to read + Required = Length % 64; + if (Required != 0) + { + fread( & X, Required, 1, file); + } + // in byte scale 512 = 64, 448 = 56 + if (Required >= 56) + { + X[Required] = 0x80; + PaddingStarted = TRUE; + memset( & X[Required + 1], 0, 63 - Required); + MD4Transform(Hash, (uint32 *) X); + Required = 0; + } + if (!PaddingStarted) + { + X[Required++] = 0x80; + } + memset( & X[Required], 0, 64 - Required); + // add size (convert to bits) + uint32 Length2 = Length >> 29; + Length <<= 3; + memcpy( & X[56], & Length, 4); + memcpy( & X[60], & Length2, 4); + MD4Transform(Hash, (uint32 *) X); + memcpy(Output, Hash, 16); + } +} + +void CKnownFile::CreateHashFromInput(int id, FILE * file, CFile * file2, int Length, uchar * Output, uchar * in_string) { // time critial bool PaddingStarted = false; @@ -470,47 +521,59 @@ Hash[1] = 0xEFCDAB89; Hash[2] = 0x98BADCFE; Hash[3] = 0x10325476; - CMemFile *data = 0; + CMemFile * data = 0; if (in_string) { data = new CMemFile(in_string, Length); } uint32 Required = Length; - uchar X[64 *128]; + uchar X[64 * 128]; while (Required >= 64) { uint32 len = Required / 64; - if (len > sizeof(X) / (64 *sizeof(X[0]))) - len = sizeof(X) / (64 *sizeof(X[0])); + if (len > sizeof(X) / (64 * sizeof(X[0]))) + len = sizeof(X) / (64 * sizeof(X[0])); if (in_string) - data -> Read( &X, len *64); + { + data -> Read( & X, len * 64); + } else if(file) - fread( &X, len *64, 1, file); + { + fread( & X, len * 64, 1, file); + } else if(file2) - file2 -> Read( &X, len *64); + { + file2 -> Read( & X, len * 64); + } for (uint32 i = 0 ; i < len ; i++) { - MD4Transform(Hash, (uint32 *)(X + i *64)); + MD4Transform(Hash, (uint32 *)(X + i * 64)); } - Required -= len *64; + Required -= len * 64; } // bytes to read Required = Length % 64; if (Required != 0) { if (in_string) - data -> Read( &X, Required); + { + data -> Read( & X, Required); + } else if(file) - fread( &X, Required, 1, file); + { + fread( & X, Required, 1, file); + } else if(file2) - file2 -> Read( &X, Required); + { + file2 -> Read( & X, Required); + } } // in byte scale 512 = 64, 448 = 56 if (Required >= 56) { X[Required] = 0x80; PaddingStarted = TRUE; - memset( &X[Required + 1], 0, 63 - Required); + memset( & X[Required + 1], 0, 63 - Required); MD4Transform(Hash, (uint32 *) X); Required = 0; } @@ -518,137 +581,27 @@ { X[Required++] = 0x80; } - memset( &X[Required], 0, 64 - Required); + memset( & X[Required], 0, 64 - Required); // add size (convert to bits) uint32 Length2 = Length >> 29; Length <<= 3; - memcpy( &X[56], &Length, 4); - memcpy( &X[60], &Length2, 4); + memcpy( & X[56], & Length, 4); + memcpy( & X[60], & Length2, 4); MD4Transform(Hash, (uint32 *) X); memcpy(Output, Hash, 16); safe_delete(data); } -uchar *CKnownFile:: GetPartHash(uint16 part) +uchar * CKnownFile::GetPartHash(uint16 part) { if (part >= hashlist.GetCount()) + { return 0; + } return hashlist[part]; } -static void MD4Transform(uint32 Hash[4], uint32 x[16]) -{ - uint32 a = Hash[0]; - uint32 b = Hash[1]; - uint32 c = Hash[2]; - uint32 d = Hash[3]; - /* Round 1 */ - // 01: - MD4_FF(a, b, c, d, x[ 0], S11); - // 02: - MD4_FF(d, a, b, c, x[ 1], S12); - // 03: - MD4_FF(c, d, a, b, x[ 2], S13); - // 04: - MD4_FF(b, c, d, a, x[ 3], S14); - // 05: - MD4_FF(a, b, c, d, x[ 4], S11); - // 06: - MD4_FF(d, a, b, c, x[ 5], S12); - // 07: - MD4_FF(c, d, a, b, x[ 6], S13); - // 08: - MD4_FF(b, c, d, a, x[ 7], S14); - // 09: - MD4_FF(a, b, c, d, x[ 8], S11); - // 10: - MD4_FF(d, a, b, c, x[ 9], S12); - // 11: - MD4_FF(c, d, a, b, x[10], S13); - // 12: - MD4_FF(b, c, d, a, x[11], S14); - // 13: - MD4_FF(a, b, c, d, x[12], S11); - // 14: - MD4_FF(d, a, b, c, x[13], S12); - // 15: - MD4_FF(c, d, a, b, x[14], S13); - // 16: - MD4_FF(b, c, d, a, x[15], S14); - /* Round 2 */ - // 17: - MD4_GG(a, b, c, d, x[ 0], S21); - // 18: - MD4_GG(d, a, b, c, x[ 4], S22); - // 19: - MD4_GG(c, d, a, b, x[ 8], S23); - // 20: - MD4_GG(b, c, d, a, x[12], S24); - // 21: - MD4_GG(a, b, c, d, x[ 1], S21); - // 22: - MD4_GG(d, a, b, c, x[ 5], S22); - // 23: - MD4_GG(c, d, a, b, x[ 9], S23); - // 24: - MD4_GG(b, c, d, a, x[13], S24); - // 25: - MD4_GG(a, b, c, d, x[ 2], S21); - // 26: - MD4_GG(d, a, b, c, x[ 6], S22); - // 27: - MD4_GG(c, d, a, b, x[10], S23); - // 28: - MD4_GG(b, c, d, a, x[14], S24); - // 29: - MD4_GG(a, b, c, d, x[ 3], S21); - // 30: - MD4_GG(d, a, b, c, x[ 7], S22); - // 31: - MD4_GG(c, d, a, b, x[11], S23); - // 32: - MD4_GG(b, c, d, a, x[15], S24); - /* Round 3 */ - // 33: - MD4_HH(a, b, c, d, x[ 0], S31); - // 34: - MD4_HH(d, a, b, c, x[ 8], S32); - // 35: - MD4_HH(c, d, a, b, x[ 4], S33); - // 36: - MD4_HH(b, c, d, a, x[12], S34); - // 37: - MD4_HH(a, b, c, d, x[ 2], S31); - // 38: - MD4_HH(d, a, b, c, x[10], S32); - // 39: - MD4_HH(c, d, a, b, x[ 6], S33); - // 40: - MD4_HH(b, c, d, a, x[14], S34); - // 41: - MD4_HH(a, b, c, d, x[ 1], S31); - // 42: - MD4_HH(d, a, b, c, x[ 9], S32); - // 43: - MD4_HH(c, d, a, b, x[ 5], S33); - // 44: - MD4_HH(b, c, d, a, x[13], S34); - // 45: - MD4_HH(a, b, c, d, x[ 3], S31); - // 46: - MD4_HH(d, a, b, c, x[11], S32); - // 47: - MD4_HH(c, d, a, b, x[ 7], S33); - // 48: - MD4_HH(b, c, d, a, x[15], S34); - Hash[0] += a; - Hash[1] += b; - Hash[2] += c; - Hash[3] += d; -} - -// Adde by Tarod [Juanjo] -void CAbstractFile:: SetFileName(char *NewName) +void CAbstractFile::SetFileName(char * NewName) { if (m_pszFileName != NULL) { @@ -669,17 +622,17 @@ //End by Tarod -Packet *CKnownFile:: CreateSrcInfoPacket(CUpDownClient *forClient) +Packet * CKnownFile::CreateSrcInfoPacket(CUpDownClient * forClient) { - CTypedPtrList < CPtrList, CUpDownClient *> srclist; + CTypedPtrList srclist; //should we use "filehash"?: - theApp.uploadqueue -> FindSourcesForFileById( &srclist, forClient -> GetUploadFileID()); + theApp.uploadqueue -> FindSourcesForFileById( & srclist, forClient -> GetUploadFileID()); if (srclist.IsEmpty()) return 0; CMemFile data; uint16 nCount = 0; data.Write(forClient -> GetUploadFileID(), 16); - data.Write( &nCount, 2); + data.Write( & nCount, 2); uint32 lastRequest = forClient -> GetLastSrcReqTime(); //we are only taking 30 random sources since we can't be sure if they have parts we need //this is hard coded because its a temp solution until next(?) version @@ -688,18 +641,18 @@ { int victim = ((rand() >> 7) % srclist.GetSize()); POSITION pos = srclist.FindIndex(victim); - CUpDownClient *cur_src = srclist.GetAt(pos); - if (!cur_src -> HasLowID() &&cur_src != forClient) + CUpDownClient * cur_src = srclist.GetAt(pos); + if (!cur_src -> HasLowID() && cur_src != forClient) { nCount++; uint32 dwID = cur_src -> GetUserID(); uint16 nPort = cur_src -> GetUserPort(); uint32 dwServerIP = cur_src -> GetServerIP(); uint16 nServerPort = cur_src -> GetServerPort(); - data.Write( &dwID, 4); - data.Write( &nPort, 2); - data.Write( &dwServerIP, 4); - data.Write( &nServerPort, 2); + data.Write( & dwID, 4); + data.Write( & nPort, 2); + data.Write( & dwServerIP, 4); + data.Write( & nServerPort, 2); if (forClient -> GetSourceExchangeVersion() > 1) data.Write(cur_src -> GetUserHash(), 16); } @@ -710,8 +663,8 @@ if (!nCount) return 0; data.Seek(16); - data.Write( &nCount, 2); - Packet *result = new Packet( &data, OP_EMULEPROT); + data.Write( & nCount, 2); + Packet * result = new Packet( & data, OP_EMULEPROT); result -> opcode = OP_ANSWERSOURCES; if (nCount > 28) result -> PackPacket(); @@ -719,7 +672,7 @@ } // Updates priority of file if autopriority is activated -void CKnownFile:: UpdateAutoUpPriority(void) +void CKnownFile::UpdateAutoUpPriority(void) { if (!this -> IsAutoUpPriority()) return; @@ -749,10 +702,10 @@ } //For File Comment // -void CKnownFile:: LoadComment() +void CKnownFile::LoadComment() { char buffer[100]; - char *fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13]; + char * fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13]; sprintf(fullpath, "%sfileinfo.ini", theApp.glob_prefs -> GetAppDir()); buffer[0] = 0; for (uint16 i = 0 ; i != 16 ; i++) @@ -765,10 +718,10 @@ delete[] fullpath; } -void CKnownFile:: SetFileComment(CString strNewComment) +void CKnownFile::SetFileComment(CString strNewComment) { char buffer[100]; - char *fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13]; + char * fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13]; sprintf(fullpath, "%sfileinfo.ini", theApp.glob_prefs -> GetAppDir()); buffer[0] = 0; for (uint16 i = 0 ; i != 16 ; i++) @@ -777,20 +730,20 @@ ini.WriteString("Comment", strNewComment); m_strComment = strNewComment; delete fullpath; - CTypedPtrList < CPtrList, CUpDownClient *> srclist; - theApp.uploadqueue -> FindSourcesForFileById( &srclist, this -> GetFileHash()); + CTypedPtrList srclist; + theApp.uploadqueue -> FindSourcesForFileById( & srclist, this -> GetFileHash()); for (POSITION pos = srclist.GetHeadPosition() ; pos != 0 ; srclist.GetNext(pos)) { - CUpDownClient *cur_src = srclist.GetAt(pos); + CUpDownClient * cur_src = srclist.GetAt(pos); cur_src -> SetCommentDirty(); } } // For File rate -void CKnownFile:: SetFileRate(int8 iNewRate) +void CKnownFile::SetFileRate(int8 iNewRate) { char buffer[100]; - char *fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13]; + char * fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13]; sprintf(fullpath, "%sfileinfo.ini", theApp.glob_prefs -> GetAppDir()); buffer[0] = 0; for (uint16 i = 0 ; i != 16 ; i++) @@ -799,19 +752,19 @@ ini.WriteInt("Rate", iNewRate); m_iRate = iNewRate; delete fullpath; - CTypedPtrList < CPtrList, CUpDownClient *> srclist; - theApp.uploadqueue -> FindSourcesForFileById( &srclist, this -> GetFileHash()); + CTypedPtrList srclist; + theApp.uploadqueue -> FindSourcesForFileById( & srclist, this -> GetFileHash()); for (POSITION pos = srclist.GetHeadPosition() ; pos != 0 ; srclist.GetNext(pos)) { - CUpDownClient *cur_src = srclist.GetAt(pos); + CUpDownClient * cur_src = srclist.GetAt(pos); cur_src -> SetCommentDirty(); } } -void CKnownFile:: SetUpPriority(uint8 iNewUpPriority, bool m_bsave) +void CKnownFile::SetUpPriority(uint8 iNewUpPriority, bool m_bsave) { m_iUpPriority = iNewUpPriority; - if (this -> IsPartFile() &&m_bsave) + if (this -> IsPartFile() && m_bsave) ((CPartFile *) this) -> SavePartFile(); } diff -ur xmule/src/KnownFile.h xmule.new/src/KnownFile.h --- xmule/src/KnownFile.h 2004-04-30 14:13:18.000000000 -0700 +++ xmule.new/src/KnownFile.h 2004-06-16 13:18:42.571088000 -0700 @@ -108,7 +108,7 @@ CKnownFile(); ~CKnownFile(); - virtual bool CreateFromFile(char* directory,char* filename, volatile int const * notify); // create date, hashset and tags from a file + virtual bool CreateFromFile(void* pf,char* directory,char* filename, volatile int const * notify); // create date, hashset and tags from a file uint32* GetFileTypePtr() {return &m_iFileType;} char* GetPath() {return directory;} void SetPath(char* path); @@ -154,16 +154,15 @@ protected: bool LoadTagsFromFile(CFile* file); bool LoadDateFromFile(CFile* file); - void CreateHashFromFile(FILE* file, int Length, uchar* Output) {CreateHashFromInput(file,0,Length,Output,0);} - void CreateHashFromFile(CFile* file, int Length, uchar* Output) {CreateHashFromInput(0,file,Length,Output,0);} - void CreateHashFromString(uchar* in_string, int Length, uchar* Output) {CreateHashFromInput(0,0,Length,Output,in_string);} + void CreateHashFromFile(FILE* file, int Length, uchar* Output); + void CreateHashFromString(uchar* in_string, int Length, uchar* Output) {CreateHashFromInput(0,0,0,Length,Output,in_string);} void LoadComment();//comment CArray hashlist; CArray taglist; char* directory; private: - void CreateHashFromInput(FILE* file,CFile* file2, int Length, uchar* Output, uchar* = 0); + void CreateHashFromInput(int id,FILE* file,CFile* file2, int Length, uchar* Output, uchar* = 0); bool m_bCommentLoaded; uint16 m_iPartCount; uint16 m_iED2KPartCount; @@ -174,6 +173,8 @@ uint32 m_iQueuedCount; static CBarShader s_ShareStatusBar; bool m_PublishedED2K; + int m_isDynamic; + long m_hfilepos; public: time_t m_nCompleteSourcesTime; @@ -191,32 +192,4 @@ #define PERM_NOONE 2 -// basic MD4 functions -#define MD4_F(x, y, z) (((x) & (y)) | ((~x) & (z))) -#define MD4_G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) -#define MD4_H(x, y, z) ((x) ^ (y) ^ (z)) - -// rotates x left n bits -#define MD4_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -// partial transformations -#define MD4_FF(a, b, c, d, x, s) \ -{ \ - (a) += MD4_F((b), (c), (d)) + (x); \ - (a) = MD4_ROTATE_LEFT((a), (s)); \ -} - -#define MD4_GG(a, b, c, d, x, s) \ -{ \ - (a) += MD4_G((b), (c), (d)) + (x) + (uint32)0x5A827999; \ - (a) = MD4_ROTATE_LEFT((a), (s)); \ -} - -#define MD4_HH(a, b, c, d, x, s) \ -{ \ - (a) += MD4_H((b), (c), (d)) + (x) + (uint32)0x6ED9EBA1; \ - (a) = MD4_ROTATE_LEFT((a), (s)); \ -} - - #endif diff -ur xmule/src/NewFunctions.cpp xmule.new/src/NewFunctions.cpp --- xmule/src/NewFunctions.cpp 2004-05-26 14:12:25.000000000 -0700 +++ xmule.new/src/NewFunctions.cpp 2004-06-16 13:18:42.576088000 -0700 @@ -34,11 +34,146 @@ #include "NewFunctions.h" #include "otherfunctions.h" + +void MD4Transform(uint32 Hash[4], uint32 x[16]) +{ +// constants for MD4Transform +#define S11 3 +#define S12 7 +#define S13 11 +#define S14 19 +#define S21 3 +#define S22 5 +#define S23 9 +#define S24 13 +#define S31 3 +#define S32 9 +#define S33 11 +#define S34 15 + + uint32 a = Hash[0]; + uint32 b = Hash[1]; + uint32 c = Hash[2]; + uint32 d = Hash[3]; + /* Round 1 */ + // 01: + MD4_FF(a, b, c, d, x[0], S11); + // 02: + MD4_FF(d, a, b, c, x[1], S12); + // 03: + MD4_FF(c, d, a, b, x[2], S13); + // 04: + MD4_FF(b, c, d, a, x[3], S14); + // 05: + MD4_FF(a, b, c, d, x[4], S11); + // 06: + MD4_FF(d, a, b, c, x[5], S12); + // 07: + MD4_FF(c, d, a, b, x[6], S13); + // 08: + MD4_FF(b, c, d, a, x[7], S14); + // 09: + MD4_FF(a, b, c, d, x[8], S11); + // 10: + MD4_FF(d, a, b, c, x[9], S12); + // 11: + MD4_FF(c, d, a, b, x[10], S13); + // 12: + MD4_FF(b, c, d, a, x[11], S14); + // 13: + MD4_FF(a, b, c, d, x[12], S11); + // 14: + MD4_FF(d, a, b, c, x[13], S12); + // 15: + MD4_FF(c, d, a, b, x[14], S13); + // 16: + MD4_FF(b, c, d, a, x[15], S14); + /* Round 2 */ + // 17: + MD4_GG(a, b, c, d, x[0], S21); + // 18: + MD4_GG(d, a, b, c, x[4], S22); + // 19: + MD4_GG(c, d, a, b, x[8], S23); + // 20: + MD4_GG(b, c, d, a, x[12], S24); + // 21: + MD4_GG(a, b, c, d, x[1], S21); + // 22: + MD4_GG(d, a, b, c, x[5], S22); + // 23: + MD4_GG(c, d, a, b, x[9], S23); + // 24: + MD4_GG(b, c, d, a, x[13], S24); + // 25: + MD4_GG(a, b, c, d, x[2], S21); + // 26: + MD4_GG(d, a, b, c, x[6], S22); + // 27: + MD4_GG(c, d, a, b, x[10], S23); + // 28: + MD4_GG(b, c, d, a, x[14], S24); + // 29: + MD4_GG(a, b, c, d, x[3], S21); + // 30: + MD4_GG(d, a, b, c, x[7], S22); + // 31: + MD4_GG(c, d, a, b, x[11], S23); + // 32: + MD4_GG(b, c, d, a, x[15], S24); + /* Round 3 */ + // 33: + MD4_HH(a, b, c, d, x[0], S31); + // 34: + MD4_HH(d, a, b, c, x[8], S32); + // 35: + MD4_HH(c, d, a, b, x[4], S33); + // 36: + MD4_HH(b, c, d, a, x[12], S34); + // 37: + MD4_HH(a, b, c, d, x[2], S31); + // 38: + MD4_HH(d, a, b, c, x[10], S32); + // 39: + MD4_HH(c, d, a, b, x[6], S33); + // 40: + MD4_HH(b, c, d, a, x[14], S34); + // 41: + MD4_HH(a, b, c, d, x[1], S31); + // 42: + MD4_HH(d, a, b, c, x[9], S32); + // 43: + MD4_HH(c, d, a, b, x[5], S33); + // 44: + MD4_HH(b, c, d, a, x[13], S34); + // 45: + MD4_HH(a, b, c, d, x[3], S31); + // 46: + MD4_HH(d, a, b, c, x[11], S32); + // 47: + MD4_HH(c, d, a, b, x[7], S33); + // 48: + MD4_HH(b, c, d, a, x[15], S34); + Hash[0] += a; + Hash[1] += b; + Hash[2] += c; + Hash[3] += d; +} + uint32 MapData(MAP *pos) { return pos -> Data; } +void md4printf(const void *hash) +{ +printf("md4hash: "); +for(int i=0;i<16;i++) { +printf("%02x",((unsigned char *)hash)[i]); +} +printf("\n"); +} + unsigned char *MapDataKey(MAP *pos) { return pos -> Key; diff -ur xmule/src/NewFunctions.h xmule.new/src/NewFunctions.h --- xmule/src/NewFunctions.h 2004-05-16 09:26:02.000000000 -0700 +++ xmule.new/src/NewFunctions.h 2004-06-16 13:18:42.579087000 -0700 @@ -24,6 +24,35 @@ #define MAPCLIENTS_MAX 30000 +// basic MD4 functions +#define MD4_F(x, y, z) (((x) & (y)) | ((~x) & (z))) +#define MD4_G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) +#define MD4_H(x, y, z) ((x) ^ (y) ^ (z)) + +// rotates x left n bits +#define MD4_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +// partial transformations +#define MD4_FF(a, b, c, d, x, s) \ +{ \ + (a) += MD4_F((b), (c), (d)) + (x); \ + (a) = MD4_ROTATE_LEFT((a), (s)); \ +} + +#define MD4_GG(a, b, c, d, x, s) \ +{ \ + (a) += MD4_G((b), (c), (d)) + (x) + (uint32)0x5A827999; \ + (a) = MD4_ROTATE_LEFT((a), (s)); \ +} + +#define MD4_HH(a, b, c, d, x, s) \ +{ \ + (a) += MD4_H((b), (c), (d)) + (x) + (uint32)0x6ED9EBA1; \ + (a) = MD4_ROTATE_LEFT((a), (s)); \ +} +void MD4Transform(uint32 Hash[4],uint32 x[16]); +void md4printf(const void *hash); + typedef struct _MAP { _MAP* next; diff -ur xmule/src/PartFile.cpp xmule.new/src/PartFile.cpp --- xmule/src/PartFile.cpp 2004-05-16 09:42:25.000000000 -0700 +++ xmule.new/src/PartFile.cpp 2004-06-16 13:18:42.617081000 -0700 @@ -41,6 +41,7 @@ # include "DownloadQueue.h" # include "ED2KLink.h" # include "ini2.h" +# include "NewFunctions.h" # include "otherfunctions.h" # include "PartFile.h" # include "Preview.h" @@ -62,40 +63,44 @@ #include #include +#include #define min(a,b) ((a)<(b)?(a):(b)) #define PROGRESS_HEIGHT 3 -void dump16f(FILE *f, uchar *d16) +void dump16f(FILE * f, uchar * d16) { int i; for (i = 0 ; i < 16 ; i++) { - fprintf(f, "%02X", *d16++); + fprintf(f, "%02X", * d16++); } } -void dump16(uchar *d16) +void dump16(uchar * d16) { int i; for (i = 0 ; i < 16 ; i++) { - printf("%02X", *d16++); + printf("%02X", * d16++); } } extern void dump16(uchar *); -CBarShader CPartFile:: s_LoadBar(PROGRESS_HEIGHT); +int bsize = 128 * 1024; +unsigned char buffer1[128 * 1024 + 1]; -CBarShader CPartFile:: s_ChunkBar(16); +CBarShader CPartFile::s_LoadBar(PROGRESS_HEIGHT); -CPartFile:: CPartFile() +CBarShader CPartFile::s_ChunkBar(16); + +CPartFile::CPartFile() { Init(); } -CPartFile:: CPartFile(CSearchFile *searchresult) +CPartFile::CPartFile(CSearchFile * searchresult) { Init(); memcpy(m_abyFileHash, searchresult -> GetFileHash(), 16); @@ -114,58 +119,65 @@ break; } default: - CTag *newtag = new CTag(searchresult -> taglist[i] -> tag); + CTag * newtag = new CTag(searchresult -> taglist[i] -> tag); taglist.Add(newtag); } } + m_hfilepos = 0; + if (newprefs01_opt[5]) + { + m_isDynamic |= 3; + m_nHeaderLength = (m_nFileSize/ bsize + 1) * 8; + m_nDynBloCount = 0; + } + else + { + m_isDynamic = 0; + m_nHeaderLength = 0; + m_nDynBloCount = 0; + } CreatePartFile(); } -CPartFile:: CPartFile(CString edonkeylink) +CPartFile::CPartFile(wxString edonkeylink) { - CED2KLink *pLink = 0; - try - { - pLink = CED2KLink:: CreateLinkFromUrl(edonkeylink); - CED2KFileLink *pFileLink = pLink -> GetFileLink(); + CED2KLink * pLink = 0; + pLink = CED2KLink::CreateLinkFromUrl(edonkeylink); + CED2KFileLink * pFileLink = pLink -> GetFileLink(); if (pFileLink == 0) throw GetResString(IDS_ERR_NOTAFILELINK); InitializeFromLink(pFileLink); - } - catch(wxString error) - { - char buffer[200]; - sprintf(buffer, GetResString(IDS_ERR_INVALIDLINK), error.GetData()); - theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_LINKERROR), buffer); - SetPartFileStatus(PS_ERROR); - } delete pLink; } void -CPartFile:: InitializeFromLink(CED2KFileLink *fileLink) +CPartFile::InitializeFromLink(CED2KFileLink * fileLink) { Init(); m_pszFileName = nstrdup(fileLink -> GetName()); m_nFileSize = fileLink -> GetSize(); memcpy(m_abyFileHash, fileLink -> GetHashKey(), sizeof(m_abyFileHash)); if (!theApp.downloadqueue -> IsFileExisting(m_abyFileHash)) + { CreatePartFile(); + } else + { SetPartFileStatus(PS_ERROR); + } } -CPartFile:: CPartFile(CED2KFileLink *fileLink) +CPartFile::CPartFile(CED2KFileLink * fileLink) { InitializeFromLink(fileLink); } -void CPartFile:: Init() +void CPartFile::Init() { fullname = 0; newdate = true; lastsearchtime = 0; - lastpurgetime =:: GetTickCount(); + lastpurgetime =::GetTickCount(); paused = false; stopped = false; SetPartFileStatus(PS_EMPTY); @@ -186,8 +198,10 @@ hashsetneeded = true; count = 0; percentcompleted = 0; - partmetfilename = 0; + partmetfilename = ""; completedsize = 0; + isnewstyle = false; + partmettype = PMT_UNKNOWN; m_bPreviewing = false; //NULL;: lastseencomplete = 0; @@ -212,76 +226,285 @@ m_category = 0; m_lastRefreshedDLDisplay = 0; m_LastSourceDropTime = 0; + m_isDynamic = 0; + m_nHeaderLength = 0; + m_nDynBloCount = 0; + m_nFileSize = 0; + convertstate=0; } -CPartFile:: ~CPartFile() +CPartFile::~ CPartFile() { - // Barry - Ensure all buffered data is written FlushBuffer(); - //m_hpartfile.Flush(); - //SavePartFile(); - //m_hpartfile.Close(); if (fullname) + { delete[] fullname; - if (partmetfilename) - delete[] partmetfilename; + } m_SrcpartFrequency.RemoveAll(); for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos)) + { delete gaplist.GetAt(pos); + } +} + +long CPartFile:: Read(void * buffer, long bytes) +{ + unsigned char tag[8]; + long bytecount = 0; + if (IsDynamic() < 2) + { + bytecount = m_hpartfile.Read(buffer, bytes); + m_hfilepos += bytecount; + } + else + { + unsigned long tag_number = 0, tag_blpo = 0; + int tag_blnr, tag_bytes, filesize; + unsigned char * bufferpos; + bufferpos = (unsigned char *) buffer; + if ((bytes + m_hfilepos) > m_nFileSize) + { + bytes = m_nFileSize - m_hfilepos; + if (bytes < 0) + { + bytes = 0; + } + } + while (bytecount < bytes) + { + tag_number = m_hfilepos/ bsize; + tag_blpo = m_hfilepos - bsize * tag_number; + tag_bytes = bsize - tag_blpo; + if (tag_bytes > (bytes - bytecount)) + { + tag_bytes = bytes - bytecount; + } + m_hpartfile.Readpos( & tag_blnr, tag_number * 8, 4); + m_hpartfile.Readpos( & filesize, tag_number * 8 + 4, 4); + if (tag_blnr) + { + tag_bytes = m_hpartfile.Readpos(bufferpos, m_nHeaderLength + (tag_blnr - 1) * bsize + tag_blpo, tag_bytes); + } + else + { + for (int i = 0 ; i < tag_bytes ; i++) + { + bufferpos[i] = 0; + } + } + if (tag_bytes) + { + m_hfilepos += tag_bytes; + bufferpos += tag_bytes; + bytecount += tag_bytes; + } + else + { + bytecount = bytes; + } + } + bytecount = bytes; + } + return bytecount; +} + +bool CPartFile:: Store(const wxString & newname) +{ + unsigned char * buffer; + int tag_number = 0; + int next = 0; + long bytepos = 0, bytes = 0; + wxFile fileOut(newname, wxFile:: write); + while (bytepos < m_nFileSize) + { + buffer = buffer1; + bytes = bsize; + if ((bytepos + bytes) > m_nFileSize) + { + bytes = m_nFileSize - bytepos; + } + m_hpartfile.Readpos( & next, tag_number * 8, 4); + (void) m_hpartfile.Readpos(buffer1, m_nHeaderLength + (next - 1) * bsize, bytes); + while (bytes > 0) + { + if (bytes > 4095) + { + fileOut.Write(buffer, 4096); + buffer += 4096; + bytes -= 4096; + } + else + { + fileOut.Write(buffer, bytes); + buffer += bytes; + bytes = 0; + } + } + tag_number++; + bytepos += bsize; + } + (void) fileOut.Close(); + return true; +} + +long CPartFile:: Write(void * buffer, long bytes) +{ + unsigned char tag[8]; + long bytecount = 0; + if (IsDynamic() < 2) + { + m_hfilepos += bytes; + if (Length() <= (m_hfilepos - 1)) + { + ftruncate(m_hpartfile.fd(), m_hfilepos); + } + bytecount = m_hpartfile.Write(buffer, bytes); + } + else + { + unsigned long tag_number = 0, tag_blpo = 0; + int tag_blnr, tag_bytes, filesize; + unsigned char * bufferpos; + bufferpos = (unsigned char *) buffer; + bytecount = bytes; + while (bytecount > 0) + { + tag_number = m_hfilepos/ bsize; + tag_blpo = m_hfilepos - bsize * tag_number; + tag_bytes = bsize - tag_blpo; + if (tag_bytes > bytecount) + { + tag_bytes = bytecount; + } + m_hpartfile.Readpos( & tag_blnr, tag_number * 8, 4); + m_hpartfile.Readpos( & filesize, tag_number * 8 + 4, 4); + if (!tag_blnr) + { + m_nDynBloCount++; + tag_blnr = m_nDynBloCount; + m_hpartfile.Writepos( & tag_blnr, tag_number * 8, 4); + ftruncate(m_hpartfile.fd(), m_nHeaderLength + tag_blnr * bsize); + } + tag_bytes = m_hpartfile.Writepos(bufferpos, m_nHeaderLength + (tag_blnr - 1) * bsize + tag_blpo, tag_bytes); + if (tag_bytes) + { + m_hfilepos += tag_bytes; + if (m_hfilepos > m_ilength) + { + m_ilength = m_hfilepos; + } + bufferpos += tag_bytes; + bytecount -= tag_bytes; + if (filesize < m_hfilepos) + { + filesize = m_hfilepos; + m_hpartfile.Writepos( & filesize, tag_number * 8 + 4, 4); + } + } + else + { + bytecount = - bytecount; + } + } + if (bytecount < 0) + { + bytecount = - bytecount; + } + } + return bytecount; } -void CPartFile:: CreatePartFile() +void CPartFile::Seek(unsigned long filepos) +{ + if (IsDynamic() < 2) + { + m_hpartfile.Seek(filepos); + } + m_hfilepos = filepos; +} + +void CPartFile::Close() +{ + m_hpartfile.Close(); +} + +unsigned long CPartFile::Length() +{ + unsigned long result; + result = m_hpartfile.Length(); + if (IsDynamic() > 1) + { + m_nHeaderLength = (m_nFileSize/ bsize + 1) * 8; + result -= m_nHeaderLength; + } + else + { + m_nHeaderLength = 0; + } + return result; +} + +void CPartFile::CreatePartFile() { // use lowest free partfilenumber for free file (InterCeptor) int i = 0; - CString filename; + wxString filename; do { i++; if (newprefs01_opt[5]) { - filename.Format("%s/%03i.pnew", theApp.glob_prefs -> GetTempDir(), i); + filename = wxString::Format("%s/%03i.pnew", theApp.glob_prefs -> GetTempDir(), i); } else { - filename.Format("%s/%03i.part", theApp.glob_prefs -> GetTempDir(), i); + filename = wxString::Format("%s/%03i.part", theApp.glob_prefs -> GetTempDir(), i); } } - while (wxFileName:: FileExists(filename)); - partmetfilename = new char[15]; + while (wxFileName::FileExists(filename)); if (newprefs01_opt[5]) { - sprintf(partmetfilename, "%03i.pnew.met", i); + partmetfilename = wxString:: Format("%03i.pnew.met", i); } else { - sprintf(partmetfilename, "%03i.part.met", i); + partmetfilename = wxString:: Format("%03i.part.met", i); } - fullname = new char[strlen(theApp.glob_prefs -> GetTempDir()) + strlen(partmetfilename) + MAX_PATH]; - sprintf(fullname, "%s/%s", theApp.glob_prefs -> GetTempDir(), partmetfilename); - char *buffer = nstrdup(partmetfilename); + fullname = new char[strlen(theApp.glob_prefs -> GetTempDir()) + partmetfilename.Len() + MAX_PATH]; + sprintf(fullname, "%s/%s", theApp.glob_prefs -> GetTempDir(), partmetfilename.GetData()); + char * buffer = nstrdup(partmetfilename.GetData()); buffer[strlen(buffer) - 4] = 0; - CTag *partnametag = new CTag(FT_PARTFILENAME, buffer); + CTag * partnametag = new CTag(FT_PARTFILENAME, buffer); delete[] buffer; taglist.Add(partnametag); - Gap_Struct *gap = new Gap_Struct; + Gap_Struct * gap = new Gap_Struct; gap -> start = 0; gap -> end = m_nFileSize - 1; gaplist.AddTail(gap); - char *partfull = nstrdup(fullname); + char * partfull = nstrdup(fullname); partfull[strlen(partfull) - 4] = 0; - printf("partfull=%s\n", partfull); - if (!m_hpartfile.Create(partfull, TRUE)) + if (m_hpartfile.Create(partfull, TRUE)) { - theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_CREATEPARTFILE)); - SetPartFileStatus(PS_ERROR); + Close(); + if (m_hpartfile.Open(partfull, CFile::read_write)) + { + if (newprefs01_opt[5]) + { + m_nHeaderLength = (m_nFileSize/ bsize + 1) * 8; + m_isDynamic |= 3; + unsigned char * pfdyn_header; + pfdyn_header = (unsigned char *) malloc(m_nHeaderLength); + for (int i = 0 ; i < m_nHeaderLength ; i++) + { + pfdyn_header[i] = 0; } - // jesh.. luotu. nyt se vaan pitää avata uudestaan read-writeen.. - m_hpartfile.Close(); - if (!m_hpartfile.Open(partfull, CFile:: read_write)) + m_hpartfile.Write(pfdyn_header, m_nHeaderLength); + free(pfdyn_header); + } + else { - theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_CREATEPARTFILE)); - SetPartFileStatus(PS_ERROR); + m_nHeaderLength = 0; + m_isDynamic = 0; } delete[] partfull; m_SrcpartFrequency.SetSize(GetPartCount()); @@ -291,60 +514,101 @@ } paused = false; SavePartFile(true); + } + else + { + theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_CREATEPARTFILE)); + SetPartFileStatus(PS_ERROR); + } + } + else + { + theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_CREATEPARTFILE)); + SetPartFileStatus(PS_ERROR); + } } -bool CPartFile:: LoadPartFile(char *in_directory, char *in_filename) +bool CPartFile::LoadPartFile(int type, char * in_directory, char * in_filename) { // Slugfiller: - CMap < uint16, uint16, Gap_Struct *, Gap_Struct *> gap_map; + if (type) + { + m_isDynamic |= 1; + m_nHeaderLength = (m_nFileSize/ bsize + 1) * 8; + } + else + { + m_isDynamic = 0; + m_nHeaderLength = 0; + } + CMap gap_map; transfered = 0; - partmetfilename = nstrdup(in_filename); + partmetfilename = wxString(nstrdup(in_filename)); directory = nstrdup(in_directory); - char *buffer = new char[strlen(directory) + strlen(partmetfilename) + 2]; - sprintf(buffer, "%s/%s", directory, partmetfilename); + char * buffer = new char[strlen(directory) + partmetfilename.Len() + 2]; + sprintf(buffer, "%s/%s", directory, partmetfilename.GetData()); fullname = buffer; - CSafeFile file; - { - // readfile data form part.met file - if (!file.Open(fullname, CFile:: read)) + CFile metFile; + if (metFile.Open(fullname, CFile::read)) { - theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_OPENMET), partmetfilename, m_pszFileName); - return false; - } + uint32 tagcount = 0; uint8 version = 0; - file.Read( &version, 1); - if (version != PARTFILE_VERSION) + metFile.Read( & version, 1); + switch (version) { - file.Close(); - theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_BADMETVERSION), partmetfilename, m_pszFileName); - return false; + case PARTFILE_SPLITTEDVERSION: + case PARTFILE_VERSION: + isnewstyle = (version == PARTFILE_SPLITTEDVERSION); + partmettype = isnewstyle? PMT_SPLITTED: PMT_DEFAULTOLD; + if (!isnewstyle) + { +printf("partfile_OLDstyle type=%u ",partmettype); + uint8 test[4]; + metFile.Seek(24, wxFromStart); + metFile.Read( & test[0], 1); + metFile.Read( & test[1], 1); + metFile.Read( & test[2], 1); + metFile.Read( & test[3], 1); + metFile.Seek(1, wxFromStart); + if (test[0] == 0 && test[1] == 0 && test[2] == 2 && test[3] == 1) + { + isnewstyle = true; + partmettype = PMT_NEWOLD; } - LoadDateFromFile( &file); - LoadHashsetFromFile( &file, false); - /* We need to forge some values here for later error - * detection to work. - */ - uint32 tagcount = 0; - uint32 j = 0; - try + LoadDateFromFile( & metFile); + LoadHashsetFromFile( & metFile, false); + } + else { - if (4 != file.Read( &tagcount, 4)) +printf("partfile_NEWstyle type=%u ",partmettype); + uint32 temp; + metFile.Read( & temp, 4); + if (temp == 0) { - tagcount = 0; - throw CInvalidPacket("short file reading tagcount"); + LoadHashsetFromFile(&metFile, false); } - for (j = 0 ; j < tagcount ; j++) + else { - try + uchar gethash[16]; + metFile.Seek(2, wxFromStart); + LoadDateFromFile( & metFile); + metFile.Read( & gethash, 16); + md4cpy(m_abyFileHash, gethash); + } + } + if (4 == metFile.Read( & tagcount, 4)) + { + uint32 j = 0; + for (j = 0 ; j < tagcount ; j++) { - CTag *newtag = new CTag( &file); + CTag * newtag = new CTag( & metFile); switch (newtag -> tag -> specialtag) { case FT_FILENAME: { if (newtag -> tag -> stringvalue == NULL) { - theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_METCORRUPT), partmetfilename, m_pszFileName); + theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_METCORRUPT), partmetfilename.GetData(), m_pszFileName); delete newtag; return false; } @@ -376,6 +640,12 @@ delete newtag; break; } + case FT_DYNAMIC: + { + m_isDynamic = newtag -> tag -> intvalue; + delete newtag; + break; + } case FT_OLDDLPRIORITY: case FT_DLPRIORITY: { @@ -418,8 +688,8 @@ (newtag -> tag -> tagname[0] == FT_GAPSTART || newtag -> tag -> tagname[0] == FT_GAPEND)) { - Gap_Struct *gap; - uint16 gapkey = atoi( &newtag -> tag -> tagname[1]); + Gap_Struct * gap; + uint16 gapkey = atoi( & newtag -> tag -> tagname[1]); if (!gap_map.Lookup(gapkey, gap)) { gap = new Gap_Struct; @@ -428,69 +698,56 @@ gap -> end = (uint32) - 1; } if (newtag -> tag -> tagname[0] == FT_GAPSTART) + { gap -> start = newtag -> tag -> intvalue; + } if (newtag -> tag -> tagname[0] == FT_GAPEND) + { gap -> end = newtag -> tag -> intvalue - 1; + } delete newtag; // End Changes by Slugfiller for better exception handling } else - taglist.Add(newtag); - } - } - } - catch(CStrangePacket) { + taglist.Add(newtag); } } } - catch(CInvalidPacket e) - { - /* - * When failing on the last tag, this might be - * due to a failure in xMule writing the file. - */ - if (!tagcount || (j != tagcount - 1)) - { - printf("failure reading part file - %s\n", e.what()); - file.Close(); - return false; - } - } - file.Close(); } // Now to flush the map into the list (Slugfiller) for (POSITION pos = gap_map.GetStartPosition() ; pos != NULL ;) { - Gap_Struct *gap; + Gap_Struct * gap; uint16 gapkey; gap_map.GetNextAssoc(pos, gapkey, gap); - if (gap -> start >= 0 &&gap -> end >= 0 &&gap -> start <= gap -> end) + if (gap -> start >= 0 && gap -> end >= 0 && gap -> start <= gap -> end) + { // All tags accounted for: gaplist.AddTail(gap); + } else + { // Some of the tags were missing: delete gap; } + } //check if this is a backup if (strcasecmp(strrchr(fullname, '.'), ".backup") == 0) { - char *shorten = strrchr(fullname, '.'); - *shorten = 0; - char *oldfullname = fullname; + char * shorten = strrchr(fullname, '.'); + * shorten = 0; + char * oldfullname = fullname; fullname = new char[strlen(fullname) + 1]; strcpy(fullname, oldfullname); delete[] oldfullname; } // open permanent handle - char *searchpath = nstrdup(fullname); + char * searchpath = nstrdup(fullname); searchpath[strlen(fullname) - 4] = 0; - if (!m_hpartfile.Open(searchpath, CFile:: read_write)) + if (m_hpartfile.Open(searchpath, CFile::read_write)) { - theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_FILEOPEN), fullname, m_pszFileName); - delete[] searchpath; - return false; - } + Seek(0); delete[] searchpath; searchpath = NULL; m_SrcpartFrequency.SetSize(GetPartCount()); @@ -509,7 +766,7 @@ hashsetneeded = false; for (int i = 0 ; i != hashlist.GetSize() ; i++) { - if (IsComplete(i *PARTSIZE, ((i + 1) *PARTSIZE) - 1)) + if (IsComplete(i * PARTSIZE, ((i + 1) * PARTSIZE) - 1)) { SetPartFileStatus(PS_READY); } @@ -521,27 +778,57 @@ return true; } struct stat statbuf; - fstat(m_hpartfile.fd(), &statbuf); + fstat(m_hpartfile.fd(), & statbuf); if ((time_t) date != (time_t) statbuf.st_mtime) { theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_REHASH), buffer, m_pszFileName); // rehash SetPartFileStatus(PS_WAITINGFORHASH); - char *partfilename = nstrdup(partmetfilename); + char * partfilename = nstrdup(partmetfilename.GetData()); partfilename[strlen(partfilename) - 4] = 0; - CAddFileThread:: AddFile(directory, partfilename, this); + CAddFileThread::AddFile(directory, partfilename, this); delete[] partfilename; } UpdateCompletedInfos(); if (completedsize > transfered) + { m_iGainDueToCompression = completedsize - transfered; + } else if(completedsize != transfered) + { m_iLostDueToCorruption = transfered - completedsize; + } return true; - return true; + } + else + { + theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_FILEOPEN), fullname, m_pszFileName); + delete[] searchpath; + } + } + else + { + tagcount = 0; + } + break; + default: + { + theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_BADMETVERSION), + partmetfilename.GetData(), m_pszFileName); + } + break; + } + metFile.Close(); + } + else + { + theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_OPENMET), partmetfilename.GetData(), + m_pszFileName); + } + return false; } -bool CPartFile:: SavePartFile(bool Initial) +bool CPartFile::SavePartFile(bool Initial) { switch (status) { @@ -551,26 +838,27 @@ } /* Don't write anything to disk if less than 5000 bytes of free space is left. */ wxLongLong total, free; - if (wxGetDiskSpace(theApp.glob_prefs -> GetTempDir(), &total, &free) && + if (wxGetDiskSpace(theApp.glob_prefs -> GetTempDir(), & total, & free) && free < 5000) { return false; } - FILE *file = 0; - char *searchpath = nstrdup(fullname); + FILE * file = 0; + char * searchpath = nstrdup(fullname); searchpath[strlen(fullname) - 4] = 0; - wxString fName =:: wxFindFirstFile(searchpath, wxFILE); + wxString fName =::wxFindFirstFile(searchpath, wxFILE); delete[] searchpath; searchpath = NULL; if (fName.IsEmpty()) { if (file) fclose(file); - theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_SAVEMET), GetResString(IDS_ERR_PART_FNF) .GetData(), partmetfilename, m_pszFileName); + theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_SAVEMET), + GetResString(IDS_ERR_PART_FNF) .GetData(), partmetfilename.GetData(), m_pszFileName); return false; } struct stat sbf; - stat(fName.GetData(), &sbf); + stat(fName.GetData(), & sbf); date = sbf.st_mtime; uint32 lsc = lastseencomplete; if (!Initial) @@ -583,20 +871,20 @@ throw GetResString(IDS_ERR_OPENMETFILE); } uint8 version = PARTFILE_VERSION; - fwrite( &version, 1, 1, file); - fwrite( &date, 4, 1, file); - fwrite( &m_abyFileHash, 16, 1, file); + fwrite( & version, 1, 1, file); + fwrite( & date, 4, 1, file); + fwrite( & m_abyFileHash, 16, 1, file); uint16 parts = hashlist.GetCount(); - fwrite( &parts, 2, 1, file); + fwrite( & parts, 2, 1, file); for (int x = 0 ; x != parts ; x++) fwrite(hashlist[x], 16, 1, file); - uint32 tagcount = taglist.GetCount() + 10 + (gaplist.GetCount() *2); - fwrite( &tagcount, 4, 1, file); + uint32 tagcount = taglist.GetCount() + 10 + (gaplist.GetCount() * 2); + fwrite( & tagcount, 4, 1, file); CTag(FT_FILENAME, m_pszFileName) .WriteTagToFile(file); CTag(FT_FILESIZE, m_nFileSize) .WriteTagToFile(file); CTag(FT_TRANSFERED, transfered) .WriteTagToFile(file); CTag(FT_STATUS, (paused) ? 1: 0) .WriteTagToFile(file); - CTag *prioritytag; + CTag * prioritytag; uint8 autoprio = PR_AUTO; if (this -> IsAutoDownPriority()) { @@ -618,10 +906,10 @@ } prioritytag -> WriteTagToFile(file); delete prioritytag; - CTag *lsctag = new CTag(FT_LASTSEENCOMPLETE, lsc); + CTag * lsctag = new CTag(FT_LASTSEENCOMPLETE, lsc); lsctag -> WriteTagToFile(file); delete lsctag; - CTag *ulprioritytag; + CTag * ulprioritytag; if (this -> IsAutoUpPriority()) { ulprioritytag = new CTag(FT_ULPRIORITY, autoprio); @@ -642,32 +930,28 @@ } ulprioritytag -> WriteTagToFile(file); delete ulprioritytag; - CTag *categorytab = new CTag(FT_CATEGORY, m_category); + CTag * categorytab = new CTag(FT_CATEGORY, m_category); categorytab -> WriteTagToFile(file); delete categorytab; for (uint32 j = 0 ; j != (uint32) taglist.GetCount() ; j++) taglist[j] -> WriteTagToFile(file); - char *namebuffer = new char[10]; - char *number = &namebuffer[1]; + char * namebuffer = new char[10]; + char * number = & namebuffer[1]; uint16 i_pos = 0; for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos)) { sprintf(number, "%d", i_pos); namebuffer[0] = FT_GAPSTART; - CTag *gapstarttag = new CTag(namebuffer, gaplist.GetAt(pos) -> start); + CTag * gapstarttag = new CTag(namebuffer, gaplist.GetAt(pos) -> start); gapstarttag -> WriteTagToFile(file); namebuffer[0] = FT_GAPEND; - CTag *gapendtag = new CTag(namebuffer, (gaplist.GetAt(pos) -> end) + 1); + CTag * gapendtag = new CTag(namebuffer, (gaplist.GetAt(pos) -> end) + 1); gapendtag -> WriteTagToFile(file); delete gapstarttag; delete gapendtag; i_pos++; } delete[] namebuffer; - if (ferror(file)) - { - throw CString("unexpected write error"); - } if (!Initial) { wxRemoveFile(wxString(fullname) + ".backup"); @@ -677,18 +961,18 @@ return true; } -void CPartFile:: PartFileHashFinished(CKnownFile *result) +void CPartFile::PartFileHashFinished(CKnownFile * result) { newdate = true; bool errorfound = false; for (uint32 i = 0 ; i != (uint32) hashlist.GetSize() ; i++) { - if (IsComplete(i *PARTSIZE, ((i + 1) *PARTSIZE) - 1)) + if (IsComplete(i * PARTSIZE, ((i + 1) * PARTSIZE) - 1)) { if (! (result -> GetPartHash(i) && !memcmp(result -> GetPartHash(i), this -> GetPartHash(i), 16))) { theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_FOUNDCORRUPTION), i + 1, m_pszFileName); - AddGap(i *PARTSIZE, ((((i + 1) *PARTSIZE) - 1) >= m_nFileSize) ? m_nFileSize - 1: ((i + 1) *PARTSIZE) - 1); + AddGap(i * PARTSIZE, ((((i + 1) * PARTSIZE) - 1) >= m_nFileSize) ? m_nFileSize - 1: ((i + 1) * PARTSIZE) - 1); errorfound = true; } } @@ -715,20 +999,20 @@ theApp.sharedfiles -> SafeAddKFile(this); } -void CPartFile:: AddGap(uint32 start, uint32 end) +void CPartFile::AddGap(uint32 start, uint32 end) { POSITION pos1, pos2; for (pos1 = gaplist.GetHeadPosition() ; (pos2 = pos1) != NULL ;) { - Gap_Struct *cur_gap = gaplist.GetNext(pos1); - if (cur_gap -> start >= start &&cur_gap -> end <= end) + Gap_Struct * cur_gap = gaplist.GetNext(pos1); + if (cur_gap -> start >= start && cur_gap -> end <= end) { // this gap is inside the new gap - delete gaplist.RemoveAt(pos2); delete cur_gap; continue; } - else if(cur_gap -> start >= start &&cur_gap -> start <= end) + else if(cur_gap -> start >= start && cur_gap -> start <= end) { // a part of this gap is in the new gap - extend limit and delete end = cur_gap -> end; @@ -736,7 +1020,7 @@ delete cur_gap; continue; } - else if(cur_gap -> end <= end &&cur_gap -> end >= start) + else if(cur_gap -> end <= end && cur_gap -> end >= start) { // a part of this gap is in the new gap - extend limit and delete start = cur_gap -> start; @@ -744,13 +1028,13 @@ delete cur_gap; continue; } - else if(start >= cur_gap -> start &&end <= cur_gap -> end) + else if(start >= cur_gap -> start && end <= cur_gap -> end) { // new gap is already inside this gap - return return; } } - Gap_Struct *new_gap = new Gap_Struct; + Gap_Struct * new_gap = new Gap_Struct; new_gap -> start = start; new_gap -> end = end; gaplist.AddTail(new_gap); @@ -759,16 +1043,16 @@ newdate = true; } -bool CPartFile:: IsComplete(uint32 start, uint32 end) +bool CPartFile::IsComplete(uint32 start, uint32 end) { if (end >= m_nFileSize) end = m_nFileSize - 1; for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos)) { - Gap_Struct *cur_gap = gaplist.GetAt(pos); - if ((cur_gap -> start >= start &&cur_gap -> end <= end) || (cur_gap -> start >= start - &&cur_gap -> start <= end) || (cur_gap -> end <= end &&cur_gap -> end >= start) - || (start >= cur_gap -> start &&end <= cur_gap -> end)) + Gap_Struct * cur_gap = gaplist.GetAt(pos); + if ((cur_gap -> start >= start && cur_gap -> end <= end) || (cur_gap -> start >= start + && cur_gap -> start <= end) || (cur_gap -> end <= end && cur_gap -> end >= start) + || (start >= cur_gap -> start && end <= cur_gap -> end)) { return false; } @@ -776,14 +1060,14 @@ return true; } -bool CPartFile:: IsPureGap(uint32 start, uint32 end) +bool CPartFile::IsPureGap(uint32 start, uint32 end) { if (end >= m_nFileSize) end = m_nFileSize - 1; for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos)) { - Gap_Struct *cur_gap = gaplist.GetAt(pos); - if (start >= cur_gap -> start &&end <= cur_gap -> end) + Gap_Struct * cur_gap = gaplist.GetAt(pos); + if (start >= cur_gap -> start && end <= cur_gap -> end) { return true; } @@ -791,7 +1075,7 @@ return false; } -bool CPartFile:: IsAlreadyRequested(uint32 start, uint32 end) +bool CPartFile::IsAlreadyRequested(uint32 start, uint32 end) { for (POSITION pos = requestedblocks_list.GetHeadPosition() ; pos != 0 ; requestedblocks_list.GetNext(pos)) { @@ -802,14 +1086,14 @@ return false; } -bool CPartFile:: GetNextEmptyBlockInPart(uint16 partNumber, Requested_Block_Struct *result) +bool CPartFile::GetNextEmptyBlockInPart(uint16 partNumber, Requested_Block_Struct * result) { - Gap_Struct *firstGap; - Gap_Struct *currentGap; + Gap_Struct * firstGap; + Gap_Struct * currentGap; uint32 end; uint32 blockLimit; // Find start of this part - uint32 partStart = (PARTSIZE *partNumber); + uint32 partStart = (PARTSIZE * partNumber); uint32 start = partStart; // What is the end limit of this block, i.e. can't go outside part (or filesize) uint32 partEnd = (PARTSIZE * (partNumber + 1)) - 1; @@ -873,30 +1157,30 @@ return false; } -void CPartFile:: FillGap(uint32 start, uint32 end) +void CPartFile::FillGap(uint32 start, uint32 end) { POSITION pos1, pos2; for (pos1 = gaplist.GetHeadPosition() ; (pos2 = pos1) != NULL ;) { - Gap_Struct *cur_gap = gaplist.GetNext(pos1); - if (cur_gap -> start >= start &&cur_gap -> end <= end) + Gap_Struct * cur_gap = gaplist.GetNext(pos1); + if (cur_gap -> start >= start && cur_gap -> end <= end) { // our part fills this gap completly gaplist.RemoveAt(pos2); delete cur_gap; continue; } - else if(cur_gap -> start >= start &&cur_gap -> start <= end) + else if(cur_gap -> start >= start && cur_gap -> start <= end) { // a part of this gap is in the part - set limit cur_gap -> start = end + 1; } - else if(cur_gap -> end <= end &&cur_gap -> end >= start) + else if(cur_gap -> end <= end && cur_gap -> end >= start) { // a part of this gap is in the part - set limit cur_gap -> end = start - 1; } - else if(start >= cur_gap -> start &&end <= cur_gap -> end) + else if(start >= cur_gap -> start && end <= cur_gap -> end) { uint32 buffer = cur_gap -> end; cur_gap -> end = start - 1; @@ -915,13 +1199,13 @@ //SavePartFile(); } -void CPartFile:: UpdateCompletedInfos() +void CPartFile::UpdateCompletedInfos() { uint32 allgaps = 0; for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ;) { POSITION prev = pos; - Gap_Struct *cur_gap = gaplist.GetNext(pos); + Gap_Struct * cur_gap = gaplist.GetNext(pos); if ((cur_gap -> end > m_nFileSize) || (cur_gap -> start >= m_nFileSize)) gaplist.RemoveAt(prev); else @@ -929,7 +1213,7 @@ } if (gaplist.GetCount() || requestedblocks_list.GetCount()) { - percentcompleted = (1.0f - (float) allgaps/m_nFileSize) *100; + percentcompleted = (1.0f - (float) allgaps/ m_nFileSize) * 100; completedsize = m_nFileSize - allgaps - 1; } else @@ -941,8 +1225,7 @@ #include typedef DWORD COLORREF; - -void CPartFile:: DrawStatusBar(wxMemoryDC *dc, wxRect rect, bool bFlat) +void CPartFile::DrawStatusBar(wxMemoryDC * dc, wxRect rect, bool bFlat) { COLORREF crProgress; COLORREF crHave; @@ -976,27 +1259,27 @@ // red gaps for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos)) { - Gap_Struct *cur_gap = gaplist.GetAt(pos); + Gap_Struct * cur_gap = gaplist.GetAt(pos); allgaps += cur_gap -> end - cur_gap -> start; bool gapdone = false; uint32 gapstart = cur_gap -> start; uint32 gapend = cur_gap -> end; for (uint32 i = 0 ; i != GetPartCount() ; i++) { - if (gapstart >= i *PARTSIZE &&gapstart <= (i + 1) *PARTSIZE) + if (gapstart >= i * PARTSIZE && gapstart <= (i + 1) * PARTSIZE) { // is in this part? - if (gapend <= (i + 1) *PARTSIZE) + if (gapend <= (i + 1) * PARTSIZE) gapdone = true; else { // and next part: - gapend = (i + 1) *PARTSIZE; + gapend = (i + 1) * PARTSIZE; } // paint COLORREF color; // frequency?: - if (m_SrcpartFrequency.GetCount() >= (int) i &&m_SrcpartFrequency[i]) + if (m_SrcpartFrequency.GetCount() >= (int) i && m_SrcpartFrequency[i]) color = RGB(0, (210 - (22 * (m_SrcpartFrequency[i] - 1)) < 0) ? 0: 210 - (22 * (m_SrcpartFrequency[i] - 1)) , 255); @@ -1017,7 +1300,7 @@ // yellow pending parts for (POSITION pos = requestedblocks_list.GetHeadPosition() ; pos != 0 ; requestedblocks_list.GetNext(pos)) { - Requested_Block_Struct *block = requestedblocks_list.GetAt(pos); + Requested_Block_Struct * block = requestedblocks_list.GetAt(pos); s_ChunkBar.FillRange(block -> StartOffset, block -> EndOffset, crPending); } s_ChunkBar.Draw(dc, rect.x, rect.y, bFlat); @@ -1030,13 +1313,13 @@ gaprect.left = rect.x; if (!bFlat) { - s_LoadBar.SetWidth((uint32)((float)((float)((m_nFileSize - ((allgaps == 0) ?1: allgaps)) - 1)) *blockpixel + .5f)); + s_LoadBar.SetWidth((uint32)((float)((float)((m_nFileSize - ((allgaps == 0) ? 1: allgaps)) - 1)) * blockpixel + .5f)); s_LoadBar.Fill(crProgress); s_LoadBar.Draw(dc, gaprect.left, gaprect.top, false); } else { - gaprect.right = rect.x + (uint32)((float)((float)((m_nFileSize - ((allgaps == 0) ?1: allgaps)) - 1)) *blockpixel + .5f); + gaprect.right = rect.x + (uint32)((float)((float)((m_nFileSize - ((allgaps == 0) ? 1: allgaps)) - 1)) * blockpixel + .5f); //wxBrush(crProgress));: dc -> SetBrush( * (wxTheBrushList -> FindOrCreateBrush(wxColour(crProgress), wxSOLID))); dc -> DrawRectangle(gaprect.left, gaprect.top, gaprect.right, gaprect.bottom); @@ -1051,7 +1334,7 @@ } if ((gaplist.GetCount() || requestedblocks_list.GetCount())) { - percentcompleted = ((1.0f - (float) allgaps/m_nFileSize)) *100; + percentcompleted = ((1.0f - (float) allgaps/ m_nFileSize)) * 100; completedsize = m_nFileSize - allgaps - 1; } else @@ -1061,27 +1344,27 @@ } } -void CPartFile:: WritePartStatus(CMemFile *file) +void CPartFile::WritePartStatus(CMemFile * file) { uint16 parts = hashlist.GetCount(); - file -> Write( &parts, 2); + file -> Write( & parts, 2); uint16 done = 0; while (done != parts) { uint8 towrite = 0; for (uint32 i = 0 ; i != 8 ; i++) { - if (IsComplete(done *PARTSIZE, ((done + 1) *PARTSIZE) - 1)) + if (IsComplete(done * PARTSIZE, ((done + 1) * PARTSIZE) - 1)) towrite |= (1 << i); done++; if (done == parts) break; } - file -> Write( &towrite, 1); + file -> Write( & towrite, 1); } } -int CPartFile:: GetValidSourcesCount() +int CPartFile::GetValidSourcesCount() { int counter = 0; POSITION pos1, pos2; @@ -1089,14 +1372,14 @@ for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;) { srclists[sl].GetNext(pos1); - CUpDownClient *cur_src = srclists[sl].GetAt(pos2); - if (cur_src -> GetDownloadState() != DS_ONQUEUE &&cur_src -> GetDownloadState() != DS_DOWNLOADING && + CUpDownClient * cur_src = srclists[sl].GetAt(pos2); + if (cur_src -> GetDownloadState() != DS_ONQUEUE && cur_src -> GetDownloadState() != DS_DOWNLOADING && cur_src -> GetDownloadState() != DS_NONEEDEDPARTS) counter++; } return counter; } -uint16 CPartFile:: GetNotCurrentSourcesCount() +uint16 CPartFile::GetNotCurrentSourcesCount() { uint16 counter = 0; POSITION pos1, pos2; @@ -1104,13 +1387,13 @@ for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;) { srclists[sl].GetNext(pos1); - CUpDownClient *cur_src = srclists[sl].GetAt(pos2); - if (cur_src -> GetDownloadState() != DS_ONQUEUE &&cur_src -> GetDownloadState() != DS_DOWNLOADING) counter++; + CUpDownClient * cur_src = srclists[sl].GetAt(pos2); + if (cur_src -> GetDownloadState() != DS_ONQUEUE && cur_src -> GetDownloadState() != DS_DOWNLOADING) counter++; } return counter; } -uint8 CPartFile:: GetStatus(bool ignorepause) +uint8 CPartFile::GetStatus(bool ignorepause) { if ((!paused) || status == PS_ERROR || ignorepause) return status; @@ -1118,11 +1401,11 @@ return PS_PAUSED; } -uint32 CPartFile:: Process(uint32 reducedownload) +uint32 CPartFile::Process(uint32 reducedownload) { //in percent uint16 old_trans; - DWORD dwCurTick =:: GetTickCount(); + DWORD dwCurTick =::GetTickCount(); // If buffer size exceeds limit, or if not written within time limit, flush data if ((m_nTotalBufferData > theApp.glob_prefs -> GetFileBufferSize())) { @@ -1135,12 +1418,12 @@ // check if we want new sources from server //uint16 test = theApp.glob_prefs->GetMaxSourcePerFileSoft(); if (((!lastsearchtime) || (dwCurTick - lastsearchtime) > SERVERREASKTIME) - &&theApp.serverconnect -> IsConnected() - &&theApp.glob_prefs -> GetMaxSourcePerFileSoft() > GetSourceCount() && !stopped) + && theApp.serverconnect -> IsConnected() + && theApp.glob_prefs -> GetMaxSourcePerFileSoft() > GetSourceCount() && !stopped) { //local server lastsearchtime = dwCurTick; - Packet *packet = new Packet(OP_GETSOURCES, 16); + Packet * packet = new Packet(OP_GETSOURCES, 16); memcpy(packet -> pBuffer, m_abyFileHash, 16); theApp.uploadqueue -> AddUpDataOverheadServer(packet -> size); theApp.serverconnect -> SendPacket(packet, true); @@ -1156,7 +1439,7 @@ for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;) { srclists[sl].GetNext(pos1); - CUpDownClient *cur_src = srclists[sl].GetAt(pos2); + CUpDownClient * cur_src = srclists[sl].GetAt(pos2); switch (cur_src -> GetDownloadState()) { case DS_DOWNLOADING: @@ -1164,11 +1447,11 @@ transferingsrc++; uint32 cur_datarate = cur_src -> CalculateDownloadRate(); datarate += cur_datarate; - if (reducedownload &&cur_src -> GetDownloadState() == DS_DOWNLOADING) + if (reducedownload && cur_src -> GetDownloadState() == DS_DOWNLOADING) { //(uint32)(((float)reducedownload/100)*cur_datarate)/10;: - uint32 limit = reducedownload *cur_datarate/1000; - if (limit < 1000 &&reducedownload == 200) + uint32 limit = reducedownload * cur_datarate/ 1000; + if (limit < 1000 && reducedownload == 200) limit += 1000; else if(limit < 1) limit = 1; @@ -1208,7 +1491,7 @@ break; } // doubled reasktime for no needed parts - save connections and traffic - if (! ((!cur_src -> GetLastAskedTime()) || (dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME *2)) + if (! ((!cur_src -> GetLastAskedTime()) || (dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME * 2)) break; } case DS_ONQUEUE: @@ -1225,9 +1508,10 @@ //Johnny-B - nothing more to do here (good eye!): break; } - if (theApp.serverconnect -> IsConnected() && ((!cur_src -> GetLastAskedTime()) || (dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME - 20000)) + if (((!cur_src -> GetLastAskedTime()) || (dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME - 20000)) { cur_src -> UDPReaskForDownload(); } + } case DS_CONNECTED: case DS_CONNECTING: if ((dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME) @@ -1257,7 +1541,7 @@ for (pos1 = this -> A4AFSourcesList.GetHeadPosition() ; (pos2 = pos1) != NULL ;) { this -> A4AFSourcesList.GetNext(pos1); - CUpDownClient *cur_source = this -> A4AFSourcesList.GetAt(pos2); + CUpDownClient * cur_source = this -> A4AFSourcesList.GetAt(pos2); if (! (cur_source -> GetDownloadState() == DS_DOWNLOADING)) { this -> A4AFSourcesList.RemoveAt(pos2); @@ -1267,11 +1551,11 @@ } } /* Sources droping engine. Auto drop allowed type of sources at interval. */ - if ((dwCurTick - m_LastSourceDropTime) > theApp.glob_prefs -> GetAutoDropTimer() *1000) + if ((dwCurTick - m_LastSourceDropTime) > theApp.glob_prefs -> GetAutoDropTimer() * 1000) { m_LastSourceDropTime = dwCurTick; /* If all three are enabled, use CleanUpSources() function, will save us some CPU. */ - if (theApp.glob_prefs -> DropNoNeededSources() &&theApp.glob_prefs -> DropFullQueueSources() &&theApp.glob_prefs -> DropHighQueueRankingSources()) + if (theApp.glob_prefs -> DropNoNeededSources() && theApp.glob_prefs -> DropFullQueueSources() && theApp.glob_prefs -> DropHighQueueRankingSources()) { CleanUpSources(); } @@ -1310,28 +1594,31 @@ return datarate; } -void CPartFile:: AddSources(CMemFile *sources, uint32 serverip, uint16 serverport) +void CPartFile::AddSources(CMemFile * sources, uint32 serverip, uint16 serverport) { if (stopped) return; uint8 count; uint8 debug_lowiddropped = 0; uint8 debug_possiblesources = 0; - sources -> Read( &count, 1); + sources -> Read( & count, 1); for (int i = 0 ; i != count ; i++) { uint32 userid; - sources -> Read( &userid, 4); + sources -> Read( & userid, 4); uint16 port; - sources -> Read( &port, 2); + sources -> Read( & port, 2); // check first if we are this source // MOD Note: Do not change this part - Merkur - if (theApp.serverconnect -> GetClientID() < 16777216 &&theApp.serverconnect -> IsConnected()) + if (theApp.serverconnect -> GetClientID() < 16777216 && theApp.serverconnect -> IsConnected()) { - if ((theApp.serverconnect -> GetClientID() == userid) &&inet_addr(theApp.serverconnect -> GetCurrentServer() -> GetFullIP()) == serverip) + if ((theApp.serverconnect -> GetClientID() == userid) && inet_addr(theApp.serverconnect -> GetCurrentServer() -> GetFullIP()) == serverip) { continue; } + } else if(theApp.serverconnect -> GetClientID() == userid) + { continue; + } else if(userid < 16777216 && !theApp.serverconnect -> IsLocalServer(serverip, serverport)) { debug_lowiddropped++; @@ -1341,14 +1628,14 @@ if (theApp.glob_prefs -> GetMaxSourcePerFile() > this -> GetSourceCount()) { debug_possiblesources++; - CUpDownClient *newsource = new CUpDownClient(port, userid, serverip, serverport, this); + CUpDownClient * newsource = new CUpDownClient(port, userid, serverip, serverport, this); theApp.downloadqueue -> CheckAndAddSource(this, newsource); } } theApp.xmuledlg -> AddDebugLogLine(false, "RCV: %i sources from server, %i low id dropped, %i possible sources File(%s)", count, debug_lowiddropped, debug_possiblesources, GetFileName()); } -void CPartFile:: NewSrcPartsInfo() +void CPartFile::NewSrcPartsInfo() { // Cache part count uint16 partcount = GetPartCount(); @@ -1362,7 +1649,7 @@ { m_SrcpartFrequency[i] = 0; } - CUpDownClient *cur_src; + CUpDownClient * cur_src; for (int sl = 0 ; sl < SOURCESSLOTS ;++sl) { if (!srclists[sl].IsEmpty()) @@ -1382,20 +1669,18 @@ UpdateDisplayedInfo(); } -bool CPartFile:: GetNextRequestedBlock(CUpDownClient *sender, Requested_Block_Struct **newblocks, uint16 *count) +bool CPartFile::GetNextRequestedBlock(CUpDownClient * sender, Requested_Block_Struct ** newblocks, uint16 * count) { - uint16 requestedCount = *count; + uint16 requestedCount = * count; uint16 newblockcount = 0; - uint8 *partsav = sender -> GetPartStatus(); - *count = 0; + uint8 * partsav = sender -> GetPartStatus(); + * count = 0; uint16 randomness; - CList < int, int > liGoodParts; - CList < int, int > liPossibleParts; + CList liGoodParts; + CList liPossibleParts; bool finished = false; while (!finished) { - // Need to empty lists to avoid infinite loop when file is smaller than 180k - // Otherwise it would keep looping to find 3 blocks, there is only one and it is requested liGoodParts.RemoveAll(); liPossibleParts.RemoveAll(); // Barry - Top priority should be to continue downloading from current blocks (if anything left to download) @@ -1411,11 +1696,11 @@ } } // Barry - Give priorty to end parts of archives and movies - if ((!foundPriorityPart) && (IsArchive() || IsMovie()) &&theApp.glob_prefs -> GetPreviewPrio()) + if ((!foundPriorityPart) && (IsArchive() || IsMovie()) && theApp.glob_prefs -> GetPreviewPrio()) { uint32 partCount = GetPartCount(); // First part - if (sender -> IsPartAvailable(0) &&GetNextEmptyBlockInPart(0, 0)) + if (sender -> IsPartAvailable(0) && GetNextEmptyBlockInPart(0, 0)) { liGoodParts.AddHead(0); foundPriorityPart = true; @@ -1423,7 +1708,7 @@ else if((partCount > 1)) { // Last part - if (sender -> IsPartAvailable(partCount - 1) &&GetNextEmptyBlockInPart(partCount - 1, 0)) + if (sender -> IsPartAvailable(partCount - 1) && GetNextEmptyBlockInPart(partCount - 1, 0)) { liGoodParts.AddHead(partCount - 1); foundPriorityPart = true; @@ -1433,22 +1718,22 @@ else if(partCount > 2) { // Second part - if (sender -> IsPartAvailable(1) &&GetNextEmptyBlockInPart(1, 0)) + if (sender -> IsPartAvailable(1) && GetNextEmptyBlockInPart(1, 0)) liGoodParts.AddHead(1); // Penultimate part - else if(sender -> IsPartAvailable(partCount - 2) &&GetNextEmptyBlockInPart(partCount - 2, 0)) + else if(sender -> IsPartAvailable(partCount - 2) && GetNextEmptyBlockInPart(partCount - 2, 0)) liGoodParts.AddHead(partCount - 2); } } } if (!foundPriorityPart) { - randomness = (uint16) ROUND(((float) rand() /RAND_MAX) * (GetPartCount() - 1)); + randomness = (uint16) ROUND(((float) rand() / RAND_MAX) * (GetPartCount() - 1)); for (uint16 i = 0 ; i != GetPartCount() ; i++) { if (sender -> IsPartAvailable(randomness)) { - if (partsav[randomness] && !IsComplete(randomness *PARTSIZE, ((randomness + 1) *PARTSIZE) - 1)) + if (partsav[randomness] && !IsComplete(randomness * PARTSIZE, ((randomness + 1) * PARTSIZE) - 1)) { /*if (IsCorruptedPart(randomness)){ if (GetNextEmptyBlockInPart(randomness,0)){ @@ -1457,7 +1742,7 @@ } } else */ - if (IsPureGap(randomness *PARTSIZE, ((randomness + 1) *PARTSIZE) - 1)) + if (IsPureGap(randomness * PARTSIZE, ((randomness + 1) * PARTSIZE) - 1)) { if (GetNextEmptyBlockInPart(randomness, 0)) liPossibleParts.AddHead(randomness); @@ -1472,11 +1757,11 @@ randomness = 0; } } - CList < int, int > *usedlist; + CList * usedlist; if (!liGoodParts.IsEmpty()) - usedlist = &liGoodParts; + usedlist = & liGoodParts; else if(!liPossibleParts.IsEmpty()) - usedlist = &liPossibleParts; + usedlist = & liPossibleParts; else { if (!newblockcount) @@ -1491,7 +1776,7 @@ for (POSITION pos = usedlist -> GetHeadPosition() ; pos != 0 ; usedlist -> GetNext(pos)) { if (m_SrcpartFrequency.GetCount() >= usedlist -> GetAt(pos) - &&m_SrcpartFrequency[usedlist -> GetAt(pos) ] < nRarest) + && m_SrcpartFrequency[usedlist -> GetAt(pos) ] < nRarest) { nRarest = m_SrcpartFrequency[usedlist -> GetAt(pos) ]; usedpart = usedlist -> GetAt(pos); @@ -1499,7 +1784,7 @@ } while (true) { - Requested_Block_Struct *block = new Requested_Block_Struct; + Requested_Block_Struct * block = new Requested_Block_Struct; if (GetNextEmptyBlockInPart(usedpart, block)) { requestedblocks_list.AddTail(block); @@ -1519,79 +1804,76 @@ } //wend: } - *count = newblockcount; + * count = newblockcount; return true; } -void CPartFile:: RemoveBlockFromList(uint32 start, uint32 end) +void CPartFile::RemoveBlockFromList(uint32 start, uint32 end) { POSITION pos1, pos2; for (pos1 = requestedblocks_list.GetHeadPosition() ; (pos2 = pos1) != NULL ;) { requestedblocks_list.GetNext(pos1); - if (requestedblocks_list.GetAt(pos2) -> StartOffset <= start &&requestedblocks_list.GetAt(pos2) -> EndOffset >= end) + if (requestedblocks_list.GetAt(pos2) -> StartOffset <= start && requestedblocks_list.GetAt(pos2) -> EndOffset >= end) requestedblocks_list.RemoveAt(pos2); } } -void CPartFile:: RemoveAllRequestedBlocks(void) +void CPartFile::RemoveAllRequestedBlocks(void) { requestedblocks_list.RemoveAll(); } #include pthread_attr_t pattr; - -void CPartFile:: CompleteFile(bool bIsHashingDone) +void CPartFile::CompleteFile(bool bIsHashingDone) { if (this -> srcarevisible) + { theApp.xmuledlg -> transferwnd -> downloadlistctrl -> HideSources(this); + } SetPartFileStatus(PS_COMPLETING); if (!bIsHashingDone) { datarate = 0; - char *partfileb = nstrdup(partmetfilename); - partfileb[strlen(partmetfilename) - 4] = 0; - CAddFileThread:: AddFile(theApp.glob_prefs -> GetTempDir(), partfileb, this); + char * partfileb = nstrdup(partmetfilename.GetData()); + partfileb[partmetfilename.Len() - 4] = 0; + CAddFileThread::AddFile(theApp.glob_prefs -> GetTempDir(), partfileb, this); delete[] partfileb; - return; } else { - StopFile(); - // guess I was wrong about not need to spaw a thread.. It is if the temp and incoming dirs are on different partitions/drives and the file is large...[oz] - // use pthreads + StopFile(0); pthread_t tid; - pthread_attr_init( &pattr); - pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_DETACHED); - pthread_create( &tid, &pattr, (void * ( *)(void *)) CompleteThreadProc, this); - } + pthread_attr_init( & pattr); + pthread_attr_setdetachstate( & pattr, PTHREAD_CREATE_DETACHED); + pthread_create( & tid, & pattr, (void * ( *)(void *)) CompleteThreadProc, this); theApp.xmuledlg -> transferwnd -> downloadlistctrl -> ShowFilesCount(); UpdateDisplayedInfo(true); + } } -UINT CPartFile:: CompleteThreadProc(CPartFile *pFile) +UINT CPartFile::CompleteThreadProc(CPartFile * pFile) { if (!pFile) + { return(UINT) - 1; + } pFile -> PerformFileComplete(); return 0; } // Lord KiRon - using threads for file completion -BOOL CPartFile:: PerformFileComplete() +BOOL CPartFile::PerformFileComplete() { - //CSingleLock(&m_FileCompleteMutex,TRUE); // will be unlocked on exit wxMutexLocker sLock(m_FileCompleteMutex); - char *partfilename = nstrdup(fullname); - // assumes ".met" at the end: + char * partfilename = nstrdup(fullname); partfilename[strlen(fullname) - 4] = 0; - char *newfilename = nstrdup(GetFileName()); + char * newfilename = nstrdup(GetFileName()); strcpy(newfilename, theApp.StripInvalidFilenameChars(newfilename)); - // ???: - char *newname = new char[strlen(newfilename) + strlen(theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath) + MAX_PATH *2]; - CString indir; - if (wxFileName:: DirExists(theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath)) + char * newname = new char[strlen(newfilename) + strlen(theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath) + MAX_PATH * 2]; + wxString indir; + if (wxFileName::DirExists(theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath)) { indir = theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath; sprintf(newname, "%s/%s", indir.GetData(), newfilename); @@ -1601,36 +1883,30 @@ indir = theApp.glob_prefs -> GetIncomingDir(); sprintf(newname, "%s/%s", indir.GetData(), newfilename); } - // add this file to the suspended uploads list CFileHash tmp_filehash(GetFileHash()); theApp.uploadqueue -> SuspendUpload(tmp_filehash); - FlushBuffer(); - // close permanent handle - m_hpartfile.Close(); bool renamed = false; - if (wxFileName:: FileExists(newname)) + if (wxFileName::FileExists(newname)) { renamed = true; int namecount = 0; size_t length = strlen(newfilename); - //the file extension - char *ext = strrchr(newfilename, '.'); + char * ext = strrchr(newfilename, '.'); if (ext == NULL) + { ext = newfilename + length; - //new end is the file name before extension: - char *last = ext; - //truncate file name: + } + char * last = ext; last[0] = 0; - //serch for matching ()s and check if it contains a number if ((ext != newfilename) && (strrchr(newfilename, ')') + 1 == last)) { - char *first = strrchr(newfilename, '('); + char * first = strrchr(newfilename, '('); if (first != NULL) { first++; bool found = true; - for (char *step = first ; step < last - 1 ; step++) - if ( *step < '0' || *step > '9') + for (char * step = first ; step < last - 1 ; step++) + if (step[0] < '0' || step[0] > '9') { found = false; break; @@ -1639,23 +1915,35 @@ { namecount = atoi(first); last = first - 1; - //truncate again: last[0] = 0; } } } - CString strTestName; + wxString strTestName; do { namecount++; strTestName.Format("%s/%s(%d).%s", theApp.glob_prefs -> GetIncomingDir(), newfilename, namecount, min(ext + 1, newfilename + length)); } - while (wxFileName:: FileExists(strTestName)); + while (wxFileName::FileExists(strTestName)); delete[] newname; newname = nstrdup(strTestName); } delete[] newfilename; + if (IsDynamic() > 1) + { + if (!Store(newname)) + { + return false; + } + FlushBuffer(); + Close(); + } + else + { + FlushBuffer(); + Close(); if (!wxRenameFile(partfilename, newname)) { if (!SafeCopyFile(partfilename, newname)) @@ -1677,13 +1965,14 @@ printf("info: could not remove original '%s' after creating backup\n", partfilename); } } + } if (!wxRemoveFile(fullname)) { wxMutexGuiEnter(); theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETEFAILED), fullname); wxMutexGuiLeave(); } - CString BAKName(fullname); + wxString BAKName(fullname); BAKName.Append(".BAK"); if (!wxRemoveFile(BAKName)) { @@ -1708,42 +1997,61 @@ theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_DOWNLOADRENAMED), (strrchr(newname, '/') ? strrchr(newname, '/') + 1: newname)); wxMutexGuiLeave(); } - // TODO: What the f*** if it is already known? theApp.knownfiles -> SafeAddKFile(this); - // remove the file from the suspended uploads list theApp.uploadqueue -> ResumeUpload(tmp_filehash); SetAutoUpPriority(false); theApp.downloadqueue -> RemoveFile(this); - //theApp.xmuledlg->transferwnd.downloadlistctrl.UpdateItem(this); wxMutexGuiEnter(); UpdateDisplayedInfo(); theApp.xmuledlg -> transferwnd -> downloadlistctrl -> ShowFilesCount(); wxMutexGuiLeave(); - //SHAddToRecentDocs(SHARD_PATH, fullname); // This is a real nasty call that takes ~110 ms on my 1.4 GHz Athlon and isn't really needed afai see...[ozon] - // Barry - Just in case - // transfered = m_nFileSize; wxMutexGuiEnter(); theApp.downloadqueue -> StartNextFile(); wxMutexGuiLeave(); return TRUE; } -void CPartFile:: RemoveAllSources(bool bTryToSwap) +void CPartFile::RemoveAllSources(int fx, bool bTryToSwap) { - //TODO transfer sources to other downloading files if possible + CUpDownClient * client; POSITION pos1, pos2; - for (int sl = 0 ; sl < SOURCESSLOTS ; sl++) if(!srclists[sl].IsEmpty()) + for (int sl = 0 ; sl < SOURCESSLOTS ; sl++) + { + if (!srclists[sl].IsEmpty()) + { for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;) { srclists[sl].GetNext(pos1); if (bTryToSwap) { - if (!srclists[sl].GetAt(pos2) -> SwapToAnotherFile()) - theApp.downloadqueue -> RemoveSource(srclists[sl].GetAt(pos2)); + client = srclists[sl].GetAt(pos2); + if (fx) + { + if (client -> GetDownloadState() != DS_DOWNLOADING) + { + (void) client -> SwapToAnotherFile(); + } } else - theApp.downloadqueue -> RemoveSource(srclists[sl].GetAt(pos2)); + { + if (!client -> SwapToAnotherFile()) + { + theApp.downloadqueue -> RemoveSource(client); + } + } + } + else + { + if (!fx) + { + theApp.downloadqueue -> RemoveSource(client); + } + } + } + } } + if (!fx) + { /* Razor 1a - Modif by MikaelB */ if (!this -> A4AFSourcesList.IsEmpty()) { @@ -1761,75 +2069,127 @@ } } /* End modif */ + } UpdateFileRatingCommentAvail(); } -void CPartFile:: DeleteFile() +void CPartFile::DeleteFile() { - // Barry - Need to tell any connected clients to stop sending the file - StopFile(); + StopFile(0); theApp.sharedfiles -> RemoveFile(this); theApp.downloadqueue -> RemoveFile(this); theApp.xmuledlg -> transferwnd -> downloadlistctrl -> RemoveFile(this); - m_hpartfile.Close(); + Close(); if (!wxRemoveFile(fullname)) theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETE), fullname); - char *partfilename = nstrdup(fullname); + char * partfilename = nstrdup(fullname); partfilename[strlen(fullname) - 4] = 0; if (!wxRemoveFile(partfilename)) theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETE), partfilename); - CString BAKName(fullname); + wxString BAKName(fullname); BAKName.Append(".BAK"); if (!wxRemoveFile(BAKName)) theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETE), BAKName.GetData()); delete[] partfilename; } -bool CPartFile:: HashSinglePart(uint16 partnumber) +void CPartFile::CreateHash(wxUint32 Length, unsigned char * Output) +{ + bool PaddingStarted = false; + wxUint32 Hash[4]; + Hash[0] = 0x67452301; + Hash[1] = 0xEFCDAB89; + Hash[2] = 0x98BADCFE; + Hash[3] = 0x10325476; + wxUint32 Required = Length; + unsigned char X[64 * 128]; + while (Required >= 64) + { + wxUint32 len = Required / 64; + if (len > sizeof(X) / (64 * sizeof(X[0]))) + { + len = sizeof(X) / (64 * sizeof(X[0])); + } + Read( & X, len * 64); + for (wxUint32 i = 0 ; i < len ; i++) + { + MD4Transform(Hash, (wxUint32 *)(X + i * 64)); + } + Required -= len * 64; + } + // bytes to read + Required = Length % 64; + if (Required) + { + Read( & X, Required); + } + // in byte scale 512 = 64, 448 = 56 + if (Required >= 56) + { + X[Required] = 0x80; + PaddingStarted = TRUE; + memset( & X[Required + 1], 0, 63 - Required); + MD4Transform(Hash, (wxUint32 *) X); + Required = 0; + } + if (!PaddingStarted) + { + X[Required++] = 0x80; + } + memset( & X[Required], 0, 64 - Required); + // add size (convert to bits) + wxUint32 Length2 = Length >> 29; + Length <<= 3; + memcpy( & X[56], & Length, 4); + memcpy( & X[60], & Length2, 4); + MD4Transform(Hash, (wxUint32 *) X); + memcpy(Output, Hash, 16); +} + +bool CPartFile::HashSinglePart(uint16 partnumber) { + bool retcode = true; if ((GetHashCount() <= partnumber) && (GetPartCount() > 1)) { theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_HASHERRORWARNING), GetFileName()); this -> hashsetneeded = true; - return true; } - else if(!GetPartHash(partnumber) &&GetPartCount() != 1) + else if(!GetPartHash(partnumber) && GetPartCount() != 1) { theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_INCOMPLETEHASH), GetFileName()); this -> hashsetneeded = true; - return true; } else { - uchar hashresult[16]; - m_hpartfile.Seek(PARTSIZE *partnumber); + unsigned char hashresult[16]; + Seek(PARTSIZE * partnumber); uint32 length = PARTSIZE; - if (PARTSIZE * (partnumber + 1) > m_hpartfile.Length()) - length = (m_hpartfile.Length() - (PARTSIZE *partnumber)); - CreateHashFromFile( &m_hpartfile, length, hashresult); + if (PARTSIZE * (partnumber + 1) > m_nFileSize) + { + length = (m_nFileSize - (PARTSIZE * partnumber)); + } + CreateHash(length, hashresult); if (GetPartCount() > 1) { if (memcmp(hashresult, GetPartHash(partnumber), 16)) - return false; - else - return true; + { + retcode = false; } - else + } + else if(memcmp(hashresult, m_abyFileHash, 16)) { - if (memcmp(hashresult, m_abyFileHash, 16)) - return false; - else - return true; + retcode = false; } } + return retcode; } -bool CPartFile:: IsCorruptedPart(uint16 partnumber) +bool CPartFile::IsCorruptedPart(uint16 partnumber) { return corrupted_list.Find(partnumber); } -bool CPartFile:: IsMovie() +bool CPartFile::IsMovie() { bool it_is; wxString extension = wxString(GetFileName()) .Right(5); @@ -1846,7 +2206,7 @@ return(it_is); } -bool CPartFile:: IsArchive() +bool CPartFile::IsArchive() { bool it_is; wxString extension = wxString(GetFileName()) .Right(4); @@ -1859,7 +2219,7 @@ return(it_is); } -bool CPartFile:: IsSound() +bool CPartFile::IsSound() { bool it_is; wxString extension = wxString(GetFileName()) .Right(4); @@ -1870,7 +2230,7 @@ return(it_is); } -bool CPartFile:: IsCDImage() +bool CPartFile::IsCDImage() { bool it_is; wxString extension = wxString(GetFileName()) .Right(4); @@ -1880,7 +2240,7 @@ return(it_is); } -bool CPartFile:: IsImage() +bool CPartFile::IsImage() { bool it_is; wxString extension = wxString(GetFileName()) .Right(5); @@ -1894,7 +2254,7 @@ return(it_is); } -bool CPartFile:: IsText() +bool CPartFile::IsText() { bool it_is; wxString extension = wxString(GetFileName()) .Right(5); @@ -1907,7 +2267,7 @@ return(it_is); } -void CPartFile:: SetDownPriority(uint8 np) +void CPartFile::SetDownPriority(uint8 np) { m_iDownPriority = np; theApp.downloadqueue -> SortByPriority(); @@ -1916,13 +2276,13 @@ SavePartFile(); } -void CPartFile:: StopFile() +void CPartFile::StopFile(int fx) { // Barry - Need to tell any connected clients to stop sending the file // Kry - Need to set it hereto get into SetPartFileStatus(status) correctly: stopped = true; PauseFile(); - RemoveAllSources(true); + RemoveAllSources(0, true); datarate = 0; transferingsrc = 0; FlushBuffer(); @@ -1930,10 +2290,10 @@ UpdateDisplayedInfo(true); } -void CPartFile:: PauseFile() +void CPartFile::PauseFile() { if (status == PS_COMPLETE || status == PS_COMPLETING) return; - Packet *packet = new Packet(OP_CANCELTRANSFER, 0); + Packet * packet = new Packet(OP_CANCELTRANSFER, 0); POSITION pos1, pos2; for (int sl = 0 ; sl < SOURCESSLOTS ; sl++) { @@ -1942,13 +2302,10 @@ for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;) { srclists[sl].GetNext(pos1); - CUpDownClient *cur_src = srclists[sl].GetAt(pos2); + CUpDownClient * cur_src = srclists[sl].GetAt(pos2); if (cur_src -> GetDownloadState() == DS_DOWNLOADING) { theApp.uploadqueue -> AddUpDataOverheadOther(packet -> size); -#if defined(__DEBUG__) - // printf("CPartFile::PauseFile OP_CANCELTRANSFER size\n", packet -> size); -#endif cur_src -> socket -> SendPacket(packet, false, true); cur_src -> SetDownloadState(DS_ONQUEUE); } @@ -1964,7 +2321,7 @@ SavePartFile(); } -void CPartFile:: ResumeFile() +void CPartFile::ResumeFile() { if (status == PS_COMPLETE || status == PS_COMPLETING) return; paused = false; @@ -1975,9 +2332,9 @@ UpdateDisplayedInfo(true); } -CString CPartFile:: getPartfileStatus() +wxString CPartFile::getPartfileStatus() { - CString mybuffer = ""; + wxString mybuffer = ""; if (GetTransferingSrcCount() > 0) mybuffer = GetResString(IDS_DOWNLOADING); else mybuffer = GetResString(IDS_WAITING); switch (GetStatus()) @@ -1992,6 +2349,9 @@ case PS_COMPLETE: mybuffer = GetResString(IDS_COMPLETE); break; + case PS_CONVERTING: + mybuffer = GetResString(IDS_CONVERTING); + break; case PS_PAUSED: mybuffer = GetResString(IDS_PAUSED); break; @@ -2006,7 +2366,7 @@ return mybuffer; } -int CPartFile:: getPartfileStatusRang() +int CPartFile::getPartfileStatusRang() { int tempstatus = 0; if (GetTransferingSrcCount() == 0) tempstatus = 1; @@ -2032,17 +2392,17 @@ return tempstatus; } -sint32 CPartFile:: getTimeRemaining() +sint32 CPartFile::getTimeRemaining() { if (GetDatarate() == 0) return - 1; return((GetFileSize() - GetCompletedSize()) / GetDatarate()); } -void CPartFile:: PreviewFile() +void CPartFile::PreviewFile() { wxString command; // If no player set in preferences, use mplayer. - if (theApp.glob_prefs -> GetVideoPlayer() == "") + if (theApp.glob_prefs -> GetVideoPlayer() =="") command.Append(wxT("mplayer")); else command.Append(theApp.glob_prefs -> GetVideoPlayer()); @@ -2055,12 +2415,12 @@ wxShell(command.c_str()); } -bool CPartFile:: PreviewAvailable() +bool CPartFile::PreviewAvailable() { - return(IsMovie() &&IsComplete(0, PARTSIZE)); + return(IsMovie() && IsComplete(0, PARTSIZE)); } -void CPartFile:: UpdateAvailablePartsCount() +void CPartFile::UpdateAvailablePartsCount() { uint8 availablecounter = 0; bool breakflag = false; @@ -2083,36 +2443,33 @@ } } } - if (iPartCount == availablecounter &&availablePartsCount < iPartCount) + if (iPartCount == availablecounter && availablePartsCount < iPartCount) //CTime::GetCurrentTime();: lastseencomplete = time(NULL); availablePartsCount = availablecounter; } -Packet *CPartFile:: CreateSrcInfoPacket(CUpDownClient *forClient) +Packet * CPartFile::CreateSrcInfoPacket(CUpDownClient * forClient) { -#if defined(__DEBUG__) - // printf("CPartFile:: CreateSrcInfoPacket\n"); -#endif int sl; for (sl = 0 ; sl < SOURCESSLOTS ; sl++) if(srclists[sl].IsEmpty()) return 0; CMemFile data; uint16 nCount = 0; data.Write(m_abyFileHash, 16); - data.Write( &nCount, 2); + data.Write( & nCount, 2); bool bNeeded; for (sl = 0 ; sl < SOURCESSLOTS ; sl++) if(!srclists[sl].IsEmpty()) for (POSITION pos = srclists[sl].GetHeadPosition() ; pos != 0 ; srclists[sl].GetNext(pos)) { bNeeded = false; - CUpDownClient *cur_src = srclists[sl].GetAt(pos); + CUpDownClient * cur_src = srclists[sl].GetAt(pos); if (cur_src -> HasLowID()) continue; // only send source which have needed parts for this client if possible - uint8 *srcstatus = cur_src -> GetPartStatus(); + uint8 * srcstatus = cur_src -> GetPartStatus(); if (srcstatus) { - uint8 *reqstatus = forClient -> GetPartStatus(); + uint8 * reqstatus = forClient -> GetPartStatus(); if (reqstatus) { // only send sources which have needed parts for this client @@ -2146,33 +2503,40 @@ uint16 nPort = cur_src -> GetUserPort(); uint32 dwServerIP = cur_src -> GetServerIP(); uint16 nServerPort = cur_src -> GetServerPort(); - data.Write( &dwID, 4); - data.Write( &nPort, 2); - data.Write( &dwServerIP, 4); - data.Write( &nServerPort, 2); + data.Write( & dwID, 4); + data.Write( & nPort, 2); + data.Write( & dwServerIP, 4); + data.Write( & nServerPort, 2); if (forClient -> GetSourceExchangeVersion() > 1) data.Write(cur_src -> GetUserHash(), 16); if (nCount > 500) break; } } - if (!nCount) - return 0; + if (nCount) + { data.Seek(16); - data.Write( &nCount, 2); - Packet *result = new Packet( &data, OP_EMULEPROT); + data.Write( & nCount, 2); + Packet * result = new Packet( & data, OP_EMULEPROT); result -> opcode = OP_ANSWERSOURCES; if (nCount > 28) + { result -> PackPacket(); + } theApp.xmuledlg -> AddDebugLogLine(false, "Send:Source User(%s) File(%s) Count(%i)", forClient -> GetUserName(), GetFileName(), nCount); return result; + } + else + { + return 0; + } } -void CPartFile:: AddClientSources(CMemFile *sources, uint8 sourceexchangeversion) +void CPartFile::AddClientSources(CMemFile * sources, uint8 sourceexchangeversion) { if (stopped) return; uint16 nCount; - sources -> Read( &nCount, 2); + sources -> Read( & nCount, 2); for (int i = 0 ; i != nCount ; i++) { uint32 dwID; @@ -2180,35 +2544,45 @@ uint32 dwServerIP; uint16 nServerPort; uchar achUserHash[16]; - sources -> Read( &dwID, 4); - sources -> Read( &nPort, 2); - sources -> Read( &dwServerIP, 4); - sources -> Read( &nServerPort, 2); + sources -> Read( & dwID, 4); + sources -> Read( & nPort, 2); + sources -> Read( & dwServerIP, 4); + sources -> Read( & nServerPort, 2); if (sourceexchangeversion > 1) + { sources -> Read(achUserHash, 16); + } // check first if we are this source - if (theApp.serverconnect -> GetClientID() < 16777216 &&theApp.serverconnect -> IsConnected()) + if (theApp.serverconnect -> GetClientID() < 16777216 && theApp.serverconnect -> IsConnected()) { - if ((theApp.serverconnect -> GetClientID() == dwID) &&theApp.serverconnect -> GetCurrentServer() -> GetIP() == dwServerIP) + if ((theApp.serverconnect -> GetClientID() == dwID) && theApp.serverconnect -> GetCurrentServer() -> GetIP() == dwServerIP) continue; } else if(theApp.serverconnect -> GetClientID() == dwID) + { continue; + } else if(dwID < 16777216) + { continue; + } if (theApp.glob_prefs -> GetMaxSourcePerFile() > this -> GetSourceCount()) { - CUpDownClient *newsource = new CUpDownClient(nPort, dwID, dwServerIP, nServerPort, this); + CUpDownClient * newsource = new CUpDownClient(nPort, dwID, dwServerIP, nServerPort, this); if (sourceexchangeversion > 1) + { newsource -> SetUserHash(achUserHash); + } theApp.downloadqueue -> CheckAndAddSource(this, newsource); } else - break; + { + i=nCount; + } } } -void CPartFile:: UpdateAutoDownPriority() +void CPartFile::UpdateAutoDownPriority() { if (!IsAutoDownPriority()) return; @@ -2222,7 +2596,7 @@ // making this function return a higher when more sources have the extended // protocol will force you to ask a larger variety of people for sources -int CPartFile:: GetCommonFilePenalty() +int CPartFile::GetCommonFilePenalty() { //TODO: implement, but never return less than MINCOMMONPENALTY! return MINCOMMONPENALTY; @@ -2242,31 +2616,27 @@ fill a gap. */ -uint32 CPartFile:: WriteToBuffer(uint32 transize, BYTE *data, uint32 start, uint32 end, Requested_Block_Struct *block) +uint32 CPartFile::WriteToBuffer(uint32 transize, BYTE * data, uint32 start, uint32 end, Requested_Block_Struct * block) { - // Increment transfered bytes counter for this file transfered += transize; - // This is needed a few times uint32 lenData = end - start + 1; if (lenData > transize) + { m_iGainDueToCompression += lenData - transize; - // Occasionally packets are duplicated, no point writing it twice + } if (IsComplete(start, end)) { theApp.xmuledlg -> AddDebugLogLine(false, "File '%s' has already been written from %ld to %ld\n", GetFileName(), start, end); return 0; } - // Create copy of data as new buffer - BYTE *buffer = new BYTE[lenData]; + BYTE * buffer = new BYTE[lenData]; memcpy(buffer, data, lenData); - // Create a new buffered queue entry - PartFileBufferedData *item = new PartFileBufferedData; + PartFileBufferedData * item = new PartFileBufferedData; item -> data = buffer; item -> start = start; item -> end = end; item -> block = block; - // Add to the queue in the correct position (most likely the end) - PartFileBufferedData *queueItem; + PartFileBufferedData * queueItem; bool added = false; POSITION pos = m_BufferedData_list.GetTailPosition(); while (pos != NULL) @@ -2280,36 +2650,37 @@ } } if (!added) + { m_BufferedData_list.AddHead(item); - // Increment buffer size marker + } m_nTotalBufferData += lenData; - // Mark this small section of the file as filled FillGap(item -> start, item -> end); - // Update the flushed mark on the requested block - // The loop here is unfortunate but necessary to detect deleted blocks. pos = requestedblocks_list.GetHeadPosition(); while (pos != NULL) { if (requestedblocks_list.GetNext(pos) == item -> block) + { item -> block -> transferred += lenData; } - if (gaplist.IsEmpty()) FlushBuffer(); - // Return the length of data written to the buffer + } + if (gaplist.IsEmpty()) + { + FlushBuffer(); + } return lenData; } -void CPartFile:: FlushBuffer(void) +void CPartFile::FlushBuffer(void) { m_nLastBufferFlushTime = GetTickCount(); - if (m_BufferedData_list.IsEmpty()) + if (!m_BufferedData_list.IsEmpty()) { - return; - } + int i; /* Madcat - Check if there is at least PARTSIZE amount of free disk space in temp dir before flushing. If not enough space, pause the file, add log line and abort flushing. */ wxLongLong total, free; - if (wxGetDiskSpace(theApp.glob_prefs -> GetTempDir(), &total, &free) && + if (wxGetDiskSpace(theApp.glob_prefs -> GetTempDir(), & total, & free) && free < PARTSIZE) { theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_OUT_OF_SPACE)); @@ -2317,44 +2688,29 @@ return; } uint32 partCount = GetPartCount(); - bool *changedPart = new bool[partCount]; - try - { + bool * changedPart = new bool[partCount]; // Remember which parts need to be checked at the end of the flush for (int partNumber = 0 ; (uint32) partNumber < partCount ; partNumber++) { changedPart[partNumber] = false; } // Ensure file is big enough to write data to (the last item will be the furthest from the start) - PartFileBufferedData *item = m_BufferedData_list.GetTail(); - if (m_hpartfile.Length() <= item -> end) - //m_hpartfile.SetLength(item->end + 1); - ftruncate(m_hpartfile.fd(), item -> end + 1); + PartFileBufferedData * item = m_BufferedData_list.GetTail(); // Loop through queue - for (int i = m_BufferedData_list.GetCount() ; i > 0 ; i--) + i = m_BufferedData_list.GetCount(); + while (i > 0) { - if (i < 1) - { - // Can this happen ? - // Well, if it did... abort then.: - return; - } - // Get top item item = m_BufferedData_list.GetHead(); - // This is needed a few times uint32 lenData = item -> end - item -> start + 1; - int curpart = item -> start/PARTSIZE; + int curpart = item -> start/ PARTSIZE; changedPart[curpart] = true; - // Go to the correct position in file and write block of data - m_hpartfile.Seek(item -> start); - m_hpartfile.Write(item -> data, lenData); - // Remove item from queue + Seek(item -> start); + Write(item -> data, lenData); m_BufferedData_list.RemoveHead(); - // Decrease buffer size m_nTotalBufferData -= lenData; - // Release memory used by this item delete [] item -> data; delete item; + i--; } // Flush to disk m_hpartfile.Flush(); @@ -2369,13 +2725,13 @@ continue; } // Is this 9MB part complete - if (IsComplete(PARTSIZE *partNumber, (PARTSIZE * (partNumber + 1)) - 1)) + if (IsComplete(PARTSIZE * partNumber, (PARTSIZE * (partNumber + 1)) - 1)) { // Is part corrupt if (!HashSinglePart(partNumber)) { theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_PARTCORRUPT), partNumber, GetFileName()); - AddGap(PARTSIZE *partNumber, (PARTSIZE *partNumber + partRange)); + AddGap(PARTSIZE * partNumber, (PARTSIZE * partNumber + partRange)); corrupted_list.AddTail(partNumber); // Reduce transfered amount by corrupt amount this -> m_iLostDueToCorruption += (partRange + 1); @@ -2390,14 +2746,14 @@ } } } - else if(IsCorruptedPart(partNumber) &&theApp.glob_prefs -> IsICHEnabled()) + else if(IsCorruptedPart(partNumber) && theApp.glob_prefs -> IsICHEnabled()) { // Try to recover with minimal loss if (HashSinglePart(partNumber)) { m_iTotalPacketsSavedDueToICH++; - FillGap(PARTSIZE *partNumber, (PARTSIZE *partNumber + partRange)); - RemoveBlockFromList(PARTSIZE *partNumber, (PARTSIZE *partNumber + partRange)); + FillGap(PARTSIZE * partNumber, (PARTSIZE * partNumber + partRange)); + RemoveBlockFromList(PARTSIZE * partNumber, (PARTSIZE * partNumber + partRange)); theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ICHWORKED), partNumber, GetFileName()); } } @@ -2408,27 +2764,19 @@ SavePartFile(); // Is this file finished? if (gaplist.IsEmpty()) - CompleteFile(false); - } - catch(...) { - theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_WRITEERROR), GetFileName(), GetResString(IDS_UNKNOWN) .GetData()); - SetPartFileStatus(PS_ERROR); - paused = true; - datarate = 0; - transferingsrc = 0; - //theApp.xmuledlg->transferwnd.downloadlistctrl.UpdateItem(this); - UpdateDisplayedInfo(); + CompleteFile(false); } delete[] changedPart; + } } // Barry - This will invert the gap list, up to caller to delete gaps when done // 'Gaps' returned are really the filled areas, and guaranteed to be in order -void CPartFile:: GetFilledList(CTypedPtrList < CPtrList, Gap_Struct *> *filled) +void CPartFile::GetFilledList(CTypedPtrList * filled) { - Gap_Struct *gap; - Gap_Struct *best; + Gap_Struct * gap; + Gap_Struct * best; POSITION pos; uint32 start = 0; uint32 bestEnd = 0; @@ -2469,9 +2817,10 @@ } } -void CPartFile:: UpdateFileRatingCommentAvail() +void CPartFile::UpdateFileRatingCommentAvail() { - if (!this) return; + if (this) + { bool prev = (hasComment || hasRating); hasComment = false; hasRating = false; @@ -2480,23 +2829,27 @@ for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;) { srclists[sl].GetNext(pos1); - CUpDownClient *cur_src = srclists[sl].GetAt(pos2); + CUpDownClient * cur_src = srclists[sl].GetAt(pos2); if (cur_src -> GetFileComment() .GetLength() > 0) hasComment = true; if (cur_src -> GetFileRate() > 0) hasRating = true; - if (hasComment &&hasRating) break; + if (hasComment && hasRating) break; } //theApp.xmuledlg->transferwnd.downloadlistctrl.UpdateItem(this);: - if (prev != (hasComment || hasRating)) UpdateDisplayedInfo(); + if (prev != (hasComment || hasRating)) + { + UpdateDisplayedInfo(); + } + } } -uint16 CPartFile:: GetSourceCount() +uint16 CPartFile::GetSourceCount() { uint16 count = 0; for (int i = 0 ; i < SOURCESSLOTS ; i++) count += srclists[i].GetCount(); return count; } -bool CPartFile:: HasBadRating() +bool CPartFile::HasBadRating() { if (!hasRating) return false; POSITION pos1, pos2; @@ -2504,49 +2857,49 @@ for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;) { srclists[sl].GetNext(pos1); - CUpDownClient *cur_src = srclists[sl].GetAt(pos2); + CUpDownClient * cur_src = srclists[sl].GetAt(pos2); if (cur_src -> GetFileRate() == 1) return true; } return false; } -void CPartFile:: UpdateDisplayedInfo(bool force) +void CPartFile::UpdateDisplayedInfo(bool force) { - DWORD curTick =:: GetTickCount(); - if (force || curTick - m_lastRefreshedDLDisplay > MINWAIT_BEFORE_DLDISPLAY_WINDOWUPDATE + (uint32)(rand() / (RAND_MAX/1000))) + DWORD curTick =::GetTickCount(); + if (force || curTick - m_lastRefreshedDLDisplay > MINWAIT_BEFORE_DLDISPLAY_WINDOWUPDATE + (uint32)(rand() / (RAND_MAX/ 1000))) { theApp.xmuledlg -> transferwnd -> downloadlistctrl -> UpdateItem(this); m_lastRefreshedDLDisplay = curTick; } } -time_t CPartFile:: GetLastChangeDatetime(bool forcecheck) +time_t CPartFile::GetLastChangeDatetime(bool forcecheck) { - if ((:: GetTickCount() - m_lastdatetimecheck) < 60000 && !forcecheck) return m_lastdatecheckvalue; - m_lastdatetimecheck =:: GetTickCount(); - if (!:: wxFileExists(m_hpartfile.GetFilePath())) m_lastdatecheckvalue = - 1; + if ((::GetTickCount() - m_lastdatetimecheck) < 60000 && !forcecheck) return m_lastdatecheckvalue; + m_lastdatetimecheck =::GetTickCount(); + if (!::wxFileExists(m_hpartfile.GetFilePath())) m_lastdatecheckvalue = - 1; else { //CFileStatus filestatus; struct stat filestatus; - fstat(m_hpartfile.fd(), &filestatus); + fstat(m_hpartfile.fd(), & filestatus); //m_hpartfile.GetStatus(filestatus); // this; "...returns m_attribute without high-order flags" indicates a known MFC bug, wonder how many unknown there are... :) m_lastdatecheckvalue = filestatus.st_mtime; } return m_lastdatecheckvalue; } -uint8 CPartFile:: GetCategory() +uint8 CPartFile::GetCategory() { if (m_category > theApp.glob_prefs -> GetCatCount() - 1) m_category = 0; return m_category; } -CString CPartFile:: GetDownloadFileInfo() +wxString CPartFile::GetDownloadFileInfo() { if (this == NULL) return ""; - CString sRet; - CString strHash = EncodeBase16(GetFileHash(), 16);; + wxString sRet; + wxString strHash = EncodeBase16(GetFileHash(), 16);; char lsc[50]; char complx[50]; char lastprogr[50]; @@ -2557,7 +2910,7 @@ } else { - strftime(lsc, sizeof(lsc), theApp.glob_prefs -> GetDateTimeFormat(), localtime((time_t *) &lastseencomplete)); + strftime(lsc, sizeof(lsc), theApp.glob_prefs -> GetDateTimeFormat(), localtime((time_t *) & lastseencomplete)); } if (GetFileDate() == 0) { @@ -2570,7 +2923,7 @@ float availability = 0; if (GetPartCount() != 0) { - availability = GetAvailablePartCount() *100 / GetPartCount(); + availability = GetAvailablePartCount() * 100 / GetPartCount(); } sRet.Format(GetResString(IDS_DL_FILENAME) + ": %s (%s %s)\n\n%s\n\n" + GetResString(IDS_FD_HASH) + " %s\n" @@ -2579,7 +2932,7 @@ GetFileName(), CastItoXBytes(GetFileSize()) .GetData(), GetResString(IDS_BYTES) .GetData(), (GetResString(IDS_STATUS) + ": " + getPartfileStatus()) .GetData(), strHash.GetData(), - GetPartMetFileName(), GetPartCount(), GetResString(IDS_AVAIL) .GetData(), + GetPartMetFileName() .GetData(), GetPartCount(), GetResString(IDS_AVAIL) .GetData(), GetAvailablePartCount(), availability, (int) GetPercentCompleted(), complx, GetTransferingSrcCount(), (GetResString(IDS_LASTSEENCOMPL) + " " + wxString(lsc)) .GetData(), @@ -2587,7 +2940,7 @@ return sRet; } -wxString CPartFile:: GetProgressString(uint16 size) +wxString CPartFile::GetProgressString(uint16 size) { //green: char crProgress = '0'; @@ -2611,35 +2964,35 @@ uint32 allgaps = 0; if (GetStatus() == PS_COMPLETE || GetStatus() == PS_COMPLETING) { - CharFillRange( &my_ChunkBar, 0, (float) m_nFileSize *unit, crProgress); + CharFillRange( & my_ChunkBar, 0, (float) m_nFileSize * unit, crProgress); } else { // red gaps for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos)) { - Gap_Struct *cur_gap = gaplist.GetAt(pos); + Gap_Struct * cur_gap = gaplist.GetAt(pos); allgaps += cur_gap -> end - cur_gap -> start; bool gapdone = false; uint32 gapstart = cur_gap -> start; uint32 gapend = cur_gap -> end; for (uint32 i = 0 ; i < GetPartCount() ; i++) { - if (gapstart >= i *PARTSIZE &&gapstart <= (i + 1) *PARTSIZE) + if (gapstart >= i * PARTSIZE && gapstart <= (i + 1) * PARTSIZE) { // is in this part? - if (gapend <= (i + 1) *PARTSIZE) + if (gapend <= (i + 1) * PARTSIZE) { gapdone = true; } else { // and next part: - gapend = (i + 1) *PARTSIZE; + gapend = (i + 1) * PARTSIZE; } // paint uint8 color; - if (m_SrcpartFrequency.GetCount() >= (int) i &&m_SrcpartFrequency[i]) + if (m_SrcpartFrequency.GetCount() >= (int) i && m_SrcpartFrequency[i]) { // frequency? color = crWaiting; @@ -2648,7 +3001,7 @@ { color = crMissing; } - CharFillRange( &my_ChunkBar, (float) gapstart *unit, (float) gapend *unit + 1, color); + CharFillRange( & my_ChunkBar, (float) gapstart * unit, (float) gapend * unit + 1, color); if (gapdone) { // finished? @@ -2666,13 +3019,13 @@ // yellow pending parts for (POSITION pos = requestedblocks_list.GetHeadPosition() ; pos != 0 ; requestedblocks_list.GetNext(pos)) { - Requested_Block_Struct *block = requestedblocks_list.GetAt(pos); - CharFillRange( &my_ChunkBar, (float)(block -> StartOffset + block -> transferred) *unit, (float) block -> EndOffset *unit, crPending); + Requested_Block_Struct * block = requestedblocks_list.GetAt(pos); + CharFillRange( & my_ChunkBar, (float)(block -> StartOffset + block -> transferred) * unit, (float) block -> EndOffset * unit, crPending); } return my_ChunkBar; } -void CPartFile:: CharFillRange(wxString *buffer, float start, float end, char color) +void CPartFile::CharFillRange(wxString * buffer, float start, float end, char color) { for (uint32 i = (uint32) start ; i <= (uint32) end ; i++) { @@ -2683,19 +3036,19 @@ /* Razor 1a - Modif by MikaelB RemoveNoNeededSources function */ -void CPartFile:: RemoveNoNeededSources() +void CPartFile::RemoveNoNeededSources() { POSITION position, temp_position; for (int slot = 0 ; slot < SOURCESSLOTS ; slot++) { - if (! srclists[slot].IsEmpty()) + if (!srclists[slot].IsEmpty()) { position = srclists[slot].GetHeadPosition(); while (position != NULL) { temp_position = position; srclists[slot].GetNext(position); - CUpDownClient *client = srclists[slot].GetAt(temp_position); + CUpDownClient * client = srclists[slot].GetAt(temp_position); if (client -> GetDownloadState() == DS_NONEEDEDPARTS) { /* If allowed, try to swap to other file. If swapping fails, remove from this one. */ @@ -2722,19 +3075,19 @@ /* Razor 1a - Modif by MikaelB RemoveFullQueueSources function */ -void CPartFile:: RemoveFullQueueSources() +void CPartFile::RemoveFullQueueSources() { POSITION position, temp_position; for (int slot = 0 ; slot < SOURCESSLOTS ; slot++) { - if (! srclists[slot].IsEmpty()) + if (!srclists[slot].IsEmpty()) { position = srclists[slot].GetHeadPosition(); while (position != NULL) { temp_position = position; srclists[slot].GetNext(position); - CUpDownClient *client = srclists[slot].GetAt(temp_position); + CUpDownClient * client = srclists[slot].GetAt(temp_position); if ((client -> GetDownloadState() == DS_ONQUEUE) && (client -> IsRemoteQueueFull())) { theApp.downloadqueue -> RemoveSourceFromPartFile(this, client, temp_position); @@ -2749,19 +3102,19 @@ /* Razor 1a - Modif by MikaelB RemoveHighQueueRatingSources function */ -void CPartFile:: RemoveHighQueueRatingSources() +void CPartFile::RemoveHighQueueRatingSources() { POSITION position, temp_position; for (int slot = 0 ; slot < SOURCESSLOTS ; slot++) { - if (! srclists[slot].IsEmpty()) + if (!srclists[slot].IsEmpty()) { position = srclists[slot].GetHeadPosition(); while (position != NULL) { temp_position = position; srclists[slot].GetNext(position); - CUpDownClient *client = srclists[slot].GetAt(temp_position); + CUpDownClient * client = srclists[slot].GetAt(temp_position); if ((client -> GetDownloadState() == DS_ONQUEUE) && (client -> GetRemoteQueueRank() > theApp.glob_prefs -> HighQueueRanking())) { theApp.downloadqueue -> RemoveSourceFromPartFile(this, client, temp_position); @@ -2776,22 +3129,22 @@ /* Razor 1a - Modif by MikaelB CleanUpSources function */ -void CPartFile:: CleanUpSources() +void CPartFile::CleanUpSources() { POSITION position, temp_position; for (int slot = 0 ; slot < SOURCESSLOTS ; slot++) { - if (! srclists[slot].IsEmpty()) + if (!srclists[slot].IsEmpty()) { position = srclists[slot].GetHeadPosition(); while (position != NULL) { temp_position = position; srclists[slot].GetNext(position); - CUpDownClient *client = srclists[slot].GetAt(temp_position); + CUpDownClient * client = srclists[slot].GetAt(temp_position); if (client -> GetDownloadState() == DS_NONEEDEDPARTS) { - if ((theApp.glob_prefs -> DropNoNeededSources()) && (! client -> SwapToAnotherFile())) + if ((theApp.glob_prefs -> DropNoNeededSources()) && (!client -> SwapToAnotherFile())) { theApp.downloadqueue -> RemoveSourceFromPartFile(this, client, temp_position); } @@ -2814,7 +3167,7 @@ /* Razor 1a - Modif by MikaelB AddDownloadingSource function */ -void CPartFile:: AddDownloadingSource(CUpDownClient *client) +void CPartFile::AddDownloadingSource(CUpDownClient * client) { POSITION position = m_downloadingSourcesList.Find(client); if (position == NULL) @@ -2828,7 +3181,7 @@ /* Razor 1a - Modif by MikaelB RemoveDownloadingSource function */ -void CPartFile:: RemoveDownloadingSource(CUpDownClient *client) +void CPartFile::RemoveDownloadingSource(CUpDownClient * client) { POSITION position = m_downloadingSourcesList.Find(client); if (position != NULL) @@ -2839,7 +3192,7 @@ /* End modif */ -void CPartFile:: SetPartFileStatus(uint8 newstatus) +void CPartFile::SetPartFileStatus(uint8 newstatus) { status = newstatus; if (theApp.glob_prefs -> GetAllcatType() > 1) diff -ur xmule/src/PartFile.h xmule.new/src/PartFile.h --- xmule/src/PartFile.h 2004-04-30 14:13:18.000000000 -0700 +++ xmule.new/src/PartFile.h 2004-06-16 13:18:42.625080000 -0700 @@ -33,11 +33,14 @@ #include "wx/treectrl.h" #include "otherfunctions.h" +#define PARTSIZE 9728000 + #define PS_READY 0 #define PS_EMPTY 1 #define PS_WAITINGFORHASH 2 #define PS_HASHING 3 #define PS_ERROR 4 +#define PS_CONVERTING 5 #define PS_UNKNOWN 6 #define PS_PAUSED 7 #define PS_COMPLETING 8 @@ -49,6 +52,12 @@ #define PR_HIGH 2 //* #define PR_VERYHIGH 3 #define PR_AUTO 5 + +#define PMT_UNKNOWN 0 +#define PMT_DEFAULTOLD 1 +#define PMT_SPLITTED 2 +#define PMT_NEWOLD 3 + #define SRV_PR_LOW 2 #define SRV_PR_NORMAL 0 #define SRV_PR_HIGH 1 @@ -71,19 +80,26 @@ public: CPartFile(); CPartFile(CSearchFile* searchresult); //used when downloading a new file - CPartFile(CString edonkeylink); + CPartFile(wxString edonkeylink); CPartFile(class CED2KFileLink* fileLink); void InitializeFromLink(CED2KFileLink* fileLink); virtual ~CPartFile(); void SetPartFileStatus(uint8 newstatus); - bool CreateFromFile(char* directory,char* filename) {return false;}// not supported in this class bool LoadFromFile(FILE* file) {return false;} bool WriteToFile(FILE* file) {return false;} bool IsPartFile() {return !(status == PS_COMPLETE);} uint32 Process(uint32 reducedownload); - bool LoadPartFile(char* in_directory, char* filename); //filename = *.part.met + bool LoadPartFile(int type,char* in_directory, char* filename); //filename = *.part.met bool SavePartFile(bool Initial=false); + void Close(); + void CreateHash(wxUint32 Length,unsigned char *Output); + void Duplicate(); + void Seek(unsigned long filepos); + long Read(void *buffer,long bytes); + bool Store(const wxString &newname); + long Write(void *buffer,long bytes); + unsigned long Length(); void PartFileHashFinished(CKnownFile* result); bool HashSinglePart(uint16 partnumber); // true = ok , false = corrupted @@ -101,7 +117,7 @@ void AddSources(CMemFile* sources,uint32 serverip, uint16 serverport); uint8 GetStatus(bool ignorepause = false); void NewSrcPartsInfo(); - char* GetPartMetFileName() {return partmetfilename;} + wxString GetPartMetFileName() {return partmetfilename;} uint32 GetTransfered() {return transfered;} char* GetFullName() {return fullname;} uint16 GetSourceCount(); @@ -118,11 +134,13 @@ bool IsText(); - CString CPartFile::getPartfileStatus(); //<<--9/21/02 + long m_nHeaderLength; + int m_nDynBloCount; + wxString CPartFile::getPartfileStatus(); //<<--9/21/02 sint32 CPartFile::getTimeRemaining(); //<<--9/21/02 time_t lastseencomplete; int getPartfileStatusRang(); - CString GetDownloadFileInfo(); + wxString GetDownloadFileInfo(); // Barry - Added as replacement for BlockReceived to buffer data before writing to disk uint32 WriteToBuffer(uint32 transize, BYTE *data, uint32 start, uint32 end, Requested_Block_Struct *block); @@ -138,11 +156,12 @@ void RemoveAllRequestedBlocks(void); void RemoveBlockFromList(uint32 start,uint32 end); - void RemoveAllSources(bool bTryToSwap); + void RemoveAllSources(int fx,bool bTryToSwap); void DeleteFile(); - void StopFile(); + void StopFile(int fx); void PauseFile(); void ResumeFile(); + void EnableConvert(uint8 targettype) { convertstate=targettype; } virtual Packet* CreateSrcInfoPacket(CUpDownClient* forClient); void AddClientSources(CMemFile* sources,uint8 sourceexchangeversion); @@ -162,9 +181,11 @@ bool IsStopped() {return stopped;} bool HasComment() {return hasComment;} bool HasRating() {return hasRating;} + int IsDynamic() {return m_isDynamic;} bool HasBadRating(); void SetHasComment(bool in) {hasComment=in;} void SetHasRating(bool in) {hasRating=in;} + void SetIsDynamic(int in) {m_isDynamic=in;} void UpdateFileRatingCommentAvail(); wxString GetProgressString(uint16 size); @@ -196,16 +217,21 @@ uint16 count; uint16 transferingsrc; uint32 completedsize; + uint32 m_ilength; uint64 m_iLostDueToCorruption; uint64 m_iGainDueToCompression; uint32 m_iTotalPacketsSavedDueToICH; uint32 datarate; char* fullname; - char* partmetfilename; + wxString partmetfilename; uint32 transfered; + bool isnewstyle; + uint8 partmettype; + uint8 convertstate; bool paused; bool stopped; bool m_DisableXS; // Flag for SourceSharing + int m_isDynamic; uint8 m_iDownPriority; bool m_bAutoDownPriority; uint8 status; @@ -226,6 +252,7 @@ static CBarShader s_ChunkBar; bool hasRating; bool hasComment; + long m_hfilepos; BOOL PerformFileComplete(); // Lord KiRon static UINT CompleteThreadProc(CPartFile* pFile); // Lord KiRon - Used as separate thread to complete file void CharFillRange(wxString* buffer,float start, float end, char color); diff -ur xmule/src/Preferences.cpp xmule.new/src/Preferences.cpp --- xmule/src/Preferences.cpp 2004-05-16 10:37:46.000000000 -0700 +++ xmule.new/src/Preferences.cpp 2004-06-16 13:18:42.633079000 -0700 @@ -41,6 +41,8 @@ #else # include "wintypes.h" # include "Preferences.h" +# include "FlowChart.h" +# include "NewFunctions.h" # include "opcodes.h" # include "otherfunctions.h" # include "ini2.h" @@ -71,42 +73,36 @@ #endif #ifdef __FreeBSD__ -extern long long atoll(char *s); +extern long long atoll(char * s); #endif /* __FreeBSD__ */ +extern wxString newprefs01_alpha[]; - -CPreferences:: CPreferences() +CPreferences::CPreferences() { // we need random numbers sometimes: srand((uint32) time(0)); // Define prefs prefs = new Preferences_Struct; memset(prefs, 0, sizeof(Preferences_Struct)); - prefsExt = new Preferences_Ext_Struct; - memset(prefsExt, 0, sizeof(Preferences_Ext_Struct)); // Use home directory to save preferences char buffer[490]; snprintf(buffer, 400, "%s/." PACKAGE_NAME, getenv("HOME")); mkdir(buffer, 0777); strncat(buffer, "/", 1); SetAppDir(nstrdup(buffer)); - // Create UserHash - CreateUserHash(); - md4cpy( &prefs->userhash, &userhash); - if (((int *) prefs -> userhash) [0] == 0 && ((int *) prefs -> userhash) [1] == 0 && ((int *) prefs -> userhash) [2] == 0 && ((int *) prefs -> userhash) [3] == 0) - { - CreateUserHash(); + if(newprefs01_opt[7]) { + newprefs01_alpha[7]=""; } - // Load Preferences + CreateUserHash(); + md4cpy( & prefs -> userhash, & userhash); Load(true); - // ??? prefs -> m_bUseSecureIdent = true; } -CPreferences:: ~CPreferences() +CPreferences::~ CPreferences() { - Category_Struct *delcat; + Category_Struct * delcat; while (!catMap.IsEmpty()) { delcat = catMap.GetAt(0); @@ -114,15 +110,14 @@ delete delcat; } delete prefs; - delete prefsExt; } - -void CPreferences:: SetStandartValues() +void CPreferences::SetStandartValues() { wxString buffer; + newprefs01_alpha[7]=""; CreateUserHash(); - md4cpy( &prefs -> userhash, &userhash); + md4cpy( & prefs -> userhash, & userhash); WINDOWPLACEMENT defaultWPM; defaultWPM.length = sizeof(WINDOWPLACEMENT); defaultWPM.rcNormalPosition.left = 10; @@ -134,16 +129,16 @@ prefs -> versioncheckLastAutomatic = 0; } -bool CPreferences:: Load(bool startup) +bool CPreferences::Load(bool startup) { bool error = false; - if(LoadPreferences()) + if (LoadPreferences()) { - if(startup) + if (startup) { //Can't find Preferences file, but in LoadPreferences() the standard was defined. Now we have to save it. SetStandartValues(); - if(Save(1)) + if (Save(1)) { error = true; } @@ -156,48 +151,48 @@ } if (startup) { - if(LoadCats()) + if (LoadCats()) { //Catfile don't exist, let's create one - if(Save(2)) + if (Save(2)) { error = true; } } - if(Load_Shared_Dirs()) - { - ; //Maybe the User has not shared dirs - } - if(Load_Adresses()) - { - ; //And also no Adresslist + if (Load_Shared_Dirs()) + {; + //Maybe the User has not shared dirs + } + if (Load_Adresses()) + {; + //And also no Adresslist } } return error; } -bool CPreferences:: Save(unsigned char selection_mask) +bool CPreferences::Save(unsigned char selection_mask) { bool error = false; - if (selection_mask &1) + if (selection_mask & 1) { SavePreferences(); } - if (selection_mask &2) + if (selection_mask & 2) { if (SaveCats()) { error = true; } } - if (selection_mask &4) + if (selection_mask & 4) { if (Save_Shared_Dirs()) { error = true; } } - if (selection_mask &8) + if (selection_mask & 8) { if (Save_Adresses()) { @@ -207,21 +202,57 @@ return error; } -void CPreferences:: CreateUserHash() +void CPreferences::CreateUserHash() { + if (newprefs01_alpha[7].Len() != 32) + { for (int i = 0 ; i != 8 ; i++) { uint16 random = rand(); - memcpy( &userhash[i*2], &random, 2); + memcpy( & userhash[i * 2], & random, 2); } // mark as emule client. that will be need in later version userhash[5] = 14; userhash[14] = 111; + newprefs01_alpha[7] =""; + for (int i = 0 ; i < 16 ; i++) + { + newprefs01_alpha[7] += wxString:: Format("%02x", (unsigned char) userhash[i]); + } + } + else + { + unsigned char c; + for (int i = 0 ; i < 32 ; i++) + { + c =((unsigned char*)(const char *) newprefs01_alpha[7])[i]; + if (c >= '0' && c <= '9') + { + c -= '0'; + } + else if(c >= 'a' && c <= 'f') + { + c -= 'a' - 10; + } + else if(c >= 'A' && c <= 'F') + { + c -='A' - 10; + } + if (i&1) + { + userhash[i>>1] = (userhash[i>>1] << 4) | c; + } + else + { + userhash[i>>1] = c; + } + } + } } -int CPreferences:: GetRecommendedMaxConnections() +int CPreferences::GetRecommendedMaxConnections() { - int iRealMax =:: GetMaxConnections(); + int iRealMax =::GetMaxConnections(); if (iRealMax == - 1 || iRealMax > 520) return 500; if (iRealMax < 20) @@ -231,7 +262,7 @@ return iRealMax - 20; } -WORD CPreferences:: GetWindowsVersion() +WORD CPreferences::GetWindowsVersion() { static bool bWinVerAlreadyDetected = false; if (!bWinVerAlreadyDetected) @@ -242,13 +273,12 @@ return m_wWinVer; } -uint16 CPreferences:: GetDefaultMaxConperFive() +uint16 CPreferences::GetDefaultMaxConperFive() { return MAXCONPER5SEC; } - -void CPreferences:: ResetStatsColor(int index) +void CPreferences::ResetStatsColor(int index) { switch (index) { @@ -272,21 +302,21 @@ break; case 9: prefs -> statcolors[9] = RGB(192, 0, 192); break; - case 10:prefs -> statcolors[10] = RGB(255, 255, 128); + case 10: prefs -> statcolors[10] = RGB(255, 255, 128); break; - case 11:prefs -> statcolors[11] = RGB(0, 0, 0); + case 11: prefs -> statcolors[11] = RGB(0, 0, 0); break; - case 12:prefs -> statcolors[12] = RGB(255, 255, 255); + case 12: prefs -> statcolors[12] = RGB(255, 255, 255); break; - default:break; + default: break; } } -void CPreferences:: SavePreferences(void) +void CPreferences::SavePreferences(void) { CString buffer; CString buffer2; - char *full_path = new char[strlen(getenv("HOME")) + 2]; + char * full_path = new char[strlen(getenv("HOME")) + 2]; sprintf(full_path, "%s/", getenv("HOME")); CIni ini(full_path, "eMule"); ini.WriteString("AppVersion", PACKAGE_STRING); @@ -468,18 +498,18 @@ ini.WriteInt("AutoDropTimer", prefs -> AutoDropTimer); } -bool CPreferences:: LoadPreferences(void) +bool CPreferences::LoadPreferences(void) { bool error = false; bool NoColor = true; CString buffer2; char buffer[200]; //Open File for Test - char *full_path = new char[strlen(getenv("HOME")) + 2]; + char * full_path = new char[strlen(getenv("HOME")) + 2]; sprintf(full_path, "%s/", getenv("HOME")); - char *test_file = new char[strlen(full_path) + 7]; + char * test_file = new char[strlen(full_path) + 7]; sprintf(test_file, "%s.eMule", full_path); - FILE *testfile = fopen(test_file, "r"); + FILE * testfile = fopen(test_file, "r"); if (!testfile) { error = true; @@ -680,13 +710,13 @@ return error; } -bool CPreferences:: Load_Adresses(void) +bool CPreferences::Load_Adresses(void) { //serverlist adresses bool error = false; - char *full_path = new char[strlen(GetAppDir()) + 13]; + char * full_path = new char[strlen(GetAppDir()) + 13]; sprintf(full_path, "%sadresses.dat", GetAppDir()); - FILE *sdirfile = fopen(full_path, "r"); + FILE * sdirfile = fopen(full_path, "r"); if (sdirfile) { char buffer[MAX_PATH]; @@ -694,8 +724,8 @@ { memset(buffer, 0, sizeof(buffer)); fgets(buffer, sizeof(buffer) - 1, sdirfile); - char *ptr = strchr(buffer, '\n'); - if (ptr) *ptr = 0; + char * ptr = strchr(buffer, '\n'); + if (ptr) * ptr = 0; if (strlen(buffer) > 1) adresses_list.Append(new CString(buffer)); } @@ -708,19 +738,19 @@ return error; } -bool CPreferences:: Save_Adresses(void) +bool CPreferences::Save_Adresses(void) { - bool error = false; - ; // I am to lazy atm :) + bool error = false;; + // I am to lazy atm :) return error; } -bool CPreferences:: Load_Shared_Dirs(void) +bool CPreferences::Load_Shared_Dirs(void) { bool error; - char *full_path = new char[strlen(GetAppDir()) + 14]; + char * full_path = new char[strlen(GetAppDir()) + 14]; sprintf(full_path, "%sshareddir.dat", GetAppDir()); - FILE *sdirfile = fopen(full_path, "r"); + FILE * sdirfile = fopen(full_path, "r"); if (sdirfile) { char buffer[MAX_PATH]; @@ -728,8 +758,8 @@ { memset(buffer, 0, sizeof(buffer)); fgets(buffer, sizeof(buffer) - 1, sdirfile); - char *ptr = strchr(buffer, '\n'); - if (ptr) *ptr = 0; + char * ptr = strchr(buffer, '\n'); + if (ptr) * ptr = 0; if (strlen(buffer) > 1) shareddir_list.Add(buffer); } @@ -742,12 +772,12 @@ return error; } -bool CPreferences:: Save_Shared_Dirs(void) +bool CPreferences::Save_Shared_Dirs(void) { bool error = false; - char *full_path = new char[strlen(GetAppDir()) + 14]; + char * full_path = new char[strlen(GetAppDir()) + 14]; sprintf(full_path, "%sshareddir.dat", GetAppDir()); - FILE *sdirfile = fopen(full_path, "w"); + FILE * sdirfile = fopen(full_path, "w"); if (sdirfile) { for (int i = 0 ; i < shareddir_list.GetCount() ; i++) @@ -763,11 +793,10 @@ return error; } - -bool CPreferences:: SaveCats(void) +bool CPreferences::SaveCats(void) { bool error = false; - FILE *category_fd; + FILE * category_fd; wxString catinif, buffer; catinif.Printf("%sCategory.dat", GetAppDir()); if (GetCatCount() > 0) @@ -778,11 +807,11 @@ fprintf(category_fd, "%d ", catMap.GetCount() - 1); for (int ix = 1 ; ix < catMap.GetCount() ; ix++) { - fprintf(category_fd,"%s\n",catMap.GetAt(ix) -> title); - fprintf(category_fd,"%s\n",catMap.GetAt(ix) -> incomingpath); - fprintf(category_fd,"%s\n",catMap.GetAt(ix) -> comment); - fprintf(category_fd,"0x%lx\n", catMap.GetAt(ix)->color); - fprintf(category_fd,"%.3u\n", catMap.GetAt(ix)->prio + 1); + fprintf(category_fd, "%s\n", catMap.GetAt(ix) -> title); + fprintf(category_fd, "%s\n", catMap.GetAt(ix) -> incomingpath); + fprintf(category_fd, "%s\n", catMap.GetAt(ix) -> comment); + fprintf(category_fd, "0x%lx\n", catMap.GetAt(ix) -> color); + fprintf(category_fd, "%.3u\n", catMap.GetAt(ix) -> prio + 1); } fclose(category_fd); } @@ -794,19 +823,19 @@ return error; } -bool CPreferences:: LoadCats(void) +bool CPreferences::LoadCats(void) { bool error = false; int max; wxString catinif; char buffer[2051]; - char *dummy; - FILE *category_fd; + char * dummy; + FILE * category_fd; // default cat - Category_Struct *newcat = new Category_Struct; - sprintf(newcat->title, ""); - sprintf(newcat->incomingpath, ""); - sprintf(newcat->comment, ""); + Category_Struct * newcat = new Category_Struct; + sprintf(newcat -> title, ""); + sprintf(newcat -> incomingpath, ""); + sprintf(newcat -> comment, ""); newcat -> prio = 0; newcat -> color = 0; AddCat(newcat); @@ -815,25 +844,25 @@ category_fd = fopen(catinif, "r"); if (category_fd != NULL) { - fscanf(category_fd, "%d ", &max); + fscanf(category_fd, "%d ", & max); for (int i = 1 ; i <= max ; i++) { - Category_Struct *newcat = new Category_Struct; + Category_Struct * newcat = new Category_Struct; fgets(buffer, 66, category_fd); - sprintf(newcat->title, ""); - strncat(newcat->title, buffer, strlen(buffer) - 1); + sprintf(newcat -> title, ""); + strncat(newcat -> title, buffer, strlen(buffer) - 1); fgets(buffer, 2050, category_fd); - sprintf(newcat->incomingpath, ""); - strncat(newcat->incomingpath, buffer, strlen(buffer) - 1); + sprintf(newcat -> incomingpath, ""); + strncat(newcat -> incomingpath, buffer, strlen(buffer) - 1); fgets(buffer, 258, category_fd); - sprintf(newcat->comment, ""); - strncat(newcat->comment, buffer, strlen(buffer) - 1); + sprintf(newcat -> comment, ""); + strncat(newcat -> comment, buffer, strlen(buffer) - 1); fgets(buffer, 15, category_fd); - newcat->color = (uint32)strtoul(buffer, &dummy, 0); + newcat -> color = (uint32) strtoul(buffer, & dummy, 0); fgets(buffer, 5, category_fd); - newcat->prio = (uint8) atoi(buffer) - 1; + newcat -> prio = (uint8) atoi(buffer) - 1; AddCat(newcat); - if (!wxFileName:: DirExists(newcat -> incomingpath)) + if (!wxFileName::DirExists(newcat -> incomingpath)) { mkdir(newcat -> incomingpath, 0777); } @@ -847,20 +876,19 @@ return error; } -void CPreferences:: RemoveCat(int index) +void CPreferences::RemoveCat(int index) { - if (index >= 0 &&index < catMap.GetCount()) + if (index >= 0 && index < catMap.GetCount()) { - Category_Struct *delcat; + Category_Struct * delcat; delcat = catMap.GetAt(index); catMap.RemoveAt(index); delete delcat; } } -int CPreferences:: GetColumnSortItem(Table t) const +int CPreferences::GetColumnSortItem(Table t) const { - switch (t) { case tableDownload: @@ -881,7 +909,7 @@ return 0; } -bool CPreferences:: GetColumnSortAscending(Table t) const +bool CPreferences::GetColumnSortAscending(Table t) const { switch (t) { @@ -901,10 +929,9 @@ return prefs -> tableSortAscendingClientList; } return true; - } -void CPreferences:: SetColumnSortItem(Table t, int sortItem) +void CPreferences::SetColumnSortItem(Table t, int sortItem) { switch (t) { @@ -932,7 +959,7 @@ } } -void CPreferences:: SetColumnSortAscending(Table t, bool sortAscending) +void CPreferences::SetColumnSortAscending(Table t, bool sortAscending) { switch (t) { @@ -960,7 +987,7 @@ } } -int CPreferences:: GetColumnWidth(Table t, int index) const +int CPreferences::GetColumnWidth(Table t, int index) const { switch (t) { @@ -980,10 +1007,9 @@ return prefs -> clientListColumnWidths[index]; } return 0; - } -void CPreferences:: SetColumnWidth(Table t, int index, int width) +void CPreferences::SetColumnWidth(Table t, int index, int width) { switch (t) { @@ -1011,7 +1037,7 @@ } } -BOOL CPreferences:: GetColumnHidden(Table t, int index) const +BOOL CPreferences::GetColumnHidden(Table t, int index) const { switch (t) { @@ -1033,7 +1059,7 @@ return FALSE; } -void CPreferences:: SetColumnHidden(Table t, int index, BOOL bHidden) +void CPreferences::SetColumnHidden(Table t, int index, BOOL bHidden) { switch (t) { @@ -1061,7 +1087,7 @@ } } -int CPreferences:: GetColumnOrder(Table t, int index) const +int CPreferences::GetColumnOrder(Table t, int index) const { switch (t) { @@ -1083,7 +1109,7 @@ return 0; } -void CPreferences:: SetColumnOrder(Table t, INT *piOrder) +void CPreferences::SetColumnOrder(Table t, INT * piOrder) { switch (t) { diff -ur xmule/src/Preferences.h xmule.new/src/Preferences.h --- xmule/src/Preferences.h 2004-05-16 09:49:41.000000000 -0700 +++ xmule.new/src/Preferences.h 2004-06-16 13:18:42.640078000 -0700 @@ -42,17 +42,6 @@ #define DEFAULT_COL_SIZE 65535 -// DO NOT EDIT VALUES like making a uint16 to uint32, or insert any value. ONLY append new vars -#pragma pack(1) -struct Preferences_Ext_Struct -{ - int8 version; - uchar userhash[16]; - WINDOWPLACEMENT EmuleWindowPlacement; -}; - -#pragma pack() - // deadlake PROXYSUPPORT struct ProxySettings { @@ -1388,7 +1377,6 @@ private: char appdir[MAX_PATH]; Preferences_Struct *prefs; - Preferences_Ext_Struct *prefsExt; char userhash[16]; WORD m_wWinVer; CArray < Category_Struct *, Category_Struct *> catMap; diff -ur xmule/src/SearchDlg.cpp xmule.new/src/SearchDlg.cpp --- xmule/src/SearchDlg.cpp 2004-05-16 09:42:25.000000000 -0700 +++ xmule.new/src/SearchDlg.cpp 2004-06-16 13:18:42.650076000 -0700 @@ -1839,7 +1839,9 @@ glspacket -> opcode = OP_GLOBSEARCHREQ; #endif } +#if defined(__DEBUG__) printf("SendUDPPacket for UDPsearch to %s:%d\n", toask -> GetAddress(), toask -> GetPort()); +#endif #ifdef __XMULE2__ theApp.serverconnect -> SendServerUDPPacket(glspacket, toask, false); #else diff -ur xmule/src/SharedFileList.cpp xmule.new/src/SharedFileList.cpp --- xmule/src/SharedFileList.cpp 2004-04-30 14:13:18.000000000 -0700 +++ xmule.new/src/SharedFileList.cpp 2004-06-16 13:18:42.655076000 -0700 @@ -333,55 +333,6 @@ return - 10; } -#if 0 -CAddFileThread:: CAddFileThread(): wxThread(wxTHREAD_DETACHED) -{ -} - -wxThread:: ExitCode CAddFileThread:: Entry() -{ - while (1) - { - g_lockWaitingForHashList.Lock(); - if (g_endWaitingForHashList) - { - g_endedWaitingForHashList.Signal(); - g_lockWaitingForHashList.Unlock(); - return 0; - } - if (g_sWaitingForHashList.IsEmpty()) - { - // Unlocks g_lockWaitingForHashList: - g_runWaitingForHashList.Wait(); - g_lockWaitingForHashList.Unlock(); - continue; - } - UnknownFile_Struct *hashfile = g_sWaitingForHashList.RemoveHead(); - g_lockWaitingForHashList.Unlock(); - CKnownFile *newrecord = new CKnownFile(); - printf("Sharing %s/%s\n", hashfile -> directory, hashfile -> name); - newrecord -> CreateFromFile(hashfile -> directory, hashfile -> name); - g_lockWaitingForHashList.Lock(); - if (g_endWaitingForHashList) - { - g_endedWaitingForHashList.Signal(); - g_lockWaitingForHashList.Unlock(); - return 0; - } - // TODO: Possible race condition between unlocking and wxPostEvent. - g_lockWaitingForHashList.Unlock(); - wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, TM_FINISHEDHASHING); - evt.SetClientData(newrecord); - evt.SetInt((int) hashfile -> partfile_Owner); - wxPostEvent(theApp.xmuledlg, evt); - free(hashfile -> name); - free(hashfile -> directory); - delete hashfile; - } -} - -#endif - void CSharedFileList:: UpdateItem(CKnownFile *toupdate) { output -> UpdateItem(toupdate); diff -ur xmule/src/TransferWnd.cpp xmule.new/src/TransferWnd.cpp --- xmule/src/TransferWnd.cpp 2004-05-04 10:10:15.000000000 -0700 +++ xmule.new/src/TransferWnd.cpp 2004-06-16 13:18:42.662075000 -0700 @@ -87,12 +87,6 @@ { } -#if 0 -BEGIN_MESSAGE_MAP(CTransferWnd, CResizableDialog) -ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipNotify) -END_MESSAGE_MAP() -#endif - BOOL CTransferWnd:: OnInitDialog() { m_dlTab = (CMuleNotebook *) FindWindowById(ID_CATEGORIES); @@ -109,44 +103,6 @@ // but they will be accepted in SetPageText().. so let's use this as a countermeasure m_dlTab -> SetPageText(ix, tmpstrstr); } -#if 0 - CResizableDialog:: OnInitDialog(); - Localize(); - windowtransferstate = false; - uploadlistctrl.Init(); - downloadlistctrl.Init(); - queuelistctrl.Init(); - ((CStatic *) GetDlgItem(IDC_DOWNLOAD_ICO)) -> SetIcon((HICON):: LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_DIRECTDOWNLOAD), IMAGE_ICON, 16, 16, 0)); - ((CStatic *) GetDlgItem(IDC_UPLOAD_ICO)) -> SetIcon((HICON):: LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_UPLOAD), IMAGE_ICON, 16, 16, 0)); - AddAnchor(IDC_DOWNLOADLIST, TOP_LEFT, CSize(100, theApp.glob_prefs -> GetSplitterbarPosition())); - AddAnchor(IDC_UPLOADLIST, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT); - AddAnchor(IDC_QUEUELIST, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT); - AddAnchor(IDC_UPLOAD_TEXT, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT); - AddAnchor(IDC_UPLOAD_ICO, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT); - AddAnchor(IDC_QUEUECOUNT, BOTTOM_LEFT); - AddAnchor(IDC_TSTATIC1, BOTTOM_LEFT); - // splitting functionality - CRect rc, rcSpl, rcDown; - GetWindowRect(rc); - ScreenToClient(rc); - rcSpl = rc; - rcSpl.top = rc.bottom - 100; - rcSpl.bottom = rcSpl.top + 5; - rcSpl.left = 55; - m_wndSplitter.Create(WS_CHILD | WS_VISIBLE, rcSpl, this, IDC_SPLITTER); - SetInitLayout(); - // create tooltip - m_ttip.Create(this); - m_ttip.SetDelayTime(TTDT_AUTOPOP, 20000); - m_ttip.SetDelayTime(TTDT_INITIAL, theApp.glob_prefs -> GetToolTipDelay() *1000); - // recognize \n chars!: - m_ttip.SendMessage(TTM_SETMAXTIPWIDTH, 0, SHRT_MAX); - m_ttip.AddTool( &downloadlistctrl); - m_ttip.AddTool( &uploadlistctrl); - m_iOldToolTipItemDown = - 1; - m_iOldToolTipItemUp = - 1; - m_iOldToolTipItemQueue = - 1; -#endif return true; } @@ -159,390 +115,31 @@ //this->GetDlgItem(IDC_QUEUECOUNT)->SetWindowText(buffer); } -#if 0 -void CTransferWnd:: DoDataExchange(CDataExchange *pDX) -{ - CResizableDialog:: DoDataExchange(pDX); - DDX_Control(pDX, IDC_UPLOADLIST, uploadlistctrl); - DDX_Control(pDX, IDC_DOWNLOADLIST, downloadlistctrl); - DDX_Control(pDX, IDC_QUEUELIST, queuelistctrl); -} - -#endif - void CTransferWnd:: SetInitLayout() { -#if 0 - CRect rcDown, rcSpl, rcW; - CWnd *pWnd; - GetWindowRect(rcW); - ScreenToClient(rcW); - LONG splitpos = (theApp.glob_prefs -> GetSplitterbarPosition() *rcW.Height()) /100; - pWnd = GetDlgItem(IDC_DOWNLOADLIST); - pWnd -> GetWindowRect(rcDown); - ScreenToClient(rcDown); - rcDown.right = rcW.right - 7; - rcDown.bottom = splitpos - 5; - downloadlistctrl.MoveWindow(rcDown); - pWnd = GetDlgItem(IDC_UPLOADLIST); - pWnd -> GetWindowRect(rcDown); - ScreenToClient(rcDown); - rcDown.right = rcW.right - 7; - rcDown.bottom = rcW.bottom - 20; - rcDown.top = splitpos + 20; - uploadlistctrl.MoveWindow(rcDown); - pWnd = GetDlgItem(IDC_QUEUELIST); - pWnd -> GetWindowRect(rcDown); - ScreenToClient(rcDown); - rcDown.right = rcW.right - 7; - rcDown.bottom = rcW.bottom - 20; - rcDown.top = splitpos + 20; - queuelistctrl.MoveWindow(rcDown); - rcSpl = rcDown; - rcSpl.top = rcDown.bottom + 4; - rcSpl.bottom = rcSpl.top + 5; - rcSpl.left = 95; - m_wndSplitter.MoveWindow(rcSpl, true); - DoResize(0); -#endif } void CTransferWnd:: DoResize(int delta) { -#if 0 - CSplitterControl:: ChangeHeight( &downloadlistctrl, delta); - CSplitterControl:: ChangeHeight( &uploadlistctrl, - delta, CW_BOTTOMALIGN); - CSplitterControl:: ChangeHeight( &queuelistctrl, - delta, CW_BOTTOMALIGN); - UpdateSplitterRange(); - Invalidate(); - UpdateWindow(); -#endif } // setting splitter range limits void CTransferWnd:: UpdateSplitterRange() { -#if 0 - CRect rcDown, rcUp, rcW, rcSpl; - CWnd *pWnd; - GetWindowRect(rcW); - ScreenToClient(rcW); - pWnd = GetDlgItem(IDC_DOWNLOADLIST); - pWnd -> GetWindowRect(rcDown); - ScreenToClient(rcDown); - pWnd = GetDlgItem(IDC_UPLOADLIST); - pWnd -> GetWindowRect(rcUp); - ScreenToClient(rcUp); - pWnd = GetDlgItem(IDC_QUEUELIST); - pWnd -> GetWindowRect(rcUp); - ScreenToClient(rcUp); - theApp.glob_prefs -> SetSplitterbarPosition((rcDown.bottom *100) /rcW.Height()); - RemoveAnchor(IDC_DOWNLOADLIST); - RemoveAnchor(IDC_UPLOADLIST); - RemoveAnchor(IDC_QUEUELIST); - AddAnchor(IDC_DOWNLOADLIST, TOP_LEFT, CSize(100, theApp.glob_prefs -> GetSplitterbarPosition())); - AddAnchor(IDC_UPLOADLIST, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT); - AddAnchor(IDC_QUEUELIST, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT); - m_wndSplitter.SetRange(rcDown.top + 50, rcUp.bottom - 40); -#endif } -#if 0 -LRESULT CTransferWnd:: DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) - { - // arrange transferwindow layout - case WM_PAINT: - if (m_wndSplitter) - { - CRect rcDown, rcSpl, rcW; - CWnd *pWnd; - GetWindowRect(rcW); - ScreenToClient(rcW); - pWnd = GetDlgItem(IDC_DOWNLOADLIST); - pWnd -> GetWindowRect(rcDown); - ScreenToClient(rcDown); - if (rcW.Height() > 0) - { - // splitter paint update - rcSpl = rcDown; - rcSpl.top = rcDown.bottom + 8; - rcSpl.bottom = rcSpl.top + 5; - rcSpl.left = 95; - GetDlgItem(IDC_UPLOAD_TEXT) -> MoveWindow(30, rcSpl.top - 5, 90, 16); - GetDlgItem(IDC_UPLOAD_ICO) -> MoveWindow(10, rcSpl.top - 5, 16, 16); - m_wndSplitter.MoveWindow(rcSpl, true); - UpdateSplitterRange(); - } - } - break; - case WM_NOTIFY: - if (wParam == IDC_SPLITTER) - { - SPC_NMHDR *pHdr = (SPC_NMHDR *) lParam; - DoResize(pHdr -> delta); - } - break; - case WM_WINDOWPOSCHANGED: - { - CRect rcW; - GetWindowRect(rcW); - ScreenToClient(rcW); - if (m_wndSplitter &&rcW.Height() > 0) Invalidate(); - break; - } - case WM_SIZE: - if (m_wndSplitter) - { - CRect rcDown, rcSpl, rcW; - CWnd *pWnd; - GetWindowRect(rcW); - ScreenToClient(rcW); - if (rcW.Height() > 0) - { - pWnd = GetDlgItem(IDC_DOWNLOADLIST); - pWnd -> GetWindowRect(rcDown); - ScreenToClient(rcDown); - long splitpos = (theApp.glob_prefs -> GetSplitterbarPosition() *rcW.Height()) /100; - rcSpl.right = rcDown.right; - rcSpl.top = splitpos + 10; - rcSpl.bottom = rcSpl.top + 5; - rcSpl.left = 95; - m_wndSplitter.MoveWindow(rcSpl, true); - } - } - break; - } - return CDialog:: DefWindowProc(message, wParam, lParam); -} - -#endif - -#if 0 -// CTransferWnd message handlers -BOOL CTransferWnd:: PreTranslateMessage(MSG *pMsg) -{ - // handle tooltip updating, when mouse is moved from one item to another - if (pMsg -> message == WM_MOUSEMOVE) - UpdateToolTips(); - // relay mouse events to tooltip control - if (pMsg -> message == WM_LBUTTONDOWN || pMsg -> message == WM_LBUTTONUP || pMsg -> message == WM_MOUSEMOVE) - m_ttip.RelayEvent(pMsg); - return CResizableDialog:: PreTranslateMessage(pMsg); -} - -#endif - void CTransferWnd:: UpdateToolTips(void) { -#if 0 - int sel = GetItemUnderMouse( &downloadlistctrl); - if (sel != - 1) - { - if (sel != m_iOldToolTipItemDown) - { - if (m_ttip.IsWindowVisible()) - m_ttip.Update(); - m_iOldToolTipItemDown = sel; - return; - } - } - int sel2 = GetItemUnderMouse( &uploadlistctrl); - if (sel2 != - 1) - { - if (sel2 != m_iOldToolTipItemUp) - { - if (m_ttip.IsWindowVisible()) - m_ttip.Update(); - m_iOldToolTipItemUp = sel2; - return; - } - } - /* no tooltips needed ATM - int sel3 = GetItemUnderMouse(&queuelistctrl); - if (sel3 != -1) - { - if (sel3 != m_iOldToolTipItemQueue) - { - if (m_ttip.IsWindowVisible()) - m_ttip.Update(); - m_iOldToolTipItemQueue = sel3; - } - } - */ - if (sel == - 1 &&sel2 == - 1 /*&& sel3 != -1*/ - ) - m_ttip.Pop(); -#endif } int CTransferWnd:: GetItemUnderMouse(wxListCtrl *ctrl) { -#if 0 - CPoint pt; - :: GetCursorPos( &pt); - ctrl -> ScreenToClient( &pt); - LVHITTESTINFO hit, subhit; - hit.pt = pt; - subhit.pt = pt; - ctrl -> SubItemHitTest( &subhit); - int sel = ctrl -> HitTest( &hit); - if (sel != LB_ERR && (hit.flags &LVHT_ONITEM)) - { - if (subhit.iSubItem == 0) - return sel; - } - return LB_ERR; -#endif } -#if 0 -BOOL CTransferWnd:: OnToolTipNotify(UINT id, NMHDR *pNMH, LRESULT *pResult) -{ - TOOLTIPTEXT *pText = (TOOLTIPTEXT *) pNMH; - int control_id =:: GetDlgCtrlID((HWND) pNMH -> idFrom); - if (!control_id) - return FALSE; - CString info; - if (control_id == IDC_DOWNLOADLIST) - { - if (downloadlistctrl.GetItemCount() < 1) - return FALSE; - int sel = GetItemUnderMouse( &downloadlistctrl); - if (sel < 0 || sel == 65535) - return FALSE; - // build info text and display it - CtrlItem_Struct *content = (CtrlItem_Struct *) downloadlistctrl.GetItemData(sel); - // for downloading files: - if (content -> type == 1) - { - CPartFile *partfile = (CPartFile *) content -> value; - CString strHash; - strHash.Format("%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", - partfile -> GetFileHash() [0], partfile -> GetFileHash() [1], partfile -> GetFileHash() [2], partfile -> GetFileHash() [3], partfile -> GetFileHash() [4], partfile -> GetFileHash() [5], partfile -> GetFileHash() [6], partfile -> GetFileHash() [7], - partfile -> GetFileHash() [8], partfile -> GetFileHash() [9], partfile -> GetFileHash() [10], partfile -> GetFileHash() [11], partfile -> GetFileHash() [12], partfile -> GetFileHash() [13], partfile -> GetFileHash() [14], partfile -> GetFileHash() [15]); - CTime t(partfile -> GetFileDate()); - char lsc[50]; - char compl[50]; - char buffer[20]; - CastItoXBytes(partfile -> GetCompletedSize(), lsc); - CastItoXBytes(partfile -> GetFileSize(), buffer); - sprintf(compl, "%s/%s", lsc, buffer); - if (partfile -> lastseencomplete == NULL) sprintf(lsc, GetResString(IDS_UNKNOWN) .MakeLower()); - else - sprintf(lsc, partfile -> lastseencomplete.Format("%A, %x, %X")); - float availability = 0; - if (partfile -> GetPartCount() != 0) - { - availability = partfile -> GetAvailablePartCount() *100 / partfile -> GetPartCount(); - } - info.Format(GetResString(IDS_DL_FILENAME) + ": %s (%d %s)\n" - + GetResString(IDS_DATE) + ": %s - " + GetResString(IDS_FD_HASH) + " %s\n" - + GetResString(IDS_PARTINFOS) + - GetResString(IDS_PARTINFOS2) + "\n%s", - partfile -> GetFileName(), partfile -> GetFileSize(), GetResString(IDS_BYTES), - t.Format("%A, %B %d, %Y"), strHash, - partfile -> GetPartMetFileName(), partfile -> GetPartCount(), GetResString(IDS_AVAIL), partfile -> GetAvailablePartCount(), availability, - (int) partfile -> GetPercentCompleted(), compl, partfile -> GetTransferingSrcCount(), - GetResString(IDS_LASTSEENCOMPL) + " " + CString(lsc)); - // for sources: - } - else if(content -> type == 3 || content -> type == 2) - { - CUpDownClient *client = (CUpDownClient *) content -> value; - in_addr server; - server.S_un.S_addr = client -> GetServerIP(); - info.Format(GetResString(IDS_NICKNAME) + " %s (" + GetResString(IDS_USERID) + ": %u)\n" - + GetResString(IDS_CLIENT) + " %s:%d\n" - + GetResString(IDS_SERVER) + " %s:%d\n" - + GetResString(IDS_SOURCEINFO), - client -> GetUserName(), client -> GetUserID(), - client -> GetFullIP(), client -> GetUserPort(), - inet_ntoa(server), client -> GetServerPort(), - /*client->GetAskedCount()*/ - 0, client -> GetAvailablePartCount()); - if (content -> type == 2) - { - // normal client - info += GetResString(IDS_CLIENTSOURCENAME) + CString(client -> GetClientFilename()); - } - else - { - // client asked twice - info += GetResString(IDS_ASKEDFAF); - } - } - } - else if(control_id == IDC_UPLOADLIST) - { - if (uploadlistctrl.GetItemCount() < 1) - return FALSE; - int sel = GetItemUnderMouse( &uploadlistctrl); - if (sel < 0 || sel == 65535) - return FALSE; - CUpDownClient *client = (CUpDownClient *) uploadlistctrl.GetItemData(sel); - CKnownFile *file = theApp.sharedfiles -> GetFileByID(client -> reqfileid); - // build info text and display it - info.Format(GetResString(IDS_USERINFO), client -> GetUserName(), client -> GetUserID()); - if (file) - { - info += GetResString(IDS_SF_REQUESTED) + CString(file -> GetFileName()) + "\n"; - CString stat; - stat.Format(GetResString(IDS_FILESTATS_SESSION) + GetResString(IDS_FILESTATS_TOTAL), - file -> statistic.GetAccepts(), file -> statistic.GetRequests(), file -> statistic.GetTransfered(), - file -> statistic.GetAllTimeAccepts(), file -> statistic.GetAllTimeRequests(), file -> statistic.GetAllTimeTransfered()); - info += stat; - } - else - { - info += GetResString(IDS_REQ_UNKNOWNFILE); - } - } - /* no tooltips needed ATM - else if (control_id == IDC_QUEUELIST) - { - if (queuelistctrl.GetItemCount() < 1) - return FALSE; - int sel = GetItemUnderMouse(&queuelistctrl); - if (sel < 0 || sel == 65535) - return FALSE; - // build info text and display it - CUpDownClient* client = (CUpDownClient*)uploadlistctrl.GetItemData(sel); - in_addr server; - server.S_un.S_addr = client->GetServerIP(); - info.Format("Nickname: %s (UserID: %u)\n" - "Client %s:%d\n" - "Server %s:%d\n" - "AskedCount: %d - AvailablePartCount: %d", - client->GetUserName(), client->GetUserID(), - client->GetFullIP(), client->GetUserPort(), - inet_ntoa(server), client->GetServerPort(), - client->GetAskedCount(), client->GetAvailablePartCount()); - } - */ - // release old used buffer: - m_strToolTip.ReleaseBuffer(); - m_strToolTip = info; - pText -> lpszText = m_strToolTip.GetBuffer(1); - // we are not using a resource: - pText -> hinst = NULL; - PostMessage(WM_ACTIVATE); - return TRUE; -} - -#endif - void CTransferWnd:: SwitchUploadList(wxCommandEvent &evt) { if (windowtransferstate == false) { -#if 0 - uploadlistctrl.Hide(); - queuelistctrl.Visable(); - windowtransferstate = 0; - GetDlgItem(IDC_UPLOAD_TEXT) -> SetWindowText(GetResString(IDS_ONQUEUE)); -#endif windowtransferstate = true; // hide the upload list queueSizer -> Remove(uploadlistctrl); @@ -554,12 +151,6 @@ } else { -#if 0 - queuelistctrl.Hide(); - uploadlistctrl.Visable(); - windowtransferstate = 1; - GetDlgItem(IDC_UPLOAD_TEXT) -> SetWindowText(GetResString(IDS_TW_UPLOADS)); -#endif windowtransferstate = false; // hide the queuelist queueSizer -> Remove(queuelistctrl); @@ -573,15 +164,6 @@ void CTransferWnd:: Localize() { -#if 0 - GetDlgItem(IDC_DOWNLOAD_TEXT) -> SetWindowText(GetResString(IDS_TW_DOWNLOADS)); - GetDlgItem(IDC_UPLOAD_TEXT) -> SetWindowText(GetResString(IDS_TW_UPLOADS)); - GetDlgItem(IDC_TSTATIC1) -> SetWindowText(GetResString(IDS_TW_QUEUE)); - downloadlistctrl.CreateMenues(); - downloadlistctrl.Localize(); - uploadlistctrl.Localize(); - queuelistctrl.Localize(); -#endif } void CTransferWnd:: OnSelchangeDltab(wxNotebookEvent &evt) @@ -777,11 +359,6 @@ theApp.downloadqueue -> SetCatStatus(m_dlTab -> GetSelection(), MP_RESUME); break; } -#if 0 - case MP_RESUMENEXT: - theApp.downloadqueue -> StartNextFile(m_dlTab -> GetSelection()); - break; -#endif case IDC_UPLOAD_ICO: { wxCommandEvent nullEvt; diff -ur xmule/src/UDPSocket.cpp xmule.new/src/UDPSocket.cpp --- xmule/src/UDPSocket.cpp 2004-04-30 14:13:18.000000000 -0700 +++ xmule.new/src/UDPSocket.cpp 2004-06-16 13:18:42.680072000 -0700 @@ -233,7 +233,9 @@ sendbuffer = 0; cur_server = 0; serverconnect = in_serverconnect; +#if defined(__DEBUG__) printf("*** UDP socket at %d\n", address.Service()); +#endif SetEventHandler( *theApp.xmuledlg, ID_SOKETTI); SetNotify(wxSOCKET_INPUT_FLAG); Notify(TRUE); @@ -375,7 +377,6 @@ update -> SetMaxUsers(cur_maxusers); update -> SetSoftFiles(cur_softfiles); update -> SetHardFiles(cur_hardfiles); - //printf("->> reading Stats from server, flags are %i\n",uUDPFlags); update -> SetUDPFlags(uUDPFlags); theApp.xmuledlg -> serverwnd -> serverlistctrl -> RefreshServer(update); } @@ -410,7 +411,9 @@ break; } default: +#if defined(__DEBUG__) printf("UDPSocket::ProcessPacket unknown opcode: %02x\n", opcode); +#endif theApp.downloadqueue -> AddDownDataOverheadOther(size); return false; } @@ -492,8 +495,6 @@ if (GAddress_INET_SetHostAddress(addr -> GetAddress(), m_SaveAddr.sin_addr.s_addr) == GSOCK_NOERROR) { SendTo( *addr, sendbuffer, sendblen); - //only for debugging: - //printf("CUDPSocket::SendBuffer to %s:%d\n",(const char *) addr->IPAddress(),addr->Service()); } } delete addr; @@ -507,7 +508,6 @@ void CUDPSocket:: SendPacket(Packet *packet, CServer *host) { -//printf("CUDPSocket:: SendPacket opcode=0x%02x size=%u\n",packet->opcode,packet->size); if (Ok()) { wxIPV4address *addr = new wxIPV4address(); @@ -518,10 +518,6 @@ { sendblen = packet -> size + 2; sendbuffer = new char[sendblen]; -#if defined(__DEBUG__) - //printf("CUDPSocket::SendPacket to %s:%d 0x%02x,%d\n", - //(const char *) addr -> IPAddress(), addr -> Service(), packet -> opcode, packet -> size); -#endif memcpy(sendbuffer, packet -> GetUDPHeader(), 2); memcpy(sendbuffer + 2, packet -> pBuffer, packet -> size); if(!newprefs01_opt[4]) { diff -ur xmule/src/UploadClient.cpp xmule.new/src/UploadClient.cpp --- xmule/src/UploadClient.cpp 2004-04-30 14:13:18.000000000 -0700 +++ xmule.new/src/UploadClient.cpp 2004-06-16 13:18:42.683071000 -0700 @@ -279,8 +279,6 @@ CFile file; byte *filedata = 0; char *fullname = 0; - try - { while (!m_BlockRequests_queue.IsEmpty()) { Requested_Block_Struct *currentblock = m_BlockRequests_queue.GetHead(); @@ -313,8 +311,9 @@ if (!srcfile -> IsPartFile()) { //CFile::modeRead|CFile::osSequentialScan|CFile::shareDenyNone)): - if (!file.Open(fullname, CFile:: read)) + if (!file.Open(fullname, CFile:: read)) { throw GetResString(IDS_ERR_OPEN); + } delete[] fullname; fullname = 0; file.Seek(currentblock -> StartOffset); @@ -331,37 +330,26 @@ CPartFile *partfile = (CPartFile *) srcfile; delete[] fullname; fullname = 0; - partfile -> m_hpartfile.Seek(currentblock -> StartOffset); + partfile -> Seek(currentblock -> StartOffset); filedata = new byte[togo + 500]; - if (uint32 done = partfile -> m_hpartfile.Read(filedata, togo) != togo) + if (uint32 done = partfile -> Read(filedata, togo) != togo) { - partfile -> m_hpartfile.Seek(0); - partfile -> m_hpartfile.Read(filedata + done, togo - done); + partfile -> Seek(0); + (void)partfile -> Read(filedata + done, togo - done); } } SetUploadFileID(currentblock -> FileID); - if (m_byDataCompVer == 1 && (!strstr(srcfile -> GetFileName(), ".zip")) && (!strstr(srcfile -> GetFileName(), ".rar")) && (!strstr(srcfile -> GetFileName(), ".ace"))) + if (m_byDataCompVer == 1 && (!strstr(srcfile -> GetFileName(), ".zip")) && (!strstr(srcfile -> GetFileName(), ".rar")) && (!strstr(srcfile -> GetFileName(), ".ace"))) { CreatePackedPackets(filedata, togo, currentblock); - else + } else { CreateStandartPackets(filedata, togo, currentblock); + } // file statistic srcfile -> statistic.AddTransferred(togo); m_DoneBlocks_list.AddHead(m_BlockRequests_queue.RemoveHead()); delete[] filedata; filedata = 0; } - } - catch(wxString error) - { - theApp.xmuledlg -> AddDebugLogLine(false, GetResString(IDS_ERR_CLIENTERRORED), GetUserName(), error.GetData()); - theApp.uploadqueue -> RemoveFromUploadQueue(this); - if (filedata) - delete filedata; - if (fullname) - delete[] fullname; - return false; - } - // theApp.xmuledlg->AddDebugLogLine(false,"Debug: Packet done. Size: %i",blockpack->GetLength()); return true; } @@ -458,14 +446,16 @@ CMemFile memfile(output, newsize); togo = newsize; uint32 nPacketSize; - if (togo > 10240) + if (togo > 10240) { nPacketSize = togo/ (uint32)(togo/10240); - else + } else { nPacketSize = togo; + } while (togo) { - if (togo < nPacketSize *2) + if (togo < nPacketSize *2) { nPacketSize = togo; + } togo -= nPacketSize; Packet *packet = new Packet(OP_COMPRESSEDPART, nPacketSize + 24, OP_EMULEPROT); memcpy( &packet -> pBuffer[0], GetUploadFileID(), 16); @@ -484,8 +474,9 @@ if (tempreqfileid) newreqfile = theApp.sharedfiles -> GetFileByID(tempreqfileid); CKnownFile *oldreqfile = theApp.sharedfiles -> GetFileByID(requpfileid); - if (newreqfile == oldreqfile) + if (newreqfile == oldreqfile) { return; + } if (newreqfile) { newreqfile -> AddQueuedCount(); diff -ur xmule/src/opcodes.h xmule.new/src/opcodes.h --- xmule/src/opcodes.h 2004-05-31 16:39:02.000000000 -0700 +++ xmule.new/src/opcodes.h 2004-06-16 13:18:42.691070000 -0700 @@ -30,7 +30,7 @@ #define WM_APP 5500 //release:#define MOD_VERSION "xMule" -#define MOD_VERSION "xMule 1.8.2c" +#define MOD_VERSION "xMule" #define ET_MOD_VERSION 0x55 // MOD Note: Do not change this part - Merkur #define CURRENT_VERSION_SHORT 0x30 @@ -40,8 +40,13 @@ #define EDONKEYVERSION 0x3c #define PREFFILE_VERSION 0x14 //<<-- last change: reduced .dat, by using .ini #define PARTFILE_VERSION 0xe0 +#define PARTFILE_SPLITTEDVERSION 0xe1 #define CREDITFILE_VERSION 0x12 #define CREDITFILE_VERSION_29 0x11 +#define VERSION_MJR 0x00 +#define VERSION_MIN 0x28 +#define VERSION_UPDATE 0x02 +#define VERSION_BUILD 0x01 #define COMPILE_DATE __DATE__ #define COMPILE_TIME __TIME__ #ifdef _DEBUG @@ -62,6 +67,7 @@ #define SERVERREASKTIME 800000 // don't set this too low, it wont speed up anything, but it could kill xmule or your internetconnection #define UDPSERVERREASKTIME 1300000 // *** #define SOURCECLIENTREASK 600000 +#define SOURCESWAPTIME 30000 #define MINCOMMONPENALTY 9 #define UDPSERVERSTATTIME 5000 #define UDPSERVSTATREASKTIME 14400000 @@ -237,7 +243,6 @@ #define FT_SOURCES 0x15 #define FT_PERMISSIONS 0x16 #define FT_OLDULPRIORITY 0x17 -#define FT_CATEGORY 0x53 #define FT_DLPRIORITY 0x18 // Was 13 #define FT_ULPRIORITY 0x19 // Was 17 @@ -246,8 +251,11 @@ #define FT_ATTRANSFERED 0x50 #define FT_ATREQUESTED 0x51 #define FT_ATACCEPTED 0x52 +#define FT_CATEGORY 0x53 #define FT_ATTRANSFEREDHI 0x54 +#define FT_DYNAMIC 0xc1 + #define CT_NAME 0x01 #define CT_PORT 0x0f #define CT_VERSION 0x11 diff -ur xmule/src/resource/newprefs01.pm xmule.new/src/resource/newprefs01.pm --- xmule/src/resource/newprefs01.pm 2004-05-16 08:56:17.000000000 -0700 +++ xmule.new/src/resource/newprefs01.pm 2004-06-16 13:18:42.710067000 -0700 @@ -1,12 +1,13 @@ 0,New Preferences -1,separator -20101,Secure Identification on/off +20101,Secure Identification active 20106,Automatic-Random-Privatekey-Generator +20107,Renew userhash on start: -1,separator -20102,Source-Exchange on/off +20102,Source-Exchange active -1,separator -20103,xMule-Identification as eMule on/off +20103,xMule-Identification as eMule -1,separator 20104,Disconnect xMule from ed2k-Network -1,separator -20105,Compressed Partfile-Support +20105,Dynamic Partfile-Support diff -ur xmule/src/resource.h xmule.new/src/resource.h --- xmule/src/resource.h 2004-04-30 14:13:21.000000000 -0700 +++ xmule.new/src/resource.h 2004-06-16 13:18:42.717066000 -0700 @@ -1057,6 +1057,7 @@ #define IDS_FILTER 1005 #define IDS_CHANGECATVIEW 1025 #define IDS_STATUS_NOTCOMPLETED 1026 +#define IDS_CONVERTING 1027 #define IDD_FLOWCHART 1109 #define IDC_ANIMATE1 2000 #define IDC_STATUS 2001 diff -ur xmule/src/strings.en xmule.new/src/strings.en --- xmule/src/strings.en 2003-08-26 03:25:48.000000000 -0700 +++ xmule.new/src/strings.en 2004-06-16 13:18:42.725065000 -0700 @@ -269,6 +269,7 @@ {IDS_HASHING, "Hashing"}, {IDS_COMPLETING, "Completing"}, {IDS_COMPLETE, "Complete"}, +{IDS_CONVERTING, "Converting"}, {IDS_PAUSED, "Paused"}, {IDS_ERRORLIKE, "Erroneous"}, {IDS_LFILES, "files"}, diff -ur xmule/src/xmuleDlg.cpp xmule.new/src/xmuleDlg.cpp --- xmule/src/xmuleDlg.cpp 2004-05-04 10:10:15.000000000 -0700 +++ xmule.new/src/xmuleDlg.cpp 2004-06-16 13:18:42.730064000 -0700 @@ -203,6 +203,7 @@ sharedfileswnd -> Show(FALSE); statisticswnd -> Show(FALSE); chatwnd -> Show(FALSE); + flowchartwnd -> Show(FALSE); SetActiveDialog(serverwnd); m_nActiveDialog = 1; // can't init now