Ejemplo n.º 1
0
void CExport::PreviewDebug(CApplication* pApplication, int layoutid)
{
	ProgressDlg.Start("Loading debug");
	m_bScreensaver = false;

	application = pApplication;

	LayoutBlock.allocator = &g_allocator;
	eventBlock.allocator = &g_allocator;
	appBlock.allocator = &g_allocator;
	imageBlock.allocator = &g_allocator;
	hlslBlock.allocator = &g_allocator;
	menuBlock.allocator = &g_allocator;

	CPath path;
	path.SetToAppDataDirectory("Scirra");
	CString OutPath = GetTempExeFile(path.GetFullPath());

	CString iniPath;
	iniPath.Format("%sConstruct.ini", path.GetFullPath());

	CIni ini;
	ini.SetPathName(iniPath);
	path.SetToCurrentDirectory();
	ini.WriteString("Path", "Install", path.GetFullPath());

	CString DataEXE;

	if (application->runtime == CApplication::rt_application)
		DataEXE.Format("%sData\\App_pd", path.GetFullPath());

	else if (application->runtime == CApplication::rt_directx)
		DataEXE.Format("%sData\\DX9_pd", path.GetFullPath());

	if (application->game_information.use_python)
		DataEXE += "s";		// script enabled

	DataEXE += ".exe";

	// Copy runtime.exe to the target file
	CopyFile(DataEXE, OutPath, false);

	// File copied, assume 10%
	ProgressDlg.SetProgress(10);

	DoExport(true, OutPath, false, layoutid);

	// Execute temp
	ShellExecute(NULL, "open", OutPath, NULL, NULL, SW_SHOW);

	// Done
	ProgressDlg.Finish();
}
Ejemplo n.º 2
0
void TemplateDialog::OnCreate() 
{
	UpdateData();

	// Create subfolder
	CPath Get;
	Get.SetToCurrentDirectory();

	CString Name;
	m_Name.GetWindowText(Name);

	if (Name == "")
	{
		CErrorDlg dlg;
		dlg.Error("Invalid name", "Please enter a name for your project.");
		return;
	}

	CString Path;
	Path.Format("%s\\Projects\\", Get.GetFullPath());
	CreateDirectory(Path, NULL);
	Path.Format("%s\\Projects\\%s\\", Get.GetFullPath(), Name);
	CreateDirectory(Path, NULL);

	// Copy over the template
	POSITION thePos = m_Templates.GetFirstSelectedItemPosition();
	int theItem     = m_Templates.GetNextSelectedItem(thePos);

	CString Title   = m_Templates.GetItemText(theItem, 0);

	CString ToCopy;
	ToCopy.Format("%sTemplates\\%s.cst", Get.GetFullPath(), Title);
	CString CopyTo;
	CopyTo.Format("%sProjects\\%s\\", Get.GetFullPath(), Name);
	CopyTo += Name;
	CopyTo += ".cap";

	CopyFile(ToCopy, CopyTo, FALSE);

	CApplication* pApp = g_MainFrame->DoLoad(CopyTo);

	if (pApp) {
		m_Name.GetWindowText(pApp->file_information.name);
		m_Author.GetWindowTextA(pApp->file_information.creator);
	}

	g_MainFrame->project_bar.tree.Select(g_MainFrame->project_bar.tree.GetChildItem(pApp->tree_items.application), TVGN_CARET);
	//g_MainFrame->project_bar.OnLButtonDblClk(NULL, NULL);	

	EndDialog(0);
}
Ejemplo n.º 3
0
void CScriptDlg::HelpMe()
{
	// When we double click on scintilla, it highlights a word. We use this word to get help information
	CScintillaWnd* pSelected = GetSelectedScintilla();
	CString selected = pSelected->GetSelectedText();

	selected.MakeLower();

	CPath Path;
	Path.SetToCurrentDirectory();

	CString Base;
	Base.Format("%sPyAutoC\\Help\\", Path.GetFullPath());

	TRY
	{
		CFile File(Base + selected + ".py", CFile::modeRead);

		char* ReadIn = new char[File.GetLength() + 1];
		File.Read(ReadIn, File.GetLength());
		ReadIn[File.GetLength()] = '\0';

		// Store details
		int Length = File.GetLength();
		CString Info;
		Info.Format("%s", ReadIn);

		// Delete memory
		delete[] ReadIn;

		m_Help.SetText(Info);
		m_Help.SendMessage(SCI_SETSEL,0,0);
	}
	CATCH(CFileException, e)
	{
		TRY
		{
			CFile File(Base + "default.txt", CFile::modeRead);

			char* ReadIn = new char[File.GetLength() + 1];
			File.Read(ReadIn, File.GetLength());
			ReadIn[File.GetLength()] = '\0';

			// Store details
			int Length = File.GetLength();
			CString Info;
			Info.Format("%s", ReadIn);

			// Delete memory
			delete[] ReadIn;

			m_Help.SetText(Info);
		}
		CATCH(CFileException, e)
		{
			// no help and no default file! do nothing
			return;
		}
		END_CATCH

		// no help for this line
		return;
	}
Ejemplo n.º 4
0
void CScriptDlg::InitPythonInfo()
{
	// First add some standard keywords into our intellisense
	CString keywords = KEYWORDS; // 
	keywords += " ";

	CString _keyword = "";
	for(int i = 0; i < keywords.GetLength(); i++)
	{
		char letter = keywords.GetAt(i);
		if(letter == ' ')
		{
			// Add our keyword
			PyInfoKeyword* key = &m_Intell.keywords[_keyword];
			key->name = _keyword;
			key->pParent = &m_Intell;

			m_IntellMap[_keyword][&m_Intell] = PY_KEYWORD;
			
			_keyword = "";
		}
		else 
			_keyword += letter;
	}
	
	// Now add operators
/*	m_IntellMap["+"][&m_Intell] = PY_OPERATOR;	
	m_IntellMap["*"][&m_Intell] = PY_OPERATOR;		
	m_IntellMap["/"][&m_Intell] = PY_OPERATOR;
	m_IntellMap["-"][&m_Intell] = PY_OPERATOR;
	m_IntellMap["="][&m_Intell] = PY_OPERATOR;
	m_IntellMap["=="][&m_Intell] = PY_OPERATOR;
	m_IntellMap["!="][&m_Intell] = PY_OPERATOR;
	m_IntellMap["<"][&m_Intell] = PY_OPERATOR;
	m_IntellMap[">"][&m_Intell] = PY_OPERATOR;
	m_IntellMap["<="][&m_Intell] = PY_OPERATOR;
	m_IntellMap[">="][&m_Intell] = PY_OPERATOR;
	m_IntellMap["("][&m_Intell] = PY_OPERATOR;
	m_IntellMap[")"][&m_Intell] = PY_OPERATOR;
	m_IntellMap["["][&m_Intell] = PY_OPERATOR;
	m_IntellMap["]"][&m_Intell] = PY_OPERATOR;
	m_IntellMap[":"][&m_Intell] = PY_OPERATOR;
	m_IntellMap["+="][&m_Intell] = PY_OPERATOR;
	m_IntellMap["-="][&m_Intell] = PY_OPERATOR;
	m_IntellMap["*="][&m_Intell] = PY_OPERATOR;
	m_IntellMap["/="][&m_Intell] = PY_OPERATOR;*/
	// Load info from file

	CPath Path;
	Path.SetToCurrentDirectory();
	
	CString FilePath;
	FilePath.Format("%sPyAutoC\\info.txt", Path.GetFullPath());
	
	CFile File(FilePath, CFile::modeRead);
	char* ReadIn = new char[File.GetLength() + 1];
	File.Read(ReadIn, File.GetLength());
	ReadIn[File.GetLength()] = '\0';	
	
	// Store details
	int Length = File.GetLength();
	CString Functions;
	Functions.Format("%s", ReadIn);	


	// Read in functions
	int Start = 0;
	int End = 0;

	list<CString> infoList;

	while(End = Functions.Find('\n', Start))
	{
		if(End == -1)
			End = Length+1;

		CString Function = Functions.Mid(Start, End - Start - 1);
		Start = End + 1;

		infoList.push_back(Function);

		if(End == Length+1)
			break;
	}

	// Make sure to close file
	File.Close();


/////////////////////////////////////////////

	list<CString>::iterator i;
	i = infoList.begin();


	for(;i!= infoList.end(); i++)
	{
		if(StringStartsWith(*i, "    class "))
		{
			CString className = ExtractKeyword( (*i).Mid(10) );
			
			if(!className.IsEmpty())
			{
				// Add a new class
				PyInfoClass* pClass = &m_Intell.classes[className];
				pClass->pParent = &m_Intell;
				pClass->name = className;

				m_IntellMap[className][&m_Intell] = PY_CLASS;

				i++;
				if(i != infoList.end()) 
				{
					if(StringStartsWith(*i, "     |  "))
					{
						pClass->help = (*i).Mid(8);
					}
			
					bool addFunctions = false;
					bool addVariables = false;
					for(i++; i!= infoList.end(); i++)
					{
						if(StringStartsWith(*i, "     |  Methods"))
						{
							addFunctions = true;
							addVariables = false;
						}
						else if(StringStartsWith(*i, "     |  Data"))
						{
							addFunctions = false;
							addVariables = true;
						}
						else if(StringStartsWith(*i, "     |  ----"))
						{
							addFunctions = false;
							addVariables = false;
						}
						else if(!StringStartsWith(*i, "     |"))
						{
							addFunctions = false;
							addVariables = false;
							break; // break out of our for loop - ie: finish processing this class
						}
						else if(!StringStartsWith(*i, "     |      "))
						{
							CString name = ExtractKeyword(*i);
							if(!name.IsEmpty())
							{
								if(addFunctions)
								{
									// Add a function to the class
									PyInfoFunc* pFunc = &pClass->functions[name];
									pFunc->pParent = pClass;
									pFunc->name = name;

									m_IntellMap[name][pClass] = PY_FUNCTION;
									i++;
									if(i != infoList.end()) 
									{
										pFunc->help = (*i).Mid(12);
									}
								}
								if(addVariables)
								{
									// Add a variable to the class
									PyInfoVar* pVar = &pClass->variables[name];
									pVar->pParent = pClass;
									pVar->name = name;

									m_IntellMap[name][pClass] = PY_VARIABLE;
									i++;
									if(i != infoList.end()) 
									{
										pVar->help = (*i).Mid(12);
									}
								}
							}
						}
					}
				}
			}
		} // if class
		
		// Main functions
		else if(StringStartsWith(*i, "    ") && !StringStartsWith(*i, "        "))
		{
			CString name = ExtractKeyword(*i);
			if(!name.IsEmpty())
			{
				PyInfoFunc* pFunc = &m_Intell.functions[name];
				pFunc->pParent = &m_Intell;
				pFunc->name = name;

				m_IntellMap[name][&m_Intell] = PY_FUNCTION;
				i++;
				if(i != infoList.end())
				{
					pFunc->help = (*i).Mid(8); 
				}
			}
		}
	}
	//////////////////////////////
	// Parsing of txt file complete

	InitPythonForObjects();

}
Ejemplo n.º 5
0
void AnimatorBar::OnRClickFilmStrip(NMHDR *pNMHDR, LRESULT *pResult)
{
	if (m_pCurrentAnimation == NULL)
		return;

	POINT MousePosition;
	GetCursorPos(&MousePosition);

	CExtPopupMenuWnd * popup = new CExtPopupMenuWnd;
	popup->LoadMenu(m_hWnd, IDR_BLANK, true, false);
	popup->ItemRemove(0);

	UINT ChosenItem = 0;

	// Add frame
	popup->ItemInsertCommand(1, -1, "Add frame", NULL, NULL);

	bool bIsSel = false;

	POSITION Pos = film_strip.GetFirstSelectedItemPosition();

	if(!m_pCurrentAnimation)
		return;

	if(!m_pCurrentAnimation->supportsFrames())
		return;

	while(Pos)
	{
		int Item = film_strip.GetNextSelectedItem(Pos);
		if (Item != -1)
			bIsSel = true;
	}

	// Import
	popup->ItemInsertCommand(3, -1, AB_IMPORTFRAME, NULL, NULL);
	popup->ItemBoldGet(0);

	// Copy/paste
	popup->ItemInsertCommand();

	// Remove frame(s)
	if (bIsSel)
		popup->ItemInsertCommand(2, -1, AB_REMOVEFRAME, NULL, NULL);

	if (film_strip.GetItemCount() != 1)
		popup->ItemInsertCommand(7, -1, AB_CUTFRAMES, NULL, NULL);

	popup->ItemInsertCommand(4, -1, AB_COPYFRAMES, NULL, NULL);
	popup->ItemInsertCommand(5, -1, AB_PASTEFRAMES, NULL, NULL);
	popup->ItemInsertCommand(10, -1, AB_DUPLICATEFRAMES, NULL, NULL);

	popup->ItemInsertCommand();

	// flip vertical/horizontal
	popup->ItemInsertCommand(8, -1, AB_MIRRORFRAMES, NULL, NULL);
	popup->ItemInsertCommand(9, -1, AB_FLIPFRAMES, NULL, NULL);

	// Explore
	popup->ItemInsertCommand();
	popup->ItemInsertCommand(6, -1, AB_LAUNCHEXPLORER, NULL, NULL);

	// Explore
	popup->ItemInsertCommand();
	popup->ItemInsertCommand(11, -1, AB_COPYCOLLISIONMASKTOEACHFRAME, NULL, NULL);


	// Show menu
	popup->TrackPopupMenu(TPMX_DO_MESSAGE_LOOP | TPMX_NO_WM_COMMAND | TPMX_NO_CMD_UI, MousePosition.x, MousePosition.y, NULL, NULL, NULL, &ChosenItem);
		
	if (ChosenItem == 1)
		AddFrame();

	else if (ChosenItem == 2)
		RemoveFrame();

	else if (ChosenItem == 3)
	{
		CImportImagesDlg ImportDlg;
		if (ImportDlg.DoModal() == IDOK)
		{			
			for(list<CImageResource>::iterator i = ImportDlg.m_Images.begin(); i!= ImportDlg.m_Images.end(); i++)
			{
				int id = layout->AddImage(i->bitmap.GetWidth(), i->bitmap.GetHeight());

				m_pCurrentAnimation->m_Images.push_back(id);
				m_pCurrentAnimation->m_FrameTimes.push_back(1.0);

				CImageResource* image = application->resources.FindImageResourceFromNumber(id);
				image->bitmap.Copy(i->bitmap);

				image->m_Action = i->m_Action;
				image->m_Hotspot = i->m_Hotspot;
				image->m_Collision = i->m_Collision;
				
			}
			
			UpdateFilmStrip();
		}
	}

	// copy
	else if (ChosenItem == 4)
	{	
		CAnimEdFrame* pFrames = new CAnimEdFrame;
		pFrames->m_anim_ed = this;
		DROPEFFECT de = DROPEFFECT_NONE;
		m_pDDMgr.PrepareDrop(DO_CLIPBOARD, "Construct Frames", pFrames, &de);
	}

	// cut
	else if (ChosenItem == 7)
	{
		CAnimEdFrame* pFrames = new CAnimEdFrame;
		pFrames->m_anim_ed = this;
		DROPEFFECT de = DROPEFFECT_NONE;
		m_pDDMgr.PrepareDrop(DO_CLIPBOARD, "Construct Frames", pFrames, &de);

		RemoveFrame();
	}

	// paste
	else if (ChosenItem == 5)
	{
		if (m_pDDMgr.OkToPaste())
		{
			CAnimEdFrame pFrames;
			pFrames.m_anim_ed = this;
			m_pDDMgr.DoDrop(&pFrames,
							  NULL,
							  "Construct Frames");
		}
	}

	// duplicate
	else if (ChosenItem == 10)
	{	
		CAnimEdFrame* pFrames = new CAnimEdFrame;
		pFrames->m_anim_ed = this;
		DROPEFFECT de = DROPEFFECT_NONE;
		m_pDDMgr.PrepareDrop(DO_CLIPBOARD, "Construct Frames", pFrames, &de);

		if (m_pDDMgr.OkToPaste())
		{
			CAnimEdFrame pFrames;
			pFrames.m_anim_ed = this;
			m_pDDMgr.DoDrop(&pFrames,
							  NULL,
							  "Construct Frames");
		}
	}
	// Copy collision mask to every other frame
	else if (ChosenItem == 11)
	{
		// Get the frame we right clicked on
		POSITION pos = film_strip.GetFirstSelectedItemPosition();
		if(pos)
		{
			int nItem = film_strip.GetNextSelectedItem(pos);
			int handle = m_pCurrentAnimation->m_Images.at(nItem);
		
			int result = MessageBox("Click 'OK' to confirm you want to copy the collision mask of this selected frame to every other frame in the animation package", "Construct", MB_OKCANCEL);

			if(result == IDOK){
				CImageResource* res = application->resources.FindImageResourceFromNumber(handle);
				if(!res)
					MessageBox("Error. Image resource could not be found for this animation frame");
				else
				{
					if(!res->m_Collision.IsValid())
						res->m_Collision = res->bitmap; // copy
					
					application->resources.CopyCollisionMaskToEveryFrameInAnimation(m_pAnimation, res); 

				}
			
				
		}
		}

	}

	// Launch explorer
	else if (ChosenItem == 6)
	{
		CPath Path;
		Path.SetToCurrentDirectory();
		
		CString InfoPath;
		InfoPath.Format("%sImages\\", Path.GetFullPath());

		// make sure directory exists
		::CreateDirectory(InfoPath, NULL);

		// now open file
		InfoPath += "frames.txt";
		CFile File(InfoPath, CFile::modeWrite | CFile::modeCreate);
	

		int index = 0;
		for(vector<int>::iterator i = m_pCurrentAnimation->m_Images.begin(); i!= m_pCurrentAnimation->m_Images.end(); i++)
		{
			CImageResource* img = application->resources.FindImageResourceFromNumber(*i);
			if(img)
			{
				CString nl;
				nl.Format("%c%c", 13,10);
				index ++;
				CString SavePath;
				SavePath.Format("%sImages\\Frame %d.png", Path.GetFullPath(), index);
				CxImage backup = img->bitmap;
				img->Predivide();
				img->bitmap.Save(SavePath,CXIMAGE_FORMAT_PNG);
				img->bitmap = backup;

				if(img->m_Collision.IsValid())
				{
					SavePath.Format("%sImages\\Mask %d.png", Path.GetFullPath(), index);
					img->m_Collision.Save(SavePath,CXIMAGE_FORMAT_PNG);
				}
				else
				{
					SavePath.Format("%sImages\\Mask %d.png", Path.GetFullPath(), index);
					img->bitmap.Save(SavePath,CXIMAGE_FORMAT_PNG);
				}


				CString Info;
				Info.Format("Frame %d%sPivotX%s%d%sPivotY%s%d%s", index, nl,nl, img->m_Hotspot.x, nl,nl, img->m_Hotspot.y, nl);
				for(map<CString, CPoint>::iterator a = img->m_Action.begin(); a!= img->m_Action.end(); a++)
				{
					Info.Format("%s%s%s%d%s%d%s", Info, a->first, nl, a->second.x, nl, a->second.y, nl);
				}
				Info += nl;
				File.Write((const char*)Info, Info.GetLength() * sizeof(char));


			}
		}
		File.Close();

		CString LaunchPath;
		LaunchPath.Format("%sImages\\", Path.GetFullPath());

		ShellExecute(NULL,  "open", LaunchPath, NULL, NULL, SW_SHOW);

		int result = MessageBox("Click 'OK' to reimport the images that have been exported to Explorer.", "Construct", MB_OKCANCEL);

		if(result == IDOK)
		{
			int result2 = MessageBox("Import collision mask?", "Construct", MB_YESNOCANCEL);
			int index = 0;
			for(vector<int>::iterator i = m_pCurrentAnimation->m_Images.begin(); i!= m_pCurrentAnimation->m_Images.end(); i++)
			{
				index ++;
				CImageResource* img = application->resources.FindImageResourceFromNumber(*i);
			
				CString SavePath;
				SavePath.Format("%sImages\\Frame %d.png", Path.GetFullPath(), index);			
				
				img->bitmap.Load(SavePath,CXIMAGE_FORMAT_PNG);
				img->Premultiply();

				if(result2 == IDYES)
				{
				SavePath.Format("%sImages\\Mask %d.png", Path.GetFullPath(), index);			
				img->m_Collision.Load(SavePath,CXIMAGE_FORMAT_PNG);
				}
				if(result2 == IDNO)
				{
					if(img->m_Collision.IsValid())
						img->m_Collision.Destroy();
				}

				application->m_image_to_texture.erase(img->m_FixedID);

				img->small_thumbnail.Destroy();
				img->large_thumbnail.Destroy();
			}

			application->resources.images_changed = true;

			AnimationHasChanged();
			UpdateFilmStrip();
		}
	}

	else if (ChosenItem == 8)
	{
		// mirror
		POSITION position = film_strip.GetFirstSelectedItemPosition();

		if(!m_pCurrentAnimation)
			return;

		vector<int>& images = m_pCurrentAnimation->m_Images;

		while(position)
		{
			int item = film_strip.GetNextSelectedItem(position);

			if (item == -1) break;

			CImageResource* image = application->resources.FindImageResourceFromNumber(images[item]);
			image->Mirror();

			application->resources.images_changed = true;
		}

		AnimationHasChanged();
		UpdateFilmStrip();
	}

	else if (ChosenItem == 9)
	{
		// mirror
		POSITION position = film_strip.GetFirstSelectedItemPosition();

		if(!m_pCurrentAnimation)
			return;

		vector<int>& images = m_pCurrentAnimation->m_Images;

		while(position)
		{
			int item = film_strip.GetNextSelectedItem(position);

			if (item == -1) break;

			CImageResource* image = application->resources.FindImageResourceFromNumber(images[item]);
			image->Flip();

			application->resources.images_changed = true;
		}

		AnimationHasChanged();
		UpdateFilmStrip();
	}
}
Ejemplo n.º 6
0
void CExport::GenerateImages()
{
	// 25-80% progress
	BYTE* tempBuffer = NULL;
	long theSize;
	int index = 0;

	CString oldAppPath = main_frame->m_INI.GetString("General", "ImageCacheApp");
	CString newAppPath = application->file_information.file_path;

	CPath path;
	path.SetToCurrentDirectory();
	CString cachePath = path.GetFullPath();
	cachePath += "Data\\imagecache.bin";

	// Check if there is a cached image block we can use
	if (application == pLastAppCachedImageBlock && !application->resources.images_changed && fileexists(cachePath) && oldAppPath == newAppPath) {
		imageBlock.load(cachePath);
		return;
	}

	// Write the app path to the INI so the cache doesnt get used with the wrong application
	main_frame->m_INI.WriteString("General", "ImageCacheApp", newAppPath);

	// Write image count
	imageBlock<<(int)application->resources.images.size();

	// Loop and add resources.images
	for (list<CImageResource>::iterator i = application->resources.images.begin(); i != application->resources.images.end(); i++, index++)
	{
		CxImage& im = i->bitmap;
		
		if (application->runtime == CApplication::rt_application)
			im.Encode(tempBuffer, theSize, CXIMAGE_FORMAT_BMP);
		else
			im.Encode(tempBuffer, theSize, CXIMAGE_FORMAT_PNG);

		// Write image ID
		imageBlock<<(int)i->m_FixedID;

		// Write image hotspot
		imageBlock << i->m_Hotspot.x;
		imageBlock << i->m_Hotspot.y;

		// Write image action points
		int apointsize = i->m_Action.size();
		imageBlock << apointsize;
		for(map<CString, CPoint>::iterator it = i->m_Action.begin(); it!= i->m_Action.end(); it++)
		{
			imageBlock << it->second.x << it->second.y << it->first;
		}

		// Write image data size
		imageBlock<<(int)theSize;

		// Write image data code
		imageBlock.append(tempBuffer, theSize);	
		
		// Free memory using CxImage (for malloc/new compatibility)
		im.FreeMemory(tempBuffer);

		// Generate a collision mask
		BYTE* bits;
		int pitch;
		CxImage* pCol = &im;
		if(i->m_Collision.IsValid())
		{
			pCol = & i->m_Collision;
		}

		CreateCollisionMask(*pCol, bits, pitch);

		imageBlock<< pCol->GetWidth();
		imageBlock<< pCol->GetHeight();
		imageBlock<< pitch;
		imageBlock.append(bits, pitch * pCol->GetHeight());

		// CreateCollisionMask allocated bits so free it
		delete[] bits;

		// CxImage requires the tempBuffer parameter be NULL (for some reason)
		tempBuffer = NULL;

		// Progress 25-80% for this function
		ProgressDlg.SetProgress(25 + (index * 55) / application->resources.images.size());
	}

	// Dump the image block to file
	imageBlock.save(cachePath);

	pLastAppCachedImageBlock = application;
	application->resources.images_changed = false;
}
Ejemplo n.º 7
0
void CExport::DoExport(bool previewMode, const CString& pathName, bool bApp, int layoutid)
{
	// Progress dialog is going from 10% to 100% in this function

	// Make the DLL list
	CList<CString, CString&> dllList;

	CPath path;
	path.SetToCurrentDirectory();

	// Allocate some initial space for the binary blocks
	imageBlock.allocate(20000);			// 20kb initial image buffer
	eventBlock.allocate(5000);			// 5kb initial event buffer
	LayoutBlock.allocate(5000);			// 5kb initial frame buffer
	appBlock.allocate(1000);			// 1kb initial app buffer
	hlslBlock.allocate(5000);			// 5kb initial hlsl buffer
	menuBlock.allocate(1000);

	// Generate
	GenerateLayout(dllList);	// also loads DLLs to dllList
	ProgressDlg.SetProgress(15);
	GenerateEvents();
	ProgressDlg.SetProgress(20);
	GenerateApplicationData(layoutid);
	ProgressDlg.SetProgress(25);
	GenerateImages();				// Longest job, use 25-80%
	ProgressDlg.SetProgress(80);

	// Open the file for addition of file data in resource
	m_UpdateHandle = BeginUpdateResource(pathName, FALSE);

	// Do python
	GeneratePython();

	// HLSL
	UpdateResource(m_UpdateHandle, "HLSL", MAKEINTRESOURCE(994), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
					hlslBlock.ptr(), hlslBlock.size());

	ProgressDlg.SetProgress(81);

	// Images
	UpdateResource(m_UpdateHandle, "IMAGEBLOCK", MAKEINTRESOURCE(995), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
					imageBlock.ptr(), imageBlock.size());

	ProgressDlg.SetProgress(82);

	// Application settings
	UpdateResource(m_UpdateHandle, "APPBLOCK", MAKEINTRESOURCE(997), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
					appBlock.ptr(), appBlock.size());

	ProgressDlg.SetProgress(83);

	// Layouts
	UpdateResource(m_UpdateHandle, "LEVELBLOCK", MAKEINTRESOURCE(998), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
					LayoutBlock.ptr(), LayoutBlock.size());

	ProgressDlg.SetProgress(84);

	// Events
	UpdateResource(m_UpdateHandle, "EVENTBLOCK", MAKEINTRESOURCE(999), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
					eventBlock.ptr(), eventBlock.size());

	ProgressDlg.SetProgress(85);

	// Number of DLLs
	long c = dllList.GetCount();
	CString ibuf;
	long te = c;
	te += MvtLookup.size();
	ibuf.Format("%d", te);
	int ilen = 0;

	// Make string of DLL count in to resource string format
	wchar_t* resString = AllocStringResourceFormat(ibuf, 1, &ilen);

	// String of DLL count is a string at resource 1
	UpdateResource(m_UpdateHandle, RT_STRING, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
					resString, ilen);

	// AllocStringResourceFormat makes a new string
	delete [] resString;

	CString dll;
	POSITION pos4 = dllList.GetHeadPosition();

	int d = 0;
		
	for (d = 1000; d < (1000 + c); d++)
	{
		// In preview mode, we only put the string of the plugin name in the resources
		if (previewMode) {
			dll = dllList.GetNext(pos4);

			ilen = 0;

			// Make string of DLL count in to resource string format
			wchar_t* resString = AllocStringResourceFormat(dll, 1, &ilen);

			UpdateResource(m_UpdateHandle, RT_STRING, MAKEINTRESOURCE(d), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
								resString, ilen);

			delete [] resString;
		}
		// In export EXE mode, the actual DLL file must be dumped in resources
		else {

			CString dllPath;
			dllPath.Format("%sPlugins\\Runtime\\%s", path.GetFullPath(), dllList.GetNext(pos4));

			// Get the DLL file binary
			FILE* f = fopen(dllPath, "rb");
			fseek(f, 0, SEEK_END);
			int fsize = ftell(f);
			fseek(f, 0, SEEK_SET);

			BYTE* fdata = new BYTE[fsize];
			fread(fdata, 1, fsize, f);
			fclose(f);
	
			UpdateResource(m_UpdateHandle, "DLLBLOCK", MAKEINTRESOURCE(d), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
							 fdata, fsize);

			delete [] fdata;
		}

	}//for

	ProgressDlg.SetProgress(88);

	// Behavior DLLs are added afterwards
	int iter = 0;
	for (int Mvt = d; Mvt < (d + MvtLookup.size()); Mvt++)
	{
		if (previewMode) {
			dll = MvtLookup[iter].Name;
			ilen = 0;

			// Make string of DLL count in to resource string format
			wchar_t* resString = AllocStringResourceFormat(dll, 1, &ilen);

			UpdateResource(m_UpdateHandle, RT_STRING, MAKEINTRESOURCE(Mvt), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
								resString, ilen);

			delete [] resString;
			iter++;
		}
		// In EXE mode export actual DLL file
		else {

			CString dllPath;
			dllPath.Format("%sPlugins\\Runtime\\%s", path.GetFullPath(), MvtLookup[iter].Name);

			// Get the DLL file binary
			FILE* f = fopen(dllPath, "rb");
			fseek(f, 0, SEEK_END);
			int fsize = ftell(f);
			fseek(f, 0, SEEK_SET);

			BYTE* fdata = new BYTE[fsize];
			fread(fdata, 1, fsize, f);
			fclose(f);
	
			UpdateResource(m_UpdateHandle, "DLLBLOCK", MAKEINTRESOURCE(Mvt), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
							 fdata, fsize);

			delete [] fdata;

			iter++;

		}
	}//for

	ProgressDlg.SetProgress(90);

	ExportResources(previewMode);

	ProgressDlg.SetProgress(99);

	UpdateResource(m_UpdateHandle, "MENUBLOCK", MAKEINTRESOURCE(993), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
					menuBlock.ptr(), menuBlock.size());

	// Write DLL segment
	EndUpdateResource(m_UpdateHandle, FALSE);

	// Free the bin data
	imageBlock.free();
	eventBlock.free();
	appBlock.free();
	LayoutBlock.free();
	hlslBlock.free();
	menuBlock.free();

	if (m_bInstaller)
	{
		// Now create an installer if necessary
		CreateInstaller();

		// Delete the old file
		DeleteFile(m_Out);

		// Transfer installer to path
		CPath Transfer;
		Transfer.SetPath(m_Out);

		CopyFile(m_InstallerOut, m_Out, FALSE);
	}

	// Now we're done
	ProgressDlg.SetProgress(100);
}
Ejemplo n.º 8
0
void CExport::ExportToEXE(CApplication* pApplication)
{
	application = pApplication;

	// Prepare allocators
	LayoutBlock.allocator = &g_allocator;
	eventBlock.allocator = &g_allocator;
	appBlock.allocator = &g_allocator;
	imageBlock.allocator = &g_allocator;
	hlslBlock.allocator = &g_allocator;
	menuBlock.allocator = &g_allocator;

	// Open export wizard
	CExportWizardDlg Dlg;
	Dlg.application = pApplication;
	if (Dlg.DoModal() != IDOK) return;

	// Transfer settings
	m_bInstaller	= Dlg.m_bInstaller;
	m_License		= Dlg.m_License;
	m_InstallPath	= Dlg.m_InstallPath;
	m_OS			= Dlg.m_OS;
	m_bScreensaver	= Dlg.m_bScreensaver;

	// Make paths
	CPath Path;
	Path.SetToCurrentDirectory();
	CString OutPath;

	// Application
	if (application->runtime == CApplication::rt_application)
		OutPath.Format("%sData\\App", Path.GetFullPath());

	// Direct-X
	else if (application->runtime == CApplication::rt_directx)
		OutPath.Format("%sData\\DX9", Path.GetFullPath());

	// Append _s for scripting (python)
	if (application->game_information.use_python)
		OutPath += "_s";		// script enabled

	OutPath += ".exe";

	// Copy runtime.exe to the target file
	CopyFile(OutPath, Dlg.m_OutputPath, false);

	// File copied, assume 10% progress
	ProgressDlg.Start("Exporting");
	ProgressDlg.SetProgress(10);

	// Transfer path
	m_Out = Dlg.m_OutputPath;

	// Screensaver
	//if (m_bScreensaver)
	//	Dlg.m_OutputPath.Replace(".exe", ".scr");

	DoExport(false, Dlg.m_OutputPath, false);

	ProgressDlg.Finish();

	// Python reminder
	if (application->game_information.use_python) {
		MessageBox(NULL, "Your application has scripting enabled and requires Python26.dll to run.  This file has been "
			"copied to the same directory as your EXE - remember to include it when sending or distributing your game!",
			"Export EXE reminder", MB_ICONINFORMATION | MB_OK);
	}
}