1 //
2 // C++ Implementation: DownloadFile
3 //
4 // Description: Implements the classes DownloadList and DownloadFile.
5 // It's this classes which keep all the downloads informations,
6 // like URL, size name, etc
7 //
8 //
9 // Author: Max Magalhães Velasques <maxvelasques@gmail.com>, (C) 2006
10 //
11 // Copyright: See COPYING file that comes with this distribution
12 //
13 //
14
15 #include "wxDFast.h"
16
RecreateIndex()17 void mDownloadList::RecreateIndex()
18 {
19 int i=0;
20 for ( mDownloadList::Node *node = this->GetFirst(); node; node = node->GetNext() )
21 {
22 mDownloadFile *current = node->GetData();
23 if (current->index != i)
24 {
25 current->index = i;
26 current->changedsincelastsave = true;
27 current->RegisterListItemOnDisk();
28 }
29 i++;
30 }
31 }
32
ChangePosition(mDownloadFile * file01,mDownloadFile * file02)33 void mDownloadList::ChangePosition(mDownloadFile *file01, mDownloadFile *file02)
34 {
35 int index01,index02;
36 index01 = file01->index;
37 index02 = file02->index;
38 file01->index = index02;
39 file02->index = index01;
40
41 Sort(mDownloadList::ListCompareByIndex);
42 }
43
ChangeName(mDownloadFile * file,wxString name,int value)44 void mDownloadList::ChangeName(mDownloadFile *file, wxString name, int value)
45 {
46 wxString strname = name;
47 if (file->name == strname)
48 return ;
49 #ifdef WXDFAST_PORTABLE
50 wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
51 wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
52 #else
53 wxFileConfig *config = new wxFileConfig(DFAST_REG);
54 #endif
55 config->SetPath(INPROGRESS_REG);
56 config->DeleteGroup(file->name);
57 delete config;
58 if (value > 0)
59 strname = MyUtilFunctions::int2wxstr(value+1) + wxT("-") + strname;
60 if (this->FindDownloadFile(strname))
61 {
62 this->ChangeName(file,name,value+1);
63 }
64 else
65 {
66 file->name = strname;
67 file->MarkWriteAsPending(TRUE);
68 }
69 }
70
ChangeDownload(mDownloadFile * file,mUrlList * urllist,wxFileName destination,wxString user,wxString password,wxString reference,wxString comments,wxString command,int bandwidth)71 void mDownloadList::ChangeDownload(mDownloadFile *file, mUrlList *urllist,wxFileName destination, wxString user, wxString password,wxString reference, wxString comments,wxString command,int bandwidth)
72 {
73 if (file->urllist)
74 delete file->urllist;
75 file->urllist->DeleteContents(TRUE);
76 file->urllist = urllist;
77 file->destination = destination.GetPath(wxPATH_GET_VOLUME|wxPATH_GET_SEPARATOR);
78 file->user = user;
79 file->password = password;
80 file->reference = reference;
81 file->command = command;
82 file->comments = comments;
83 file->bandwidth = bandwidth;
84 file->MarkWriteAsPending(TRUE);
85 }
86
LoadDownloadListFromDisk()87 void mDownloadList::LoadDownloadListFromDisk()
88 {
89 #ifdef WXDFAST_PORTABLE
90 wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
91 wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
92 #else
93 wxFileConfig *config = new wxFileConfig(DFAST_REG);
94 #endif
95 wxString name;
96 wxString tmp;
97 int status;
98 long index;
99 config->SetPath(INPROGRESS_REG);
100 if (config->GetFirstGroup(name, index))
101 {
102
103 do
104 {
105 mDownloadFile *file = new mDownloadFile();
106 file->name = name;
107 this->Append(file);
108 }
109 while(config->GetNextGroup(name, index));
110 }
111 for ( mDownloadList::Node *node = this->GetFirst(); node; node = node->GetNext() )
112 {
113 mDownloadFile *file = node->GetData();
114 tmp = wxEmptyString;
115 config->SetPath(file->GetName());
116 config->Read(INDEX_REG,&(file->index));
117
118 config->Read(STATUS_REG,&(status));
119 config->Read(SCHEDULED_REG,&(file->scheduled));
120 if (status == STATUS_STOPED)
121 file->SetAsStoped();
122 else if ((status == STATUS_ACTIVE) || (status == STATUS_QUEUE))
123 file->PutOnQueue();
124 else if (status == STATUS_FINISHED)
125 file->SetAsFinished();
126 else if (status == STATUS_ERROR)
127 file->ErrorOccurred();
128 else if ((status == STATUS_SCHEDULE_QUEUE) || (file->scheduled))
129 file->PutOnScheduleQueue();
130 else
131 file->SetAsStoped();
132
133 config->Read(RESTART_REG,&(file->restart));
134 config->Read(PARTS_REG,&(file->parts));
135 if (file->parts > MAX_NUM_PARTS)
136 file->parts = 1;
137
138 config->Read(DESTINATION_REG,&(file->destination));
139 #ifdef WXDFAST_PORTABLE
140 {
141 #ifdef __WXMSW__
142 wxFileName destinationtmp(file->destination);
143 if (destinationtmp.GetVolume().Upper() == wxT("PORTABLE"))
144 {
145 destinationtmp.SetVolume(wxGetApp().programvolume);
146 file->destination = destinationtmp.GetFullPath();
147 }
148 #endif
149 }
150 #endif
151
152 config->Read(TEMPDESTINATION_REG,&(file->tempdestination));
153
154 //TOTAL SIZE
155 config->Read(SIZE_REG,&tmp);
156 file->totalsize = MyUtilFunctions::wxstrtolonglong(tmp);
157
158 //TOTAL SIZE COMPLETED
159 config->Read(SIZECOMPLETED_REG,&tmp);
160 file->totalsizecompleted = MyUtilFunctions::wxstrtolonglong(tmp);
161
162 //EACH PART SIZE AND SIZECOMPLETED
163 for (int i = 0 ; i < file->parts ; i++)
164 {
165 tmp = wxT("0");
166 config->Read(SIZEPART_REG + MyUtilFunctions::int2wxstr(i+1),&tmp);
167 file->size[i] = MyUtilFunctions::wxstrtolonglong(tmp);
168
169 tmp = wxT("0");
170 config->Read(SIZEPARTCOMPLETED_REG + MyUtilFunctions::int2wxstr(i+1),&tmp);
171 file->sizecompleted[i] = MyUtilFunctions::wxstrtolonglong(tmp);
172 }
173
174 config->Read(TIMEPASSED_REG,&tmp);
175 file->timepassed = MyUtilFunctions::wxstrtolonglong(tmp);
176
177 config->Read(SPEED_REG,&(file->totalspeed));
178 config->Read(PERCENTUAL_REG,&(file->percentual));
179 config->Read(MD5_REG,&(file->MD5));
180 config->Read(COMMENTS_REG,&(file->comments));
181 config->Read(REFERENCE_REG,&(file->reference));
182 config->Read(COMMAND_REG,&(file->command));
183
184 config->Read(CONTENTTYPE_REG,&(file->contenttype));
185 {
186 time_t value = 0;
187 config->Read(START_REG,&(value));
188 file->start.Set(value);
189 value = 0;
190 config->Read(END_REG,&(value));
191 file->end.Set(value);
192 }
193 file->bandwidth = 0;
194 config->Read(BANDWIDTH_REG,&(file->bandwidth));
195 file->metalinkindex = -1;
196 config->Read(METALINK_INDEX_REG,&(file->metalinkindex));
197
198 file->urllist = new mUrlList();
199 file->urllist->DeleteContents(TRUE);
200 file->currenturl = 0;
201 bool existurl = TRUE;
202 int count = 1;
203 wxString str;
204 while (existurl)
205 {
206 str = wxEmptyString;
207 config->Read(URL_REG + MyUtilFunctions::int2wxstr(count),&(str));
208 if (str.IsEmpty())
209 break;
210 else
211 {
212 mUrlName *urltmp = new mUrlName(str);
213 if (urltmp->IsComplete())
214 file->urllist->Append(urltmp);
215 }
216 count++;
217 }
218
219 if (file->percentual > 100)
220 file->percentual = 0;
221 file->timeremaining = 0;
222 file->totalspeed = 0;
223 file->currentattempt = 0;
224 file->free = TRUE;
225 file->criticalerror = FALSE;
226 file->split = FALSE;
227 file->waitbeforesplit = FALSE;
228 file->changedsincelastsave = false;
229 file->MarkWriteAsPending(FALSE);
230 file->MarkRemoveAsPending(FALSE);
231 if ((file->parts < 1) || (file->parts > MAX_NUM_PARTS))
232 file->parts = 1;
233 file->metalinkdata = NULL;
234 config->Read(NEED_TO_REGET_METALINK_REG,&(file->needtoregetmetalink));
235
236 for (int i =0;i<MAX_NUM_PARTS;i++)
237 {
238
239 file->messages[i].Clear();
240 file->delta_size[i] = 0;
241 //file->sizecompleted[i] = 0;
242 file->percentualparts[i] = 0;
243 file->startpoint[i] = 0;
244 //file->size[i] = 0;
245 file->finished[i] = FALSE;
246 }
247
248 config->Read(USER_REG,&(file->user));
249 config->Read(PASSWORD_REG,&(file->password));
250
251 config->SetPath(BACK_DIR_REG);
252 }
253 this->Sort(mDownloadList::ListCompareByIndex);
254 delete config;
255 }
256
RemoveDownloadRegister(mDownloadFile * currentfile)257 void mDownloadList::RemoveDownloadRegister(mDownloadFile *currentfile)
258 {
259 /*unsigned int item = this->IndexOf(currentfile);
260 if ((item + 1) < this->GetCount())
261 {
262 int count = item;
263 for ( mDownloadList::Node *node = this->Item(item+1); node; node = node->GetNext() )
264 {
265 node->GetData()->index = count;
266 node->GetData()->MarkWriteAsPending(TRUE);
267 count++;
268 }
269 }*/
270 mDownloadList::Node *node = this->Find(currentfile);
271 this->DeleteNode(node);
272 }
273
FindDownloadFile(wxString str)274 mDownloadFile *mDownloadList::FindDownloadFile(wxString str)
275 {
276 for ( mDownloadList::Node *node = this->GetFirst(); node; node = node->GetNext() )
277 if (node->GetData()->GetName().Lower() == str.Lower())
278 return (node->GetData());
279 return (NULL);
280 }
281
ListCompareByIndex(const mDownloadFile ** arg1,const mDownloadFile ** arg2)282 int mDownloadList::ListCompareByIndex(const mDownloadFile** arg1, const mDownloadFile** arg2)
283 {
284 if ((*arg1)->index > (*arg2)->index)
285 return 1;
286 else
287 return -1;
288 }
289
NewDownloadRegister(mUrlList * urllist,wxFileName destination,wxFileName tempdestination,int metalinkindex,int parts,wxString user,wxString password,wxString reference,wxString comments,wxString command,int scheduled,int bandwidth,int ontop)290 mDownloadFile *mDownloadList::NewDownloadRegister(mUrlList *urllist,wxFileName destination,wxFileName tempdestination, int metalinkindex, int parts, wxString user, wxString password, wxString reference, wxString comments,wxString command,int scheduled,int bandwidth,int ontop)
291 {
292 mDownloadFile *file = new mDownloadFile();
293 file->metalinkdata = NULL;
294 file->needtoregetmetalink = FALSE;
295 if (this->GetCount() > 0)
296 {
297 if (ontop)
298 file->index = this->GetFirst()->GetData()->index-1;
299 else
300 file->index = this->GetLast()->GetData()->index+1;
301 }
302 else
303 file->index = 0;
304 file->scheduled = scheduled;
305 file->status = STATUS_STOPED;
306 file->restart = -1;
307 file->parts = parts;
308 file->urllist = urllist;
309 file->urllist->DeleteContents(TRUE);
310 file->currenturl = 0;
311 if (metalinkindex > 0)
312 file->name = MyUtilFunctions::int2wxstr(metalinkindex) + file->GetFirstUrl().GetFullName();
313 else
314 file->name = file->GetFirstUrl().GetFullName();
315 file->destination = destination.GetFullPath();
316 file->tempdestination = tempdestination.GetFullPath();
317 file->command = command;
318 file->totalsize = 0;
319 file->totalsizecompleted = 0;
320 file->comments = comments;
321 file->reference = reference;
322 file->percentual = 0;
323 file->timepassed = 0;
324 file->timeremaining = 0;
325 file->totalspeed = 0;
326 file->contenttype = wxEmptyString;
327 file->MD5 = wxEmptyString;
328 file->start = wxDateTime::Now();
329 file->end = wxDateTime::Now();
330 file->currentattempt = 0;
331 for (int i =0;i<MAX_NUM_PARTS;i++)
332 {
333 file->messages[i].Clear();
334 file->delta_size[i] = 0;
335 file->sizecompleted[i] = 0;
336 file->percentualparts[i] = 0;
337 file->startpoint[i] = 0;
338 file->size[i] = 0;
339 file->finished[i] = FALSE;
340 }
341 /*if (user.IsEmpty())
342 {
343 file->user = ANONYMOUS_USER;
344 file->password = ANONYMOUS_PASS;
345 }
346 else
347 {*/
348 file->user = user;
349 file->password = password;
350 file->bandwidth = bandwidth;
351 file->free = TRUE;
352 file->criticalerror = FALSE;
353 file->split = FALSE;
354 file->waitbeforesplit = TRUE;
355 file->metalinkindex = metalinkindex;
356
357 file->MarkWriteAsPending(TRUE);
358 file->MarkRemoveAsPending(FALSE);
359 if (ontop)
360 this->Insert(file);
361 else
362 this->Append(file);
363 return file;
364 }
365
GetNumberofActiveDownloads()366 int mDownloadList::GetNumberofActiveDownloads()
367 {
368 if (numberofactivedownloads < 1)
369 return 1;
370 return numberofactivedownloads;
371 }
372
SetNumberofActiveDownloads(int number)373 void mDownloadList::SetNumberofActiveDownloads(int number)
374 {
375 numberofactivedownloads = number;
376 }
377
RemoveListItemFromDisk()378 void mDownloadFile::RemoveListItemFromDisk()
379 {
380 #ifdef WXDFAST_PORTABLE
381 wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
382 wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
383 #else
384 wxFileConfig *config = new wxFileConfig(DFAST_REG);
385 #endif
386 config->SetPath(FILES_REG);
387 if (this->status == STATUS_FINISHED)
388 {
389 config->SetPath(BACK_DIR_REG);
390 config->SetPath(INPROGRESS_REG);
391 config->DeleteGroup(this->name);
392 config->SetPath(BACK_DIR_REG);
393 config->SetPath(BACK_DIR_REG);
394 config->SetPath(FINISHED_REG);
395
396 }
397 else
398 {
399 config->SetPath(BACK_DIR_REG);
400 config->SetPath(INPROGRESS_REG);
401 }
402 config->DeleteGroup(this->name);
403 delete config;
404 this->MarkRemoveAsPending(FALSE);
405 }
406
RegisterListItemOnDisk()407 void mDownloadFile::RegisterListItemOnDisk()
408 {
409 if (changedsincelastsave)
410 {
411 #ifdef WXDFAST_PORTABLE
412 wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
413 wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
414 #else
415 wxFileConfig *config = new wxFileConfig(DFAST_REG);
416 #endif
417 config->SetPath(FILES_REG);
418 if (this->status == STATUS_FINISHED)
419 {
420 config->SetPath(BACK_DIR_REG);
421 config->SetPath(INPROGRESS_REG);
422 config->DeleteGroup(this->name);
423 config->SetPath(BACK_DIR_REG);
424 config->SetPath(BACK_DIR_REG);
425 config->SetPath(FINISHED_REG);
426
427 }
428 else
429 {
430 config->SetPath(BACK_DIR_REG);
431 config->SetPath(INPROGRESS_REG);
432 }
433 config->SetPath(this->name);
434 config->Write(NAME_REG,this->name);
435 config->Write(INDEX_REG,this->index);
436 config->Write(STATUS_REG,this->status);
437 config->Write(SCHEDULED_REG,this->scheduled);
438 config->Write(RESTART_REG,this->restart);
439 config->Write(PARTS_REG,this->parts);
440 #ifdef WXDFAST_PORTABLE
441 {
442 #ifdef __WXMSW__
443 wxFileName destinationtmp(this->destination);
444 if (destinationtmp.GetVolume().Lower() == wxGetApp().programvolume.Lower())
445 {
446 destinationtmp.SetVolume(wxEmptyString);
447 config->Write(DESTINATION_REG,wxT("PORTABLE:") + destinationtmp.GetFullPath());
448 }
449 else
450 config->Write(DESTINATION_REG,this->destination);
451 #else
452 config->Write(DESTINATION_REG,this->destination);
453 #endif
454 }
455 #else
456 config->Write(DESTINATION_REG,this->destination);
457 #endif
458 config->Write(TEMPDESTINATION_REG,this->tempdestination);
459 config->Write(SIZE_REG,this->totalsize.ToString());
460 config->Write(SIZECOMPLETED_REG,this->totalsizecompleted.ToString());
461
462 //EACH PART SIZE AND SIZECOMPLETED
463 for (int i = 0 ; i < this->parts ; i++)
464 {
465 config->Write(SIZEPART_REG + MyUtilFunctions::int2wxstr(i+1),this->size[i].ToString());
466 config->Write(SIZEPARTCOMPLETED_REG + MyUtilFunctions::int2wxstr(i+1),this->sizecompleted[i].ToString());
467 }
468
469 config->Write(TIMEPASSED_REG,this->timepassed.ToString());
470 config->Write(SPEED_REG,this->totalspeed);
471 config->Write(PERCENTUAL_REG,this->percentual);
472 config->Write(MD5_REG,this->MD5);
473 config->Write(START_REG,this->start.GetTicks());
474 config->Write(END_REG,this->end.GetTicks());
475 config->Write(COMMENTS_REG,this->comments);
476 config->Write(REFERENCE_REG,this->reference);
477 config->Write(COMMAND_REG,this->command);
478 config->Write(CONTENTTYPE_REG,this->contenttype);
479 config->Write(BANDWIDTH_REG,this->bandwidth);
480 config->Write(NEED_TO_REGET_METALINK_REG,this->needtoregetmetalink);
481 config->Write(METALINK_INDEX_REG,this->metalinkindex);
482
483 unsigned int count = 1;
484 bool deleteoldurls = TRUE;
485 wxString str;
486 for ( mUrlList::Node *node = urllist->GetFirst(); node; node = node->GetNext() )
487 {
488 config->Write(URL_REG + MyUtilFunctions::int2wxstr(count),node->GetData()->GetFullPath());
489 count++;
490 }
491 while (deleteoldurls) //THIS ERASE URLS THAT WAS WRITE BEFORE, BUT THAT DOESN'T WAS REWRITE NOW
492 {
493 str = wxEmptyString;
494 config->Read(URL_REG + MyUtilFunctions::int2wxstr(count),&(str));
495 if (str.IsEmpty())
496 break;
497 else
498 config->DeleteEntry(URL_REG + MyUtilFunctions::int2wxstr(count));
499 }
500
501 config->Write(USER_REG,this->user);
502 config->Write(PASSWORD_REG,this->password);
503
504 delete config;
505 changedsincelastsave = false;
506 }
507 this->MarkWriteAsPending(FALSE);
508 }
509
GetName()510 wxString mDownloadFile::GetName()
511 {
512 return this->name;
513 }
514
GetExposedName()515 wxString mDownloadFile::GetExposedName()
516 {
517 if (this->exposedname != wxEmptyString)
518 return this->exposedname;
519 else
520 return this->name;
521 }
522
SetExposedName(wxString name)523 void mDownloadFile::SetExposedName(wxString name)
524 {
525 this->exposedname = name;
526 }
527
UnSetExposedName()528 void mDownloadFile::UnSetExposedName()
529 {
530 this->exposedname = wxEmptyString;
531 }
532
GetStatus()533 int mDownloadFile::GetStatus()
534 {
535 return this->status;
536 }
537
SetAsActive()538 void mDownloadFile::SetAsActive()
539 {
540 changedsincelastsave = true;
541 this->status = STATUS_ACTIVE;
542 }
543
SetAsStoped(bool stopschedule)544 void mDownloadFile::SetAsStoped(bool stopschedule)
545 {
546 changedsincelastsave = true;
547 this->status = STATUS_STOPED;
548 if (stopschedule)
549 this->scheduled = FALSE;
550 }
551
SetAsFinished()552 void mDownloadFile::SetAsFinished()
553 {
554 changedsincelastsave = true;
555 this->status = STATUS_FINISHED;
556 }
557
ErrorOccurred()558 void mDownloadFile::ErrorOccurred()
559 {
560 changedsincelastsave = true;
561 this->status = STATUS_ERROR;
562 }
563
PutOnScheduleQueue()564 void mDownloadFile::PutOnScheduleQueue()
565 {
566 changedsincelastsave = true;
567 this->scheduled = TRUE;
568 this->status = STATUS_SCHEDULE_QUEUE;
569 }
570
PutOnQueue()571 void mDownloadFile::PutOnQueue()
572 {
573 changedsincelastsave = true;
574 this->scheduled = FALSE;
575 this->status = STATUS_QUEUE;
576 }
577
GetDestination()578 wxString mDownloadFile::GetDestination()
579 {
580 return this->destination;
581 }
582
GetTemporaryDestination()583 wxString mDownloadFile::GetTemporaryDestination()
584 {
585 if (this->tempdestination.IsEmpty())
586 return this->destination;
587 else
588 return this->tempdestination;
589 }
590
GetReferenceURL()591 wxString mDownloadFile::GetReferenceURL()
592 {
593 return this->reference;
594 }
595
GetComments()596 wxString mDownloadFile::GetComments()
597 {
598 return this->comments;
599 }
600
GetUser()601 wxString mDownloadFile::GetUser()
602 {
603 return this->user;
604 }
605
GetPassword()606 wxString mDownloadFile::GetPassword()
607 {
608 return this->password;
609 }
610
RestartSupport()611 int mDownloadFile::RestartSupport()
612 {
613 return this->restart;
614 }
615
SetRestartSupport(bool support)616 void mDownloadFile::SetRestartSupport(bool support)
617 {
618 changedsincelastsave = true;
619 if (support)
620 this->restart = YES;
621 else
622 this->restart = NO;
623 }
624
IsScheduled()625 bool mDownloadFile::IsScheduled()
626 {
627 return this->scheduled;
628 }
629
GetContentType()630 wxString mDownloadFile::GetContentType()
631 {
632 return this->contenttype;
633 }
634
SetContentType(wxString contenttype)635 void mDownloadFile::SetContentType(wxString contenttype)
636 {
637 changedsincelastsave = true;
638 this->contenttype = contenttype;
639 }
640
IsHtml()641 bool mDownloadFile::IsHtml()
642 {
643 return this->GetContentType().Lower().Contains(wxT("html"));
644 }
645
IsMetalink()646 bool mDownloadFile::IsMetalink()
647 {
648 bool result = FALSE;
649 if ((this->GetContentType().Lower().Contains(wxT("metalink"))) ||
650 (this->name.Lower().Contains(wxT("metalink"))))
651 result = TRUE;
652 return result;
653 }
654
IsZip()655 bool mDownloadFile::IsZip()
656 {
657 return (this->GetContentType().Lower().Contains(wxT("zip"))
658 & this->GetName().Lower().Contains(wxT(".zip"))) ;
659 }
660
GetNumberofParts()661 int mDownloadFile::GetNumberofParts()
662 {
663 return this->parts;
664 }
665
GetCurrentAttempt()666 int mDownloadFile::GetCurrentAttempt()
667 {
668 return this->currentattempt;
669 }
670
ResetAttempts()671 void mDownloadFile::ResetAttempts()
672 {
673 changedsincelastsave = true;
674 this->currentattempt = 1;
675 }
676
IncrementAttempt()677 void mDownloadFile::IncrementAttempt()
678 {
679 changedsincelastsave = true;
680 this->currentattempt++;
681 }
682
GetNextUrl()683 mUrlName mDownloadFile::GetNextUrl()
684 {
685 mUrlName urltmp;
686 mUrlList::Node *node;
687 if (metalinkdata)
688 {
689 if (metalinkdata->urllist.GetCount() > this->currenturl)
690 {
691 node = metalinkdata->urllist.Item(this->currenturl);
692 if (node)
693 {
694 this->currenturl++;
695 return *(node->GetData());
696 }
697 else
698 {
699 currenturl = 1;
700 return this->GetFirstUrl();
701 }
702 }
703 else
704 {
705 currenturl = 1;
706 return this->GetFirstUrl();
707 }
708 }
709
710 if (!this->urllist)
711 return urltmp;
712 if (this->urllist->GetCount() > this->currenturl)
713 {
714 node = this->urllist->Item(this->currenturl);
715 if (node)
716 {
717 this->currenturl++;
718 return *(node->GetData());
719 }
720 else
721 {
722 currenturl = 1;
723 return this->GetFirstUrl();
724 }
725 }
726 else
727 {
728 currenturl = 1;
729 return this->GetFirstUrl();
730 }
731 }
732
GetFirstUrl()733 mUrlName mDownloadFile::GetFirstUrl()
734 {
735 mUrlName urltmp;
736 mUrlList::Node *node;
737 if (metalinkdata)
738 {
739 node = metalinkdata->urllist.GetFirst();
740 if (node)
741 {
742 return *(node->GetData());
743 }
744 else
745 {
746 return urltmp;
747 }
748 }
749
750 if (!urllist)
751 return urltmp;
752 node = this->urllist->GetFirst();
753 if (node)
754 {
755 return *(node->GetData());
756 }
757 else
758 {
759 return urltmp;
760 }
761 }
762
AppendUrl(mUrlName * url)763 bool mDownloadFile::AppendUrl(mUrlName *url)
764 {
765 if (url->IsComplete())
766 {
767 this->urllist->Append(url);
768 this->MarkWriteAsPending(TRUE);
769 return TRUE;
770 }
771 else
772 return FALSE;
773 }
774
FindUrl(mUrlName url)775 bool mDownloadFile::FindUrl(mUrlName url)
776 {
777 for ( mUrlList::Node *node = this->urllist->GetFirst(); node; node = node->GetNext() )
778 if (node->GetData()->GetFullPath().Lower() == url.GetFullPath().Lower())
779 return TRUE;
780 return FALSE;
781 }
782
GetUrlCount()783 int mDownloadFile::GetUrlCount()
784 {
785 return this->urllist->GetCount();
786 }
787
GetUrlArray()788 wxArrayString mDownloadFile::GetUrlArray()
789 {
790 wxArrayString urlarray;
791 for ( mUrlList::Node *node = this->urllist->GetFirst(); node; node = node->GetNext() )
792 urlarray.Add(node->GetData()->GetFullPath());
793 return urlarray;
794 }
795
SetFinishedDateTime(wxDateTime time)796 void mDownloadFile::SetFinishedDateTime(wxDateTime time)
797 {
798 changedsincelastsave = true;
799 this->end = time;
800 }
801
GetFinishedDateTime()802 wxDateTime mDownloadFile::GetFinishedDateTime()
803 {
804 return this->end;
805 }
806
SetMD5(wxString md5)807 void mDownloadFile::SetMD5(wxString md5)
808 {
809 changedsincelastsave = true;
810 this->MD5 = md5;
811 }
812
GetProgress()813 int mDownloadFile::GetProgress()
814 {
815 return this->percentual;
816 }
817
SetProgress(int percentual)818 void mDownloadFile::SetProgress(int percentual)
819 {
820 changedsincelastsave = true;
821 this->percentual = percentual;
822 }
823
IsSplitted()824 bool mDownloadFile::IsSplitted()
825 {
826 return this->split;
827 }
828
Split(bool split)829 void mDownloadFile::Split(bool split)
830 {
831 changedsincelastsave = true;
832 this->split = split;
833 this->waitbeforesplit = FALSE;
834 }
835
WaitingForSplit()836 bool mDownloadFile::WaitingForSplit()
837 {
838 return this->waitbeforesplit;
839 }
840
WaitSplit()841 void mDownloadFile::WaitSplit()
842 {
843 this->split = FALSE;
844 this->waitbeforesplit = TRUE;
845 }
846
WriteIsPending()847 bool mDownloadFile::WriteIsPending()
848 {
849 return this->writependig;
850 }
851
MarkWriteAsPending(bool pending)852 void mDownloadFile::MarkWriteAsPending(bool pending)
853 {
854 if (pending)
855 changedsincelastsave = true;
856 this->writependig = pending;
857 }
858
SetFree(bool free)859 void mDownloadFile::SetFree(bool free)
860 {
861 this->free = free;
862 }
863
IsFree()864 bool mDownloadFile::IsFree()
865 {
866 return this->free;
867 }
868
RemoveIsPending()869 bool mDownloadFile::RemoveIsPending()
870 {
871 return this->removepending;
872 }
873
MarkRemoveAsPending(bool pending)874 void mDownloadFile::MarkRemoveAsPending(bool pending)
875 {
876 this->removepending = pending;
877 }
878
SetBandWidth(int band)879 void mDownloadFile::SetBandWidth(int band)
880 {
881 changedsincelastsave = true;
882 bandwidth = band;
883 }
884
GetBandWidth()885 int mDownloadFile::GetBandWidth()
886 {
887 return bandwidth;
888 }
889
NeedToReGetMetalink()890 bool mDownloadFile::NeedToReGetMetalink()
891 {
892 return needtoregetmetalink;
893 }
894
SetToReGetMetalinkWhenNeeded(bool reget)895 void mDownloadFile::SetToReGetMetalinkWhenNeeded(bool reget)
896 {
897 changedsincelastsave = true;
898 needtoregetmetalink = reget;
899 }
900
GetMetalinkFileIndex()901 int mDownloadFile::GetMetalinkFileIndex()
902 {
903 return metalinkindex;
904 }
905
SetMetalinkFileIndex(int index)906 void mDownloadFile::SetMetalinkFileIndex(int index)
907 {
908 changedsincelastsave = true;
909 metalinkindex = index;
910 }
911
GetCommand()912 wxString mDownloadFile::GetCommand()
913 {
914 return command;
915 }
916
SetChangedSinceLastSave()917 void mDownloadFile::SetChangedSinceLastSave()
918 {
919 changedsincelastsave = true;
920 }
921