Rev 228 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "../StdAfx.h"
#include "InstallPackageDialog.h"
#undef GetTempPath
#undef GetCurrentDirectory
namespace PluginManager {
InstallPackageDialog::InstallPackageDialog(CPackages *p) : m_pPackages(p)
{
InitializeComponent();
this->UpdatePackages();
}
void InstallPackageDialog::UpdatePackages()
{
ListPackages->Items->Clear();
ListPackages->Groups->Clear();
ListPackages->SmallImageList = gcnew ImageList();
ListPackages->LargeImageList = ListPackages->SmallImageList;
int count = 0;
for ( CListNode<CBaseFile> *node = m_pPackages->GetInstallPackageList()->Front(); node; node = node->next() )
{
CBaseFile *p = node->Data();
ListViewItem ^item = gcnew ListViewItem(_US(p->name(m_pPackages->GetLanguage())));
item->SubItems->Add(_US(p->author()));
item->SubItems->Add(_US(p->version()));
switch ( p->GetLoadError() )
{
case INSTALLCHECK_OLDVERSION:
item->SubItems->Add("Newer version installed");
break;
case INSTALLCHECK_WRONGGAME:
item->SubItems->Add("For Wrong Game");
break;
case INSTALLCHECK_WRONGVERSION:
item->SubItems->Add("For Wrong Game Version");
break;
}
ListPackages->Items->Add(item);
item->Tag = _US(Utils::WString::Number(count));
++count;
if ( p->icon() )
{
//extract icon
C_File *f = p->icon();
f->setFullDir(_WS(System::IO::Path::GetTempPath()));
if ( f->UncompressData() )
f->writeFilePointer();
PluginManager::DisplayListIcon(p, ListPackages, item);
}
C_File *gf = p->GetFirstFile(FILETYPE_ADVERT);
if ( gf )
{
gf->setFullDir(_WS(System::IO::Path::GetTempPath()));
if ( gf->UncompressData() )
gf->writeFilePointer();
}
if ( count == 1 )
item->Selected = true;
item->Checked = (p->GetLoadError()) ? false : true;
// select one with an error if there is any
if ( p->GetLoadError() )
item->Selected = true;
updateUI();
}
if ( ListPackages->Items->Count == 1 )
{
//this->GroupList->Hide();
//this->Height = 250;
this->DisplayPackage(m_pPackages->GetInstallPackageList()->Get(0));
}
}
void InstallPackageDialog::DisplayPackage(CBaseFile *p)
{
TextInstall->Hide();
this->PanelRating->Hide();
PicEase1->Hide();
PicEase2->Hide();
PicEase3->Hide();
PicEase4->Hide();
PicEase5->Hide();
PicChange1->Hide();
PicChange2->Hide();
PicChange3->Hide();
PicChange4->Hide();
PicChange5->Hide();
PicRec1->Hide();
PicRec2->Hide();
PicRec3->Hide();
PicRec4->Hide();
PicRec5->Hide();
this->LabError->Text = "";
if ( p )
{
this->GroupPackage->Text = _US(p->getFullPackageName(m_pPackages->GetLanguage(), false));
this->TextDesc->Text = _US(p->description().findReplace(L"<br>", L"\n").stripHtml());
// update graphic
bool addedIcon = false;
C_File *picFile = p->GetFirstFile(FILETYPE_ADVERT);
if ( picFile )
{
System::String ^pic = _US(picFile->filePointer());
if ( System::IO::File::Exists(pic) )
{
try {
Bitmap ^myBitmap = gcnew Bitmap(pic);
if ( myBitmap )
{
this->PictureDisplay->Image = dynamic_cast<Image ^>(myBitmap);
addedIcon = true;
}
}
catch (System::ArgumentException ^E) {
(void)E;
}
}
}
if ( !addedIcon )
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(InstallPackageDialog::typeid));
System::Drawing::Icon ^icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
this->PictureDisplay->Image = icon->ToBitmap();
}
if ( !p->installText(m_pPackages->GetLanguage(), true).empty() )
{
this->TextInstall->Text = _US(p->installText(m_pPackages->GetLanguage(), true).stripHtml());
this->TextInstall->Show();
}
this->LabDate->Text = _US(p->creationDate());
this->LabVersion->Text = _US(p->version());
if ( p->GetType() == TYPE_SPK )
{
this->LabType->Text = _US(((CSpkFile *)p)->scriptTypeString(m_pPackages->GetLanguage()));
switch ( p->pluginType() ) {
case PLUGIN_NORMAL: this->LabPluginType->Text = "Normal"; break;
case PLUGIN_STABLE: this->LabPluginType->Text = "Stable"; break;
case PLUGIN_EXPERIMENTAL: this->LabPluginType->Text = "Experimental"; break;
case PLUGIN_CHEAT: this->LabPluginType->Text = "Cheat"; break;
case PLUGIN_MOD: this->LabPluginType->Text = "Mod"; break;
}
}
else if ( p->GetType() == TYPE_XSP )
{
this->LabType->Text = "Ship";
this->LabPluginType->Text = "Ship";
}
else
{
this->LabType->Text = "Other";
this->LabPluginType->Text = "Other";
}
if ( p->AnyGameCompatability() )
this->LabGames->Text = _US(m_pPackages->getGameTypesString(p, true));
else
this->LabGames->Text = "All Games";
if ( p->gameChanging() >= 1 || p->recommended() >= 1 || p->easeOfUse() >= 1 )
{
this->PanelRating->Show();
// ease of use rating
if ( p->easeOfUse() >= 1 )
PicEase1->Show();
if ( p->easeOfUse() >= 2 )
PicEase2->Show();
if ( p->easeOfUse() >= 3 )
PicEase3->Show();
if ( p->easeOfUse() >= 4 )
PicEase4->Show();
if ( p->easeOfUse() >= 5 )
PicEase5->Show();
// game changing rating
if ( p->gameChanging() >= 1 )
PicChange1->Show();
if ( p->gameChanging() >= 2 )
PicChange2->Show();
if ( p->gameChanging() >= 3 )
PicChange3->Show();
if ( p->gameChanging() >= 4 )
PicChange4->Show();
if ( p->gameChanging() >= 5 )
PicChange5->Show();
// Recommanded rating
if ( p->recommended() >= 1 )
PicRec1->Show();
if ( p->recommended() >= 2 )
PicRec2->Show();
if ( p->recommended() >= 3 )
PicRec3->Show();
if ( p->recommended() >= 4 )
PicRec4->Show();
if ( p->recommended() >= 5 )
PicRec5->Show();
}
switch ( p->GetLoadError() )
{
case INSTALLCHECK_OLDVERSION:
{
CBaseFile *oldPackage = m_pPackages->findPackage(p);
if ( oldPackage )
this->LabError->Text = "Newer version already installed: V" + _US(oldPackage->version()) + " - " + _US(oldPackage->creationDate());
else
this->LabError->Text = "Newer version already installed";
}
break;
case INSTALLCHECK_WRONGGAME:
this->LabError->Text = "For Wrong Game, Requires: " + _US(m_pPackages->getGameTypesString(p, false));
break;
case INSTALLCHECK_WRONGVERSION:
this->LabError->Text = "For Wrong Game Version, Requires: " + _US(m_pPackages->getGameVersionString(p));
break;
}
}
else
{
this->LabType->Text = "";
this->GroupPackage->Text = "";
this->TextDesc->Text = "";
this->PictureDisplay->Image = nullptr;
}
}
void InstallPackageDialog::DoClose()
{
// remove any packages that are not selected
// if only 1 package, we cant select the check box, so always checked
if ( ListPackages->Items->Count > 1 )
{
CLinkList<CBaseFile> removePackages;
for ( int i = ListPackages->Items->Count - 1; i >= 0; i-- )
{
ListViewItem ^item = ListPackages->Items[i];
if ( !item->Checked )
{
int num = Convert::ToInt32(item->Tag);
removePackages.push_back(m_pPackages->GetInstallPackageList()->Get(num));
}
}
for ( CBaseFile *p = removePackages.First(); p; p = removePackages.Next() )
m_pPackages->RemovePreparedInstall(p);
removePackages.MemoryClear();
}
m_pPackages->CheckPreparedInstallRequired(NULL);
this->Close();
}
void InstallPackageDialog::updateUI()
{
bool anyChecked = false;
for ( int i = 0; i < ListPackages->Items->Count; i++ ) {
if ( ListPackages->Items[i]->Checked ) {
anyChecked = true;
break;
}
}
this->ButInstall->Enabled = anyChecked;
}
}