Subversion Repositories spk

Rev

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

Rev Author Line No. Line
1 cycrow 1
#include "../StdAfx.h"
2
#include "ImportShip.h"
3
 
36 cycrow 4
namespace Creator {
116 cycrow 5
ImportShip::ImportShip(String ^id, String ^shipName, CVirtualFileSystem *pVfs)
36 cycrow 6
{
7
	InitializeComponent();
8
 
116 cycrow 9
	if ( shipName && shipName->Length )
10
		this->Text = this->Text + ": " + shipName + " (" + id + ")";
11
	else
12
		this->Text = this->Text + " (" + id + ")";
36 cycrow 13
 
14
	this->button1->Visible = false;
15
	this->pictureBox1->Visible = false;
16
	this->pictureBox2->Visible = false;
17
	this->pictureBox3->Visible = false;
18
	this->pictureBox4->Visible = false;
19
	this->pictureBox5->Visible = false;
20
	this->pictureBox6->Visible = false;
21
	this->pictureBox7->Visible = false;
22
	this->pictureBox8->Visible = false;
23
	this->pictureBox9->Visible = false;
24
	this->pictureBox10->Visible = false;
25
 
26
	m_pVfs = pVfs;
27
	m_bError = false;
28
	m_sID = id;
29
	m_pShip = NULL;
30
 
31
	m_pInfo = new CProgressInfoDone;
32
	m_pInfo->UpdateStatus(IMPORTSHIP_NONE);
170 cycrow 33
	_lModels = NULL;
36 cycrow 34
	m_iStatus = IMPORTSHIP_SCENE;
116 cycrow 35
 
36
	_sShipName = shipName;
36 cycrow 37
}
38
 
39
void ImportShip::StartImport()
40
{
41
	m_pShip = new CXspFile();
224 cycrow 42
	if ( _sShipName ) m_pShip->setName(_WS(_sShipName));
36 cycrow 43
	m_bError = false;
44
	m_iStatus = IMPORTSHIP_SCENE;
45
	this->backgroundWorker1->RunWorkerAsync();
46
}
47
 
48
void ImportShip::Import()
49
{
50
	m_bError = false;
51
	if ( m_iStatus <= IMPORTSHIP_SCENE )
52
	{
53
		// make sure the id is correct
225 cycrow 54
		Utils::WString data = _WS(m_sID);
36 cycrow 55
		data.removeChar('\r');
226 cycrow 56
		while(data.right(1) == L";")
36 cycrow 57
			data.truncate(-1);
58
 
59
		m_bError = !m_pShip->startExtractShip(m_pVfs, data, m_pInfo);
60
		if ( m_bError ) m_sError = "Unable to extract scene file";
61
 
62
		m_iStatus = IMPORTSHIP_EXTRACTSCENE;
63
	}
64
	else if ( m_iStatus == IMPORTSHIP_EXTRACTSCENE )
65
	{
170 cycrow 66
		if(!m_pShip->readSceneModels(*_lModels) || _lModels->empty())
67
		{
36 cycrow 68
			m_bError = true;
69
			m_sError = "Unable to read the scene file to extract model data";
70
		}
71
		++m_iStatus;
72
	}
73
	else if ( m_iStatus == IMPORTSHIP_PACK )
74
	{
75
		m_pShip->PackAllFiles();
76
		m_iStatus = IMPORTSHIP_DONE;
77
	}
78
	else if ( m_iStatus > IMPORTSHIP_EXTRACTSCENE )
79
	{
170 cycrow 80
		m_bError = !m_pShip->processSceneFileSection(m_iStatus, m_pVfs, *_lModels, m_pInfo);
36 cycrow 81
		if ( m_bError ) m_sError = "Unable to process scene file (Status=" + (long)m_iStatus;
82
		++m_iStatus;
83
	}
84
}
85
 
86
void ImportShip::_runNext()
87
{
88
	 if ( m_bError )
89
	 {
90
		 this->Close();
91
		 return;
92
	 }
93
 
94
	 if ( m_iStatus > IMPORTSHIP_SCENE )
95
		 this->pictureBox2->Visible = true;
96
	 if ( m_iStatus > IMPORTSHIP_EXTRACTSCENE )
97
		 this->pictureBox1->Visible = true;
98
	 if ( m_iStatus > IMPORTSHIP_DUMMIES )
99
		 this->pictureBox3->Visible = true;
100
	 if ( m_iStatus > IMPORTSHIP_COMPONANT )
101
		 this->pictureBox4->Visible = true;
102
	 if ( m_iStatus > IMPORTSHIP_MODELS )
103
		 this->pictureBox5->Visible = true;
104
	 if ( m_iStatus > IMPORTSHIP_TEXTURES )
105
		 this->pictureBox6->Visible = true;
106
	 if ( m_iStatus > IMPORTSHIP_TEXTS )
107
		 this->pictureBox7->Visible = true;
108
	 if ( m_iStatus > IMPORTSHIP_BODIES )
109
		 this->pictureBox8->Visible = true;
110
	 if ( m_iStatus > IMPORTSHIP_COCKPITS )
111
		 this->pictureBox9->Visible = true;
112
	 if ( m_iStatus > IMPORTSHIP_PACK )
113
		 this->pictureBox10->Visible = true;
114
 
115
	 if ( m_iStatus < IMPORTSHIP_DONE )
116
		 this->backgroundWorker1->RunWorkerAsync();
116 cycrow 117
	 else {
36 cycrow 118
		 this->button1->Visible = true;
224 cycrow 119
		 if ( _sShipName && _sShipName->Length ) m_pShip->setName(_WS(_sShipName));
116 cycrow 120
	 }
36 cycrow 121
}
122
 
123
void ImportShip::_cleanUp()
124
{
125
	delete m_pInfo;
170 cycrow 126
	if ( _lModels )
127
		delete _lModels;
36 cycrow 128
}
129
}