Subversion Repositories spk

Rev

Rev 6 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "../StdAfx.h"
#include "PackageForm.h"
#include "InputBox.h"
#include "Form1.h"
#include "AddWareText.h"
#include "AddCockpit.h"
#include "SaveDialog.h"

namespace Creator {
        bool PackageForm::LoadPackage(CBaseFile *base, System::String ^filename)
        {
                m_sFilename = filename;

                if ( !base )
                {
                        int error;
                        m_pPackage = m_pP->OpenPackage(CyStringFromSystemString(filename), &error);
                        if ( !m_pPackage )
                                return false;
                }
                else
                        m_pPackage = base;
                
                m_pPackage->SetChanged(false);
                m_pPackage->UpdateSigned(true);
                this->UpdateChanged();
                m_bLoading = true;

                if ( m_pPackage->AnyFileType(FILETYPE_ADVERT) )
                {
                        for ( C_File *f = m_pPackage->GetFirstFile(FILETYPE_ADVERT); f; f = m_pPackage->GetNextFile(f) )
                        {
                                f->SetFullDir(CyStringFromSystemString(System::IO::Path::GetTempPath()));
                                long size;
                                unsigned char *data = f->UncompressData(&size, 0);
                                if ( data && size )
                                {
                                        if ( f->WriteFilePointer(data, size) )
                                        {
                                                if ( !m_pDisplayFile )
                                                        m_pDisplayFile = f;
                                        }

                                        if ( f->GetCompressionType() != SPKCOMPRESS_NONE )
                                                delete data;
                                }
                        }
                }

                if ( m_pPackage->GetIcon() )
                {
                        C_File *f = m_pPackage->GetIcon();
                        f->SetFilename(CyStringFromSystemString(System::IO::Path::GetTempPath()) + "/package_icon." + m_pPackage->GetIconExt());
                        f->SetFullDir(CyStringFromSystemString(System::IO::Path::GetTempPath()));
                        long size;
                        unsigned char *data = f->UncompressData(&size, 0);
                        if ( data && size )
                        {
                                f->WriteFilePointer(data, size);
                                if ( f->GetCompressionType() != SPKCOMPRESS_NONE )
                                        delete data;
                        }
                }

                this->RadioInstallBefore->Checked = true;
                this->RadioInstallAfter->Checked = false;
                this->RadioUninstallAfter->Checked = false;
                this->RadioUninstallBefore->Checked = false;
                this->UpdateView();

                m_pPackage->SetChanged(false);

                m_bLoading = false;

                return true;
        }

        void PackageForm::DoToolTips()
        {
                //tooltip1 for any controls with text to display
                this->toolTip1->SetToolTip(this->RadioTypeUpdate, "This allows you to create a small package to update an already installed one with new files.\nIn the Dependacy section you can set the minimum version required to install.\nAny mod files only need to contain the files you want to update, they will be added into the existing mod file when installed");
                this->toolTip1->SetToolTip(this->RadioTypeStart, "This allows you to create a custom start in the old format\nWhen installed, it will use the added initplayer script to create the maps and jobs file automatically\nThis allows it to always use the most up to date map automatically, so you only need to make changes to the script file\nIf set to use another mod, it'll use the map from the mod instead of the games one");
                this->toolTip1->SetToolTip(this->RadioTypePatch, "This allows you to create patchs to your mod files\nWhen installing, any files in the patch mod will overright the base mod files, allowing you to create different patchs allowing users to customise your mod without having to have seperate mod installs\nWhen the patch is uninstalled, any changed files will be restored back to the normal ones");
                this->toolTip1->SetToolTip(this->CheckShipID, "This allows you to replaing an existing ship when you install\nNormally, the ship is simply added into the game, at the end of the ships file, when set to replace, it will replace the ship with the same ship id.\nThis allows you to create an update to an existing ship without having to have both in the game");
                this->toolTip1->SetToolTip(this->groupBox3, "This allows you to set the parent package\nThis will need to be installed as well, unlike depencies, the child/parent packages are linked to each other\nThis allows you to release updates or addons for a certain package, one that will only work with the parent package");
                this->toolTip1->SetToolTip(this->ButFromFile, "This will read the details from an existing file\nWhen selected, you will be prompted to select a saved package file.\nThe package name and author is then read from the package and automatically filled in so you know its entered correctly");
                this->toolTip1->SetToolTip(this->RadioInstallBefore, "This is a message you can give to the user when they install your package\nThis will come before the installation starts and allows you to display information or warnings about the package they are about to install to help them decide if they want to continue installing or not");
                this->toolTip1->SetToolTip(this->RadioInstallAfter, "This message is displayed to the user once the package has been installed\nThis is usually used to give the user information about your package, like how to start using it in game, or important information before they start using it, etc");
                this->toolTip1->SetToolTip(this->RadioUninstallBefore, "This message is displayed when the user attempts to uninstall your package\nThis can be used to give the user instruction on what else they might need to do to uninstall, ie if theres something they need to do ingame first before removing the package");
                this->toolTip1->SetToolTip(this->RadioUninstallAfter, "This message is displayed after the user has uninstalled your package\nThis can give them information about anything else they might need to do to remove the package, ie to allow the uninstall scripts to function to remove anything from thier game");
                this->toolTip1->SetToolTip(this->GroupEase, "This is a rating allowing the user to see how easy it is to use the script\nThe ratings are displayed when installing the package and are from 1 to 5, 5 being easy to use, 1 being hard\nClicking on the stars will adjust the rating");
                this->toolTip1->SetToolTip(this->GroupChange, "This is a rating allowing the user to see how much the package changes the game\nThe ratings are displayed when installing the package and are from 1 to 5, 5 being alot of change, 1 being very little\nClicking on the stars will adjust the rating");
                this->toolTip1->SetToolTip(this->GroupRec, "This is a rating allowing the user to see how much you recommended this package\nThe ratings are displayed when installing the package and are from 1 to 5, 5 highly recommended\nClicking on the stars will adjust the rating");

                // controls that need custom title texts using tags
                this->ComboPluginType->Tag = "Plugin Type";
                this->toolTip2->SetToolTip(this->ComboPluginType, "The plugin type is used to display roughly what type the plugin comes under, this is displayed during installation\nNormal = Just a normal package\nStable = A stable or final release of a package\nExperimental = Potentinally unstable package\nCheat = Considered to be a cheat, ie breaks game balance\nMod = A Mod, can only run 1 at a time and not compatable with other mods");
        }

        void PackageForm::UpdateScriptType()
        {
                 if ( this->ComboType->SelectedIndex == SCRIPTTYPE_CUSTOM )
                 {
                         this->TextCustomType->Visible = true;
                         this->ComboType->Dock = Windows::Forms::DockStyle::Left;
                         if ( !m_bLoading )
                                ((CSpkFile *)m_pPackage)->SetScriptType(CyStringFromSystemString(this->TextCustomType->Text));
                 }
                 else
                 {
                         this->TextCustomType->Visible = false;
                         this->ComboType->Dock = Windows::Forms::DockStyle::Fill;
                 }
        }
        void PackageForm::UpdateText()
        {
                this->TextText->Tag = 1;
                CLinkList<SInstallText> *list = NULL;
                if ( this->RadioInstallAfter->Checked || this->RadioInstallBefore->Checked )
                        list = m_pPackage->GetInstallTextList();
                else if ( this->RadioUninstallAfter->Checked || this->RadioUninstallBefore->Checked )
                        list = m_pPackage->GetUninstallTextList();
                else
                {
                        this->ListLang->Enabled = false;
                        this->ButTextAdd->Enabled = false;
                        this->UpdateTextLang();
                        return;
                }

                this->ListLang->Enabled = true;
                this->ButTextAdd->Enabled = true;

                int selected = this->ListLang->SelectedIndex;
                if ( selected >= 1 )
                        selected = Convert::ToInt32(this->ListLang->Text);
                else
                        selected = -1;

                this->ListLang->Items->Clear();
                this->ListLang->Items->Add("- Default -");

                if ( !list )
                {
                        this->UpdateTextLang();
                        return;
                }

                bool before = false;
                if ( this->RadioInstallBefore->Checked || this->RadioUninstallBefore->Checked )
                        before = true;

                // add languages
                for ( SInstallText *t = list->First(); t; t = list->Next() )
                {
                        if ( t->iLanguage <= 0 )
                                continue;
                        this->ListLang->Items->Add(System::Convert::ToString(t->iLanguage));
                }

                if ( selected == -1 )
                        this->ListLang->SelectedIndex = 0;
                else
                        this->ListLang->Text = Convert::ToString(selected);
                if ( this->ListLang->SelectedIndex == -1 )
                        this->ListLang->SelectedIndex = 0;

                this->UpdateTextLang();
        }

        void PackageForm::UpdateTextLang()
        {
                this->TextText->Tag = 1;
                this->TextText->Enabled = false;
                this->TextText->Text = "";

                if ( this->ListLang->SelectedIndex >= 0 )
                {
                        int lang = CyStringFromSystemString(this->ListLang->Text).ToInt();
                        CyString desc;
                        if ( this->RadioInstallAfter->Checked )
                                desc = m_pPackage->GetInstallAfterText(lang, true);
                        else if ( this->RadioInstallBefore->Checked )
                                desc = m_pPackage->GetInstallBeforeText(lang, true);
                        else if ( this->RadioUninstallAfter->Checked )
                                desc = m_pPackage->GetUninstallAfterText(lang, true);
                        else if ( this->RadioUninstallBefore->Checked )
                                desc = m_pPackage->GetUninstallBeforeText(lang, true);
                        this->TextText->Text = SystemStringFromCyString(desc);
                        this->TextText->Enabled = true;
                }

                this->ButTextDel->Enabled = false;
                if ( this->ListLang->SelectedIndex >= 1 )
                        this->ButTextDel->Enabled = true;

                this->TextText->Tag = nullptr;
        }

        void PackageForm::UpdateWares()
        {
                CSpkFile *spk = (CSpkFile *)m_pPackage;

                this->ListWares->Items->Clear();
                for ( SWares *w = spk->GetWaresList()->First(); w; w = spk->GetWaresList()->Next() )
                {
                        ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(w->sID));
                        switch ( tolower(w->cType) )
                        {
                                case 'b':
                                        item->SubItems->Add("Bio");
                                        break;
                                case 'e':
                                        item->SubItems->Add("Energy");
                                        break;
                                case 'f':
                                        item->SubItems->Add("Food");
                                        break;
                                case 't':
                                        item->SubItems->Add("Tech");
                                        break;
                                case 'm':
                                        item->SubItems->Add("Mineral");
                                        break;
                                default:
                                        item->SubItems->Add("Other");
                        }
                        item->SubItems->Add(System::Convert::ToString(w->iPrice));
                        switch ( w->iSize )
                        {
                                case 0:
                                        item->SubItems->Add("Tiny Containers");
                                        break;
                                case 1:
                                        item->SubItems->Add("Small Containers (S)");
                                        break;
                                case 2:
                                        item->SubItems->Add("Medium Containers (M)");
                                        break;
                                case 3:
                                        item->SubItems->Add("Large Containers (L)");
                                        break;
                                case 4:
                                        item->SubItems->Add("Extra Large Containers (XL)");
                                        break;
                                case 5:
                                        item->SubItems->Add("Station Containers (ST)");
                                        break;
                                default:
                                        item->SubItems->Add("Other Containers");
                        }

                        item->SubItems->Add(System::Convert::ToString(w->iVolumn));
                        item->SubItems->Add(System::Convert::ToString(w->iNotority));

                        if ( w->iTextPage > 0 && w->iTextID > 0 )
                                item->SubItems->Add(System::Convert::ToString(w->iTextPage) + ", " + System::Convert::ToString(w->iTextID));
                        item->ImageIndex = 2;
                        this->ListWares->Items->Add(item);
                }
                this->ListWares->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);

                this->UpdateWareText();
                m_pPackage->UpdateSigned(false);
                this->UpdateChanged();
        }

        void PackageForm::UpdateWareText()
        {
                this->ListWareText->Items->Clear();
                this->splitContainer1->Panel2Collapsed = true;

                if ( this->ListWares->SelectedItems->Count )
                {
                        SWares *w = ((CSpkFile *)m_pPackage)->FindWare(CyStringFromSystemString(this->ListWares->SelectedItems[0]->Text));
                        if ( w )
                        {
                                if ( w->iTextPage <= 0 && w->iTextID <= 0 )
                                {                       
                                        this->ListWareText->Items->Clear();
                                        this->splitContainer1->Panel2Collapsed = false;
                                        for ( SWaresText *wt = w->lText.First(); wt; wt = w->lText.Next() )
                                        {
                                                ListViewItem ^item = gcnew ListViewItem(System::Convert::ToString(wt->iLang));
                                                item->ImageIndex = 0;
                                                item->SubItems->Add(SystemStringFromCyString(wt->sName));
                                                item->SubItems->Add(SystemStringFromCyString(wt->sDesc));
                                                this->ListWareText->Items->Add(item);
                                        }
                                }
                        }
                }
        }

        void PackageForm::UpdateView()
        {
                m_bLoading = true;

                System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(PackageForm::typeid));

                this->LabelShipWarning->Visible = false;
                this->TextName->Text = SystemStringFromCyString(m_pPackage->GetName());
                this->TextAuthor->Text = SystemStringFromCyString(m_pPackage->GetAuthor());
                this->TextVersion->Text = SystemStringFromCyString(m_pPackage->GetVersion());
                CyString desc = m_pPackage->GetDescription();
                desc = desc.FindReplace("<br>", "\n");
                desc = desc.FindReplace("<newline>", "\n");
                desc = desc.StripHTML();
                this->TextDesc->Text = SystemStringFromCyString(desc);

                if ( m_pPackage->GetType() == TYPE_XSP )
                {
                        CXspFile *xsp = (CXspFile *)m_pPackage;
                        this->TextShipID->Text = SystemStringFromCyString(xsp->GetShipID());
                        this->PanelShip->Show();
                        this->LabelShipWarning->Visible = true;
                        this->groupBox6->Visible = false;

                        this->TextShipData->Text = SystemStringFromCyString(xsp->GetShipData());

                        this->CheckShipID->Checked = xsp->IsExistingShip();
                        this->CheckExistingText->Checked = (xsp->GetOriginalDescription()) ? true : false;
                        if ( xsp->GetOriginalDescription() )
                                this->NumTextID->Value = xsp->GetOriginalDescription();

                        // shipyards
                        this->CheckSYArgon->Checked = xsp->IsShipyard(SHIPYARD_ARGON);
                        this->CheckSYBoron->Checked = xsp->IsShipyard(SHIPYARD_BORON);
                        this->CheckSYTeladi->Checked = xsp->IsShipyard(SHIPYARD_TELADI);
                        this->CheckSYParanid->Checked = xsp->IsShipyard(SHIPYARD_PARANID);
                        this->CheckSYSplit->Checked = xsp->IsShipyard(SHIPYARD_SPLIT);
                        this->CheckSYFriend->Checked = xsp->IsShipyard(SHIPYARD_FRIEND);
                        this->CheckSYPirate->Checked = xsp->IsShipyard(SHIPYARD_PIRATES);
                        this->CheckSYXenon->Checked = xsp->IsShipyard(SHIPYARD_XENON);
                        this->CheckSYTerran->Checked = xsp->IsShipyard(SHIPYARD_TERRAN);
                        this->CheckSYATF->Checked = xsp->IsShipyard(SHIPYARD_ATF);
                        this->CheckSYYaki->Checked = xsp->IsShipyard(SHIPYARD_YAKI);

                        this->UpdateShipText();
                        this->UpdateShipPartList();
                }
                else if ( m_pPackage->GetType() == TYPE_SPK )
                {
                        CSpkFile *spk = (CSpkFile *)m_pPackage;
                        
                        this->ComboType->Text = "Custom";
                        this->ComboType->Enabled = false;

                        this->ComboPluginType->SelectedIndex = spk->GetPluginType();

                        if ( spk->IsLibrary() )
                                this->RadioTypeLibrary->Checked = true;
                        else if ( spk->IsCustomStart() )
                                this->RadioTypeStart->Checked = true;
                        else if ( spk->IsPackageUpdate() )
                                this->RadioTypeUpdate->Checked = true;
                        else if ( spk->IsPatch() )
                                this->RadioTypePatch->Checked = true;
                        else
                        {
                                this->RadioTypeScript->Checked = true;
                                this->ComboType->SelectedIndex = spk->GetScriptType();
                                this->ComboType->Enabled = true;
                                if ( this->ComboType->SelectedIndex == SCRIPTTYPE_CUSTOM )
                                        this->TextCustomType->Text = SystemStringFromCyString(spk->GetCustomScriptType(m_pP->GetLanguage()));
                        }

                        this->CheckOther->Checked = spk->IsAnotherMod();
                        this->TextOtherAuthor->Enabled = this->CheckOther->Checked;
                        this->TextOtherName->Enabled = this->CheckOther->Checked;
                        this->ButFromFile->Enabled = this->CheckOther->Checked;

                        if ( spk->IsAnotherMod() )
                        {
                                this->TextOtherAuthor->Text = SystemStringFromCyString(spk->GetOtherAuthor());
                                this->TextOtherName->Text = SystemStringFromCyString(spk->GetOtherName());
                        }

                        this->UpdateWares();
                        this->UpdateScriptType();
                }

                if ( !m_pPackage->GetCreationDate().Empty() )
                {
                        CyString date = m_pPackage->GetCreationDate();
                        int day = m_pPackage->GetCreationDate().GetToken("/", 1, 1).ToInt();
                        int month = m_pPackage->GetCreationDate().GetToken("/", 2, 2).ToInt();
                        int year = m_pPackage->GetCreationDate().GetToken("/", 3, 3).ToInt();
                        if ( month > 12 && day <= 12 ) { int temp = day; day = month; month = temp; }
                        if ( month < 1 ) month = 1;
                        if ( month > 12 ) month = 12;
                        if ( day < 1 ) day = 1;
                        if ( day > 31 ) day = 1;
                        if ( year < 1900 ) year += 2000;
                        try {
                                this->CreationDate->Value = DateTime(year, month, day);
                        } catch(System::ArgumentOutOfRangeException ^) {
                                this->CreationDate->Value = DateTime::Today;
                        }
                }
                else
                        this->CreationDate->Value = DateTime::Today;

                this->TextForum->Text = SystemStringFromCyString(m_pPackage->GetForumLink());
                this->TextEmail->Text = SystemStringFromCyString(m_pPackage->GetEmail());
                this->TextWebsite->Text = SystemStringFromCyString(m_pPackage->GetWebSite());
                this->TextWebAddress->Text = SystemStringFromCyString(m_pPackage->GetWebAddress());

                this->UpdateGamesList();
                this->UpdateFileList();
                this->UpdateMirrors();
                this->UpdatePackageNames();

                m_bSortingAsc = true;
                m_iSortingCol = 1;
                this->ListFiles->ListViewItemSorter = gcnew ListViewItemComparer(m_iSortingCol, !m_bSortingAsc);

                this->UpdateDisplayPic();
                this->UpdateDisplayIcon();
                this->UpdateRatings();
                this->UpdateText();
                this->UpdateDependacies();

                // delete the pages
                if ( m_pPackage->GetType() != TYPE_XSP )
                {
                        delete this->PageShip;
                        delete this->PageRaw;
                        delete this->PageShipComp;
                        this->PageShip = nullptr;
                        this->PageRaw = nullptr;
                        this->PageShipComp = nullptr;
                        this->PanelShip->Hide();
                        this->ToolCustomise->Visible = false;
                }
                else if ( m_pPackage->GetType() != TYPE_SPK )
                {
                        delete this->PagePackage;
                        delete this->PageWares;
                        this->PageWares = nullptr;
                        this->PagePackage = nullptr;
                }

                m_bLoading = false;
        }

        void PackageForm::UpdateDependacies()
        {
                this->ListDep->Items->Clear();
                for ( SNeededLibrary *nl = m_pPackage->GetNeededLibraries()->First(); nl; nl = m_pPackage->GetNeededLibraries()->Next() )
                {
                        ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(nl->sName));
                        item->SubItems->Add(SystemStringFromCyString(nl->sAuthor));
                        item->SubItems->Add(SystemStringFromCyString(nl->sMinVersion));
                        item->ImageIndex = 3;
                        this->ListDep->Items->Add(item);
                }
                this->ListDep->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
        }

        void PackageForm::UpdateShipPartList()
        {
                if ( !m_pPackage )
                        return;
                CXspFile *xsp = (CXspFile *)m_pPackage;

                // first lets adjust out columns
                int numColums = 1;
                this->ListShipPart->Visible = true;
                this->ListShipPart->Items->Clear();
                switch ( this->ComboShipPart->SelectedIndex )
                {
                        case 0: // componants
                                numColums = 3;
                                this->ColumnPart1->Text = "Section";
                                this->ColumnPart2->Text = "ID";
                                this->ColumnPart3->Text = "Data";
                                for ( SComponent *c = xsp->GetComponents()->First(); c; c = xsp->GetComponents()->Next() )
                                {
                                        ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(c->sSection));
                                        item->ImageKey = "components";
                                        item->SubItems->Add(SystemStringFromCyString(c->sSection2));
                                        item->SubItems->Add(SystemStringFromCyString(c->sData));
                                        this->ListShipPart->Items->Add(item);
                                }
                                break;
                        case 1: // dummies
                                numColums = 2;
                                this->ColumnPart1->Text = "Section";
                                this->ColumnPart2->Text = "Data";
                                for ( SDummy *d = xsp->GetDummies()->First(); d; d = xsp->GetDummies()->Next() )
                                {
                                        ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(d->sSection));
                                        item->SubItems->Add(SystemStringFromCyString(d->sData));
                                        item->ImageKey = "dummies";
                                        this->ListShipPart->Items->Add(item);
                                }
                                break;
                        case 2: // Cockpit
                                numColums = 3;
                                this->ColumnPart1->Text = "ID";
                                this->ColumnPart2->Text = "Index";
                                this->ColumnPart3->Text = "Data";
                                for ( SCockpit *c = xsp->GetCockpits()->First(); c; c = xsp->GetCockpits()->Next() )
                                {
                                        CyString cName = c->sCockpit;
                                        cName = cName.GetToken(";", -2);
                                        while ( cName.Right(1) == ";" )
                                                cName.Truncate(-1);
                                        ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(cName));
                                        if ( c->iIndex == -1 )
                                                item->SubItems->Add("<PACKAGE>");
                                        else
                                                item->SubItems->Add(Convert::ToString(c->iIndex));
                                        item->SubItems->Add(SystemStringFromCyString(c->sCockpit));
                                        item->ImageKey = "cockpit";
                                        this->ListShipPart->Items->Add(item);
                                }
                                break;
                        case 3: // CutData
                                numColums = 1;
                                this->ColumnPart1->Text = "Cuts";
                                for ( SStringList *cut = xsp->GetCutData()->Head(); cut; cut = cut->next )
                                {
                                        ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(cut->str));
                                        item->ImageKey = "cutdata";
                                        this->ListShipPart->Items->Add(item);
                                }
                                break;
                        case 4: // Bodies
                                numColums = 2;
                                this->ColumnPart1->Text = "Section";
                                this->ColumnPart2->Text = "Bodies";
                                for ( SStringList *b = xsp->GetBodies()->Head(); b; b = b->next )
                                {
                                        ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(b->str.GetToken(";", 1, 1)));
                                        item->SubItems->Add(SystemStringFromCyString(b->str.GetToken(";", 2)));
                                        item->ImageKey = "bodies";
                                        this->ListShipPart->Items->Add(item);
                                }
                                break;
                        case 5: // Animations
                                numColums = 1;
                                this->ColumnPart1->Text = "Animations";
                                for ( SStringList *a = xsp->GetAnimations()->Head(); a; a = a->next )
                                {
                                        ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(a->str));
                                        item->ImageKey = "animations";
                                        this->ListShipPart->Items->Add(item);
                                }
                                break;

                        // dont know what we are supposed to be displaying
                        default:
                                this->ListShipPart->Visible = false;
                }

                this->ListShipPart->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
                // adjust size of columns
                if ( numColums < 3 )
                        this->ColumnPart3->Width = 0;
                if ( numColums < 2 )
                        this->ColumnPart2->Width = 0;
        }

        void PackageForm::UpdateShipText()
        {
                CXspFile *xsp = (CXspFile *)m_pPackage;

                this->ListShipText->Items->Clear();

                for ( SText *t = xsp->GetTexts()->First(); t; t = xsp->GetTexts()->Next() )
                {
                        ListViewItem ^item = gcnew ListViewItem(System::Convert::ToString(t->iId));
                        item->ImageIndex = 0;
                        item->SubItems->Add(SystemStringFromCyString(t->sName));
                        item->SubItems->Add(SystemStringFromCyString(t->sDesc));
                        this->ListShipText->Items->Add(item);
                }

                this->ListShipText->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
        }

        void PackageForm::UpdateDisplayPic()
        {
                System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(PackageForm::typeid));
                this->ButPicBack->Enabled = false;
                this->ButPicNext->Enabled = false;
                if ( m_pDisplayFile )
                {
                        CyString filePointer = m_pDisplayFile->GetFilePointer();
                        filePointer = filePointer.FindReplace("/", "\\");
                        filePointer = filePointer.FindReplace("\\\\", "\\");
                        if ( System::IO::File::Exists(SystemStringFromCyString(filePointer)) )
                        {
                                Bitmap ^myBitmap = gcnew Bitmap(SystemStringFromCyString(filePointer));
                                if ( myBitmap )
                                        this->DisplayPicture->Image = dynamic_cast<Image ^>(myBitmap);
                        }
                        this->ButPicDel->Enabled = true;

                        if ( m_pPackage->GetFirstFile(FILETYPE_ADVERT) != m_pDisplayFile )
                                this->ButPicBack->Enabled = true;
                        if ( m_pPackage->GetNextFile(m_pDisplayFile)  )
                                this->ButPicNext->Enabled = true;
                }
                else
                {
                        this->ButPicDel->Enabled = false;
                        this->DisplayPicture->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"DisplayPicture.Image")));
                }

        }

        void PackageForm::UpdateDisplayIcon()
        {
                System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(PackageForm::typeid));

                m_pTabPage->ImageIndex = 0;

                if ( m_pPackage->GetType() == TYPE_XSP )
                        this->DisplayIcon->Image = this->imageList1->Images[1];
                else
                {
                        this->DisplayIcon->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"DisplayIcon.Image")));

                        int num = -1;
                        if ( m_pPackage->GetType() == TYPE_SPK )
                        {
                                CSpkFile *spk = (CSpkFile *)m_pPackage;
                                if ( spk->IsLibrary() )
                                        num = 3;
                                else if ( spk->IsPackageUpdate() )
                                        num = 6;
                                else if ( spk->IsPatch() )
                                        num = 7;
                                else if ( spk->IsCustomStart() )
                                        num = 8;
                        }

                        if ( num == -1 && m_pPackage->IsFakePatch() )
                                num = 2;

                        if ( num != -1 )
                        {
                                this->DisplayIcon->Image = this->imageList1->Images[num];
                                m_pTabPage->ImageIndex = num;
                        }
                }

                this->ButIconDel->Enabled = false;

                if ( m_pPackage->GetIcon() )
                {
                        this->ButIconDel->Enabled = true;
                        CyString filePointer = m_pPackage->GetIcon()->GetFilePointer();
                        filePointer = filePointer.FindReplace("/", "\\");
                        filePointer = filePointer.FindReplace("\\\\", "\\");
                        String ^file = SystemStringFromCyString(filePointer);
                        if ( System::IO::File::Exists(file) )
                        {
                                Bitmap ^myBitmap = gcnew Bitmap(file);
                                if ( myBitmap )
                                {
                                        this->DisplayIcon->Image = dynamic_cast<Image ^>(myBitmap);
                                        this->imageList1->Images->Add(file, myBitmap);
                                        m_pTabPage->ImageIndex = this->imageList1->Images->IndexOfKey(file);
                                        if ( m_pTabPage->ImageIndex == -1 )
                                                m_pTabPage->ImageIndex = 0;
                                }
                        }
                }

                if ( m_pTabPage->ImageIndex == 0 )
                {
                        if ( m_pPackage->GetType() == TYPE_XSP )
                                m_pTabPage->ImageIndex = 1;
                }

                m_pMenuItem->Image = this->imageList1->Images[m_pTabPage->ImageIndex];
        }

        void PackageForm::UpdateGameVersion()
        {
                bool restoreLoad = m_bLoading;
                m_bLoading = true;

                ComboVersion->BeginUpdate();
                ComboVersion->Items->Clear();

                this->TextExactVersion->Hide();

                SGameExe *exe = NULL;
                if ( ButGame->ImageIndex >= 0 )
                        exe = m_pP->GetGameExe()->GetGame((m_pPackage) ? ButGame->ImageIndex : -1);
                if ( exe )
                {                       
                        ComboVersion->Items->Add("Original");
                        for ( int i = 0; i < exe->lVersions.size(); i++ )
                        {
                                SGameExeVersion *v = exe->lVersions[i];
                                ComboVersion->Items->Add(SystemStringFromCyString(v->sName));
                        }
                        ComboVersion->Items->Add("Exact (Custom)");
                        ComboVersion->Enabled = true;
                }
                else
                {
                        ComboVersion->Enabled = false;
                }
                

                ComboVersion->EndUpdate();

                if ( !restoreLoad )
                        m_bLoading = false;
        }

        void PackageForm::UpdateRatings()
        {
                this->PicEase1->BackColor = System::Drawing::Color::Transparent;
                this->PicEase2->BackColor = System::Drawing::Color::Transparent;
                this->PicEase3->BackColor = System::Drawing::Color::Transparent;
                this->PicEase4->BackColor = System::Drawing::Color::Transparent;
                this->PicEase5->BackColor = System::Drawing::Color::Transparent;

                this->PicChange1->BackColor = System::Drawing::Color::Transparent;
                this->PicChange2->BackColor = System::Drawing::Color::Transparent;
                this->PicChange3->BackColor = System::Drawing::Color::Transparent;
                this->PicChange4->BackColor = System::Drawing::Color::Transparent;
                this->PicChange5->BackColor = System::Drawing::Color::Transparent;

                this->PicRec1->BackColor = System::Drawing::Color::Transparent;
                this->PicRec2->BackColor = System::Drawing::Color::Transparent;
                this->PicRec3->BackColor = System::Drawing::Color::Transparent;
                this->PicRec4->BackColor = System::Drawing::Color::Transparent;
                this->PicRec5->BackColor = System::Drawing::Color::Transparent;

                if ( m_pPackage->GetEaseOfUse() >= 1 )
                        this->PicEase1->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetEaseOfUse() >= 2 )
                        this->PicEase2->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetEaseOfUse() >= 3 )
                        this->PicEase3->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetEaseOfUse() >= 4 )
                        this->PicEase4->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetEaseOfUse() >= 5 )
                        this->PicEase5->BackColor = System::Drawing::Color::Red;

                if ( m_pPackage->GetRecommended() >= 1 )
                        this->PicRec1->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetRecommended() >= 2 )
                        this->PicRec2->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetRecommended() >= 3 )
                        this->PicRec3->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetRecommended() >= 4 )
                        this->PicRec4->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetRecommended() >= 5 )
                        this->PicRec5->BackColor = System::Drawing::Color::Red;

                if ( m_pPackage->GetGameChanging() >= 1 )
                        this->PicChange1->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetGameChanging() >= 2 )
                        this->PicChange2->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetGameChanging() >= 3 )
                        this->PicChange3->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetGameChanging() >= 4 )
                        this->PicChange4->BackColor = System::Drawing::Color::Red;
                if ( m_pPackage->GetGameChanging() >= 5 )
                        this->PicChange5->BackColor = System::Drawing::Color::Red;

                if ( m_pPackage->GetEaseOfUse() < 0 )
                        this->GroupEase->Text = "Ease of Use";
                else
                        this->GroupEase->Text = "Ease of Use (" + System::Convert::ToString(m_pPackage->GetEaseOfUse()) + ")";

                if ( m_pPackage->GetGameChanging() < 0 )
                        this->GroupChange->Text = "Game Changing";
                else
                        this->GroupChange->Text = "Game Changing (" + System::Convert::ToString(m_pPackage->GetGameChanging()) + ")";

                if ( m_pPackage->GetRecommended() < 0 )
                        this->GroupRec->Text = "Recommended";
                else
                        this->GroupRec->Text = "Recommended (" + System::Convert::ToString(m_pPackage->GetRecommended()) + ")";
        }

        void PackageForm::Setup()
        {
                m_bLoading = true;

                this->ComboFileType->Items->Add("All Files");
                for ( int i = 0; i < FILETYPE_MAX; i++ )
                        this->ComboFileType->Items->Add(SystemStringFromCyString(GetFileTypeString(i)));
                this->ComboFileType->SelectedIndex = 0;

                this->PanelShip->Hide();

                m_bSortingAsc = true;
                m_iSortingCol = 1;

                this->ListFiles->ColumnClick += gcnew ColumnClickEventHandler(this, &Creator::PackageForm::SortList);
                this->ListFiles->ItemChecked += gcnew ItemCheckedEventHandler(this, &PackageForm::Event_FileChecked);

                this->ContextGames->Items->Clear();

                this->ComboGameFilter->Items->Clear();
                this->ToolGame->DropDownItems->Clear();

                this->ComboGameFilter->Items->Add("- None -");
                this->ComboGameFilter->Items->Add("- All Games -");

                for ( int i = 0; i < m_pP->GetGameExe()->GetNumGames(); i++ )
                {
                        SGameExe *gameExe = m_pP->GetGameExe()->GetGame(i);
                        if ( gameExe )
                        {
                                System::Windows::Forms::ToolStripMenuItem ^newItem = gcnew System::Windows::Forms::ToolStripMenuItem;
                                newItem->Text = SystemStringFromCyString(gameExe->sName);
                                newItem->Tag = Convert::ToString(i + 1);
                                newItem->Image = this->imageListGames->Images[i];
                                newItem->Click += gcnew System::EventHandler(this, &PackageForm::ContextGame_Selected);
                                this->ContextGames->Items->Add(newItem);

                                System::Windows::Forms::ToolStripMenuItem ^newItem2 = gcnew System::Windows::Forms::ToolStripMenuItem;
                                newItem2->Text = SystemStringFromCyString(gameExe->sName);
                                newItem2->Tag = Convert::ToString(i + 1);
                                newItem2->Image = this->imageListGames->Images[i];
                                newItem2->Click += gcnew System::EventHandler(this, &PackageForm::SetGame_Selected);
                                this->ToolGame->DropDownItems->Add(newItem2);

                                this->ComboGameFilter->Items->Add(SystemStringFromCyString(gameExe->sName));
                        }
                }

                this->ComboGameFilter->SelectedIndex = 0;

                this->ButGame->Text = "- Select Game -";
                this->ButGameAdd->Enabled = false;

                m_pTypeList->Clear();
                for ( int i = 0; i < SCRIPTTYPE_MAX; i++ )
                {
                        m_pTypeList->PushBack(CSpkFile::GetScriptTypeStringStatic(i));
                        ComboType->Items->Add(SystemStringFromCyString(CSpkFile::GetScriptTypeStringStatic(i)));
                }

                this->CreationDate->Value = DateTime::Today;

                m_bLoading = false;
        }

        void PackageForm::UpdateGamesList()
        {
                this->ListGames->Items->Clear();
                for ( SGameCompat *game = m_pPackage->GetGameCompatabilityList()->First(); game; game = m_pPackage->GetGameCompatabilityList()->Next() ) {
                        ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(m_pP->GetGameNameFromType(game->iGame)));
                        item->ImageIndex = (game->iGame < 0) ? -1 : (game->iGame - 1);
                        if ( !game->sVersion.Empty() ) {
                                item->SubItems->Add("Exact: " + SystemStringFromCyString(game->sVersion));
                        }
                        else {
                                item->SubItems->Add(SystemStringFromCyString(m_pP->GetGameVersionFromType(game->iGame, game->iVersion, game->sVersion)));
                        }
                        item->Tag = game->iGame;
                        this->ListGames->Items->Add(item);
                }

                this->ListGames->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
        }

        void PackageForm::UpdateFileList()
        {
                this->ButRemoveFile->Enabled = false;

                int pos = 0;
                this->ListFiles->Items->Clear();
                if ( m_pPackage ) {
                        for ( C_File *file = m_pPackage->GetFileList()->First(); file; file = m_pPackage->GetFileList()->Next() )
                        {
                                file->SetPos(pos++);
                                if ( this->ComboGameFilter->SelectedIndex > 0 ) {
                                        if ( this->ComboGameFilter->SelectedIndex - 1 != file->GetGame() )
                                                continue;
                                }
                                if ( this->ComboFileType->SelectedIndex == 0 || (this->ComboFileType->SelectedIndex - 1) == file->GetFileType() )
                                        this->AddFile(file);
                        }
                        ((Form1 ^)this->MdiParent)->UpdateStatus();
                }

                this->ListFiles->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
        }

        void PackageForm::AddFile(C_File *file)
        {
                ListViewItem ^item = gcnew ListViewItem("");

                if ( file->GetData() )
                {
                        item->SubItems->Add(SystemStringFromCyString(CyString("<PACKAGE>/") + file->GetNameDirectory(NULL)));
                        item->SubItems->Add(SystemStringFromCyString(file->GetUncompressedSizeString()));
                }
                else
                {
                        item->SubItems->Add(SystemStringFromCyString(file->GetFullFilename()));
                        item->SubItems->Add(SystemStringFromCyString(SPK::GetSizeString(file->GetSize())));
                }

                if ( file->IsFakePatch() )
                        item->SubItems->Add("Mod (Fakepatch)");
                else
                        item->SubItems->Add(SystemStringFromCyString(file->GetFileTypeString()));

                if ( !file->GetDir().Empty() )
                        item->SubItems->Add(SystemStringFromCyString(file->GetDir()));
                else
                        item->SubItems->Add("");

                if ( file->IsSigned() )
                        item->SubItems->Add("Yes");
                else
                        item->SubItems->Add("No");

                if ( !file->GetGame() )
                        item->SubItems->Add("All Games");
                else {
                        CPackages p;
                        p.Startup(".", ".", ".");
                        SGameExe *exe = p.GetGameExe()->GetGame(file->GetGame() - 1);
                        if ( exe ) {
                                item->SubItems->Add(SystemStringFromCyString(exe->sName));
                        }
                        else {
                                item->SubItems->Add("Game: " + file->GetGame());
                        }
                }

                item->Tag = SystemStringFromCyString(CyString::Number(file->GetPos()));
                if ( file->IsFakePatch() )
                        item->ImageKey = "fakepatch";
                else
                        item->ImageIndex = file->GetFileType();

                item->Checked = file->IsShared();

                this->ListFiles->Items->Add(item);
        }

        void PackageForm::AddNewFile()
        {
                // add filters
                OpenFileDialog ^ofd = gcnew OpenFileDialog();

                System::String ^filter;
                for ( int i = 0; i < FILETYPE_MAX; i++ )
                {
                        if ( filter )
                                filter += "|";
                        filter += SystemStringFromCyString(GetFileTypeString(i));
                        filter += "|";
                        // add extensions
                        switch ( i )
                        {
                                case FILETYPE_SCRIPT:
                                case FILETYPE_UNINSTALL:
                                case FILETYPE_MAP:
                                case FILETYPE_TEXT:
                                case FILETYPE_MISSION:
                                        filter += "*.pck;*.xml";
                                        break;

                                case FILETYPE_README:
                                        filter += "*.txt;*.doc;*.docx;*.pdf";
                                        break;

                                case FILETYPE_MOD:
                                        filter += "*.cat";
                                        break;

                                case FILETYPE_SOUND:
                                        filter += "*.wav";
                                        break;

                                case FILETYPE_SCREEN:
                                case FILETYPE_ADVERT:
                                        filter += "*.jpg;*.png";
                                        break;

                                case FILETYPE_SHIPSCENE:
                                case FILETYPE_COCKPITSCENE:
                                        filter += "*.pbd;*.bod";
                                        break;

                                case FILETYPE_SHIPMODEL:
                                        filter += "*.pbd;*.bod;*.bob;*.pbb";
                                        break;

                                default:
                                        filter += "*.*";
                        }
                }
                ofd->Filter = filter;
                ofd->FilterIndex = 1;
                ofd->RestoreDirectory = true;
                ofd->Multiselect = true;
                ofd->Title = "Select File(s) to add to package";
                if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
                {
                        CyString dir;
                        if ( C_File::DoesTypeHaveExtraDir(ofd->FilterIndex - 1) )
                        {
                                InputBox ^input = gcnew InputBox("Enter the directory to add files to", ((ofd->FilterIndex - 1) == FILETYPE_EXTRA) ? "PluginManager/Extras/$scriptname" : "");
                                if ( input->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
                                        dir = CyStringFromSystemString(input->GetInput());
                        }
                        array<System::String ^> ^fileArray = ofd->FileNames;
                        for ( int i = 0; i < fileArray->Length; i++ )
                        {
                                System::String ^file = fileArray[i];
                                int filetype = m_pP->AdjustFileType(CyStringFromSystemString(file), ofd->FilterIndex - 1);
                                C_File *f = m_pPackage->AddFile(CyStringFromSystemString(file), dir, filetype);
                                if ( (ofd->FilterIndex - 1) == FILETYPE_MOD )
                                        m_pPackage->AddFile(CFileIO(CyStringFromSystemString(file)).ChangeFileExtension("dat"), dir, filetype);
                        }
                        m_pPackage->UpdateSigned(false);
                        this->UpdateFileList();
                        this->UpdateDisplayPic();
                        this->UpdateChanged();
                }
        }

        bool PackageForm::CheckSave()
        {
                if ( m_pPackage->GetName().Empty() )
                {
                        MessageBox::Show(this, "You must specify a package name", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
                        return false;
                }
                if ( m_pPackage->GetAuthor().Empty() )
                {
                        MessageBox::Show(this, "You must specify an Author", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
                        return false;
                }
                if ( m_pPackage->GetVersion().Empty() )
                {
                        MessageBox::Show(this, "You must specify a version number", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
                        return false;
                }

                if ( m_pPackage->GetType() == TYPE_SPK )
                {
                        if ( ((CSpkFile *)m_pPackage)->IsPackageUpdate() )
                        {
                                SNeededLibrary *n = m_pPackage->FindPackageNeeded("<package>", "<author>");
                                if ( !n )
                                        m_pPackage->AddNeededLibrary("<package>", "<author>", "1.00");
                                n = m_pPackage->FindPackageNeeded("<package>", "<author>");

                                if ( n )
                                {
                                        if ( ((CSpkFile *)m_pPackage)->GetVersion().CompareVersion(n->sMinVersion) != COMPARE_OLDER )
                                        {
                                                MessageBox::Show(this, "The depencay vesion (" + SystemStringFromCyString(n->sMinVersion) + ") is too high, it must be lower than the current version (" + SystemStringFromCyString(m_pPackage->GetVersion()) + ")", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
                                                return false;
                                        }
                                }
                        }
                        else if ( ((CSpkFile *)m_pPackage)->IsCustomStart() )
                        {
                                if ( !((CSpkFile *)m_pPackage)->CheckValidCustomStart() )
                                {
                                        MessageBox::Show(this, "For a custom start, you must include an initplayer script", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
                                        return false;
                                }
                        }
                        else if ( ((CSpkFile *)m_pPackage)->IsPatch() )
                        {
                                if ( ((CSpkFile *)m_pPackage)->GetOtherAuthor().Empty() || ((CSpkFile *)m_pPackage)->GetOtherName().Empty() )
                                {
                                        MessageBox::Show(this, "For a mod patch, you must specify the parent mod that this will be patching\nEnter the parent mod name and author", "Invalid Entry", MessageBoxButtons::OK, MessageBoxIcon::Stop);
                                        return false;
                                }
                        }
                }

                 System::DateTime ^time = DateTime(this->CreationDate->Value);
                 
                 String ^t = System::Convert::ToString(time->Day) + "/" + System::Convert::ToString(time->Month) + "/" + System::Convert::ToString(time->Year);
                 m_pPackage->SetCreationDate(CyStringFromSystemString(t));

                return true;
        }

        void PackageForm::Save()
        {
                if ( !this->CheckSave() )
                        return;

                if ( m_pPackage->GetFilename().Empty() )
                {
                        this->SaveAs();
                        return;
                }

                if ( m_pPackage->GetType() == TYPE_XSP )
                        ((CXspFile *)m_pPackage)->AdjustCockpits();

                SaveDialog ^save = gcnew SaveDialog(m_pPackage, SystemStringFromCyString(m_pPackage->GetFilename()));
                if ( save->ShowDialog(this) == Windows::Forms::DialogResult::Cancel )
                        return;

                this->UpdateFileList();
                m_pPackage->SetChanged(false);
                this->UpdateChanged();

                if ( m_pSettings->bGenerateUpdate )
                        m_pPackage->CreateUpdateFile(CFileIO(m_pPackage->GetFilename()).GetDir());

                MessageBox::Show("Package: " + SystemStringFromCyString(m_pPackage->GetFilename()) + "\nHas been saved!", "Saved", MessageBoxButtons::OK, MessageBoxIcon::Information);
        }

        void PackageForm::SaveAs()
        {
                if ( !this->CheckSave() )
                        return;

                SaveFileDialog ^ofd = gcnew SaveFileDialog();
                if ( m_pPackage->GetType() == TYPE_XSP )
                        ofd->Filter = "Ship Files (*.xsp)|*.xsp";
                else
                        ofd->Filter = "Package Files (*.spk)|*.spk";
                ofd->AddExtension = true;
                CyString filename = m_pPackage->GetFilename();
                if ( filename.Empty() )
                        filename = m_pPackage->GetAutosaveName();
                filename = filename.FindReplace("/", "\\");
                ofd->FileName = SystemStringFromCyString(filename);
                ofd->FilterIndex = 1;
                ofd->RestoreDirectory = true;
                if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
                {
                        m_pPackage->SetFilename(CyStringFromSystemString(ofd->FileName));
                        m_sFilename = ofd->FileName;
                        m_pTabPage->Text = SystemStringFromCyString(CFileIO(m_pPackage->GetFilename()).GetFilename());
                        m_pMenuItem->Text = m_pTabPage->Text;
                        this->Save();
                }
        }

        System::Void PackageForm::PackageForm_Closing(System::Object^  sender, CancelEventArgs^  e)     {
                if ( m_pPackage->IsChanged() )
                {
                        String ^name = m_pTabPage->Text;
                        if ( name[name->Length - 1] == '*' )
                                name = name->Remove(name->Length - 1);
                        System::Windows::Forms::DialogResult result = MessageBox::Show("Would you like to save changes to the package?\n\n" + name, "Save Package", MessageBoxButtons::YesNoCancel, MessageBoxIcon::Question);

                        if ( result == System::Windows::Forms::DialogResult::Cancel )
                        {
                                e->Cancel = true;
                                return;
                        }
                        else if ( result == System::Windows::Forms::DialogResult::Yes )
                        {
                                if ( !this->CheckSave() )
                                {
                                        e->Cancel = true;
                                        return;
                                }

                                if ( m_pPackage->GetFilename().Empty() )
                                {
                                        SaveFileDialog ^ofd = gcnew SaveFileDialog();
                                        if ( m_pPackage->GetType() == TYPE_XSP )
                                                ofd->Filter = "Ship Files (*.xsp)|*.xsp";
                                        else
                                                ofd->Filter = "Package Files (*.spk)|*.spk";
                                        ofd->FilterIndex = 1;
                                        ofd->RestoreDirectory = true;
                                        if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
                                                m_pPackage->SetFilename(CyStringFromSystemString(ofd->FileName));
                                        else
                                        {
                                                 e->Cancel = true;
                                                 return;
                                        }
                                }

                                if ( !m_pPackage->WriteFile(m_pPackage->GetFilename()) )
                                {
                                        e->Cancel = true;
                                        MessageBox::Show("Unable to save package\n" + SystemStringFromCyString(m_pPackage->GetFilename()), "Save Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
                                        return;
                                }
                        }
                }

                delete m_pPackage;
                m_pPackage = NULL;
        }

        void PackageForm::UpdateMirrors()
        {
                this->ListMirrors->Items->Clear();
                for ( int i = 0; i < m_pPackage->GetMaxWebMirrors(); i++ )
                {
                        ListViewItem ^item = gcnew ListViewItem(SystemStringFromCyString(m_pPackage->GetWebMirror(i)));
                        this->ListMirrors->Items->Add(item);
                        item->ImageIndex = 1;
                }

                this->ListMirrors->AutoResizeColumns(ColumnHeaderAutoResizeStyle::ColumnContent);
                if ( this->ListMirrors->Columns[0]->Width < 100 )
                        this->ListMirrors->Columns[0]->Width = 100;
        }

        void PackageForm::UpdatePackageNames()
        {
                this->ListNames->Items->Clear();
                for ( SNames *n = m_pPackage->GetNamesList()->First(); n; n = m_pPackage->GetNamesList()->Next() )
                {
                        ListViewItem ^item = gcnew ListViewItem(Convert::ToString(n->iLanguage));
                        item->SubItems->Add(SystemStringFromCyString(n->sName));
                        item->ImageIndex = 0;
                        this->ListNames->Items->Add(item);
                }
                this->ListNames->AutoResizeColumns(ColumnHeaderAutoResizeStyle::ColumnContent);
                if ( this->ListNames->Columns[0]->Width < 100 )
                        this->ListNames->Columns[0]->Width = 100;
                if ( this->ListNames->Columns[1]->Width < 100 )
                        this->ListNames->Columns[1]->Width = 100;
        }

        void PackageForm::AddDisplayPic()
        {
                OpenFileDialog ^ofd = gcnew OpenFileDialog();
                ofd->Filter = "Display Images|*.gif;*.png;*.jpg";
                ofd->FilterIndex = 1;
                ofd->RestoreDirectory = true;
                ofd->Multiselect = true;
                ofd->Title = "Select the Display image to add";

                if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
                {
                        array<System::String ^> ^fileArray = ofd->FileNames;
                        for ( int i = 0; i < fileArray->Length; i++ )
                        {
                                CyString file = CyStringFromSystemString(fileArray[i]);
                                m_pDisplayFile = m_pPackage->AddFile(file, "", FILETYPE_ADVERT);
                        }

                        this->UpdateDisplayPic();
                        this->UpdateFileList();
                }
        }

        void PackageForm::AddDisplayIcon()
        {
                OpenFileDialog ^ofd = gcnew OpenFileDialog();
                ofd->Filter = "Icon Files|*.ico;*.png;*.bmp";
                ofd->FilterIndex = 1;
                ofd->RestoreDirectory = true;
                ofd->Multiselect = false;
                ofd->Title = "Select the Icon file to add";

                if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
                {
                        CyString file = CyStringFromSystemString(ofd->FileName);
                        C_File *icon = new C_File(file);
                        if ( icon->ReadFromFile() )
                                m_pPackage->SetIcon(icon, CFileIO(file).GetFileExtension());

                        this->UpdateDisplayIcon();
                        this->UpdateChanged();
                }
        }

        void PackageForm::SaveText()
        {
                if ( this->TextText->Text->Length )
                {
                        if ( this->ListLang->SelectedIndex >= 0 )
                        {
                                int lang = CyStringFromSystemString(this->ListLang->Text).ToInt();
                                if ( this->RadioInstallAfter->Checked )
                                        m_pPackage->AddInstallAfterText(lang, CyStringFromSystemString(this->TextText->Text));
                                else if ( this->RadioInstallBefore->Checked )
                                        m_pPackage->AddInstallBeforeText(lang, CyStringFromSystemString(this->TextText->Text));
                                else if ( this->RadioUninstallBefore->Checked )
                                        m_pPackage->AddUninstallBeforeText(lang, CyStringFromSystemString(this->TextText->Text));
                                else if ( this->RadioUninstallAfter->Checked )
                                        m_pPackage->AddUninstallAfterText(lang, CyStringFromSystemString(this->TextText->Text));
                                this->UpdateChanged();
                        }
                }
        }

        void PackageForm::LoadShipData()
        {
                OpenFileDialog ^ofd = gcnew OpenFileDialog();
                ofd->Filter = "All (*.cat, tships)|*.cat;tships.txt;tships.pck|TShips Files (tships.txt/pck)|tships.txt;tships.pck|Mod Files (*.cat)|*.cat";
                ofd->FilterIndex = 1;
                ofd->RestoreDirectory = true;
                ofd->Multiselect = false;
                ofd->Title = "Select the TShips/Mod file to load ship data from";

                if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
                {
                        // if its a cat file, lets load the text
                        Hashtable ^catText = gcnew Hashtable();

                        if ( String::Compare(IO::FileInfo(ofd->FileName).Extension, ".cat") == 0 )
                        {
                                CyStringList readText;
                                if ( m_pP->ReadTextPage(CyStringFromSystemString(ofd->FileName), &readText, false, 17) )
                                {
                                        for ( SStringList *str = readText.Head(); str; str = str->next )
                                        {
                                                String ^key = SystemStringFromCyString(str->str);
                                                if ( catText->ContainsKey(key) )
                                                        catText[key] = SystemStringFromCyString(str->data);
                                                else
                                                        catText->Add(key, SystemStringFromCyString(str->data));
                                        }
                                }
                        }

                        CyStringList list;
                        if ( m_pP->LoadShipData(CyStringFromSystemString(ofd->FileName), &list) )
                        {
                                LoadShip ^ls = gcnew LoadShip();
                                for ( SStringList *str = list.Head(); str; str = str->next )
                                {
                                        int tId = str->data.GetToken(";", 7, 7).ToInt();
                                        String ^name;
                                        if ( catText->ContainsKey(Convert::ToString(tId)) )
                                                name = Convert::ToString(catText[Convert::ToString(tId)]);
                                        else
                                                name = ((Form1 ^)this->MdiParent)->FindText(-1, 17, tId);
                                        String ^text = ((Form1 ^)this->MdiParent)->FindText(-1, 1266, str->data.GetToken(";", 46, 46).ToInt()) + " " + name;
                                        int variation = str->data.GetToken(";", 51, 51).ToInt();
                                        if ( variation )
                                                text = text + " " + ((Form1 ^)this->MdiParent)->FindText(-1, 17, 10000 + variation);
                                        ls->AddShip(SystemStringFromCyString(str->str), text);
                                }

                                if ( ls->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
                                {
                                        SStringList *str = list.FindString(CyStringFromSystemString(ls->GetData()));
                                        if ( str )
                                        {
                                                ((CXspFile *)m_pPackage)->SetShipData(str->data);
                                                if ( ((CXspFile *)m_pPackage)->GetShipID().Empty() )
                                                {
                                                        CyString id = str->data.GetToken(";", -2);
                                                        while ( id.Right(1) == ";" )
                                                                id.Truncate((int)id.Length() - 1);
                                                        ((CXspFile *)m_pPackage)->SetShipID(id);
                                                        this->TextShipID->Text = SystemStringFromCyString(id);
                                                }

                                                ((CXspFile *)m_pPackage)->SetShipData(str->data);
                                                this->TextShipData->Text = SystemStringFromCyString(str->data);
                                                this->NumTextID->Value = str->data.GetToken(";", 7, 7).ToInt();
                                                this->UpdateChanged();
                                        }
                                }
                        }
                        else
                                MessageBox::Show(this, "Unable to find any ship entries, invalid/missing TShips?", "Error Loading", MessageBoxButtons::OK, MessageBoxIcon::Error);
                }
        }

        void PackageForm::EditShipParts(bool edit)
        {
                 CXspFile *xsp = (CXspFile *)m_pPackage;
                 switch ( this->ComboShipPart->SelectedIndex )
                 {
                        case 0:
                                {
                                        AddShipPart ^component = gcnew AddShipPart((Form1 ^)this->MdiParent);
                                        component->SetComponent(edit);

                                        if ( edit )
                                        {
                                                component->SetSection(m_pSelectedItem->Text);
                                                component->SetSection2(m_pSelectedItem->SubItems[1]->Text);
                                                component->SetData(m_pSelectedItem->SubItems[2]->Text);
                                        }

                                        if ( component->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                                        {
                                                if ( edit )
                                                        xsp->RemoveComponent(CyStringFromSystemString(m_pSelectedItem->Text), CyStringFromSystemString(m_pSelectedItem->SubItems[1]->Text), CyStringFromSystemString(m_pSelectedItem->SubItems[2]->Text));
                                                xsp->AddComponent(CyStringFromSystemString(component->GetSection()), CyStringFromSystemString(component->GetSection2()), CyStringFromSystemString(component->GetData()));
                                                if ( !edit )
                                                        this->UpdateShipPartList();
                                                else
                                                {
                                                        m_pSelectedItem->Text = component->GetSection();
                                                        m_pSelectedItem->SubItems[1]->Text = component->GetSection2();
                                                        m_pSelectedItem->SubItems[2]->Text = component->GetData();
                                                }
                                        }
                                }
                                break;
                        case 1:
                                {
                                        AddShipPart ^dummy = gcnew AddShipPart((Form1 ^)this->MdiParent);
                                        dummy->SetDummy(edit);

                                        if ( edit )
                                        {
                                                dummy->SetSection(m_pSelectedItem->Text);
                                                dummy->SetData(m_pSelectedItem->SubItems[1]->Text);
                                        }

                                        if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                                        {
                                                if ( edit )
                                                        xsp->RemoveDummy(CyStringFromSystemString(m_pSelectedItem->Text), CyStringFromSystemString(m_pSelectedItem->SubItems[1]->Text));
                                                xsp->AddDummy(CyStringFromSystemString(dummy->GetSection()), CyStringFromSystemString(dummy->GetData()));
                                                if ( !edit )
                                                        this->UpdateShipPartList();
                                                else
                                                {
                                                        m_pSelectedItem->Text = dummy->GetSection();
                                                        m_pSelectedItem->SubItems[1]->Text = dummy->GetData();
                                                }
                                        }
                                }
                                break;

                        case 2:
                                {
                                        AddCockpit ^cockpit = gcnew AddCockpit();
                                        if ( edit )
                                                cockpit->SetEdit(m_pSelectedItem->Text, SystemStringFromCyString(CyStringFromSystemString(m_pSelectedItem->SubItems[2]->Text).GetToken(";", 8, 8)), CyStringFromSystemString(m_pSelectedItem->SubItems[2]->Text).GetToken(";", 9, 9).ToInt());
                                        if ( cockpit->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                                        {
                                                if ( !edit )
                                                {
                                                        xsp->NewCockpit(CyStringFromSystemString(cockpit->GetID()), CyStringFromSystemString(cockpit->GetScene()), cockpit->GetMask());
                                                        this->UpdateShipPartList();
                                                }
                                                else
                                                {
                                                        xsp->EditCockpit(CyStringFromSystemString(cockpit->GetID()), CyStringFromSystemString(cockpit->GetScene()), cockpit->GetMask());
                                                        m_pSelectedItem->SubItems[2]->Text = SystemStringFromCyString(xsp->GetCockpitData(CyStringFromSystemString(cockpit->GetID())));
                                                }
                                        }
                                }
                                break;

                        case 3:
                                {
                                        if ( edit )
                                        {
                                                InputBox ^input2 = gcnew InputBox("Enter the filename for cut id: " + SystemStringFromCyString(CyStringFromSystemString(m_pSelectedItem->Text).GetToken(";", 1, 1)), SystemStringFromCyString(CyStringFromSystemString(m_pSelectedItem->Text).GetToken(";", 2, 2)));
                                                if ( input2->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                                                {
                                                        xsp->RemoveCutData(CyStringFromSystemString(m_pSelectedItem->Text));
                                                        xsp->AddCutData(CyStringFromSystemString(SystemStringFromCyString(CyStringFromSystemString(m_pSelectedItem->Text).GetToken(";", 1, 1)) + "; " + input2->GetInput()));
                                                        this->UpdateShipPartList();
                                                }
                                        }
                                        else
                                        {
                                                InputBox ^input = gcnew InputBox("Enter the cut id to add");
                                                if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                                                {
                                                        InputBox ^input2 = gcnew InputBox("Enter the filename for cut id: " + input->GetInput());
                                                        if ( input2->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                                                        {
                                                                xsp->AddCutData(CyStringFromSystemString(input->GetInput() + "; " + input2->GetInput()));
                                                                this->UpdateShipPartList();
                                                        }
                                                }
                                        }
                                }
                                break;

                        case 4:
                                {
                                        AddShipPart ^dummy = gcnew AddShipPart((Form1 ^)this->MdiParent);
                                        dummy->SetBodies(edit);

                                        if ( edit )
                                        {
                                                dummy->SetSection(m_pSelectedItem->Text);
                                                dummy->SetData(m_pSelectedItem->SubItems[1]->Text);
                                        }

                                        if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                                        {
                                                if ( edit )
                                                        xsp->RemoveBodies(CyStringFromSystemString(m_pSelectedItem->Text + ";" + m_pSelectedItem->SubItems[1]->Text));
                                                xsp->AddBodies(CyStringFromSystemString(dummy->GetSection() + ";" + dummy->GetData()));
                                                if ( !edit )
                                                        this->UpdateShipPartList();
                                                else
                                                {
                                                        m_pSelectedItem->Text = dummy->GetSection();
                                                        m_pSelectedItem->SubItems[1]->Text = dummy->GetData();
                                                }
                                        }
                                }
                                break;

                        case 5:
                                {
                                        InputBox ^input = gcnew InputBox("Enter the animation data to add", (!edit) ? "" : m_pSelectedItem->Text);
                                        input->Large();
                                        if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                                        {
                                                if ( edit )
                                                        xsp->RemoveAnimation(CyStringFromSystemString(m_pSelectedItem->Text));
                                                xsp->AddAnimation(CyStringFromSystemString(input->GetInput()));
                                                this->UpdateShipPartList();
                                        }
                                }
                                break;
                 }
        }

        void PackageForm::DropGetDirectories(String ^dir, CyStringList *list, bool packages)
        {
                cli::array<String ^> ^dirList = IO::Directory::GetFileSystemEntries(dir);
                for ( int j = 0; j < dirList->Length; j++ )
                {
                        if ( IO::DirectoryInfo(dirList[j]).Exists )
                                this->DropGetDirectories(dirList[j], list, packages);
                        else
                        {
                                if ( packages )
                                        list->PushBack(CyStringFromSystemString(dirList[j]), "-1");
                                else
                                        list->PushBack(CyStringFromSystemString(dirList[j]), CyString::Number(SPK::GetAutomaticFiletype(CyStringFromSystemString(dirList[j]), NULL)));
                        }
                }
        }

        void PackageForm::RemoveSelectedFiles()
        {
                CLinkList<C_File> removeFiles;
                for ( int i = 0; i < ListFiles->SelectedItems->Count; i++ )
                {
                        int id = CyStringFromSystemString(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).ToInt();
                        C_File *file = m_pPackage->GetFileList()->Get(id);
                        if ( m_pDisplayFile == file )
                                m_pDisplayFile = NULL;
                        removeFiles.push_back(file);
                }

                if ( removeFiles.size() )
                {
                        for ( C_File *f = removeFiles.First(); f; f = removeFiles.Next() )
                                m_pPackage->RemoveFile(f);
                        m_pPackage->UpdateSigned(false);
                        this->UpdateFileList();
                        this->UpdateDisplayPic();
                        this->UpdateChanged();
                }

                if ( !ListFiles->SelectedItems->Count )
                        this->ButRemoveFile->Enabled = false;
        }

        String ^PackageForm::ExtractImport(String ^file, String ^type)
        {
                if ( String::Compare(IO::FileInfo(file).Extension, ".xml") == 0 )
                        return file;
                
                if ( String::Compare(IO::FileInfo(file).Extension, ".pck") == 0 )
                {
                        C_File F(CyStringFromSystemString(file));
                        F.UnPCKFile();
                        if ( F.WriteToFile("tmp") )
                                return "tmp";
                }
                else if ( String::Compare(IO::FileInfo(file).Extension, ".cat") == 0 )
                {
                        CCatFile cat;
                        if ( cat.Open(CyStringFromSystemString(file), "", CATREAD_CATDECRYPT, false) == CATERR_NONE )
                        {
                                if ( cat.ExtractFile(CyStringFromSystemString("types\\" + type + ".pck"), "tmp") )
                                        return "tmp";
                        }
                }

                return "";
        }

        int PackageForm::GetHighestGame()
        {
                return ((Form1 ^)this->MdiParent)->GetHighestGame();
        }


        void PackageForm::ImportData(String ^file, int type)
        {
                CFileIO F(CyStringFromSystemString(file));
                if ( !F.Exists() )
                        return;

                CyStringList *lines = F.ReadLinesStr();
                if ( !lines )
                        return;

                LoadShip ^load = gcnew LoadShip();

                int entryPos = 1;
                int dataPos = 1;
                int dataPos2 = 0;
                bool sections = false;
                CyString section;
                switch ( type )
                {
                        case 2:
                                entryPos = 2;
                                dataPos = 19;
                                load->Cockpits();
                                break;
                        case 3:
                                dataPos2 = 2;
                                load->CutData();
                                break;
                        case 4:
                                sections = true;
                                entryPos = 2;
                                load->Bodies();
                                break;
                        case 1:
                                sections = true;
                                entryPos = 2;
                                dataPos = -1;
                                load->Dummies();
                                break;
                        case 0:
                                sections = true;
                                entryPos = 2;
                                dataPos = -1;
                                load->Components();
                                break;
                }

                int entries2 = 0;
                int entries = -1;
                CyStringList list;
                CyString data;
                int e = 0;
                for ( SStringList *str = lines->Head(); str; str = str->next )
                {
                        str->str.RemoveChar(9);
                        str->str.RemoveChar('\r');
                        str->str.RemoveFirstSpace();
                        if ( str->str.Empty() )
                                continue;
                        if ( str->str[0] == '/' )
                                continue;

                        if ( entries == -1 || (entries <= 0 && sections) )
                        {
                                entries = str->str.GetToken(";", entryPos, entryPos).ToInt();
                                if ( sections )
                                {
                                        section = str->str.GetToken(";", 1, 1);
                                        load->AddGroup(SystemStringFromCyString(section));
                                }
                        }
                        else
                        {
                                if ( type == 4 )
                                {
                                        int max;
                                        CyString *strs = str->str.SplitToken(";", &max);
                                        if ( max && strs )
                                        {
                                                for ( int i = 0; i < max; i++ )
                                                {
                                                        strs[i].RemoveFirstSpace();
                                                        if ( strs[i].Empty() ) continue;
                                                        CyString id = strs[i].GetToken(";", dataPos, dataPos);
                                                        load->AddShip(SystemStringFromCyString(id), "");
                                                        list.PushBack(id, CyString::Number(e) + " " + section + ";" + strs[i]);
                                                        ++e;
                                                        --entries;
                                                }
                                        }

                                        CLEANSPLIT(strs, max)
                                }
                                else if ( type == 0 )
                                {
                                        if ( entries2 )
                                        {
                                                load->AddShip(SystemStringFromCyString(data), SystemStringFromCyString(str->str));
                                                list.PushBack(data, section + ";" + data + ";" + str->str);
                                                --entries2;
                                        }
                                        else
                                        {
                                                data = str->str.GetToken(";", 1, 1);
                                                entries2 = str->str.GetToken(";", 2, 2).ToInt();
                                                ++e;
                                                --entries;
                                        }
                                }
                                else
                                {
                                        CyString id;
                                        if ( dataPos == -1 )
                                                id = str->str; 
                                        else
                                                id = str->str.GetToken(";", dataPos, dataPos); 

                                        if ( dataPos2 )
                                                load->AddShip(SystemStringFromCyString(id), SystemStringFromCyString(str->str.GetToken(";", dataPos2, dataPos2)));
                                        else
                                                load->AddShip(SystemStringFromCyString(id), "");
                                        if ( sections )
                                                list.PushBack(id, CyString::Number(e) + " " + section + ";" + str->str);
                                        else
                                                list.PushBack(id, CyString::Number(e) + " " + str->str);
                                        ++e;
                                        --entries;
                                }
                        }
                }

                if ( load->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                {
                        for ( SStringList *str = load->GetDataList()->Head(); str; str = str->next )
                        {
                                SStringList *s = list.FindString(str->str);
                                if ( s )
                                {
                                        switch ( type )
                                        {
                                                case 0:
                                                        ((CXspFile *)m_pPackage)->AddComponent(s->data.GetToken(";", 1, 1), s->data.GetToken(";", 2, 2), s->data.GetToken(";", 3));
                                                        break;
                                                case 2:
                                                        ((CXspFile *)m_pPackage)->AddCockpit(s->data.GetToken(" ", 2), 0, -1, s->data.GetToken(" ", 1, 1).ToInt());
                                                        break;
                                                case 3:
                                                        ((CXspFile *)m_pPackage)->AddCutData(s->data.GetToken(" ", 2));
                                                        break;
                                                case 4:
                                                        ((CXspFile *)m_pPackage)->AddBodies(s->data.GetToken(" ", 2));
                                                        break;
                                                case 1:
                                                        ((CXspFile *)m_pPackage)->AddDummy(s->data.GetToken(" ", 2).GetToken(";", 1, 1), s->data.GetToken(" ", 2).GetToken(";", 2));
                                                        break;
                                        }
                                }
                        }

                        this->UpdateShipPartList();
                        this->UpdateChanged();
                }

                delete lines;
        }

        void PackageForm::ImportAnimations(String ^file)
        {
                CFileIO F(CyStringFromSystemString(file));
                if ( !F.Exists() )
                        return;

                CyStringList *lines = F.ReadLinesStr();
                if ( !lines )
                        return;


                CyStringList lOut;
                if ( CXspFile::ReadAnimations(lines, &lOut, 0) )
                {
                        LoadShip ^load = gcnew LoadShip();
                        load->Animations();
                        for ( SStringList *str = lOut.Head(); str; str = str->next )
                        {
                                load->AddShip(SystemStringFromCyString(str->str), "");
                        }

                        if ( load->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                        {
                                ((CXspFile *)m_pPackage)->AddAnimation(load->GetDataList());
                                this->UpdateShipPartList();
                                this->UpdateChanged();
                        }
                }

                delete lines;
        }

        void PackageForm::EditDepend()
        {
                 AddDepend ^depend = gcnew AddDepend();
                 depend->SetEdit(m_pSelectedItem->Text, m_pSelectedItem->SubItems[1]->Text, m_pSelectedItem->SubItems[2]->Text);

                 bool builtin = false;
                 if ( String::Compare("<package>", m_pSelectedItem->Text) == 0 && String::Compare("<author>", m_pSelectedItem->SubItems[1]->Text) == 0 )
                 {
                         builtin = true;
                         depend->BuiltIn();
                 }

                 if ( depend->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                 {
                         if ( builtin )
                         {
                                 SNeededLibrary *ns = m_pPackage->FindPackageNeeded("<package>", "<author>");
                                 if ( ns )
                                         ns->sMinVersion = CyStringFromSystemString(depend->GetVersion());
                         }
                         else
                         {
                                 m_pPackage->RemovePackageNeeded(CyStringFromSystemString(m_pSelectedItem->Text), CyStringFromSystemString(m_pSelectedItem->SubItems[1]->Text));
                                 m_pPackage->AddNeededLibrary(CyStringFromSystemString(depend->GetName()), CyStringFromSystemString(depend->GetAuthor()), CyStringFromSystemString(depend->GetVersion()));
                         }
                         this->UpdateDependacies();
                         this->UpdateChanged();
                 }
        }
}