Subversion Repositories spk

Rev

Rev 161 | Rev 170 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 161 Rev 162
Line 37... Line 37...
37
			this->listView1->Groups->Add(gcnew ListViewGroup("Packages", HorizontalAlignment::Left));
37
			this->listView1->Groups->Add(gcnew ListViewGroup("Packages", HorizontalAlignment::Left));
38
			this->listView1->Groups->Add(gcnew ListViewGroup("Ships", HorizontalAlignment::Left));
38
			this->listView1->Groups->Add(gcnew ListViewGroup("Ships", HorizontalAlignment::Left));
39
			this->listView1->Groups->Add(gcnew ListViewGroup("Mods", HorizontalAlignment::Left));
39
			this->listView1->Groups->Add(gcnew ListViewGroup("Mods", HorizontalAlignment::Left));
40
 
40
 
41
			m_pCurrentItem = nullptr;
41
			m_pCurrentItem = nullptr;
42
			m_lAddress = new CyStringList;
42
			_lAddress = new Utils::CStringList;
43
 
43
 
44
			for ( CBaseFile *package = p->PackageList()->First(); package; package = p->PackageList()->Next() ) {
44
			for ( CBaseFile *package = p->PackageList()->First(); package; package = p->PackageList()->Next() ) {
45
				if ( !package->webAddress().empty() ) this->AddPackage(package);
45
				if ( !package->webAddress().empty() ) this->AddPackage(package);
46
			}
46
			}
47
 
47
 
Line 270... Line 270...
270
 
270
 
271
			this->UpdateList();
271
			this->UpdateList();
272
 
272
 
273
			// add all address
273
			// add all address
274
			if ( m_pDownloadPackage )
274
			if ( m_pDownloadPackage )
275
				m_lAddress->PushBack(CyString(m_pDownloadPackage->sFilename));
275
				_lAddress->pushBack(m_pDownloadPackage->sFilename);
276
			else if ( m_pPackage )
276
			else if ( m_pPackage )
277
			{
277
			{
278
				m_lAddress->PushBack(CyString(m_pPackage->webAddress()));
278
				_lAddress->pushBack(m_pPackage->webAddress());
279
				for ( int i = 0; i < m_pPackage->GetMaxWebMirrors(); i++ )
279
				for ( int i = 0; i < m_pPackage->getMaxWebMirrors(); i++ )
280
					m_lAddress->PushBack(m_pPackage->GetWebMirror(i));
280
					_lAddress->pushBack(m_pPackage->getWebMirror(i));
281
			}
281
			}
282
			else
282
			else
283
				return;
283
				return;
284
 
284
 
285
			// start the check
285
			// start the check
286
			this->backgroundWorker1->RunWorkerAsync();
286
			this->backgroundWorker1->RunWorkerAsync();
-
 
287
		}
-
 
288
 
-
 
289
		System::String^ GetDestiantion()
-
 
290
		{
-
 
291
			return Environment::GetFolderPath(Environment::SpecialFolder::Personal) + "\\Egosoft\\PluginManager";
287
		}
292
		}
288
 
293
 
289
		void StartUpdate()
294
		void StartUpdate()
290
		{
295
		{
291
			// create downloads directory
296
			// create downloads directory
292
			System::String ^dir = System::IO::FileInfo(System::Windows::Forms::Application::ExecutablePath).DirectoryName;
297
			System::String^ dir = GetDestiantion();
293
			if ( !IO::Directory::Exists(dir + "\\Downloads") )
298
			if ( !IO::Directory::Exists(dir + "\\Downloads") )
294
			{
299
			{
295
				try {
300
				try {
296
					IO::Directory::CreateDirectory(dir + "\\Downloads");
301
					IO::Directory::CreateDirectory(dir + "\\Downloads");
297
				}
302
				}
Line 391... Line 396...
391
		ImageList		^m_pImageList;
396
		ImageList		^m_pImageList;
392
		ArrayList		^m_lInstall;
397
		ArrayList		^m_lInstall;
393
		String			^m_sData;
398
		String			^m_sData;
394
		String			^m_sStatus;
399
		String			^m_sStatus;
395
		String			^m_sBestServer;
400
		String			^m_sBestServer;
396
		CyStringList	*m_lAddress;
401
		Utils::CStringList	*_lAddress;
397
		ListViewItem	^m_pCurrentItem;
402
		ListViewItem	^m_pCurrentItem;
398
		CPackages		*m_pPackages;
403
		CPackages		*m_pPackages;
399
		CBaseFile		*m_pPackage;
404
		CBaseFile		*m_pPackage;
400
		int				 m_iStatus;
405
		int				 m_iStatus;
401
		bool			 m_bDownloader;
406
		bool			 m_bDownloader;
Line 413... Line 418...
413
		{
418
		{
414
			if (components)
419
			if (components)
415
			{
420
			{
416
				delete components;
421
				delete components;
417
			}
422
			}
418
			delete m_lAddress;
423
			delete _lAddress;
419
		}
424
		}
420
 
425
 
421
	private: System::Windows::Forms::ProgressBar^  progressBar1;
426
	private: System::Windows::Forms::ProgressBar^  progressBar1;
422
	private: System::ComponentModel::BackgroundWorker^  backgroundWorker1;
427
	private: System::ComponentModel::BackgroundWorker^  backgroundWorker1;
423
	private: System::Windows::Forms::ListView^  listView1;
428
	private: System::Windows::Forms::ListView^  listView1;
Line 584... Line 589...
584
				 }
589
				 }
585
			 }
590
			 }
586
private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
591
private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
587
			 // for each server
592
			 // for each server
588
			 String ^bestServer = "";
593
			 String ^bestServer = "";
589
			 CyString bestVersion = "0.00";
594
			 Utils::String bestVersion = "0.00";
590
			 String ^bestFile = "";
595
			 String ^bestFile = "";
591
 
596
 
592
			 for ( SStringList *str = m_lAddress->Head(); str; str = str->next )
597
			 for(auto itr = _lAddress->begin(); itr != _lAddress->end(); itr++)
593
			 {
598
			 {
594
				 if ( backgroundWorker1->CancellationPending )
599
				 if ( backgroundWorker1->CancellationPending )
595
					 break;
600
					 break;
596
				 String ^address = SystemStringFromCyString(str->str);
601
				 String ^address = _US((*itr)->str);
597
				 m_sData = "";
602
				 m_sData = "";
598
				 String ^url = address;
603
				 String ^url = address;
599
				 
604
				 
600
				 if ( !m_bDownloader )
605
				 if ( !m_bDownloader )
601
					url += "/" + m_pCurrentItem->SubItems[4]->Text;
606
					url += "/" + m_pCurrentItem->SubItems[4]->Text;
Line 638... Line 643...
638
 
643
 
639
						// we have the file, parse data
644
						// we have the file, parse data
640
						cli::array<String ^> ^lines = m_sData->Split('\n');
645
						cli::array<String ^> ^lines = m_sData->Split('\n');
641
						if ( lines )
646
						if ( lines )
642
						{
647
						{
643
							 CyString version;
648
							 Utils::String version;
644
							 CyString file;
649
							 Utils::String file;
645
							 for ( int i = 0; i < lines->Length; i++ )
650
							 for ( int i = 0; i < lines->Length; i++ )
646
							 {
651
							 {
647
								 CyString l = CyStringFromSystemString(lines[i]).Remove(9).Remove('\r');
652
								 Utils::String l = _S(lines[i]).remove(9).remove('\r');
648
								 //if ( !l.IsIn(":") ) continue;
653
								 //if ( !l.IsIn(":") ) continue;
649
								 CyString first = l.GetToken(":", 1, 1);
654
								 Utils::String first = l.token(":", 1);
650
								 if ( first.Compare("Version") )
655
								 if ( first.Compare("Version") )
651
									 version = l.GetToken(":", 2).RemoveFirstSpace();
656
									 version = l.tokens(":", 2).removeFirstSpace();
652
								 else if ( first.Compare("File") )
657
								 else if ( first.Compare("File") )
653
									 file = l.GetToken(":", 2).RemoveFirstSpace();
658
									 file = l.tokens(":", 2).removeFirstSpace();
654
							 }
659
							 }
655
 
660
 
656
							 if ( !version.Empty() && !file.Empty() )
661
							 if ( !version.empty() && !file.empty() )
657
							 {
662
							 {
658
								 int error = this->CheckFile(address + "/" + SystemStringFromCyString(file));
663
								 int error = this->CheckFile(address + "/" + _US(file));
659
								 if ( error == CONNECTERROR_NONE )
664
								 if ( error == CONNECTERROR_NONE )
660
								 {
665
								 {
661
									 if ( bestVersion.CompareVersion(version) == COMPARE_NEWER )
666
									 if ( bestVersion.compareVersion(version) == COMPARE_NEWER )
662
									 {
667
									 {
663
										 bestServer = address + "/" + SystemStringFromCyString(file);
668
										 bestServer = address + "/" + _US(file);
664
										 bestVersion = version;
669
										 bestVersion = version;
665
									 }
670
									 }
666
								 }
671
								 }
667
							 }
672
							 }
668
						 }
673
						 }
Line 674... Line 679...
674
				 return;
679
				 return;
675
 
680
 
676
			 // now check if we have found an update
681
			 // now check if we have found an update
677
			 if ( bestServer->Length )
682
			 if ( bestServer->Length )
678
			 {
683
			 {
679
				 int v = m_pPackage->version().compareVersion(bestVersion.ToString());
684
				 int v = m_pPackage->version().compareVersion(bestVersion);
680
				 switch ( v )
685
				 switch ( v )
681
				 {
686
				 {
682
					case COMPARE_OLDER:
687
					case COMPARE_OLDER:
683
						m_sStatus = "Older";
688
						m_sStatus = "Older";
684
						break;
689
						break;
685
					case COMPARE_SAME:
690
					case COMPARE_SAME:
686
						m_sStatus = "Same";
691
						m_sStatus = "Same";
687
						break;
692
						break;
688
					case COMPARE_NEWER:
693
					case COMPARE_NEWER:
689
						m_sStatus = "Newer (" + SystemStringFromCyString(bestVersion) + ")";
694
						m_sStatus = "Newer (" + _US(bestVersion) + ")";
690
						m_sBestServer = bestServer;
695
						m_sBestServer = bestServer;
691
						break;
696
						break;
692
				 }
697
				 }
693
			 }
698
			 }
694
			 else
699
			 else
Line 758... Line 763...
758
				}
763
				}
759
 
764
 
760
				if ( backgroundWorker2->CancellationPending )
765
				if ( backgroundWorker2->CancellationPending )
761
					return;
766
					return;
762
 
767
 
763
				System::String ^dir = System::IO::FileInfo(System::Windows::Forms::Application::ExecutablePath).DirectoryName;
768
				System::String ^dir = GetDestiantion();
764
				dir += "\\Downloads";
769
				dir += "\\Downloads";
765
				String ^file = dir + "\\" + _US(CFileIO(_S(m_pCurrentItem->SubItems[5]->Text)).filename().remove('\r').remove(9));
770
				String ^file = dir + "\\" + _US(CFileIO(_S(m_pCurrentItem->SubItems[5]->Text)).filename().remove('\r').remove(9));
766
 
771
 
767
				__int64 maxSize = res->ContentLength;
772
				__int64 maxSize = res->ContentLength;
768
				__int64 curSize = 0;
773
				__int64 curSize = 0;
Line 835... Line 840...
835
				 m_pCurrentItem->SubItems[3]->Text = "Cancelled";
840
				 m_pCurrentItem->SubItems[3]->Text = "Cancelled";
836
				 m_pCurrentItem->SubItems[5]->Text = "";
841
				 m_pCurrentItem->SubItems[5]->Text = "";
837
			}
842
			}
838
			else
843
			else
839
			{
844
			{
840
				System::String ^dir = System::IO::FileInfo(System::Windows::Forms::Application::ExecutablePath).DirectoryName;
845
				System::String ^dir = GetDestiantion();
841
				dir += "\\Downloads";
846
				dir += "\\Downloads";
842
				String ^file = dir + "\\" + _US(CFileIO(_S(m_pCurrentItem->SubItems[5]->Text)).filename().remove('\r').remove(9));
847
				String ^file = dir + "\\" + _US(CFileIO(_S(m_pCurrentItem->SubItems[5]->Text)).filename().remove('\r').remove(9));
843
 
848
 
844
				 if ( IO::File::Exists(file) )
849
				 if ( IO::File::Exists(file) )
845
				 {
850
				 {