Subversion Repositories spk

Rev

Rev 226 | 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
	{
274 cycrow 66
		_lModels = new Utils::WStringList;
170 cycrow 67
		if(!m_pShip->readSceneModels(*_lModels) || _lModels->empty())
68
		{
36 cycrow 69
			m_bError = true;
70
			m_sError = "Unable to read the scene file to extract model data";
71
		}
72
		++m_iStatus;
73
	}
74
	else if ( m_iStatus == IMPORTSHIP_PACK )
75
	{
76
		m_pShip->PackAllFiles();
77
		m_iStatus = IMPORTSHIP_DONE;
78
	}
79
	else if ( m_iStatus > IMPORTSHIP_EXTRACTSCENE )
80
	{
170 cycrow 81
		m_bError = !m_pShip->processSceneFileSection(m_iStatus, m_pVfs, *_lModels, m_pInfo);
36 cycrow 82
		if ( m_bError ) m_sError = "Unable to process scene file (Status=" + (long)m_iStatus;
83
		++m_iStatus;
84
	}
85
}
86
 
87
void ImportShip::_runNext()
88
{
89
	 if ( m_bError )
90
	 {
91
		 this->Close();
92
		 return;
93
	 }
94
 
95
	 if ( m_iStatus > IMPORTSHIP_SCENE )
96
		 this->pictureBox2->Visible = true;
97
	 if ( m_iStatus > IMPORTSHIP_EXTRACTSCENE )
98
		 this->pictureBox1->Visible = true;
99
	 if ( m_iStatus > IMPORTSHIP_DUMMIES )
100
		 this->pictureBox3->Visible = true;
101
	 if ( m_iStatus > IMPORTSHIP_COMPONANT )
102
		 this->pictureBox4->Visible = true;
103
	 if ( m_iStatus > IMPORTSHIP_MODELS )
104
		 this->pictureBox5->Visible = true;
105
	 if ( m_iStatus > IMPORTSHIP_TEXTURES )
106
		 this->pictureBox6->Visible = true;
107
	 if ( m_iStatus > IMPORTSHIP_TEXTS )
108
		 this->pictureBox7->Visible = true;
109
	 if ( m_iStatus > IMPORTSHIP_BODIES )
110
		 this->pictureBox8->Visible = true;
111
	 if ( m_iStatus > IMPORTSHIP_COCKPITS )
112
		 this->pictureBox9->Visible = true;
113
	 if ( m_iStatus > IMPORTSHIP_PACK )
114
		 this->pictureBox10->Visible = true;
115
 
116
	 if ( m_iStatus < IMPORTSHIP_DONE )
117
		 this->backgroundWorker1->RunWorkerAsync();
116 cycrow 118
	 else {
36 cycrow 119
		 this->button1->Visible = true;
224 cycrow 120
		 if ( _sShipName && _sShipName->Length ) m_pShip->setName(_WS(_sShipName));
116 cycrow 121
	 }
36 cycrow 122
}
123
 
124
void ImportShip::_cleanUp()
125
{
126
	delete m_pInfo;
170 cycrow 127
	if ( _lModels )
128
		delete _lModels;
36 cycrow 129
}
130
}