コード例 #1
0
HRESULT XZPManager::XZPOpenMemory( string xzpPath, string filePath, BYTE ** pFileData, UINT * pFileSize )
{
	HRESULT hr = NULL;
	HXUIPACKAGE hPackage;

	if(!FileExistsA(xzpPath))
	{
		DebugMsg("XZPManager", "Provided XZP File Path Does Not Exist");
		return S_FALSE;
	}

	
	// Convert absolute path to xui path
	string xuiPath = "file://" + xzpPath;
	
	hr = XuiResourceOpenPackage(strtowchar(xuiPath), &hPackage, false);
	if(hr != S_OK)
	{
		DebugMsg("XZPManager", "Failed To Open XZP Package");
		return S_FALSE;
	}

	WCHAR * szLocator = strtowchar(xuiPath + "#" + filePath);
	
	BYTE * pSectionData;
	UINT pSectionSize;

	hr = XuiResourceLoadAllNoLoc(szLocator, &pSectionData, &pSectionSize);
	if( hr != S_OK )
	{
		DebugMsg("XZPManager", "Failed To Load Resource File.");
		return S_FALSE;
	}

	*pFileData = (BYTE *)malloc(pSectionSize);
	memcpy(*pFileData, pSectionData, pSectionSize);
	*pFileSize = pSectionSize;
	XuiFree((void*)pSectionData);

	XuiResourceReleasePackage(hPackage);
	

	return S_OK;
}
コード例 #2
0
HRESULT XZPManager::XZPOpenBinary(string opath, string filename, string xmlname)
{
	m_basePath = SETTINGS::getInstance().getDataPath();
	string loadfilename = "file://" + opath + filename;
	loadfilename = str_replaceall(loadfilename, "\\", "/");
	Path = strtowchar(loadfilename);
	DebugMsg("XZPManager", "PATH: %s, loading package", wstrtostr(Path).c_str());
	HRESULT hr = XuiResourceOpenPackage(Path,&phPackage,false);
	if (hr != S_OK)
	{
		DebugMsg("XZPManager", "Error HRESULT: %08x", hr);
		return hr;
	} else {
		szLocator = strtowchar(loadfilename + "#" + xmlname);

		byte * buf;
		UINT size;
		hr = XuiResourceLoadAllNoLoc(szLocator, &buf, &size);
		if (hr != S_OK)
		{
			DebugMsg("XZPManager", "HRESULT : %08x, Loading resource");
			XuiResourceReleasePackage(phPackage);
			return hr;
		} else {
			DebugMsg("XZPManager", "Resource is in memory Size is %d", size);
			string outpath = sprintfaA("%sSkins\\%s\\%s", m_basePath.c_str(), filename.c_str(), xmlname.c_str());
			DebugMsg("XZPManager", "Saving file to %s", outpath.c_str());

			// Write Item To File
			FILE * fHandle;
			fopen_s(&fHandle, outpath.c_str(), "wb");
			fwrite(buf, size, 1, fHandle);
			fclose(fHandle);

			XuiFree((void*)buf);
		}
	}

	XuiResourceReleasePackage(phPackage);
	return S_OK;
}
コード例 #3
0
void DVDWorker::ExtractCurrent360Item() {


	// Try and get slot stuff first if we can
	string nxeArtPath = "dvd:\\nxeart";
	m_CurrentItem->setTitle(L"Xbox 360 DVD");
	if(FileExists(nxeArtPath)) {
		
		// Read our Container info
		Xbox360Container container;
		if(container.OpenContainer(nxeArtPath) != S_OK) {
			goto LoadFromXEX;
		}

		// Make sure its the correct content type
		if(container.pContainerMetaData->ContentType != 
			XCONTENTTYPE_THEMATICSKIN) {

			container.CloseContainer();
			goto LoadFromXEX;
		}

		// Check if theres a title name we can load
		if(wcslen(container.pContainerMetaData->TitleName) > 0) {
			wstring Title = container.pContainerMetaData->TitleName;
			wstring fullTitle = sprintfaW(L"Play %s", container.pContainerMetaData->TitleName);
			m_CurrentItem->setFullTitle(fullTitle);
			m_CurrentItem->setTitle(Title);
		}

		// Check if theres a thumbnail we can load
		if(container.pContainerMetaData->ThumbnailSize > 0) {
			BYTE* thumbnailData = NULL; long thumbnailSize = 0;
			#ifdef _USING_DXT5
				ConvertImageInMemoryToDXT5Buffer(
					container.pContainerMetaData->Thumbnail, 
					container.pContainerMetaData->ThumbnailSize, 
					&thumbnailData, &thumbnailSize);
			#else if
				ConvertImageInMemoryToDXT1Buffer(
					container.pContainerMetaData->Thumbnail, 
					container.pContainerMetaData->ThumbnailSize, 
					&thumbnailData, &thumbnailSize);
			#endif
			iconData dataIcon;
			dataIcon.thumbnailData = thumbnailData;
			dataIcon.thumbnailSize = thumbnailSize;
			m_CurrentItem->SetThumbData(dataIcon);
			m_CurrentItem->setHaveThumb(true);
		}

		// Close our container
		container.CloseContainer();

		// Try and mount it to get our bg image and slot image
		if(container.Mount("NXEART") != S_OK) {
			if(m_CurrentItem->requester != NULL)
				m_CurrentItem->requester->ExtractCompleted(m_CurrentItem);
			return;
		}

		string nxeslotPath = "NXEART:\\nxeslot.jpg";
		if(FileExists(nxeslotPath)){
			BYTE* thumbnailData = NULL; long thumbnailSize = 0;
			#ifdef _USING_DXT5
				ConvertImageFileToDXT5Buffer(nxeslotPath, &thumbnailData, &thumbnailSize);
			#else if
				ConvertImageFileToDXT1(nxeslotPath, &thumbnailData, &thumbnailSize);
			#endif
			iconData dataIcon;
			dataIcon.thumbnailData = thumbnailData;
			dataIcon.thumbnailSize = thumbnailSize;
			m_CurrentItem->setSlotData(dataIcon);
			m_CurrentItem->setHaveSlot(true);
		}

		// Unmount now
		container.UnMount();
		
		// Trigger the download complete function
		if(m_CurrentItem->requester != NULL)
			m_CurrentItem->requester->ExtractCompleted(m_CurrentItem);
		// All done
		return;
	}

LoadFromXEX:

	// Open our xex
	XeXtractor xex;
	if(xex.OpenXex("dvd:\\default.xex") != S_OK) {
		if(m_CurrentItem->requester != NULL)
			m_CurrentItem->requester->ExtractCompleted(m_CurrentItem);
		return;
	}

	// Extract our spa
	BYTE* spaData = NULL; DWORD spaDataLength = 0;
	if(xex.ExtractTitleSPA(&spaData, &spaDataLength) != S_OK) {
		xex.CloseXex();
		if(m_CurrentItem->requester != NULL)
			m_CurrentItem->requester->ExtractCompleted(m_CurrentItem);
		return;
	}

	// We have our spa so lets close
	xex.CloseXex();

	// Read our spa
	SPA spa;
	if(spa.OpenSPA(spaData, spaDataLength) != S_OK) {
		spa.CloseSPA();
		free(spaData);
		if(m_CurrentItem->requester != NULL)
			m_CurrentItem->requester->ExtractCompleted(m_CurrentItem);
		return;
	}

	// Get our title name
	string titleNameSpa = "";
	if(spa.GetTitleName(&titleNameSpa, LOCALE_ENGLISH) != S_OK) {
		spa.CloseSPA();
		free(spaData);
		if(m_CurrentItem->requester != NULL)
			m_CurrentItem->requester->ExtractCompleted(m_CurrentItem);
		return;
	}

	// We have our title
	WCHAR* multiByte = strtowchar(titleNameSpa);
	wstring fullTitle = sprintfaW(L"Play %s", multiByte);
	m_CurrentItem->setTitle(multiByte);
	m_CurrentItem->setFullTitle(fullTitle);
	delete multiByte;

	// Load our image
	BYTE* spaImage = NULL;	DWORD spaImageSize = 0;
	if(spa.GetTitleImage(&spaImage, &spaImageSize) != S_OK) {
		spa.CloseSPA();
		free(spaData);
		if(m_CurrentItem->requester != NULL)
			m_CurrentItem->requester->ExtractCompleted(m_CurrentItem);
		return;
	}

	// Convert ot dxt5
	if(spaImageSize > 0 && spaImage != NULL) {
		BYTE* thumbnailData = NULL; long thumbnailSize = 0;
		ConvertImageInMemoryToDXT5Buffer(spaImage, spaImageSize, 
			&thumbnailData, &thumbnailSize);

		iconData dataIcon;
		dataIcon.thumbnailData = thumbnailData;
		dataIcon.thumbnailSize = thumbnailSize;
		m_CurrentItem->SetThumbData(dataIcon);
		m_CurrentItem->setHaveThumb(true);
		
		// Can clean up the image now
		free(spaImage);
	}

	// Clean up our mess
	spa.CloseSPA();
	free(spaData);

	// Trigger the download complete function
	if(m_CurrentItem->requester != NULL)
		m_CurrentItem->requester->ExtractCompleted(m_CurrentItem);
}
コード例 #4
0
ファイル: mimerun.c プロジェクト: LRN/mimerun
/* Casts libmagic on the file <lpfile> to determine its type and
 * tries to find and run a handler for that type of files.
 */
int runmime (wchar_t *logfile, LPSHELLEXECUTEINFOW einfo, wchar_t *lpfile, wchar_t *lpdirectory)
{
  magic_t magicmimetype = NULL, magicmimeencoding = NULL, magicapple = NULL, magicname = NULL;
  char *mimetype, *mimeencoding, *apple, *name;
  char *argv1 = NULL;
  MimeResults mres;
  int ret = 0;

  logtofilew (logfile, L">runmime\n");

  magicname = load (NULL, MAGIC_NONE);
  magicmimetype = load (NULL, MAGIC_MIME_TYPE);
  magicmimeencoding = load (NULL, MAGIC_MIME_ENCODING);
  magicapple = load (NULL, MAGIC_APPLE);

  logtofilew (logfile, L"magics: %08x, %08x, %08x, %08x\n", magicname, magicmimetype, magicmimeencoding, magicapple);
  wchartostr (lpfile, &argv1, CP_THREAD_ACP);
  logtofilew (logfile, L"file to check is %S\n", argv1);
  
  memset (&mres, 0, sizeof (mres));

  mres.type = (char *) magic_file (magicmimetype, argv1);
  mres.enc = (char *) magic_file (magicmimeencoding, argv1);
  mres.apple = (char *) magic_file (magicapple, argv1);
  mres.name = (char *) magic_file (magicname, argv1);

  logtofilew (logfile, L"magic results: {%S} {%S} {%S} {%S}\n", mres.name, mres.type, mres.enc, mres.apple);
  if (mres.name != NULL)
    mres.name = strdup (mres.name);
  if (mres.type != NULL)
    mres.type = strdup (mres.type);
  if (mres.enc != NULL)
    mres.enc = strdup (mres.enc);
  if (mres.apple != NULL)
    mres.apple = strdup (mres.apple);

  strtowchar (mres.name, &mres.wname, CP_THREAD_ACP);
  strtowchar (mres.type, &mres.wtype, CP_THREAD_ACP);
  strtowchar (mres.enc, &mres.wenc, CP_THREAD_ACP);
  strtowchar (mres.apple, &mres.wapple, CP_THREAD_ACP);

  magic_close (magicmimetype);
  magic_close (magicmimeencoding);
  magic_close (magicapple);
  magic_close (magicname);

  if (argv1 != NULL)
    free (argv1);

  if (mres.type == NULL && mres.apple == NULL && mres.name == NULL)
  {
    logtofilew (logfile, L"Zero results, returning.\n");
    ret = -1;
  }
  else
  {
    ret = handle (logfile, &mres, einfo, lpfile, lpdirectory);
  }

  if (mres.name != NULL)
    free (mres.name);
  if (mres.type != NULL)
    free (mres.type);
  if (mres.enc != NULL)
    free (mres.enc);
  if (mres.apple != NULL)
    free (mres.apple);

  if (mres.wname != NULL)
    free (mres.wname);
  if (mres.wtype != NULL)
    free (mres.wtype);
  if (mres.wenc != NULL)
    free (mres.wenc);
  if (mres.wapple != NULL)
    free (mres.wapple);
  
  logtofilew (logfile, L"<runmime %d\n", ret);
  return ret;
}