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) |