Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 53638 | Differences between
and this patch

Collapse All | Expand All

(-)xmule/ChangeLog (+14 lines)
Lines 1-5 Link Here
1
Please read the IMPORTANT NOTE on xMule's versioning system below!
1
Please read the IMPORTANT NOTE on xMule's versioning system below!
2
For changes to the UNSTABLE branch, see ChangeLog-UNSTABLE.
2
For changes to the UNSTABLE branch, see ChangeLog-UNSTABLE.
3
Version 1.8.2d
4
--------------
5
*New in 1.8.2d
6
     *ADDED: Dynamic Partfiles (named as x.pnew and x.pnew.met instead of x.part and x.part.met)
7
	     This type of partfiles needs only as much space on disk as downloaded, not as the filesize tells
8
	     Its possible, to use both types with the some xmule at the same time (to finish older downloads)
9
     *ADDED: Renewable Clienthash on startup (to increase security) (to activate look at FlowChart
10
     *ADDED: Configureoption "--enable-cryptopp" to use the original library instead of the far more
11
	     compact CryptoXMpp for compatibility reasons (on 64-Bitsystems and other than i386).
12
*Bugfixes
13
     *FIXED: Corrected version-information for xmule (Thanks to Kry from aMule team to inform us
14
	     about that!) for CT_VERSION_MOD on SendHelloTypePacket in BaseClient.cpp.
15
     *FIXED: Clienthash now saved and loaded
16
	     
3
Version 1.8.2c
17
Version 1.8.2c
4
--------------
18
--------------
5
2004-06-01
19
2004-06-01
(-)xmule/INSTALL (+190 lines)
Lines 56-58 Link Here
56
Otherwise, you will miss some popup-menues inside the FlowChart-Window, which are needed to enable functions
56
Otherwise, you will miss some popup-menues inside the FlowChart-Window, which are needed to enable functions
57
like "source-exchange" and "securehash/ident/creditfiles".
57
like "source-exchange" and "securehash/ident/creditfiles".
58
58
59
===========================================================================================================
60
NEW: Overview to install all needed libs from scratch under problematic conditions (suse/mandrake/fc2/etc):
61
=========================================english===========================================================
62
You will need: 
63
64
autoconf-2.59 (min. see autoconf --version) 
65
gettext-0.11.5 (min. see gettext --version) 
66
automake-1.7.9 (min. see automake --version) 
67
glib-1.2.10 
68
gtk-1.2.10 
69
wxGTK-2.4.2 (no unicode, to configure with --with-gtk 
70
--disable-gtk2) 
71
xMule-1.8.2c 
72
73
74
To download: 
75
76
cd /usr/src 
77
wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.59.tar.gz 
78
wget ftp://ftp.gnu.org/gnu/gettext/gettext-0.11.5.tar.gz 
79
wget ftp://ftp.gnu.org/gnu/automake/automake-1.7.9.tar.gz 
80
wget ftp://ftp.nctu.edu.tw/UNIX/gtk/v1.2/glib-1.2.10.tar.gz 
81
wget ftp://ftp.nctu.edu.tw/UNIX/gtk/v1.2/gtk+-1.2.10.tar.gz 
82
wget 
83
http://heanet.dl.sourceforge.net/sourceforge/wxwindows/wxGTK-2.4.2.tar.gz 
84
wget http://download.gna.org/xmule/xmule-1.8.2c.tar.gz 
85
86
To install: 
87
88
cd /usr/src 
89
tar zxvf autoconf*.gz 
90
tar zxvf gettext*.gz 
91
tar zxvf automake*.gz 
92
tar zxvf glib*.gz 
93
tar zxvf gtk*.gz 
94
tar zxvf wxGTK*.gz 
95
tar zxvf xmule*.gz 
96
97
cd /usr/src/autoconf*9 
98
./configure 
99
make 
100
make install 
101
102
cd /usr/src/gettext*5 
103
./configure 
104
make 
105
make install 
106
107
cd /usr/src/automake*9 
108
./configure 
109
make 
110
make install 
111
112
vi /etc/ld.so.conf 
113
>>>>insert the following lines if not exist: 
114
/usr/local/lib 
115
/usr/local/lib/glib-1.2 
116
/usr/local/lib/gtk-1.2 
117
118
cd /usr/src/glib*10 
119
./configure 
120
make 
121
make install 
122
ldconfig 
123
124
cd /usr/src/gtk*10 
125
./configure 
126
make 
127
make install 
128
ldconfig 
129
130
cd /usr/src/wxGTK*2 
131
./configure --with-gtk --disable-gtk2 
132
make 
133
make install 
134
ldconfig 
135
136
cd /usr/src/xmule*2c 
137
./configure --enable-debug 
138
make 
139
cp /usr/src/xmule*2c/src/xmule /usr/bin 
140
chmod 755 /usr/bin/xmule 
141
142
For every user-account ($HOME) you wish to use xMule, you 
143
have to do the following: 
144
145
mkdir $HOME/.xMule 
146
chmod 777 $HOME/.xMule 
147
cp -R /usr/src/xmule*2c/src/resource $HOME/.xMule 
148
chmod 755 $HOME/.xMule/resource 
149
150
That's all!
151
===========================================================================================================
152
NEW: Übersicht um alle benötigten Libraries zu installieren unter erschwerten Bedingungen/ohne Kentnisse:
153
=========================================deutsch===========================================================
154
Benötigt dazu werden nur (alle selbst zu kompilieren, in dieser Reihenfolge - in 30 Minuten erledigt): 
155
156
autoconf-2.59 (mindestens, siehe autoconf --version) 
157
gettext-0.11.5 (mindestens, siehe gettext --version) 
158
automake-1.7.9 (mindestens, siehe automake --version) 
159
glib-1.2.10 
160
gtk-1.2.10 
161
wxGTK-2.4.2 (kein Unicode, configured mit --with-gtk --disable-gtk2) 
162
xMule-1.8.2c 
163
164
Zur Vorbereitung: 
165
166
Yast2 starten, Software installieren/deinstallieren, Suche: 
167
168
glib -> eventuell installierte Pakete glib-1.2.10 & -devel löschen 
169
gtk -> eventuell installierte Pakete gtk+-1.2.10 & -devel löschen 
170
wxGTK-2.4.1 -> falls installiert, löschen 
171
172
Yast2 verlassen. 
173
174
Zum Download: 
175
176
cd /usr/src 
177
wget <ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.59.tar.gz> 
178
wget <ftp://ftp.gnu.org/gnu/gettext/gettext-0.11.5.tar.gz> 
179
wget <ftp://ftp.gnu.org/gnu/automake/automake-1.7.9.tar.gz> 
180
wget <ftp://ftp.nctu.edu.tw/UNIX/gtk/v1.2/glib-1.2.10.tar.gz> 
181
wget <ftp://ftp.nctu.edu.tw/UNIX/gtk/v1.2/gtk+-1.2.10.tar.gz> 
182
wget <http://heanet.dl.sourceforge.net/sourceforge/wxwindows/wxGTK-2.4.2.tar.gz> 
183
wget <http://download.gna.org/xmule/xmule-1.8.2c.tar.gz> 
184
185
Zur Installation: 
186
187
cd /usr/src 
188
tar zxvf autoconf*.gz 
189
tar zxvf gettext*.gz 
190
tar zxvf automake*.gz 
191
tar zxvf glib*.gz 
192
tar zxvf gtk*.gz 
193
tar zxvf wxGTK*.gz 
194
tar zxvf xmule*.gz 
195
196
cd /usr/src/autoconf*9 
197
./configure 
198
make 
199
make install 
200
201
cd /usr/src/gettext*5 
202
./configure 
203
make 
204
make install 
205
206
cd /usr/src/automake*9 
207
./configure 
208
make 
209
make install 
210
211
vi /etc/ld.so.conf 
212
>>>>folgende Zeilen eintragen (falls keine solche vorhanden) 
213
/usr/local/lib 
214
/usr/local/lib/glib-1.2 
215
/usr/local/lib/gtk-1.2 
216
217
cd /usr/src/glib*10 
218
./configure 
219
make 
220
make install 
221
ldconfig 
222
223
cd /usr/src/gtk*10 
224
./configure 
225
make 
226
make install 
227
ldconfig 
228
229
cd /usr/src/wxGTK*2 
230
./configure --with-gtk --disable-gtk2 
231
make 
232
make install 
233
ldconfig 
234
235
cd /usr/src/xmule*2c 
236
./configure --enable-debug 
237
make 
238
cp /usr/src/xmule*2c/src/xmule /usr/bin 
239
chmod 755 /usr/bin/xmule 
240
241
Für jeden Benutzeraccount ($HOME) notwendig, für den man xMule verwenden möchte: 
242
243
mkdir $HOME/.xMule 
244
chmod 777 $HOME/.xMule 
245
cp -R /usr/src/xmule*2c/src/resource $HOME/.xMule 
246
chmod 755 $HOME/.xMule/resource 
247
248
Das war alles!
(-)xmule/TODO (-9 / +26 lines)
Lines 1-10 Link Here
1
V1.8.0 TODO:
1
v1.8.x TODO:
2
------------
2
------------
3
DONE: Fixing Bug that Files <9mb are not downloadable
3
priority,status,info
4
DONE: Fixing UDP-Port CPU-idle Bug
4
1,open: new functions to convert partfiles from and to new-format
5
DONE: Fix the m4 file missing problem
5
1,open: serverless-runmode for xmule
6
DONE: Make listctrl events work with GTK2
6
2,open: priorities-bugfix & optimization for downloadtable
7
DONE: Changing Version Number to 1.8.0
7
3,open: xmule-icon-only instead of minimized in toolbar & icon at the same time
8
DONE: Only one file seems to download at a time, unless 2 files start downloading within 1 minute of each other.
8
3,open: encryption of partfiles and sharedfiles for only being decrypted while xmule is running with the
9
DONE:Fixing crashes caused by CClientReqSocket::ProcessPacket OP_EMULEINFOANSWER 02,76 and other
9
.......correct privatekey. publickey will be endless (for every byte/character enother encoding-base)
10
10
.......so only who knows the privatekey is able to decrypt the encrypted date and this only while xmule
11
.......is running - so no further filesystem-encryption will be needed after xmule encrypted all files
12
.......in itself on disk.
13
.......the encrypted files could be burned to dvd or cd - the length of the files will be the same
14
.......(encrypted or decrypted)
15
.......encrypted files on dvd/cdr will be usable/accessible after an additional decryption over xmule to disk
16
.......
17
.......the private key will not be stored anywhere
18
.......the private key will be the key to enter xmule in the future - everyone can define the privatekey for
19
.......itself on every start. if the privatekey on start is another than on the last start of xmule,
20
.......all files not encrypted with the actual privatekey will not be accessible/usable
21
.......
22
.......the encryption-algorithm will be a completely new one - never used before. so there will be no
23
.......other program at the moment which will be able to decrypt the files encrypted by xmule other than
24
.......xmule itself
25
.......
26
.......this means: you should never forget your privatekey, otherwise all files encrypted with this key
27
...................will be lost forever
(-)xmule/configure (-15 / +38 lines)
Lines 1-6 Link Here
1
#! /bin/sh
1
#! /bin/sh
2
# Guess values for system-dependent variables and create Makefiles.
2
# Guess values for system-dependent variables and create Makefiles.
3
# Generated by GNU Autoconf 2.59 for xMule 1.8.2c.
3
# Generated by GNU Autoconf 2.59 for xMule 1.8.2d.
4
#
4
#
5
# Report bugs to <http://xmule.hopto.org/board/>.
5
# Report bugs to <http://xmule.hopto.org/board/>.
6
#
6
#
Lines 269-276 Link Here
269
# Identity of this package.
269
# Identity of this package.
270
PACKAGE_NAME='xMule'
270
PACKAGE_NAME='xMule'
271
PACKAGE_TARNAME='xmule'
271
PACKAGE_TARNAME='xmule'
272
PACKAGE_VERSION='1.8.2c'
272
PACKAGE_VERSION='1.8.2d'
273
PACKAGE_STRING='xMule 1.8.2c'
273
PACKAGE_STRING='xMule 1.8.2d'
274
PACKAGE_BUGREPORT='http://xmule.hopto.org/board/'
274
PACKAGE_BUGREPORT='http://xmule.hopto.org/board/'
275
275
276
ac_unique_file="src/SharedFileList.h"
276
ac_unique_file="src/SharedFileList.h"
Lines 788-794 Link Here
788
  # Omit some internal or obsolete options to make the list less imposing.
788
  # Omit some internal or obsolete options to make the list less imposing.
789
  # This message is too long to be a string in the A/UX 3.1 sh.
789
  # This message is too long to be a string in the A/UX 3.1 sh.
790
  cat <<_ACEOF
790
  cat <<_ACEOF
791
\`configure' configures xMule 1.8.2c to adapt to many kinds of systems.
791
\`configure' configures xMule 1.8.2d to adapt to many kinds of systems.
792
792
793
Usage: $0 [OPTION]... [VAR=VALUE]...
793
Usage: $0 [OPTION]... [VAR=VALUE]...
794
794
Lines 849-855 Link Here
849
849
850
if test -n "$ac_init_help"; then
850
if test -n "$ac_init_help"; then
851
  case $ac_init_help in
851
  case $ac_init_help in
852
     short | recursive ) echo "Configuration of xMule 1.8.2c:";;
852
     short | recursive ) echo "Configuration of xMule 1.8.2d:";;
853
   esac
853
   esac
854
  cat <<\_ACEOF
854
  cat <<\_ACEOF
855
855
Lines 862-867 Link Here
862
  --disable-gtktest       Do not try to compile and run a test GTK program
862
  --disable-gtktest       Do not try to compile and run a test GTK program
863
  --enable-debug          Enable additional debugging output
863
  --enable-debug          Enable additional debugging output
864
  --disable-debug-syms    Disable debugging information
864
  --disable-debug-syms    Disable debugging information
865
  --enable-cryptopp       Enable use of libcryptopp.a instead of CryptoXMpp
865
  --enable-optimise       Enable code optimising
866
  --enable-optimise       Enable code optimising
866
  --enable-profile        Enable code profiling
867
  --enable-profile        Enable code profiling
867
  --disable-gtk           Disable pure GTK code in xmule
868
  --disable-gtk           Disable pure GTK code in xmule
Lines 994-1000 Link Here
994
test -n "$ac_init_help" && exit 0
995
test -n "$ac_init_help" && exit 0
995
if $ac_init_version; then
996
if $ac_init_version; then
996
  cat <<\_ACEOF
997
  cat <<\_ACEOF
997
xMule configure 1.8.2c
998
xMule configure 1.8.2d
998
generated by GNU Autoconf 2.59
999
generated by GNU Autoconf 2.59
999
1000
1000
Copyright (C) 2003 Free Software Foundation, Inc.
1001
Copyright (C) 2003 Free Software Foundation, Inc.
Lines 1008-1014 Link Here
1008
This file contains any messages produced by compilers while
1009
This file contains any messages produced by compilers while
1009
running configure, to aid debugging if configure makes a mistake.
1010
running configure, to aid debugging if configure makes a mistake.
1010
1011
1011
It was created by xMule $as_me 1.8.2c, which was
1012
It was created by xMule $as_me 1.8.2d, which was
1012
generated by GNU Autoconf 2.59.  Invocation command line was
1013
generated by GNU Autoconf 2.59.  Invocation command line was
1013
1014
1014
  $ $0 $@
1015
  $ $0 $@
Lines 1345-1352 Link Here
1345
1346
1346
1347
1347
1348
1349
1348
          ac_config_headers="$ac_config_headers config.h"
1350
          ac_config_headers="$ac_config_headers config.h"
1349
1351
1352
          ac_config_commands="$ac_config_commands default-1"
1353
1350
1354
1351
# BEGIN COMPAT VARIABLES
1355
# BEGIN COMPAT VARIABLES
1352
1356
Lines 1356-1366 Link Here
1356
1360
1357
1361
1358
cat >>confdefs.h <<\_ACEOF
1362
cat >>confdefs.h <<\_ACEOF
1359
#define VERSION "1.8.2c"
1363
#define VERSION "1.8.2d"
1360
_ACEOF
1364
_ACEOF
1361
1365
1362
PACKAGE="xmule"
1366
PACKAGE="xmule"
1363
VERSION="1.8.2c"
1367
VERSION="1.8.2d"
1364
1368
1365
1369
1366
# END COMPAT VARIABLES
1370
# END COMPAT VARIABLES
Lines 3216-3222 Link Here
3216
        rm -f messages.po
3220
        rm -f messages.po
3217
  fi
3221
  fi
3218
3222
3219
            ac_config_commands="$ac_config_commands default-1"
3223
            ac_config_commands="$ac_config_commands default-2"
3220
3224
3221
3225
3222
# Make sure we can run config.sub.
3226
# Make sure we can run config.sub.
Lines 8535-8540 Link Here
8535
  USE_DEBUG_SYMS="yes"
8539
  USE_DEBUG_SYMS="yes"
8536
fi;
8540
fi;
8537
8541
8542
# Check whether --enable-cryptopp or --disable-cryptopp was given.
8543
if test "${enable_cryptopp+set}" = set; then
8544
  enableval="$enable_cryptopp"
8545
8546
fi;
8547
8538
# Check whether --enable-optimise or --disable-optimise was given.
8548
# Check whether --enable-optimise or --disable-optimise was given.
8539
if test "${enable_optimise+set}" = set; then
8549
if test "${enable_optimise+set}" = set; then
8540
  enableval="$enable_optimise"
8550
  enableval="$enable_optimise"
Lines 10222-10227 Link Here
10222
   esac
10232
   esac
10223
fi
10233
fi
10224
10234
10235
if test -n "$enable_cryptopp"; then
10236
   enable_cryptopp=no
10237
   CRDEFS="-D__CRPP__"
10238
   LIBCRPP="-lcryptopp"
10239
else
10240
   CRDEFS=""
10241
fi
10242
10243
10225
if test -n "$enable_gtk"; then
10244
if test -n "$enable_gtk"; then
10226
   enable_stripgtk=no
10245
   enable_stripgtk=no
10227
   GTK_DEFS="-D__NOGTK__"
10246
   GTK_DEFS="-D__NOGTK__"
Lines 10248-10255 Link Here
10248
10267
10249
# we have it anyway by now
10268
# we have it anyway by now
10250
10269
10251
LIBS="$LIBS $WX_LIBS $ZLIB_LIBS $LIBM"
10270
LIBS="$LIBS $WX_LIBS $ZLIB_LIBS $LIBM $LIBCRPP"
10252
10271
10272
GTK_CFLAGS="$GTK_CFLAGS $CRDEFS"
10253
PCHFLAGS="$PCHFLAGS $DEBUG_FLAGS $GTK_CFLAGS -I. $DEFS $WX_CXXFLAGS"
10273
PCHFLAGS="$PCHFLAGS $DEBUG_FLAGS $GTK_CFLAGS -I. $DEFS $WX_CXXFLAGS"
10254
10274
10255
10275
Lines 10258-10264 Link Here
10258
10278
10259
XRCFLAGS="-Isrc"
10279
XRCFLAGS="-Isrc"
10260
CXXFLAGS="$CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS $WX_CXXFLAGS $GTK_CFLAGS $XRCFLAGS $ZLIB_CFLAGSx"
10280
CXXFLAGS="$CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS $WX_CXXFLAGS $GTK_CFLAGS $XRCFLAGS $ZLIB_CFLAGSx"
10261
CFLAGS="$GTK_DEFS $CFLAGS $CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS"
10281
CFLAGS="$GTK_DEFS $CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS"
10262
LDFLAGS="$EXPORT_DYN_FLAGS $PROFILE_FLAGS $LDFLAGS"
10282
LDFLAGS="$EXPORT_DYN_FLAGS $PROFILE_FLAGS $LDFLAGS"
10263
10283
10264
                                                            ac_config_files="$ac_config_files src/Makefile intl/Makefile po/Makefile.in src/wx/xrc/Makefile Makefile Compilation.flags"
10284
                                                            ac_config_files="$ac_config_files src/Makefile intl/Makefile po/Makefile.in src/wx/xrc/Makefile Makefile Compilation.flags"
Lines 10625-10631 Link Here
10625
} >&5
10645
} >&5
10626
cat >&5 <<_CSEOF
10646
cat >&5 <<_CSEOF
10627
10647
10628
This file was extended by xMule $as_me 1.8.2c, which was
10648
This file was extended by xMule $as_me 1.8.2d, which was
10629
generated by GNU Autoconf 2.59.  Invocation command line was
10649
generated by GNU Autoconf 2.59.  Invocation command line was
10630
10650
10631
  CONFIG_FILES    = $CONFIG_FILES
10651
  CONFIG_FILES    = $CONFIG_FILES
Lines 10688-10694 Link Here
10688
10708
10689
cat >>$CONFIG_STATUS <<_ACEOF
10709
cat >>$CONFIG_STATUS <<_ACEOF
10690
ac_cs_version="\\
10710
ac_cs_version="\\
10691
xMule config.status 1.8.2c
10711
xMule config.status 1.8.2d
10692
configured by $0, generated by GNU Autoconf 2.59,
10712
configured by $0, generated by GNU Autoconf 2.59,
10693
  with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
10713
  with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
10694
10714
Lines 10787-10792 Link Here
10787
# INIT-COMMANDS section.
10807
# INIT-COMMANDS section.
10788
#
10808
#
10789
10809
10810
10790
# Capture the value of obsolete ALL_LINGUAS because we need it to compute
10811
# Capture the value of obsolete ALL_LINGUAS because we need it to compute
10791
    # POFILES, GMOFILES, UPDATEPOFILES, DUMMYPOFILES, CATALOGS. But hide it
10812
    # POFILES, GMOFILES, UPDATEPOFILES, DUMMYPOFILES, CATALOGS. But hide it
10792
    # from automake.
10813
    # from automake.
Lines 10811-10816 Link Here
10811
  "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
10832
  "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
10812
  "Compilation.flags" ) CONFIG_FILES="$CONFIG_FILES Compilation.flags" ;;
10833
  "Compilation.flags" ) CONFIG_FILES="$CONFIG_FILES Compilation.flags" ;;
10813
  "default-1" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;;
10834
  "default-1" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;;
10835
  "default-2" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-2" ;;
10814
  "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
10836
  "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
10815
  *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
10837
  *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
10816
echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
10838
echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
Lines 11547-11553 Link Here
11547
  { echo "$as_me:$LINENO: executing $ac_dest commands" >&5
11569
  { echo "$as_me:$LINENO: executing $ac_dest commands" >&5
11548
echo "$as_me: executing $ac_dest commands" >&6;}
11570
echo "$as_me: executing $ac_dest commands" >&6;}
11549
  case $ac_dest in
11571
  case $ac_dest in
11550
    default-1 )
11572
    default-1 ) test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h ;;
11573
    default-2 )
11551
    for ac_file in $CONFIG_FILES; do
11574
    for ac_file in $CONFIG_FILES; do
11552
      # Support "outfile[:infile[:infile...]]"
11575
      # Support "outfile[:infile[:infile...]]"
11553
      case "$ac_file" in
11576
      case "$ac_file" in
(-)xmule/configure.in (-5 / +17 lines)
Lines 1-13 Link Here
1
# Process this file with autoconf to produce a configure script.
1
# Process this file with autoconf to produce a configure script.
2
AC_INIT([xMule],[1.8.2c],[http://xmule.hopto.org/board/])
2
AC_INIT([xMule],[1.8.2d],[http://xmule.hopto.org/board/])
3
AC_CONFIG_SRCDIR([src/SharedFileList.h])
3
AC_CONFIG_SRCDIR([src/SharedFileList.h])
4
AM_CONFIG_HEADER([config.h])
4
AM_CONFIG_HEADER([config.h])
5
5
6
# BEGIN COMPAT VARIABLES
6
# BEGIN COMPAT VARIABLES
7
AC_DEFINE(PACKAGE, ["xmule"], [Description])
7
AC_DEFINE(PACKAGE, ["xmule"], [Description])
8
AC_DEFINE(VERSION, ["1.8.2c"], [Description])
8
AC_DEFINE(VERSION, ["1.8.2d"], [Description])
9
PACKAGE="xmule"
9
PACKAGE="xmule"
10
VERSION="1.8.2c"
10
VERSION="1.8.2d"
11
AC_SUBST(PACKAGE)
11
AC_SUBST(PACKAGE)
12
AC_SUBST(VERSION)
12
AC_SUBST(VERSION)
13
# END COMPAT VARIABLES
13
# END COMPAT VARIABLES
Lines 64-69 Link Here
64
AC_ARG_ENABLE(debug,   [  --disable-debug-syms    Disable debugging information],
64
AC_ARG_ENABLE(debug,   [  --disable-debug-syms    Disable debugging information],
65
              USE_DEBUG_SYMS="$disableval", USE_DEBUG_SYMS="yes")
65
              USE_DEBUG_SYMS="$disableval", USE_DEBUG_SYMS="yes")
66
66
67
AC_ARG_ENABLE(cryptopp,   [  --enable-cryptopp       Enable use of libcryptopp.a instead of CryptoXMpp])
68
67
AC_ARG_ENABLE(optimise,[  --enable-optimise       Enable code optimising],
69
AC_ARG_ENABLE(optimise,[  --enable-optimise       Enable code optimising],
68
		USE_OPTIMISE="$enableval", USE_OPTIMISE="no")
70
		USE_OPTIMISE="$enableval", USE_OPTIMISE="no")
69
71
Lines 146-151 Link Here
146
   esac
148
   esac
147
fi
149
fi
148
  
150
  
151
if test -n "$enable_cryptopp"; then
152
   enable_cryptopp=no
153
   CRDEFS="-D__CRPP__"
154
   LIBCRPP="-lcryptopp"
155
else
156
   CRDEFS=""
157
fi
158
159
  
149
if test -n "$enable_gtk"; then
160
if test -n "$enable_gtk"; then
150
   enable_stripgtk=no
161
   enable_stripgtk=no
151
   GTK_DEFS="-D__NOGTK__"
162
   GTK_DEFS="-D__NOGTK__"
Lines 168-175 Link Here
168
AC_DEFINE_UNQUOTED(LOCALEDIR, "`eval echo $datadir/locale`", [Define where the locales are.])
179
AC_DEFINE_UNQUOTED(LOCALEDIR, "`eval echo $datadir/locale`", [Define where the locales are.])
169
# we have it anyway by now
180
# we have it anyway by now
170
181
171
LIBS="$LIBS $WX_LIBS $ZLIB_LIBS $LIBM"
182
LIBS="$LIBS $WX_LIBS $ZLIB_LIBS $LIBM $LIBCRPP"
172
183
184
GTK_CFLAGS="$GTK_CFLAGS $CRDEFS"
173
PCHFLAGS="$PCHFLAGS $DEBUG_FLAGS $GTK_CFLAGS -I. $DEFS $WX_CXXFLAGS"
185
PCHFLAGS="$PCHFLAGS $DEBUG_FLAGS $GTK_CFLAGS -I. $DEFS $WX_CXXFLAGS"
174
186
175
AC_SUBST(GTK_DEFS)
187
AC_SUBST(GTK_DEFS)
Lines 178-184 Link Here
178
AC_SUBST(MAKE_PRECOMP)
190
AC_SUBST(MAKE_PRECOMP)
179
XRCFLAGS="-Isrc"
191
XRCFLAGS="-Isrc"
180
CXXFLAGS="$CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS $WX_CXXFLAGS $GTK_CFLAGS $XRCFLAGS $ZLIB_CFLAGSx"
192
CXXFLAGS="$CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS $WX_CXXFLAGS $GTK_CFLAGS $XRCFLAGS $ZLIB_CFLAGSx"
181
CFLAGS="$GTK_DEFS $CFLAGS $CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS"
193
CFLAGS="$GTK_DEFS $CXXFLAGS $OPTIMISE_FLAGS $PROFILE_FLAGS"
182
LDFLAGS="$EXPORT_DYN_FLAGS $PROFILE_FLAGS $LDFLAGS"
194
LDFLAGS="$EXPORT_DYN_FLAGS $PROFILE_FLAGS $LDFLAGS"
183
195
184
AC_CONFIG_FILES([src/Makefile intl/Makefile po/Makefile.in src/wx/xrc/Makefile Makefile Compilation.flags])
196
AC_CONFIG_FILES([src/Makefile intl/Makefile po/Makefile.in src/wx/xrc/Makefile Makefile Compilation.flags])
(-)xmule/src/AddFileThread.cpp (-6 / +3 lines)
Lines 23-28 Link Here
23
#	include "KnownFile.h"
23
#	include "KnownFile.h"
24
#	include "opcodes.h"
24
#	include "opcodes.h"
25
#	include "otherfunctions.h"
25
#	include "otherfunctions.h"
26
#	include "PartFile.h"
26
#	include "types.h"
27
#	include "types.h"
27
#	include "xmule.h"
28
#	include "xmule.h"
28
#	include "xmuleDlg.h"
29
#	include "xmuleDlg.h"
Lines 59-67 Link Here
59
void CAddFileThread:: Shutdown()
60
void CAddFileThread:: Shutdown()
60
{
61
{
61
    m_lockWaitingForHashList.Lock();
62
    m_lockWaitingForHashList.Lock();
62
#if defined(__DEBUG__)
63
    printf("Signaling hashing thread to terminate\n");
64
#endif
65
    // Tell the thread to exit
63
    // Tell the thread to exit
66
    m_endWaitingForHashList = 1;
64
    m_endWaitingForHashList = 1;
67
    // Signal the thread there is something to do
65
    // Signal the thread there is something to do
Lines 101-109 Link Here
101
        UnknownFile_Struct *hashfile = m_sWaitingForHashList.RemoveHead();
99
        UnknownFile_Struct *hashfile = m_sWaitingForHashList.RemoveHead();
102
        m_lockWaitingForHashList.Unlock();
100
        m_lockWaitingForHashList.Unlock();
103
        CKnownFile *newrecord = new CKnownFile();
101
        CKnownFile *newrecord = new CKnownFile();
104
        printf("Sharing %s/%s\n", hashfile -> directory, hashfile -> name);
102
        newrecord -> CreateFromFile(hashfile->owner,hashfile -> directory, hashfile -> name, 
105
        // TODO: What we are supposed to do if the following does fail?
103
			&m_endWaitingForHashList);
106
        newrecord -> CreateFromFile(hashfile -> directory, hashfile -> name, &m_endWaitingForHashList);
107
        if (!m_endWaitingForHashList)
104
        if (!m_endWaitingForHashList)
108
        {
105
        {
109
            wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, TM_FINISHEDHASHING);
106
            wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, TM_FINISHEDHASHING);
(-)xmule/src/BaseClient.cpp (-18 / +19 lines)
Lines 805-819 Link Here
805
805
806
void CUpDownClient:: SendHelloTypePacket(CMemFile *data)
806
void CUpDownClient:: SendHelloTypePacket(CMemFile *data)
807
{
807
{
808
/*
809
unsigned char *uh;
810
uh=(unsigned char *)theApp.glob_prefs->GetUserHash();
811
for(int i=0;i<16;i++) {
812
printf("  %02x",uh[i]);
813
}
814
printf("\n");
815
*/
816
817
    data -> Write(theApp.glob_prefs -> GetUserHash(), 16);
808
    data -> Write(theApp.glob_prefs -> GetUserHash(), 16);
818
    uint32 clientid = theApp.serverconnect -> GetClientID();
809
    uint32 clientid = theApp.serverconnect -> GetClientID();
819
    data -> Write( &clientid, 4);
810
    data -> Write( &clientid, 4);
Lines 881-888 Link Here
881
    tagVersion.WriteTagToFile(data);
872
    tagVersion.WriteTagToFile(data);
882
    CTag tagUDPports(CT_EMULE_UDPPORTS, (uint32) theApp.glob_prefs -> GetUDPPort());
873
    CTag tagUDPports(CT_EMULE_UDPPORTS, (uint32) theApp.glob_prefs -> GetUDPPort());
883
    tagUDPports.WriteTagToFile(data);
874
    tagUDPports.WriteTagToFile(data);
884
    CTag tagMuleVersion(CT_EMULE_VERSION, SO_XMULE << 24);
875
    if(!newprefs01_opt[3]) {
876
    	CTag tagMuleVersion(CT_EMULE_VERSION, 
877
		(SO_XMULE << 24)|(VERSION_MJR<<17)|(VERSION_MIN<<10)|(VERSION_UPDATE<<7));
878
        tagMuleVersion.WriteTagToFile(data);
879
    } else {
880
    	CTag tagMuleVersion(CT_EMULE_VERSION, 
881
		(SO_EMULE << 24)|(0<<17)|(42<<10)|(VERSION_UPDATE<<4));
885
    tagMuleVersion.WriteTagToFile(data);
882
    tagMuleVersion.WriteTagToFile(data);
883
    }
886
    const uint32 uUdpVer = 4;
884
    const uint32 uUdpVer = 4;
887
    const uint32 uDataCompVer = 1;
885
    const uint32 uDataCompVer = 1;
888
    const uint32 uSupportSecIdent = theApp.clientcredits -> CryptoAvailable() ?3: 0;
886
    const uint32 uSupportSecIdent = theApp.clientcredits -> CryptoAvailable() ?3: 0;
Lines 1300-1313 Link Here
1300
1298
1301
int CUpDownClient:: GetHashType()
1299
int CUpDownClient:: GetHashType()
1302
{
1300
{
1303
    if (m_achUserHash[5] == 13 &&m_achUserHash[14] == 110)
1301
    int retcode=0;
1304
    return SO_OLDEMULE;
1302
    if (m_achUserHash[5] == 13 &&m_achUserHash[14] == 110) {
1305
    else if(m_achUserHash[5] == 14 &&m_achUserHash[14] == 111)
1303
      retcode=SO_OLDEMULE;
1306
    return SO_EMULE;
1304
    } else if(m_achUserHash[5] == 14 &&m_achUserHash[14] == 111) {
1307
    else if(m_achUserHash[5] == 'M' &&m_achUserHash[14] == 'L')
1305
      retcode=SO_EMULE;
1308
    return SO_MLDONKEY;
1306
    } else if(m_achUserHash[5] == 'M' &&m_achUserHash[14] == 'L') {
1309
    else
1307
      retcode=SO_MLDONKEY;
1310
    return SO_UNKNOWN;
1308
    } else {
1309
      retcode=SO_UNKNOWN;
1310
    }
1311
    return retcode;
1311
}
1312
}
1312
1313
1313
void CUpDownClient:: SetUserName(char *pszNewName)
1314
void CUpDownClient:: SetUserName(char *pszNewName)
(-)xmule/src/ClientCredits.cpp (-3 / +2 lines)
Lines 19-26 Link Here
19
//along with this program; if not, write to the Free Software
19
//along with this program; if not, write to the Free Software
20
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
21
22
//#ifdef PRECOMP
22
#ifdef PRECOMP
23
#if 1
24
#	include "xmule-headers.h"
23
#	include "xmule-headers.h"
25
#else
24
#else
26
#	include "ClientCredits.h"
25
#	include "ClientCredits.h"
Lines 42-48 Link Here
42
#include <fcntl.h>
41
#include <fcntl.h>
43
#include <wx/utils.h>
42
#include <wx/utils.h>
44
43
45
#if 1
44
#ifndef __CRPP__
46
#	include "CryptoXMpp.h"
45
#	include "CryptoXMpp.h"
47
#else
46
#else
48
#	include <cryptopp/config.h>
47
#	include <cryptopp/config.h>
(-)xmule/src/ClientCredits.h (-3 / +3 lines)
Lines 26-37 Link Here
26
#include "Preferences.h"
26
#include "Preferences.h"
27
#include "MapKey.h"
27
#include "MapKey.h"
28
28
29
#if 1
29
#ifdef __CRPP__
30
#	include "CryptoXMpp.h"
31
#else
32
#	include	<cryptopp/cryptlib.h>
30
#	include	<cryptopp/cryptlib.h>
33
#	include	<cryptopp/rsa.h>
31
#	include	<cryptopp/rsa.h>
34
#define CryptoXMpp		CryptoPP
32
#define CryptoXMpp		CryptoPP
33
#else
34
#	include "CryptoXMpp.h"
35
#endif
35
#endif
36
36
37
/* winemaker: #pragma pack(1) */
37
/* winemaker: #pragma pack(1) */
(-)xmule/src/CryptoXMpp.cpp (-1 / +2 lines)
Lines 59-64 Link Here
59
 only the for xmule needed parts taken from cryptopp in 2004 by upload2010
59
 only the for xmule needed parts taken from cryptopp in 2004 by upload2010
60
    */
60
    */
61
61
62
#ifndef __CRPP__
62
#include <errno.h>
63
#include <errno.h>
63
#include <fcntl.h>
64
#include <fcntl.h>
64
#include <iomanip>
65
#include <iomanip>
Lines 9371-9374 Link Here
9371
}
9372
}
9372
9373
9373
}
9374
}
9374
9375
#endif
(-)xmule/src/CryptoXMpp.h (+2 lines)
Lines 72-77 Link Here
72
only the for xmule needed parts taken from cryptopp in 2004 by upload2010
72
only the for xmule needed parts taken from cryptopp in 2004 by upload2010
73
*/
73
*/
74
74
75
#ifndef __CRPP__
75
#ifndef CRYPTOPP_CONFIG_H
76
#ifndef CRYPTOPP_CONFIG_H
76
#define CRYPTOPP_CONFIG_H
77
#define CRYPTOPP_CONFIG_H
77
78
Lines 9440-9442 Link Here
9440
}
9441
}
9441
9442
9442
#endif
9443
#endif
9444
#endif
(-)xmule/src/DownloadClient.cpp (-183 / +139 lines)
Lines 47-55 Link Here
47
47
48
extern int newprefs03_opt[];
48
extern int newprefs03_opt[];
49
49
50
CBarShader CUpDownClient:: s_StatusBar(16);
50
CBarShader CUpDownClient::s_StatusBar(16);
51
51
52
void CUpDownClient:: DrawStatusBar(wxMemoryDC *dc, wxRect rect, bool onlygreyrect, bool bFlat)
52
void CUpDownClient::DrawStatusBar(wxMemoryDC * dc, wxRect rect, bool onlygreyrect, bool bFlat)
53
{
53
{
54
    DWORD crBoth;
54
    DWORD crBoth;
55
    DWORD crNeither;
55
    DWORD crNeither;
Lines 79-85 Link Here
79
    // Barry - was only showing one part from client, even when reserved bits from 2 parts
79
    // Barry - was only showing one part from client, even when reserved bits from 2 parts
80
    wxString gettingParts;
80
    wxString gettingParts;
81
    ShowDownloadingParts(gettingParts);
81
    ShowDownloadingParts(gettingParts);
82
    if (!onlygreyrect &&reqfile &&m_abyPartStatus)
82
    if (!onlygreyrect && reqfile && m_abyPartStatus)
83
    {
83
    {
84
        for (uint32 i = 0 ; i != m_nPartCount ; i++)
84
        for (uint32 i = 0 ; i != m_nPartCount ; i++)
85
        {
85
        {
Lines 90-121 Link Here
90
                uEnd = reqfile -> GetFileSize();
90
                uEnd = reqfile -> GetFileSize();
91
                else
91
                else
92
                uEnd = PARTSIZE * (i + 1);
92
                uEnd = PARTSIZE * (i + 1);
93
                if (reqfile -> IsComplete(PARTSIZE *i, PARTSIZE * (i + 1) - 1))
93
                if (reqfile -> IsComplete(PARTSIZE * i, PARTSIZE * (i + 1) - 1))
94
                s_StatusBar.FillRange(PARTSIZE *i, uEnd, crBoth);
94
                s_StatusBar.FillRange(PARTSIZE * i, uEnd, crBoth);
95
                else if(m_nDownloadState == DS_DOWNLOADING &&m_nLastBlockOffset < uEnd &&
95
                else if(m_nDownloadState == DS_DOWNLOADING && m_nLastBlockOffset < uEnd &&
96
                m_nLastBlockOffset >= PARTSIZE *i)
96
                m_nLastBlockOffset >= PARTSIZE * i)
97
                s_StatusBar.FillRange(PARTSIZE *i, uEnd, crPending);
97
                s_StatusBar.FillRange(PARTSIZE * i, uEnd, crPending);
98
                else if(gettingParts.GetChar(i) == 'Y')
98
                else if(gettingParts.GetChar(i) == 'Y')
99
                s_StatusBar.FillRange(PARTSIZE *i, uEnd, crNextPending);
99
                s_StatusBar.FillRange(PARTSIZE * i, uEnd, crNextPending);
100
                else
100
                else
101
                s_StatusBar.FillRange(PARTSIZE *i, uEnd, crClientOnly);
101
                s_StatusBar.FillRange(PARTSIZE * i, uEnd, crClientOnly);
102
            }
102
            }
103
        }
103
        }
104
    }
104
    }
105
    s_StatusBar.Draw(dc, rect.x, rect.y, bFlat);
105
    s_StatusBar.Draw(dc, rect.x, rect.y, bFlat);
106
}
106
}
107
107
108
bool CUpDownClient:: Compare(CUpDownClient *tocomp)
108
bool CUpDownClient::Compare(CUpDownClient * tocomp)
109
{
109
{
110
    if (HasValidHash() &&tocomp -> HasValidHash())
110
    if (HasValidHash() && tocomp -> HasValidHash())
111
    return !memcmp(this -> GetUserHash(), tocomp -> GetUserHash(), 16);
111
    return !memcmp(this -> GetUserHash(), tocomp -> GetUserHash(), 16);
112
    if (HasLowID())
112
    if (HasLowID())
113
    return((this -> GetUserID() == tocomp -> GetUserID()) && (GetServerIP() == tocomp -> GetServerIP()));
113
    return((this -> GetUserID() == tocomp -> GetUserID()) && (GetServerIP() == tocomp -> GetServerIP()));
114
    else
114
    else
115
    return(this -> GetUserID() == tocomp -> GetUserID() || (this -> GetIP() &&this -> GetIP() == tocomp -> GetIP()));
115
    return(this -> GetUserID() == tocomp -> GetUserID() || (this -> GetIP() && this -> GetIP() == tocomp -> GetIP()));
116
}
116
}
117
117
118
void CUpDownClient:: AskForDownload()
118
void CUpDownClient::AskForDownload()
119
{
119
{
120
    int rank = GetRemoteQueueRank();
120
    int rank = GetRemoteQueueRank();
121
    if (GetDownloadState() == DS_CONNECTING)
121
    if (GetDownloadState() == DS_CONNECTING)
Lines 126-133 Link Here
126
    {
126
    {
127
        m_cFailed = 0;
127
        m_cFailed = 0;
128
    }
128
    }
129
    bool hotrank = (rank &&rank < 5);
129
    bool hotrank = (rank && rank < 5);
130
    if (theApp.listensocket -> TooManySockets(hotrank) && ! (socket &&socket -> IsConnected()))
130
    if (theApp.listensocket -> TooManySockets(hotrank) && ! (socket && socket -> IsConnected()))
131
    {
131
    {
132
        if (GetDownloadState() != DS_TOOMANYCONNS)
132
        if (GetDownloadState() != DS_TOOMANYCONNS)
133
        {
133
        {
Lines 141-147 Link Here
141
            socket -> hotrank = hotrank;
141
            socket -> hotrank = hotrank;
142
        }
142
        }
143
        m_bUDPPending = false;
143
        m_bUDPPending = false;
144
        m_dwLastAskedTime =:: GetTickCount();
144
        m_dwLastAskedTime =::GetTickCount();
145
        if (m_cFailed < 3)
145
        if (m_cFailed < 3)
146
        {
146
        {
147
            SetDownloadState(DS_CONNECTING);
147
            SetDownloadState(DS_CONNECTING);
Lines 156-170 Link Here
156
    }
156
    }
157
}
157
}
158
158
159
bool CUpDownClient:: IsSourceRequestAllowed()
159
bool CUpDownClient::IsSourceRequestAllowed()
160
{
160
{
161
    DWORD dwTickCount =:: GetTickCount() + CONNECTION_LATENCY;
161
    DWORD dwTickCount =::GetTickCount() + CONNECTION_LATENCY;
162
    int nTimePassedClient = dwTickCount - GetLastSrcAnswerTime();
162
    int nTimePassedClient = dwTickCount - GetLastSrcAnswerTime();
163
    int nTimePassedFile = dwTickCount - reqfile -> GetLastAnsweredTime();
163
    int nTimePassedFile = dwTickCount - reqfile -> GetLastAnsweredTime();
164
    bool bNeverAskedBefore = GetLastSrcReqTime() == 0;
164
    bool bNeverAskedBefore = GetLastSrcReqTime() == 0;
165
    return(
165
    return(
166
    //if client has the correct extended protocol
166
    //if client has the correct extended protocol
167
    ExtProtocolAvailable() &&m_bySourceExchangeVer >= 1 &&
167
    ExtProtocolAvailable() && m_bySourceExchangeVer >= 1 &&
168
    //AND if we need more sources
168
    //AND if we need more sources
169
    theApp.glob_prefs -> GetMaxSourcePerFileSoft() > reqfile -> GetSourceCount() &&
169
    theApp.glob_prefs -> GetMaxSourcePerFileSoft() > reqfile -> GetSourceCount() &&
170
    //AND if...
170
    //AND if...
Lines 172-196 Link Here
172
    //source is not complete and file is rare, allow once every 10 minutes
172
    //source is not complete and file is rare, allow once every 10 minutes
173
    (!m_bCompleteSource &&
173
    (!m_bCompleteSource &&
174
    (reqfile -> GetSourceCount() - reqfile -> GetValidSourcesCount() <= RARE_FILE / 4 ||
174
    (reqfile -> GetSourceCount() - reqfile -> GetValidSourcesCount() <= RARE_FILE / 4 ||
175
    reqfile -> GetSourceCount() <= RARE_FILE *2
175
    reqfile -> GetSourceCount() <= RARE_FILE * 2
176
    ) &&
176
    ) &&
177
    (bNeverAskedBefore || nTimePassedClient > SOURCECLIENTREASK)
177
    (bNeverAskedBefore || nTimePassedClient > SOURCECLIENTREASK)
178
    ) ||
178
    ) ||
179
    // otherwise, allow every 90 minutes, but only if we haven't
179
    // otherwise, allow every 90 minutes, but only if we haven't
180
    //   asked someone else in last 10 minutes
180
    //   asked someone else in last 10 minutes
181
    ((bNeverAskedBefore || nTimePassedClient > SOURCECLIENTREASK *reqfile -> GetCommonFilePenalty()) &&
181
    ((bNeverAskedBefore || nTimePassedClient > SOURCECLIENTREASK * reqfile -> GetCommonFilePenalty()) &&
182
    (nTimePassedFile > SOURCECLIENTREASK)
182
    (nTimePassedFile > SOURCECLIENTREASK)
183
    )
183
    )
184
    )
184
    )
185
    );
185
    );
186
}
186
}
187
187
188
void CUpDownClient:: SendFileRequest()
188
void CUpDownClient::SendFileRequest()
189
{
189
{
190
    if (reqfile)
190
    if (reqfile)
191
    {
191
    {
192
        AddAskedCountDown();
192
        AddAskedCountDown();
193
        CSafeMemFile *dataFileReq;
193
        CSafeMemFile * dataFileReq;
194
        if (newprefs02_opt[1])
194
        if (newprefs02_opt[1])
195
        {
195
        {
196
            dataFileReq = new CSafeMemFile(32);
196
            dataFileReq = new CSafeMemFile(32);
Lines 221-227 Link Here
221
        {
221
        {
222
            CSafeMemFile dataSetReqFileID(16);
222
            CSafeMemFile dataSetReqFileID(16);
223
            dataSetReqFileID.Write(reqfile -> GetFileHash(), 16);
223
            dataSetReqFileID.Write(reqfile -> GetFileHash(), 16);
224
            NewSocket_SendPacketOPdata(2, OP_SETREQFILEID, &dataSetReqFileID, (wxUint32) this, 0);
224
            NewSocket_SendPacketOPdata(2, OP_SETREQFILEID, & dataSetReqFileID, (wxUint32) this, 0);
225
        }
225
        }
226
        if (IsEmuleClient())
226
        if (IsEmuleClient())
227
        {
227
        {
Lines 233-239 Link Here
233
            if (IsSourceRequestAllowed())
233
            if (IsSourceRequestAllowed())
234
            {
234
            {
235
                reqfile -> SetLastAnsweredTimeTimeout();
235
                reqfile -> SetLastAnsweredTimeTimeout();
236
                Packet *packet = new Packet(OP_REQUESTSOURCES, 16, OP_EMULEPROT);
236
                Packet * packet = new Packet(OP_REQUESTSOURCES, 16, OP_EMULEPROT);
237
                md4cpy(packet -> pBuffer, reqfile -> GetFileHash());
237
                md4cpy(packet -> pBuffer, reqfile -> GetFileHash());
238
                NewSocket_SendPacketOP(2, OP_REQUESTSOURCES, packet, (wxUint32) this, 0);
238
                NewSocket_SendPacketOP(2, OP_REQUESTSOURCES, packet, (wxUint32) this, 0);
239
                SetLastAskedForSources();
239
                SetLastAskedForSources();
Lines 242-255 Link Here
242
    }
242
    }
243
}
243
}
244
244
245
void CUpDownClient:: ProcessFileInfo(char *packet, uint32 size)
245
void CUpDownClient::ProcessFileInfo(char * packet, uint32 size)
246
{
246
{
247
    CSafeMemFile *data = new CSafeMemFile((BYTE *) packet, size);
247
    CSafeMemFile * data = new CSafeMemFile((BYTE *) packet, size);
248
    uchar cfilehash[16];
248
    uchar cfilehash[16];
249
    data -> Read(cfilehash, 16);
249
    data -> Read(cfilehash, 16);
250
    uint16 namelength;
250
    uint16 namelength;
251
    data -> Read( &namelength, 2);
251
    data -> Read( & namelength, 2);
252
    if (m_pszClientFilename) {
252
    if (m_pszClientFilename)
253
    {
253
    delete[] m_pszClientFilename;
254
    delete[] m_pszClientFilename;
254
	}
255
	}
255
    m_pszClientFilename = new char[namelength + 1];
256
    m_pszClientFilename = new char[namelength + 1];
Lines 260-273 Link Here
260
    delete data;
261
    delete data;
261
}
262
}
262
263
263
void CUpDownClient:: ProcessFileStatus(char *packet, uint32 size)
264
void CUpDownClient::ProcessFileStatus(char * packet, uint32 size)
264
{
265
{
265
    CSafeMemFile *data = new CSafeMemFile((BYTE *) packet, size);
266
    CSafeMemFile * data = new CSafeMemFile((BYTE *) packet, size);
266
    uchar cfilehash[16];
267
    uchar cfilehash[16];
267
    data -> Read(cfilehash, 16);
268
    data -> Read(cfilehash, 16);
268
    if ((reqfile) && (! memcmp(cfilehash, reqfile -> GetFileHash(), 16)))
269
    if ((reqfile) && (!memcmp(cfilehash, reqfile -> GetFileHash(), 16)))
269
    {
270
    {
270
        data -> Read( &m_nPartCount, 2);
271
        data -> Read( & m_nPartCount, 2);
271
        if (m_abyPartStatus)
272
        if (m_abyPartStatus)
272
        {
273
        {
273
            delete[] m_abyPartStatus;
274
            delete[] m_abyPartStatus;
Lines 292-302 Link Here
292
                while (done != m_nPartCount)
293
                while (done != m_nPartCount)
293
                {
294
                {
294
                    uint8 toread;
295
                    uint8 toread;
295
                    data -> Read( &toread, 1);
296
                    data -> Read( & toread, 1);
296
                    for (sint32 i = 0 ; i != 8 ; i++)
297
                    for (sint32 i = 0 ; i != 8 ; i++)
297
                    {
298
                    {
298
                        m_abyPartStatus[done] = ((toread >> i) &1) ? 1: 0;
299
                        m_abyPartStatus[done] = ((toread >> i) & 1) ? 1: 0;
299
                        if (m_abyPartStatus[done] && !reqfile -> IsComplete(done *PARTSIZE, ((done + 1) *PARTSIZE) - 1))
300
                        if (m_abyPartStatus[done] && !reqfile -> IsComplete(done * PARTSIZE, ((done + 1) * PARTSIZE) - 1))
300
                        bPartsNeeded = true;
301
                        bPartsNeeded = true;
301
                        done++;
302
                        done++;
302
                        if (done == m_nPartCount)
303
                        if (done == m_nPartCount)
Lines 311-320 Link Here
311
        if (!bPartsNeeded)
312
        if (!bPartsNeeded)
312
        {
313
        {
313
            SetDownloadState(DS_NONEEDEDPARTS);
314
            SetDownloadState(DS_NONEEDEDPARTS);
315
	    if(reqfile->GetDownPriority()==PR_LOW) {
316
	    	SwapToAnotherFile();
317
	    }
314
        }
318
        }
315
        else if(reqfile -> hashsetneeded)
319
        else if(reqfile -> hashsetneeded)
316
        {
320
        {
317
            Packet *packet = new Packet(OP_HASHSETREQUEST, 16);
321
            Packet * packet = new Packet(OP_HASHSETREQUEST, 16);
318
            memcpy(packet -> pBuffer, reqfile -> GetFileHash(), 16);
322
            memcpy(packet -> pBuffer, reqfile -> GetFileHash(), 16);
319
            NewSocket_SendPacketOP(2, OP_HASHSETREQUEST, packet, (wxUint32) this, 0);
323
            NewSocket_SendPacketOP(2, OP_HASHSETREQUEST, packet, (wxUint32) this, 0);
320
            SetDownloadState(DS_REQHASHSET);
324
            SetDownloadState(DS_REQHASHSET);
Lines 334-340 Link Here
334
    delete data;
338
    delete data;
335
}
339
}
336
340
337
bool CUpDownClient:: AddRequestForAnotherFile(CPartFile *file)
341
bool CUpDownClient::AddRequestForAnotherFile(CPartFile * file)
338
{
342
{
339
    for (POSITION pos = m_OtherNoNeeded_list.GetHeadPosition() ; pos != 0 ; m_OtherNoNeeded_list.GetNext(pos))
343
    for (POSITION pos = m_OtherNoNeeded_list.GetHeadPosition() ; pos != 0 ; m_OtherNoNeeded_list.GetNext(pos))
340
    {
344
    {
Lines 352-358 Link Here
352
    return true;
356
    return true;
353
}
357
}
354
358
355
void CUpDownClient:: SetDownloadState(uint8 byNewState)
359
void CUpDownClient::SetDownloadState(uint8 byNewState)
356
{
360
{
357
    if (m_nDownloadState != byNewState)
361
    if (m_nDownloadState != byNewState)
358
    {
362
    {
Lines 371-384 Link Here
371
            m_nDownloadState = byNewState;
375
            m_nDownloadState = byNewState;
372
            for (POSITION pos = m_DownloadBlocks_list.GetHeadPosition() ; pos != 0 ; m_DownloadBlocks_list.GetNext(pos))
376
            for (POSITION pos = m_DownloadBlocks_list.GetHeadPosition() ; pos != 0 ; m_DownloadBlocks_list.GetNext(pos))
373
            {
377
            {
374
                Requested_Block_Struct *cur_block = m_DownloadBlocks_list.GetAt(pos);
378
                Requested_Block_Struct * cur_block = m_DownloadBlocks_list.GetAt(pos);
375
                reqfile -> RemoveBlockFromList(cur_block -> StartOffset, cur_block -> EndOffset);
379
                reqfile -> RemoveBlockFromList(cur_block -> StartOffset, cur_block -> EndOffset);
376
                delete m_DownloadBlocks_list.GetAt(pos);
380
                delete m_DownloadBlocks_list.GetAt(pos);
377
            }
381
            }
378
            m_DownloadBlocks_list.RemoveAll();
382
            m_DownloadBlocks_list.RemoveAll();
379
            for (POSITION pos = m_PendingBlocks_list.GetHeadPosition() ; pos != 0 ; m_PendingBlocks_list.GetNext(pos))
383
            for (POSITION pos = m_PendingBlocks_list.GetHeadPosition() ; pos != 0 ; m_PendingBlocks_list.GetNext(pos))
380
            {
384
            {
381
                Pending_Block_Struct *pending = m_PendingBlocks_list.GetAt(pos);
385
                Pending_Block_Struct * pending = m_PendingBlocks_list.GetAt(pos);
382
                if (reqfile)
386
                if (reqfile)
383
                reqfile -> RemoveBlockFromList(pending -> block -> StartOffset, pending -> block -> EndOffset);
387
                reqfile -> RemoveBlockFromList(pending -> block -> StartOffset, pending -> block -> EndOffset);
384
                delete pending -> block;
388
                delete pending -> block;
Lines 398-404 Link Here
398
                delete[] m_abyPartStatus;
402
                delete[] m_abyPartStatus;
399
                m_abyPartStatus = 0;
403
                m_abyPartStatus = 0;
400
            }
404
            }
401
            if (socket &&byNewState != DS_ERROR)
405
            if (socket && byNewState != DS_ERROR)
402
            socket -> DisableDownloadLimit();
406
            socket -> DisableDownloadLimit();
403
        }
407
        }
404
        m_nDownloadState = byNewState;
408
        m_nDownloadState = byNewState;
Lines 422-435 Link Here
422
    }
426
    }
423
}
427
}
424
428
425
void CUpDownClient:: ProcessHashSet(unsigned char *packet, uint32 size)
429
void CUpDownClient::ProcessHashSet(unsigned char * packet, uint32 size)
426
{
430
{
427
    if (reqfile && (!memcmp(packet, reqfile -> GetFileHash(), 16)))
431
    if (reqfile && (!memcmp(packet, reqfile -> GetFileHash(), 16)))
428
    {
432
    {
429
        if (m_bHashsetRequested)
433
        if (m_bHashsetRequested)
430
        {
434
        {
431
            m_bHashsetRequested = false;
435
            m_bHashsetRequested = false;
432
            CSafeMemFile *data = new CSafeMemFile((BYTE *) packet, size);
436
            CSafeMemFile * data = new CSafeMemFile((BYTE *) packet, size);
433
            if (reqfile -> LoadHashsetFromFile(data, true))
437
            if (reqfile -> LoadHashsetFromFile(data, true))
434
            {
438
            {
435
                SetDownloadState(DS_ONQUEUE);
439
                SetDownloadState(DS_ONQUEUE);
Lines 447-463 Link Here
447
    }
451
    }
448
}
452
}
449
453
450
void CUpDownClient:: SendBlockRequests()
454
void CUpDownClient::SendBlockRequests()
451
{
455
{
452
    m_dwLastBlockReceived =:: GetTickCount();
456
    m_dwLastBlockReceived =::GetTickCount();
453
    if (reqfile)
457
    if (reqfile)
454
    {
458
    {
455
        if (m_DownloadBlocks_list.IsEmpty())
459
        if (m_DownloadBlocks_list.IsEmpty())
456
        {
460
        {
457
            // Barry - instead of getting 3, just get how many is needed
461
            // Barry - instead of getting 3, just get how many is needed
458
            uint16 count = 3 - m_PendingBlocks_list.GetCount();
462
            uint16 count = 3 - m_PendingBlocks_list.GetCount();
459
            Requested_Block_Struct **toadd = new Requested_Block_Struct *[count];
463
            Requested_Block_Struct ** toadd = new Requested_Block_Struct *[count];
460
            if (reqfile -> GetNextRequestedBlock(this, toadd, &count))
464
            if (reqfile -> GetNextRequestedBlock(this, toadd, & count))
461
            {
465
            {
462
                for (int i = 0 ; i != count ; i++)
466
                for (int i = 0 ; i != count ; i++)
463
                m_DownloadBlocks_list.AddTail(toadd[i]);
467
                m_DownloadBlocks_list.AddTail(toadd[i]);
Lines 467-473 Link Here
467
        // Barry - Why are unfinished blocks requested again, not just new ones?
471
        // Barry - Why are unfinished blocks requested again, not just new ones?
468
        while (m_PendingBlocks_list.GetCount() < 3 && !m_DownloadBlocks_list.IsEmpty())
472
        while (m_PendingBlocks_list.GetCount() < 3 && !m_DownloadBlocks_list.IsEmpty())
469
        {
473
        {
470
            Pending_Block_Struct *pblock = new Pending_Block_Struct;
474
            Pending_Block_Struct * pblock = new Pending_Block_Struct;
471
            pblock -> block = m_DownloadBlocks_list.RemoveHead();
475
            pblock -> block = m_DownloadBlocks_list.RemoveHead();
472
            pblock -> zStream = NULL;
476
            pblock -> zStream = NULL;
473
            pblock -> totalUnzipped = 0;
477
            pblock -> totalUnzipped = 0;
Lines 478-502 Link Here
478
        {
482
        {
479
            NewSocket_SendPacketOPdata(2, OP_CANCELTRANSFER, NULL, (wxUint32) this, 0);
483
            NewSocket_SendPacketOPdata(2, OP_CANCELTRANSFER, NULL, (wxUint32) this, 0);
480
            SetDownloadState(DS_NONEEDEDPARTS);
484
            SetDownloadState(DS_NONEEDEDPARTS);
485
	    if(reqfile->GetDownPriority()==PR_LOW) {
486
	      SwapToAnotherFile();
487
	    }
481
        }
488
        }
482
        else
489
        else
483
        {
490
        {
484
            CMemFile *data = new CMemFile(40);
491
            CMemFile * data = new CMemFile(40);
485
            data -> Write(reqfile -> GetFileHash(), 16);
492
            data -> Write(reqfile -> GetFileHash(), 16);
486
            POSITION pos = m_PendingBlocks_list.GetHeadPosition();
493
            POSITION pos = m_PendingBlocks_list.GetHeadPosition();
487
            uint32 null = 0;
494
            uint32 null = 0;
488
            Requested_Block_Struct *block;
495
            Requested_Block_Struct * block;
489
            for (uint32 i = 0 ; i != 3 ; i++)
496
            for (uint32 i = 0 ; i != 3 ; i++)
490
            {
497
            {
491
                if (pos)
498
                if (pos)
492
                {
499
                {
493
                    block = m_PendingBlocks_list.GetAt(pos) -> block;
500
                    block = m_PendingBlocks_list.GetAt(pos) -> block;
494
                    m_PendingBlocks_list.GetNext(pos);
501
                    m_PendingBlocks_list.GetNext(pos);
495
                    data -> Write( &block -> StartOffset, 4);
502
                    data -> Write( & block -> StartOffset, 4);
496
                }
503
                }
497
                else
504
                else
498
                {
505
                {
499
                    data -> Write( &null, 4);
506
                    data -> Write( & null, 4);
500
                }
507
                }
501
            }
508
            }
502
            pos = m_PendingBlocks_list.GetHeadPosition();
509
            pos = m_PendingBlocks_list.GetHeadPosition();
Lines 507-517 Link Here
507
                    block = m_PendingBlocks_list.GetAt(pos) -> block;
514
                    block = m_PendingBlocks_list.GetAt(pos) -> block;
508
                    m_PendingBlocks_list.GetNext(pos);
515
                    m_PendingBlocks_list.GetNext(pos);
509
                    uint32 endpos = block -> EndOffset + 1;
516
                    uint32 endpos = block -> EndOffset + 1;
510
                    data -> Write( &endpos, 4);
517
                    data -> Write( & endpos, 4);
511
                }
518
                }
512
                else
519
                else
513
                {
520
                {
514
                    data -> Write( &null, 4);
521
                    data -> Write( & null, 4);
515
                }
522
                }
516
            }
523
            }
517
            NewSocket_SendPacketOPdata(2, OP_REQUESTPARTS, data, (wxUint32) this, 0);
524
            NewSocket_SendPacketOPdata(2, OP_REQUESTPARTS, data, (wxUint32) this, 0);
Lines 519-608 Link Here
519
    }
526
    }
520
}
527
}
521
528
522
void CUpDownClient:: ProcessBlockPacket(char *packet, uint32 size, bool packed)
529
void CUpDownClient::ProcessBlockPacket(char * packet, uint32 size, bool packed)
523
{
530
{
524
    // Ignore if no data required
531
    // Ignore if no data required
525
    if (! (GetDownloadState() == DS_DOWNLOADING || GetDownloadState() == DS_NONEEDEDPARTS))
532
    if (GetDownloadState() == DS_DOWNLOADING || GetDownloadState() == DS_NONEEDEDPARTS)
526
    return;
533
    {
527
    const int HEADER_SIZE = 24;
534
    const int HEADER_SIZE = 24;
528
    // Update stats
535
        m_dwLastBlockReceived =::GetTickCount();
529
    m_dwLastBlockReceived =:: GetTickCount();
536
        CSafeMemFile * data = new CSafeMemFile((BYTE *) packet, size);
530
    // Read data from packet
531
    CSafeMemFile *data = new CSafeMemFile((BYTE *) packet, size);
532
    uchar fileID[16];
537
    uchar fileID[16];
533
    data -> Read(fileID, 16);
538
    data -> Read(fileID, 16);
534
    // Check that this data is for the correct file
539
        if (reqfile && (!memcmp(packet, reqfile -> GetFileHash(), 16)))
535
    if (reqfile && (! memcmp(packet, reqfile -> GetFileHash(), 16)))
536
    {
540
    {
537
        // Find the start & end positions, and size of this chunk of data
538
        uint32 nStartPos;
541
        uint32 nStartPos;
539
        uint32 nEndPos;
542
        uint32 nEndPos;
540
        uint32 nBlockSize = 0;
543
        uint32 nBlockSize = 0;
541
        data -> Read( &nStartPos, 4);
544
            data -> Read( & nStartPos, 4);
542
        if (packed)
545
        if (packed)
543
        {
546
        {
544
            data -> Read( &nBlockSize, 4);
547
                data -> Read( & nBlockSize, 4);
545
            nEndPos = nStartPos + (size - HEADER_SIZE);
548
            nEndPos = nStartPos + (size - HEADER_SIZE);
546
            usedcompressiondown = true;
549
            usedcompressiondown = true;
547
        }
550
        }
548
        else
551
        else
549
        {
552
        {
550
            data -> Read( &nEndPos, 4);
553
                data -> Read( & nEndPos, 4);
551
        }
554
        }
552
        // Check that packet size matches the declared data size + header size (24)
555
        // Check that packet size matches the declared data size + header size (24)
553
        if (size == ((nEndPos - nStartPos) + HEADER_SIZE))
556
        if (size == ((nEndPos - nStartPos) + HEADER_SIZE))
554
        {
557
        {
555
            // Move end back one, should be inclusive
556
            theApp.UpdateReceivedBytes(size - HEADER_SIZE);
558
            theApp.UpdateReceivedBytes(size - HEADER_SIZE);
557
            m_nDownDataRateMS += size - HEADER_SIZE;
559
            m_nDownDataRateMS += size - HEADER_SIZE;
558
            credits -> AddDownloaded(size - HEADER_SIZE, GetIP());
560
            credits -> AddDownloaded(size - HEADER_SIZE, GetIP());
559
            nEndPos--;
561
            nEndPos--;
560
            // Loop through to find the reserved block that this is within
562
                Pending_Block_Struct * cur_block;
561
            Pending_Block_Struct *cur_block;
563
                for (POSITION pos = m_PendingBlocks_list.GetHeadPosition() ;
562
            for (POSITION pos = m_PendingBlocks_list.GetHeadPosition() ; pos != NULL ; m_PendingBlocks_list.GetNext(pos))
564
                pos != NULL ; m_PendingBlocks_list.GetNext(pos))
563
            {
565
            {
564
                cur_block = m_PendingBlocks_list.GetAt(pos);
566
                cur_block = m_PendingBlocks_list.GetAt(pos);
565
                if ((cur_block -> block -> StartOffset <= nStartPos) && (cur_block -> block -> EndOffset >= nStartPos))
567
                    if ((cur_block -> block -> StartOffset <= nStartPos) &&
568
                    (cur_block -> block -> EndOffset >= nStartPos))
566
                {
569
                {
567
                    // Found reserved block
568
                    if (cur_block -> bZStreamError)
570
                    if (cur_block -> bZStreamError)
569
                    {
571
                    {
570
                        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());
572
                        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());
571
                        reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset, cur_block -> block -> EndOffset);
573
                        reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset, cur_block -> block -> EndOffset);
572
                        return;
574
                        return;
573
                    }
575
                    }
574
                    // Remember this start pos, used to draw part downloading in list
575
                    m_nLastBlockOffset = nStartPos;
576
                    m_nLastBlockOffset = nStartPos;
576
                    // Occasionally packets are duplicated, no point writing it twice
577
                    // This will be 0 in these cases, or the length written otherwise
578
                    uint32 lenWritten = 0;
577
                    uint32 lenWritten = 0;
579
                    // Handle differently depending on whether packed or not
580
                    if (!packed)
578
                    if (!packed)
581
                    {
579
                    {
582
                        // Write to disk (will be buffered in part file class)
583
                        lenWritten = reqfile -> WriteToBuffer(size - HEADER_SIZE,
580
                        lenWritten = reqfile -> WriteToBuffer(size - HEADER_SIZE,
584
                        (BYTE *)(packet + HEADER_SIZE),
581
                        (BYTE *)(packet + HEADER_SIZE),
585
                        nStartPos,
582
                        nStartPos,
586
                        nEndPos,
583
                        nEndPos,
587
                        cur_block -> block);
584
                        cur_block -> block);
588
                        // Packed:
589
                    }
585
                    }
590
                    else
586
                    else
591
                    {
587
                    {
592
                        // Create space to store unzipped data, the size is only an initial guess, will be resized in unzip() if not big enough
588
                            uint32 lenUnzipped = (size * 2);
593
                        uint32 lenUnzipped = (size *2);
594
                        // Don't get too big
595
                        if (lenUnzipped > (GAPBLOCKSIZE + 300))
589
                        if (lenUnzipped > (GAPBLOCKSIZE + 300))
590
                            {
596
                        lenUnzipped = (GAPBLOCKSIZE + 300);
591
                        lenUnzipped = (GAPBLOCKSIZE + 300);
597
                        BYTE *unzipped = new BYTE[lenUnzipped];
592
                            }
598
                        // Try to unzip the packet
593
                            BYTE * unzipped = new BYTE[lenUnzipped];
599
                        int result = unzip(cur_block, (BYTE *)(packet + HEADER_SIZE), (size - HEADER_SIZE), &unzipped, &lenUnzipped);
594
                            int result = unzip(cur_block, (BYTE *)(packet + HEADER_SIZE), (size - HEADER_SIZE), & unzipped, & lenUnzipped);
600
                        if (result == Z_OK)
595
                        if (result == Z_OK)
601
                        {
596
                        {
602
                            // Write any unzipped data to disk
603
                            if (lenUnzipped > 0)
597
                            if (lenUnzipped > 0)
604
                            {
598
                            {
605
                                // Use the current start and end positions for the uncompressed data
606
                                nStartPos = cur_block -> block -> StartOffset + cur_block -> totalUnzipped - lenUnzipped;
599
                                nStartPos = cur_block -> block -> StartOffset + cur_block -> totalUnzipped - lenUnzipped;
607
                                nEndPos = cur_block -> block -> StartOffset + cur_block -> totalUnzipped - 1;
600
                                nEndPos = cur_block -> block -> StartOffset + cur_block -> totalUnzipped - 1;
608
                                if (nStartPos > cur_block -> block -> EndOffset || nEndPos > cur_block -> block -> EndOffset)
601
                                if (nStartPos > cur_block -> block -> EndOffset || nEndPos > cur_block -> block -> EndOffset)
Lines 612-618 Link Here
612
                                }
605
                                }
613
                                else
606
                                else
614
                                {
607
                                {
615
                                    // Write uncompressed data to file
616
                                    lenWritten = reqfile -> WriteToBuffer(size - HEADER_SIZE,
608
                                    lenWritten = reqfile -> WriteToBuffer(size - HEADER_SIZE,
617
                                    unzipped,
609
                                    unzipped,
618
                                    nStartPos,
610
                                    nStartPos,
Lines 624-658 Link Here
624
                        else
616
                        else
625
                        {
617
                        {
626
                            CString strZipError;
618
                            CString strZipError;
627
                            if (cur_block -> zStream &&cur_block -> zStream -> msg)
619
                                if (cur_block -> zStream && cur_block -> zStream -> msg)
628
                            strZipError.Format(_T(" - %s"), cur_block -> zStream -> msg);
620
                            strZipError.Format(_T(" - %s"), cur_block -> zStream -> msg);
629
                            theApp.xmuledlg -> AddDebugLogLine(false, GetResString(IDS_ERR_CORRUPTCOMPRPKG) + strZipError, reqfile -> GetFileName(), result);
621
                                theApp.xmuledlg -> AddDebugLogLine(false, GetResString(IDS_ERR_CORRUPTCOMPRPKG)
630
                            reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset, cur_block -> block -> EndOffset);
622
                                + strZipError, reqfile -> GetFileName(), result);
631
                            // If we had an zstream error, there is no chance that we could recover from it nor that we
623
                                reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset,
632
                            // could use the current zstream (which is in error state) any longer.
624
                                cur_block -> block -> EndOffset);
633
                            if (cur_block -> zStream)
625
                            if (cur_block -> zStream)
634
                            {
626
                            {
635
                                inflateEnd(cur_block -> zStream);
627
                                inflateEnd(cur_block -> zStream);
636
                                delete cur_block -> zStream;
628
                                delete cur_block -> zStream;
637
                                cur_block -> zStream = NULL;
629
                                cur_block -> zStream = NULL;
638
                            }
630
                            }
639
                            // Although we can't further use the current zstream, there is no need to disconnect the sending
640
                            // client because the next zstream (a series of 10K-blocks which build a 180K-block) could be
641
                            // valid again. Just ignore all further blocks for the current zstream.
642
                            cur_block -> bZStreamError = true;
631
                            cur_block -> bZStreamError = true;
643
                        }
632
                        }
644
                        delete [] unzipped;
633
                        delete [] unzipped;
645
                    }
634
                    }
646
                    // These checks only need to be done if any data was written
647
                    if (lenWritten > 0)
635
                    if (lenWritten > 0)
648
                    {
636
                    {
649
                        m_nTransferedDown += lenWritten;
637
                        m_nTransferedDown += lenWritten;
650
                        // If finished reserved block
651
                        if (nEndPos == cur_block -> block -> EndOffset)
638
                        if (nEndPos == cur_block -> block -> EndOffset)
652
                        {
639
                        {
653
                            reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset, cur_block -> block -> EndOffset);
640
                                reqfile -> RemoveBlockFromList(cur_block -> block -> StartOffset,
641
                                cur_block -> block -> EndOffset);
654
                            delete cur_block -> block;
642
                            delete cur_block -> block;
655
                            // Not always allocated
656
                            if (cur_block -> zStream)
643
                            if (cur_block -> zStream)
657
                            {
644
                            {
658
                                inflateEnd(cur_block -> zStream);
645
                                inflateEnd(cur_block -> zStream);
Lines 660-685 Link Here
660
                            }
647
                            }
661
                            delete cur_block;
648
                            delete cur_block;
662
                            m_PendingBlocks_list.RemoveAt(pos);
649
                            m_PendingBlocks_list.RemoveAt(pos);
663
                            // Request next block
664
                            SendBlockRequests();
650
                            SendBlockRequests();
665
                        }
651
                        }
666
                    }
652
                    }
667
                    // Stop looping and exit method
668
                    return;
653
                    return;
669
                }
654
                }
670
            }
655
            }
671
        }
656
        }
672
    }
657
    }
673
    delete data;
658
    delete data;
659
    }
674
}
660
}
675
661
676
int CUpDownClient:: unzip(Pending_Block_Struct *block, BYTE *zipped, uint32 lenZipped, BYTE **unzipped, uint32 *lenUnzipped, bool recursive)
662
int CUpDownClient::unzip(Pending_Block_Struct * block, BYTE * zipped, uint32 lenZipped, BYTE ** unzipped, uint32 * lenUnzipped, bool recursive)
677
{
663
{
678
    int err = Z_DATA_ERROR;
664
    int err = Z_DATA_ERROR;
679
    try
665
    try
680
    {
666
    {
681
        // Save some typing
667
        // Save some typing
682
        z_stream *zS = block -> zStream;
668
        z_stream * zS = block -> zStream;
683
        // Is this the first time this block has been unzipped
669
        // Is this the first time this block has been unzipped
684
        if (zS == NULL)
670
        if (zS == NULL)
685
        {
671
        {
Lines 691-698 Link Here
691
            zS -> zfree = (free_func) 0;
677
            zS -> zfree = (free_func) 0;
692
            zS -> opaque = (voidpf) 0;
678
            zS -> opaque = (voidpf) 0;
693
            // Set output data streams, do this here to avoid overwriting on recursive calls
679
            // Set output data streams, do this here to avoid overwriting on recursive calls
694
            zS -> next_out = ( *unzipped);
680
            zS -> next_out = ( * unzipped);
695
            zS -> avail_out = ( *lenUnzipped);
681
            zS -> avail_out = ( * lenUnzipped);
696
            // Initialise the z_stream
682
            // Initialise the z_stream
697
            err = inflateInit(zS);
683
            err = inflateInit(zS);
698
            if (err != Z_OK)
684
            if (err != Z_OK)
Lines 704-711 Link Here
704
        // Only set the output if not being called recursively
690
        // Only set the output if not being called recursively
705
        if (!recursive)
691
        if (!recursive)
706
        {
692
        {
707
            zS -> next_out = ( *unzipped);
693
            zS -> next_out = ( * unzipped);
708
            zS -> avail_out = ( *lenUnzipped);
694
            zS -> avail_out = ( * lenUnzipped);
709
        }
695
        }
710
        // Try to unzip the data
696
        // Try to unzip the data
711
        err = inflate(zS, Z_SYNC_FLUSH);
697
        err = inflate(zS, Z_SYNC_FLUSH);
Lines 717-741 Link Here
717
            if (err != Z_OK)
703
            if (err != Z_OK)
718
            return err;
704
            return err;
719
            // Got a good result, set the size to the amount unzipped in this call (including all recursive calls)
705
            // Got a good result, set the size to the amount unzipped in this call (including all recursive calls)
720
            ( *lenUnzipped) = (zS -> total_out - block -> totalUnzipped);
706
            ( * lenUnzipped) = (zS -> total_out - block -> totalUnzipped);
721
            block -> totalUnzipped = zS -> total_out;
707
            block -> totalUnzipped = zS -> total_out;
722
        }
708
        }
723
        else if((err == Z_OK) && (zS -> avail_out == 0))
709
        else if((err == Z_OK) && (zS -> avail_out == 0))
724
        {
710
        {
725
            // Output array was not big enough, call recursively until there is enough space
711
            // Output array was not big enough, call recursively until there is enough space
726
            // What size should we try next
712
            // What size should we try next
727
            uint32 newLength = ( *lenUnzipped) *= 2;
713
            uint32 newLength = ( * lenUnzipped) *= 2;
728
            if (newLength == 0)
714
            if (newLength == 0)
729
            newLength = lenZipped *2;
715
            newLength = lenZipped * 2;
730
            // Copy any data that was successfully unzipped to new array
716
            // Copy any data that was successfully unzipped to new array
731
            BYTE *temp = new BYTE[newLength];
717
            BYTE * temp = new BYTE[newLength];
732
            memcpy(temp, ( *unzipped), (zS -> total_out - block -> totalUnzipped));
718
            memcpy(temp, ( * unzipped), (zS -> total_out - block -> totalUnzipped));
733
            delete [] ( *unzipped);
719
            delete [] ( * unzipped);
734
            ( *unzipped) = temp;
720
            ( * unzipped) = temp;
735
            ( *lenUnzipped) = newLength;
721
            ( * lenUnzipped) = newLength;
736
            // Position stream output to correct place in new array
722
            // Position stream output to correct place in new array
737
            zS -> next_out = ( *unzipped) + (zS -> total_out - block -> totalUnzipped);
723
            zS -> next_out = ( * unzipped) + (zS -> total_out - block -> totalUnzipped);
738
            zS -> avail_out = ( *lenUnzipped) - (zS -> total_out - block -> totalUnzipped);
724
            zS -> avail_out = ( * lenUnzipped) - (zS -> total_out - block -> totalUnzipped);
739
            // Try again
725
            // Try again
740
            err = unzip(block, zS -> next_in, zS -> avail_in, unzipped, lenUnzipped, true);
726
            err = unzip(block, zS -> next_in, zS -> avail_in, unzipped, lenUnzipped, true);
741
        }
727
        }
Lines 743-749 Link Here
743
        {
729
        {
744
            // All available input has been processed, everything ok.
730
            // All available input has been processed, everything ok.
745
            // Set the size to the amount unzipped in this call (including all recursive calls)
731
            // Set the size to the amount unzipped in this call (including all recursive calls)
746
            ( *lenUnzipped) = (zS -> total_out - block -> totalUnzipped);
732
            ( * lenUnzipped) = (zS -> total_out - block -> totalUnzipped);
747
            block -> totalUnzipped = zS -> total_out;
733
            block -> totalUnzipped = zS -> total_out;
748
        }
734
        }
749
        else
735
        else
Lines 753-759 Link Here
753
            //		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..
739
            //		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..
754
        }
740
        }
755
        if (err != Z_OK)
741
        if (err != Z_OK)
756
        ( *lenUnzipped) = 0;
742
        ( * lenUnzipped) = 0;
757
    }
743
    }
758
    catch(...)
744
    catch(...)
759
    {
745
    {
Lines 761-767 Link Here
761
    return err;
747
    return err;
762
}
748
}
763
749
764
uint32 CUpDownClient:: CalculateDownloadRate()
750
uint32 CUpDownClient::CalculateDownloadRate()
765
{
751
{
766
    m_AvarageDDR_list.AddTail(m_nDownDataRateMS);
752
    m_AvarageDDR_list.AddTail(m_nDownDataRateMS);
767
    m_nSumForAvgDownDataRate += m_nDownDataRateMS;
753
    m_nSumForAvgDownDataRate += m_nDownDataRateMS;
Lines 769-785 Link Here
769
    m_nSumForAvgDownDataRate -= m_AvarageDDR_list.RemoveHead();
755
    m_nSumForAvgDownDataRate -= m_AvarageDDR_list.RemoveHead();
770
    m_nDownDataRateMS = 0;
756
    m_nDownDataRateMS = 0;
771
    if (m_AvarageDDR_list.GetCount() > 10)
757
    if (m_AvarageDDR_list.GetCount() > 10)
772
    m_nDownDatarate = 10 *m_nSumForAvgDownDataRate / m_AvarageDDR_list.GetCount();
758
    m_nDownDatarate = 10 * m_nSumForAvgDownDataRate / m_AvarageDDR_list.GetCount();
773
    else
759
    else
774
    m_nDownDatarate = 0;
760
    m_nDownDatarate = 0;
775
    m_cShowDR++;
761
    m_cShowDR++;
776
    if (m_cShowDR == 30)
762
    if (m_cShowDR == 30)
777
    {
763
    {
778
        m_cShowDR = 0;
764
        m_cShowDR = 0;
779
        //theApp.xmuledlg->transferwnd.downloadlistctrl.UpdateItem(this);
780
        UpdateDisplayedInfo();
765
        UpdateDisplayedInfo();
781
    }
766
    }
782
    if ((:: GetTickCount() - m_dwLastBlockReceived) > DOWNLOADTIMEOUT)
767
    if ((::GetTickCount() - m_dwLastBlockReceived) > DOWNLOADTIMEOUT)
783
    {
768
    {
784
        NewSocket_SendPacketOPdata(2, OP_CANCELTRANSFER, NULL, (wxUint32) this, 1);
769
        NewSocket_SendPacketOPdata(2, OP_CANCELTRANSFER, NULL, (wxUint32) this, 1);
785
        SetDownloadState(DS_ONQUEUE);
770
        SetDownloadState(DS_ONQUEUE);
Lines 787-793 Link Here
787
    return m_nDownDatarate;
772
    return m_nDownDatarate;
788
}
773
}
789
774
790
uint16 CUpDownClient:: GetAvailablePartCount()
775
uint16 CUpDownClient::GetAvailablePartCount()
791
{
776
{
792
    uint16 result = 0;
777
    uint16 result = 0;
793
    for (int i = 0 ; i != m_nPartCount ; i++)
778
    for (int i = 0 ; i != m_nPartCount ; i++)
Lines 798-817 Link Here
798
    return result;
783
    return result;
799
}
784
}
800
785
801
void CUpDownClient:: SetRemoteQueueRank(uint16 nr)
786
void CUpDownClient::SetRemoteQueueRank(uint16 nr)
802
{
787
{
803
    m_nRemoteQueueRank = nr;
788
    m_nRemoteQueueRank = nr;
804
    theApp.xmuledlg -> transferwnd -> downloadlistctrl -> UpdateItem(this);
789
    theApp.xmuledlg -> transferwnd -> downloadlistctrl -> UpdateItem(this);
805
}
790
}
806
791
807
void CUpDownClient:: UDPReaskACK(uint16 nNewQR)
792
void CUpDownClient::UDPReaskACK(uint16 nNewQR)
808
{
793
{
809
    m_bUDPPending = false;
794
    m_bUDPPending = false;
810
    SetRemoteQueueRank(nNewQR);
795
    SetRemoteQueueRank(nNewQR);
811
    m_dwLastAskedTime =:: GetTickCount();
796
    m_dwLastAskedTime =::GetTickCount();
812
}
797
}
813
798
814
void CUpDownClient:: UDPReaskFNF()
799
void CUpDownClient::UDPReaskFNF()
815
{
800
{
816
    m_bUDPPending = false;
801
    m_bUDPPending = false;
817
    theApp.downloadqueue -> RemoveSource(this);
802
    theApp.downloadqueue -> RemoveSource(this);
Lines 821-833 Link Here
821
    }
806
    }
822
}
807
}
823
808
824
void CUpDownClient:: UDPReaskForDownload()
809
void CUpDownClient::UDPReaskForDownload()
825
{
810
{
826
    if (reqfile && (!m_bUDPPending))
811
    if (reqfile && (!m_bUDPPending))
827
    {
812
    {
828
        //the line "m_bUDPPending = true;" use to be here
813
        //the line "m_bUDPPending = true;" use to be here
829
        if (m_nUDPPort != 0 &&theApp.glob_prefs -> GetUDPPort() != 0 &&
814
        if (m_nUDPPort != 0 && theApp.glob_prefs -> GetUDPPort() != 0 &&
830
        !theApp.serverconnect -> IsLowID() && !HasLowID() && ! (socket &&socket -> IsConnected()))
815
        !theApp.serverconnect -> IsLowID() && !HasLowID() && ! (socket && socket -> IsConnected()))
831
        {
816
        {
832
            //don't use udp to ask for sources
817
            //don't use udp to ask for sources
833
            if (IsSourceRequestAllowed())
818
            if (IsSourceRequestAllowed())
Lines 842-854 Link Here
842
                {
827
                {
843
                    packetsize = 16;
828
                    packetsize = 16;
844
                }
829
                }
845
                Packet *response = new Packet(OP_REASKFILEPING, packetsize, OP_EMULEPROT);
830
                Packet * response = new Packet(OP_REASKFILEPING, packetsize, OP_EMULEPROT);
846
                md4cpy(response -> pBuffer, reqfile -> GetFileHash());
831
                md4cpy(response -> pBuffer, reqfile -> GetFileHash());
847
                // #zegzav:completesrc (modify):
832
                // #zegzav:completesrc (modify):
848
                if (GetUDPVersion() >= 3)
833
                if (GetUDPVersion() >= 3)
849
                {
834
                {
850
                    uint16 completecount = reqfile -> m_nCompleteSourcesCount;
835
                    uint16 completecount = reqfile -> m_nCompleteSourcesCount;
851
                    memcpy(response -> pBuffer + 16, &completecount, 2);
836
                    memcpy(response -> pBuffer + 16, & completecount, 2);
852
                }
837
                }
853
                NewSocket_SendPacketOP(1, OP_REASKFILEPING, response, GetIP(), GetUDPPort());
838
                NewSocket_SendPacketOP(1, OP_REASKFILEPING, response, GetIP(), GetUDPPort());
854
            }
839
            }
Lines 857-865 Link Here
857
}
842
}
858
843
859
// Barry - Sets string to show parts downloading, eg NNNYNNNNYYNYN
844
// Barry - Sets string to show parts downloading, eg NNNYNNNNYYNYN
860
void CUpDownClient:: ShowDownloadingParts(wxString &partsYN)
845
void CUpDownClient::ShowDownloadingParts(wxString & partsYN)
861
{
846
{
862
    Requested_Block_Struct *cur_block;
847
    Requested_Block_Struct * cur_block;
863
    unsigned int x;
848
    unsigned int x;
864
    partsYN.Alloc(m_nPartCount + 1);
849
    partsYN.Alloc(m_nPartCount + 1);
865
    for (x = 0 ; x <= m_nPartCount ; x++) partsYN.SetChar(x, 'N');
850
    for (x = 0 ; x <= m_nPartCount ; x++) partsYN.SetChar(x, 'N');
Lines 871-888 Link Here
871
        {
856
        {
872
            partsYN.SetChar(x, 'Y');
857
            partsYN.SetChar(x, 'Y');
873
        }
858
        }
874
        else
875
        {
876
            //printf("CUpDownClient::ShowDownloadingParts x(%ld) > partsYN.Len()(%ld) pc=%ld\n",
877
            //x, partsYN.Len(), m_nPartCount);
878
        }
879
    }
859
    }
880
}
860
}
881
861
882
void CUpDownClient:: UpdateDisplayedInfo(bool force)
862
void CUpDownClient::UpdateDisplayedInfo(bool force)
883
{
863
{
884
    DWORD curTick =:: GetTickCount();
864
    DWORD curTick =::GetTickCount();
885
    if (force || curTick - m_lastRefreshedDLDisplay > MINWAIT_BEFORE_DLDISPLAY_WINDOWUPDATE + (uint32)(rand() / (RAND_MAX/1000)))
865
    if (force || curTick - m_lastRefreshedDLDisplay > MINWAIT_BEFORE_DLDISPLAY_WINDOWUPDATE + (uint32)(rand() / (RAND_MAX/ 1000)))
886
    {
866
    {
887
        theApp.xmuledlg -> transferwnd -> downloadlistctrl -> UpdateItem(this);
867
        theApp.xmuledlg -> transferwnd -> downloadlistctrl -> UpdateItem(this);
888
        m_lastRefreshedDLDisplay = curTick;
868
        m_lastRefreshedDLDisplay = curTick;
Lines 892-898 Link Here
892
 /* Razor 1a - Modif by MikaelB
872
 /* Razor 1a - Modif by MikaelB
893
    SwapToThisFile function */
873
    SwapToThisFile function */
894
874
895
void CUpDownClient:: SwapToThisFile(CPartFile *file)
875
void CUpDownClient::SwapToThisFile(CPartFile * file)
896
{
876
{
897
    // Get the position of the file in other requests' list
877
    // Get the position of the file in other requests' list
898
    POSITION position = this -> m_OtherRequests_list.Find(file);
878
    POSITION position = this -> m_OtherRequests_list.Find(file);
Lines 904-910 Link Here
904
        // Add file at the head of other requests' list
884
        // Add file at the head of other requests' list
905
        this -> m_OtherRequests_list.AddHead(file);
885
        this -> m_OtherRequests_list.AddHead(file);
906
        // Some files
886
        // Some files
907
        CPartFile *SwapFile, *TempFile, *RequestedFile;
887
        CPartFile * SwapFile, * TempFile, * RequestedFile;
908
        TempFile = this -> m_OtherRequests_list.GetHead();
888
        TempFile = this -> m_OtherRequests_list.GetHead();
909
        RequestedFile = this -> reqfile;
889
        RequestedFile = this -> reqfile;
910
        // If the file at the head of other requests' list isn't the requested file
890
        // If the file at the head of other requests' list isn't the requested file
Lines 931-1024 Link Here
931
            // if position isn't null...
911
            // if position isn't null...
932
            if (position)
912
            if (position)
933
            {
913
            {
934
                // Remove source at position from the sources list of requested file
935
                RequestedFile -> srclists[this -> sourcesslot].RemoveAt(position);
914
                RequestedFile -> srclists[this -> sourcesslot].RemoveAt(position);
936
                // Remove source of this client from requested file in the download list
937
                theApp.xmuledlg -> transferwnd -> downloadlistctrl -> RemoveSource(this, RequestedFile);
915
                theApp.xmuledlg -> transferwnd -> downloadlistctrl -> RemoveSource(this, RequestedFile);
938
                // Add this source in the A4AF sources list of the requested file
939
                RequestedFile -> A4AFSourcesList.AddTail(this);
916
                RequestedFile -> A4AFSourcesList.AddTail(this);
940
                // Add the requested file in the other requests' list
941
                this -> m_OtherRequests_list.AddTail(RequestedFile);
917
                this -> m_OtherRequests_list.AddTail(RequestedFile);
942
                // Add source of requested file from this client in the download list
943
                theApp.xmuledlg -> transferwnd -> downloadlistctrl -> AddSource(RequestedFile, this, true);
918
                theApp.xmuledlg -> transferwnd -> downloadlistctrl -> AddSource(RequestedFile, this, true);
944
                // Update requested file's sources infos
945
                RequestedFile -> NewSrcPartsInfo();
919
                RequestedFile -> NewSrcPartsInfo();
946
                // Update requested file's parts counts
947
                RequestedFile -> UpdateAvailablePartsCount();
920
                RequestedFile -> UpdateAvailablePartsCount();
948
                // Set download state of this client to no
949
                this -> SetDownloadState(DS_NONE);
921
                this -> SetDownloadState(DS_NONE);
950
                // Set requested file to 0
951
                RequestedFile = 0;
922
                RequestedFile = 0;
952
                // Set remote queue rank to 0
953
                this -> m_nRemoteQueueRank = 0;
923
                this -> m_nRemoteQueueRank = 0;
954
                // If  abyPartStatus isn't null
955
                if (this -> m_abyPartStatus)
924
                if (this -> m_abyPartStatus)
956
                {
925
                {
957
                    // Delete abyPartStatus
958
                    delete[] this -> m_abyPartStatus;
926
                    delete[] this -> m_abyPartStatus;
959
                    // Set it to null
960
                    this -> m_abyPartStatus = 0;
927
                    this -> m_abyPartStatus = 0;
961
                }
928
                }
962
                // Set part count to
963
                this -> m_nPartCount = 0;
929
                this -> m_nPartCount = 0;
964
                // Set last asked time to 0
965
                this -> m_dwLastAskedTime = 0;
930
                this -> m_dwLastAskedTime = 0;
966
                // set irate to 0
967
                this -> m_iRate = 0;
931
                this -> m_iRate = 0;
968
                // Set comment to ""
969
                this -> m_strComment = "";
932
                this -> m_strComment = "";
970
                // If pszClientFilename isn't null
971
                if (this -> m_pszClientFilename)
933
                if (this -> m_pszClientFilename)
972
                {
934
                {
973
                    // Delete pszClientFilename
974
                    delete this -> m_pszClientFilename;
935
                    delete this -> m_pszClientFilename;
975
                    // Set it to 0
976
                    this -> m_pszClientFilename = 0;
936
                    this -> m_pszClientFilename = 0;
977
                }
937
                }
978
                // Set requested file to swapped file
979
                this -> reqfile = SwapFile;
938
                this -> reqfile = SwapFile;
980
                // Add this source in the sources list of swapped file
981
                SwapFile -> srclists[this -> sourcesslot].AddTail(this);
939
                SwapFile -> srclists[this -> sourcesslot].AddTail(this);
982
                // Add source of swapped file from this client to download list
983
                theApp.xmuledlg -> transferwnd -> downloadlistctrl -> AddSource(SwapFile, this, false);
940
                theApp.xmuledlg -> transferwnd -> downloadlistctrl -> AddSource(SwapFile, this, false);
984
            }
941
            }
985
        }
942
        }
986
        // Else if swapped file isn't null...
943
        // Else if swapped file isn't null...
987
        else if(SwapFile)
944
        else if(SwapFile)
988
        {
945
        {
989
            // Add it to other requests' list
990
            this -> m_OtherRequests_list.AddHead(SwapFile);
946
            this -> m_OtherRequests_list.AddHead(SwapFile);
991
            // Add this source to A4AF sources list of swapped file
992
            this -> m_OtherRequests_list.GetHead() -> A4AFSourcesList.AddHead(this);
947
            this -> m_OtherRequests_list.GetHead() -> A4AFSourcesList.AddHead(this);
993
        }
948
        }
994
        // Else...
995
        else
949
        else
996
        // Add this source to A4AF sources list of swapped file
950
        {
997
        this -> m_OtherRequests_list.GetHead() -> A4AFSourcesList.AddHead(this);
951
        this -> m_OtherRequests_list.GetHead() -> A4AFSourcesList.AddHead(this);
998
    }
952
    }
999
    // Else...
953
    }
1000
    else
954
    else
1001
    // Add this source to A4AF sources lisy of file
955
    {
1002
    file -> A4AFSourcesList.AddHead(this);
956
    file -> A4AFSourcesList.AddHead(this);
957
    }
1003
}
958
}
1004
959
1005
 /* Razor 1a - Modif by MikaelB
960
 /* Razor 1a - Modif by MikaelB
1006
    Made some changes in SwapToAnoterFile function */
961
    Made some changes in SwapToAnoterFile function */
1007
962
1008
bool CUpDownClient:: SwapToAnotherFile()
963
bool CUpDownClient::SwapToAnotherFile()
1009
{
964
{
1010
    if (this -> GetDownloadState() == DS_DOWNLOADING)
965
    if (this -> GetDownloadState() == DS_DOWNLOADING) {
1011
    return false;
966
    return false;
967
    }
1012
    if (!this -> m_OtherRequests_list.IsEmpty())
968
    if (!this -> m_OtherRequests_list.IsEmpty())
1013
    {
969
    {
1014
        CPartFile *SwapTo = NULL;
970
        CPartFile * SwapTo = NULL;
1015
        POSITION pos, pos1, pos2;
971
        POSITION pos, pos1, pos2;
1016
        for (pos1 = this -> m_OtherRequests_list.GetHeadPosition() ; (pos2 = pos1) != NULL ;)
972
        for (pos1 = this -> m_OtherRequests_list.GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1017
        {
973
        {
1018
            this -> m_OtherRequests_list.GetNext(pos1);
974
            this -> m_OtherRequests_list.GetNext(pos1);
1019
            CPartFile *cur_file = this -> m_OtherRequests_list.GetAt(pos2);
975
            CPartFile * cur_file = this -> m_OtherRequests_list.GetAt(pos2);
1020
            if (cur_file != this -> reqfile
976
            if (cur_file != this -> reqfile
1021
            &&theApp.downloadqueue -> IsPartFile(cur_file)
977
            && theApp.downloadqueue -> IsPartFile(cur_file)
1022
            && !cur_file -> IsStopped()
978
            && !cur_file -> IsStopped()
1023
            && (cur_file -> GetStatus(false) == PS_READY || cur_file -> GetStatus(false) == PS_EMPTY))
979
            && (cur_file -> GetStatus(false) == PS_READY || cur_file -> GetStatus(false) == PS_EMPTY))
1024
            {
980
            {
Lines 1080-1086 Link Here
1080
1036
1081
    /* End modif */
1037
    /* End modif */
1082
1038
1083
void CUpDownClient:: SetDownloadFile(CPartFile *part)
1039
void CUpDownClient::SetDownloadFile(CPartFile * part)
1084
{
1040
{
1085
    delete[] m_abyPartStatus;
1041
    delete[] m_abyPartStatus;
1086
    m_abyPartStatus = NULL;
1042
    m_abyPartStatus = NULL;
(-)xmule/src/DownloadListCtrl.cpp (-4 / +34 lines)
Lines 109-114 Link Here
109
 EVT_MENU(MP_CANCEL,CDownloadListCtrl::OnMCancel)
109
 EVT_MENU(MP_CANCEL,CDownloadListCtrl::OnMCancel)
110
    */
110
    */
111
111
112
int fireup=0;
113
112
void preloadImages(wxImageList *imgs)
114
void preloadImages(wxImageList *imgs)
113
{
115
{
114
    imgs -> Add(wxBitmap(client0_ICO));
116
    imgs -> Add(wxBitmap(client0_ICO));
Lines 193-203 Link Here
193
            if ((isShift || isCtrl || isAlt) && (cl -> GetDownloadFile() == toCollapse))
195
            if ((isShift || isCtrl || isAlt) && (cl -> GetDownloadFile() == toCollapse))
194
            {
196
            {
195
                uint8 ds = cl -> GetDownloadState();
197
                uint8 ds = cl -> GetDownloadState();
198
		if(fireup==30002) {
199
		  if(ds!=DS_NONEEDEDPARTS) {
200
printf("fireup: %u\n",(uint32)cl);
201
			continue;
202
		  }
203
		} else {
196
                if ((isShift &&ds == DS_DOWNLOADING) || (isCtrl &&cl -> GetRemoteQueueRank() > 0) || (isAlt &&ds != DS_NONEEDEDPARTS))
204
                if ((isShift &&ds == DS_DOWNLOADING) || (isCtrl &&cl -> GetRemoteQueueRank() > 0) || (isAlt &&ds != DS_NONEEDEDPARTS))
197
                {
205
                {
198
                    continue;
206
                    continue;
199
                }
207
                }
200
            }
208
            }
209
            }
201
            item -> dwUpdated = 0;
210
            item -> dwUpdated = 0;
202
            //item->status.DeleteObject();
211
            //item->status.DeleteObject();
203
            if (item -> status)
212
            if (item -> status)
Lines 383-388 Link Here
383
                menu -> Append(MP_CANCEL, GetResString(IDS_MAIN_BTN_CANCEL));
392
                menu -> Append(MP_CANCEL, GetResString(IDS_MAIN_BTN_CANCEL));
384
                menu -> Append(MP_STOP, GetResString(IDS_DL_STOP));
393
                menu -> Append(MP_STOP, GetResString(IDS_DL_STOP));
385
                menu -> Append(MP_PAUSE, GetResString(IDS_DL_PAUSE));
394
                menu -> Append(MP_PAUSE, GetResString(IDS_DL_PAUSE));
395
                menu -> Append(30002, "Sourcecrunching");
386
                menu -> Append(MP_RESUME, GetResString(IDS_DL_RESUME));
396
                menu -> Append(MP_RESUME, GetResString(IDS_DL_RESUME));
387
                menu -> AppendSeparator();
397
                menu -> AppendSeparator();
388
 /* Razor 1a - Modif by MikaelB
398
 /* Razor 1a - Modif by MikaelB
Lines 446-452 Link Here
446
            menu -> Enable(MP_RESUME, ((file -> GetStatus() == PS_PAUSED) ? MF_ENABLED: MF_GRAYED));
456
            menu -> Enable(MP_RESUME, ((file -> GetStatus() == PS_PAUSED) ? MF_ENABLED: MF_GRAYED));
447
            //<<--9/21/02:
457
            //<<--9/21/02:
448
            menu -> Enable(MP_OPEN, ((file -> GetStatus() == PS_COMPLETE) ? MF_ENABLED: MF_GRAYED));
458
            menu -> Enable(MP_OPEN, ((file -> GetStatus() == PS_COMPLETE) ? MF_ENABLED: MF_GRAYED));
449
            menu -> SetLabel(MP_PREVIEW, wxString:: Format(_("Preview [%s]"), file -> GetPartMetFileName()));
459
            menu -> SetLabel(MP_PREVIEW, wxString:: Format(_("Preview [%s]"), file -> GetPartMetFileName().GetData()));
450
            menu -> Enable(MP_PREVIEW, ((file -> PreviewAvailable()) ? MF_ENABLED: MF_GRAYED));
460
            menu -> Enable(MP_PREVIEW, ((file -> PreviewAvailable()) ? MF_ENABLED: MF_GRAYED));
451
 /* Razor 1a - Modif by MikaelB
461
 /* Razor 1a - Modif by MikaelB
452
 Set menu items' state for :
462
 Set menu items' state for :
Lines 2052-2057 Link Here
2052
                file -> SavePartFile();
2062
                file -> SavePartFile();
2053
                break;
2063
                break;
2054
            case MP_STOP:
2064
            case MP_STOP:
2065
		fireup=0;
2055
                if (selectedCount > 1)
2066
                if (selectedCount > 1)
2056
                {
2067
                {
2057
                    Freeze();
2068
                    Freeze();
Lines 2059-2072 Link Here
2059
                    {
2070
                    {
2060
                        CPartFile *selected = selectedList.GetHead();
2071
                        CPartFile *selected = selectedList.GetHead();
2061
                        HideSources(selected);
2072
                        HideSources(selected);
2062
                        selected -> StopFile();
2073
                        selected -> StopFile(0);
2063
                        selectedList.RemoveHead();
2074
                        selectedList.RemoveHead();
2064
                    }
2075
                    }
2065
                    Thaw();
2076
                    Thaw();
2077
                } else {
2078
                  HideSources(file);
2079
                  file -> StopFile(0);
2080
		}
2066
                    break;
2081
                    break;
2082
            case 30002:
2083
		fireup=30002;
2084
                if (selectedCount > 1)
2085
                {
2086
                //    Freeze();
2087
                    while (!selectedList.IsEmpty())
2088
                    {
2089
                        CPartFile *selected = selectedList.GetHead();
2090
                        //HideSources(selected);
2091
                        selected -> RemoveAllSources(fireup,true);
2092
                        selectedList.RemoveHead();
2067
                }
2093
                }
2068
                HideSources(file);
2094
                 //   Thaw();
2069
                file -> StopFile();
2095
                } else {
2096
                //HideSources(file);
2097
                  file -> RemoveAllSources(fireup,true);
2098
		}
2099
		fireup=0;
2070
                break;
2100
                break;
2071
            case MP_CLEARCOMPLETED:
2101
            case MP_CLEARCOMPLETED:
2072
                Freeze();
2102
                Freeze();
(-)xmule/src/DownloadQueue.cpp (-2 / +8 lines)
Lines 159-166 Link Here
159
            wxFileName myFileName(fileName);
159
            wxFileName myFileName(fileName);
160
            printf("Loading %s... ", myFileName.GetFullName() .GetData());
160
            printf("Loading %s... ", myFileName.GetFullName() .GetData());
161
            CPartFile *toadd = new CPartFile();
161
            CPartFile *toadd = new CPartFile();
162
            if (toadd -> LoadPartFile(app_prefs -> GetTempDir(), (char *) myFileName.GetFullName() .GetData()))
162
            if (toadd -> LoadPartFile(count0,app_prefs -> GetTempDir(), (char *) myFileName.GetFullName() .GetData()))
163
            {
163
            {
164
		switch(count0) {
165
		case 0:
166
			toadd->SetIsDynamic(false);break;
167
		case 1:
168
			toadd->SetIsDynamic(true);break;
169
		}
164
                count++;
170
                count++;
165
                printf("Done.\n");
171
                printf("Done.\n");
166
                filelist.AddTail(toadd);
172
                filelist.AddTail(toadd);
Lines 980-986 Link Here
980
                cur_file -> PauseFile();
986
                cur_file -> PauseFile();
981
                break;
987
                break;
982
            case MP_STOP:
988
            case MP_STOP:
983
                cur_file -> StopFile();
989
                cur_file -> StopFile(0);
984
                break;
990
                break;
985
            case MP_RESUME:
991
            case MP_RESUME:
986
                if (cur_file -> GetStatus() == PS_PAUSED)
992
                if (cur_file -> GetStatus() == PS_PAUSED)
(-)xmule/src/FlowChart.cpp (-7 / +62 lines)
Lines 110-115 Link Here
110
wxMenu *pop_oldprefs09;
110
wxMenu *pop_oldprefs09;
111
111
112
int newprefs01_opt[101];
112
int newprefs01_opt[101];
113
wxString newprefs01_alpha[101];
113
114
114
wxString newprefs01info[256];
115
wxString newprefs01info[256];
115
116
Lines 172-178 Link Here
172
173
173
void Load_NewPrefs01()
174
void Load_NewPrefs01()
174
{
175
{
175
    for (int i = 0 ; i < 7 ; i++)
176
	int i=0;
177
    for (i = 1 ; i <= 100 ; i++)
178
    {
179
        newprefs01_opt[i] = 0;
180
        newprefs01_alpha[i] = "";
181
    }
182
    for (i = 0 ; i < 7 ; i++)
176
    {
183
    {
177
	switch(i) {
184
	switch(i) {
178
	case 3:
185
	case 3:
Lines 204-210 Link Here
204
        (void) fread( &byte, 1, 1, newprefs01_fd);
211
        (void) fread( &byte, 1, 1, newprefs01_fd);
205
        line += (wxChar) byte[0];
212
        line += (wxChar) byte[0];
206
    }
213
    }
207
    for (int i = 0 ; i < 7 ; i++)
214
    for (i = 0 ; i < 7 ; i++)
208
    {
215
    {
209
        if (i *4 <= line.Len())
216
        if (i *4 <= line.Len())
210
        {
217
        {
Lines 212-221 Link Here
212
        }
219
        }
213
    }
220
    }
214
    (void) fclose(newprefs01_fd);
221
    (void) fclose(newprefs01_fd);
222
    newprefs01_filename = wxString:: Format("%s/.xMule/", getenv("HOME")) + wxT("newprefs01.alp");
223
    newprefs01_fd = fopen(newprefs01_filename, "r");
224
    if (newprefs01_fd == NULL)
225
    {
226
        newprefs01_fd = fopen(newprefs01_filename, "w");
227
        (void) fclose(newprefs01_fd);
228
        newprefs01_fd = fopen(newprefs01_filename, "r");
229
    }
230
    line = "";
231
    long v;
232
    while (!feof(newprefs01_fd))
233
    {
234
        (void) fread( &byte, 1, 1, newprefs01_fd);
235
	switch(byte[0]) {
236
	case 10:
237
		line.Mid(1,3).ToLong(&v);	
238
		newprefs01_alpha[v]=line.Mid(4);
239
	case 13:break;
240
	case 0:break;
241
	default:
242
        	line += (wxChar) byte[0];
243
		break;
244
	}
245
    }
246
    (void) fclose(newprefs01_fd);
215
}
247
}
216
248
217
void Save_NewPrefs01()
249
void Save_NewPrefs01()
218
{
250
{
251
	int i=0;
219
    FILE *newprefs01_fd;
252
    FILE *newprefs01_fd;
220
    wxString line;
253
    wxString line;
221
    wxString newprefs01_filename = wxString:: Format("%s/.xMule/", getenv("HOME")) + wxT("newprefs01.dat");
254
    wxString newprefs01_filename = wxString:: Format("%s/.xMule/", getenv("HOME")) + wxT("newprefs01.dat");
Lines 223-234 Link Here
223
    if (newprefs01_fd != NULL)
256
    if (newprefs01_fd != NULL)
224
    {
257
    {
225
        line = "";
258
        line = "";
226
        for (int i = 0 ; i < 7 ; i++)
259
        for (i = 0 ; i < 7 ; i++)
227
        {
260
        {
228
            line += "    ";
261
            line += "    ";
229
            memcpy((void *)(((const char *) line) + i *4), &newprefs01_opt[i], 4);
262
            memcpy((void *)(((const char *) line) + i *4), &newprefs01_opt[i], 4);
230
        }
263
        }
231
        (void) fwrite(((const char *) line), 1, line.Len(), newprefs01_fd);
264
        (void) fwrite((const char *) line, 1, line.Len(), newprefs01_fd);
265
        (void) fclose(newprefs01_fd);
266
    }
267
    newprefs01_filename = wxString:: Format("%s/.xMule/", getenv("HOME")) + wxT("newprefs01.alp");
268
    newprefs01_fd = fopen(newprefs01_filename, "w");
269
    if (newprefs01_fd != NULL)
270
    {
271
        for (i = 0 ; i < 100 ; i++)
272
        {
273
	  if(newprefs01_alpha[i].Len()) {
274
	    line=wxString::Format("%03d:",i);
275
       	    (void) fwrite((const char *) line, 1, 4, newprefs01_fd);
276
            (void) fwrite((const char *) newprefs01_alpha[i], 1, newprefs01_alpha[i].Len(), newprefs01_fd);
277
       	    (void) fwrite("\n", 1, 1, newprefs01_fd);
278
	  }
279
        }
232
        (void) fclose(newprefs01_fd);
280
        (void) fclose(newprefs01_fd);
233
    }
281
    }
234
}
282
}
Lines 239-249 Link Here
239
#define WXOBEF	(wxObjectEventFunction)&CFlowChart
287
#define WXOBEF	(wxObjectEventFunction)&CFlowChart
240
    for (int i = 1 ; i <= 100 ; i++)
288
    for (int i = 1 ; i <= 100 ; i++)
241
    {
289
    {
242
        newprefs01_opt[i] = 0;
243
        newprefs03_opt[i] = 0;
290
        newprefs03_opt[i] = 0;
244
        newprefs04_opt[i] = 0;
291
        newprefs04_opt[i] = 0;
245
    }
292
    }
246
    //Save_NewPrefs01();
247
    DARK_WHITE = new wxColour(0xef, 0xef, 0xef);
293
    DARK_WHITE = new wxColour(0xef, 0xef, 0xef);
248
    Load_NewPrefs01();
294
    Load_NewPrefs01();
249
    ReadOldPrefs();
295
    ReadOldPrefs();
Lines 362-369 Link Here
362
    wxBoxSizer *root = new wxBoxSizer(wxVERTICAL);
408
    wxBoxSizer *root = new wxBoxSizer(wxVERTICAL);
363
    this -> SetAutoLayout(TRUE);
409
    this -> SetAutoLayout(TRUE);
364
    this -> SetSizer(root);
410
    this -> SetSizer(root);
365
    root -> Fit(this);
366
    root -> SetSizeHints(this);
411
    root -> SetSizeHints(this);
412
    root -> Fit(this);
367
    root -> Show(this, TRUE);
413
    root -> Show(this, TRUE);
368
    Connect( - 1, wxEVT_MOTION, SDMOUSEEVT:: OnMouseMove);
414
    Connect( - 1, wxEVT_MOTION, SDMOUSEEVT:: OnMouseMove);
369
    Connect( - 1, wxEVT_PAINT, SDPAINTEVT:: OnPaint);
415
    Connect( - 1, wxEVT_PAINT, SDPAINTEVT:: OnPaint);
Lines 480-485 Link Here
480
526
481
CFlowChart:: ~CFlowChart()
527
CFlowChart:: ~CFlowChart()
482
{
528
{
529
    Save_NewPrefs01();
483
}
530
}
484
531
485
void CFlowChart:: Popup_NewPrefs(wxMouseEvent &event)
532
void CFlowChart:: Popup_NewPrefs(wxMouseEvent &event)
Lines 536-541 Link Here
536
    {
583
    {
537
        if (x > 25 &&x < 130)
584
        if (x > 25 &&x < 130)
538
        {
585
        {
586
	    int p=0;wxString ps;
587
    	    ps=pop_newprefs01 -> GetLabel(20107);
588
	    p=ps.Find(":");
589
	    if(p) {
590
		ps=ps.Left(p+1);
591
	    }
592
    	    pop_newprefs01 -> SetLabel(20107, ps+" "+newprefs01_alpha[7]);
539
            PopupMenu(pop_newprefs01, event.GetPosition());
593
            PopupMenu(pop_newprefs01, event.GetPosition());
540
        }
594
        }
541
        else if(x > 141 &&x < 236)
595
        else if(x > 141 &&x < 236)
Lines 564-569 Link Here
564
    case 20104:
618
    case 20104:
565
    case 20105:
619
    case 20105:
566
    case 20106:
620
    case 20106:
621
    case 20107:
567
        if (pop_newprefs01 -> IsChecked(eventid))
622
        if (pop_newprefs01 -> IsChecked(eventid))
568
        {
623
        {
569
            newprefs01_opt[eventid - 20100] = 1;
624
            newprefs01_opt[eventid - 20100] = 1;
(-)xmule/src/KnownFile.cpp (-253 / +206 lines)
Lines 26-33 Link Here
26
#	include "ini2.h"
26
#	include "ini2.h"
27
#	include "KnownFile.h"
27
#	include "KnownFile.h"
28
#	include "KnownFileList.h"
28
#	include "KnownFileList.h"
29
#	include "NewFunctions.h"
29
#	include "opcodes.h"
30
#	include "opcodes.h"
30
#	include "otherfunctions.h"
31
#	include "otherfunctions.h"
32
#	include "PartFile.h"
31
#	include "Preferences.h"
33
#	include "Preferences.h"
32
#	include "SharedFileList.h"
34
#	include "SharedFileList.h"
33
#	include "SharedFilesWnd.h"
35
#	include "SharedFilesWnd.h"
Lines 40-62 Link Here
40
#include <sys/types.h>
42
#include <sys/types.h>
41
#include <sys/stat.h>
43
#include <sys/stat.h>
42
44
43
// constants for MD4Transform
45
// Adde by Tarod [Juanjo]
44
#define S11 3
46
void CFileStatistic::AddRequest()
45
#define S12 7
46
#define S13 11
47
#define S14 19
48
#define S21 3
49
#define S22 5
50
#define S23 9
51
#define S24 13
52
#define S31 3
53
#define S32 9
54
#define S33 11
55
#define S34 15
56
57
static void MD4Transform(uint32 Hash[4], uint32 x[16]);
58
59
void CFileStatistic:: AddRequest()
60
{
47
{
61
    requested++;
48
    requested++;
62
    alltimerequested++;
49
    alltimerequested++;
Lines 64-70 Link Here
64
    theApp.sharedfiles -> UpdateItem(fileParent);
51
    theApp.sharedfiles -> UpdateItem(fileParent);
65
}
52
}
66
53
67
void CFileStatistic:: AddAccepted()
54
void CFileStatistic::AddAccepted()
68
{
55
{
69
    accepted++;
56
    accepted++;
70
    alltimeaccepted++;
57
    alltimeaccepted++;
Lines 72-78 Link Here
72
    theApp.sharedfiles -> UpdateItem(fileParent);
59
    theApp.sharedfiles -> UpdateItem(fileParent);
73
}
60
}
74
61
75
void CFileStatistic:: AddTransferred(uint64 bytes)
62
void CFileStatistic::AddTransferred(uint64 bytes)
76
{
63
{
77
    transfered += bytes;
64
    transfered += bytes;
78
    alltimetransfered += bytes;
65
    alltimetransfered += bytes;
Lines 80-86 Link Here
80
    theApp.sharedfiles -> UpdateItem(fileParent);
67
    theApp.sharedfiles -> UpdateItem(fileParent);
81
}
68
}
82
69
83
CKnownFile:: CKnownFile()
70
CKnownFile::CKnownFile()
84
{
71
{
85
    m_iFileType = 2;
72
    m_iFileType = 2;
86
    directory = NULL;
73
    directory = NULL;
Lines 106-112 Link Here
106
    m_iPartCount = 0;
93
    m_iPartCount = 0;
107
}
94
}
108
95
109
CKnownFile:: ~CKnownFile()
96
CKnownFile::~ CKnownFile()
110
{
97
{
111
    for (int i = 0 ; i != hashlist.GetSize() ; i++)
98
    for (int i = 0 ; i != hashlist.GetSize() ; i++)
112
    if (hashlist[i])
99
    if (hashlist[i])
Lines 120-149 Link Here
120
    m_AvailPartFrequency.RemoveAll();
107
    m_AvailPartFrequency.RemoveAll();
121
}
108
}
122
109
123
CBarShader CKnownFile:: s_ShareStatusBar(16);
110
CBarShader CKnownFile::s_ShareStatusBar(16);
124
111
125
void CKnownFile:: DrawShareStatusBar(wxDC *dc, wxRect rect, bool onlygreyrect, bool bFlat)
112
void CKnownFile::DrawShareStatusBar(wxDC * dc, wxRect rect, bool onlygreyrect, bool bFlat)
126
{
113
{
127
 /*
128
 DWORD crBoth;
129
 DWORD crNeither;
130
 DWORD crClientOnly;
131
 DWORD crPending;
132
 DWORD crNextPending;
133
 if(bFlat) {
134
 crBoth = RGB(0, 150, 0);
135
 crNeither = RGB(224, 224, 224);
136
 crClientOnly = RGB(0, 0, 0);
137
 crPending = RGB(255,208,0);
138
 crNextPending = RGB(255,255,100);
139
 } else {
140
 crBoth = RGB(0, 192, 0);
141
 crNeither = RGB(240, 240, 240);
142
 crClientOnly = RGB(104, 104, 104);
143
 crPending = RGB(255, 208, 0);
144
 crNextPending = RGB(255,255,100);
145
 }
146
    */
147
    s_ShareStatusBar.SetFileSize(GetFileSize());
114
    s_ShareStatusBar.SetFileSize(GetFileSize());
148
    s_ShareStatusBar.SetHeight(rect.GetHeight());
115
    s_ShareStatusBar.SetHeight(rect.GetHeight());
149
    s_ShareStatusBar.SetWidth(rect.GetWidth());
116
    s_ShareStatusBar.SetWidth(rect.GetWidth());
Lines 162-168 Link Here
162
    s_ShareStatusBar.Draw(dc, rect.GetLeft(), rect.GetTop(), bFlat);
129
    s_ShareStatusBar.Draw(dc, rect.GetLeft(), rect.GetTop(), bFlat);
163
}
130
}
164
131
165
void CKnownFile:: NewAvailPartsInfo()
132
void CKnownFile::NewAvailPartsInfo()
166
{
133
{
167
    // Cache part count
134
    // Cache part count
168
    uint16 partcount = GetPartCount();
135
    uint16 partcount = GetPartCount();
Lines 173-179 Link Here
173
    {
140
    {
174
        m_AvailPartFrequency.Add(0);
141
        m_AvailPartFrequency.Add(0);
175
    }
142
    }
176
    CUpDownClient *cur_src;
143
    CUpDownClient * cur_src;
177
    if (this -> IsPartFile())
144
    if (this -> IsPartFile())
178
    cur_src = NULL;
145
    cur_src = NULL;
179
    for (POSITION pos = m_ClientUploadList.GetHeadPosition() ; pos != 0 ;)
146
    for (POSITION pos = m_ClientUploadList.GetHeadPosition() ; pos != 0 ;)
Lines 188-194 Link Here
188
    theApp.xmuledlg -> sharedfileswnd -> sharedfilesctrl -> UpdateItem(this);
155
    theApp.xmuledlg -> sharedfileswnd -> sharedfilesctrl -> UpdateItem(this);
189
}
156
}
190
157
191
void CKnownFile:: AddUploadingClient(CUpDownClient *client)
158
void CKnownFile::AddUploadingClient(CUpDownClient * client)
192
{
159
{
193
    // to be sure:
160
    // to be sure:
194
    POSITION pos = m_ClientUploadList.Find(client);
161
    POSITION pos = m_ClientUploadList.Find(client);
Lines 198-204 Link Here
198
    }
165
    }
199
}
166
}
200
167
201
void CKnownFile:: RemoveUploadingClient(CUpDownClient *client)
168
void CKnownFile::RemoveUploadingClient(CUpDownClient * client)
202
{
169
{
203
    // to be sure:
170
    // to be sure:
204
    POSITION pos = m_ClientUploadList.Find(client);
171
    POSITION pos = m_ClientUploadList.Find(client);
Lines 208-299 Link Here
208
    }
175
    }
209
}
176
}
210
177
211
void CKnownFile:: SetPath(char *path)
178
void CKnownFile::SetPath(char * path)
212
{
179
{
213
    if (directory)
180
    if (directory)
214
    delete[] directory;
181
    delete[] directory;
215
    directory = nstrdup(path);
182
    directory = nstrdup(path);
216
}
183
}
217
184
218
bool CKnownFile:: CreateFromFile(char *in_directory, char *in_filename, volatile int const *notify)
185
bool CKnownFile::CreateFromFile(void * pf0, char * in_directory, char * in_filename, volatile int const * notify)
219
{
186
{
220
    // TODO Errorhandling
187
    CPartFile *pf;
221
    //first create the filehashset
188
    pf=(CPartFile *)pf0;
222
    // open file
189
    m_isDynamic = 0;
190
    printf("CKnownFile::CreateFromFile: %s %s\n",in_directory, in_filename);
223
    directory = nstrdup(in_directory);
191
    directory = nstrdup(in_directory);
224
    char *namebuffer = new char[strlen(in_directory) + strlen(in_filename) + 2];
192
    char * namebuffer = new char[strlen(in_directory) + strlen(in_filename) + 2];
225
    sprintf(namebuffer, "%s/%s", in_directory, in_filename);
193
    sprintf(namebuffer, "%s/%s", in_directory, in_filename);
226
    FILE *file = fopen(namebuffer, "r");
194
    FILE * file = fopen(namebuffer, "r");
227
    delete[] namebuffer;
195
    delete[] namebuffer;
228
    if (!file)
196
    if (file)
229
    {
197
    {
230
        printf("%s/%s ei aukea\n", in_directory, in_filename);
198
 	long curpos=0;
231
        return false;
199
        printf("%s/%s  curpos=%u\n", in_directory, in_filename, curpos);
232
    }
233
    // set filesize + name
234
    m_pszFileName = nstrdup(in_filename);
200
    m_pszFileName = nstrdup(in_filename);
235
    //filesize =_filelength(file->_file);
201
        if (pf != NULL)
236
    long curpos = ftell(file);
202
        {
203
            m_isDynamic = pf -> IsDynamic();
204
            m_nFileSize = pf -> m_nFileSize;
205
	    pf->Seek(curpos);
206
        }
207
        else
208
        {
209
            curpos = ftell(file);
237
    fseek(file, 0, SEEK_END);
210
    fseek(file, 0, SEEK_END);
238
    m_nFileSize = ftell(file);
211
    m_nFileSize = ftell(file);
239
    fseek(file, curpos, SEEK_SET);
212
    fseek(file, curpos, SEEK_SET);
213
        }
240
    m_AvailPartFrequency.SetSize(GetPartCount());
214
    m_AvailPartFrequency.SetSize(GetPartCount());
241
    for (uint32 i = 0 ; i != GetPartCount() ; i++)
215
    for (uint32 i = 0 ; i != GetPartCount() ; i++)
216
        {
242
    m_AvailPartFrequency.Add(0);
217
    m_AvailPartFrequency.Add(0);
218
        }
243
    // create hashset
219
    // create hashset
244
    uint32 togo = m_nFileSize;
220
    uint32 togo = m_nFileSize;
245
    uint16 hashcount;
221
        uint16 hashcount=0;
246
    for (hashcount = 0 ; togo >= PARTSIZE ;)
222
        while(togo >= PARTSIZE)
223
        {
224
            uchar * newhash = new uchar[16];
225
            if (pf != NULL)
226
            {
227
                pf -> CreateHash(PARTSIZE, newhash);
228
            }
229
            else
247
    {
230
    {
248
        uchar *newhash = new uchar[16];
249
        CreateHashFromFile(file, PARTSIZE, newhash);
231
        CreateHashFromFile(file, PARTSIZE, newhash);
232
            }
250
        hashlist.Add(newhash);
233
        hashlist.Add(newhash);
251
        togo -= PARTSIZE;
234
        togo -= PARTSIZE;
252
        hashcount++;
235
        hashcount++;
253
        if (notify && *notify)
236
            if (notify && * notify)
237
            {
238
                if (pf == NULL)
254
        {
239
        {
255
            fclose(file);
240
            fclose(file);
241
                }
256
            return false;
242
            return false;
257
        }
243
        }
258
    }
244
    }
259
    uchar *lasthash = new uchar[16];
245
        uchar * lasthash = new uchar[16];
260
    memset(lasthash, 0, 16);
246
    memset(lasthash, 0, 16);
261
    CreateHashFromFile(file, togo, lasthash);
247
        if (pf != NULL)
248
        {
249
            pf -> CreateHash(togo, lasthash);
250
        }
251
        else
252
        {
253
            CreateHashFromFile( file, togo, lasthash);
254
        }
262
    if (!hashcount)
255
    if (!hashcount)
263
    {
256
    {
264
        memcpy(m_abyFileHash, lasthash, 16);
257
        memcpy(m_abyFileHash, lasthash, 16);
265
        // i_a: memleak:
266
        delete[] lasthash;
258
        delete[] lasthash;
267
    }
259
    }
268
    else
260
    else
269
    {
261
    {
270
        hashlist.Add(lasthash);
262
        hashlist.Add(lasthash);
271
        uchar *buffer = new uchar[hashlist.GetCount() *16];
263
            uchar * buffer = new uchar[hashlist.GetCount() * 16];
272
        for (int i = 0 ; i != hashlist.GetCount() ; i++)
264
        for (int i = 0 ; i != hashlist.GetCount() ; i++)
273
        memcpy(buffer + (i *16), hashlist[i], 16);
265
            {
274
        CreateHashFromString(buffer, hashlist.GetCount() *16, m_abyFileHash);
266
                memcpy(buffer + (i * 16), hashlist[i], 16);
267
            }
268
            CreateHashFromString(buffer, hashlist.GetCount() * 16, m_abyFileHash);
275
        delete[] buffer;
269
        delete[] buffer;
276
    }
270
    }
277
    // TODO: Add filetags
278
    // set lastwrite date
279
    struct stat fileinfo;
271
    struct stat fileinfo;
280
    fstat(fileno(file), &fileinfo);
272
        fstat(fileno(file), & fileinfo);
281
    date = fileinfo.st_mtime;
273
    date = fileinfo.st_mtime;
282
    //finished
283
    fclose(file);
274
    fclose(file);
284
    return true;
275
    return true;
276
    }
277
    else
278
    {
279
        return false;
280
    }
285
}
281
}
286
282
287
// needed for memfiles. its probably better to switch everything to CFile...
283
bool CKnownFile::LoadHashsetFromFile(CFile * file, bool checkhash)
288
bool CKnownFile:: LoadHashsetFromFile(CFile *file, bool checkhash)
289
{
284
{
290
    uchar checkid[16];
285
    uchar checkid[16];
291
    file -> Read( &checkid, 16);
286
    file -> Read( & checkid, 16);
292
    uint16 parts;
287
    uint16 parts;
293
    file -> Read( &parts, 2);
288
    file -> Read( & parts, 2);
294
    for (int i = 0 ; i != parts ; i++)
289
    for (int i = 0 ; i != parts ; i++)
295
    {
290
    {
296
        uchar *cur_hash = new uchar[16];
291
        uchar * cur_hash = new uchar[16];
297
        file -> Read(cur_hash, 16);
292
        file -> Read(cur_hash, 16);
298
        hashlist.Add(cur_hash);
293
        hashlist.Add(cur_hash);
299
    }
294
    }
Lines 305-316 Link Here
305
    // trust noone ;-)
300
    // trust noone ;-)
306
    if (!hashlist.IsEmpty())
301
    if (!hashlist.IsEmpty())
307
    {
302
    {
308
        uchar *buffer = new uchar[hashlist.GetCount() *16];
303
        uchar * buffer = new uchar[hashlist.GetCount() * 16];
309
        for (int i = 0 ; i != hashlist.GetCount() ; i++)
304
        for (int i = 0 ; i != hashlist.GetCount() ; i++)
310
        {
305
        {
311
            memcpy(buffer + (i *16), hashlist[i], 16);
306
            memcpy(buffer + (i * 16), hashlist[i], 16);
312
        }
307
        }
313
        CreateHashFromString(buffer, hashlist.GetCount() *16, checkid);
308
        CreateHashFromString(buffer, hashlist.GetCount() * 16, checkid);
314
        delete[] buffer;
309
        delete[] buffer;
315
    }
310
    }
316
    if (!memcmp(m_abyFileHash, checkid, 16))
311
    if (!memcmp(m_abyFileHash, checkid, 16))
Lines 326-343 Link Here
326
    }
321
    }
327
}
322
}
328
323
329
bool CKnownFile:: LoadTagsFromFile(CFile *file)
324
bool CKnownFile::LoadTagsFromFile(CFile * file)
330
{
325
{
331
    try
326
    try
332
    {
327
    {
333
        uint32 tagcount;
328
        uint32 tagcount;
334
        if (4 != file -> Read( &tagcount, 4))
329
        if (4 != file -> Read( & tagcount, 4))
335
        throw CInvalidPacket("short file reading tag count");
330
        throw CInvalidPacket("short file reading tag count");
336
        for (uint32 j = 0 ; j < tagcount ; j++)
331
        for (uint32 j = 0 ; j < tagcount ; j++)
337
        {
332
        {
338
            try
333
            try
339
            {
334
            {
340
                CTag *newtag = new CTag(file);
335
                CTag * newtag = new CTag(file);
341
                switch (newtag -> tag -> specialtag)
336
                switch (newtag -> tag -> specialtag)
342
                {
337
                {
343
                case FT_FILENAME:
338
                case FT_FILENAME:
Lines 416-446 Link Here
416
    return true;
411
    return true;
417
}
412
}
418
413
419
bool CKnownFile:: LoadDateFromFile(CFile *file)
414
bool CKnownFile::LoadDateFromFile(CFile * file)
420
{
415
{
421
    return(4 == file -> Read( &date, 4));
416
    return(4 == file -> Read( & date, 4));
422
}
417
}
423
418
424
bool CKnownFile:: LoadFromFile(CFile *file)
419
bool CKnownFile::LoadFromFile(CFile * file)
425
{
420
{
426
    return(LoadDateFromFile(file) &&LoadHashsetFromFile(file, false) &&LoadTagsFromFile(file));
421
    return(LoadDateFromFile(file) && LoadHashsetFromFile(file, false) && LoadTagsFromFile(file));
427
}
422
}
428
423
429
bool CKnownFile:: WriteToFile(FILE *file)
424
bool CKnownFile::WriteToFile(FILE * file)
430
{
425
{
431
    // date
426
    // date
432
    fwrite( &date, 4, 1, file);
427
    fwrite( & date, 4, 1, file);
433
    // hashset
428
    // hashset
434
    fwrite( &m_abyFileHash, 16, 1, file);
429
    fwrite( & m_abyFileHash, 16, 1, file);
435
    uint16 parts = hashlist.GetCount();
430
    uint16 parts = hashlist.GetCount();
436
    fwrite( &parts, 2, 1, file);
431
    fwrite( & parts, 2, 1, file);
437
    for (int i = 0 ; i != parts ; i++)
432
    for (int i = 0 ; i != parts ; i++)
438
    fwrite(hashlist[i], 16, 1, file);
433
    fwrite(hashlist[i], 16, 1, file);
439
    //tags
434
    //tags
440
#define NR_TAGS 10
435
#define NR_TAGS 10
441
    uint32 tagcount = taglist.GetCount() + NR_TAGS;
436
    uint32 tagcount = taglist.GetCount() + NR_TAGS;
442
    // standard tags
437
    // standard tags
443
    fwrite( &tagcount, 4, 1, file);
438
    fwrite( & tagcount, 4, 1, file);
444
    CTag(FT_FILENAME, m_pszFileName) .WriteTagToFile(file);
439
    CTag(FT_FILENAME, m_pszFileName) .WriteTagToFile(file);
445
    CTag(FT_FILESIZE, m_nFileSize) .WriteTagToFile(file);
440
    CTag(FT_FILESIZE, m_nFileSize) .WriteTagToFile(file);
446
    // statistic
441
    // statistic
Lines 461-467 Link Here
461
#undef NR_TAGS
456
#undef NR_TAGS
462
}
457
}
463
458
464
void CKnownFile:: CreateHashFromInput(FILE *file, CFile *file2, int Length, uchar *Output, uchar *in_string)
459
void CKnownFile::CreateHashFromFile( FILE * file, int Length, uchar * Output)
460
{
461
    if (file != NULL)
462
    {
463
        bool PaddingStarted = false;
464
        uint32 Hash[4];
465
        Hash[0] = 0x67452301;
466
        Hash[1] = 0xEFCDAB89;
467
        Hash[2] = 0x98BADCFE;
468
        Hash[3] = 0x10325476;
469
        uint32 Required = Length;
470
        uchar X[64 * 128];
471
        while (Required >= 64)
472
        {
473
            uint32 len = Required / 64;
474
            if (len > sizeof(X) / (64 * sizeof(X[0])))
475
            {
476
                len = sizeof(X) / (64 * sizeof(X[0]));
477
            }
478
            fread( & X, len * 64, 1, file);
479
            for (uint32 i = 0 ; i < len ; i++)
480
            {
481
                MD4Transform(Hash, (uint32 *)(X + i * 64));
482
            }
483
            Required -= len * 64;
484
        }
485
        // bytes to read
486
        Required = Length % 64;
487
        if (Required != 0)
488
        {
489
            fread( & X, Required, 1, file);
490
        }
491
        // in byte scale 512 = 64, 448 = 56
492
        if (Required >= 56)
493
        {
494
            X[Required] = 0x80;
495
            PaddingStarted = TRUE;
496
            memset( & X[Required + 1], 0, 63 - Required);
497
            MD4Transform(Hash, (uint32 *) X);
498
            Required = 0;
499
        }
500
        if (!PaddingStarted)
501
        {
502
            X[Required++] = 0x80;
503
        }
504
        memset( & X[Required], 0, 64 - Required);
505
        // add size (convert to bits)
506
        uint32 Length2 = Length >> 29;
507
        Length <<= 3;
508
        memcpy( & X[56], & Length, 4);
509
        memcpy( & X[60], & Length2, 4);
510
        MD4Transform(Hash, (uint32 *) X);
511
        memcpy(Output, Hash, 16);
512
    }
513
}
514
515
void CKnownFile::CreateHashFromInput(int id, FILE * file, CFile * file2, int Length, uchar * Output, uchar * in_string)
465
{
516
{
466
    // time critial
517
    // time critial
467
    bool PaddingStarted = false;
518
    bool PaddingStarted = false;
Lines 470-516 Link Here
470
    Hash[1] = 0xEFCDAB89;
521
    Hash[1] = 0xEFCDAB89;
471
    Hash[2] = 0x98BADCFE;
522
    Hash[2] = 0x98BADCFE;
472
    Hash[3] = 0x10325476;
523
    Hash[3] = 0x10325476;
473
    CMemFile *data = 0;
524
    CMemFile * data = 0;
474
    if (in_string)
525
    if (in_string)
475
    {
526
    {
476
        data = new CMemFile(in_string, Length);
527
        data = new CMemFile(in_string, Length);
477
    }
528
    }
478
    uint32 Required = Length;
529
    uint32 Required = Length;
479
    uchar X[64 *128];
530
    uchar X[64 * 128];
480
    while (Required >= 64)
531
    while (Required >= 64)
481
    {
532
    {
482
        uint32 len = Required / 64;
533
        uint32 len = Required / 64;
483
        if (len > sizeof(X) / (64 *sizeof(X[0])))
534
        if (len > sizeof(X) / (64 * sizeof(X[0])))
484
        len = sizeof(X) / (64 *sizeof(X[0]));
535
        len = sizeof(X) / (64 * sizeof(X[0]));
485
        if (in_string)
536
        if (in_string)
486
        data -> Read( &X, len *64);
537
        {
538
            data -> Read( & X, len * 64);
539
        }
487
        else if(file)
540
        else if(file)
488
        fread( &X, len *64, 1, file);
541
        {
542
            fread( & X, len * 64, 1, file);
543
        }
489
        else if(file2)
544
        else if(file2)
490
        file2 -> Read( &X, len *64);
545
        {
546
            file2 -> Read( & X, len * 64);
547
        }
491
        for (uint32 i = 0 ; i < len ; i++)
548
        for (uint32 i = 0 ; i < len ; i++)
492
        {
549
        {
493
            MD4Transform(Hash, (uint32 *)(X + i *64));
550
            MD4Transform(Hash, (uint32 *)(X + i * 64));
494
        }
551
        }
495
        Required -= len *64;
552
        Required -= len * 64;
496
    }
553
    }
497
    // bytes to read
554
    // bytes to read
498
    Required = Length % 64;
555
    Required = Length % 64;
499
    if (Required != 0)
556
    if (Required != 0)
500
    {
557
    {
501
        if (in_string)
558
        if (in_string)
502
        data -> Read( &X, Required);
559
        {
560
            data -> Read( & X, Required);
561
        }
503
        else if(file)
562
        else if(file)
504
        fread( &X, Required, 1, file);
563
        {
564
            fread( & X, Required, 1, file);
565
        }
505
        else if(file2)
566
        else if(file2)
506
        file2 -> Read( &X, Required);
567
        {
568
            file2 -> Read( & X, Required);
569
        }
507
    }
570
    }
508
    // in byte scale 512 = 64, 448 = 56
571
    // in byte scale 512 = 64, 448 = 56
509
    if (Required >= 56)
572
    if (Required >= 56)
510
    {
573
    {
511
        X[Required] = 0x80;
574
        X[Required] = 0x80;
512
        PaddingStarted = TRUE;
575
        PaddingStarted = TRUE;
513
        memset( &X[Required + 1], 0, 63 - Required);
576
        memset( & X[Required + 1], 0, 63 - Required);
514
        MD4Transform(Hash, (uint32 *) X);
577
        MD4Transform(Hash, (uint32 *) X);
515
        Required = 0;
578
        Required = 0;
516
    }
579
    }
Lines 518-654 Link Here
518
    {
581
    {
519
        X[Required++] = 0x80;
582
        X[Required++] = 0x80;
520
    }
583
    }
521
    memset( &X[Required], 0, 64 - Required);
584
    memset( & X[Required], 0, 64 - Required);
522
    // add size (convert to bits)
585
    // add size (convert to bits)
523
    uint32 Length2 = Length >> 29;
586
    uint32 Length2 = Length >> 29;
524
    Length <<= 3;
587
    Length <<= 3;
525
    memcpy( &X[56], &Length, 4);
588
    memcpy( & X[56], & Length, 4);
526
    memcpy( &X[60], &Length2, 4);
589
    memcpy( & X[60], & Length2, 4);
527
    MD4Transform(Hash, (uint32 *) X);
590
    MD4Transform(Hash, (uint32 *) X);
528
    memcpy(Output, Hash, 16);
591
    memcpy(Output, Hash, 16);
529
    safe_delete(data);
592
    safe_delete(data);
530
}
593
}
531
594
532
uchar *CKnownFile:: GetPartHash(uint16 part)
595
uchar * CKnownFile::GetPartHash(uint16 part)
533
{
596
{
534
    if (part >= hashlist.GetCount())
597
    if (part >= hashlist.GetCount())
598
    {
535
    return 0;
599
    return 0;
600
    }
536
    return hashlist[part];
601
    return hashlist[part];
537
}
602
}
538
603
539
static void MD4Transform(uint32 Hash[4], uint32 x[16])
604
void CAbstractFile::SetFileName(char * NewName)
540
{
541
    uint32 a = Hash[0];
542
    uint32 b = Hash[1];
543
    uint32 c = Hash[2];
544
    uint32 d = Hash[3];
545
    /* Round 1 */
546
    // 01:
547
    MD4_FF(a, b, c, d, x[ 0], S11);
548
    // 02:
549
    MD4_FF(d, a, b, c, x[ 1], S12);
550
    // 03:
551
    MD4_FF(c, d, a, b, x[ 2], S13);
552
    // 04:
553
    MD4_FF(b, c, d, a, x[ 3], S14);
554
    // 05:
555
    MD4_FF(a, b, c, d, x[ 4], S11);
556
    // 06:
557
    MD4_FF(d, a, b, c, x[ 5], S12);
558
    // 07:
559
    MD4_FF(c, d, a, b, x[ 6], S13);
560
    // 08:
561
    MD4_FF(b, c, d, a, x[ 7], S14);
562
    // 09:
563
    MD4_FF(a, b, c, d, x[ 8], S11);
564
    // 10:
565
    MD4_FF(d, a, b, c, x[ 9], S12);
566
    // 11:
567
    MD4_FF(c, d, a, b, x[10], S13);
568
    // 12:
569
    MD4_FF(b, c, d, a, x[11], S14);
570
    // 13:
571
    MD4_FF(a, b, c, d, x[12], S11);
572
    // 14:
573
    MD4_FF(d, a, b, c, x[13], S12);
574
    // 15:
575
    MD4_FF(c, d, a, b, x[14], S13);
576
    // 16:
577
    MD4_FF(b, c, d, a, x[15], S14);
578
    /* Round 2 */
579
    // 17:
580
    MD4_GG(a, b, c, d, x[ 0], S21);
581
    // 18:
582
    MD4_GG(d, a, b, c, x[ 4], S22);
583
    // 19:
584
    MD4_GG(c, d, a, b, x[ 8], S23);
585
    // 20:
586
    MD4_GG(b, c, d, a, x[12], S24);
587
    // 21:
588
    MD4_GG(a, b, c, d, x[ 1], S21);
589
    // 22:
590
    MD4_GG(d, a, b, c, x[ 5], S22);
591
    // 23:
592
    MD4_GG(c, d, a, b, x[ 9], S23);
593
    // 24:
594
    MD4_GG(b, c, d, a, x[13], S24);
595
    // 25:
596
    MD4_GG(a, b, c, d, x[ 2], S21);
597
    // 26:
598
    MD4_GG(d, a, b, c, x[ 6], S22);
599
    // 27:
600
    MD4_GG(c, d, a, b, x[10], S23);
601
    // 28:
602
    MD4_GG(b, c, d, a, x[14], S24);
603
    // 29:
604
    MD4_GG(a, b, c, d, x[ 3], S21);
605
    // 30:
606
    MD4_GG(d, a, b, c, x[ 7], S22);
607
    // 31:
608
    MD4_GG(c, d, a, b, x[11], S23);
609
    // 32:
610
    MD4_GG(b, c, d, a, x[15], S24);
611
    /* Round 3 */
612
    // 33:
613
    MD4_HH(a, b, c, d, x[ 0], S31);
614
    // 34:
615
    MD4_HH(d, a, b, c, x[ 8], S32);
616
    // 35:
617
    MD4_HH(c, d, a, b, x[ 4], S33);
618
    // 36:
619
    MD4_HH(b, c, d, a, x[12], S34);
620
    // 37:
621
    MD4_HH(a, b, c, d, x[ 2], S31);
622
    // 38:
623
    MD4_HH(d, a, b, c, x[10], S32);
624
    // 39:
625
    MD4_HH(c, d, a, b, x[ 6], S33);
626
    // 40:
627
    MD4_HH(b, c, d, a, x[14], S34);
628
    // 41:
629
    MD4_HH(a, b, c, d, x[ 1], S31);
630
    // 42:
631
    MD4_HH(d, a, b, c, x[ 9], S32);
632
    // 43:
633
    MD4_HH(c, d, a, b, x[ 5], S33);
634
    // 44:
635
    MD4_HH(b, c, d, a, x[13], S34);
636
    // 45:
637
    MD4_HH(a, b, c, d, x[ 3], S31);
638
    // 46:
639
    MD4_HH(d, a, b, c, x[11], S32);
640
    // 47:
641
    MD4_HH(c, d, a, b, x[ 7], S33);
642
    // 48:
643
    MD4_HH(b, c, d, a, x[15], S34);
644
    Hash[0] += a;
645
    Hash[1] += b;
646
    Hash[2] += c;
647
    Hash[3] += d;
648
}
649
650
// Adde by Tarod [Juanjo]
651
void CAbstractFile:: SetFileName(char *NewName)
652
{
605
{
653
    if (m_pszFileName != NULL)
606
    if (m_pszFileName != NULL)
654
    {
607
    {
Lines 669-685 Link Here
669
622
670
//End by Tarod
623
//End by Tarod
671
624
672
Packet *CKnownFile:: CreateSrcInfoPacket(CUpDownClient *forClient)
625
Packet * CKnownFile::CreateSrcInfoPacket(CUpDownClient * forClient)
673
{
626
{
674
    CTypedPtrList < CPtrList, CUpDownClient *> srclist;
627
    CTypedPtrList <CPtrList, CUpDownClient *> srclist;
675
    //should we use "filehash"?:
628
    //should we use "filehash"?:
676
    theApp.uploadqueue -> FindSourcesForFileById( &srclist, forClient -> GetUploadFileID());
629
    theApp.uploadqueue -> FindSourcesForFileById( & srclist, forClient -> GetUploadFileID());
677
    if (srclist.IsEmpty())
630
    if (srclist.IsEmpty())
678
    return 0;
631
    return 0;
679
    CMemFile data;
632
    CMemFile data;
680
    uint16 nCount = 0;
633
    uint16 nCount = 0;
681
    data.Write(forClient -> GetUploadFileID(), 16);
634
    data.Write(forClient -> GetUploadFileID(), 16);
682
    data.Write( &nCount, 2);
635
    data.Write( & nCount, 2);
683
    uint32 lastRequest = forClient -> GetLastSrcReqTime();
636
    uint32 lastRequest = forClient -> GetLastSrcReqTime();
684
    //we are only taking 30 random sources since we can't be sure if they have parts we need
637
    //we are only taking 30 random sources since we can't be sure if they have parts we need
685
    //this is hard coded because its a temp solution until next(?) version
638
    //this is hard coded because its a temp solution until next(?) version
Lines 688-705 Link Here
688
    {
641
    {
689
        int victim = ((rand() >> 7) % srclist.GetSize());
642
        int victim = ((rand() >> 7) % srclist.GetSize());
690
        POSITION pos = srclist.FindIndex(victim);
643
        POSITION pos = srclist.FindIndex(victim);
691
        CUpDownClient *cur_src = srclist.GetAt(pos);
644
        CUpDownClient * cur_src = srclist.GetAt(pos);
692
        if (!cur_src -> HasLowID() &&cur_src != forClient)
645
        if (!cur_src -> HasLowID() && cur_src != forClient)
693
        {
646
        {
694
            nCount++;
647
            nCount++;
695
            uint32 dwID = cur_src -> GetUserID();
648
            uint32 dwID = cur_src -> GetUserID();
696
            uint16 nPort = cur_src -> GetUserPort();
649
            uint16 nPort = cur_src -> GetUserPort();
697
            uint32 dwServerIP = cur_src -> GetServerIP();
650
            uint32 dwServerIP = cur_src -> GetServerIP();
698
            uint16 nServerPort = cur_src -> GetServerPort();
651
            uint16 nServerPort = cur_src -> GetServerPort();
699
            data.Write( &dwID, 4);
652
            data.Write( & dwID, 4);
700
            data.Write( &nPort, 2);
653
            data.Write( & nPort, 2);
701
            data.Write( &dwServerIP, 4);
654
            data.Write( & dwServerIP, 4);
702
            data.Write( &nServerPort, 2);
655
            data.Write( & nServerPort, 2);
703
            if (forClient -> GetSourceExchangeVersion() > 1)
656
            if (forClient -> GetSourceExchangeVersion() > 1)
704
            data.Write(cur_src -> GetUserHash(), 16);
657
            data.Write(cur_src -> GetUserHash(), 16);
705
        }
658
        }
Lines 710-717 Link Here
710
    if (!nCount)
663
    if (!nCount)
711
    return 0;
664
    return 0;
712
    data.Seek(16);
665
    data.Seek(16);
713
    data.Write( &nCount, 2);
666
    data.Write( & nCount, 2);
714
    Packet *result = new Packet( &data, OP_EMULEPROT);
667
    Packet * result = new Packet( & data, OP_EMULEPROT);
715
    result -> opcode = OP_ANSWERSOURCES;
668
    result -> opcode = OP_ANSWERSOURCES;
716
    if (nCount > 28)
669
    if (nCount > 28)
717
    result -> PackPacket();
670
    result -> PackPacket();
Lines 719-725 Link Here
719
}
672
}
720
673
721
// Updates priority of file if autopriority is activated
674
// Updates priority of file if autopriority is activated
722
void CKnownFile:: UpdateAutoUpPriority(void)
675
void CKnownFile::UpdateAutoUpPriority(void)
723
{
676
{
724
    if (!this -> IsAutoUpPriority())
677
    if (!this -> IsAutoUpPriority())
725
    return;
678
    return;
Lines 749-758 Link Here
749
}
702
}
750
703
751
//For File Comment //
704
//For File Comment //
752
void CKnownFile:: LoadComment()
705
void CKnownFile::LoadComment()
753
{
706
{
754
    char buffer[100];
707
    char buffer[100];
755
    char *fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13];
708
    char * fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13];
756
    sprintf(fullpath, "%sfileinfo.ini", theApp.glob_prefs -> GetAppDir());
709
    sprintf(fullpath, "%sfileinfo.ini", theApp.glob_prefs -> GetAppDir());
757
    buffer[0] = 0;
710
    buffer[0] = 0;
758
    for (uint16 i = 0 ; i != 16 ; i++)
711
    for (uint16 i = 0 ; i != 16 ; i++)
Lines 765-774 Link Here
765
    delete[] fullpath;
718
    delete[] fullpath;
766
}
719
}
767
720
768
void CKnownFile:: SetFileComment(CString strNewComment)
721
void CKnownFile::SetFileComment(CString strNewComment)
769
{
722
{
770
    char buffer[100];
723
    char buffer[100];
771
    char *fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13];
724
    char * fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13];
772
    sprintf(fullpath, "%sfileinfo.ini", theApp.glob_prefs -> GetAppDir());
725
    sprintf(fullpath, "%sfileinfo.ini", theApp.glob_prefs -> GetAppDir());
773
    buffer[0] = 0;
726
    buffer[0] = 0;
774
    for (uint16 i = 0 ; i != 16 ; i++)
727
    for (uint16 i = 0 ; i != 16 ; i++)
Lines 777-796 Link Here
777
    ini.WriteString("Comment", strNewComment);
730
    ini.WriteString("Comment", strNewComment);
778
    m_strComment = strNewComment;
731
    m_strComment = strNewComment;
779
    delete fullpath;
732
    delete fullpath;
780
    CTypedPtrList < CPtrList, CUpDownClient *> srclist;
733
    CTypedPtrList <CPtrList, CUpDownClient *> srclist;
781
    theApp.uploadqueue -> FindSourcesForFileById( &srclist, this -> GetFileHash());
734
    theApp.uploadqueue -> FindSourcesForFileById( & srclist, this -> GetFileHash());
782
    for (POSITION pos = srclist.GetHeadPosition() ; pos != 0 ; srclist.GetNext(pos))
735
    for (POSITION pos = srclist.GetHeadPosition() ; pos != 0 ; srclist.GetNext(pos))
783
    {
736
    {
784
        CUpDownClient *cur_src = srclist.GetAt(pos);
737
        CUpDownClient * cur_src = srclist.GetAt(pos);
785
        cur_src -> SetCommentDirty();
738
        cur_src -> SetCommentDirty();
786
    }
739
    }
787
}
740
}
788
741
789
// For File rate
742
// For File rate
790
void CKnownFile:: SetFileRate(int8 iNewRate)
743
void CKnownFile::SetFileRate(int8 iNewRate)
791
{
744
{
792
    char buffer[100];
745
    char buffer[100];
793
    char *fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13];
746
    char * fullpath = new char[strlen(theApp.glob_prefs -> GetAppDir()) + 13];
794
    sprintf(fullpath, "%sfileinfo.ini", theApp.glob_prefs -> GetAppDir());
747
    sprintf(fullpath, "%sfileinfo.ini", theApp.glob_prefs -> GetAppDir());
795
    buffer[0] = 0;
748
    buffer[0] = 0;
796
    for (uint16 i = 0 ; i != 16 ; i++)
749
    for (uint16 i = 0 ; i != 16 ; i++)
Lines 799-817 Link Here
799
    ini.WriteInt("Rate", iNewRate);
752
    ini.WriteInt("Rate", iNewRate);
800
    m_iRate = iNewRate;
753
    m_iRate = iNewRate;
801
    delete fullpath;
754
    delete fullpath;
802
    CTypedPtrList < CPtrList, CUpDownClient *> srclist;
755
    CTypedPtrList <CPtrList, CUpDownClient *> srclist;
803
    theApp.uploadqueue -> FindSourcesForFileById( &srclist, this -> GetFileHash());
756
    theApp.uploadqueue -> FindSourcesForFileById( & srclist, this -> GetFileHash());
804
    for (POSITION pos = srclist.GetHeadPosition() ; pos != 0 ; srclist.GetNext(pos))
757
    for (POSITION pos = srclist.GetHeadPosition() ; pos != 0 ; srclist.GetNext(pos))
805
    {
758
    {
806
        CUpDownClient *cur_src = srclist.GetAt(pos);
759
        CUpDownClient * cur_src = srclist.GetAt(pos);
807
        cur_src -> SetCommentDirty();
760
        cur_src -> SetCommentDirty();
808
    }
761
    }
809
}
762
}
810
763
811
void CKnownFile:: SetUpPriority(uint8 iNewUpPriority, bool m_bsave)
764
void CKnownFile::SetUpPriority(uint8 iNewUpPriority, bool m_bsave)
812
{
765
{
813
    m_iUpPriority = iNewUpPriority;
766
    m_iUpPriority = iNewUpPriority;
814
    if (this -> IsPartFile() &&m_bsave)
767
    if (this -> IsPartFile() && m_bsave)
815
    ((CPartFile *) this) -> SavePartFile();
768
    ((CPartFile *) this) -> SavePartFile();
816
}
769
}
817
770
(-)xmule/src/KnownFile.h (-33 / +6 lines)
Lines 108-114 Link Here
108
	CKnownFile();
108
	CKnownFile();
109
	~CKnownFile();
109
	~CKnownFile();
110
110
111
	virtual bool	CreateFromFile(char* directory,char* filename, volatile int const * notify); // create date, hashset and tags from a file
111
	virtual bool	CreateFromFile(void* pf,char* directory,char* filename, volatile int const * notify); // create date, hashset and tags from a file
112
	uint32*	GetFileTypePtr()		{return &m_iFileType;}
112
	uint32*	GetFileTypePtr()		{return &m_iFileType;}
113
	char*	GetPath()				{return directory;}
113
	char*	GetPath()				{return directory;}
114
	void	SetPath(char* path);
114
	void	SetPath(char* path);
Lines 154-169 Link Here
154
protected:
154
protected:
155
	bool	LoadTagsFromFile(CFile* file);
155
	bool	LoadTagsFromFile(CFile* file);
156
	bool	LoadDateFromFile(CFile* file);
156
	bool	LoadDateFromFile(CFile* file);
157
	void	CreateHashFromFile(FILE* file, int Length, uchar* Output)	{CreateHashFromInput(file,0,Length,Output,0);}
157
	void	CreateHashFromFile(FILE* file, int Length, uchar* Output);
158
	void	CreateHashFromFile(CFile* file, int Length, uchar* Output)	{CreateHashFromInput(0,file,Length,Output,0);}
158
	void	CreateHashFromString(uchar* in_string, int Length, uchar* Output)	{CreateHashFromInput(0,0,0,Length,Output,in_string);}
159
	void	CreateHashFromString(uchar* in_string, int Length, uchar* Output)	{CreateHashFromInput(0,0,Length,Output,in_string);}
160
	void	LoadComment();//comment
159
	void	LoadComment();//comment
161
	CArray<uchar*,uchar*> hashlist;
160
	CArray<uchar*,uchar*> hashlist;
162
	CArray<CTag*,CTag*> taglist;
161
	CArray<CTag*,CTag*> taglist;
163
	char*	directory;
162
	char*	directory;
164
163
165
private:
164
private:
166
	void	CreateHashFromInput(FILE* file,CFile* file2, int Length, uchar* Output, uchar* = 0);
165
	void	CreateHashFromInput(int id,FILE* file,CFile* file2, int Length, uchar* Output, uchar* = 0);
167
	bool	m_bCommentLoaded;
166
	bool	m_bCommentLoaded;
168
	uint16	m_iPartCount;
167
	uint16	m_iPartCount;
169
        uint16  m_iED2KPartCount;
168
        uint16  m_iED2KPartCount;
Lines 174-179 Link Here
174
	uint32	m_iQueuedCount;
173
	uint32	m_iQueuedCount;
175
	static	CBarShader s_ShareStatusBar;
174
	static	CBarShader s_ShareStatusBar;
176
	bool	m_PublishedED2K;
175
	bool	m_PublishedED2K;
176
	int	m_isDynamic;
177
	long	m_hfilepos;
177
178
178
public:
179
public:
179
	time_t	m_nCompleteSourcesTime;
180
	time_t	m_nCompleteSourcesTime;
Lines 191-222 Link Here
191
#define PERM_NOONE		2
192
#define PERM_NOONE		2
192
193
193
194
194
// basic MD4 functions
195
#define MD4_F(x, y, z) (((x) & (y)) | ((~x) & (z)))
196
#define MD4_G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
197
#define MD4_H(x, y, z) ((x) ^ (y) ^ (z))
198
199
// rotates x left n bits
200
#define MD4_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
201
202
// partial transformations
203
#define MD4_FF(a, b, c, d, x, s) \
204
{ \
205
  (a) += MD4_F((b), (c), (d)) + (x); \
206
  (a) = MD4_ROTATE_LEFT((a), (s)); \
207
}
208
209
#define MD4_GG(a, b, c, d, x, s) \
210
{ \
211
  (a) += MD4_G((b), (c), (d)) + (x) + (uint32)0x5A827999; \
212
  (a) = MD4_ROTATE_LEFT((a), (s)); \
213
}
214
215
#define MD4_HH(a, b, c, d, x, s) \
216
{ \
217
  (a) += MD4_H((b), (c), (d)) + (x) + (uint32)0x6ED9EBA1; \
218
  (a) = MD4_ROTATE_LEFT((a), (s)); \
219
}
220
221
222
#endif
195
#endif
(-)xmule/src/NewFunctions.cpp (+135 lines)
Lines 34-44 Link Here
34
#include "NewFunctions.h"
34
#include "NewFunctions.h"
35
#include "otherfunctions.h"
35
#include "otherfunctions.h"
36
36
37
38
void MD4Transform(uint32 Hash[4], uint32 x[16])
39
{
40
// constants for MD4Transform
41
#define S11 3
42
#define S12 7
43
#define S13 11
44
#define S14 19
45
#define S21 3
46
#define S22 5
47
#define S23 9
48
#define S24 13
49
#define S31 3
50
#define S32 9
51
#define S33 11
52
#define S34 15
53
54
    uint32 a = Hash[0];
55
    uint32 b = Hash[1];
56
    uint32 c = Hash[2];
57
    uint32 d = Hash[3];
58
    /* Round 1 */
59
    // 01:
60
    MD4_FF(a, b, c, d, x[0], S11);
61
    // 02:
62
    MD4_FF(d, a, b, c, x[1], S12);
63
    // 03:
64
    MD4_FF(c, d, a, b, x[2], S13);
65
    // 04:
66
    MD4_FF(b, c, d, a, x[3], S14);
67
    // 05:
68
    MD4_FF(a, b, c, d, x[4], S11);
69
    // 06:
70
    MD4_FF(d, a, b, c, x[5], S12);
71
    // 07:
72
    MD4_FF(c, d, a, b, x[6], S13);
73
    // 08:
74
    MD4_FF(b, c, d, a, x[7], S14);
75
    // 09:
76
    MD4_FF(a, b, c, d, x[8], S11);
77
    // 10:
78
    MD4_FF(d, a, b, c, x[9], S12);
79
    // 11:
80
    MD4_FF(c, d, a, b, x[10], S13);
81
    // 12:
82
    MD4_FF(b, c, d, a, x[11], S14);
83
    // 13:
84
    MD4_FF(a, b, c, d, x[12], S11);
85
    // 14:
86
    MD4_FF(d, a, b, c, x[13], S12);
87
    // 15:
88
    MD4_FF(c, d, a, b, x[14], S13);
89
    // 16:
90
    MD4_FF(b, c, d, a, x[15], S14);
91
    /* Round 2 */
92
    // 17:
93
    MD4_GG(a, b, c, d, x[0], S21);
94
    // 18:
95
    MD4_GG(d, a, b, c, x[4], S22);
96
    // 19:
97
    MD4_GG(c, d, a, b, x[8], S23);
98
    // 20:
99
    MD4_GG(b, c, d, a, x[12], S24);
100
    // 21:
101
    MD4_GG(a, b, c, d, x[1], S21);
102
    // 22:
103
    MD4_GG(d, a, b, c, x[5], S22);
104
    // 23:
105
    MD4_GG(c, d, a, b, x[9], S23);
106
    // 24:
107
    MD4_GG(b, c, d, a, x[13], S24);
108
    // 25:
109
    MD4_GG(a, b, c, d, x[2], S21);
110
    // 26:
111
    MD4_GG(d, a, b, c, x[6], S22);
112
    // 27:
113
    MD4_GG(c, d, a, b, x[10], S23);
114
    // 28:
115
    MD4_GG(b, c, d, a, x[14], S24);
116
    // 29:
117
    MD4_GG(a, b, c, d, x[3], S21);
118
    // 30:
119
    MD4_GG(d, a, b, c, x[7], S22);
120
    // 31:
121
    MD4_GG(c, d, a, b, x[11], S23);
122
    // 32:
123
    MD4_GG(b, c, d, a, x[15], S24);
124
    /* Round 3 */
125
    // 33:
126
    MD4_HH(a, b, c, d, x[0], S31);
127
    // 34:
128
    MD4_HH(d, a, b, c, x[8], S32);
129
    // 35:
130
    MD4_HH(c, d, a, b, x[4], S33);
131
    // 36:
132
    MD4_HH(b, c, d, a, x[12], S34);
133
    // 37:
134
    MD4_HH(a, b, c, d, x[2], S31);
135
    // 38:
136
    MD4_HH(d, a, b, c, x[10], S32);
137
    // 39:
138
    MD4_HH(c, d, a, b, x[6], S33);
139
    // 40:
140
    MD4_HH(b, c, d, a, x[14], S34);
141
    // 41:
142
    MD4_HH(a, b, c, d, x[1], S31);
143
    // 42:
144
    MD4_HH(d, a, b, c, x[9], S32);
145
    // 43:
146
    MD4_HH(c, d, a, b, x[5], S33);
147
    // 44:
148
    MD4_HH(b, c, d, a, x[13], S34);
149
    // 45:
150
    MD4_HH(a, b, c, d, x[3], S31);
151
    // 46:
152
    MD4_HH(d, a, b, c, x[11], S32);
153
    // 47:
154
    MD4_HH(c, d, a, b, x[7], S33);
155
    // 48:
156
    MD4_HH(b, c, d, a, x[15], S34);
157
    Hash[0] += a;
158
    Hash[1] += b;
159
    Hash[2] += c;
160
    Hash[3] += d;
161
}
162
37
uint32 MapData(MAP *pos)
163
uint32 MapData(MAP *pos)
38
{
164
{
39
    return pos -> Data;
165
    return pos -> Data;
40
}
166
}
41
167
168
void md4printf(const void *hash)
169
{
170
printf("md4hash: ");
171
for(int i=0;i<16;i++) {
172
printf("%02x",((unsigned char *)hash)[i]);
173
}
174
printf("\n");
175
}
176
42
unsigned char *MapDataKey(MAP *pos)
177
unsigned char *MapDataKey(MAP *pos)
43
{
178
{
44
    return pos -> Key;
179
    return pos -> Key;
(-)xmule/src/NewFunctions.h (+29 lines)
Lines 24-29 Link Here
24
24
25
#define		MAPCLIENTS_MAX		30000
25
#define		MAPCLIENTS_MAX		30000
26
26
27
// basic MD4 functions
28
#define MD4_F(x, y, z) (((x) & (y)) | ((~x) & (z)))
29
#define MD4_G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
30
#define MD4_H(x, y, z) ((x) ^ (y) ^ (z))
31
32
// rotates x left n bits
33
#define MD4_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
34
35
// partial transformations
36
#define MD4_FF(a, b, c, d, x, s) \
37
{ \
38
  (a) += MD4_F((b), (c), (d)) + (x); \
39
  (a) = MD4_ROTATE_LEFT((a), (s)); \
40
}
41
42
#define MD4_GG(a, b, c, d, x, s) \
43
{ \
44
  (a) += MD4_G((b), (c), (d)) + (x) + (uint32)0x5A827999; \
45
  (a) = MD4_ROTATE_LEFT((a), (s)); \
46
}
47
48
#define MD4_HH(a, b, c, d, x, s) \
49
{ \
50
  (a) += MD4_H((b), (c), (d)) + (x) + (uint32)0x6ED9EBA1; \
51
  (a) = MD4_ROTATE_LEFT((a), (s)); \
52
}
53
void MD4Transform(uint32 Hash[4],uint32 x[16]);
54
void md4printf(const void *hash);
55
27
typedef struct _MAP
56
typedef struct _MAP
28
{
57
{
29
	_MAP*	next;
58
	_MAP*	next;
(-)xmule/src/PartFile.cpp (-497 / +850 lines)
Lines 41-46 Link Here
41
#	include "DownloadQueue.h"
41
#	include "DownloadQueue.h"
42
#	include "ED2KLink.h"
42
#	include "ED2KLink.h"
43
#	include "ini2.h"
43
#	include "ini2.h"
44
#	include "NewFunctions.h"
44
#	include "otherfunctions.h"
45
#	include "otherfunctions.h"
45
#	include "PartFile.h"
46
#	include "PartFile.h"
46
#	include "Preview.h"
47
#	include "Preview.h"
Lines 62-101 Link Here
62
#include <arpa/inet.h>
63
#include <arpa/inet.h>
63
64
64
#include <wx/filename.h>
65
#include <wx/filename.h>
66
#include <wx/file.h>
65
67
66
#define min(a,b) ((a)<(b)?(a):(b))
68
#define min(a,b) ((a)<(b)?(a):(b))
67
#define PROGRESS_HEIGHT 3
69
#define PROGRESS_HEIGHT 3
68
70
69
void dump16f(FILE *f, uchar *d16)
71
void dump16f(FILE * f, uchar * d16)
70
{
72
{
71
    int i;
73
    int i;
72
    for (i = 0 ; i < 16 ; i++)
74
    for (i = 0 ; i < 16 ; i++)
73
    {
75
    {
74
        fprintf(f, "%02X", *d16++);
76
        fprintf(f, "%02X", * d16++);
75
    }
77
    }
76
}
78
}
77
79
78
void dump16(uchar *d16)
80
void dump16(uchar * d16)
79
{
81
{
80
    int i;
82
    int i;
81
    for (i = 0 ; i < 16 ; i++)
83
    for (i = 0 ; i < 16 ; i++)
82
    {
84
    {
83
        printf("%02X", *d16++);
85
        printf("%02X", * d16++);
84
    }
86
    }
85
}
87
}
86
88
87
extern void dump16(uchar *);
89
extern void dump16(uchar *);
88
90
89
CBarShader CPartFile:: s_LoadBar(PROGRESS_HEIGHT);
91
int bsize = 128 * 1024;
92
unsigned char buffer1[128 * 1024 + 1];
90
93
91
CBarShader CPartFile:: s_ChunkBar(16);
94
CBarShader CPartFile::s_LoadBar(PROGRESS_HEIGHT);
92
95
93
CPartFile:: CPartFile()
96
CBarShader CPartFile::s_ChunkBar(16);
97
98
CPartFile::CPartFile()
94
{
99
{
95
    Init();
100
    Init();
96
}
101
}
97
102
98
CPartFile:: CPartFile(CSearchFile *searchresult)
103
CPartFile::CPartFile(CSearchFile * searchresult)
99
{
104
{
100
    Init();
105
    Init();
101
    memcpy(m_abyFileHash, searchresult -> GetFileHash(), 16);
106
    memcpy(m_abyFileHash, searchresult -> GetFileHash(), 16);
Lines 114-171 Link Here
114
                break;
119
                break;
115
            }
120
            }
116
        default:
121
        default:
117
            CTag *newtag = new CTag(searchresult -> taglist[i] -> tag);
122
            CTag * newtag = new CTag(searchresult -> taglist[i] -> tag);
118
            taglist.Add(newtag);
123
            taglist.Add(newtag);
119
        }
124
        }
120
    }
125
    }
126
    m_hfilepos = 0;
127
    if (newprefs01_opt[5])
128
    {
129
        m_isDynamic |= 3;
130
        m_nHeaderLength = (m_nFileSize/ bsize + 1) * 8;
131
        m_nDynBloCount = 0;
132
    }
133
    else
134
    {
135
        m_isDynamic = 0;
136
        m_nHeaderLength = 0;
137
        m_nDynBloCount = 0;
138
    }
121
    CreatePartFile();
139
    CreatePartFile();
122
}
140
}
123
141
124
CPartFile:: CPartFile(CString edonkeylink)
142
CPartFile::CPartFile(wxString edonkeylink)
125
{
143
{
126
    CED2KLink *pLink = 0;
144
    CED2KLink * pLink = 0;
127
    try
145
    pLink = CED2KLink::CreateLinkFromUrl(edonkeylink);
128
    {
146
    CED2KFileLink * pFileLink = pLink -> GetFileLink();
129
        pLink = CED2KLink:: CreateLinkFromUrl(edonkeylink);
130
        CED2KFileLink *pFileLink = pLink -> GetFileLink();
131
        if (pFileLink == 0)
147
        if (pFileLink == 0)
132
        throw GetResString(IDS_ERR_NOTAFILELINK);
148
        throw GetResString(IDS_ERR_NOTAFILELINK);
133
        InitializeFromLink(pFileLink);
149
        InitializeFromLink(pFileLink);
134
    }
135
    catch(wxString error)
136
    {
137
        char buffer[200];
138
        sprintf(buffer, GetResString(IDS_ERR_INVALIDLINK), error.GetData());
139
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_LINKERROR), buffer);
140
        SetPartFileStatus(PS_ERROR);
141
    }
142
    delete pLink;
150
    delete pLink;
143
}
151
}
144
152
145
void
153
void
146
CPartFile:: InitializeFromLink(CED2KFileLink *fileLink)
154
CPartFile::InitializeFromLink(CED2KFileLink * fileLink)
147
{
155
{
148
    Init();
156
    Init();
149
    m_pszFileName = nstrdup(fileLink -> GetName());
157
    m_pszFileName = nstrdup(fileLink -> GetName());
150
    m_nFileSize = fileLink -> GetSize();
158
    m_nFileSize = fileLink -> GetSize();
151
    memcpy(m_abyFileHash, fileLink -> GetHashKey(), sizeof(m_abyFileHash));
159
    memcpy(m_abyFileHash, fileLink -> GetHashKey(), sizeof(m_abyFileHash));
152
    if (!theApp.downloadqueue -> IsFileExisting(m_abyFileHash))
160
    if (!theApp.downloadqueue -> IsFileExisting(m_abyFileHash))
161
    {
153
    CreatePartFile();
162
    CreatePartFile();
163
    }
154
    else
164
    else
165
    {
155
    SetPartFileStatus(PS_ERROR);
166
    SetPartFileStatus(PS_ERROR);
167
    }
156
}
168
}
157
169
158
CPartFile:: CPartFile(CED2KFileLink *fileLink)
170
CPartFile::CPartFile(CED2KFileLink * fileLink)
159
{
171
{
160
    InitializeFromLink(fileLink);
172
    InitializeFromLink(fileLink);
161
}
173
}
162
174
163
void CPartFile:: Init()
175
void CPartFile::Init()
164
{
176
{
165
    fullname = 0;
177
    fullname = 0;
166
    newdate = true;
178
    newdate = true;
167
    lastsearchtime = 0;
179
    lastsearchtime = 0;
168
    lastpurgetime =:: GetTickCount();
180
    lastpurgetime =::GetTickCount();
169
    paused = false;
181
    paused = false;
170
    stopped = false;
182
    stopped = false;
171
    SetPartFileStatus(PS_EMPTY);
183
    SetPartFileStatus(PS_EMPTY);
Lines 186-193 Link Here
186
    hashsetneeded = true;
198
    hashsetneeded = true;
187
    count = 0;
199
    count = 0;
188
    percentcompleted = 0;
200
    percentcompleted = 0;
189
    partmetfilename = 0;
201
    partmetfilename = "";
190
    completedsize = 0;
202
    completedsize = 0;
203
    isnewstyle = false;
204
    partmettype = PMT_UNKNOWN;
191
    m_bPreviewing = false;
205
    m_bPreviewing = false;
192
    //NULL;:
206
    //NULL;:
193
    lastseencomplete = 0;
207
    lastseencomplete = 0;
Lines 212-287 Link Here
212
    m_category = 0;
226
    m_category = 0;
213
    m_lastRefreshedDLDisplay = 0;
227
    m_lastRefreshedDLDisplay = 0;
214
    m_LastSourceDropTime = 0;
228
    m_LastSourceDropTime = 0;
229
    m_isDynamic = 0;
230
    m_nHeaderLength = 0;
231
    m_nDynBloCount = 0;
232
    m_nFileSize = 0;
233
    convertstate=0;
215
}
234
}
216
235
217
CPartFile:: ~CPartFile()
236
CPartFile::~ CPartFile()
218
{
237
{
219
    // Barry - Ensure all buffered data is written
220
    FlushBuffer();
238
    FlushBuffer();
221
    //m_hpartfile.Flush();
222
    //SavePartFile();
223
    //m_hpartfile.Close();
224
    if (fullname)
239
    if (fullname)
240
    {
225
    delete[] fullname;
241
    delete[] fullname;
226
    if (partmetfilename)
242
    }
227
    delete[] partmetfilename;
228
    m_SrcpartFrequency.RemoveAll();
243
    m_SrcpartFrequency.RemoveAll();
229
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
244
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
245
    {
230
    delete gaplist.GetAt(pos);
246
    delete gaplist.GetAt(pos);
247
    }
248
}
249
250
long CPartFile:: Read(void * buffer, long bytes)
251
{
252
    unsigned char tag[8];
253
    long bytecount = 0;
254
    if (IsDynamic() < 2)
255
    {
256
        bytecount = m_hpartfile.Read(buffer, bytes);
257
        m_hfilepos += bytecount;
258
    }
259
    else
260
    {
261
        unsigned long tag_number = 0, tag_blpo = 0;
262
        int tag_blnr, tag_bytes, filesize;
263
        unsigned char * bufferpos;
264
        bufferpos = (unsigned char *) buffer;
265
        if ((bytes + m_hfilepos) > m_nFileSize)
266
        {
267
            bytes = m_nFileSize - m_hfilepos;
268
            if (bytes < 0)
269
            {
270
                bytes = 0;
271
            }
272
        }
273
        while (bytecount < bytes)
274
        {
275
            tag_number = m_hfilepos/ bsize;
276
            tag_blpo = m_hfilepos - bsize * tag_number;
277
            tag_bytes = bsize - tag_blpo;
278
            if (tag_bytes > (bytes - bytecount))
279
            {
280
                tag_bytes = bytes - bytecount;
281
            }
282
            m_hpartfile.Readpos( & tag_blnr, tag_number * 8, 4);
283
            m_hpartfile.Readpos( & filesize, tag_number * 8 + 4, 4);
284
            if (tag_blnr)
285
            {
286
                tag_bytes = m_hpartfile.Readpos(bufferpos, m_nHeaderLength + (tag_blnr - 1) * bsize + tag_blpo, tag_bytes);
287
            }
288
            else
289
            {
290
                for (int i = 0 ; i < tag_bytes ; i++)
291
                {
292
                    bufferpos[i] = 0;
293
                }
294
            }
295
            if (tag_bytes)
296
            {
297
                m_hfilepos += tag_bytes;
298
                bufferpos += tag_bytes;
299
                bytecount += tag_bytes;
300
            }
301
            else
302
            {
303
                bytecount = bytes;
304
            }
305
        }
306
        bytecount = bytes;
307
    }
308
    return bytecount;
309
}
310
311
bool CPartFile:: Store(const wxString & newname)
312
{
313
    unsigned char * buffer;
314
    int tag_number = 0;
315
    int next = 0;
316
    long bytepos = 0, bytes = 0;
317
    wxFile fileOut(newname, wxFile:: write);
318
    while (bytepos < m_nFileSize)
319
    {
320
        buffer = buffer1;
321
        bytes = bsize;
322
        if ((bytepos + bytes) > m_nFileSize)
323
        {
324
            bytes = m_nFileSize - bytepos;
325
        }
326
        m_hpartfile.Readpos( & next, tag_number * 8, 4);
327
        (void) m_hpartfile.Readpos(buffer1, m_nHeaderLength + (next - 1) * bsize, bytes);
328
        while (bytes > 0)
329
        {
330
            if (bytes > 4095)
331
            {
332
                fileOut.Write(buffer, 4096);
333
                buffer += 4096;
334
                bytes -= 4096;
335
            }
336
            else
337
            {
338
                fileOut.Write(buffer, bytes);
339
                buffer += bytes;
340
                bytes = 0;
341
            }
342
        }
343
        tag_number++;
344
        bytepos += bsize;
345
    }
346
    (void) fileOut.Close();
347
    return true;
348
}
349
350
long CPartFile:: Write(void * buffer, long bytes)
351
{
352
    unsigned char tag[8];
353
    long bytecount = 0;
354
    if (IsDynamic() < 2)
355
    {
356
        m_hfilepos += bytes;
357
        if (Length() <= (m_hfilepos - 1))
358
        {
359
            ftruncate(m_hpartfile.fd(), m_hfilepos);
360
        }
361
        bytecount = m_hpartfile.Write(buffer, bytes);
362
    }
363
    else
364
    {
365
        unsigned long tag_number = 0, tag_blpo = 0;
366
        int tag_blnr, tag_bytes, filesize;
367
        unsigned char * bufferpos;
368
        bufferpos = (unsigned char *) buffer;
369
        bytecount = bytes;
370
        while (bytecount > 0)
371
        {
372
            tag_number = m_hfilepos/ bsize;
373
            tag_blpo = m_hfilepos - bsize * tag_number;
374
            tag_bytes = bsize - tag_blpo;
375
            if (tag_bytes > bytecount)
376
            {
377
                tag_bytes = bytecount;
378
            }
379
            m_hpartfile.Readpos( & tag_blnr, tag_number * 8, 4);
380
            m_hpartfile.Readpos( & filesize, tag_number * 8 + 4, 4);
381
            if (!tag_blnr)
382
            {
383
                m_nDynBloCount++;
384
                tag_blnr = m_nDynBloCount;
385
                m_hpartfile.Writepos( & tag_blnr, tag_number * 8, 4);
386
                ftruncate(m_hpartfile.fd(), m_nHeaderLength + tag_blnr * bsize);
387
            }
388
            tag_bytes = m_hpartfile.Writepos(bufferpos, m_nHeaderLength + (tag_blnr - 1) * bsize + tag_blpo, tag_bytes);
389
            if (tag_bytes)
390
            {
391
                m_hfilepos += tag_bytes;
392
                if (m_hfilepos > m_ilength)
393
                {
394
                    m_ilength = m_hfilepos;
395
                }
396
                bufferpos += tag_bytes;
397
                bytecount -= tag_bytes;
398
                if (filesize < m_hfilepos)
399
                {
400
                    filesize = m_hfilepos;
401
                    m_hpartfile.Writepos( & filesize, tag_number * 8 + 4, 4);
402
                }
403
            }
404
            else
405
            {
406
                bytecount = - bytecount;
407
            }
408
        }
409
        if (bytecount < 0)
410
        {
411
            bytecount = - bytecount;
412
        }
413
    }
414
    return bytecount;
231
}
415
}
232
416
233
void CPartFile:: CreatePartFile()
417
void CPartFile::Seek(unsigned long filepos)
418
{
419
    if (IsDynamic() < 2)
420
    {
421
        m_hpartfile.Seek(filepos);
422
    }
423
    m_hfilepos = filepos;
424
}
425
426
void CPartFile::Close()
427
{
428
    m_hpartfile.Close();
429
}
430
431
unsigned long CPartFile::Length()
432
{
433
    unsigned long result;
434
    result = m_hpartfile.Length();
435
    if (IsDynamic() > 1)
436
    {
437
        m_nHeaderLength = (m_nFileSize/ bsize + 1) * 8;
438
        result -= m_nHeaderLength;
439
    }
440
    else
441
    {
442
        m_nHeaderLength = 0;
443
    }
444
    return result;
445
}
446
447
void CPartFile::CreatePartFile()
234
{
448
{
235
    // use lowest free partfilenumber for free file (InterCeptor)
449
    // use lowest free partfilenumber for free file (InterCeptor)
236
    int i = 0;
450
    int i = 0;
237
    CString filename;
451
    wxString filename;
238
    do
452
    do
239
    {
453
    {
240
        i++;
454
        i++;
241
        if (newprefs01_opt[5])
455
        if (newprefs01_opt[5])
242
        {
456
        {
243
            filename.Format("%s/%03i.pnew", theApp.glob_prefs -> GetTempDir(), i);
457
            filename = wxString::Format("%s/%03i.pnew", theApp.glob_prefs -> GetTempDir(), i);
244
        }
458
        }
245
        else
459
        else
246
        {
460
        {
247
            filename.Format("%s/%03i.part", theApp.glob_prefs -> GetTempDir(), i);
461
            filename = wxString::Format("%s/%03i.part", theApp.glob_prefs -> GetTempDir(), i);
248
        }
462
        }
249
    }
463
    }
250
    while (wxFileName:: FileExists(filename));
464
    while (wxFileName::FileExists(filename));
251
    partmetfilename = new char[15];
252
    if (newprefs01_opt[5])
465
    if (newprefs01_opt[5])
253
    {
466
    {
254
        sprintf(partmetfilename, "%03i.pnew.met", i);
467
        partmetfilename = wxString:: Format("%03i.pnew.met", i);
255
    }
468
    }
256
    else
469
    else
257
    {
470
    {
258
        sprintf(partmetfilename, "%03i.part.met", i);
471
        partmetfilename = wxString:: Format("%03i.part.met", i);
259
    }
472
    }
260
    fullname = new char[strlen(theApp.glob_prefs -> GetTempDir()) + strlen(partmetfilename) + MAX_PATH];
473
    fullname = new char[strlen(theApp.glob_prefs -> GetTempDir()) + partmetfilename.Len() + MAX_PATH];
261
    sprintf(fullname, "%s/%s", theApp.glob_prefs -> GetTempDir(), partmetfilename);
474
    sprintf(fullname, "%s/%s", theApp.glob_prefs -> GetTempDir(), partmetfilename.GetData());
262
    char *buffer = nstrdup(partmetfilename);
475
    char * buffer = nstrdup(partmetfilename.GetData());
263
    buffer[strlen(buffer) - 4] = 0;
476
    buffer[strlen(buffer) - 4] = 0;
264
    CTag *partnametag = new CTag(FT_PARTFILENAME, buffer);
477
    CTag * partnametag = new CTag(FT_PARTFILENAME, buffer);
265
    delete[] buffer;
478
    delete[] buffer;
266
    taglist.Add(partnametag);
479
    taglist.Add(partnametag);
267
    Gap_Struct *gap = new Gap_Struct;
480
    Gap_Struct * gap = new Gap_Struct;
268
    gap -> start = 0;
481
    gap -> start = 0;
269
    gap -> end = m_nFileSize - 1;
482
    gap -> end = m_nFileSize - 1;
270
    gaplist.AddTail(gap);
483
    gaplist.AddTail(gap);
271
    char *partfull = nstrdup(fullname);
484
    char * partfull = nstrdup(fullname);
272
    partfull[strlen(partfull) - 4] = 0;
485
    partfull[strlen(partfull) - 4] = 0;
273
    printf("partfull=%s\n", partfull);
486
    if (m_hpartfile.Create(partfull, TRUE))
274
    if (!m_hpartfile.Create(partfull, TRUE))
275
    {
487
    {
276
        theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_CREATEPARTFILE));
488
        Close();
277
        SetPartFileStatus(PS_ERROR);
489
        if (m_hpartfile.Open(partfull, CFile::read_write))
490
        {
491
            if (newprefs01_opt[5])
492
            {
493
                m_nHeaderLength = (m_nFileSize/ bsize + 1) * 8;
494
                m_isDynamic |= 3;
495
                unsigned char * pfdyn_header;
496
                pfdyn_header = (unsigned char *) malloc(m_nHeaderLength);
497
                for (int i = 0 ; i < m_nHeaderLength ; i++)
498
                {
499
                    pfdyn_header[i] = 0;
278
    }
500
    }
279
    // jesh.. luotu. nyt se vaan pitää avata uudestaan read-writeen..
501
                m_hpartfile.Write(pfdyn_header, m_nHeaderLength);
280
    m_hpartfile.Close();
502
                free(pfdyn_header);
281
    if (!m_hpartfile.Open(partfull, CFile:: read_write))
503
            }
504
            else
282
    {
505
    {
283
        theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_CREATEPARTFILE));
506
                m_nHeaderLength = 0;
284
        SetPartFileStatus(PS_ERROR);
507
                m_isDynamic = 0;
285
    }
508
    }
286
    delete[] partfull;
509
    delete[] partfull;
287
    m_SrcpartFrequency.SetSize(GetPartCount());
510
    m_SrcpartFrequency.SetSize(GetPartCount());
Lines 291-350 Link Here
291
    }
514
    }
292
    paused = false;
515
    paused = false;
293
    SavePartFile(true);
516
    SavePartFile(true);
517
        }
518
        else
519
        {
520
            theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_CREATEPARTFILE));
521
            SetPartFileStatus(PS_ERROR);
522
        }
523
    }
524
    else
525
    {
526
        theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_CREATEPARTFILE));
527
        SetPartFileStatus(PS_ERROR);
528
    }
294
}
529
}
295
530
296
bool CPartFile:: LoadPartFile(char *in_directory, char *in_filename)
531
bool CPartFile::LoadPartFile(int type, char * in_directory, char * in_filename)
297
{
532
{
298
    // Slugfiller:
533
    // Slugfiller:
299
    CMap < uint16, uint16, Gap_Struct *, Gap_Struct *> gap_map;
534
    if (type)
535
    {
536
        m_isDynamic |= 1;
537
        m_nHeaderLength = (m_nFileSize/ bsize + 1) * 8;
538
    }
539
    else
540
    {
541
        m_isDynamic = 0;
542
        m_nHeaderLength = 0;
543
    }
544
    CMap <uint16, uint16, Gap_Struct *, Gap_Struct *> gap_map;
300
    transfered = 0;
545
    transfered = 0;
301
    partmetfilename = nstrdup(in_filename);
546
    partmetfilename = wxString(nstrdup(in_filename));
302
    directory = nstrdup(in_directory);
547
    directory = nstrdup(in_directory);
303
    char *buffer = new char[strlen(directory) + strlen(partmetfilename) + 2];
548
    char * buffer = new char[strlen(directory) + partmetfilename.Len() + 2];
304
    sprintf(buffer, "%s/%s", directory, partmetfilename);
549
    sprintf(buffer, "%s/%s", directory, partmetfilename.GetData());
305
    fullname = buffer;
550
    fullname = buffer;
306
    CSafeFile file;
551
    CFile metFile;
307
    {
552
    if (metFile.Open(fullname, CFile::read))
308
        // readfile data form part.met file
309
        if (!file.Open(fullname, CFile:: read))
310
        {
553
        {
311
            theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_OPENMET), partmetfilename, m_pszFileName);
554
        uint32 tagcount = 0;
312
            return false;
313
        }
314
        uint8 version = 0;
555
        uint8 version = 0;
315
        file.Read( &version, 1);
556
        metFile.Read( & version, 1);
316
        if (version != PARTFILE_VERSION)
557
        switch (version)
317
        {
558
        {
318
            file.Close();
559
        case PARTFILE_SPLITTEDVERSION:
319
            theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_BADMETVERSION), partmetfilename, m_pszFileName);
560
        case PARTFILE_VERSION:
320
            return false;
561
            isnewstyle = (version == PARTFILE_SPLITTEDVERSION);
562
            partmettype = isnewstyle? PMT_SPLITTED: PMT_DEFAULTOLD;
563
            if (!isnewstyle)
564
            {
565
printf("partfile_OLDstyle  type=%u  ",partmettype);
566
                uint8 test[4];
567
                metFile.Seek(24, wxFromStart);
568
                metFile.Read( & test[0], 1);
569
                metFile.Read( & test[1], 1);
570
                metFile.Read( & test[2], 1);
571
                metFile.Read( & test[3], 1);
572
                metFile.Seek(1, wxFromStart);
573
                if (test[0] == 0 && test[1] == 0 && test[2] == 2 && test[3] == 1)
574
                {
575
                    isnewstyle = true;
576
                    partmettype = PMT_NEWOLD;
321
        }
577
        }
322
        LoadDateFromFile( &file);
578
                LoadDateFromFile( & metFile);
323
        LoadHashsetFromFile( &file, false);
579
                LoadHashsetFromFile( & metFile, false);
324
 /* We need to forge some values here for later error
580
            }
325
 * detection to work.
581
            else
326
    */
327
        uint32 tagcount = 0;
328
        uint32 j = 0;
329
        try
330
        {
582
        {
331
            if (4 != file.Read( &tagcount, 4))
583
printf("partfile_NEWstyle  type=%u  ",partmettype);
584
                uint32 temp;
585
                metFile.Read( & temp, 4);
586
                if (temp == 0)
332
            {
587
            {
333
                tagcount = 0;
588
                    LoadHashsetFromFile(&metFile, false);
334
                throw CInvalidPacket("short file reading tagcount");
335
            }
589
            }
336
            for (j = 0 ; j < tagcount ; j++)
590
                else
337
            {
591
            {
338
                try
592
                    uchar gethash[16];
593
                    metFile.Seek(2, wxFromStart);
594
                    LoadDateFromFile( & metFile);
595
                    metFile.Read( & gethash, 16);
596
                    md4cpy(m_abyFileHash, gethash);
597
                }
598
            }
599
            if (4 == metFile.Read( & tagcount, 4))
600
                {
601
                uint32 j = 0;
602
                for (j = 0 ; j < tagcount ; j++)
339
                {
603
                {
340
                    CTag *newtag = new CTag( &file);
604
                    CTag * newtag = new CTag( & metFile);
341
                    switch (newtag -> tag -> specialtag)
605
                    switch (newtag -> tag -> specialtag)
342
                    {
606
                    {
343
                    case FT_FILENAME:
607
                    case FT_FILENAME:
344
                        {
608
                        {
345
                            if (newtag -> tag -> stringvalue == NULL)
609
                            if (newtag -> tag -> stringvalue == NULL)
346
                            {
610
                            {
347
                                theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_METCORRUPT), partmetfilename, m_pszFileName);
611
                                theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_METCORRUPT), partmetfilename.GetData(), m_pszFileName);
348
                                delete newtag;
612
                                delete newtag;
349
                                return false;
613
                                return false;
350
                            }
614
                            }
Lines 376-381 Link Here
376
                            delete newtag;
640
                            delete newtag;
377
                            break;
641
                            break;
378
                        }
642
                        }
643
                    case FT_DYNAMIC:
644
                        {
645
                            m_isDynamic = newtag -> tag -> intvalue;
646
                            delete newtag;
647
                            break;
648
                        }
379
                    case FT_OLDDLPRIORITY:
649
                    case FT_OLDDLPRIORITY:
380
                    case FT_DLPRIORITY:
650
                    case FT_DLPRIORITY:
381
                        {
651
                        {
Lines 418-425 Link Here
418
                            (newtag -> tag -> tagname[0] == FT_GAPSTART ||
688
                            (newtag -> tag -> tagname[0] == FT_GAPSTART ||
419
                            newtag -> tag -> tagname[0] == FT_GAPEND))
689
                            newtag -> tag -> tagname[0] == FT_GAPEND))
420
                            {
690
                            {
421
                                Gap_Struct *gap;
691
                                Gap_Struct * gap;
422
                                uint16 gapkey = atoi( &newtag -> tag -> tagname[1]);
692
                                uint16 gapkey = atoi( & newtag -> tag -> tagname[1]);
423
                                if (!gap_map.Lookup(gapkey, gap))
693
                                if (!gap_map.Lookup(gapkey, gap))
424
                                {
694
                                {
425
                                    gap = new Gap_Struct;
695
                                    gap = new Gap_Struct;
Lines 428-496 Link Here
428
                                    gap -> end = (uint32) - 1;
698
                                    gap -> end = (uint32) - 1;
429
                                }
699
                                }
430
                                if (newtag -> tag -> tagname[0] == FT_GAPSTART)
700
                                if (newtag -> tag -> tagname[0] == FT_GAPSTART)
701
                                {
431
                                gap -> start = newtag -> tag -> intvalue;
702
                                gap -> start = newtag -> tag -> intvalue;
703
                                }
432
                                if (newtag -> tag -> tagname[0] == FT_GAPEND)
704
                                if (newtag -> tag -> tagname[0] == FT_GAPEND)
705
                                {
433
                                gap -> end = newtag -> tag -> intvalue - 1;
706
                                gap -> end = newtag -> tag -> intvalue - 1;
707
                                }
434
                                delete newtag;
708
                                delete newtag;
435
                                // End Changes by Slugfiller for better exception handling
709
                                // End Changes by Slugfiller for better exception handling
436
                            }
710
                            }
437
                            else
711
                            else
438
                            taglist.Add(newtag);
439
                        }
440
                    }
441
                }
442
                catch(CStrangePacket)
443
                {
712
                {
713
                                taglist.Add(newtag);
444
                }
714
                }
445
            }
715
            }
446
        }
716
        }
447
        catch(CInvalidPacket e)
448
        {
449
 /*
450
 * When failing on the last tag, this might be
451
 * due to a failure in xMule writing the file.
452
    */
453
            if (!tagcount || (j != tagcount - 1))
454
            {
455
                printf("failure reading part file - %s\n", e.what());
456
                file.Close();
457
                return false;
458
            }
459
        }
460
        file.Close();
461
    }
717
    }
462
    // Now to flush the map into the list (Slugfiller)
718
    // Now to flush the map into the list (Slugfiller)
463
    for (POSITION pos = gap_map.GetStartPosition() ; pos != NULL ;)
719
    for (POSITION pos = gap_map.GetStartPosition() ; pos != NULL ;)
464
    {
720
    {
465
        Gap_Struct *gap;
721
                    Gap_Struct * gap;
466
        uint16 gapkey;
722
        uint16 gapkey;
467
        gap_map.GetNextAssoc(pos, gapkey, gap);
723
        gap_map.GetNextAssoc(pos, gapkey, gap);
468
        if (gap -> start >= 0 &&gap -> end >= 0 &&gap -> start <= gap -> end)
724
                    if (gap -> start >= 0 && gap -> end >= 0 && gap -> start <= gap -> end)
725
                    {
469
        // All tags accounted for:
726
        // All tags accounted for:
470
        gaplist.AddTail(gap);
727
        gaplist.AddTail(gap);
728
                    }
471
        else
729
        else
730
                    {
472
        // Some of the tags were missing:
731
        // Some of the tags were missing:
473
        delete gap;
732
        delete gap;
474
    }
733
    }
734
                }
475
    //check if this is a backup
735
    //check if this is a backup
476
    if (strcasecmp(strrchr(fullname, '.'), ".backup") == 0)
736
    if (strcasecmp(strrchr(fullname, '.'), ".backup") == 0)
477
    {
737
    {
478
        char *shorten = strrchr(fullname, '.');
738
                    char * shorten = strrchr(fullname, '.');
479
        *shorten = 0;
739
                    * shorten = 0;
480
        char *oldfullname = fullname;
740
                    char * oldfullname = fullname;
481
        fullname = new char[strlen(fullname) + 1];
741
        fullname = new char[strlen(fullname) + 1];
482
        strcpy(fullname, oldfullname);
742
        strcpy(fullname, oldfullname);
483
        delete[] oldfullname;
743
        delete[] oldfullname;
484
    }
744
    }
485
    // open permanent handle
745
    // open permanent handle
486
    char *searchpath = nstrdup(fullname);
746
                char * searchpath = nstrdup(fullname);
487
    searchpath[strlen(fullname) - 4] = 0;
747
    searchpath[strlen(fullname) - 4] = 0;
488
    if (!m_hpartfile.Open(searchpath, CFile:: read_write))
748
                if (m_hpartfile.Open(searchpath, CFile::read_write))
489
    {
749
    {
490
        theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_FILEOPEN), fullname, m_pszFileName);
750
                    Seek(0);
491
        delete[] searchpath;
492
        return false;
493
    }
494
    delete[] searchpath;
751
    delete[] searchpath;
495
    searchpath = NULL;
752
    searchpath = NULL;
496
    m_SrcpartFrequency.SetSize(GetPartCount());
753
    m_SrcpartFrequency.SetSize(GetPartCount());
Lines 509-515 Link Here
509
        hashsetneeded = false;
766
        hashsetneeded = false;
510
        for (int i = 0 ; i != hashlist.GetSize() ; i++)
767
        for (int i = 0 ; i != hashlist.GetSize() ; i++)
511
        {
768
        {
512
            if (IsComplete(i *PARTSIZE, ((i + 1) *PARTSIZE) - 1))
769
                            if (IsComplete(i * PARTSIZE, ((i + 1) * PARTSIZE) - 1))
513
            {
770
            {
514
                SetPartFileStatus(PS_READY);
771
                SetPartFileStatus(PS_READY);
515
            }
772
            }
Lines 521-547 Link Here
521
        return true;
778
        return true;
522
    }
779
    }
523
    struct stat statbuf;
780
    struct stat statbuf;
524
    fstat(m_hpartfile.fd(), &statbuf);
781
                    fstat(m_hpartfile.fd(), & statbuf);
525
    if ((time_t) date != (time_t) statbuf.st_mtime)
782
    if ((time_t) date != (time_t) statbuf.st_mtime)
526
    {
783
    {
527
        theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_REHASH), buffer, m_pszFileName);
784
        theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_REHASH), buffer, m_pszFileName);
528
        // rehash
785
        // rehash
529
        SetPartFileStatus(PS_WAITINGFORHASH);
786
        SetPartFileStatus(PS_WAITINGFORHASH);
530
        char *partfilename = nstrdup(partmetfilename);
787
                        char * partfilename = nstrdup(partmetfilename.GetData());
531
        partfilename[strlen(partfilename) - 4] = 0;
788
        partfilename[strlen(partfilename) - 4] = 0;
532
        CAddFileThread:: AddFile(directory, partfilename, this);
789
                        CAddFileThread::AddFile(directory, partfilename, this);
533
        delete[] partfilename;
790
        delete[] partfilename;
534
    }
791
    }
535
    UpdateCompletedInfos();
792
    UpdateCompletedInfos();
536
    if (completedsize > transfered)
793
    if (completedsize > transfered)
794
                    {
537
    m_iGainDueToCompression = completedsize - transfered;
795
    m_iGainDueToCompression = completedsize - transfered;
796
                    }
538
    else if(completedsize != transfered)
797
    else if(completedsize != transfered)
798
                    {
539
    m_iLostDueToCorruption = transfered - completedsize;
799
    m_iLostDueToCorruption = transfered - completedsize;
800
                    }
540
    return true;
801
    return true;
541
    return true;
802
                }
803
                else
804
                {
805
                    theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_FILEOPEN), fullname, m_pszFileName);
806
                    delete[] searchpath;
807
                }
808
            }
809
            else
810
            {
811
                tagcount = 0;
812
            }
813
            break;
814
        default:
815
            {
816
                theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_BADMETVERSION),
817
                partmetfilename.GetData(), m_pszFileName);
818
            }
819
            break;
820
        }
821
        metFile.Close();
822
    }
823
    else
824
    {
825
        theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_OPENMET), partmetfilename.GetData(),
826
        m_pszFileName);
827
    }
828
    return false;
542
}
829
}
543
830
544
bool CPartFile:: SavePartFile(bool Initial)
831
bool CPartFile::SavePartFile(bool Initial)
545
{
832
{
546
    switch (status)
833
    switch (status)
547
    {
834
    {
Lines 551-576 Link Here
551
    }
838
    }
552
    /* Don't write anything to disk if less than 5000 bytes of free space is left. */
839
    /* Don't write anything to disk if less than 5000 bytes of free space is left. */
553
    wxLongLong total, free;
840
    wxLongLong total, free;
554
    if (wxGetDiskSpace(theApp.glob_prefs -> GetTempDir(), &total, &free) &&
841
    if (wxGetDiskSpace(theApp.glob_prefs -> GetTempDir(), & total, & free) &&
555
    free < 5000)
842
    free < 5000)
556
    {
843
    {
557
        return false;
844
        return false;
558
    }
845
    }
559
    FILE *file = 0;
846
    FILE * file = 0;
560
    char *searchpath = nstrdup(fullname);
847
    char * searchpath = nstrdup(fullname);
561
    searchpath[strlen(fullname) - 4] = 0;
848
    searchpath[strlen(fullname) - 4] = 0;
562
    wxString fName =:: wxFindFirstFile(searchpath, wxFILE);
849
    wxString fName =::wxFindFirstFile(searchpath, wxFILE);
563
    delete[] searchpath;
850
    delete[] searchpath;
564
    searchpath = NULL;
851
    searchpath = NULL;
565
    if (fName.IsEmpty())
852
    if (fName.IsEmpty())
566
    {
853
    {
567
        if (file)
854
        if (file)
568
        fclose(file);
855
        fclose(file);
569
        theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_SAVEMET), GetResString(IDS_ERR_PART_FNF) .GetData(), partmetfilename, m_pszFileName);
856
        theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_SAVEMET),
857
        GetResString(IDS_ERR_PART_FNF) .GetData(), partmetfilename.GetData(), m_pszFileName);
570
        return false;
858
        return false;
571
    }
859
    }
572
    struct stat sbf;
860
    struct stat sbf;
573
    stat(fName.GetData(), &sbf);
861
    stat(fName.GetData(), & sbf);
574
    date = sbf.st_mtime;
862
    date = sbf.st_mtime;
575
    uint32 lsc = lastseencomplete;
863
    uint32 lsc = lastseencomplete;
576
    if (!Initial)
864
    if (!Initial)
Lines 583-602 Link Here
583
        throw GetResString(IDS_ERR_OPENMETFILE);
871
        throw GetResString(IDS_ERR_OPENMETFILE);
584
    }
872
    }
585
    uint8 version = PARTFILE_VERSION;
873
    uint8 version = PARTFILE_VERSION;
586
    fwrite( &version, 1, 1, file);
874
    fwrite( & version, 1, 1, file);
587
    fwrite( &date, 4, 1, file);
875
    fwrite( & date, 4, 1, file);
588
    fwrite( &m_abyFileHash, 16, 1, file);
876
    fwrite( & m_abyFileHash, 16, 1, file);
589
    uint16 parts = hashlist.GetCount();
877
    uint16 parts = hashlist.GetCount();
590
    fwrite( &parts, 2, 1, file);
878
    fwrite( & parts, 2, 1, file);
591
    for (int x = 0 ; x != parts ; x++)
879
    for (int x = 0 ; x != parts ; x++)
592
    fwrite(hashlist[x], 16, 1, file);
880
    fwrite(hashlist[x], 16, 1, file);
593
    uint32 tagcount = taglist.GetCount() + 10 + (gaplist.GetCount() *2);
881
    uint32 tagcount = taglist.GetCount() + 10 + (gaplist.GetCount() * 2);
594
    fwrite( &tagcount, 4, 1, file);
882
    fwrite( & tagcount, 4, 1, file);
595
    CTag(FT_FILENAME, m_pszFileName) .WriteTagToFile(file);
883
    CTag(FT_FILENAME, m_pszFileName) .WriteTagToFile(file);
596
    CTag(FT_FILESIZE, m_nFileSize) .WriteTagToFile(file);
884
    CTag(FT_FILESIZE, m_nFileSize) .WriteTagToFile(file);
597
    CTag(FT_TRANSFERED, transfered) .WriteTagToFile(file);
885
    CTag(FT_TRANSFERED, transfered) .WriteTagToFile(file);
598
    CTag(FT_STATUS, (paused) ? 1: 0) .WriteTagToFile(file);
886
    CTag(FT_STATUS, (paused) ? 1: 0) .WriteTagToFile(file);
599
    CTag *prioritytag;
887
    CTag * prioritytag;
600
    uint8 autoprio = PR_AUTO;
888
    uint8 autoprio = PR_AUTO;
601
    if (this -> IsAutoDownPriority())
889
    if (this -> IsAutoDownPriority())
602
    {
890
    {
Lines 618-627 Link Here
618
    }
906
    }
619
    prioritytag -> WriteTagToFile(file);
907
    prioritytag -> WriteTagToFile(file);
620
    delete prioritytag;
908
    delete prioritytag;
621
    CTag *lsctag = new CTag(FT_LASTSEENCOMPLETE, lsc);
909
    CTag * lsctag = new CTag(FT_LASTSEENCOMPLETE, lsc);
622
    lsctag -> WriteTagToFile(file);
910
    lsctag -> WriteTagToFile(file);
623
    delete lsctag;
911
    delete lsctag;
624
    CTag *ulprioritytag;
912
    CTag * ulprioritytag;
625
    if (this -> IsAutoUpPriority())
913
    if (this -> IsAutoUpPriority())
626
    {
914
    {
627
        ulprioritytag = new CTag(FT_ULPRIORITY, autoprio);
915
        ulprioritytag = new CTag(FT_ULPRIORITY, autoprio);
Lines 642-673 Link Here
642
    }
930
    }
643
    ulprioritytag -> WriteTagToFile(file);
931
    ulprioritytag -> WriteTagToFile(file);
644
    delete ulprioritytag;
932
    delete ulprioritytag;
645
    CTag *categorytab = new CTag(FT_CATEGORY, m_category);
933
    CTag * categorytab = new CTag(FT_CATEGORY, m_category);
646
    categorytab -> WriteTagToFile(file);
934
    categorytab -> WriteTagToFile(file);
647
    delete categorytab;
935
    delete categorytab;
648
    for (uint32 j = 0 ; j != (uint32) taglist.GetCount() ; j++)
936
    for (uint32 j = 0 ; j != (uint32) taglist.GetCount() ; j++)
649
    taglist[j] -> WriteTagToFile(file);
937
    taglist[j] -> WriteTagToFile(file);
650
    char *namebuffer = new char[10];
938
    char * namebuffer = new char[10];
651
    char *number = &namebuffer[1];
939
    char * number = & namebuffer[1];
652
    uint16 i_pos = 0;
940
    uint16 i_pos = 0;
653
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
941
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
654
    {
942
    {
655
        sprintf(number, "%d", i_pos);
943
        sprintf(number, "%d", i_pos);
656
        namebuffer[0] = FT_GAPSTART;
944
        namebuffer[0] = FT_GAPSTART;
657
        CTag *gapstarttag = new CTag(namebuffer, gaplist.GetAt(pos) -> start);
945
        CTag * gapstarttag = new CTag(namebuffer, gaplist.GetAt(pos) -> start);
658
        gapstarttag -> WriteTagToFile(file);
946
        gapstarttag -> WriteTagToFile(file);
659
        namebuffer[0] = FT_GAPEND;
947
        namebuffer[0] = FT_GAPEND;
660
        CTag *gapendtag = new CTag(namebuffer, (gaplist.GetAt(pos) -> end) + 1);
948
        CTag * gapendtag = new CTag(namebuffer, (gaplist.GetAt(pos) -> end) + 1);
661
        gapendtag -> WriteTagToFile(file);
949
        gapendtag -> WriteTagToFile(file);
662
        delete gapstarttag;
950
        delete gapstarttag;
663
        delete gapendtag;
951
        delete gapendtag;
664
        i_pos++;
952
        i_pos++;
665
    }
953
    }
666
    delete[] namebuffer;
954
    delete[] namebuffer;
667
    if (ferror(file))
668
    {
669
        throw CString("unexpected write error");
670
    }
671
    if (!Initial)
955
    if (!Initial)
672
    {
956
    {
673
        wxRemoveFile(wxString(fullname) + ".backup");
957
        wxRemoveFile(wxString(fullname) + ".backup");
Lines 677-694 Link Here
677
    return true;
961
    return true;
678
}
962
}
679
963
680
void CPartFile:: PartFileHashFinished(CKnownFile *result)
964
void CPartFile::PartFileHashFinished(CKnownFile * result)
681
{
965
{
682
    newdate = true;
966
    newdate = true;
683
    bool errorfound = false;
967
    bool errorfound = false;
684
    for (uint32 i = 0 ; i != (uint32) hashlist.GetSize() ; i++)
968
    for (uint32 i = 0 ; i != (uint32) hashlist.GetSize() ; i++)
685
    {
969
    {
686
        if (IsComplete(i *PARTSIZE, ((i + 1) *PARTSIZE) - 1))
970
        if (IsComplete(i * PARTSIZE, ((i + 1) * PARTSIZE) - 1))
687
        {
971
        {
688
            if (! (result -> GetPartHash(i) && !memcmp(result -> GetPartHash(i), this -> GetPartHash(i), 16)))
972
            if (! (result -> GetPartHash(i) && !memcmp(result -> GetPartHash(i), this -> GetPartHash(i), 16)))
689
            {
973
            {
690
                theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_FOUNDCORRUPTION), i + 1, m_pszFileName);
974
                theApp.xmuledlg -> AddLogLine(false, GetResString(IDS_ERR_FOUNDCORRUPTION), i + 1, m_pszFileName);
691
                AddGap(i *PARTSIZE, ((((i + 1) *PARTSIZE) - 1) >= m_nFileSize) ? m_nFileSize - 1: ((i + 1) *PARTSIZE) - 1);
975
                AddGap(i * PARTSIZE, ((((i + 1) * PARTSIZE) - 1) >= m_nFileSize) ? m_nFileSize - 1: ((i + 1) * PARTSIZE) - 1);
692
                errorfound = true;
976
                errorfound = true;
693
            }
977
            }
694
        }
978
        }
Lines 715-734 Link Here
715
    theApp.sharedfiles -> SafeAddKFile(this);
999
    theApp.sharedfiles -> SafeAddKFile(this);
716
}
1000
}
717
1001
718
void CPartFile:: AddGap(uint32 start, uint32 end)
1002
void CPartFile::AddGap(uint32 start, uint32 end)
719
{
1003
{
720
    POSITION pos1, pos2;
1004
    POSITION pos1, pos2;
721
    for (pos1 = gaplist.GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1005
    for (pos1 = gaplist.GetHeadPosition() ; (pos2 = pos1) != NULL ;)
722
    {
1006
    {
723
        Gap_Struct *cur_gap = gaplist.GetNext(pos1);
1007
        Gap_Struct * cur_gap = gaplist.GetNext(pos1);
724
        if (cur_gap -> start >= start &&cur_gap -> end <= end)
1008
        if (cur_gap -> start >= start && cur_gap -> end <= end)
725
        {
1009
        {
726
            // this gap is inside the new gap - delete
1010
            // this gap is inside the new gap - delete
727
            gaplist.RemoveAt(pos2);
1011
            gaplist.RemoveAt(pos2);
728
            delete cur_gap;
1012
            delete cur_gap;
729
            continue;
1013
            continue;
730
        }
1014
        }
731
        else if(cur_gap -> start >= start &&cur_gap -> start <= end)
1015
        else if(cur_gap -> start >= start && cur_gap -> start <= end)
732
        {
1016
        {
733
            // a part of this gap is in the new gap - extend limit and delete
1017
            // a part of this gap is in the new gap - extend limit and delete
734
            end = cur_gap -> end;
1018
            end = cur_gap -> end;
Lines 736-742 Link Here
736
            delete cur_gap;
1020
            delete cur_gap;
737
            continue;
1021
            continue;
738
        }
1022
        }
739
        else if(cur_gap -> end <= end &&cur_gap -> end >= start)
1023
        else if(cur_gap -> end <= end && cur_gap -> end >= start)
740
        {
1024
        {
741
            // a part of this gap is in the new gap - extend limit and delete
1025
            // a part of this gap is in the new gap - extend limit and delete
742
            start = cur_gap -> start;
1026
            start = cur_gap -> start;
Lines 744-756 Link Here
744
            delete cur_gap;
1028
            delete cur_gap;
745
            continue;
1029
            continue;
746
        }
1030
        }
747
        else if(start >= cur_gap -> start &&end <= cur_gap -> end)
1031
        else if(start >= cur_gap -> start && end <= cur_gap -> end)
748
        {
1032
        {
749
            // new gap is already inside this gap - return
1033
            // new gap is already inside this gap - return
750
            return;
1034
            return;
751
        }
1035
        }
752
    }
1036
    }
753
    Gap_Struct *new_gap = new Gap_Struct;
1037
    Gap_Struct * new_gap = new Gap_Struct;
754
    new_gap -> start = start;
1038
    new_gap -> start = start;
755
    new_gap -> end = end;
1039
    new_gap -> end = end;
756
    gaplist.AddTail(new_gap);
1040
    gaplist.AddTail(new_gap);
Lines 759-774 Link Here
759
    newdate = true;
1043
    newdate = true;
760
}
1044
}
761
1045
762
bool CPartFile:: IsComplete(uint32 start, uint32 end)
1046
bool CPartFile::IsComplete(uint32 start, uint32 end)
763
{
1047
{
764
    if (end >= m_nFileSize)
1048
    if (end >= m_nFileSize)
765
    end = m_nFileSize - 1;
1049
    end = m_nFileSize - 1;
766
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
1050
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
767
    {
1051
    {
768
        Gap_Struct *cur_gap = gaplist.GetAt(pos);
1052
        Gap_Struct * cur_gap = gaplist.GetAt(pos);
769
        if ((cur_gap -> start >= start &&cur_gap -> end <= end) || (cur_gap -> start >= start
1053
        if ((cur_gap -> start >= start && cur_gap -> end <= end) || (cur_gap -> start >= start
770
        &&cur_gap -> start <= end) || (cur_gap -> end <= end &&cur_gap -> end >= start)
1054
        && cur_gap -> start <= end) || (cur_gap -> end <= end && cur_gap -> end >= start)
771
        || (start >= cur_gap -> start &&end <= cur_gap -> end))
1055
        || (start >= cur_gap -> start && end <= cur_gap -> end))
772
        {
1056
        {
773
            return false;
1057
            return false;
774
        }
1058
        }
Lines 776-789 Link Here
776
    return true;
1060
    return true;
777
}
1061
}
778
1062
779
bool CPartFile:: IsPureGap(uint32 start, uint32 end)
1063
bool CPartFile::IsPureGap(uint32 start, uint32 end)
780
{
1064
{
781
    if (end >= m_nFileSize)
1065
    if (end >= m_nFileSize)
782
    end = m_nFileSize - 1;
1066
    end = m_nFileSize - 1;
783
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
1067
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
784
    {
1068
    {
785
        Gap_Struct *cur_gap = gaplist.GetAt(pos);
1069
        Gap_Struct * cur_gap = gaplist.GetAt(pos);
786
        if (start >= cur_gap -> start &&end <= cur_gap -> end)
1070
        if (start >= cur_gap -> start && end <= cur_gap -> end)
787
        {
1071
        {
788
            return true;
1072
            return true;
789
        }
1073
        }
Lines 791-797 Link Here
791
    return false;
1075
    return false;
792
}
1076
}
793
1077
794
bool CPartFile:: IsAlreadyRequested(uint32 start, uint32 end)
1078
bool CPartFile::IsAlreadyRequested(uint32 start, uint32 end)
795
{
1079
{
796
    for (POSITION pos = requestedblocks_list.GetHeadPosition() ; pos != 0 ; requestedblocks_list.GetNext(pos))
1080
    for (POSITION pos = requestedblocks_list.GetHeadPosition() ; pos != 0 ; requestedblocks_list.GetNext(pos))
797
    {
1081
    {
Lines 802-815 Link Here
802
    return false;
1086
    return false;
803
}
1087
}
804
1088
805
bool CPartFile:: GetNextEmptyBlockInPart(uint16 partNumber, Requested_Block_Struct *result)
1089
bool CPartFile::GetNextEmptyBlockInPart(uint16 partNumber, Requested_Block_Struct * result)
806
{
1090
{
807
    Gap_Struct *firstGap;
1091
    Gap_Struct * firstGap;
808
    Gap_Struct *currentGap;
1092
    Gap_Struct * currentGap;
809
    uint32 end;
1093
    uint32 end;
810
    uint32 blockLimit;
1094
    uint32 blockLimit;
811
    // Find start of this part
1095
    // Find start of this part
812
    uint32 partStart = (PARTSIZE *partNumber);
1096
    uint32 partStart = (PARTSIZE * partNumber);
813
    uint32 start = partStart;
1097
    uint32 start = partStart;
814
    // What is the end limit of this block, i.e. can't go outside part (or filesize)
1098
    // What is the end limit of this block, i.e. can't go outside part (or filesize)
815
    uint32 partEnd = (PARTSIZE * (partNumber + 1)) - 1;
1099
    uint32 partEnd = (PARTSIZE * (partNumber + 1)) - 1;
Lines 873-902 Link Here
873
    return false;
1157
    return false;
874
}
1158
}
875
1159
876
void CPartFile:: FillGap(uint32 start, uint32 end)
1160
void CPartFile::FillGap(uint32 start, uint32 end)
877
{
1161
{
878
    POSITION pos1, pos2;
1162
    POSITION pos1, pos2;
879
    for (pos1 = gaplist.GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1163
    for (pos1 = gaplist.GetHeadPosition() ; (pos2 = pos1) != NULL ;)
880
    {
1164
    {
881
        Gap_Struct *cur_gap = gaplist.GetNext(pos1);
1165
        Gap_Struct * cur_gap = gaplist.GetNext(pos1);
882
        if (cur_gap -> start >= start &&cur_gap -> end <= end)
1166
        if (cur_gap -> start >= start && cur_gap -> end <= end)
883
        {
1167
        {
884
            // our part fills this gap completly
1168
            // our part fills this gap completly
885
            gaplist.RemoveAt(pos2);
1169
            gaplist.RemoveAt(pos2);
886
            delete cur_gap;
1170
            delete cur_gap;
887
            continue;
1171
            continue;
888
        }
1172
        }
889
        else if(cur_gap -> start >= start &&cur_gap -> start <= end)
1173
        else if(cur_gap -> start >= start && cur_gap -> start <= end)
890
        {
1174
        {
891
            // a part of this gap is in the part - set limit
1175
            // a part of this gap is in the part - set limit
892
            cur_gap -> start = end + 1;
1176
            cur_gap -> start = end + 1;
893
        }
1177
        }
894
        else if(cur_gap -> end <= end &&cur_gap -> end >= start)
1178
        else if(cur_gap -> end <= end && cur_gap -> end >= start)
895
        {
1179
        {
896
            // a part of this gap is in the part - set limit
1180
            // a part of this gap is in the part - set limit
897
            cur_gap -> end = start - 1;
1181
            cur_gap -> end = start - 1;
898
        }
1182
        }
899
        else if(start >= cur_gap -> start &&end <= cur_gap -> end)
1183
        else if(start >= cur_gap -> start && end <= cur_gap -> end)
900
        {
1184
        {
901
            uint32 buffer = cur_gap -> end;
1185
            uint32 buffer = cur_gap -> end;
902
            cur_gap -> end = start - 1;
1186
            cur_gap -> end = start - 1;
Lines 915-927 Link Here
915
    //SavePartFile();
1199
    //SavePartFile();
916
}
1200
}
917
1201
918
void CPartFile:: UpdateCompletedInfos()
1202
void CPartFile::UpdateCompletedInfos()
919
{
1203
{
920
    uint32 allgaps = 0;
1204
    uint32 allgaps = 0;
921
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ;)
1205
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ;)
922
    {
1206
    {
923
        POSITION prev = pos;
1207
        POSITION prev = pos;
924
        Gap_Struct *cur_gap = gaplist.GetNext(pos);
1208
        Gap_Struct * cur_gap = gaplist.GetNext(pos);
925
        if ((cur_gap -> end > m_nFileSize) || (cur_gap -> start >= m_nFileSize))
1209
        if ((cur_gap -> end > m_nFileSize) || (cur_gap -> start >= m_nFileSize))
926
        gaplist.RemoveAt(prev);
1210
        gaplist.RemoveAt(prev);
927
        else
1211
        else
Lines 929-935 Link Here
929
    }
1213
    }
930
    if (gaplist.GetCount() || requestedblocks_list.GetCount())
1214
    if (gaplist.GetCount() || requestedblocks_list.GetCount())
931
    {
1215
    {
932
        percentcompleted = (1.0f - (float) allgaps/m_nFileSize) *100;
1216
        percentcompleted = (1.0f - (float) allgaps/ m_nFileSize) * 100;
933
        completedsize = m_nFileSize - allgaps - 1;
1217
        completedsize = m_nFileSize - allgaps - 1;
934
    }
1218
    }
935
    else
1219
    else
Lines 941-948 Link Here
941
1225
942
#include <wx/gdicmn.h>
1226
#include <wx/gdicmn.h>
943
typedef DWORD COLORREF;
1227
typedef DWORD COLORREF;
944
1228
void CPartFile::DrawStatusBar(wxMemoryDC * dc, wxRect rect, bool bFlat)
945
void CPartFile:: DrawStatusBar(wxMemoryDC *dc, wxRect rect, bool bFlat)
946
{
1229
{
947
    COLORREF crProgress;
1230
    COLORREF crProgress;
948
    COLORREF crHave;
1231
    COLORREF crHave;
Lines 976-1002 Link Here
976
    // red gaps
1259
    // red gaps
977
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
1260
    for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
978
    {
1261
    {
979
        Gap_Struct *cur_gap = gaplist.GetAt(pos);
1262
        Gap_Struct * cur_gap = gaplist.GetAt(pos);
980
        allgaps += cur_gap -> end - cur_gap -> start;
1263
        allgaps += cur_gap -> end - cur_gap -> start;
981
        bool gapdone = false;
1264
        bool gapdone = false;
982
        uint32 gapstart = cur_gap -> start;
1265
        uint32 gapstart = cur_gap -> start;
983
        uint32 gapend = cur_gap -> end;
1266
        uint32 gapend = cur_gap -> end;
984
        for (uint32 i = 0 ; i != GetPartCount() ; i++)
1267
        for (uint32 i = 0 ; i != GetPartCount() ; i++)
985
        {
1268
        {
986
            if (gapstart >= i *PARTSIZE &&gapstart <= (i + 1) *PARTSIZE)
1269
            if (gapstart >= i * PARTSIZE && gapstart <= (i + 1) * PARTSIZE)
987
            {
1270
            {
988
                // is in this part?
1271
                // is in this part?
989
                if (gapend <= (i + 1) *PARTSIZE)
1272
                if (gapend <= (i + 1) * PARTSIZE)
990
                gapdone = true;
1273
                gapdone = true;
991
                else
1274
                else
992
                {
1275
                {
993
                    // and next part:
1276
                    // and next part:
994
                    gapend = (i + 1) *PARTSIZE;
1277
                    gapend = (i + 1) * PARTSIZE;
995
                }
1278
                }
996
                // paint
1279
                // paint
997
                COLORREF color;
1280
                COLORREF color;
998
                // frequency?:
1281
                // frequency?:
999
                if (m_SrcpartFrequency.GetCount() >= (int) i &&m_SrcpartFrequency[i])
1282
                if (m_SrcpartFrequency.GetCount() >= (int) i && m_SrcpartFrequency[i])
1000
                color = RGB(0,
1283
                color = RGB(0,
1001
                (210 - (22 * (m_SrcpartFrequency[i] - 1)) < 0) ? 0: 210 - (22 * (m_SrcpartFrequency[i] - 1))
1284
                (210 - (22 * (m_SrcpartFrequency[i] - 1)) < 0) ? 0: 210 - (22 * (m_SrcpartFrequency[i] - 1))
1002
                , 255);
1285
                , 255);
Lines 1017-1023 Link Here
1017
    // yellow pending parts
1300
    // yellow pending parts
1018
    for (POSITION pos = requestedblocks_list.GetHeadPosition() ; pos != 0 ; requestedblocks_list.GetNext(pos))
1301
    for (POSITION pos = requestedblocks_list.GetHeadPosition() ; pos != 0 ; requestedblocks_list.GetNext(pos))
1019
    {
1302
    {
1020
        Requested_Block_Struct *block = requestedblocks_list.GetAt(pos);
1303
        Requested_Block_Struct * block = requestedblocks_list.GetAt(pos);
1021
        s_ChunkBar.FillRange(block -> StartOffset, block -> EndOffset, crPending);
1304
        s_ChunkBar.FillRange(block -> StartOffset, block -> EndOffset, crPending);
1022
    }
1305
    }
1023
    s_ChunkBar.Draw(dc, rect.x, rect.y, bFlat);
1306
    s_ChunkBar.Draw(dc, rect.x, rect.y, bFlat);
Lines 1030-1042 Link Here
1030
    gaprect.left = rect.x;
1313
    gaprect.left = rect.x;
1031
    if (!bFlat)
1314
    if (!bFlat)
1032
    {
1315
    {
1033
        s_LoadBar.SetWidth((uint32)((float)((float)((m_nFileSize - ((allgaps == 0) ?1: allgaps)) - 1)) *blockpixel + .5f));
1316
        s_LoadBar.SetWidth((uint32)((float)((float)((m_nFileSize - ((allgaps == 0) ? 1: allgaps)) - 1)) * blockpixel + .5f));
1034
        s_LoadBar.Fill(crProgress);
1317
        s_LoadBar.Fill(crProgress);
1035
        s_LoadBar.Draw(dc, gaprect.left, gaprect.top, false);
1318
        s_LoadBar.Draw(dc, gaprect.left, gaprect.top, false);
1036
    }
1319
    }
1037
    else
1320
    else
1038
    {
1321
    {
1039
        gaprect.right = rect.x + (uint32)((float)((float)((m_nFileSize - ((allgaps == 0) ?1: allgaps)) - 1)) *blockpixel + .5f);
1322
        gaprect.right = rect.x + (uint32)((float)((float)((m_nFileSize - ((allgaps == 0) ? 1: allgaps)) - 1)) * blockpixel + .5f);
1040
        //wxBrush(crProgress));:
1323
        //wxBrush(crProgress));:
1041
        dc -> SetBrush( * (wxTheBrushList -> FindOrCreateBrush(wxColour(crProgress), wxSOLID)));
1324
        dc -> SetBrush( * (wxTheBrushList -> FindOrCreateBrush(wxColour(crProgress), wxSOLID)));
1042
        dc -> DrawRectangle(gaprect.left, gaprect.top, gaprect.right, gaprect.bottom);
1325
        dc -> DrawRectangle(gaprect.left, gaprect.top, gaprect.right, gaprect.bottom);
Lines 1051-1057 Link Here
1051
    }
1334
    }
1052
    if ((gaplist.GetCount() || requestedblocks_list.GetCount()))
1335
    if ((gaplist.GetCount() || requestedblocks_list.GetCount()))
1053
    {
1336
    {
1054
        percentcompleted = ((1.0f - (float) allgaps/m_nFileSize)) *100;
1337
        percentcompleted = ((1.0f - (float) allgaps/ m_nFileSize)) * 100;
1055
        completedsize = m_nFileSize - allgaps - 1;
1338
        completedsize = m_nFileSize - allgaps - 1;
1056
    }
1339
    }
1057
    else
1340
    else
Lines 1061-1087 Link Here
1061
    }
1344
    }
1062
}
1345
}
1063
1346
1064
void CPartFile:: WritePartStatus(CMemFile *file)
1347
void CPartFile::WritePartStatus(CMemFile * file)
1065
{
1348
{
1066
    uint16 parts = hashlist.GetCount();
1349
    uint16 parts = hashlist.GetCount();
1067
    file -> Write( &parts, 2);
1350
    file -> Write( & parts, 2);
1068
    uint16 done = 0;
1351
    uint16 done = 0;
1069
    while (done != parts)
1352
    while (done != parts)
1070
    {
1353
    {
1071
        uint8 towrite = 0;
1354
        uint8 towrite = 0;
1072
        for (uint32 i = 0 ; i != 8 ; i++)
1355
        for (uint32 i = 0 ; i != 8 ; i++)
1073
        {
1356
        {
1074
            if (IsComplete(done *PARTSIZE, ((done + 1) *PARTSIZE) - 1))
1357
            if (IsComplete(done * PARTSIZE, ((done + 1) * PARTSIZE) - 1))
1075
            towrite |= (1 << i);
1358
            towrite |= (1 << i);
1076
            done++;
1359
            done++;
1077
            if (done == parts)
1360
            if (done == parts)
1078
            break;
1361
            break;
1079
        }
1362
        }
1080
        file -> Write( &towrite, 1);
1363
        file -> Write( & towrite, 1);
1081
    }
1364
    }
1082
}
1365
}
1083
1366
1084
int CPartFile:: GetValidSourcesCount()
1367
int CPartFile::GetValidSourcesCount()
1085
{
1368
{
1086
    int counter = 0;
1369
    int counter = 0;
1087
    POSITION pos1, pos2;
1370
    POSITION pos1, pos2;
Lines 1089-1102 Link Here
1089
    for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1372
    for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1090
    {
1373
    {
1091
        srclists[sl].GetNext(pos1);
1374
        srclists[sl].GetNext(pos1);
1092
        CUpDownClient *cur_src = srclists[sl].GetAt(pos2);
1375
        CUpDownClient * cur_src = srclists[sl].GetAt(pos2);
1093
        if (cur_src -> GetDownloadState() != DS_ONQUEUE &&cur_src -> GetDownloadState() != DS_DOWNLOADING &&
1376
        if (cur_src -> GetDownloadState() != DS_ONQUEUE && cur_src -> GetDownloadState() != DS_DOWNLOADING &&
1094
        cur_src -> GetDownloadState() != DS_NONEEDEDPARTS) counter++;
1377
        cur_src -> GetDownloadState() != DS_NONEEDEDPARTS) counter++;
1095
    }
1378
    }
1096
    return counter;
1379
    return counter;
1097
}
1380
}
1098
1381
1099
uint16 CPartFile:: GetNotCurrentSourcesCount()
1382
uint16 CPartFile::GetNotCurrentSourcesCount()
1100
{
1383
{
1101
    uint16 counter = 0;
1384
    uint16 counter = 0;
1102
    POSITION pos1, pos2;
1385
    POSITION pos1, pos2;
Lines 1104-1116 Link Here
1104
    for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1387
    for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1105
    {
1388
    {
1106
        srclists[sl].GetNext(pos1);
1389
        srclists[sl].GetNext(pos1);
1107
        CUpDownClient *cur_src = srclists[sl].GetAt(pos2);
1390
        CUpDownClient * cur_src = srclists[sl].GetAt(pos2);
1108
        if (cur_src -> GetDownloadState() != DS_ONQUEUE &&cur_src -> GetDownloadState() != DS_DOWNLOADING) counter++;
1391
        if (cur_src -> GetDownloadState() != DS_ONQUEUE && cur_src -> GetDownloadState() != DS_DOWNLOADING) counter++;
1109
    }
1392
    }
1110
    return counter;
1393
    return counter;
1111
}
1394
}
1112
1395
1113
uint8 CPartFile:: GetStatus(bool ignorepause)
1396
uint8 CPartFile::GetStatus(bool ignorepause)
1114
{
1397
{
1115
    if ((!paused) || status == PS_ERROR || ignorepause)
1398
    if ((!paused) || status == PS_ERROR || ignorepause)
1116
    return status;
1399
    return status;
Lines 1118-1128 Link Here
1118
    return PS_PAUSED;
1401
    return PS_PAUSED;
1119
}
1402
}
1120
1403
1121
uint32 CPartFile:: Process(uint32 reducedownload)
1404
uint32 CPartFile::Process(uint32 reducedownload)
1122
{
1405
{
1123
    //in percent
1406
    //in percent
1124
    uint16 old_trans;
1407
    uint16 old_trans;
1125
    DWORD dwCurTick =:: GetTickCount();
1408
    DWORD dwCurTick =::GetTickCount();
1126
    // If buffer size exceeds limit, or if not written within time limit, flush data
1409
    // If buffer size exceeds limit, or if not written within time limit, flush data
1127
    if ((m_nTotalBufferData > theApp.glob_prefs -> GetFileBufferSize()))
1410
    if ((m_nTotalBufferData > theApp.glob_prefs -> GetFileBufferSize()))
1128
    {
1411
    {
Lines 1135-1146 Link Here
1135
    // check if we want new sources from server
1418
    // check if we want new sources from server
1136
    //uint16 test = theApp.glob_prefs->GetMaxSourcePerFileSoft();
1419
    //uint16 test = theApp.glob_prefs->GetMaxSourcePerFileSoft();
1137
    if (((!lastsearchtime) || (dwCurTick - lastsearchtime) > SERVERREASKTIME)
1420
    if (((!lastsearchtime) || (dwCurTick - lastsearchtime) > SERVERREASKTIME)
1138
    &&theApp.serverconnect -> IsConnected()
1421
    && theApp.serverconnect -> IsConnected()
1139
    &&theApp.glob_prefs -> GetMaxSourcePerFileSoft() > GetSourceCount() && !stopped)
1422
    && theApp.glob_prefs -> GetMaxSourcePerFileSoft() > GetSourceCount() && !stopped)
1140
    {
1423
    {
1141
        //local server
1424
        //local server
1142
        lastsearchtime = dwCurTick;
1425
        lastsearchtime = dwCurTick;
1143
        Packet *packet = new Packet(OP_GETSOURCES, 16);
1426
        Packet * packet = new Packet(OP_GETSOURCES, 16);
1144
        memcpy(packet -> pBuffer, m_abyFileHash, 16);
1427
        memcpy(packet -> pBuffer, m_abyFileHash, 16);
1145
        theApp.uploadqueue -> AddUpDataOverheadServer(packet -> size);
1428
        theApp.uploadqueue -> AddUpDataOverheadServer(packet -> size);
1146
        theApp.serverconnect -> SendPacket(packet, true);
1429
        theApp.serverconnect -> SendPacket(packet, true);
Lines 1156-1162 Link Here
1156
            for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1439
            for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1157
            {
1440
            {
1158
                srclists[sl].GetNext(pos1);
1441
                srclists[sl].GetNext(pos1);
1159
                CUpDownClient *cur_src = srclists[sl].GetAt(pos2);
1442
                CUpDownClient * cur_src = srclists[sl].GetAt(pos2);
1160
                switch (cur_src -> GetDownloadState())
1443
                switch (cur_src -> GetDownloadState())
1161
                {
1444
                {
1162
                case DS_DOWNLOADING:
1445
                case DS_DOWNLOADING:
Lines 1164-1174 Link Here
1164
                        transferingsrc++;
1447
                        transferingsrc++;
1165
                        uint32 cur_datarate = cur_src -> CalculateDownloadRate();
1448
                        uint32 cur_datarate = cur_src -> CalculateDownloadRate();
1166
                        datarate += cur_datarate;
1449
                        datarate += cur_datarate;
1167
                        if (reducedownload &&cur_src -> GetDownloadState() == DS_DOWNLOADING)
1450
                        if (reducedownload && cur_src -> GetDownloadState() == DS_DOWNLOADING)
1168
                        {
1451
                        {
1169
                            //(uint32)(((float)reducedownload/100)*cur_datarate)/10;:
1452
                            //(uint32)(((float)reducedownload/100)*cur_datarate)/10;:
1170
                            uint32 limit = reducedownload *cur_datarate/1000;
1453
                            uint32 limit = reducedownload * cur_datarate/ 1000;
1171
                            if (limit < 1000 &&reducedownload == 200)
1454
                            if (limit < 1000 && reducedownload == 200)
1172
                            limit += 1000;
1455
                            limit += 1000;
1173
                            else if(limit < 1)
1456
                            else if(limit < 1)
1174
                            limit = 1;
1457
                            limit = 1;
Lines 1208-1214 Link Here
1208
                            break;
1491
                            break;
1209
                        }
1492
                        }
1210
                        // doubled reasktime for no needed parts - save connections and traffic
1493
                        // doubled reasktime for no needed parts - save connections and traffic
1211
                        if (! ((!cur_src -> GetLastAskedTime()) || (dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME *2))
1494
                        if (! ((!cur_src -> GetLastAskedTime()) || (dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME * 2))
1212
                        break;
1495
                        break;
1213
                    }
1496
                    }
1214
                case DS_ONQUEUE:
1497
                case DS_ONQUEUE:
Lines 1225-1233 Link Here
1225
                            //Johnny-B - nothing more to do here (good eye!):
1508
                            //Johnny-B - nothing more to do here (good eye!):
1226
                            break;
1509
                            break;
1227
                        }
1510
                        }
1228
                        if (theApp.serverconnect -> IsConnected() && ((!cur_src -> GetLastAskedTime()) || (dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME - 20000))
1511
                        if (((!cur_src -> GetLastAskedTime()) || (dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME - 20000)) {
1229
                        cur_src -> UDPReaskForDownload();
1512
                        cur_src -> UDPReaskForDownload();
1230
                    }
1513
                    }
1514
                    }
1231
                case DS_CONNECTED:
1515
                case DS_CONNECTED:
1232
                case DS_CONNECTING:
1516
                case DS_CONNECTING:
1233
                    if ((dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME)
1517
                    if ((dwCurTick - cur_src -> GetLastAskedTime()) > FILEREASKTIME)
Lines 1257-1263 Link Here
1257
            for (pos1 = this -> A4AFSourcesList.GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1541
            for (pos1 = this -> A4AFSourcesList.GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1258
            {
1542
            {
1259
                this -> A4AFSourcesList.GetNext(pos1);
1543
                this -> A4AFSourcesList.GetNext(pos1);
1260
                CUpDownClient *cur_source = this -> A4AFSourcesList.GetAt(pos2);
1544
                CUpDownClient * cur_source = this -> A4AFSourcesList.GetAt(pos2);
1261
                if (! (cur_source -> GetDownloadState() == DS_DOWNLOADING))
1545
                if (! (cur_source -> GetDownloadState() == DS_DOWNLOADING))
1262
                {
1546
                {
1263
                    this -> A4AFSourcesList.RemoveAt(pos2);
1547
                    this -> A4AFSourcesList.RemoveAt(pos2);
Lines 1267-1277 Link Here
1267
        }
1551
        }
1268
    }
1552
    }
1269
    /* Sources droping engine. Auto drop allowed type of sources at interval. */
1553
    /* Sources droping engine. Auto drop allowed type of sources at interval. */
1270
    if ((dwCurTick - m_LastSourceDropTime) > theApp.glob_prefs -> GetAutoDropTimer() *1000)
1554
    if ((dwCurTick - m_LastSourceDropTime) > theApp.glob_prefs -> GetAutoDropTimer() * 1000)
1271
    {
1555
    {
1272
        m_LastSourceDropTime = dwCurTick;
1556
        m_LastSourceDropTime = dwCurTick;
1273
    /* If all three are enabled, use CleanUpSources() function, will save us some CPU. */
1557
    /* If all three are enabled, use CleanUpSources() function, will save us some CPU. */
1274
        if (theApp.glob_prefs -> DropNoNeededSources() &&theApp.glob_prefs -> DropFullQueueSources() &&theApp.glob_prefs -> DropHighQueueRankingSources())
1558
        if (theApp.glob_prefs -> DropNoNeededSources() && theApp.glob_prefs -> DropFullQueueSources() && theApp.glob_prefs -> DropHighQueueRankingSources())
1275
        {
1559
        {
1276
            CleanUpSources();
1560
            CleanUpSources();
1277
        }
1561
        }
Lines 1310-1337 Link Here
1310
    return datarate;
1594
    return datarate;
1311
}
1595
}
1312
1596
1313
void CPartFile:: AddSources(CMemFile *sources, uint32 serverip, uint16 serverport)
1597
void CPartFile::AddSources(CMemFile * sources, uint32 serverip, uint16 serverport)
1314
{
1598
{
1315
    if (stopped) return;
1599
    if (stopped) return;
1316
    uint8 count;
1600
    uint8 count;
1317
    uint8 debug_lowiddropped = 0;
1601
    uint8 debug_lowiddropped = 0;
1318
    uint8 debug_possiblesources = 0;
1602
    uint8 debug_possiblesources = 0;
1319
    sources -> Read( &count, 1);
1603
    sources -> Read( & count, 1);
1320
    for (int i = 0 ; i != count ; i++)
1604
    for (int i = 0 ; i != count ; i++)
1321
    {
1605
    {
1322
        uint32 userid;
1606
        uint32 userid;
1323
        sources -> Read( &userid, 4);
1607
        sources -> Read( & userid, 4);
1324
        uint16 port;
1608
        uint16 port;
1325
        sources -> Read( &port, 2);
1609
        sources -> Read( & port, 2);
1326
        // check first if we are this source
1610
        // check first if we are this source
1327
        // MOD Note: Do not change this part - Merkur
1611
        // MOD Note: Do not change this part - Merkur
1328
        if (theApp.serverconnect -> GetClientID() < 16777216 &&theApp.serverconnect -> IsConnected())
1612
        if (theApp.serverconnect -> GetClientID() < 16777216 && theApp.serverconnect -> IsConnected())
1329
        {
1613
        {
1330
            if ((theApp.serverconnect -> GetClientID() == userid) &&inet_addr(theApp.serverconnect -> GetCurrentServer() -> GetFullIP()) == serverip)
1614
            if ((theApp.serverconnect -> GetClientID() == userid) && inet_addr(theApp.serverconnect -> GetCurrentServer() -> GetFullIP()) == serverip) {
1331
            continue;
1615
            continue;
1332
        }
1616
        }
1617
        }
1333
        else if(theApp.serverconnect -> GetClientID() == userid)
1618
        else if(theApp.serverconnect -> GetClientID() == userid)
1619
	{
1334
        continue;
1620
        continue;
1621
	}
1335
        else if(userid < 16777216 && !theApp.serverconnect -> IsLocalServer(serverip, serverport))
1622
        else if(userid < 16777216 && !theApp.serverconnect -> IsLocalServer(serverip, serverport))
1336
        {
1623
        {
1337
            debug_lowiddropped++;
1624
            debug_lowiddropped++;
Lines 1341-1354 Link Here
1341
        if (theApp.glob_prefs -> GetMaxSourcePerFile() > this -> GetSourceCount())
1628
        if (theApp.glob_prefs -> GetMaxSourcePerFile() > this -> GetSourceCount())
1342
        {
1629
        {
1343
            debug_possiblesources++;
1630
            debug_possiblesources++;
1344
            CUpDownClient *newsource = new CUpDownClient(port, userid, serverip, serverport, this);
1631
            CUpDownClient * newsource = new CUpDownClient(port, userid, serverip, serverport, this);
1345
            theApp.downloadqueue -> CheckAndAddSource(this, newsource);
1632
            theApp.downloadqueue -> CheckAndAddSource(this, newsource);
1346
        }
1633
        }
1347
    }
1634
    }
1348
    theApp.xmuledlg -> AddDebugLogLine(false, "RCV: %i sources from server, %i low id dropped, %i possible sources File(%s)", count, debug_lowiddropped, debug_possiblesources, GetFileName());
1635
    theApp.xmuledlg -> AddDebugLogLine(false, "RCV: %i sources from server, %i low id dropped, %i possible sources File(%s)", count, debug_lowiddropped, debug_possiblesources, GetFileName());
1349
}
1636
}
1350
1637
1351
void CPartFile:: NewSrcPartsInfo()
1638
void CPartFile::NewSrcPartsInfo()
1352
{
1639
{
1353
    // Cache part count
1640
    // Cache part count
1354
    uint16 partcount = GetPartCount();
1641
    uint16 partcount = GetPartCount();
Lines 1362-1368 Link Here
1362
    {
1649
    {
1363
        m_SrcpartFrequency[i] = 0;
1650
        m_SrcpartFrequency[i] = 0;
1364
    }
1651
    }
1365
    CUpDownClient *cur_src;
1652
    CUpDownClient * cur_src;
1366
    for (int sl = 0 ; sl < SOURCESSLOTS ;++sl)
1653
    for (int sl = 0 ; sl < SOURCESSLOTS ;++sl)
1367
    {
1654
    {
1368
        if (!srclists[sl].IsEmpty())
1655
        if (!srclists[sl].IsEmpty())
Lines 1382-1401 Link Here
1382
    UpdateDisplayedInfo();
1669
    UpdateDisplayedInfo();
1383
}
1670
}
1384
1671
1385
bool CPartFile:: GetNextRequestedBlock(CUpDownClient *sender, Requested_Block_Struct **newblocks, uint16 *count)
1672
bool CPartFile::GetNextRequestedBlock(CUpDownClient * sender, Requested_Block_Struct ** newblocks, uint16 * count)
1386
{
1673
{
1387
    uint16 requestedCount = *count;
1674
    uint16 requestedCount = * count;
1388
    uint16 newblockcount = 0;
1675
    uint16 newblockcount = 0;
1389
    uint8 *partsav = sender -> GetPartStatus();
1676
    uint8 * partsav = sender -> GetPartStatus();
1390
    *count = 0;
1677
    * count = 0;
1391
    uint16 randomness;
1678
    uint16 randomness;
1392
    CList < int, int > liGoodParts;
1679
    CList <int, int > liGoodParts;
1393
    CList < int, int > liPossibleParts;
1680
    CList <int, int > liPossibleParts;
1394
    bool finished = false;
1681
    bool finished = false;
1395
    while (!finished)
1682
    while (!finished)
1396
    {
1683
    {
1397
        // Need to empty lists to avoid infinite loop when file is smaller than 180k
1398
        // Otherwise it would keep looping to find 3 blocks, there is only one and it is requested
1399
        liGoodParts.RemoveAll();
1684
        liGoodParts.RemoveAll();
1400
        liPossibleParts.RemoveAll();
1685
        liPossibleParts.RemoveAll();
1401
        // Barry - Top priority should be to continue downloading from current blocks (if anything left to download)
1686
        // Barry - Top priority should be to continue downloading from current blocks (if anything left to download)
Lines 1411-1421 Link Here
1411
            }
1696
            }
1412
        }
1697
        }
1413
        // Barry - Give priorty to end parts of archives and movies
1698
        // Barry - Give priorty to end parts of archives and movies
1414
        if ((!foundPriorityPart) && (IsArchive() || IsMovie()) &&theApp.glob_prefs -> GetPreviewPrio())
1699
        if ((!foundPriorityPart) && (IsArchive() || IsMovie()) && theApp.glob_prefs -> GetPreviewPrio())
1415
        {
1700
        {
1416
            uint32 partCount = GetPartCount();
1701
            uint32 partCount = GetPartCount();
1417
            // First part
1702
            // First part
1418
            if (sender -> IsPartAvailable(0) &&GetNextEmptyBlockInPart(0, 0))
1703
            if (sender -> IsPartAvailable(0) && GetNextEmptyBlockInPart(0, 0))
1419
            {
1704
            {
1420
                liGoodParts.AddHead(0);
1705
                liGoodParts.AddHead(0);
1421
                foundPriorityPart = true;
1706
                foundPriorityPart = true;
Lines 1423-1429 Link Here
1423
            else if((partCount > 1))
1708
            else if((partCount > 1))
1424
            {
1709
            {
1425
                // Last part
1710
                // Last part
1426
                if (sender -> IsPartAvailable(partCount - 1) &&GetNextEmptyBlockInPart(partCount - 1, 0))
1711
                if (sender -> IsPartAvailable(partCount - 1) && GetNextEmptyBlockInPart(partCount - 1, 0))
1427
                {
1712
                {
1428
                    liGoodParts.AddHead(partCount - 1);
1713
                    liGoodParts.AddHead(partCount - 1);
1429
                    foundPriorityPart = true;
1714
                    foundPriorityPart = true;
Lines 1433-1454 Link Here
1433
                else if(partCount > 2)
1718
                else if(partCount > 2)
1434
                {
1719
                {
1435
                    // Second part
1720
                    // Second part
1436
                    if (sender -> IsPartAvailable(1) &&GetNextEmptyBlockInPart(1, 0))
1721
                    if (sender -> IsPartAvailable(1) && GetNextEmptyBlockInPart(1, 0))
1437
                    liGoodParts.AddHead(1);
1722
                    liGoodParts.AddHead(1);
1438
                    // Penultimate part
1723
                    // Penultimate part
1439
                    else if(sender -> IsPartAvailable(partCount - 2) &&GetNextEmptyBlockInPart(partCount - 2, 0))
1724
                    else if(sender -> IsPartAvailable(partCount - 2) && GetNextEmptyBlockInPart(partCount - 2, 0))
1440
                    liGoodParts.AddHead(partCount - 2);
1725
                    liGoodParts.AddHead(partCount - 2);
1441
                }
1726
                }
1442
            }
1727
            }
1443
        }
1728
        }
1444
        if (!foundPriorityPart)
1729
        if (!foundPriorityPart)
1445
        {
1730
        {
1446
            randomness = (uint16) ROUND(((float) rand() /RAND_MAX) * (GetPartCount() - 1));
1731
            randomness = (uint16) ROUND(((float) rand() / RAND_MAX) * (GetPartCount() - 1));
1447
            for (uint16 i = 0 ; i != GetPartCount() ; i++)
1732
            for (uint16 i = 0 ; i != GetPartCount() ; i++)
1448
            {
1733
            {
1449
                if (sender -> IsPartAvailable(randomness))
1734
                if (sender -> IsPartAvailable(randomness))
1450
                {
1735
                {
1451
                    if (partsav[randomness] && !IsComplete(randomness *PARTSIZE, ((randomness + 1) *PARTSIZE) - 1))
1736
                    if (partsav[randomness] && !IsComplete(randomness * PARTSIZE, ((randomness + 1) * PARTSIZE) - 1))
1452
                    {
1737
                    {
1453
 /*if (IsCorruptedPart(randomness)){
1738
 /*if (IsCorruptedPart(randomness)){
1454
 if (GetNextEmptyBlockInPart(randomness,0)){
1739
 if (GetNextEmptyBlockInPart(randomness,0)){
Lines 1457-1463 Link Here
1457
 }
1742
 }
1458
 }
1743
 }
1459
    else */
1744
    else */
1460
                        if (IsPureGap(randomness *PARTSIZE, ((randomness + 1) *PARTSIZE) - 1))
1745
                        if (IsPureGap(randomness * PARTSIZE, ((randomness + 1) * PARTSIZE) - 1))
1461
                        {
1746
                        {
1462
                            if (GetNextEmptyBlockInPart(randomness, 0))
1747
                            if (GetNextEmptyBlockInPart(randomness, 0))
1463
                            liPossibleParts.AddHead(randomness);
1748
                            liPossibleParts.AddHead(randomness);
Lines 1472-1482 Link Here
1472
                randomness = 0;
1757
                randomness = 0;
1473
            }
1758
            }
1474
        }
1759
        }
1475
        CList < int, int > *usedlist;
1760
        CList <int, int > * usedlist;
1476
        if (!liGoodParts.IsEmpty())
1761
        if (!liGoodParts.IsEmpty())
1477
        usedlist = &liGoodParts;
1762
        usedlist = & liGoodParts;
1478
        else if(!liPossibleParts.IsEmpty())
1763
        else if(!liPossibleParts.IsEmpty())
1479
        usedlist = &liPossibleParts;
1764
        usedlist = & liPossibleParts;
1480
        else
1765
        else
1481
        {
1766
        {
1482
            if (!newblockcount)
1767
            if (!newblockcount)
Lines 1491-1497 Link Here
1491
        for (POSITION pos = usedlist -> GetHeadPosition() ; pos != 0 ; usedlist -> GetNext(pos))
1776
        for (POSITION pos = usedlist -> GetHeadPosition() ; pos != 0 ; usedlist -> GetNext(pos))
1492
        {
1777
        {
1493
            if (m_SrcpartFrequency.GetCount() >= usedlist -> GetAt(pos)
1778
            if (m_SrcpartFrequency.GetCount() >= usedlist -> GetAt(pos)
1494
            &&m_SrcpartFrequency[usedlist -> GetAt(pos) ] < nRarest)
1779
            && m_SrcpartFrequency[usedlist -> GetAt(pos) ] < nRarest)
1495
            {
1780
            {
1496
                nRarest = m_SrcpartFrequency[usedlist -> GetAt(pos) ];
1781
                nRarest = m_SrcpartFrequency[usedlist -> GetAt(pos) ];
1497
                usedpart = usedlist -> GetAt(pos);
1782
                usedpart = usedlist -> GetAt(pos);
Lines 1499-1505 Link Here
1499
        }
1784
        }
1500
        while (true)
1785
        while (true)
1501
        {
1786
        {
1502
            Requested_Block_Struct *block = new Requested_Block_Struct;
1787
            Requested_Block_Struct * block = new Requested_Block_Struct;
1503
            if (GetNextEmptyBlockInPart(usedpart, block))
1788
            if (GetNextEmptyBlockInPart(usedpart, block))
1504
            {
1789
            {
1505
                requestedblocks_list.AddTail(block);
1790
                requestedblocks_list.AddTail(block);
Lines 1519-1597 Link Here
1519
        }
1804
        }
1520
        //wend:
1805
        //wend:
1521
    }
1806
    }
1522
    *count = newblockcount;
1807
    * count = newblockcount;
1523
    return true;
1808
    return true;
1524
}
1809
}
1525
1810
1526
void CPartFile:: RemoveBlockFromList(uint32 start, uint32 end)
1811
void CPartFile::RemoveBlockFromList(uint32 start, uint32 end)
1527
{
1812
{
1528
    POSITION pos1, pos2;
1813
    POSITION pos1, pos2;
1529
    for (pos1 = requestedblocks_list.GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1814
    for (pos1 = requestedblocks_list.GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1530
    {
1815
    {
1531
        requestedblocks_list.GetNext(pos1);
1816
        requestedblocks_list.GetNext(pos1);
1532
        if (requestedblocks_list.GetAt(pos2) -> StartOffset <= start &&requestedblocks_list.GetAt(pos2) -> EndOffset >= end)
1817
        if (requestedblocks_list.GetAt(pos2) -> StartOffset <= start && requestedblocks_list.GetAt(pos2) -> EndOffset >= end)
1533
        requestedblocks_list.RemoveAt(pos2);
1818
        requestedblocks_list.RemoveAt(pos2);
1534
    }
1819
    }
1535
}
1820
}
1536
1821
1537
void CPartFile:: RemoveAllRequestedBlocks(void)
1822
void CPartFile::RemoveAllRequestedBlocks(void)
1538
{
1823
{
1539
    requestedblocks_list.RemoveAll();
1824
    requestedblocks_list.RemoveAll();
1540
}
1825
}
1541
1826
1542
#include <pthread.h>
1827
#include <pthread.h>
1543
pthread_attr_t pattr;
1828
pthread_attr_t pattr;
1544
1829
void CPartFile::CompleteFile(bool bIsHashingDone)
1545
void CPartFile:: CompleteFile(bool bIsHashingDone)
1546
{
1830
{
1547
    if (this -> srcarevisible)
1831
    if (this -> srcarevisible)
1832
    {
1548
    theApp.xmuledlg -> transferwnd -> downloadlistctrl -> HideSources(this);
1833
    theApp.xmuledlg -> transferwnd -> downloadlistctrl -> HideSources(this);
1834
    }
1549
    SetPartFileStatus(PS_COMPLETING);
1835
    SetPartFileStatus(PS_COMPLETING);
1550
    if (!bIsHashingDone)
1836
    if (!bIsHashingDone)
1551
    {
1837
    {
1552
        datarate = 0;
1838
        datarate = 0;
1553
        char *partfileb = nstrdup(partmetfilename);
1839
        char * partfileb = nstrdup(partmetfilename.GetData());
1554
        partfileb[strlen(partmetfilename) - 4] = 0;
1840
        partfileb[partmetfilename.Len() - 4] = 0;
1555
        CAddFileThread:: AddFile(theApp.glob_prefs -> GetTempDir(), partfileb, this);
1841
        CAddFileThread::AddFile(theApp.glob_prefs -> GetTempDir(), partfileb, this);
1556
        delete[] partfileb;
1842
        delete[] partfileb;
1557
        return;
1558
    }
1843
    }
1559
    else
1844
    else
1560
    {
1845
    {
1561
        StopFile();
1846
        StopFile(0);
1562
        // 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]
1563
        // use pthreads
1564
        pthread_t tid;
1847
        pthread_t tid;
1565
        pthread_attr_init( &pattr);
1848
        pthread_attr_init( & pattr);
1566
        pthread_attr_setdetachstate( &pattr, PTHREAD_CREATE_DETACHED);
1849
        pthread_attr_setdetachstate( & pattr, PTHREAD_CREATE_DETACHED);
1567
        pthread_create( &tid, &pattr, (void * ( *)(void *)) CompleteThreadProc, this);
1850
        pthread_create( & tid, & pattr, (void * ( *)(void *)) CompleteThreadProc, this);
1568
    }
1569
    theApp.xmuledlg -> transferwnd -> downloadlistctrl -> ShowFilesCount();
1851
    theApp.xmuledlg -> transferwnd -> downloadlistctrl -> ShowFilesCount();
1570
    UpdateDisplayedInfo(true);
1852
    UpdateDisplayedInfo(true);
1853
    }
1571
}
1854
}
1572
1855
1573
UINT CPartFile:: CompleteThreadProc(CPartFile *pFile)
1856
UINT CPartFile::CompleteThreadProc(CPartFile * pFile)
1574
{
1857
{
1575
    if (!pFile)
1858
    if (!pFile)
1859
    {
1576
    return(UINT) - 1;
1860
    return(UINT) - 1;
1861
    }
1577
    pFile -> PerformFileComplete();
1862
    pFile -> PerformFileComplete();
1578
    return 0;
1863
    return 0;
1579
}
1864
}
1580
1865
1581
// Lord KiRon - using threads for file completion
1866
// Lord KiRon - using threads for file completion
1582
BOOL CPartFile:: PerformFileComplete()
1867
BOOL CPartFile::PerformFileComplete()
1583
{
1868
{
1584
    //CSingleLock(&m_FileCompleteMutex,TRUE); // will be unlocked on exit
1585
    wxMutexLocker sLock(m_FileCompleteMutex);
1869
    wxMutexLocker sLock(m_FileCompleteMutex);
1586
    char *partfilename = nstrdup(fullname);
1870
    char * partfilename = nstrdup(fullname);
1587
    // assumes ".met" at the end:
1588
    partfilename[strlen(fullname) - 4] = 0;
1871
    partfilename[strlen(fullname) - 4] = 0;
1589
    char *newfilename = nstrdup(GetFileName());
1872
    char * newfilename = nstrdup(GetFileName());
1590
    strcpy(newfilename, theApp.StripInvalidFilenameChars(newfilename));
1873
    strcpy(newfilename, theApp.StripInvalidFilenameChars(newfilename));
1591
    // ???:
1874
    char * newname = new char[strlen(newfilename) + strlen(theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath) + MAX_PATH * 2];
1592
    char *newname = new char[strlen(newfilename) + strlen(theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath) + MAX_PATH *2];
1875
    wxString indir;
1593
    CString indir;
1876
    if (wxFileName::DirExists(theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath))
1594
    if (wxFileName:: DirExists(theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath))
1595
    {
1877
    {
1596
        indir = theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath;
1878
        indir = theApp.glob_prefs -> GetCategory(GetCategory()) -> incomingpath;
1597
        sprintf(newname, "%s/%s", indir.GetData(), newfilename);
1879
        sprintf(newname, "%s/%s", indir.GetData(), newfilename);
Lines 1601-1636 Link Here
1601
        indir = theApp.glob_prefs -> GetIncomingDir();
1883
        indir = theApp.glob_prefs -> GetIncomingDir();
1602
        sprintf(newname, "%s/%s", indir.GetData(), newfilename);
1884
        sprintf(newname, "%s/%s", indir.GetData(), newfilename);
1603
    }
1885
    }
1604
    // add this file to the suspended uploads list
1605
    CFileHash tmp_filehash(GetFileHash());
1886
    CFileHash tmp_filehash(GetFileHash());
1606
    theApp.uploadqueue -> SuspendUpload(tmp_filehash);
1887
    theApp.uploadqueue -> SuspendUpload(tmp_filehash);
1607
    FlushBuffer();
1608
    // close permanent handle
1609
    m_hpartfile.Close();
1610
    bool renamed = false;
1888
    bool renamed = false;
1611
    if (wxFileName:: FileExists(newname))
1889
    if (wxFileName::FileExists(newname))
1612
    {
1890
    {
1613
        renamed = true;
1891
        renamed = true;
1614
        int namecount = 0;
1892
        int namecount = 0;
1615
        size_t length = strlen(newfilename);
1893
        size_t length = strlen(newfilename);
1616
        //the file extension
1894
        char * ext = strrchr(newfilename, '.');
1617
        char *ext = strrchr(newfilename, '.');
1618
        if (ext == NULL)
1895
        if (ext == NULL)
1896
        {
1619
        ext = newfilename + length;
1897
        ext = newfilename + length;
1620
        //new end is the file name before extension:
1898
        }
1621
        char *last = ext;
1899
        char * last = ext;
1622
        //truncate file name:
1623
        last[0] = 0;
1900
        last[0] = 0;
1624
        //serch for matching ()s and check if it contains a number
1625
        if ((ext != newfilename) && (strrchr(newfilename, ')') + 1 == last))
1901
        if ((ext != newfilename) && (strrchr(newfilename, ')') + 1 == last))
1626
        {
1902
        {
1627
            char *first = strrchr(newfilename, '(');
1903
            char * first = strrchr(newfilename, '(');
1628
            if (first != NULL)
1904
            if (first != NULL)
1629
            {
1905
            {
1630
                first++;
1906
                first++;
1631
                bool found = true;
1907
                bool found = true;
1632
                for (char *step = first ; step < last - 1 ; step++)
1908
                for (char * step = first ; step < last - 1 ; step++)
1633
                if ( *step < '0' || *step > '9')
1909
                if (step[0] < '0' || step[0] > '9')
1634
                {
1910
                {
1635
                    found = false;
1911
                    found = false;
1636
                    break;
1912
                    break;
Lines 1639-1661 Link Here
1639
                {
1915
                {
1640
                    namecount = atoi(first);
1916
                    namecount = atoi(first);
1641
                    last = first - 1;
1917
                    last = first - 1;
1642
                    //truncate again:
1643
                    last[0] = 0;
1918
                    last[0] = 0;
1644
                }
1919
                }
1645
            }
1920
            }
1646
        }
1921
        }
1647
        CString strTestName;
1922
        wxString strTestName;
1648
        do
1923
        do
1649
        {
1924
        {
1650
            namecount++;
1925
            namecount++;
1651
            strTestName.Format("%s/%s(%d).%s", theApp.glob_prefs -> GetIncomingDir(),
1926
            strTestName.Format("%s/%s(%d).%s", theApp.glob_prefs -> GetIncomingDir(),
1652
            newfilename, namecount, min(ext + 1, newfilename + length));
1927
            newfilename, namecount, min(ext + 1, newfilename + length));
1653
        }
1928
        }
1654
        while (wxFileName:: FileExists(strTestName));
1929
        while (wxFileName::FileExists(strTestName));
1655
        delete[] newname;
1930
        delete[] newname;
1656
        newname = nstrdup(strTestName);
1931
        newname = nstrdup(strTestName);
1657
    }
1932
    }
1658
    delete[] newfilename;
1933
    delete[] newfilename;
1934
    if (IsDynamic() > 1)
1935
    {
1936
        if (!Store(newname))
1937
        {
1938
            return false;
1939
        }
1940
        FlushBuffer();
1941
        Close();
1942
    }
1943
    else
1944
    {
1945
        FlushBuffer();
1946
        Close();
1659
    if (!wxRenameFile(partfilename, newname))
1947
    if (!wxRenameFile(partfilename, newname))
1660
    {
1948
    {
1661
        if (!SafeCopyFile(partfilename, newname))
1949
        if (!SafeCopyFile(partfilename, newname))
Lines 1677-1689 Link Here
1677
            printf("info: could not remove original '%s' after creating backup\n", partfilename);
1965
            printf("info: could not remove original '%s' after creating backup\n", partfilename);
1678
        }
1966
        }
1679
    }
1967
    }
1968
    }
1680
    if (!wxRemoveFile(fullname))
1969
    if (!wxRemoveFile(fullname))
1681
    {
1970
    {
1682
        wxMutexGuiEnter();
1971
        wxMutexGuiEnter();
1683
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETEFAILED), fullname);
1972
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETEFAILED), fullname);
1684
        wxMutexGuiLeave();
1973
        wxMutexGuiLeave();
1685
    }
1974
    }
1686
    CString BAKName(fullname);
1975
    wxString BAKName(fullname);
1687
    BAKName.Append(".BAK");
1976
    BAKName.Append(".BAK");
1688
    if (!wxRemoveFile(BAKName))
1977
    if (!wxRemoveFile(BAKName))
1689
    {
1978
    {
Lines 1708-1749 Link Here
1708
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_DOWNLOADRENAMED), (strrchr(newname, '/') ? strrchr(newname, '/') + 1: newname));
1997
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_DOWNLOADRENAMED), (strrchr(newname, '/') ? strrchr(newname, '/') + 1: newname));
1709
        wxMutexGuiLeave();
1998
        wxMutexGuiLeave();
1710
    }
1999
    }
1711
    // TODO: What the f*** if it is already known?
1712
    theApp.knownfiles -> SafeAddKFile(this);
2000
    theApp.knownfiles -> SafeAddKFile(this);
1713
    // remove the file from the suspended uploads list
1714
    theApp.uploadqueue -> ResumeUpload(tmp_filehash);
2001
    theApp.uploadqueue -> ResumeUpload(tmp_filehash);
1715
    SetAutoUpPriority(false);
2002
    SetAutoUpPriority(false);
1716
    theApp.downloadqueue -> RemoveFile(this);
2003
    theApp.downloadqueue -> RemoveFile(this);
1717
    //theApp.xmuledlg->transferwnd.downloadlistctrl.UpdateItem(this);
1718
    wxMutexGuiEnter();
2004
    wxMutexGuiEnter();
1719
    UpdateDisplayedInfo();
2005
    UpdateDisplayedInfo();
1720
    theApp.xmuledlg -> transferwnd -> downloadlistctrl -> ShowFilesCount();
2006
    theApp.xmuledlg -> transferwnd -> downloadlistctrl -> ShowFilesCount();
1721
    wxMutexGuiLeave();
2007
    wxMutexGuiLeave();
1722
    //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]
1723
    // Barry - Just in case
1724
    //		transfered = m_nFileSize;
1725
    wxMutexGuiEnter();
2008
    wxMutexGuiEnter();
1726
    theApp.downloadqueue -> StartNextFile();
2009
    theApp.downloadqueue -> StartNextFile();
1727
    wxMutexGuiLeave();
2010
    wxMutexGuiLeave();
1728
    return TRUE;
2011
    return TRUE;
1729
}
2012
}
1730
2013
1731
void CPartFile:: RemoveAllSources(bool bTryToSwap)
2014
void CPartFile::RemoveAllSources(int fx, bool bTryToSwap)
1732
{
2015
{
1733
    //TODO transfer sources to other downloading files if possible
2016
    CUpDownClient * client;
1734
    POSITION pos1, pos2;
2017
    POSITION pos1, pos2;
1735
    for (int sl = 0 ; sl < SOURCESSLOTS ; sl++) if(!srclists[sl].IsEmpty())
2018
    for (int sl = 0 ; sl < SOURCESSLOTS ; sl++)
2019
    {
2020
        if (!srclists[sl].IsEmpty())
2021
        {
1736
    for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
2022
    for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1737
    {
2023
    {
1738
        srclists[sl].GetNext(pos1);
2024
        srclists[sl].GetNext(pos1);
1739
        if (bTryToSwap)
2025
        if (bTryToSwap)
1740
        {
2026
        {
1741
            if (!srclists[sl].GetAt(pos2) -> SwapToAnotherFile())
2027
                    client = srclists[sl].GetAt(pos2);
1742
            theApp.downloadqueue -> RemoveSource(srclists[sl].GetAt(pos2));
2028
                    if (fx)
2029
                    {
2030
                        if (client -> GetDownloadState() != DS_DOWNLOADING)
2031
                        {
2032
                            (void) client -> SwapToAnotherFile();
2033
                        }
1743
        }
2034
        }
1744
        else
2035
        else
1745
        theApp.downloadqueue -> RemoveSource(srclists[sl].GetAt(pos2));
2036
                    {
2037
                        if (!client -> SwapToAnotherFile())
2038
                        {
2039
                            theApp.downloadqueue -> RemoveSource(client);
2040
                        }
2041
                    }
2042
                }
2043
                else
2044
                {
2045
                    if (!fx)
2046
                    {
2047
                        theApp.downloadqueue -> RemoveSource(client);
2048
                    }
2049
                }
2050
            }
2051
        }
1746
    }
2052
    }
2053
    if (!fx)
2054
    {
1747
    /* Razor 1a - Modif by MikaelB */
2055
    /* Razor 1a - Modif by MikaelB */
1748
    if (!this -> A4AFSourcesList.IsEmpty())
2056
    if (!this -> A4AFSourcesList.IsEmpty())
1749
    {
2057
    {
Lines 1761-1835 Link Here
1761
        }
2069
        }
1762
    }
2070
    }
1763
    /* End modif */
2071
    /* End modif */
2072
    }
1764
    UpdateFileRatingCommentAvail();
2073
    UpdateFileRatingCommentAvail();
1765
}
2074
}
1766
2075
1767
void CPartFile:: DeleteFile()
2076
void CPartFile::DeleteFile()
1768
{
2077
{
1769
    // Barry - Need to tell any connected clients to stop sending the file
2078
    StopFile(0);
1770
    StopFile();
1771
    theApp.sharedfiles -> RemoveFile(this);
2079
    theApp.sharedfiles -> RemoveFile(this);
1772
    theApp.downloadqueue -> RemoveFile(this);
2080
    theApp.downloadqueue -> RemoveFile(this);
1773
    theApp.xmuledlg -> transferwnd -> downloadlistctrl -> RemoveFile(this);
2081
    theApp.xmuledlg -> transferwnd -> downloadlistctrl -> RemoveFile(this);
1774
    m_hpartfile.Close();
2082
    Close();
1775
    if (!wxRemoveFile(fullname))
2083
    if (!wxRemoveFile(fullname))
1776
    theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETE), fullname);
2084
    theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETE), fullname);
1777
    char *partfilename = nstrdup(fullname);
2085
    char * partfilename = nstrdup(fullname);
1778
    partfilename[strlen(fullname) - 4] = 0;
2086
    partfilename[strlen(fullname) - 4] = 0;
1779
    if (!wxRemoveFile(partfilename))
2087
    if (!wxRemoveFile(partfilename))
1780
    theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETE), partfilename);
2088
    theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETE), partfilename);
1781
    CString BAKName(fullname);
2089
    wxString BAKName(fullname);
1782
    BAKName.Append(".BAK");
2090
    BAKName.Append(".BAK");
1783
    if (!wxRemoveFile(BAKName))
2091
    if (!wxRemoveFile(BAKName))
1784
    theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETE), BAKName.GetData());
2092
    theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_DELETE), BAKName.GetData());
1785
    delete[] partfilename;
2093
    delete[] partfilename;
1786
}
2094
}
1787
2095
1788
bool CPartFile:: HashSinglePart(uint16 partnumber)
2096
void CPartFile::CreateHash(wxUint32 Length, unsigned char * Output)
2097
{
2098
    bool PaddingStarted = false;
2099
    wxUint32 Hash[4];
2100
    Hash[0] = 0x67452301;
2101
    Hash[1] = 0xEFCDAB89;
2102
    Hash[2] = 0x98BADCFE;
2103
    Hash[3] = 0x10325476;
2104
    wxUint32 Required = Length;
2105
    unsigned char X[64 * 128];
2106
    while (Required >= 64)
2107
    {
2108
        wxUint32 len = Required / 64;
2109
        if (len > sizeof(X) / (64 * sizeof(X[0])))
2110
        {
2111
            len = sizeof(X) / (64 * sizeof(X[0]));
2112
        }
2113
        Read( & X, len * 64);
2114
        for (wxUint32 i = 0 ; i < len ; i++)
2115
        {
2116
            MD4Transform(Hash, (wxUint32 *)(X + i * 64));
2117
        }
2118
        Required -= len * 64;
2119
    }
2120
    // bytes to read
2121
    Required = Length % 64;
2122
    if (Required)
2123
    {
2124
        Read( & X, Required);
2125
    }
2126
    // in byte scale 512 = 64, 448 = 56
2127
    if (Required >= 56)
2128
    {
2129
        X[Required] = 0x80;
2130
        PaddingStarted = TRUE;
2131
        memset( & X[Required + 1], 0, 63 - Required);
2132
        MD4Transform(Hash, (wxUint32 *) X);
2133
        Required = 0;
2134
    }
2135
    if (!PaddingStarted)
2136
    {
2137
        X[Required++] = 0x80;
2138
    }
2139
    memset( & X[Required], 0, 64 - Required);
2140
    // add size (convert to bits)
2141
    wxUint32 Length2 = Length >> 29;
2142
    Length <<= 3;
2143
    memcpy( & X[56], & Length, 4);
2144
    memcpy( & X[60], & Length2, 4);
2145
    MD4Transform(Hash, (wxUint32 *) X);
2146
    memcpy(Output, Hash, 16);
2147
}
2148
2149
bool CPartFile::HashSinglePart(uint16 partnumber)
1789
{
2150
{
2151
    bool retcode = true;
1790
    if ((GetHashCount() <= partnumber) && (GetPartCount() > 1))
2152
    if ((GetHashCount() <= partnumber) && (GetPartCount() > 1))
1791
    {
2153
    {
1792
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_HASHERRORWARNING), GetFileName());
2154
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_HASHERRORWARNING), GetFileName());
1793
        this -> hashsetneeded = true;
2155
        this -> hashsetneeded = true;
1794
        return true;
1795
    }
2156
    }
1796
    else if(!GetPartHash(partnumber) &&GetPartCount() != 1)
2157
    else if(!GetPartHash(partnumber) && GetPartCount() != 1)
1797
    {
2158
    {
1798
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_INCOMPLETEHASH), GetFileName());
2159
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_INCOMPLETEHASH), GetFileName());
1799
        this -> hashsetneeded = true;
2160
        this -> hashsetneeded = true;
1800
        return true;
1801
    }
2161
    }
1802
    else
2162
    else
1803
    {
2163
    {
1804
        uchar hashresult[16];
2164
        unsigned char hashresult[16];
1805
        m_hpartfile.Seek(PARTSIZE *partnumber);
2165
        Seek(PARTSIZE * partnumber);
1806
        uint32 length = PARTSIZE;
2166
        uint32 length = PARTSIZE;
1807
        if (PARTSIZE * (partnumber + 1) > m_hpartfile.Length())
2167
        if (PARTSIZE * (partnumber + 1) > m_nFileSize)
1808
        length = (m_hpartfile.Length() - (PARTSIZE *partnumber));
2168
        {
1809
        CreateHashFromFile( &m_hpartfile, length, hashresult);
2169
            length = (m_nFileSize - (PARTSIZE * partnumber));
2170
        }
2171
        CreateHash(length, hashresult);
1810
        if (GetPartCount() > 1)
2172
        if (GetPartCount() > 1)
1811
        {
2173
        {
1812
            if (memcmp(hashresult, GetPartHash(partnumber), 16))
2174
            if (memcmp(hashresult, GetPartHash(partnumber), 16))
1813
            return false;
2175
            {
1814
            else
2176
                retcode = false;
1815
            return true;
1816
        }
2177
        }
1817
        else
2178
        }
2179
        else if(memcmp(hashresult, m_abyFileHash, 16))
1818
        {
2180
        {
1819
            if (memcmp(hashresult, m_abyFileHash, 16))
2181
            retcode = false;
1820
            return false;
1821
            else
1822
            return true;
1823
        }
2182
        }
1824
    }
2183
    }
2184
    return retcode;
1825
}
2185
}
1826
2186
1827
bool CPartFile:: IsCorruptedPart(uint16 partnumber)
2187
bool CPartFile::IsCorruptedPart(uint16 partnumber)
1828
{
2188
{
1829
    return corrupted_list.Find(partnumber);
2189
    return corrupted_list.Find(partnumber);
1830
}
2190
}
1831
2191
1832
bool CPartFile:: IsMovie()
2192
bool CPartFile::IsMovie()
1833
{
2193
{
1834
    bool it_is;
2194
    bool it_is;
1835
    wxString extension = wxString(GetFileName()) .Right(5);
2195
    wxString extension = wxString(GetFileName()) .Right(5);
Lines 1846-1852 Link Here
1846
    return(it_is);
2206
    return(it_is);
1847
}
2207
}
1848
2208
1849
bool CPartFile:: IsArchive()
2209
bool CPartFile::IsArchive()
1850
{
2210
{
1851
    bool it_is;
2211
    bool it_is;
1852
    wxString extension = wxString(GetFileName()) .Right(4);
2212
    wxString extension = wxString(GetFileName()) .Right(4);
Lines 1859-1865 Link Here
1859
    return(it_is);
2219
    return(it_is);
1860
}
2220
}
1861
2221
1862
bool CPartFile:: IsSound()
2222
bool CPartFile::IsSound()
1863
{
2223
{
1864
    bool it_is;
2224
    bool it_is;
1865
    wxString extension = wxString(GetFileName()) .Right(4);
2225
    wxString extension = wxString(GetFileName()) .Right(4);
Lines 1870-1876 Link Here
1870
    return(it_is);
2230
    return(it_is);
1871
}
2231
}
1872
2232
1873
bool CPartFile:: IsCDImage()
2233
bool CPartFile::IsCDImage()
1874
{
2234
{
1875
    bool it_is;
2235
    bool it_is;
1876
    wxString extension = wxString(GetFileName()) .Right(4);
2236
    wxString extension = wxString(GetFileName()) .Right(4);
Lines 1880-1886 Link Here
1880
    return(it_is);
2240
    return(it_is);
1881
}
2241
}
1882
2242
1883
bool CPartFile:: IsImage()
2243
bool CPartFile::IsImage()
1884
{
2244
{
1885
    bool it_is;
2245
    bool it_is;
1886
    wxString extension = wxString(GetFileName()) .Right(5);
2246
    wxString extension = wxString(GetFileName()) .Right(5);
Lines 1894-1900 Link Here
1894
    return(it_is);
2254
    return(it_is);
1895
}
2255
}
1896
2256
1897
bool CPartFile:: IsText()
2257
bool CPartFile::IsText()
1898
{
2258
{
1899
    bool it_is;
2259
    bool it_is;
1900
    wxString extension = wxString(GetFileName()) .Right(5);
2260
    wxString extension = wxString(GetFileName()) .Right(5);
Lines 1907-1913 Link Here
1907
    return(it_is);
2267
    return(it_is);
1908
}
2268
}
1909
2269
1910
void CPartFile:: SetDownPriority(uint8 np)
2270
void CPartFile::SetDownPriority(uint8 np)
1911
{
2271
{
1912
    m_iDownPriority = np;
2272
    m_iDownPriority = np;
1913
    theApp.downloadqueue -> SortByPriority();
2273
    theApp.downloadqueue -> SortByPriority();
Lines 1916-1928 Link Here
1916
    SavePartFile();
2276
    SavePartFile();
1917
}
2277
}
1918
2278
1919
void CPartFile:: StopFile()
2279
void CPartFile::StopFile(int fx)
1920
{
2280
{
1921
    // Barry - Need to tell any connected clients to stop sending the file
2281
    // Barry - Need to tell any connected clients to stop sending the file
1922
    // Kry - Need to set it hereto get into SetPartFileStatus(status) correctly:
2282
    // Kry - Need to set it hereto get into SetPartFileStatus(status) correctly:
1923
    stopped = true;
2283
    stopped = true;
1924
    PauseFile();
2284
    PauseFile();
1925
    RemoveAllSources(true);
2285
    RemoveAllSources(0, true);
1926
    datarate = 0;
2286
    datarate = 0;
1927
    transferingsrc = 0;
2287
    transferingsrc = 0;
1928
    FlushBuffer();
2288
    FlushBuffer();
Lines 1930-1939 Link Here
1930
    UpdateDisplayedInfo(true);
2290
    UpdateDisplayedInfo(true);
1931
}
2291
}
1932
2292
1933
void CPartFile:: PauseFile()
2293
void CPartFile::PauseFile()
1934
{
2294
{
1935
    if (status == PS_COMPLETE || status == PS_COMPLETING) return;
2295
    if (status == PS_COMPLETE || status == PS_COMPLETING) return;
1936
    Packet *packet = new Packet(OP_CANCELTRANSFER, 0);
2296
    Packet * packet = new Packet(OP_CANCELTRANSFER, 0);
1937
    POSITION pos1, pos2;
2297
    POSITION pos1, pos2;
1938
    for (int sl = 0 ; sl < SOURCESSLOTS ; sl++)
2298
    for (int sl = 0 ; sl < SOURCESSLOTS ; sl++)
1939
    {
2299
    {
Lines 1942-1954 Link Here
1942
            for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
2302
            for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
1943
            {
2303
            {
1944
                srclists[sl].GetNext(pos1);
2304
                srclists[sl].GetNext(pos1);
1945
                CUpDownClient *cur_src = srclists[sl].GetAt(pos2);
2305
                CUpDownClient * cur_src = srclists[sl].GetAt(pos2);
1946
                if (cur_src -> GetDownloadState() == DS_DOWNLOADING)
2306
                if (cur_src -> GetDownloadState() == DS_DOWNLOADING)
1947
                {
2307
                {
1948
                    theApp.uploadqueue -> AddUpDataOverheadOther(packet -> size);
2308
                    theApp.uploadqueue -> AddUpDataOverheadOther(packet -> size);
1949
#if defined(__DEBUG__)
1950
                    // printf("CPartFile::PauseFile OP_CANCELTRANSFER size\n", packet -> size);
1951
#endif
1952
                    cur_src -> socket -> SendPacket(packet, false, true);
2309
                    cur_src -> socket -> SendPacket(packet, false, true);
1953
                    cur_src -> SetDownloadState(DS_ONQUEUE);
2310
                    cur_src -> SetDownloadState(DS_ONQUEUE);
1954
                }
2311
                }
Lines 1964-1970 Link Here
1964
    SavePartFile();
2321
    SavePartFile();
1965
}
2322
}
1966
2323
1967
void CPartFile:: ResumeFile()
2324
void CPartFile::ResumeFile()
1968
{
2325
{
1969
    if (status == PS_COMPLETE || status == PS_COMPLETING) return;
2326
    if (status == PS_COMPLETE || status == PS_COMPLETING) return;
1970
    paused = false;
2327
    paused = false;
Lines 1975-1983 Link Here
1975
    UpdateDisplayedInfo(true);
2332
    UpdateDisplayedInfo(true);
1976
}
2333
}
1977
2334
1978
CString CPartFile:: getPartfileStatus()
2335
wxString CPartFile::getPartfileStatus()
1979
{
2336
{
1980
    CString mybuffer = "";
2337
    wxString mybuffer = "";
1981
    if (GetTransferingSrcCount() > 0) mybuffer = GetResString(IDS_DOWNLOADING);
2338
    if (GetTransferingSrcCount() > 0) mybuffer = GetResString(IDS_DOWNLOADING);
1982
    else mybuffer = GetResString(IDS_WAITING);
2339
    else mybuffer = GetResString(IDS_WAITING);
1983
    switch (GetStatus())
2340
    switch (GetStatus())
Lines 1992-1997 Link Here
1992
    case PS_COMPLETE:
2349
    case PS_COMPLETE:
1993
        mybuffer = GetResString(IDS_COMPLETE);
2350
        mybuffer = GetResString(IDS_COMPLETE);
1994
        break;
2351
        break;
2352
    case PS_CONVERTING:
2353
        mybuffer = GetResString(IDS_CONVERTING);
2354
        break;
1995
    case PS_PAUSED:
2355
    case PS_PAUSED:
1996
        mybuffer = GetResString(IDS_PAUSED);
2356
        mybuffer = GetResString(IDS_PAUSED);
1997
        break;
2357
        break;
Lines 2006-2012 Link Here
2006
    return mybuffer;
2366
    return mybuffer;
2007
}
2367
}
2008
2368
2009
int CPartFile:: getPartfileStatusRang()
2369
int CPartFile::getPartfileStatusRang()
2010
{
2370
{
2011
    int tempstatus = 0;
2371
    int tempstatus = 0;
2012
    if (GetTransferingSrcCount() == 0) tempstatus = 1;
2372
    if (GetTransferingSrcCount() == 0) tempstatus = 1;
Lines 2032-2048 Link Here
2032
    return tempstatus;
2392
    return tempstatus;
2033
}
2393
}
2034
2394
2035
sint32 CPartFile:: getTimeRemaining()
2395
sint32 CPartFile::getTimeRemaining()
2036
{
2396
{
2037
    if (GetDatarate() == 0) return - 1;
2397
    if (GetDatarate() == 0) return - 1;
2038
    return((GetFileSize() - GetCompletedSize()) / GetDatarate());
2398
    return((GetFileSize() - GetCompletedSize()) / GetDatarate());
2039
}
2399
}
2040
2400
2041
void CPartFile:: PreviewFile()
2401
void CPartFile::PreviewFile()
2042
{
2402
{
2043
    wxString command;
2403
    wxString command;
2044
    // If no player set in preferences, use mplayer.
2404
    // If no player set in preferences, use mplayer.
2045
    if (theApp.glob_prefs -> GetVideoPlayer() == "")
2405
    if (theApp.glob_prefs -> GetVideoPlayer() =="")
2046
    command.Append(wxT("mplayer"));
2406
    command.Append(wxT("mplayer"));
2047
    else
2407
    else
2048
    command.Append(theApp.glob_prefs -> GetVideoPlayer());
2408
    command.Append(theApp.glob_prefs -> GetVideoPlayer());
Lines 2055-2066 Link Here
2055
    wxShell(command.c_str());
2415
    wxShell(command.c_str());
2056
}
2416
}
2057
2417
2058
bool CPartFile:: PreviewAvailable()
2418
bool CPartFile::PreviewAvailable()
2059
{
2419
{
2060
    return(IsMovie() &&IsComplete(0, PARTSIZE));
2420
    return(IsMovie() && IsComplete(0, PARTSIZE));
2061
}
2421
}
2062
2422
2063
void CPartFile:: UpdateAvailablePartsCount()
2423
void CPartFile::UpdateAvailablePartsCount()
2064
{
2424
{
2065
    uint8 availablecounter = 0;
2425
    uint8 availablecounter = 0;
2066
    bool breakflag = false;
2426
    bool breakflag = false;
Lines 2083-2118 Link Here
2083
            }
2443
            }
2084
        }
2444
        }
2085
    }
2445
    }
2086
    if (iPartCount == availablecounter &&availablePartsCount < iPartCount)
2446
    if (iPartCount == availablecounter && availablePartsCount < iPartCount)
2087
    //CTime::GetCurrentTime();:
2447
    //CTime::GetCurrentTime();:
2088
    lastseencomplete = time(NULL);
2448
    lastseencomplete = time(NULL);
2089
    availablePartsCount = availablecounter;
2449
    availablePartsCount = availablecounter;
2090
}
2450
}
2091
2451
2092
Packet *CPartFile:: CreateSrcInfoPacket(CUpDownClient *forClient)
2452
Packet * CPartFile::CreateSrcInfoPacket(CUpDownClient * forClient)
2093
{
2453
{
2094
#if defined(__DEBUG__)
2095
    // printf("CPartFile:: CreateSrcInfoPacket\n");
2096
#endif
2097
    int sl;
2454
    int sl;
2098
    for (sl = 0 ; sl < SOURCESSLOTS ; sl++) if(srclists[sl].IsEmpty()) return 0;
2455
    for (sl = 0 ; sl < SOURCESSLOTS ; sl++) if(srclists[sl].IsEmpty()) return 0;
2099
    CMemFile data;
2456
    CMemFile data;
2100
    uint16 nCount = 0;
2457
    uint16 nCount = 0;
2101
    data.Write(m_abyFileHash, 16);
2458
    data.Write(m_abyFileHash, 16);
2102
    data.Write( &nCount, 2);
2459
    data.Write( & nCount, 2);
2103
    bool bNeeded;
2460
    bool bNeeded;
2104
    for (sl = 0 ; sl < SOURCESSLOTS ; sl++) if(!srclists[sl].IsEmpty())
2461
    for (sl = 0 ; sl < SOURCESSLOTS ; sl++) if(!srclists[sl].IsEmpty())
2105
    for (POSITION pos = srclists[sl].GetHeadPosition() ; pos != 0 ; srclists[sl].GetNext(pos))
2462
    for (POSITION pos = srclists[sl].GetHeadPosition() ; pos != 0 ; srclists[sl].GetNext(pos))
2106
    {
2463
    {
2107
        bNeeded = false;
2464
        bNeeded = false;
2108
        CUpDownClient *cur_src = srclists[sl].GetAt(pos);
2465
        CUpDownClient * cur_src = srclists[sl].GetAt(pos);
2109
        if (cur_src -> HasLowID())
2466
        if (cur_src -> HasLowID())
2110
        continue;
2467
        continue;
2111
        // only send source which have needed parts for this client if possible
2468
        // only send source which have needed parts for this client if possible
2112
        uint8 *srcstatus = cur_src -> GetPartStatus();
2469
        uint8 * srcstatus = cur_src -> GetPartStatus();
2113
        if (srcstatus)
2470
        if (srcstatus)
2114
        {
2471
        {
2115
            uint8 *reqstatus = forClient -> GetPartStatus();
2472
            uint8 * reqstatus = forClient -> GetPartStatus();
2116
            if (reqstatus)
2473
            if (reqstatus)
2117
            {
2474
            {
2118
                // only send sources which have needed parts for this client
2475
                // only send sources which have needed parts for this client
Lines 2146-2178 Link Here
2146
            uint16 nPort = cur_src -> GetUserPort();
2503
            uint16 nPort = cur_src -> GetUserPort();
2147
            uint32 dwServerIP = cur_src -> GetServerIP();
2504
            uint32 dwServerIP = cur_src -> GetServerIP();
2148
            uint16 nServerPort = cur_src -> GetServerPort();
2505
            uint16 nServerPort = cur_src -> GetServerPort();
2149
            data.Write( &dwID, 4);
2506
            data.Write( & dwID, 4);
2150
            data.Write( &nPort, 2);
2507
            data.Write( & nPort, 2);
2151
            data.Write( &dwServerIP, 4);
2508
            data.Write( & dwServerIP, 4);
2152
            data.Write( &nServerPort, 2);
2509
            data.Write( & nServerPort, 2);
2153
            if (forClient -> GetSourceExchangeVersion() > 1)
2510
            if (forClient -> GetSourceExchangeVersion() > 1)
2154
            data.Write(cur_src -> GetUserHash(), 16);
2511
            data.Write(cur_src -> GetUserHash(), 16);
2155
            if (nCount > 500)
2512
            if (nCount > 500)
2156
            break;
2513
            break;
2157
        }
2514
        }
2158
    }
2515
    }
2159
    if (!nCount)
2516
    if (nCount)
2160
    return 0;
2517
    {
2161
    data.Seek(16);
2518
    data.Seek(16);
2162
    data.Write( &nCount, 2);
2519
        data.Write( & nCount, 2);
2163
    Packet *result = new Packet( &data, OP_EMULEPROT);
2520
        Packet * result = new Packet( & data, OP_EMULEPROT);
2164
    result -> opcode = OP_ANSWERSOURCES;
2521
    result -> opcode = OP_ANSWERSOURCES;
2165
    if (nCount > 28)
2522
    if (nCount > 28)
2523
        {
2166
    result -> PackPacket();
2524
    result -> PackPacket();
2525
        }
2167
    theApp.xmuledlg -> AddDebugLogLine(false, "Send:Source User(%s) File(%s) Count(%i)", forClient -> GetUserName(), GetFileName(), nCount);
2526
    theApp.xmuledlg -> AddDebugLogLine(false, "Send:Source User(%s) File(%s) Count(%i)", forClient -> GetUserName(), GetFileName(), nCount);
2168
    return result;
2527
    return result;
2528
    }
2529
    else
2530
    {
2531
        return 0;
2532
    }
2169
}
2533
}
2170
2534
2171
void CPartFile:: AddClientSources(CMemFile *sources, uint8 sourceexchangeversion)
2535
void CPartFile::AddClientSources(CMemFile * sources, uint8 sourceexchangeversion)
2172
{
2536
{
2173
    if (stopped) return;
2537
    if (stopped) return;
2174
    uint16 nCount;
2538
    uint16 nCount;
2175
    sources -> Read( &nCount, 2);
2539
    sources -> Read( & nCount, 2);
2176
    for (int i = 0 ; i != nCount ; i++)
2540
    for (int i = 0 ; i != nCount ; i++)
2177
    {
2541
    {
2178
        uint32 dwID;
2542
        uint32 dwID;
Lines 2180-2214 Link Here
2180
        uint32 dwServerIP;
2544
        uint32 dwServerIP;
2181
        uint16 nServerPort;
2545
        uint16 nServerPort;
2182
        uchar achUserHash[16];
2546
        uchar achUserHash[16];
2183
        sources -> Read( &dwID, 4);
2547
        sources -> Read( & dwID, 4);
2184
        sources -> Read( &nPort, 2);
2548
        sources -> Read( & nPort, 2);
2185
        sources -> Read( &dwServerIP, 4);
2549
        sources -> Read( & dwServerIP, 4);
2186
        sources -> Read( &nServerPort, 2);
2550
        sources -> Read( & nServerPort, 2);
2187
        if (sourceexchangeversion > 1)
2551
        if (sourceexchangeversion > 1)
2552
        {
2188
        sources -> Read(achUserHash, 16);
2553
        sources -> Read(achUserHash, 16);
2554
        }
2189
        // check first if we are this source
2555
        // check first if we are this source
2190
        if (theApp.serverconnect -> GetClientID() < 16777216 &&theApp.serverconnect -> IsConnected())
2556
        if (theApp.serverconnect -> GetClientID() < 16777216 && theApp.serverconnect -> IsConnected())
2191
        {
2557
        {
2192
            if ((theApp.serverconnect -> GetClientID() == dwID) &&theApp.serverconnect -> GetCurrentServer() -> GetIP() == dwServerIP)
2558
            if ((theApp.serverconnect -> GetClientID() == dwID) && theApp.serverconnect -> GetCurrentServer() -> GetIP() == dwServerIP)
2193
            continue;
2559
            continue;
2194
        }
2560
        }
2195
        else if(theApp.serverconnect -> GetClientID() == dwID)
2561
        else if(theApp.serverconnect -> GetClientID() == dwID)
2562
        {
2196
        continue;
2563
        continue;
2564
        }
2197
        else if(dwID < 16777216)
2565
        else if(dwID < 16777216)
2566
        {
2198
        continue;
2567
        continue;
2568
        }
2199
        if (theApp.glob_prefs -> GetMaxSourcePerFile() > this -> GetSourceCount())
2569
        if (theApp.glob_prefs -> GetMaxSourcePerFile() > this -> GetSourceCount())
2200
        {
2570
        {
2201
            CUpDownClient *newsource = new CUpDownClient(nPort, dwID, dwServerIP, nServerPort, this);
2571
            CUpDownClient * newsource = new CUpDownClient(nPort, dwID, dwServerIP, nServerPort, this);
2202
            if (sourceexchangeversion > 1)
2572
            if (sourceexchangeversion > 1)
2573
            {
2203
            newsource -> SetUserHash(achUserHash);
2574
            newsource -> SetUserHash(achUserHash);
2575
            }
2204
            theApp.downloadqueue -> CheckAndAddSource(this, newsource);
2576
            theApp.downloadqueue -> CheckAndAddSource(this, newsource);
2205
        }
2577
        }
2206
        else
2578
        else
2207
        break;
2579
        {
2580
		i=nCount;
2581
	} 
2208
    }
2582
    }
2209
}
2583
}
2210
2584
2211
void CPartFile:: UpdateAutoDownPriority()
2585
void CPartFile::UpdateAutoDownPriority()
2212
{
2586
{
2213
    if (!IsAutoDownPriority())
2587
    if (!IsAutoDownPriority())
2214
    return;
2588
    return;
Lines 2222-2228 Link Here
2222
2596
2223
// making this function return a higher when more sources have the extended
2597
// making this function return a higher when more sources have the extended
2224
// protocol will force you to ask a larger variety of people for sources
2598
// protocol will force you to ask a larger variety of people for sources
2225
int CPartFile:: GetCommonFilePenalty()
2599
int CPartFile::GetCommonFilePenalty()
2226
{
2600
{
2227
    //TODO: implement, but never return less than MINCOMMONPENALTY!
2601
    //TODO: implement, but never return less than MINCOMMONPENALTY!
2228
    return MINCOMMONPENALTY;
2602
    return MINCOMMONPENALTY;
Lines 2242-2272 Link Here
2242
 fill a gap.
2616
 fill a gap.
2243
    */
2617
    */
2244
2618
2245
uint32 CPartFile:: WriteToBuffer(uint32 transize, BYTE *data, uint32 start, uint32 end, Requested_Block_Struct *block)
2619
uint32 CPartFile::WriteToBuffer(uint32 transize, BYTE * data, uint32 start, uint32 end, Requested_Block_Struct * block)
2246
{
2620
{
2247
    // Increment transfered bytes counter for this file
2248
    transfered += transize;
2621
    transfered += transize;
2249
    // This is needed a few times
2250
    uint32 lenData = end - start + 1;
2622
    uint32 lenData = end - start + 1;
2251
    if (lenData > transize)
2623
    if (lenData > transize)
2624
    {
2252
    m_iGainDueToCompression += lenData - transize;
2625
    m_iGainDueToCompression += lenData - transize;
2253
    // Occasionally packets are duplicated, no point writing it twice
2626
    }
2254
    if (IsComplete(start, end))
2627
    if (IsComplete(start, end))
2255
    {
2628
    {
2256
        theApp.xmuledlg -> AddDebugLogLine(false, "File '%s' has already been written from %ld to %ld\n", GetFileName(), start, end);
2629
        theApp.xmuledlg -> AddDebugLogLine(false, "File '%s' has already been written from %ld to %ld\n", GetFileName(), start, end);
2257
        return 0;
2630
        return 0;
2258
    }
2631
    }
2259
    // Create copy of data as new buffer
2632
    BYTE * buffer = new BYTE[lenData];
2260
    BYTE *buffer = new BYTE[lenData];
2261
    memcpy(buffer, data, lenData);
2633
    memcpy(buffer, data, lenData);
2262
    // Create a new buffered queue entry
2634
    PartFileBufferedData * item = new PartFileBufferedData;
2263
    PartFileBufferedData *item = new PartFileBufferedData;
2264
    item -> data = buffer;
2635
    item -> data = buffer;
2265
    item -> start = start;
2636
    item -> start = start;
2266
    item -> end = end;
2637
    item -> end = end;
2267
    item -> block = block;
2638
    item -> block = block;
2268
    // Add to the queue in the correct position (most likely the end)
2639
    PartFileBufferedData * queueItem;
2269
    PartFileBufferedData *queueItem;
2270
    bool added = false;
2640
    bool added = false;
2271
    POSITION pos = m_BufferedData_list.GetTailPosition();
2641
    POSITION pos = m_BufferedData_list.GetTailPosition();
2272
    while (pos != NULL)
2642
    while (pos != NULL)
Lines 2280-2315 Link Here
2280
        }
2650
        }
2281
    }
2651
    }
2282
    if (!added)
2652
    if (!added)
2653
    {
2283
    m_BufferedData_list.AddHead(item);
2654
    m_BufferedData_list.AddHead(item);
2284
    // Increment buffer size marker
2655
    }
2285
    m_nTotalBufferData += lenData;
2656
    m_nTotalBufferData += lenData;
2286
    // Mark this small section of the file as filled
2287
    FillGap(item -> start, item -> end);
2657
    FillGap(item -> start, item -> end);
2288
    // Update the flushed mark on the requested block
2289
    // The loop here is unfortunate but necessary to detect deleted blocks.
2290
    pos = requestedblocks_list.GetHeadPosition();
2658
    pos = requestedblocks_list.GetHeadPosition();
2291
    while (pos != NULL)
2659
    while (pos != NULL)
2292
    {
2660
    {
2293
        if (requestedblocks_list.GetNext(pos) == item -> block)
2661
        if (requestedblocks_list.GetNext(pos) == item -> block)
2662
        {
2294
        item -> block -> transferred += lenData;
2663
        item -> block -> transferred += lenData;
2295
    }
2664
    }
2296
    if (gaplist.IsEmpty()) FlushBuffer();
2665
    }
2297
    // Return the length of data written to the buffer
2666
    if (gaplist.IsEmpty())
2667
    {
2668
        FlushBuffer();
2669
    }
2298
    return lenData;
2670
    return lenData;
2299
}
2671
}
2300
2672
2301
void CPartFile:: FlushBuffer(void)
2673
void CPartFile::FlushBuffer(void)
2302
{
2674
{
2303
    m_nLastBufferFlushTime = GetTickCount();
2675
    m_nLastBufferFlushTime = GetTickCount();
2304
    if (m_BufferedData_list.IsEmpty())
2676
    if (!m_BufferedData_list.IsEmpty())
2305
    {
2677
    {
2306
        return;
2678
        int i;
2307
    }
2308
 /* Madcat - Check if there is at least PARTSIZE amount of free disk space
2679
 /* Madcat - Check if there is at least PARTSIZE amount of free disk space
2309
 in temp dir before flushing. If not enough space, pause the file,
2680
 in temp dir before flushing. If not enough space, pause the file,
2310
    add log line and abort flushing. */
2681
    add log line and abort flushing. */
2311
    wxLongLong total, free;
2682
    wxLongLong total, free;
2312
    if (wxGetDiskSpace(theApp.glob_prefs -> GetTempDir(), &total, &free) &&
2683
        if (wxGetDiskSpace(theApp.glob_prefs -> GetTempDir(), & total, & free) &&
2313
    free < PARTSIZE)
2684
    free < PARTSIZE)
2314
    {
2685
    {
2315
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_OUT_OF_SPACE));
2686
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_OUT_OF_SPACE));
Lines 2317-2360 Link Here
2317
        return;
2688
        return;
2318
    }
2689
    }
2319
    uint32 partCount = GetPartCount();
2690
    uint32 partCount = GetPartCount();
2320
    bool *changedPart = new bool[partCount];
2691
        bool * changedPart = new bool[partCount];
2321
    try
2322
    {
2323
        // Remember which parts need to be checked at the end of the flush
2692
        // Remember which parts need to be checked at the end of the flush
2324
        for (int partNumber = 0 ; (uint32) partNumber < partCount ; partNumber++)
2693
        for (int partNumber = 0 ; (uint32) partNumber < partCount ; partNumber++)
2325
        {
2694
        {
2326
            changedPart[partNumber] = false;
2695
            changedPart[partNumber] = false;
2327
        }
2696
        }
2328
        // Ensure file is big enough to write data to (the last item will be the furthest from the start)
2697
        // Ensure file is big enough to write data to (the last item will be the furthest from the start)
2329
        PartFileBufferedData *item = m_BufferedData_list.GetTail();
2698
        PartFileBufferedData * item = m_BufferedData_list.GetTail();
2330
        if (m_hpartfile.Length() <= item -> end)
2331
        //m_hpartfile.SetLength(item->end + 1);
2332
        ftruncate(m_hpartfile.fd(), item -> end + 1);
2333
        // Loop through queue
2699
        // Loop through queue
2334
        for (int i = m_BufferedData_list.GetCount() ; i > 0 ; i--)
2700
        i = m_BufferedData_list.GetCount();
2701
        while (i > 0)
2335
        {
2702
        {
2336
            if (i < 1)
2337
            {
2338
                // Can this happen ?
2339
                // Well, if it did... abort then.:
2340
                return;
2341
            }
2342
            // Get top item
2343
            item = m_BufferedData_list.GetHead();
2703
            item = m_BufferedData_list.GetHead();
2344
            // This is needed a few times
2345
            uint32 lenData = item -> end - item -> start + 1;
2704
            uint32 lenData = item -> end - item -> start + 1;
2346
            int curpart = item -> start/PARTSIZE;
2705
            int curpart = item -> start/ PARTSIZE;
2347
            changedPart[curpart] = true;
2706
            changedPart[curpart] = true;
2348
            // Go to the correct position in file and write block of data
2707
            Seek(item -> start);
2349
            m_hpartfile.Seek(item -> start);
2708
            Write(item -> data, lenData);
2350
            m_hpartfile.Write(item -> data, lenData);
2351
            // Remove item from queue
2352
            m_BufferedData_list.RemoveHead();
2709
            m_BufferedData_list.RemoveHead();
2353
            // Decrease buffer size
2354
            m_nTotalBufferData -= lenData;
2710
            m_nTotalBufferData -= lenData;
2355
            // Release memory used by this item
2356
            delete [] item -> data;
2711
            delete [] item -> data;
2357
            delete item;
2712
            delete item;
2713
            i--;
2358
        }
2714
        }
2359
        // Flush to disk
2715
        // Flush to disk
2360
        m_hpartfile.Flush();
2716
        m_hpartfile.Flush();
Lines 2369-2381 Link Here
2369
                continue;
2725
                continue;
2370
            }
2726
            }
2371
            // Is this 9MB part complete
2727
            // Is this 9MB part complete
2372
            if (IsComplete(PARTSIZE *partNumber, (PARTSIZE * (partNumber + 1)) - 1))
2728
            if (IsComplete(PARTSIZE * partNumber, (PARTSIZE * (partNumber + 1)) - 1))
2373
            {
2729
            {
2374
                // Is part corrupt
2730
                // Is part corrupt
2375
                if (!HashSinglePart(partNumber))
2731
                if (!HashSinglePart(partNumber))
2376
                {
2732
                {
2377
                    theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_PARTCORRUPT), partNumber, GetFileName());
2733
                    theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_PARTCORRUPT), partNumber, GetFileName());
2378
                    AddGap(PARTSIZE *partNumber, (PARTSIZE *partNumber + partRange));
2734
                    AddGap(PARTSIZE * partNumber, (PARTSIZE * partNumber + partRange));
2379
                    corrupted_list.AddTail(partNumber);
2735
                    corrupted_list.AddTail(partNumber);
2380
                    // Reduce transfered amount by corrupt amount
2736
                    // Reduce transfered amount by corrupt amount
2381
                    this -> m_iLostDueToCorruption += (partRange + 1);
2737
                    this -> m_iLostDueToCorruption += (partRange + 1);
Lines 2390-2403 Link Here
2390
                    }
2746
                    }
2391
                }
2747
                }
2392
            }
2748
            }
2393
            else if(IsCorruptedPart(partNumber) &&theApp.glob_prefs -> IsICHEnabled())
2749
            else if(IsCorruptedPart(partNumber) && theApp.glob_prefs -> IsICHEnabled())
2394
            {
2750
            {
2395
                // Try to recover with minimal loss
2751
                // Try to recover with minimal loss
2396
                if (HashSinglePart(partNumber))
2752
                if (HashSinglePart(partNumber))
2397
                {
2753
                {
2398
                    m_iTotalPacketsSavedDueToICH++;
2754
                    m_iTotalPacketsSavedDueToICH++;
2399
                    FillGap(PARTSIZE *partNumber, (PARTSIZE *partNumber + partRange));
2755
                    FillGap(PARTSIZE * partNumber, (PARTSIZE * partNumber + partRange));
2400
                    RemoveBlockFromList(PARTSIZE *partNumber, (PARTSIZE *partNumber + partRange));
2756
                    RemoveBlockFromList(PARTSIZE * partNumber, (PARTSIZE * partNumber + partRange));
2401
                    theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ICHWORKED), partNumber, GetFileName());
2757
                    theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ICHWORKED), partNumber, GetFileName());
2402
                }
2758
                }
2403
            }
2759
            }
Lines 2408-2434 Link Here
2408
        SavePartFile();
2764
        SavePartFile();
2409
        // Is this file finished?
2765
        // Is this file finished?
2410
        if (gaplist.IsEmpty())
2766
        if (gaplist.IsEmpty())
2411
        CompleteFile(false);
2412
    }
2413
    catch(...)
2414
    {
2767
    {
2415
        theApp.xmuledlg -> AddLogLine(true, GetResString(IDS_ERR_WRITEERROR), GetFileName(), GetResString(IDS_UNKNOWN) .GetData());
2768
            CompleteFile(false);
2416
        SetPartFileStatus(PS_ERROR);
2417
        paused = true;
2418
        datarate = 0;
2419
        transferingsrc = 0;
2420
        //theApp.xmuledlg->transferwnd.downloadlistctrl.UpdateItem(this);
2421
        UpdateDisplayedInfo();
2422
    }
2769
    }
2423
    delete[] changedPart;
2770
    delete[] changedPart;
2771
    }
2424
}
2772
}
2425
2773
2426
// Barry - This will invert the gap list, up to caller to delete gaps when done
2774
// Barry - This will invert the gap list, up to caller to delete gaps when done
2427
// 'Gaps' returned are really the filled areas, and guaranteed to be in order
2775
// 'Gaps' returned are really the filled areas, and guaranteed to be in order
2428
void CPartFile:: GetFilledList(CTypedPtrList < CPtrList, Gap_Struct *> *filled)
2776
void CPartFile::GetFilledList(CTypedPtrList <CPtrList, Gap_Struct *> * filled)
2429
{
2777
{
2430
    Gap_Struct *gap;
2778
    Gap_Struct * gap;
2431
    Gap_Struct *best;
2779
    Gap_Struct * best;
2432
    POSITION pos;
2780
    POSITION pos;
2433
    uint32 start = 0;
2781
    uint32 start = 0;
2434
    uint32 bestEnd = 0;
2782
    uint32 bestEnd = 0;
Lines 2469-2477 Link Here
2469
    }
2817
    }
2470
}
2818
}
2471
2819
2472
void CPartFile:: UpdateFileRatingCommentAvail()
2820
void CPartFile::UpdateFileRatingCommentAvail()
2473
{
2821
{
2474
    if (!this) return;
2822
    if (this)
2823
    {
2475
    bool prev = (hasComment || hasRating);
2824
    bool prev = (hasComment || hasRating);
2476
    hasComment = false;
2825
    hasComment = false;
2477
    hasRating = false;
2826
    hasRating = false;
Lines 2480-2502 Link Here
2480
    for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
2829
    for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
2481
    {
2830
    {
2482
        srclists[sl].GetNext(pos1);
2831
        srclists[sl].GetNext(pos1);
2483
        CUpDownClient *cur_src = srclists[sl].GetAt(pos2);
2832
            CUpDownClient * cur_src = srclists[sl].GetAt(pos2);
2484
        if (cur_src -> GetFileComment() .GetLength() > 0) hasComment = true;
2833
        if (cur_src -> GetFileComment() .GetLength() > 0) hasComment = true;
2485
        if (cur_src -> GetFileRate() > 0) hasRating = true;
2834
        if (cur_src -> GetFileRate() > 0) hasRating = true;
2486
        if (hasComment &&hasRating) break;
2835
            if (hasComment && hasRating) break;
2487
    }
2836
    }
2488
    //theApp.xmuledlg->transferwnd.downloadlistctrl.UpdateItem(this);:
2837
    //theApp.xmuledlg->transferwnd.downloadlistctrl.UpdateItem(this);:
2489
    if (prev != (hasComment || hasRating)) UpdateDisplayedInfo();
2838
        if (prev != (hasComment || hasRating))
2839
        {
2840
            UpdateDisplayedInfo();
2841
        }
2842
    }
2490
}
2843
}
2491
2844
2492
uint16 CPartFile:: GetSourceCount()
2845
uint16 CPartFile::GetSourceCount()
2493
{
2846
{
2494
    uint16 count = 0;
2847
    uint16 count = 0;
2495
    for (int i = 0 ; i < SOURCESSLOTS ; i++) count += srclists[i].GetCount();
2848
    for (int i = 0 ; i < SOURCESSLOTS ; i++) count += srclists[i].GetCount();
2496
    return count;
2849
    return count;
2497
}
2850
}
2498
2851
2499
bool CPartFile:: HasBadRating()
2852
bool CPartFile::HasBadRating()
2500
{
2853
{
2501
    if (!hasRating) return false;
2854
    if (!hasRating) return false;
2502
    POSITION pos1, pos2;
2855
    POSITION pos1, pos2;
Lines 2504-2552 Link Here
2504
    for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
2857
    for (pos1 = srclists[sl].GetHeadPosition() ; (pos2 = pos1) != NULL ;)
2505
    {
2858
    {
2506
        srclists[sl].GetNext(pos1);
2859
        srclists[sl].GetNext(pos1);
2507
        CUpDownClient *cur_src = srclists[sl].GetAt(pos2);
2860
        CUpDownClient * cur_src = srclists[sl].GetAt(pos2);
2508
        if (cur_src -> GetFileRate() == 1) return true;
2861
        if (cur_src -> GetFileRate() == 1) return true;
2509
    }
2862
    }
2510
    return false;
2863
    return false;
2511
}
2864
}
2512
2865
2513
void CPartFile:: UpdateDisplayedInfo(bool force)
2866
void CPartFile::UpdateDisplayedInfo(bool force)
2514
{
2867
{
2515
    DWORD curTick =:: GetTickCount();
2868
    DWORD curTick =::GetTickCount();
2516
    if (force || curTick - m_lastRefreshedDLDisplay > MINWAIT_BEFORE_DLDISPLAY_WINDOWUPDATE + (uint32)(rand() / (RAND_MAX/1000)))
2869
    if (force || curTick - m_lastRefreshedDLDisplay > MINWAIT_BEFORE_DLDISPLAY_WINDOWUPDATE + (uint32)(rand() / (RAND_MAX/ 1000)))
2517
    {
2870
    {
2518
        theApp.xmuledlg -> transferwnd -> downloadlistctrl -> UpdateItem(this);
2871
        theApp.xmuledlg -> transferwnd -> downloadlistctrl -> UpdateItem(this);
2519
        m_lastRefreshedDLDisplay = curTick;
2872
        m_lastRefreshedDLDisplay = curTick;
2520
    }
2873
    }
2521
}
2874
}
2522
2875
2523
time_t CPartFile:: GetLastChangeDatetime(bool forcecheck)
2876
time_t CPartFile::GetLastChangeDatetime(bool forcecheck)
2524
{
2877
{
2525
    if ((:: GetTickCount() - m_lastdatetimecheck) < 60000 && !forcecheck) return m_lastdatecheckvalue;
2878
    if ((::GetTickCount() - m_lastdatetimecheck) < 60000 && !forcecheck) return m_lastdatecheckvalue;
2526
    m_lastdatetimecheck =:: GetTickCount();
2879
    m_lastdatetimecheck =::GetTickCount();
2527
    if (!:: wxFileExists(m_hpartfile.GetFilePath())) m_lastdatecheckvalue = - 1;
2880
    if (!::wxFileExists(m_hpartfile.GetFilePath())) m_lastdatecheckvalue = - 1;
2528
    else
2881
    else
2529
    {
2882
    {
2530
        //CFileStatus filestatus;
2883
        //CFileStatus filestatus;
2531
        struct stat filestatus;
2884
        struct stat filestatus;
2532
        fstat(m_hpartfile.fd(), &filestatus);
2885
        fstat(m_hpartfile.fd(), & filestatus);
2533
        //m_hpartfile.GetStatus(filestatus); // this; "...returns m_attribute without high-order flags" indicates a known MFC bug, wonder how many unknown there are... :)
2886
        //m_hpartfile.GetStatus(filestatus); // this; "...returns m_attribute without high-order flags" indicates a known MFC bug, wonder how many unknown there are... :)
2534
        m_lastdatecheckvalue = filestatus.st_mtime;
2887
        m_lastdatecheckvalue = filestatus.st_mtime;
2535
    }
2888
    }
2536
    return m_lastdatecheckvalue;
2889
    return m_lastdatecheckvalue;
2537
}
2890
}
2538
2891
2539
uint8 CPartFile:: GetCategory()
2892
uint8 CPartFile::GetCategory()
2540
{
2893
{
2541
    if (m_category > theApp.glob_prefs -> GetCatCount() - 1) m_category = 0;
2894
    if (m_category > theApp.glob_prefs -> GetCatCount() - 1) m_category = 0;
2542
    return m_category;
2895
    return m_category;
2543
}
2896
}
2544
2897
2545
CString CPartFile:: GetDownloadFileInfo()
2898
wxString CPartFile::GetDownloadFileInfo()
2546
{
2899
{
2547
    if (this == NULL) return "";
2900
    if (this == NULL) return "";
2548
    CString sRet;
2901
    wxString sRet;
2549
        CString strHash = EncodeBase16(GetFileHash(), 16);;
2902
        wxString strHash = EncodeBase16(GetFileHash(), 16);;
2550
    char lsc[50];
2903
    char lsc[50];
2551
    char complx[50];
2904
    char complx[50];
2552
    char lastprogr[50];
2905
    char lastprogr[50];
Lines 2557-2563 Link Here
2557
    }
2910
    }
2558
    else
2911
    else
2559
    {
2912
    {
2560
        strftime(lsc, sizeof(lsc), theApp.glob_prefs -> GetDateTimeFormat(), localtime((time_t *) &lastseencomplete));
2913
        strftime(lsc, sizeof(lsc), theApp.glob_prefs -> GetDateTimeFormat(), localtime((time_t *) & lastseencomplete));
2561
    }
2914
    }
2562
    if (GetFileDate() == 0)
2915
    if (GetFileDate() == 0)
2563
    {
2916
    {
Lines 2570-2576 Link Here
2570
    float availability = 0;
2923
    float availability = 0;
2571
    if (GetPartCount() != 0)
2924
    if (GetPartCount() != 0)
2572
    {
2925
    {
2573
        availability = GetAvailablePartCount() *100 / GetPartCount();
2926
        availability = GetAvailablePartCount() * 100 / GetPartCount();
2574
    }
2927
    }
2575
    sRet.Format(GetResString(IDS_DL_FILENAME) + ": %s (%s %s)\n\n%s\n\n"
2928
    sRet.Format(GetResString(IDS_DL_FILENAME) + ": %s (%s %s)\n\n%s\n\n"
2576
    + GetResString(IDS_FD_HASH) + " %s\n"
2929
    + GetResString(IDS_FD_HASH) + " %s\n"
Lines 2579-2585 Link Here
2579
    GetFileName(), CastItoXBytes(GetFileSize()) .GetData(), GetResString(IDS_BYTES) .GetData(),
2932
    GetFileName(), CastItoXBytes(GetFileSize()) .GetData(), GetResString(IDS_BYTES) .GetData(),
2580
    (GetResString(IDS_STATUS) + ": " + getPartfileStatus()) .GetData(),
2933
    (GetResString(IDS_STATUS) + ": " + getPartfileStatus()) .GetData(),
2581
    strHash.GetData(),
2934
    strHash.GetData(),
2582
    GetPartMetFileName(), GetPartCount(), GetResString(IDS_AVAIL) .GetData(),
2935
    GetPartMetFileName() .GetData(), GetPartCount(), GetResString(IDS_AVAIL) .GetData(),
2583
    GetAvailablePartCount(), availability,
2936
    GetAvailablePartCount(), availability,
2584
    (int) GetPercentCompleted(), complx, GetTransferingSrcCount(),
2937
    (int) GetPercentCompleted(), complx, GetTransferingSrcCount(),
2585
    (GetResString(IDS_LASTSEENCOMPL) + " " + wxString(lsc)) .GetData(),
2938
    (GetResString(IDS_LASTSEENCOMPL) + " " + wxString(lsc)) .GetData(),
Lines 2587-2593 Link Here
2587
    return sRet;
2940
    return sRet;
2588
}
2941
}
2589
2942
2590
wxString CPartFile:: GetProgressString(uint16 size)
2943
wxString CPartFile::GetProgressString(uint16 size)
2591
{
2944
{
2592
    //green:
2945
    //green:
2593
    char crProgress = '0';
2946
    char crProgress = '0';
Lines 2611-2645 Link Here
2611
    uint32 allgaps = 0;
2964
    uint32 allgaps = 0;
2612
    if (GetStatus() == PS_COMPLETE || GetStatus() == PS_COMPLETING)
2965
    if (GetStatus() == PS_COMPLETE || GetStatus() == PS_COMPLETING)
2613
    {
2966
    {
2614
        CharFillRange( &my_ChunkBar, 0, (float) m_nFileSize *unit, crProgress);
2967
        CharFillRange( & my_ChunkBar, 0, (float) m_nFileSize * unit, crProgress);
2615
    }
2968
    }
2616
    else
2969
    else
2617
    {
2970
    {
2618
        // red gaps
2971
        // red gaps
2619
        for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
2972
        for (POSITION pos = gaplist.GetHeadPosition() ; pos != 0 ; gaplist.GetNext(pos))
2620
        {
2973
        {
2621
            Gap_Struct *cur_gap = gaplist.GetAt(pos);
2974
            Gap_Struct * cur_gap = gaplist.GetAt(pos);
2622
            allgaps += cur_gap -> end - cur_gap -> start;
2975
            allgaps += cur_gap -> end - cur_gap -> start;
2623
            bool gapdone = false;
2976
            bool gapdone = false;
2624
            uint32 gapstart = cur_gap -> start;
2977
            uint32 gapstart = cur_gap -> start;
2625
            uint32 gapend = cur_gap -> end;
2978
            uint32 gapend = cur_gap -> end;
2626
            for (uint32 i = 0 ; i < GetPartCount() ; i++)
2979
            for (uint32 i = 0 ; i < GetPartCount() ; i++)
2627
            {
2980
            {
2628
                if (gapstart >= i *PARTSIZE &&gapstart <= (i + 1) *PARTSIZE)
2981
                if (gapstart >= i * PARTSIZE && gapstart <= (i + 1) * PARTSIZE)
2629
                {
2982
                {
2630
                    // is in this part?
2983
                    // is in this part?
2631
                    if (gapend <= (i + 1) *PARTSIZE)
2984
                    if (gapend <= (i + 1) * PARTSIZE)
2632
                    {
2985
                    {
2633
                        gapdone = true;
2986
                        gapdone = true;
2634
                    }
2987
                    }
2635
                    else
2988
                    else
2636
                    {
2989
                    {
2637
                        // and next part:
2990
                        // and next part:
2638
                        gapend = (i + 1) *PARTSIZE;
2991
                        gapend = (i + 1) * PARTSIZE;
2639
                    }
2992
                    }
2640
                    // paint
2993
                    // paint
2641
                    uint8 color;
2994
                    uint8 color;
2642
                    if (m_SrcpartFrequency.GetCount() >= (int) i &&m_SrcpartFrequency[i])
2995
                    if (m_SrcpartFrequency.GetCount() >= (int) i && m_SrcpartFrequency[i])
2643
                    {
2996
                    {
2644
                        // frequency?
2997
                        // frequency?
2645
                        color = crWaiting;
2998
                        color = crWaiting;
Lines 2648-2654 Link Here
2648
                    {
3001
                    {
2649
                        color = crMissing;
3002
                        color = crMissing;
2650
                    }
3003
                    }
2651
                    CharFillRange( &my_ChunkBar, (float) gapstart *unit, (float) gapend *unit + 1, color);
3004
                    CharFillRange( & my_ChunkBar, (float) gapstart * unit, (float) gapend * unit + 1, color);
2652
                    if (gapdone)
3005
                    if (gapdone)
2653
                    {
3006
                    {
2654
                        // finished?
3007
                        // finished?
Lines 2666-2678 Link Here
2666
    // yellow pending parts
3019
    // yellow pending parts
2667
    for (POSITION pos = requestedblocks_list.GetHeadPosition() ; pos != 0 ; requestedblocks_list.GetNext(pos))
3020
    for (POSITION pos = requestedblocks_list.GetHeadPosition() ; pos != 0 ; requestedblocks_list.GetNext(pos))
2668
    {
3021
    {
2669
        Requested_Block_Struct *block = requestedblocks_list.GetAt(pos);
3022
        Requested_Block_Struct * block = requestedblocks_list.GetAt(pos);
2670
        CharFillRange( &my_ChunkBar, (float)(block -> StartOffset + block -> transferred) *unit, (float) block -> EndOffset *unit, crPending);
3023
        CharFillRange( & my_ChunkBar, (float)(block -> StartOffset + block -> transferred) * unit, (float) block -> EndOffset * unit, crPending);
2671
    }
3024
    }
2672
    return my_ChunkBar;
3025
    return my_ChunkBar;
2673
}
3026
}
2674
3027
2675
void CPartFile:: CharFillRange(wxString *buffer, float start, float end, char color)
3028
void CPartFile::CharFillRange(wxString * buffer, float start, float end, char color)
2676
{
3029
{
2677
    for (uint32 i = (uint32) start ; i <= (uint32) end ; i++)
3030
    for (uint32 i = (uint32) start ; i <= (uint32) end ; i++)
2678
    {
3031
    {
Lines 2683-2701 Link Here
2683
 /* Razor 1a - Modif by MikaelB
3036
 /* Razor 1a - Modif by MikaelB
2684
    RemoveNoNeededSources function */
3037
    RemoveNoNeededSources function */
2685
3038
2686
void CPartFile:: RemoveNoNeededSources()
3039
void CPartFile::RemoveNoNeededSources()
2687
{
3040
{
2688
    POSITION position, temp_position;
3041
    POSITION position, temp_position;
2689
    for (int slot = 0 ; slot < SOURCESSLOTS ; slot++)
3042
    for (int slot = 0 ; slot < SOURCESSLOTS ; slot++)
2690
    {
3043
    {
2691
        if (! srclists[slot].IsEmpty())
3044
        if (!srclists[slot].IsEmpty())
2692
        {
3045
        {
2693
            position = srclists[slot].GetHeadPosition();
3046
            position = srclists[slot].GetHeadPosition();
2694
            while (position != NULL)
3047
            while (position != NULL)
2695
            {
3048
            {
2696
                temp_position = position;
3049
                temp_position = position;
2697
                srclists[slot].GetNext(position);
3050
                srclists[slot].GetNext(position);
2698
                CUpDownClient *client = srclists[slot].GetAt(temp_position);
3051
                CUpDownClient * client = srclists[slot].GetAt(temp_position);
2699
                if (client -> GetDownloadState() == DS_NONEEDEDPARTS)
3052
                if (client -> GetDownloadState() == DS_NONEEDEDPARTS)
2700
                {
3053
                {
2701
    /* If allowed, try to swap to other file. If swapping fails, remove from this one. */
3054
    /* If allowed, try to swap to other file. If swapping fails, remove from this one. */
Lines 2722-2740 Link Here
2722
 /* Razor 1a - Modif by MikaelB
3075
 /* Razor 1a - Modif by MikaelB
2723
    RemoveFullQueueSources function */
3076
    RemoveFullQueueSources function */
2724
3077
2725
void CPartFile:: RemoveFullQueueSources()
3078
void CPartFile::RemoveFullQueueSources()
2726
{
3079
{
2727
    POSITION position, temp_position;
3080
    POSITION position, temp_position;
2728
    for (int slot = 0 ; slot < SOURCESSLOTS ; slot++)
3081
    for (int slot = 0 ; slot < SOURCESSLOTS ; slot++)
2729
    {
3082
    {
2730
        if (! srclists[slot].IsEmpty())
3083
        if (!srclists[slot].IsEmpty())
2731
        {
3084
        {
2732
            position = srclists[slot].GetHeadPosition();
3085
            position = srclists[slot].GetHeadPosition();
2733
            while (position != NULL)
3086
            while (position != NULL)
2734
            {
3087
            {
2735
                temp_position = position;
3088
                temp_position = position;
2736
                srclists[slot].GetNext(position);
3089
                srclists[slot].GetNext(position);
2737
                CUpDownClient *client = srclists[slot].GetAt(temp_position);
3090
                CUpDownClient * client = srclists[slot].GetAt(temp_position);
2738
                if ((client -> GetDownloadState() == DS_ONQUEUE) && (client -> IsRemoteQueueFull()))
3091
                if ((client -> GetDownloadState() == DS_ONQUEUE) && (client -> IsRemoteQueueFull()))
2739
                {
3092
                {
2740
                    theApp.downloadqueue -> RemoveSourceFromPartFile(this, client, temp_position);
3093
                    theApp.downloadqueue -> RemoveSourceFromPartFile(this, client, temp_position);
Lines 2749-2767 Link Here
2749
 /* Razor 1a - Modif by MikaelB
3102
 /* Razor 1a - Modif by MikaelB
2750
    RemoveHighQueueRatingSources function */
3103
    RemoveHighQueueRatingSources function */
2751
3104
2752
void CPartFile:: RemoveHighQueueRatingSources()
3105
void CPartFile::RemoveHighQueueRatingSources()
2753
{
3106
{
2754
    POSITION position, temp_position;
3107
    POSITION position, temp_position;
2755
    for (int slot = 0 ; slot < SOURCESSLOTS ; slot++)
3108
    for (int slot = 0 ; slot < SOURCESSLOTS ; slot++)
2756
    {
3109
    {
2757
        if (! srclists[slot].IsEmpty())
3110
        if (!srclists[slot].IsEmpty())
2758
        {
3111
        {
2759
            position = srclists[slot].GetHeadPosition();
3112
            position = srclists[slot].GetHeadPosition();
2760
            while (position != NULL)
3113
            while (position != NULL)
2761
            {
3114
            {
2762
                temp_position = position;
3115
                temp_position = position;
2763
                srclists[slot].GetNext(position);
3116
                srclists[slot].GetNext(position);
2764
                CUpDownClient *client = srclists[slot].GetAt(temp_position);
3117
                CUpDownClient * client = srclists[slot].GetAt(temp_position);
2765
                if ((client -> GetDownloadState() == DS_ONQUEUE) && (client -> GetRemoteQueueRank() > theApp.glob_prefs -> HighQueueRanking()))
3118
                if ((client -> GetDownloadState() == DS_ONQUEUE) && (client -> GetRemoteQueueRank() > theApp.glob_prefs -> HighQueueRanking()))
2766
                {
3119
                {
2767
                    theApp.downloadqueue -> RemoveSourceFromPartFile(this, client, temp_position);
3120
                    theApp.downloadqueue -> RemoveSourceFromPartFile(this, client, temp_position);
Lines 2776-2797 Link Here
2776
 /* Razor 1a - Modif by MikaelB
3129
 /* Razor 1a - Modif by MikaelB
2777
    CleanUpSources function */
3130
    CleanUpSources function */
2778
3131
2779
void CPartFile:: CleanUpSources()
3132
void CPartFile::CleanUpSources()
2780
{
3133
{
2781
    POSITION position, temp_position;
3134
    POSITION position, temp_position;
2782
    for (int slot = 0 ; slot < SOURCESSLOTS ; slot++)
3135
    for (int slot = 0 ; slot < SOURCESSLOTS ; slot++)
2783
    {
3136
    {
2784
        if (! srclists[slot].IsEmpty())
3137
        if (!srclists[slot].IsEmpty())
2785
        {
3138
        {
2786
            position = srclists[slot].GetHeadPosition();
3139
            position = srclists[slot].GetHeadPosition();
2787
            while (position != NULL)
3140
            while (position != NULL)
2788
            {
3141
            {
2789
                temp_position = position;
3142
                temp_position = position;
2790
                srclists[slot].GetNext(position);
3143
                srclists[slot].GetNext(position);
2791
                CUpDownClient *client = srclists[slot].GetAt(temp_position);
3144
                CUpDownClient * client = srclists[slot].GetAt(temp_position);
2792
                if (client -> GetDownloadState() == DS_NONEEDEDPARTS)
3145
                if (client -> GetDownloadState() == DS_NONEEDEDPARTS)
2793
                {
3146
                {
2794
                    if ((theApp.glob_prefs -> DropNoNeededSources()) && (! client -> SwapToAnotherFile()))
3147
                    if ((theApp.glob_prefs -> DropNoNeededSources()) && (!client -> SwapToAnotherFile()))
2795
                    {
3148
                    {
2796
                        theApp.downloadqueue -> RemoveSourceFromPartFile(this, client, temp_position);
3149
                        theApp.downloadqueue -> RemoveSourceFromPartFile(this, client, temp_position);
2797
                    }
3150
                    }
Lines 2814-2820 Link Here
2814
 /* Razor 1a - Modif by MikaelB
3167
 /* Razor 1a - Modif by MikaelB
2815
    AddDownloadingSource function */
3168
    AddDownloadingSource function */
2816
3169
2817
void CPartFile:: AddDownloadingSource(CUpDownClient *client)
3170
void CPartFile::AddDownloadingSource(CUpDownClient * client)
2818
{
3171
{
2819
    POSITION position = m_downloadingSourcesList.Find(client);
3172
    POSITION position = m_downloadingSourcesList.Find(client);
2820
    if (position == NULL)
3173
    if (position == NULL)
Lines 2828-2834 Link Here
2828
 /* Razor 1a - Modif by MikaelB
3181
 /* Razor 1a - Modif by MikaelB
2829
    RemoveDownloadingSource function */
3182
    RemoveDownloadingSource function */
2830
3183
2831
void CPartFile:: RemoveDownloadingSource(CUpDownClient *client)
3184
void CPartFile::RemoveDownloadingSource(CUpDownClient * client)
2832
{
3185
{
2833
    POSITION position = m_downloadingSourcesList.Find(client);
3186
    POSITION position = m_downloadingSourcesList.Find(client);
2834
    if (position != NULL)
3187
    if (position != NULL)
Lines 2839-2845 Link Here
2839
3192
2840
    /* End modif */
3193
    /* End modif */
2841
3194
2842
void CPartFile:: SetPartFileStatus(uint8 newstatus)
3195
void CPartFile::SetPartFileStatus(uint8 newstatus)
2843
{
3196
{
2844
    status = newstatus;
3197
    status = newstatus;
2845
    if (theApp.glob_prefs -> GetAllcatType() > 1)
3198
    if (theApp.glob_prefs -> GetAllcatType() > 1)
(-)xmule/src/PartFile.h (-9 / +36 lines)
Lines 33-43 Link Here
33
#include "wx/treectrl.h"
33
#include "wx/treectrl.h"
34
#include "otherfunctions.h"
34
#include "otherfunctions.h"
35
35
36
#define	PARTSIZE			9728000
37
36
#define	PS_READY			0
38
#define	PS_READY			0
37
#define	PS_EMPTY			1
39
#define	PS_EMPTY			1
38
#define PS_WAITINGFORHASH	2
40
#define PS_WAITINGFORHASH	2
39
#define PS_HASHING			3
41
#define PS_HASHING			3
40
#define PS_ERROR			4
42
#define PS_ERROR			4
43
#define PS_CONVERTING			5
41
#define	PS_UNKNOWN			6
44
#define	PS_UNKNOWN			6
42
#define PS_PAUSED			7
45
#define PS_PAUSED			7
43
#define PS_COMPLETING		8
46
#define PS_COMPLETING		8
Lines 49-54 Link Here
49
#define	PR_HIGH				2 //*
52
#define	PR_HIGH				2 //*
50
#define PR_VERYHIGH			3
53
#define PR_VERYHIGH			3
51
#define PR_AUTO				5
54
#define PR_AUTO				5
55
56
#define PMT_UNKNOWN			0
57
#define PMT_DEFAULTOLD			1
58
#define PMT_SPLITTED			2
59
#define PMT_NEWOLD			3
60
52
#define SRV_PR_LOW			2
61
#define SRV_PR_LOW			2
53
#define SRV_PR_NORMAL		0
62
#define SRV_PR_NORMAL		0
54
#define SRV_PR_HIGH			1
63
#define SRV_PR_HIGH			1
Lines 71-89 Link Here
71
public:
80
public:
72
	CPartFile();
81
	CPartFile();
73
	CPartFile(CSearchFile* searchresult);  //used when downloading a new file
82
	CPartFile(CSearchFile* searchresult);  //used when downloading a new file
74
	CPartFile(CString edonkeylink);
83
	CPartFile(wxString edonkeylink);
75
	CPartFile(class CED2KFileLink* fileLink);
84
	CPartFile(class CED2KFileLink* fileLink);
76
	void InitializeFromLink(CED2KFileLink* fileLink);
85
	void InitializeFromLink(CED2KFileLink* fileLink);
77
	virtual ~CPartFile();
86
	virtual ~CPartFile();
78
	
87
	
79
	void 	SetPartFileStatus(uint8 newstatus);
88
	void 	SetPartFileStatus(uint8 newstatus);
80
	bool	CreateFromFile(char* directory,char* filename)	{return false;}// not supported in this class
81
	bool	LoadFromFile(FILE* file)						{return false;}
89
	bool	LoadFromFile(FILE* file)						{return false;}
82
	bool	WriteToFile(FILE* file)							{return false;}
90
	bool	WriteToFile(FILE* file)							{return false;}
83
	bool	IsPartFile()									{return !(status == PS_COMPLETE);}
91
	bool	IsPartFile()									{return !(status == PS_COMPLETE);}
84
	uint32	Process(uint32 reducedownload);
92
	uint32	Process(uint32 reducedownload);
85
	bool	LoadPartFile(char* in_directory, char* filename); //filename = *.part.met
93
	bool	LoadPartFile(int type,char* in_directory, char* filename); //filename = *.part.met
86
	bool	SavePartFile(bool Initial=false);
94
	bool	SavePartFile(bool Initial=false);
95
	void	Close();
96
 	void	CreateHash(wxUint32 Length,unsigned char *Output);
97
	void	Duplicate();
98
	void	Seek(unsigned long filepos);
99
	long	Read(void *buffer,long bytes);
100
	bool	Store(const wxString &newname);
101
	long	Write(void *buffer,long bytes);
102
	unsigned long	Length();
87
	void	PartFileHashFinished(CKnownFile* result);
103
	void	PartFileHashFinished(CKnownFile* result);
88
	bool	HashSinglePart(uint16 partnumber); // true = ok , false = corrupted	
104
	bool	HashSinglePart(uint16 partnumber); // true = ok , false = corrupted	
89
105
Lines 101-107 Link Here
101
	void	AddSources(CMemFile* sources,uint32 serverip, uint16 serverport);
117
	void	AddSources(CMemFile* sources,uint32 serverip, uint16 serverport);
102
	uint8	GetStatus(bool ignorepause = false);
118
	uint8	GetStatus(bool ignorepause = false);
103
	void	NewSrcPartsInfo();
119
	void	NewSrcPartsInfo();
104
	char*	GetPartMetFileName()							{return partmetfilename;}
120
	wxString	GetPartMetFileName()			{return partmetfilename;}
105
	uint32	GetTransfered()									{return transfered;}
121
	uint32	GetTransfered()									{return transfered;}
106
	char*	GetFullName()									{return fullname;}
122
	char*	GetFullName()									{return fullname;}
107
	uint16	GetSourceCount();
123
	uint16	GetSourceCount();
Lines 118-128 Link Here
118
	bool 	IsText();
134
	bool 	IsText();
119
	
135
	
120
	
136
	
121
	CString CPartFile::getPartfileStatus(); //<<--9/21/02
137
	long 	m_nHeaderLength;
138
	int	m_nDynBloCount;
139
	wxString CPartFile::getPartfileStatus(); //<<--9/21/02
122
	sint32	CPartFile::getTimeRemaining(); //<<--9/21/02
140
	sint32	CPartFile::getTimeRemaining(); //<<--9/21/02
123
	time_t	lastseencomplete;
141
	time_t	lastseencomplete;
124
	int		getPartfileStatusRang();
142
	int		getPartfileStatusRang();
125
        CString GetDownloadFileInfo();
143
        wxString GetDownloadFileInfo();
126
144
127
	// Barry - Added as replacement for BlockReceived to buffer data before writing to disk
145
	// Barry - Added as replacement for BlockReceived to buffer data before writing to disk
128
	uint32	WriteToBuffer(uint32 transize, BYTE *data, uint32 start, uint32 end, Requested_Block_Struct *block);
146
	uint32	WriteToBuffer(uint32 transize, BYTE *data, uint32 start, uint32 end, Requested_Block_Struct *block);
Lines 138-148 Link Here
138
	void	RemoveAllRequestedBlocks(void);
156
	void	RemoveAllRequestedBlocks(void);
139
157
140
	void	RemoveBlockFromList(uint32 start,uint32 end);
158
	void	RemoveBlockFromList(uint32 start,uint32 end);
141
	void	RemoveAllSources(bool bTryToSwap);
159
	void	RemoveAllSources(int fx,bool bTryToSwap);
142
	void	DeleteFile();
160
	void	DeleteFile();
143
	void	StopFile();
161
	void	StopFile(int fx);
144
	void	PauseFile();
162
	void	PauseFile();
145
	void	ResumeFile();
163
	void	ResumeFile();
164
	void	EnableConvert(uint8 targettype) { convertstate=targettype; }
146
165
147
	virtual	Packet* CreateSrcInfoPacket(CUpDownClient* forClient);
166
	virtual	Packet* CreateSrcInfoPacket(CUpDownClient* forClient);
148
	void	AddClientSources(CMemFile* sources,uint8 sourceexchangeversion);
167
	void	AddClientSources(CMemFile* sources,uint8 sourceexchangeversion);
Lines 162-170 Link Here
162
	bool	IsStopped() 				{return stopped;}
181
	bool	IsStopped() 				{return stopped;}
163
	bool	HasComment()				{return hasComment;}
182
	bool	HasComment()				{return hasComment;}
164
	bool	HasRating()				{return hasRating;}
183
	bool	HasRating()				{return hasRating;}
184
	int	IsDynamic()				{return m_isDynamic;}
165
	bool	HasBadRating();
185
	bool	HasBadRating();
166
	void	SetHasComment(bool in)			{hasComment=in;}
186
	void	SetHasComment(bool in)			{hasComment=in;}
167
	void	SetHasRating(bool in)			{hasRating=in;}
187
	void	SetHasRating(bool in)			{hasRating=in;}
188
	void	SetIsDynamic(int in)			{m_isDynamic=in;}
168
	void	UpdateFileRatingCommentAvail();
189
	void	UpdateFileRatingCommentAvail();
169
190
170
        wxString GetProgressString(uint16 size);
191
        wxString GetProgressString(uint16 size);
Lines 196-211 Link Here
196
	uint16	count;
217
	uint16	count;
197
	uint16	transferingsrc;
218
	uint16	transferingsrc;
198
	uint32  completedsize;
219
	uint32  completedsize;
220
	uint32	m_ilength;
199
	uint64	m_iLostDueToCorruption;
221
	uint64	m_iLostDueToCorruption;
200
	uint64	m_iGainDueToCompression;
222
	uint64	m_iGainDueToCompression;
201
	uint32  m_iTotalPacketsSavedDueToICH;
223
	uint32  m_iTotalPacketsSavedDueToICH;
202
	uint32	datarate;
224
	uint32	datarate;
203
	char*	fullname;
225
	char*	fullname;
204
	char*	partmetfilename;
226
	wxString  partmetfilename;
205
	uint32	transfered;
227
	uint32	transfered;
228
	bool	isnewstyle;
229
	uint8	partmettype;
230
	uint8	convertstate;
206
	bool	paused;
231
	bool	paused;
207
	bool	stopped;
232
	bool	stopped;
208
        bool    m_DisableXS;                  // Flag for SourceSharing
233
        bool    m_DisableXS;                  // Flag for SourceSharing
234
	int	m_isDynamic;
209
	uint8	m_iDownPriority;
235
	uint8	m_iDownPriority;
210
	bool	m_bAutoDownPriority;
236
	bool	m_bAutoDownPriority;
211
	uint8	status;
237
	uint8	status;
Lines 226-231 Link Here
226
	static	CBarShader s_ChunkBar; 
252
	static	CBarShader s_ChunkBar; 
227
	bool	hasRating;
253
	bool	hasRating;
228
	bool	hasComment;
254
	bool	hasComment;
255
	long	m_hfilepos;
229
	BOOL 	PerformFileComplete(); // Lord KiRon
256
	BOOL 	PerformFileComplete(); // Lord KiRon
230
	static UINT CompleteThreadProc(CPartFile* pFile); // Lord KiRon - Used as separate thread to complete file
257
	static UINT CompleteThreadProc(CPartFile* pFile); // Lord KiRon - Used as separate thread to complete file
231
	void    CharFillRange(wxString* buffer,float start, float end, char color);
258
	void    CharFillRange(wxString* buffer,float start, float end, char color);
(-)xmule/src/Preferences.cpp (-113 / +139 lines)
Lines 41-46 Link Here
41
#else
41
#else
42
#	include "wintypes.h"
42
#	include "wintypes.h"
43
#	include "Preferences.h"
43
#	include "Preferences.h"
44
#	include "FlowChart.h"
45
#	include "NewFunctions.h"
44
#	include "opcodes.h"
46
#	include "opcodes.h"
45
#	include "otherfunctions.h"
47
#	include "otherfunctions.h"
46
#	include "ini2.h"
48
#	include "ini2.h"
Lines 71-112 Link Here
71
#endif
73
#endif
72
74
73
#ifdef __FreeBSD__
75
#ifdef __FreeBSD__
74
extern long long atoll(char *s);
76
extern long long atoll(char * s);
75
#endif /* __FreeBSD__ */
77
#endif /* __FreeBSD__ */
76
78
79
extern wxString newprefs01_alpha[];
77
80
78
81
CPreferences::CPreferences()
79
CPreferences:: CPreferences()
80
{
82
{
81
    // we need random numbers sometimes:
83
    // we need random numbers sometimes:
82
    srand((uint32) time(0));
84
    srand((uint32) time(0));
83
    // Define prefs 
85
    // Define prefs 
84
    prefs = new Preferences_Struct;
86
    prefs = new Preferences_Struct;
85
    memset(prefs, 0, sizeof(Preferences_Struct));
87
    memset(prefs, 0, sizeof(Preferences_Struct));
86
    prefsExt = new Preferences_Ext_Struct;
87
    memset(prefsExt, 0, sizeof(Preferences_Ext_Struct));
88
    // Use home directory to save preferences
88
    // Use home directory to save preferences
89
    char buffer[490];
89
    char buffer[490];
90
    snprintf(buffer, 400, "%s/." PACKAGE_NAME, getenv("HOME"));
90
    snprintf(buffer, 400, "%s/." PACKAGE_NAME, getenv("HOME"));
91
    mkdir(buffer, 0777);
91
    mkdir(buffer, 0777);
92
    strncat(buffer, "/", 1);
92
    strncat(buffer, "/", 1);
93
    SetAppDir(nstrdup(buffer)); 
93
    SetAppDir(nstrdup(buffer)); 
94
    // Create UserHash
94
    if(newprefs01_opt[7]) {
95
    CreateUserHash();
95
	newprefs01_alpha[7]="";
96
    md4cpy( &prefs->userhash, &userhash);
97
   if (((int *) prefs -> userhash) [0] == 0 && ((int *) prefs -> userhash) [1] == 0 && ((int *) prefs -> userhash) [2] == 0 && ((int *) prefs -> userhash) [3] == 0)
98
    {
99
       CreateUserHash();
100
    }
96
    }
101
    // Load Preferences
97
    CreateUserHash();
98
    md4cpy( & prefs -> userhash, & userhash);
102
    Load(true);
99
    Load(true);
103
    // ???
104
    prefs -> m_bUseSecureIdent = true;
100
    prefs -> m_bUseSecureIdent = true;
105
}
101
}
106
102
107
CPreferences:: ~CPreferences()
103
CPreferences::~ CPreferences()
108
{
104
{
109
    Category_Struct *delcat;
105
    Category_Struct * delcat;
110
    while (!catMap.IsEmpty())
106
    while (!catMap.IsEmpty())
111
    {
107
    {
112
        delcat = catMap.GetAt(0);
108
        delcat = catMap.GetAt(0);
Lines 114-128 Link Here
114
        delete delcat;
110
        delete delcat;
115
    }
111
    }
116
    delete prefs;
112
    delete prefs;
117
    delete prefsExt;
118
}
113
}
119
114
120
115
void CPreferences::SetStandartValues()
121
void CPreferences:: SetStandartValues()
122
{
116
{
123
    wxString buffer;
117
    wxString buffer;
118
    newprefs01_alpha[7]="";
124
    CreateUserHash();
119
    CreateUserHash();
125
    md4cpy( &prefs -> userhash, &userhash);
120
    md4cpy( & prefs -> userhash, & userhash);
126
    WINDOWPLACEMENT defaultWPM;
121
    WINDOWPLACEMENT defaultWPM;
127
    defaultWPM.length = sizeof(WINDOWPLACEMENT);
122
    defaultWPM.length = sizeof(WINDOWPLACEMENT);
128
    defaultWPM.rcNormalPosition.left = 10;
123
    defaultWPM.rcNormalPosition.left = 10;
Lines 134-149 Link Here
134
    prefs -> versioncheckLastAutomatic = 0;
129
    prefs -> versioncheckLastAutomatic = 0;
135
}
130
}
136
131
137
bool CPreferences:: Load(bool startup)
132
bool CPreferences::Load(bool startup)
138
{
133
{
139
    bool error = false;
134
    bool error = false;
140
    if(LoadPreferences())
135
    if (LoadPreferences())
141
    {
136
    {
142
        if(startup)
137
        if (startup)
143
	{
138
	{
144
	    //Can't find Preferences file, but in LoadPreferences() the standard was defined. Now we have to save it.
139
	    //Can't find Preferences file, but in LoadPreferences() the standard was defined. Now we have to save it.
145
            SetStandartValues(); 
140
            SetStandartValues(); 
146
            if(Save(1)) 
141
            if (Save(1))
147
	    {
142
	    {
148
                error = true;
143
                error = true;
149
            }
144
            }
Lines 156-203 Link Here
156
    }
151
    }
157
    if (startup)
152
    if (startup)
158
    {
153
    {
159
         if(LoadCats())
154
        if (LoadCats())
160
         {
155
         {
161
             //Catfile don't exist, let's create one
156
             //Catfile don't exist, let's create one
162
             if(Save(2))
157
            if (Save(2))
163
	     {
158
	     {
164
	       error = true;
159
	       error = true;
165
             }
160
             }
166
         }
161
         }
167
         if(Load_Shared_Dirs())
162
        if (Load_Shared_Dirs())
168
         {
163
                    {;
169
	     ; //Maybe the User has not shared dirs 
164
            //Maybe the User has not shared dirs
170
         }
165
        }
171
          if(Load_Adresses())
166
        if (Load_Adresses())
172
         {
167
                    {;
173
	     ; //And also no Adresslist
168
            //And also no Adresslist
174
         }
169
         }
175
    }
170
    }
176
    return error;
171
    return error;
177
}
172
}
178
173
179
bool CPreferences:: Save(unsigned char selection_mask)
174
bool CPreferences::Save(unsigned char selection_mask)
180
{
175
{
181
    bool error = false;
176
    bool error = false;
182
    if (selection_mask &1)
177
    if (selection_mask & 1)
183
    {
178
    {
184
      SavePreferences();
179
      SavePreferences();
185
    }
180
    }
186
    if (selection_mask &2)
181
    if (selection_mask & 2)
187
    {
182
    {
188
       if (SaveCats())
183
       if (SaveCats())
189
       {
184
       {
190
           error = true;
185
           error = true;
191
       }
186
       }
192
    }
187
    }
193
    if (selection_mask &4)
188
    if (selection_mask & 4)
194
    {
189
    {
195
       if (Save_Shared_Dirs())
190
       if (Save_Shared_Dirs())
196
       { 
191
       { 
197
           error = true;
192
           error = true;
198
       }
193
       }
199
    }
194
    }
200
    if (selection_mask &8)
195
    if (selection_mask & 8)
201
    {
196
    {
202
       if (Save_Adresses())
197
       if (Save_Adresses())
203
       {
198
       {
Lines 207-227 Link Here
207
    return error;
202
    return error;
208
}
203
}
209
204
210
void CPreferences:: CreateUserHash()
205
void CPreferences::CreateUserHash()
211
{
206
{
207
    if (newprefs01_alpha[7].Len() != 32)
208
    {
212
    for (int i = 0 ; i != 8 ; i++)
209
    for (int i = 0 ; i != 8 ; i++)
213
    {
210
    {
214
        uint16 random = rand();
211
        uint16 random = rand();
215
        memcpy( &userhash[i*2], &random, 2);
212
            memcpy( & userhash[i * 2], & random, 2);
216
    }
213
    }
217
    // mark as emule client. that will be need in later version
214
    // mark as emule client. that will be need in later version
218
    userhash[5] = 14;
215
    userhash[5] = 14;
219
    userhash[14] = 111;
216
    userhash[14] = 111;
217
        newprefs01_alpha[7] ="";
218
        for (int i = 0 ; i < 16 ; i++)
219
        {
220
            newprefs01_alpha[7] += wxString:: Format("%02x", (unsigned char) userhash[i]);
221
        }
222
    }
223
    else
224
    {
225
	unsigned char c;
226
        for (int i = 0 ; i < 32 ; i++)
227
        {
228
            c =((unsigned char*)(const char *) newprefs01_alpha[7])[i];
229
            if (c >= '0' && c <= '9')
230
            {
231
                c -= '0';
232
            }
233
            else if(c >= 'a' && c <= 'f')
234
            {
235
                c -= 'a' - 10;
236
            }
237
            else if(c >= 'A' && c <= 'F')
238
            {
239
                c -='A' - 10;
240
            }
241
            if (i&1)
242
            {
243
                userhash[i>>1] = (userhash[i>>1] << 4) | c;
244
            }
245
            else
246
            {
247
                userhash[i>>1] = c;
248
            }
249
        }
250
    }
220
}
251
}
221
252
222
int CPreferences:: GetRecommendedMaxConnections()
253
int CPreferences::GetRecommendedMaxConnections()
223
{
254
{
224
    int iRealMax =:: GetMaxConnections();
255
    int iRealMax =::GetMaxConnections();
225
    if (iRealMax == - 1 || iRealMax > 520)
256
    if (iRealMax == - 1 || iRealMax > 520)
226
    return 500;
257
    return 500;
227
    if (iRealMax < 20)
258
    if (iRealMax < 20)
Lines 231-237 Link Here
231
    return iRealMax - 20;
262
    return iRealMax - 20;
232
}
263
}
233
264
234
WORD CPreferences:: GetWindowsVersion()
265
WORD CPreferences::GetWindowsVersion()
235
{
266
{
236
    static bool bWinVerAlreadyDetected = false;
267
    static bool bWinVerAlreadyDetected = false;
237
    if (!bWinVerAlreadyDetected)
268
    if (!bWinVerAlreadyDetected)
Lines 242-254 Link Here
242
    return m_wWinVer;
273
    return m_wWinVer;
243
}
274
}
244
275
245
uint16 CPreferences:: GetDefaultMaxConperFive()
276
uint16 CPreferences::GetDefaultMaxConperFive()
246
{
277
{
247
    return MAXCONPER5SEC;
278
    return MAXCONPER5SEC;
248
}
279
}
249
280
250
281
void CPreferences::ResetStatsColor(int index)
251
void CPreferences:: ResetStatsColor(int index)
252
{
282
{
253
    switch (index)
283
    switch (index)
254
    {
284
    {
Lines 272-292 Link Here
272
            break;
302
            break;
273
    case 9: prefs -> statcolors[9] = RGB(192, 0, 192);
303
    case 9: prefs -> statcolors[9] = RGB(192, 0, 192);
274
            break;
304
            break;
275
    case 10:prefs -> statcolors[10] = RGB(255, 255, 128);
305
    case 10: prefs -> statcolors[10] = RGB(255, 255, 128);
276
            break;
306
            break;
277
    case 11:prefs -> statcolors[11] = RGB(0, 0, 0);
307
    case 11: prefs -> statcolors[11] = RGB(0, 0, 0);
278
            break;
308
            break;
279
    case 12:prefs -> statcolors[12] = RGB(255, 255, 255);
309
    case 12: prefs -> statcolors[12] = RGB(255, 255, 255);
280
            break;
310
            break;
281
    default:break;
311
    default: break;
282
    }
312
    }
283
}
313
}
284
314
285
void CPreferences:: SavePreferences(void)
315
void CPreferences::SavePreferences(void)
286
{
316
{
287
    CString buffer;
317
    CString buffer;
288
    CString buffer2;
318
    CString buffer2;
289
    char *full_path = new char[strlen(getenv("HOME")) + 2];
319
    char * full_path = new char[strlen(getenv("HOME")) + 2];
290
    sprintf(full_path, "%s/", getenv("HOME"));
320
    sprintf(full_path, "%s/", getenv("HOME"));
291
    CIni ini(full_path, "eMule");
321
    CIni ini(full_path, "eMule");
292
    ini.WriteString("AppVersion", PACKAGE_STRING);
322
    ini.WriteString("AppVersion", PACKAGE_STRING);
Lines 468-485 Link Here
468
    ini.WriteInt("AutoDropTimer", prefs -> AutoDropTimer);
498
    ini.WriteInt("AutoDropTimer", prefs -> AutoDropTimer);
469
}
499
}
470
500
471
bool CPreferences:: LoadPreferences(void)
501
bool CPreferences::LoadPreferences(void)
472
{
502
{
473
    bool error = false;
503
    bool error = false;
474
    bool NoColor = true;    
504
    bool NoColor = true;    
475
    CString buffer2;
505
    CString buffer2;
476
    char buffer[200];
506
    char buffer[200];
477
    //Open File for Test
507
    //Open File for Test
478
    char *full_path = new char[strlen(getenv("HOME")) + 2];
508
    char * full_path = new char[strlen(getenv("HOME")) + 2];
479
    sprintf(full_path, "%s/", getenv("HOME"));
509
    sprintf(full_path, "%s/", getenv("HOME"));
480
    char *test_file = new char[strlen(full_path) + 7];
510
    char * test_file = new char[strlen(full_path) + 7];
481
    sprintf(test_file, "%s.eMule", full_path); 
511
    sprintf(test_file, "%s.eMule", full_path); 
482
    FILE *testfile = fopen(test_file, "r");
512
    FILE * testfile = fopen(test_file, "r");
483
    if (!testfile)
513
    if (!testfile)
484
    {
514
    {
485
         error = true;      
515
         error = true;      
Lines 680-692 Link Here
680
    return error;
710
    return error;
681
}
711
}
682
712
683
bool CPreferences:: Load_Adresses(void)
713
bool CPreferences::Load_Adresses(void)
684
{
714
{
685
    //serverlist adresses
715
    //serverlist adresses
686
    bool error = false;
716
    bool error = false;
687
    char *full_path = new char[strlen(GetAppDir()) + 13];
717
    char * full_path = new char[strlen(GetAppDir()) + 13];
688
    sprintf(full_path, "%sadresses.dat", GetAppDir());
718
    sprintf(full_path, "%sadresses.dat", GetAppDir());
689
    FILE *sdirfile = fopen(full_path, "r");
719
    FILE * sdirfile = fopen(full_path, "r");
690
    if (sdirfile)
720
    if (sdirfile)
691
    {
721
    {
692
        char buffer[MAX_PATH];
722
        char buffer[MAX_PATH];
Lines 694-701 Link Here
694
        {
724
        {
695
            memset(buffer, 0, sizeof(buffer));
725
            memset(buffer, 0, sizeof(buffer));
696
            fgets(buffer, sizeof(buffer) - 1, sdirfile);
726
            fgets(buffer, sizeof(buffer) - 1, sdirfile);
697
            char *ptr = strchr(buffer, '\n');
727
            char * ptr = strchr(buffer, '\n');
698
            if (ptr) *ptr = 0;
728
            if (ptr) * ptr = 0;
699
            if (strlen(buffer) > 1)
729
            if (strlen(buffer) > 1)
700
            adresses_list.Append(new CString(buffer));
730
            adresses_list.Append(new CString(buffer));
701
        }
731
        }
Lines 708-726 Link Here
708
    return error;
738
    return error;
709
}
739
}
710
740
711
bool CPreferences:: Save_Adresses(void)
741
bool CPreferences::Save_Adresses(void)
712
{
742
{
713
    bool error = false;
743
        bool error = false;;
714
    ; // I am to lazy atm :)
744
    // I am to lazy atm :)
715
    return error;
745
    return error;
716
}
746
}
717
747
718
bool CPreferences:: Load_Shared_Dirs(void)
748
bool CPreferences::Load_Shared_Dirs(void)
719
{
749
{
720
    bool error;
750
    bool error;
721
    char *full_path = new char[strlen(GetAppDir()) + 14];
751
    char * full_path = new char[strlen(GetAppDir()) + 14];
722
    sprintf(full_path, "%sshareddir.dat", GetAppDir());
752
    sprintf(full_path, "%sshareddir.dat", GetAppDir());
723
    FILE *sdirfile = fopen(full_path, "r");
753
    FILE * sdirfile = fopen(full_path, "r");
724
    if (sdirfile)
754
    if (sdirfile)
725
    {
755
    {
726
        char buffer[MAX_PATH];
756
        char buffer[MAX_PATH];
Lines 728-735 Link Here
728
        {
758
        {
729
            memset(buffer, 0, sizeof(buffer));
759
            memset(buffer, 0, sizeof(buffer));
730
            fgets(buffer, sizeof(buffer) - 1, sdirfile);
760
            fgets(buffer, sizeof(buffer) - 1, sdirfile);
731
            char *ptr = strchr(buffer, '\n');
761
            char * ptr = strchr(buffer, '\n');
732
            if (ptr) *ptr = 0;
762
            if (ptr) * ptr = 0;
733
            if (strlen(buffer) > 1)
763
            if (strlen(buffer) > 1)
734
            shareddir_list.Add(buffer);
764
            shareddir_list.Add(buffer);
735
        }
765
        }
Lines 742-753 Link Here
742
    return error;
772
    return error;
743
}
773
}
744
774
745
bool CPreferences:: Save_Shared_Dirs(void)
775
bool CPreferences::Save_Shared_Dirs(void)
746
{
776
{
747
  bool error = false;
777
  bool error = false;
748
    char *full_path = new char[strlen(GetAppDir()) + 14];
778
    char * full_path = new char[strlen(GetAppDir()) + 14];
749
    sprintf(full_path, "%sshareddir.dat", GetAppDir());
779
    sprintf(full_path, "%sshareddir.dat", GetAppDir());
750
    FILE *sdirfile = fopen(full_path, "w");
780
    FILE * sdirfile = fopen(full_path, "w");
751
    if (sdirfile)
781
    if (sdirfile)
752
    {
782
    {
753
        for (int i = 0 ; i < shareddir_list.GetCount() ; i++)
783
        for (int i = 0 ; i < shareddir_list.GetCount() ; i++)
Lines 763-773 Link Here
763
    return error;
793
    return error;
764
}
794
}
765
795
766
796
bool CPreferences::SaveCats(void)
767
bool CPreferences:: SaveCats(void)
768
{
797
{
769
    bool error = false;
798
    bool error = false;
770
    FILE *category_fd;    
799
    FILE * category_fd;
771
    wxString catinif, buffer;
800
    wxString catinif, buffer;
772
    catinif.Printf("%sCategory.dat", GetAppDir());
801
    catinif.Printf("%sCategory.dat", GetAppDir());
773
    if (GetCatCount() > 0)
802
    if (GetCatCount() > 0)
Lines 778-788 Link Here
778
	     fprintf(category_fd, "%d ", catMap.GetCount() - 1);
807
	     fprintf(category_fd, "%d ", catMap.GetCount() - 1);
779
             for (int ix = 1 ; ix < catMap.GetCount() ; ix++)
808
             for (int ix = 1 ; ix < catMap.GetCount() ; ix++)
780
             { 
809
             { 
781
  	          fprintf(category_fd,"%s\n",catMap.GetAt(ix) -> title);              
810
                fprintf(category_fd, "%s\n", catMap.GetAt(ix) -> title);
782
                  fprintf(category_fd,"%s\n",catMap.GetAt(ix) -> incomingpath);
811
                fprintf(category_fd, "%s\n", catMap.GetAt(ix) -> incomingpath);
783
                  fprintf(category_fd,"%s\n",catMap.GetAt(ix) -> comment);
812
                fprintf(category_fd, "%s\n", catMap.GetAt(ix) -> comment);
784
                  fprintf(category_fd,"0x%lx\n", catMap.GetAt(ix)->color);
813
                fprintf(category_fd, "0x%lx\n", catMap.GetAt(ix) -> color);
785
                  fprintf(category_fd,"%.3u\n", catMap.GetAt(ix)->prio + 1);
814
                fprintf(category_fd, "%.3u\n", catMap.GetAt(ix) -> prio + 1);
786
	     }
815
	     }
787
             fclose(category_fd);
816
             fclose(category_fd);
788
         } 
817
         } 
Lines 794-812 Link Here
794
    return error;
823
    return error;
795
}
824
}
796
825
797
bool CPreferences:: LoadCats(void)
826
bool CPreferences::LoadCats(void)
798
{
827
{
799
    bool error = false;
828
    bool error = false;
800
    int max;
829
    int max;
801
    wxString catinif;
830
    wxString catinif;
802
    char buffer[2051];
831
    char buffer[2051];
803
    char *dummy;
832
    char * dummy;
804
    FILE *category_fd; 
833
    FILE * category_fd;
805
    // default cat
834
    // default cat
806
    Category_Struct *newcat = new Category_Struct;
835
    Category_Struct * newcat = new Category_Struct;
807
    sprintf(newcat->title, "");
836
    sprintf(newcat -> title, "");
808
    sprintf(newcat->incomingpath, "");
837
    sprintf(newcat -> incomingpath, "");
809
    sprintf(newcat->comment, "");
838
    sprintf(newcat -> comment, "");
810
    newcat -> prio = 0;
839
    newcat -> prio = 0;
811
    newcat -> color = 0;
840
    newcat -> color = 0;
812
    AddCat(newcat);
841
    AddCat(newcat);
Lines 815-839 Link Here
815
    category_fd = fopen(catinif, "r");
844
    category_fd = fopen(catinif, "r");
816
    if (category_fd != NULL)
845
    if (category_fd != NULL)
817
    {
846
    {
818
	   fscanf(category_fd, "%d ", &max);
847
        fscanf(category_fd, "%d ", & max);
819
           for (int i = 1 ; i <= max ; i++)
848
           for (int i = 1 ; i <= max ; i++)
820
           {
849
           {
821
                  Category_Struct *newcat = new Category_Struct;
850
            Category_Struct * newcat = new Category_Struct;
822
  	          fgets(buffer, 66, category_fd);
851
  	          fgets(buffer, 66, category_fd);
823
                  sprintf(newcat->title, "");
852
            sprintf(newcat -> title, "");
824
                  strncat(newcat->title, buffer, strlen(buffer) - 1);          
853
            strncat(newcat -> title, buffer, strlen(buffer) - 1);
825
                  fgets(buffer, 2050, category_fd);                                  
854
                  fgets(buffer, 2050, category_fd);                                  
826
                  sprintf(newcat->incomingpath, "");
855
            sprintf(newcat -> incomingpath, "");
827
                  strncat(newcat->incomingpath, buffer, strlen(buffer) - 1);
856
            strncat(newcat -> incomingpath, buffer, strlen(buffer) - 1);
828
                  fgets(buffer, 258, category_fd);
857
                  fgets(buffer, 258, category_fd);
829
                  sprintf(newcat->comment, "");
858
            sprintf(newcat -> comment, "");
830
                  strncat(newcat->comment, buffer, strlen(buffer) - 1);
859
            strncat(newcat -> comment, buffer, strlen(buffer) - 1);
831
                  fgets(buffer, 15, category_fd);
860
                  fgets(buffer, 15, category_fd);
832
                  newcat->color = (uint32)strtoul(buffer, &dummy, 0);
861
            newcat -> color = (uint32) strtoul(buffer, & dummy, 0);
833
                  fgets(buffer, 5, category_fd);
862
                  fgets(buffer, 5, category_fd);
834
                  newcat->prio = (uint8) atoi(buffer) - 1;
863
            newcat -> prio = (uint8) atoi(buffer) - 1;
835
                  AddCat(newcat);
864
                  AddCat(newcat);
836
                  if (!wxFileName:: DirExists(newcat -> incomingpath)) 
865
            if (!wxFileName::DirExists(newcat -> incomingpath))
837
                  {
866
                  {
838
                      mkdir(newcat -> incomingpath, 0777);
867
                      mkdir(newcat -> incomingpath, 0777);
839
		  }
868
		  }
Lines 847-866 Link Here
847
    return error;
876
    return error;
848
}
877
}
849
878
850
void CPreferences:: RemoveCat(int index)
879
void CPreferences::RemoveCat(int index)
851
{
880
{
852
    if (index >= 0 &&index < catMap.GetCount())
881
    if (index >= 0 && index < catMap.GetCount())
853
    {
882
    {
854
        Category_Struct *delcat;
883
        Category_Struct * delcat;
855
        delcat = catMap.GetAt(index);
884
        delcat = catMap.GetAt(index);
856
        catMap.RemoveAt(index);
885
        catMap.RemoveAt(index);
857
        delete delcat;
886
        delete delcat;
858
    }
887
    }
859
}
888
}
860
889
861
int CPreferences:: GetColumnSortItem(Table t) const
890
int CPreferences::GetColumnSortItem(Table t) const
862
{
891
{
863
864
    switch (t)
892
    switch (t)
865
    {
893
    {
866
    case tableDownload:
894
    case tableDownload:
Lines 881-887 Link Here
881
    return 0;
909
    return 0;
882
}
910
}
883
911
884
bool CPreferences:: GetColumnSortAscending(Table t) const
912
bool CPreferences::GetColumnSortAscending(Table t) const
885
{
913
{
886
    switch (t)
914
    switch (t)
887
    {
915
    {
Lines 901-910 Link Here
901
        return prefs -> tableSortAscendingClientList;
929
        return prefs -> tableSortAscendingClientList;
902
    }
930
    }
903
    return true;
931
    return true;
904
905
}
932
}
906
933
907
void CPreferences:: SetColumnSortItem(Table t, int sortItem)
934
void CPreferences::SetColumnSortItem(Table t, int sortItem)
908
{
935
{
909
    switch (t)
936
    switch (t)
910
    {
937
    {
Lines 932-938 Link Here
932
    }
959
    }
933
}
960
}
934
961
935
void CPreferences:: SetColumnSortAscending(Table t, bool sortAscending)
962
void CPreferences::SetColumnSortAscending(Table t, bool sortAscending)
936
{
963
{
937
    switch (t)
964
    switch (t)
938
    {
965
    {
Lines 960-966 Link Here
960
    }
987
    }
961
}
988
}
962
989
963
int CPreferences:: GetColumnWidth(Table t, int index) const
990
int CPreferences::GetColumnWidth(Table t, int index) const
964
{
991
{
965
    switch (t)
992
    switch (t)
966
    {
993
    {
Lines 980-989 Link Here
980
        return prefs -> clientListColumnWidths[index];
1007
        return prefs -> clientListColumnWidths[index];
981
    }
1008
    }
982
    return 0;
1009
    return 0;
983
984
}
1010
}
985
1011
986
void CPreferences:: SetColumnWidth(Table t, int index, int width)
1012
void CPreferences::SetColumnWidth(Table t, int index, int width)
987
{
1013
{
988
    switch (t)
1014
    switch (t)
989
    {
1015
    {
Lines 1011-1017 Link Here
1011
    }
1037
    }
1012
}
1038
}
1013
1039
1014
BOOL CPreferences:: GetColumnHidden(Table t, int index) const
1040
BOOL CPreferences::GetColumnHidden(Table t, int index) const
1015
{
1041
{
1016
    switch (t)
1042
    switch (t)
1017
    {
1043
    {
Lines 1033-1039 Link Here
1033
    return FALSE;
1059
    return FALSE;
1034
}
1060
}
1035
1061
1036
void CPreferences:: SetColumnHidden(Table t, int index, BOOL bHidden)
1062
void CPreferences::SetColumnHidden(Table t, int index, BOOL bHidden)
1037
{
1063
{
1038
    switch (t)
1064
    switch (t)
1039
    {
1065
    {
Lines 1061-1067 Link Here
1061
    }
1087
    }
1062
}
1088
}
1063
1089
1064
int CPreferences:: GetColumnOrder(Table t, int index) const
1090
int CPreferences::GetColumnOrder(Table t, int index) const
1065
{
1091
{
1066
    switch (t)
1092
    switch (t)
1067
    {
1093
    {
Lines 1083-1089 Link Here
1083
    return 0;
1109
    return 0;
1084
}
1110
}
1085
1111
1086
void CPreferences:: SetColumnOrder(Table t, INT *piOrder)
1112
void CPreferences::SetColumnOrder(Table t, INT * piOrder)
1087
{
1113
{
1088
    switch (t)
1114
    switch (t)
1089
    {
1115
    {
(-)xmule/src/Preferences.h (-12 lines)
Lines 42-58 Link Here
42
42
43
#define DEFAULT_COL_SIZE 65535
43
#define DEFAULT_COL_SIZE 65535
44
44
45
// DO NOT EDIT VALUES like making a uint16 to uint32, or insert any value. ONLY append new vars
46
#pragma pack(1)
47
struct Preferences_Ext_Struct
48
{
49
    int8 version;
50
    uchar userhash[16];
51
    WINDOWPLACEMENT EmuleWindowPlacement;
52
};
53
54
#pragma pack()
55
56
// deadlake PROXYSUPPORT
45
// deadlake PROXYSUPPORT
57
struct ProxySettings
46
struct ProxySettings
58
{
47
{
Lines 1388-1394 Link Here
1388
    private:
1377
    private:
1389
    char appdir[MAX_PATH];
1378
    char appdir[MAX_PATH];
1390
    Preferences_Struct *prefs;
1379
    Preferences_Struct *prefs;
1391
    Preferences_Ext_Struct *prefsExt;
1392
    char userhash[16];
1380
    char userhash[16];
1393
    WORD m_wWinVer;
1381
    WORD m_wWinVer;
1394
    CArray < Category_Struct *, Category_Struct *> catMap;
1382
    CArray < Category_Struct *, Category_Struct *> catMap;
(-)xmule/src/SearchDlg.cpp (+2 lines)
Lines 1839-1845 Link Here
1839
                glspacket -> opcode = OP_GLOBSEARCHREQ;
1839
                glspacket -> opcode = OP_GLOBSEARCHREQ;
1840
#endif
1840
#endif
1841
            }
1841
            }
1842
#if defined(__DEBUG__)
1842
            printf("SendUDPPacket for UDPsearch to %s:%d\n", toask -> GetAddress(), toask -> GetPort());
1843
            printf("SendUDPPacket for UDPsearch to %s:%d\n", toask -> GetAddress(), toask -> GetPort());
1844
#endif
1843
#ifdef __XMULE2__
1845
#ifdef __XMULE2__
1844
            theApp.serverconnect -> SendServerUDPPacket(glspacket, toask, false);
1846
            theApp.serverconnect -> SendServerUDPPacket(glspacket, toask, false);
1845
#else
1847
#else
(-)xmule/src/SharedFileList.cpp (-49 lines)
Lines 333-387 Link Here
333
    return - 10;
333
    return - 10;
334
}
334
}
335
335
336
#if 0
337
CAddFileThread:: CAddFileThread(): wxThread(wxTHREAD_DETACHED)
338
{
339
}
340
341
wxThread:: ExitCode CAddFileThread:: Entry()
342
{
343
    while (1)
344
    {
345
        g_lockWaitingForHashList.Lock();
346
        if (g_endWaitingForHashList)
347
        {
348
            g_endedWaitingForHashList.Signal();
349
            g_lockWaitingForHashList.Unlock();
350
            return 0;
351
        }
352
        if (g_sWaitingForHashList.IsEmpty())
353
        {
354
            // Unlocks g_lockWaitingForHashList:
355
            g_runWaitingForHashList.Wait();
356
            g_lockWaitingForHashList.Unlock();
357
            continue;
358
        }
359
        UnknownFile_Struct *hashfile = g_sWaitingForHashList.RemoveHead();
360
        g_lockWaitingForHashList.Unlock();
361
        CKnownFile *newrecord = new CKnownFile();
362
        printf("Sharing %s/%s\n", hashfile -> directory, hashfile -> name);
363
        newrecord -> CreateFromFile(hashfile -> directory, hashfile -> name);
364
        g_lockWaitingForHashList.Lock();
365
        if (g_endWaitingForHashList)
366
        {
367
            g_endedWaitingForHashList.Signal();
368
            g_lockWaitingForHashList.Unlock();
369
            return 0;
370
        }
371
        // TODO: Possible race condition between unlocking and wxPostEvent.
372
        g_lockWaitingForHashList.Unlock();
373
        wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, TM_FINISHEDHASHING);
374
        evt.SetClientData(newrecord);
375
        evt.SetInt((int) hashfile -> partfile_Owner);
376
        wxPostEvent(theApp.xmuledlg, evt);
377
        free(hashfile -> name);
378
        free(hashfile -> directory);
379
        delete hashfile;
380
    }
381
}
382
383
#endif
384
385
void CSharedFileList:: UpdateItem(CKnownFile *toupdate)
336
void CSharedFileList:: UpdateItem(CKnownFile *toupdate)
386
{
337
{
387
    output -> UpdateItem(toupdate);
338
    output -> UpdateItem(toupdate);
(-)xmule/src/TransferWnd.cpp (-423 lines)
Lines 87-98 Link Here
87
{
87
{
88
}
88
}
89
89
90
#if 0
91
BEGIN_MESSAGE_MAP(CTransferWnd, CResizableDialog)
92
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipNotify)
93
END_MESSAGE_MAP()
94
#endif
95
96
BOOL CTransferWnd:: OnInitDialog()
90
BOOL CTransferWnd:: OnInitDialog()
97
{
91
{
98
    m_dlTab = (CMuleNotebook *) FindWindowById(ID_CATEGORIES);
92
    m_dlTab = (CMuleNotebook *) FindWindowById(ID_CATEGORIES);
Lines 109-152 Link Here
109
        // but they will be accepted in SetPageText().. so let's use this as a countermeasure
103
        // but they will be accepted in SetPageText().. so let's use this as a countermeasure
110
        m_dlTab -> SetPageText(ix, tmpstrstr);
104
        m_dlTab -> SetPageText(ix, tmpstrstr);
111
    }
105
    }
112
#if 0
113
    CResizableDialog:: OnInitDialog();
114
    Localize();
115
    windowtransferstate = false;
116
    uploadlistctrl.Init();
117
    downloadlistctrl.Init();
118
    queuelistctrl.Init();
119
    ((CStatic *) GetDlgItem(IDC_DOWNLOAD_ICO)) -> SetIcon((HICON):: LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_DIRECTDOWNLOAD), IMAGE_ICON, 16, 16, 0));
120
    ((CStatic *) GetDlgItem(IDC_UPLOAD_ICO)) -> SetIcon((HICON):: LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_UPLOAD), IMAGE_ICON, 16, 16, 0));
121
    AddAnchor(IDC_DOWNLOADLIST, TOP_LEFT, CSize(100, theApp.glob_prefs -> GetSplitterbarPosition()));
122
    AddAnchor(IDC_UPLOADLIST, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT);
123
    AddAnchor(IDC_QUEUELIST, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT);
124
    AddAnchor(IDC_UPLOAD_TEXT, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT);
125
    AddAnchor(IDC_UPLOAD_ICO, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT);
126
    AddAnchor(IDC_QUEUECOUNT, BOTTOM_LEFT);
127
    AddAnchor(IDC_TSTATIC1, BOTTOM_LEFT);
128
    // splitting functionality
129
    CRect rc, rcSpl, rcDown;
130
    GetWindowRect(rc);
131
    ScreenToClient(rc);
132
    rcSpl = rc;
133
    rcSpl.top = rc.bottom - 100;
134
    rcSpl.bottom = rcSpl.top + 5;
135
    rcSpl.left = 55;
136
    m_wndSplitter.Create(WS_CHILD | WS_VISIBLE, rcSpl, this, IDC_SPLITTER);
137
    SetInitLayout();
138
    // create tooltip
139
    m_ttip.Create(this);
140
    m_ttip.SetDelayTime(TTDT_AUTOPOP, 20000);
141
    m_ttip.SetDelayTime(TTDT_INITIAL, theApp.glob_prefs -> GetToolTipDelay() *1000);
142
    // recognize \n chars!:
143
    m_ttip.SendMessage(TTM_SETMAXTIPWIDTH, 0, SHRT_MAX);
144
    m_ttip.AddTool( &downloadlistctrl);
145
    m_ttip.AddTool( &uploadlistctrl);
146
    m_iOldToolTipItemDown = - 1;
147
    m_iOldToolTipItemUp = - 1;
148
    m_iOldToolTipItemQueue = - 1;
149
#endif
150
    return true;
106
    return true;
151
}
107
}
152
108
Lines 159-548 Link Here
159
    //this->GetDlgItem(IDC_QUEUECOUNT)->SetWindowText(buffer);
115
    //this->GetDlgItem(IDC_QUEUECOUNT)->SetWindowText(buffer);
160
}
116
}
161
117
162
#if 0
163
void CTransferWnd:: DoDataExchange(CDataExchange *pDX)
164
{
165
    CResizableDialog:: DoDataExchange(pDX);
166
    DDX_Control(pDX, IDC_UPLOADLIST, uploadlistctrl);
167
    DDX_Control(pDX, IDC_DOWNLOADLIST, downloadlistctrl);
168
    DDX_Control(pDX, IDC_QUEUELIST, queuelistctrl);
169
}
170
171
#endif
172
173
void CTransferWnd:: SetInitLayout()
118
void CTransferWnd:: SetInitLayout()
174
{
119
{
175
#if 0
176
    CRect rcDown, rcSpl, rcW;
177
    CWnd *pWnd;
178
    GetWindowRect(rcW);
179
    ScreenToClient(rcW);
180
    LONG splitpos = (theApp.glob_prefs -> GetSplitterbarPosition() *rcW.Height()) /100;
181
    pWnd = GetDlgItem(IDC_DOWNLOADLIST);
182
    pWnd -> GetWindowRect(rcDown);
183
    ScreenToClient(rcDown);
184
    rcDown.right = rcW.right - 7;
185
    rcDown.bottom = splitpos - 5;
186
    downloadlistctrl.MoveWindow(rcDown);
187
    pWnd = GetDlgItem(IDC_UPLOADLIST);
188
    pWnd -> GetWindowRect(rcDown);
189
    ScreenToClient(rcDown);
190
    rcDown.right = rcW.right - 7;
191
    rcDown.bottom = rcW.bottom - 20;
192
    rcDown.top = splitpos + 20;
193
    uploadlistctrl.MoveWindow(rcDown);
194
    pWnd = GetDlgItem(IDC_QUEUELIST);
195
    pWnd -> GetWindowRect(rcDown);
196
    ScreenToClient(rcDown);
197
    rcDown.right = rcW.right - 7;
198
    rcDown.bottom = rcW.bottom - 20;
199
    rcDown.top = splitpos + 20;
200
    queuelistctrl.MoveWindow(rcDown);
201
    rcSpl = rcDown;
202
    rcSpl.top = rcDown.bottom + 4;
203
    rcSpl.bottom = rcSpl.top + 5;
204
    rcSpl.left = 95;
205
    m_wndSplitter.MoveWindow(rcSpl, true);
206
    DoResize(0);
207
#endif
208
}
120
}
209
121
210
void CTransferWnd:: DoResize(int delta)
122
void CTransferWnd:: DoResize(int delta)
211
{
123
{
212
#if 0
213
    CSplitterControl:: ChangeHeight( &downloadlistctrl, delta);
214
    CSplitterControl:: ChangeHeight( &uploadlistctrl, - delta, CW_BOTTOMALIGN);
215
    CSplitterControl:: ChangeHeight( &queuelistctrl, - delta, CW_BOTTOMALIGN);
216
    UpdateSplitterRange();
217
    Invalidate();
218
    UpdateWindow();
219
#endif
220
}
124
}
221
125
222
// setting splitter range limits
126
// setting splitter range limits
223
void CTransferWnd:: UpdateSplitterRange()
127
void CTransferWnd:: UpdateSplitterRange()
224
{
128
{
225
#if 0
226
    CRect rcDown, rcUp, rcW, rcSpl;
227
    CWnd *pWnd;
228
    GetWindowRect(rcW);
229
    ScreenToClient(rcW);
230
    pWnd = GetDlgItem(IDC_DOWNLOADLIST);
231
    pWnd -> GetWindowRect(rcDown);
232
    ScreenToClient(rcDown);
233
    pWnd = GetDlgItem(IDC_UPLOADLIST);
234
    pWnd -> GetWindowRect(rcUp);
235
    ScreenToClient(rcUp);
236
    pWnd = GetDlgItem(IDC_QUEUELIST);
237
    pWnd -> GetWindowRect(rcUp);
238
    ScreenToClient(rcUp);
239
    theApp.glob_prefs -> SetSplitterbarPosition((rcDown.bottom *100) /rcW.Height());
240
    RemoveAnchor(IDC_DOWNLOADLIST);
241
    RemoveAnchor(IDC_UPLOADLIST);
242
    RemoveAnchor(IDC_QUEUELIST);
243
    AddAnchor(IDC_DOWNLOADLIST, TOP_LEFT, CSize(100, theApp.glob_prefs -> GetSplitterbarPosition()));
244
    AddAnchor(IDC_UPLOADLIST, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT);
245
    AddAnchor(IDC_QUEUELIST, CSize(0, theApp.glob_prefs -> GetSplitterbarPosition()), BOTTOM_RIGHT);
246
    m_wndSplitter.SetRange(rcDown.top + 50, rcUp.bottom - 40);
247
#endif
248
}
129
}
249
130
250
#if 0
251
LRESULT CTransferWnd:: DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
252
{
253
    switch (message)
254
    {
255
        // arrange transferwindow layout
256
    case WM_PAINT:
257
        if (m_wndSplitter)
258
        {
259
            CRect rcDown, rcSpl, rcW;
260
            CWnd *pWnd;
261
            GetWindowRect(rcW);
262
            ScreenToClient(rcW);
263
            pWnd = GetDlgItem(IDC_DOWNLOADLIST);
264
            pWnd -> GetWindowRect(rcDown);
265
            ScreenToClient(rcDown);
266
            if (rcW.Height() > 0)
267
            {
268
                // splitter paint update
269
                rcSpl = rcDown;
270
                rcSpl.top = rcDown.bottom + 8;
271
                rcSpl.bottom = rcSpl.top + 5;
272
                rcSpl.left = 95;
273
                GetDlgItem(IDC_UPLOAD_TEXT) -> MoveWindow(30, rcSpl.top - 5, 90, 16);
274
                GetDlgItem(IDC_UPLOAD_ICO) -> MoveWindow(10, rcSpl.top - 5, 16, 16);
275
                m_wndSplitter.MoveWindow(rcSpl, true);
276
                UpdateSplitterRange();
277
            }
278
        }
279
        break;
280
    case WM_NOTIFY:
281
        if (wParam == IDC_SPLITTER)
282
        {
283
            SPC_NMHDR *pHdr = (SPC_NMHDR *) lParam;
284
            DoResize(pHdr -> delta);
285
        }
286
        break;
287
    case WM_WINDOWPOSCHANGED:
288
        {
289
            CRect rcW;
290
            GetWindowRect(rcW);
291
            ScreenToClient(rcW);
292
            if (m_wndSplitter &&rcW.Height() > 0) Invalidate();
293
            break;
294
        }
295
    case WM_SIZE:
296
        if (m_wndSplitter)
297
        {
298
            CRect rcDown, rcSpl, rcW;
299
            CWnd *pWnd;
300
            GetWindowRect(rcW);
301
            ScreenToClient(rcW);
302
            if (rcW.Height() > 0)
303
            {
304
                pWnd = GetDlgItem(IDC_DOWNLOADLIST);
305
                pWnd -> GetWindowRect(rcDown);
306
                ScreenToClient(rcDown);
307
                long splitpos = (theApp.glob_prefs -> GetSplitterbarPosition() *rcW.Height()) /100;
308
                rcSpl.right = rcDown.right;
309
                rcSpl.top = splitpos + 10;
310
                rcSpl.bottom = rcSpl.top + 5;
311
                rcSpl.left = 95;
312
                m_wndSplitter.MoveWindow(rcSpl, true);
313
            }
314
        }
315
        break;
316
    }
317
    return CDialog:: DefWindowProc(message, wParam, lParam);
318
}
319
320
#endif
321
322
#if 0
323
// CTransferWnd message handlers
324
BOOL CTransferWnd:: PreTranslateMessage(MSG *pMsg)
325
{
326
    // handle tooltip updating, when mouse is moved from one item to another
327
    if (pMsg -> message == WM_MOUSEMOVE)
328
    UpdateToolTips();
329
    // relay mouse events to tooltip control
330
    if (pMsg -> message == WM_LBUTTONDOWN || pMsg -> message == WM_LBUTTONUP || pMsg -> message == WM_MOUSEMOVE)
331
    m_ttip.RelayEvent(pMsg);
332
    return CResizableDialog:: PreTranslateMessage(pMsg);
333
}
334
335
#endif
336
337
void CTransferWnd:: UpdateToolTips(void)
131
void CTransferWnd:: UpdateToolTips(void)
338
{
132
{
339
#if 0
340
    int sel = GetItemUnderMouse( &downloadlistctrl);
341
    if (sel != - 1)
342
    {
343
        if (sel != m_iOldToolTipItemDown)
344
        {
345
            if (m_ttip.IsWindowVisible())
346
            m_ttip.Update();
347
            m_iOldToolTipItemDown = sel;
348
            return;
349
        }
350
    }
351
    int sel2 = GetItemUnderMouse( &uploadlistctrl);
352
    if (sel2 != - 1)
353
    {
354
        if (sel2 != m_iOldToolTipItemUp)
355
        {
356
            if (m_ttip.IsWindowVisible())
357
            m_ttip.Update();
358
            m_iOldToolTipItemUp = sel2;
359
            return;
360
        }
361
    }
362
 /* no tooltips needed ATM
363
 int sel3 = GetItemUnderMouse(&queuelistctrl);
364
 if (sel3 != -1)
365
 {
366
 if (sel3 != m_iOldToolTipItemQueue)
367
 {
368
 if (m_ttip.IsWindowVisible())
369
 m_ttip.Update();
370
 m_iOldToolTipItemQueue = sel3;
371
 }
372
 }
373
    */
374
    if (sel == - 1 &&sel2 == - 1 /*&& sel3 != -1*/
375
    )
376
    m_ttip.Pop();
377
#endif
378
}
133
}
379
134
380
int CTransferWnd:: GetItemUnderMouse(wxListCtrl *ctrl)
135
int CTransferWnd:: GetItemUnderMouse(wxListCtrl *ctrl)
381
{
136
{
382
#if 0
383
    CPoint pt;
384
    :: GetCursorPos( &pt);
385
    ctrl -> ScreenToClient( &pt);
386
    LVHITTESTINFO hit, subhit;
387
    hit.pt = pt;
388
    subhit.pt = pt;
389
    ctrl -> SubItemHitTest( &subhit);
390
    int sel = ctrl -> HitTest( &hit);
391
    if (sel != LB_ERR && (hit.flags &LVHT_ONITEM))
392
    {
393
        if (subhit.iSubItem == 0)
394
        return sel;
395
    }
396
    return LB_ERR;
397
#endif
398
}
137
}
399
138
400
#if 0
401
BOOL CTransferWnd:: OnToolTipNotify(UINT id, NMHDR *pNMH, LRESULT *pResult)
402
{
403
    TOOLTIPTEXT *pText = (TOOLTIPTEXT *) pNMH;
404
    int control_id =:: GetDlgCtrlID((HWND) pNMH -> idFrom);
405
    if (!control_id)
406
    return FALSE;
407
    CString info;
408
    if (control_id == IDC_DOWNLOADLIST)
409
    {
410
        if (downloadlistctrl.GetItemCount() < 1)
411
        return FALSE;
412
        int sel = GetItemUnderMouse( &downloadlistctrl);
413
        if (sel < 0 || sel == 65535)
414
        return FALSE;
415
        // build info text and display it
416
        CtrlItem_Struct *content = (CtrlItem_Struct *) downloadlistctrl.GetItemData(sel);
417
        // for downloading files:
418
        if (content -> type == 1)
419
        {
420
            CPartFile *partfile = (CPartFile *) content -> value;
421
            CString strHash;
422
            strHash.Format("%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
423
            partfile -> GetFileHash() [0], partfile -> GetFileHash() [1], partfile -> GetFileHash() [2], partfile -> GetFileHash() [3], partfile -> GetFileHash() [4], partfile -> GetFileHash() [5], partfile -> GetFileHash() [6], partfile -> GetFileHash() [7],
424
            partfile -> GetFileHash() [8], partfile -> GetFileHash() [9], partfile -> GetFileHash() [10], partfile -> GetFileHash() [11], partfile -> GetFileHash() [12], partfile -> GetFileHash() [13], partfile -> GetFileHash() [14], partfile -> GetFileHash() [15]);
425
            CTime t(partfile -> GetFileDate());
426
            char lsc[50];
427
            char compl[50];
428
            char buffer[20];
429
            CastItoXBytes(partfile -> GetCompletedSize(), lsc);
430
            CastItoXBytes(partfile -> GetFileSize(), buffer);
431
            sprintf(compl, "%s/%s", lsc, buffer);
432
            if (partfile -> lastseencomplete == NULL) sprintf(lsc, GetResString(IDS_UNKNOWN) .MakeLower());
433
            else
434
            sprintf(lsc, partfile -> lastseencomplete.Format("%A, %x, %X"));
435
            float availability = 0;
436
            if (partfile -> GetPartCount() != 0)
437
            {
438
                availability = partfile -> GetAvailablePartCount() *100 / partfile -> GetPartCount();
439
            }
440
            info.Format(GetResString(IDS_DL_FILENAME) + ": %s (%d %s)\n"
441
            + GetResString(IDS_DATE) + ": %s - " + GetResString(IDS_FD_HASH) + " %s\n"
442
            + GetResString(IDS_PARTINFOS) +
443
            GetResString(IDS_PARTINFOS2) + "\n%s",
444
            partfile -> GetFileName(), partfile -> GetFileSize(), GetResString(IDS_BYTES),
445
            t.Format("%A, %B %d, %Y"), strHash,
446
            partfile -> GetPartMetFileName(), partfile -> GetPartCount(), GetResString(IDS_AVAIL), partfile -> GetAvailablePartCount(), availability,
447
            (int) partfile -> GetPercentCompleted(), compl, partfile -> GetTransferingSrcCount(),
448
            GetResString(IDS_LASTSEENCOMPL) + " " + CString(lsc));
449
            // for sources:
450
        }
451
        else if(content -> type == 3 || content -> type == 2)
452
        {
453
            CUpDownClient *client = (CUpDownClient *) content -> value;
454
            in_addr server;
455
            server.S_un.S_addr = client -> GetServerIP();
456
            info.Format(GetResString(IDS_NICKNAME) + " %s (" + GetResString(IDS_USERID) + ": %u)\n"
457
            + GetResString(IDS_CLIENT) + " %s:%d\n"
458
            + GetResString(IDS_SERVER) + " %s:%d\n"
459
            + GetResString(IDS_SOURCEINFO),
460
            client -> GetUserName(), client -> GetUserID(),
461
            client -> GetFullIP(), client -> GetUserPort(),
462
            inet_ntoa(server), client -> GetServerPort(),
463
    /*client->GetAskedCount()*/
464
            0, client -> GetAvailablePartCount());
465
            if (content -> type == 2)
466
            {
467
                // normal client
468
                info += GetResString(IDS_CLIENTSOURCENAME) + CString(client -> GetClientFilename());
469
            }
470
            else
471
            {
472
                // client asked twice
473
                info += GetResString(IDS_ASKEDFAF);
474
            }
475
        }
476
    }
477
    else if(control_id == IDC_UPLOADLIST)
478
    {
479
        if (uploadlistctrl.GetItemCount() < 1)
480
        return FALSE;
481
        int sel = GetItemUnderMouse( &uploadlistctrl);
482
        if (sel < 0 || sel == 65535)
483
        return FALSE;
484
        CUpDownClient *client = (CUpDownClient *) uploadlistctrl.GetItemData(sel);
485
        CKnownFile *file = theApp.sharedfiles -> GetFileByID(client -> reqfileid);
486
        // build info text and display it
487
        info.Format(GetResString(IDS_USERINFO), client -> GetUserName(), client -> GetUserID());
488
        if (file)
489
        {
490
            info += GetResString(IDS_SF_REQUESTED) + CString(file -> GetFileName()) + "\n";
491
            CString stat;
492
            stat.Format(GetResString(IDS_FILESTATS_SESSION) + GetResString(IDS_FILESTATS_TOTAL),
493
            file -> statistic.GetAccepts(), file -> statistic.GetRequests(), file -> statistic.GetTransfered(),
494
            file -> statistic.GetAllTimeAccepts(), file -> statistic.GetAllTimeRequests(), file -> statistic.GetAllTimeTransfered());
495
            info += stat;
496
        }
497
        else
498
        {
499
            info += GetResString(IDS_REQ_UNKNOWNFILE);
500
        }
501
    }
502
 /*	no tooltips needed ATM
503
 else if (control_id == IDC_QUEUELIST)
504
 {
505
 if (queuelistctrl.GetItemCount() < 1)
506
 return FALSE;
507
 int sel = GetItemUnderMouse(&queuelistctrl);
508
 if (sel < 0 || sel == 65535)
509
 return FALSE;
510
 // build info text and display it
511
 CUpDownClient* client = (CUpDownClient*)uploadlistctrl.GetItemData(sel);
512
 in_addr server;
513
 server.S_un.S_addr = client->GetServerIP();
514
 info.Format("Nickname: %s (UserID: %u)\n"
515
 "Client %s:%d\n"
516
 "Server %s:%d\n"
517
 "AskedCount: %d - AvailablePartCount: %d",
518
 client->GetUserName(), client->GetUserID(),
519
 client->GetFullIP(), client->GetUserPort(),
520
 inet_ntoa(server), client->GetServerPort(),
521
 client->GetAskedCount(), client->GetAvailablePartCount());
522
 }
523
    */
524
    // release old used buffer:
525
    m_strToolTip.ReleaseBuffer();
526
    m_strToolTip = info;
527
    pText -> lpszText = m_strToolTip.GetBuffer(1);
528
    // we are not using a resource:
529
    pText -> hinst = NULL;
530
    PostMessage(WM_ACTIVATE);
531
    return TRUE;
532
}
533
534
#endif
535
536
void CTransferWnd:: SwitchUploadList(wxCommandEvent &evt)
139
void CTransferWnd:: SwitchUploadList(wxCommandEvent &evt)
537
{
140
{
538
    if (windowtransferstate == false)
141
    if (windowtransferstate == false)
539
    {
142
    {
540
#if 0
541
        uploadlistctrl.Hide();
542
        queuelistctrl.Visable();
543
        windowtransferstate = 0;
544
        GetDlgItem(IDC_UPLOAD_TEXT) -> SetWindowText(GetResString(IDS_ONQUEUE));
545
#endif
546
        windowtransferstate = true;
143
        windowtransferstate = true;
547
        // hide the upload list
144
        // hide the upload list
548
        queueSizer -> Remove(uploadlistctrl);
145
        queueSizer -> Remove(uploadlistctrl);
Lines 554-565 Link Here
554
    }
151
    }
555
    else
152
    else
556
    {
153
    {
557
#if 0
558
        queuelistctrl.Hide();
559
        uploadlistctrl.Visable();
560
        windowtransferstate = 1;
561
        GetDlgItem(IDC_UPLOAD_TEXT) -> SetWindowText(GetResString(IDS_TW_UPLOADS));
562
#endif
563
        windowtransferstate = false;
154
        windowtransferstate = false;
564
        // hide the queuelist
155
        // hide the queuelist
565
        queueSizer -> Remove(queuelistctrl);
156
        queueSizer -> Remove(queuelistctrl);
Lines 573-587 Link Here
573
164
574
void CTransferWnd:: Localize()
165
void CTransferWnd:: Localize()
575
{
166
{
576
#if 0
577
    GetDlgItem(IDC_DOWNLOAD_TEXT) -> SetWindowText(GetResString(IDS_TW_DOWNLOADS));
578
    GetDlgItem(IDC_UPLOAD_TEXT) -> SetWindowText(GetResString(IDS_TW_UPLOADS));
579
    GetDlgItem(IDC_TSTATIC1) -> SetWindowText(GetResString(IDS_TW_QUEUE));
580
    downloadlistctrl.CreateMenues();
581
    downloadlistctrl.Localize();
582
    uploadlistctrl.Localize();
583
    queuelistctrl.Localize();
584
#endif
585
}
167
}
586
168
587
void CTransferWnd:: OnSelchangeDltab(wxNotebookEvent &evt)
169
void CTransferWnd:: OnSelchangeDltab(wxNotebookEvent &evt)
Lines 777-787 Link Here
777
            theApp.downloadqueue -> SetCatStatus(m_dlTab -> GetSelection(), MP_RESUME);
359
            theApp.downloadqueue -> SetCatStatus(m_dlTab -> GetSelection(), MP_RESUME);
778
            break;
360
            break;
779
        }
361
        }
780
#if 0
781
    case MP_RESUMENEXT:
782
        theApp.downloadqueue -> StartNextFile(m_dlTab -> GetSelection());
783
        break;
784
#endif
785
    case IDC_UPLOAD_ICO:
362
    case IDC_UPLOAD_ICO:
786
        {
363
        {
787
            wxCommandEvent nullEvt;
364
            wxCommandEvent nullEvt;
(-)xmule/src/UDPSocket.cpp (-8 / +4 lines)
Lines 233-239 Link Here
233
    sendbuffer = 0;
233
    sendbuffer = 0;
234
    cur_server = 0;
234
    cur_server = 0;
235
    serverconnect = in_serverconnect;
235
    serverconnect = in_serverconnect;
236
#if defined(__DEBUG__) 
236
    printf("*** UDP socket at %d\n", address.Service());
237
    printf("*** UDP socket at %d\n", address.Service());
238
#endif
237
    SetEventHandler( *theApp.xmuledlg, ID_SOKETTI);
239
    SetEventHandler( *theApp.xmuledlg, ID_SOKETTI);
238
    SetNotify(wxSOCKET_INPUT_FLAG);
240
    SetNotify(wxSOCKET_INPUT_FLAG);
239
    Notify(TRUE);
241
    Notify(TRUE);
Lines 375-381 Link Here
375
                update -> SetMaxUsers(cur_maxusers);
377
                update -> SetMaxUsers(cur_maxusers);
376
                update -> SetSoftFiles(cur_softfiles);
378
                update -> SetSoftFiles(cur_softfiles);
377
                update -> SetHardFiles(cur_hardfiles);
379
                update -> SetHardFiles(cur_hardfiles);
378
                //printf("->> reading Stats from server, flags are %i\n",uUDPFlags);
379
                update -> SetUDPFlags(uUDPFlags);
380
                update -> SetUDPFlags(uUDPFlags);
380
                theApp.xmuledlg -> serverwnd -> serverlistctrl -> RefreshServer(update);
381
                theApp.xmuledlg -> serverwnd -> serverlistctrl -> RefreshServer(update);
381
            }
382
            }
Lines 410-416 Link Here
410
            break;
411
            break;
411
        }
412
        }
412
    default:
413
    default:
414
#if defined(__DEBUG__) 
413
        printf("UDPSocket::ProcessPacket unknown opcode: %02x\n", opcode);
415
        printf("UDPSocket::ProcessPacket unknown opcode: %02x\n", opcode);
416
#endif
414
        theApp.downloadqueue -> AddDownDataOverheadOther(size);
417
        theApp.downloadqueue -> AddDownDataOverheadOther(size);
415
        return false;
418
        return false;
416
    }
419
    }
Lines 492-499 Link Here
492
                if (GAddress_INET_SetHostAddress(addr -> GetAddress(), m_SaveAddr.sin_addr.s_addr) == GSOCK_NOERROR)
495
                if (GAddress_INET_SetHostAddress(addr -> GetAddress(), m_SaveAddr.sin_addr.s_addr) == GSOCK_NOERROR)
493
                {
496
                {
494
                    SendTo( *addr, sendbuffer, sendblen);
497
                    SendTo( *addr, sendbuffer, sendblen);
495
                    //only for debugging:
496
                    //printf("CUDPSocket::SendBuffer to %s:%d\n",(const char *) addr->IPAddress(),addr->Service());
497
                }
498
                }
498
            }
499
            }
499
            delete addr;
500
            delete addr;
Lines 507-513 Link Here
507
508
508
void CUDPSocket:: SendPacket(Packet *packet, CServer *host)
509
void CUDPSocket:: SendPacket(Packet *packet, CServer *host)
509
{
510
{
510
//printf("CUDPSocket:: SendPacket opcode=0x%02x size=%u\n",packet->opcode,packet->size);
511
    if (Ok())
511
    if (Ok())
512
    {
512
    {
513
        wxIPV4address *addr = new wxIPV4address();
513
        wxIPV4address *addr = new wxIPV4address();
Lines 518-527 Link Here
518
            {
518
            {
519
                sendblen = packet -> size + 2;
519
                sendblen = packet -> size + 2;
520
                sendbuffer = new char[sendblen];
520
                sendbuffer = new char[sendblen];
521
#if defined(__DEBUG__)
522
                //printf("CUDPSocket::SendPacket to %s:%d 0x%02x,%d\n", 
523
		//(const char *) addr -> IPAddress(), addr -> Service(), packet -> opcode, packet -> size);
524
#endif
525
                memcpy(sendbuffer, packet -> GetUDPHeader(), 2);
521
                memcpy(sendbuffer, packet -> GetUDPHeader(), 2);
526
                memcpy(sendbuffer + 2, packet -> pBuffer, packet -> size);
522
                memcpy(sendbuffer + 2, packet -> pBuffer, packet -> size);
527
	if(!newprefs01_opt[4]) {
523
	if(!newprefs01_opt[4]) {
(-)xmule/src/UploadClient.cpp (-25 / +16 lines)
Lines 279-286 Link Here
279
    CFile file;
279
    CFile file;
280
    byte *filedata = 0;
280
    byte *filedata = 0;
281
    char *fullname = 0;
281
    char *fullname = 0;
282
    try
283
    {
284
        while (!m_BlockRequests_queue.IsEmpty())
282
        while (!m_BlockRequests_queue.IsEmpty())
285
        {
283
        {
286
            Requested_Block_Struct *currentblock = m_BlockRequests_queue.GetHead();
284
            Requested_Block_Struct *currentblock = m_BlockRequests_queue.GetHead();
Lines 313-320 Link Here
313
            if (!srcfile -> IsPartFile())
311
            if (!srcfile -> IsPartFile())
314
            {
312
            {
315
                //CFile::modeRead|CFile::osSequentialScan|CFile::shareDenyNone)):
313
                //CFile::modeRead|CFile::osSequentialScan|CFile::shareDenyNone)):
316
                if (!file.Open(fullname, CFile:: read))
314
                if (!file.Open(fullname, CFile:: read)) {
317
                throw GetResString(IDS_ERR_OPEN);
315
                throw GetResString(IDS_ERR_OPEN);
316
		}
318
                delete[] fullname;
317
                delete[] fullname;
319
                fullname = 0;
318
                fullname = 0;
320
                file.Seek(currentblock -> StartOffset);
319
                file.Seek(currentblock -> StartOffset);
Lines 331-367 Link Here
331
                CPartFile *partfile = (CPartFile *) srcfile;
330
                CPartFile *partfile = (CPartFile *) srcfile;
332
                delete[] fullname;
331
                delete[] fullname;
333
                fullname = 0;
332
                fullname = 0;
334
                partfile -> m_hpartfile.Seek(currentblock -> StartOffset);
333
                partfile -> Seek(currentblock -> StartOffset);
335
                filedata = new byte[togo + 500];
334
                filedata = new byte[togo + 500];
336
                if (uint32 done = partfile -> m_hpartfile.Read(filedata, togo) != togo)
335
                if (uint32 done = partfile -> Read(filedata, togo) != togo)
337
                {
336
                {
338
                    partfile -> m_hpartfile.Seek(0);
337
                    partfile -> Seek(0);
339
                    partfile -> m_hpartfile.Read(filedata + done, togo - done);
338
                    (void)partfile -> Read(filedata + done, togo - done);
340
                }
339
                }
341
            }
340
            }
342
            SetUploadFileID(currentblock -> FileID);
341
            SetUploadFileID(currentblock -> FileID);
343
            if (m_byDataCompVer == 1 && (!strstr(srcfile -> GetFileName(), ".zip")) && (!strstr(srcfile -> GetFileName(), ".rar")) && (!strstr(srcfile -> GetFileName(), ".ace")))
342
            if (m_byDataCompVer == 1 && (!strstr(srcfile -> GetFileName(), ".zip")) && (!strstr(srcfile -> GetFileName(), ".rar")) && (!strstr(srcfile -> GetFileName(), ".ace"))) {
344
            CreatePackedPackets(filedata, togo, currentblock);
343
            CreatePackedPackets(filedata, togo, currentblock);
345
            else
344
            } else {
346
            CreateStandartPackets(filedata, togo, currentblock);
345
            CreateStandartPackets(filedata, togo, currentblock);
346
		}
347
            // file statistic
347
            // file statistic
348
            srcfile -> statistic.AddTransferred(togo);
348
            srcfile -> statistic.AddTransferred(togo);
349
            m_DoneBlocks_list.AddHead(m_BlockRequests_queue.RemoveHead());
349
            m_DoneBlocks_list.AddHead(m_BlockRequests_queue.RemoveHead());
350
            delete[] filedata;
350
            delete[] filedata;
351
            filedata = 0;
351
            filedata = 0;
352
        }
352
        }
353
    }
354
    catch(wxString error)
355
    {
356
        theApp.xmuledlg -> AddDebugLogLine(false, GetResString(IDS_ERR_CLIENTERRORED), GetUserName(), error.GetData());
357
        theApp.uploadqueue -> RemoveFromUploadQueue(this);
358
        if (filedata)
359
        delete filedata;
360
        if (fullname)
361
        delete[] fullname;
362
        return false;
363
    }
364
    //	theApp.xmuledlg->AddDebugLogLine(false,"Debug: Packet done. Size: %i",blockpack->GetLength());
365
    return true;
353
    return true;
366
}
354
}
367
355
Lines 458-471 Link Here
458
    CMemFile memfile(output, newsize);
446
    CMemFile memfile(output, newsize);
459
    togo = newsize;
447
    togo = newsize;
460
    uint32 nPacketSize;
448
    uint32 nPacketSize;
461
    if (togo > 10240)
449
    if (togo > 10240) {
462
    nPacketSize = togo/ (uint32)(togo/10240);
450
    nPacketSize = togo/ (uint32)(togo/10240);
463
    else
451
    } else {
464
    nPacketSize = togo;
452
    nPacketSize = togo;
453
	}
465
    while (togo)
454
    while (togo)
466
    {
455
    {
467
        if (togo < nPacketSize *2)
456
        if (togo < nPacketSize *2) {
468
        nPacketSize = togo;
457
        nPacketSize = togo;
458
	}
469
        togo -= nPacketSize;
459
        togo -= nPacketSize;
470
        Packet *packet = new Packet(OP_COMPRESSEDPART, nPacketSize + 24, OP_EMULEPROT);
460
        Packet *packet = new Packet(OP_COMPRESSEDPART, nPacketSize + 24, OP_EMULEPROT);
471
        memcpy( &packet -> pBuffer[0], GetUploadFileID(), 16);
461
        memcpy( &packet -> pBuffer[0], GetUploadFileID(), 16);
Lines 484-491 Link Here
484
    if (tempreqfileid)
474
    if (tempreqfileid)
485
    newreqfile = theApp.sharedfiles -> GetFileByID(tempreqfileid);
475
    newreqfile = theApp.sharedfiles -> GetFileByID(tempreqfileid);
486
    CKnownFile *oldreqfile = theApp.sharedfiles -> GetFileByID(requpfileid);
476
    CKnownFile *oldreqfile = theApp.sharedfiles -> GetFileByID(requpfileid);
487
    if (newreqfile == oldreqfile)
477
    if (newreqfile == oldreqfile) {
488
    return;
478
    return;
479
	}
489
    if (newreqfile)
480
    if (newreqfile)
490
    {
481
    {
491
        newreqfile -> AddQueuedCount();
482
        newreqfile -> AddQueuedCount();
(-)xmule/src/opcodes.h (-2 / +10 lines)
Lines 30-36 Link Here
30
#define WM_APP 5500
30
#define WM_APP 5500
31
31
32
//release:#define MOD_VERSION             "xMule"
32
//release:#define MOD_VERSION             "xMule"
33
#define MOD_VERSION             "xMule 1.8.2c"
33
#define MOD_VERSION             "xMule"
34
#define ET_MOD_VERSION 			0x55
34
#define ET_MOD_VERSION 			0x55
35
// MOD Note: Do not change this part - Merkur
35
// MOD Note: Do not change this part - Merkur
36
#define CURRENT_VERSION_SHORT	0x30
36
#define CURRENT_VERSION_SHORT	0x30
Lines 40-47 Link Here
40
#define	EDONKEYVERSION			0x3c
40
#define	EDONKEYVERSION			0x3c
41
#define PREFFILE_VERSION		0x14	//<<-- last change: reduced .dat, by using .ini
41
#define PREFFILE_VERSION		0x14	//<<-- last change: reduced .dat, by using .ini
42
#define PARTFILE_VERSION		0xe0
42
#define PARTFILE_VERSION		0xe0
43
#define PARTFILE_SPLITTEDVERSION	0xe1
43
#define CREDITFILE_VERSION		0x12
44
#define CREDITFILE_VERSION		0x12
44
#define CREDITFILE_VERSION_29		0x11
45
#define CREDITFILE_VERSION_29		0x11
46
#define VERSION_MJR			0x00
47
#define VERSION_MIN			0x28
48
#define VERSION_UPDATE			0x02
49
#define VERSION_BUILD			0x01
45
#define COMPILE_DATE			__DATE__
50
#define COMPILE_DATE			__DATE__
46
#define COMPILE_TIME			__TIME__
51
#define COMPILE_TIME			__TIME__
47
#ifdef _DEBUG
52
#ifdef _DEBUG
Lines 62-67 Link Here
62
#define SERVERREASKTIME			800000  // don't set this too low, it wont speed up anything, but it could kill xmule or your internetconnection
67
#define SERVERREASKTIME			800000  // don't set this too low, it wont speed up anything, but it could kill xmule or your internetconnection
63
#define UDPSERVERREASKTIME		1300000	// ***
68
#define UDPSERVERREASKTIME		1300000	// ***
64
#define SOURCECLIENTREASK		600000
69
#define SOURCECLIENTREASK		600000
70
#define SOURCESWAPTIME			30000
65
#define MINCOMMONPENALTY		9
71
#define MINCOMMONPENALTY		9
66
#define UDPSERVERSTATTIME		5000
72
#define UDPSERVERSTATTIME		5000
67
#define UDPSERVSTATREASKTIME	14400000
73
#define UDPSERVSTATREASKTIME	14400000
Lines 237-243 Link Here
237
#define FT_SOURCES				0x15
243
#define FT_SOURCES				0x15
238
#define FT_PERMISSIONS			0x16
244
#define FT_PERMISSIONS			0x16
239
#define FT_OLDULPRIORITY			0x17
245
#define FT_OLDULPRIORITY			0x17
240
#define FT_CATEGORY 			0x53
241
#define FT_DLPRIORITY			0x18	// Was 13
246
#define FT_DLPRIORITY			0x18	// Was 13
242
#define FT_ULPRIORITY			0x19	// Was 17
247
#define FT_ULPRIORITY			0x19	// Was 17
243
248
Lines 246-253 Link Here
246
#define FT_ATTRANSFERED			0x50
251
#define FT_ATTRANSFERED			0x50
247
#define FT_ATREQUESTED			0x51
252
#define FT_ATREQUESTED			0x51
248
#define FT_ATACCEPTED			0x52
253
#define FT_ATACCEPTED			0x52
254
#define FT_CATEGORY 			0x53
249
#define	FT_ATTRANSFEREDHI		0x54
255
#define	FT_ATTRANSFEREDHI		0x54
250
256
257
#define FT_DYNAMIC			0xc1
258
251
#define CT_NAME					0x01
259
#define CT_NAME					0x01
252
#define	CT_PORT					0x0f
260
#define	CT_PORT					0x0f
253
#define CT_VERSION				0x11
261
#define CT_VERSION				0x11
(-)xmule/src/resource/newprefs01.pm (-4 / +5 lines)
Lines 1-12 Link Here
1
0,New Preferences
1
0,New Preferences
2
-1,separator
2
-1,separator
3
20101,Secure Identification on/off 
3
20101,Secure Identification active
4
20106,Automatic-Random-Privatekey-Generator
4
20106,Automatic-Random-Privatekey-Generator
5
20107,Renew userhash on start:
5
-1,separator
6
-1,separator
6
20102,Source-Exchange on/off
7
20102,Source-Exchange active
7
-1,separator
8
-1,separator
8
20103,xMule-Identification as eMule on/off
9
20103,xMule-Identification as eMule 
9
-1,separator
10
-1,separator
10
20104,Disconnect xMule from ed2k-Network
11
20104,Disconnect xMule from ed2k-Network
11
-1,separator
12
-1,separator
12
20105,Compressed Partfile-Support
13
20105,Dynamic Partfile-Support
(-)xmule/src/resource.h (+1 lines)
Lines 1057-1062 Link Here
1057
#define IDS_FILTER                      1005
1057
#define IDS_FILTER                      1005
1058
#define IDS_CHANGECATVIEW               1025
1058
#define IDS_CHANGECATVIEW               1025
1059
#define IDS_STATUS_NOTCOMPLETED         1026
1059
#define IDS_STATUS_NOTCOMPLETED         1026
1060
#define IDS_CONVERTING			1027
1060
#define IDD_FLOWCHART			1109
1061
#define IDD_FLOWCHART			1109
1061
#define IDC_ANIMATE1                    2000
1062
#define IDC_ANIMATE1                    2000
1062
#define IDC_STATUS                      2001
1063
#define IDC_STATUS                      2001
(-)xmule/src/strings.en (+1 lines)
Lines 269-274 Link Here
269
{IDS_HASHING,             "Hashing"},
269
{IDS_HASHING,             "Hashing"},
270
{IDS_COMPLETING,          "Completing"},
270
{IDS_COMPLETING,          "Completing"},
271
{IDS_COMPLETE,            "Complete"},
271
{IDS_COMPLETE,            "Complete"},
272
{IDS_CONVERTING,          "Converting"},
272
{IDS_PAUSED,              "Paused"},
273
{IDS_PAUSED,              "Paused"},
273
{IDS_ERRORLIKE,           "Erroneous"},
274
{IDS_ERRORLIKE,           "Erroneous"},
274
{IDS_LFILES,              "files"},
275
{IDS_LFILES,              "files"},
(-)xmule/src/xmuleDlg.cpp (+1 lines)
Lines 203-208 Link Here
203
    sharedfileswnd -> Show(FALSE);
203
    sharedfileswnd -> Show(FALSE);
204
    statisticswnd -> Show(FALSE);
204
    statisticswnd -> Show(FALSE);
205
    chatwnd -> Show(FALSE);
205
    chatwnd -> Show(FALSE);
206
    flowchartwnd -> Show(FALSE);
206
    SetActiveDialog(serverwnd);
207
    SetActiveDialog(serverwnd);
207
    m_nActiveDialog = 1;
208
    m_nActiveDialog = 1;
208
    // can't init now
209
    // can't init now

Return to bug 53638