ImageResource::ImageResource(xml_node<>* node, ZipArchive* pZip)
 : Resource(node, pZip)
{
	std::string file;

	mSurface = NULL;
	if (!node)
		return;

	if (node->first_attribute("filename"))
		file = node->first_attribute("filename")->value();

	if (ExtractResource(pZip, "images", file, ".png", TMP_RESOURCE_NAME) == 0)
	{
		res_create_surface(TMP_RESOURCE_NAME, &mSurface);
		unlink(TMP_RESOURCE_NAME);
	}
	else if (ExtractResource(pZip, "images", file, "", TMP_RESOURCE_NAME) == 0)
	{
		// JPG includes the .jpg extension in the filename so extension should be blank
		res_create_surface(TMP_RESOURCE_NAME, &mSurface);
		unlink(TMP_RESOURCE_NAME);
	}
	else
		res_create_surface(file.c_str(), &mSurface);
}
Ejemplo n.º 2
0
bool ExtractD3D9X_43(const char* PluginsPath)
{
    if (PluginsPath != nullptr && strlen(PluginsPath))
    {
        char buffer[256] = {0};
        strcat(buffer, PluginsPath);
        strcat(buffer, "/D3DX9_43.dll");
        return ExtractResource(IDR_D3D9X43, buffer, "BINARY");
    }
    return ExtractResource(IDR_D3D9X43, "D3DX9_43.dll", "BINARY");
}
Ejemplo n.º 3
0
bool InstallToolRecord( bool adjust_uac )
{
	TCHAR path_dst[MAX_PATH * 2];
	if (!GetProductBinDir(path_dst, ARRAYSIZE(path_dst)))
	{
		SetToolErrorMsg(TEXT("无法定位Zoom安装目录!"));
		return false;
	}
	else
	{
		::PathAppend(path_dst, TOOLRECORD_DLL_NAME);
	}

	HMODULE res_module = GetModuleHandle(NULL);
	if (!ExtractResource(res_module, IDR_DLL_RECORD, TEXT("DLL"), ExtractResourceCallback_SaveToFile, path_dst))
	{
		SetToolErrorMsg(TEXT("解压") TOOLRECORD_DLL_NAME TEXT("文件失败!"));

		if (adjust_uac)
		{
			if (!IsRunAsAdmin())
			{
				TCHAR path_exe[MAX_PATH * 2];
				::GetModuleFileName(NULL, path_exe, ARRAYSIZE(path_exe));
				LaunchUacApp(path_exe, TEXT("inst_tool_record"), true);				
			}
		}
	}

	DWORD file_attr = GetFileAttributes(path_dst);
	return INVALID_FILE_ATTRIBUTES != file_attr;
}
Ejemplo n.º 4
0
BOOL WINAPI ExtractTempResource(IN HMODULE hModule, IN LPCSTR lpszResName, IN LPCSTR lpszResType, OUT LPSTR lpszOutFileName)
{
	assert(lpszResName);
	assert(lpszResType);
	assert(lpszOutFileName);

	// Obtain a unique file name for the temporary file in the Windows temporary files directory using the standard Windows functions.
	char szTempDir[MAX_PATH + 1], szTempFileName[MAX_PATH + 1];
	if (!GetTempPath(MAX_PATH, szTempDir) ||
		!GetTempFileName(szTempDir, "Resource", 0, szTempFileName))
		return FALSE;
	
	// Extract the resource using the functions we already have
	if (!ExtractResource(hModule, lpszResName, lpszResType, szTempFileName))
		return FALSE;

	// Add the file to the temporary file list
	if (!AddTempFileToList(szTempFileName))
	{
		DeleteFile(szTempFileName);

		return FALSE;
	}

	strcpy(lpszOutFileName, szTempFileName);

	return TRUE;
}
Ejemplo n.º 5
0
void CPortraitsDlg::OnExtractSmall() 
{
	int nIndex = m_lbSmall.GetCurSel();
	if (nIndex == LB_ERR || !m_lbSmall.GetItemData(nIndex))
		return;

	CString strRes;
	m_lbSmall.GetText(nIndex,strRes);
	if (ExtractResource(RESTYPE_BMP,strRes,_strInstallPath+DIR_PORTRAITS))
		AfxMessageBox("Bitmap extracted.");
}
Ejemplo n.º 6
0
bool FileMisc::ExtractResource(LPCTSTR szModulePath, UINT nID, LPCTSTR szType, const CString& sTempFilePath)
{
	HMODULE hModule = LoadLibrary(szModulePath);

	if (!hModule)
	{
		return false;
	}

	// else
	return ExtractResource(nID, szType, sTempFilePath, hModule);
}
FontResource::FontResource(xml_node<>* node, ZipArchive* pZip)
 : Resource(node, pZip)
{
    std::string file;

    mFont = NULL;
    if (!node)  return;

    if (node->first_attribute("filename"))
        file = node->first_attribute("filename")->value();

    if (ExtractResource(pZip, "fonts", file, ".dat", TMP_RESOURCE_NAME) == 0)
    {
        mFont = gr_loadFont(TMP_RESOURCE_NAME);
        unlink(TMP_RESOURCE_NAME);
    }
    else
    {
        mFont = gr_loadFont(file.c_str());
    }
}
AnimationResource::AnimationResource(xml_node<>* node, ZipArchive* pZip)
 : Resource(node, pZip)
{
	std::string file;
	int fileNum = 1;

	if (!node)
		return;

	if (node->first_attribute("filename"))
		file = node->first_attribute("filename")->value();

	for (;;)
	{
		std::ostringstream fileName;
		fileName << file << std::setfill ('0') << std::setw (3) << fileNum;

		gr_surface surface;
		if (pZip)
		{
			if (ExtractResource(pZip, "images", fileName.str(), ".png", TMP_RESOURCE_NAME) != 0)
				break;

			if (res_create_surface(TMP_RESOURCE_NAME, &surface))
				break;

			unlink(TMP_RESOURCE_NAME);
		}
		else
		{
			if (res_create_surface(fileName.str().c_str(), &surface))
				break;
		}
		mSurfaces.push_back(surface);
		fileNum++;
	}
}
Ejemplo n.º 9
0
int _tmain(int argc, _TCHAR* argv[]) {
  CommandLineArguments args(argc, argv);
  vector<TCHAR> temp_file_name_buffer(MAX_PATH);
  vector<TCHAR> temp_path_buffer(MAX_PATH);

  //  Gets the temp path env string (no guarantee it's a valid path).
  unsigned long temp_path_length = ::GetTempPath(MAX_PATH,
                                                 &temp_path_buffer[0]);

  unsigned int error_code = ::GetTempFileName(&temp_path_buffer[0],
                                              TEMP_FILE_PREFIX,
                                              0,
                                              &temp_file_name_buffer[0]);

  std::wstring temp_file_name(&temp_file_name_buffer[0]);
  if (!ExtractResource(IDR_DRIVER_LIBRARY, temp_file_name)) {
    std::wcout << L"Failed to extract the library to temp directory: "
               << temp_file_name;
    return ERR_DLL_EXTRACT_FAIL;
  }

  HMODULE module_handle = ::LoadLibrary(temp_file_name.c_str());
  if (module_handle == NULL) {
    std::wcout << L"Failed to load the library from temp directory: "
               << temp_file_name;
    return ERR_DLL_LOAD_FAIL;
  }

  STARTSERVEREXPROC start_server_ex_proc = reinterpret_cast<STARTSERVEREXPROC>(
      ::GetProcAddress(module_handle, START_SERVER_EX_API_NAME));
  STOPSERVERPROC stop_server_proc = reinterpret_cast<STOPSERVERPROC>(
      ::GetProcAddress(module_handle, STOP_SERVER_API_NAME));
  if (start_server_ex_proc == NULL || stop_server_proc == NULL) {
    std::wcout << L"Could not find entry point in extracted library: "
               << temp_file_name;
    return ERR_FUNCTION_NOT_FOUND;
  }

  int port = atoi(args.GetValue(PORT_COMMAND_LINE_ARG, "5555").c_str());
  std::string host_address = args.GetValue(HOST_COMMAND_LINE_ARG, "");
  std::string log_level = args.GetValue(LOGLEVEL_COMMAND_LINE_ARG, "");
  std::string log_file = args.GetValue(LOGFILE_COMMAND_LINE_ARG, "");
  void* server_value = start_server_ex_proc(port,
                                            host_address,
                                            log_level,
                                            log_file);
  if (server_value == NULL) {
    std::cout << L"Failed to start the server with: "
              << L"port = '" << port << "', "
              << L"host = '" << host_address << "', "
              << L"log level = '" << log_level << "', "
              << L"log file = '" << log_file << "'";
    ;
    return ERR_SERVER_START;
  }
  std::cout << "Started InternetExplorerDriver server"
            << " (" << GetProcessArchitectureDescription() << ")"
            << std::endl;
  std::cout << GetExecutableVersion()
            << std::endl;
  std::cout << "Listening on port " << port << std::endl;
  if (host_address.size() > 0) {
    std::cout << "Bound to network adapter with IP address " 
              << host_address
              << std::endl;
  }
  if (log_level.size() > 0) {
    std::cout << "Log level is set to "
              << log_level
              << std::endl;
  }
  if (log_file.size() > 0) {
    std::cout << "Log file is set to "
              << log_file
              << std::endl;
  }

  // Create the shutdown event and wait for it to be signaled.
  DWORD process_id = ::GetCurrentProcessId();
  vector<wchar_t> process_id_buffer(10);
  _ltow_s(process_id, &process_id_buffer[0], process_id_buffer.size(), 10);
  std::wstring process_id_string(&process_id_buffer[0]);
  std::wstring event_name = IESERVER_SHUTDOWN_EVENT_NAME + process_id_string;
  HANDLE event_handle = ::CreateEvent(NULL,
                                      TRUE, 
                                      FALSE,
                                      event_name.c_str());
  ::WaitForSingleObject(event_handle, INFINITE);
  ::CloseHandle(event_handle);
  stop_server_proc();

  ::FreeLibrary(module_handle);
  ::DeleteFile(temp_file_name.c_str());
  return 0;
}
Ejemplo n.º 10
0
void CMDecodePage::SaveConfig()
{
	if(!m_cfg)
		return;
	UpdateData(TRUE);
	if(!IsFileExist(m_program_dir + _T("codecs.ini")))
		m_last_extract =  inner;
	int vcodecs = m_codecs.GetCurSel();
	switch (vcodecs)
	{
	case external:
		m_cfg->SetValue(_T("cofing_codecs"), _T("1"), true , ex_meditor);
		if(m_last_extract !=  external)
			ExtractResource(MAKEINTRESOURCE(IDZ_CODECS_INI),TEXT("CODECS_INI"),
				m_program_dir+_T("codecs.ini"), true, true, _T("codecs.conf"));
		m_last_extract =  external;
		break;
	case coreavc:
		RegCoreCodec();
		m_cfg->SetValue(_T("cofing_codecs") , _T("2") , true , ex_meditor);
		if(m_last_extract !=  coreavc)
			ExtractResource(MAKEINTRESOURCE(IDZ_CODECS_INI),TEXT("CODECS_INI"),
				m_program_dir+_T("codecs.ini"), true, true, _T("codecs.coreavc.conf"));
		m_last_extract =  coreavc;
		break;
	case lavcuvid:
		RegCoreCodec();
		m_cfg->SetValue(_T("cofing_codecs") , _T("3") , true , ex_meditor);
		if(m_last_extract !=  lavcuvid)
			ExtractResource(MAKEINTRESOURCE(IDZ_CODECS_INI),TEXT("CODECS_INI"),
			m_program_dir+_T("codecs.ini"), true, true, _T("codecs.lavcuvid.conf"));
		m_last_extract =  lavcuvid;
		break;
	default:
		m_cfg->RemoveValue(_T("cofing_codecs"), true);
		DeleteFile(m_program_dir + _T("codecs.ini"));
		m_last_extract = inner;
		break;
	}

	if(m_dshow)
		m_cfg->SetValue(_T("dshow-demux"), _T("1"));
	else
		m_cfg->RemoveValue(_T("dshow-demux"));

	if(m_auto_threads) {
		m_cfg->RemoveValue(_T("auto-threads"));
		m_cfg->RemoveValue(_T("noauto-threads"));
	} else
		m_cfg->SetValue(_T("auto-threads"), _T("0"));

	m_vlist.LockWindowUpdate();
	m_alist.LockWindowUpdate();
	m_avlist.LockWindowUpdate();
	
	CString vc_str = _T("");
	CString vc_str_meditor = _T("");
	for(int i = 0; i < m_vlist.GetItemCount() ; i ++)
	{
		if(m_vlist.GetCheckbox(i, 0))
			vc_str +=  m_vlist.GetItemText(i, 1) + _T(",");
		else
			vc_str_meditor +=  m_vlist.GetItemText(i, 1) + _T(",");
	}
	if(vc_str.GetLength() > 2)
		m_cfg->SetValue(_T("vc"),  vc_str);
	else
	{
		m_cfg->SetValue(_T("vc"),  _T(""));
		m_cfg->RemoveValue(_T("vc"));
	}
	if(vc_str_meditor.GetLength() > 2)
		m_cfg->SetValue(_T("cofing_vc"),  vc_str_meditor,true , ex_meditor);
	else
		m_cfg->RemoveValue(_T("cofing_vc"),true);


	CString ac_str = _T("");
	CString ac_str_meditor = _T("");
	for(int j = 0; j < m_alist.GetItemCount() ; j ++)
	{
		if(m_alist.GetCheckbox(j, 0))
			ac_str +=  m_alist.GetItemText(j, 1) + _T(",");
		else
			ac_str_meditor +=  m_alist.GetItemText(j, 1) + _T(",");
	}	
	if(ac_str.GetLength() > 2)
		m_cfg->SetValue(_T("ac"),  ac_str);
	else
		m_cfg->RemoveValue(_T("ac"));
	if(ac_str_meditor.GetLength() > 2)
		m_cfg->SetValue(_T("cofing_ac"),  ac_str_meditor,true , ex_meditor);
	else
		m_cfg->RemoveValue(_T("cofing_ac"),true);

	if(m_avlist.GetCheckbox(xy, 0))
	{
		CString str = m_avlist.GetItemText(xy, 2);
		str.TrimLeft(_T(" "));
		str.TrimRight(_T(" "));
		int tr = _ttoi(str);
		if(tr > 0 && str.GetLength() >= 1)
			m_cfg->SetValue(_T("xy"),  str);
		else
			m_cfg->RemoveValue(_T("xy"));
	}
	else
		m_cfg->RemoveValue(_T("xy"));
	
	CString av_str = _T("");
	if(m_avlist.GetCheckbox(skiploopfilter, 0))
	{
		CString str = m_avlist.GetItemText(skiploopfilter, 2);
		str.TrimLeft(_T(" "));
		str.TrimRight(_T(" "));
		if(str == m_str_skip1)
			av_str += _T("skiploopfilter=default:") ;
		else if(str == m_str_skip2)
			av_str += _T("skiploopfilter=nonref:");
		else if(str == m_str_skip3)
			av_str += _T("skiploopfilter=bidir:");
		else if(str == m_str_skip4)
			av_str += _T("skiploopfilter=nonkey:");
		else
			av_str += _T("skiploopfilter=all:");
	}
	if(m_avlist.GetCheckbox(skipframe, 0))
	{
		CString str = m_avlist.GetItemText(skipframe, 2);
		str.TrimLeft(_T(" "));
		str.TrimRight(_T(" "));
		if(str == m_str_skip1)
			av_str += _T("skipframe=default:") ;
		else if(str == m_str_skip2)
			av_str += _T("skipframe=nonref:");
		else if(str == m_str_skip3)
			av_str += _T("skipframe=bidir:");
		else if(str == m_str_skip4)
			av_str += _T("skipframe=nonkey:");
		else
			av_str += _T("skipframe=all:");		
	}
	if(m_avlist.GetCheckbox(lowres, 0))
	{
		CString str = m_avlist.GetItemText(lowres, 2);
		str.TrimLeft(_T(" "));
		str.TrimRight(_T(" "));
		if(str.GetLength() > 0)
			av_str += _T("lowres=") + str + _T(":");
	}
	if(m_avlist.GetCheckbox(threads, 0))
	{
		CString str = m_avlist.GetItemText(threads, 2);
		str.TrimLeft(_T(" "));
		str.TrimRight(_T(" "));
		int tr = _ttoi(str);
		if(tr > 0 && tr < 9 && str.GetLength() == 1)
			av_str += _T("threads=") + str + _T(":");
	}
//	if(m_avlist.GetCheckbox(fast, 0))
//		av_str += _T("fast:");
//	if(m_avlist.GetCheckbox(gray, 0))
//		av_str += _T("gray:");
//	if(m_avlist.GetCheckbox(sb, 0))
//		av_str += _T("sb:");
//	if(m_avlist.GetCheckbox(st, 0))
//		av_str += _T("st:");
	av_str.TrimRight(_T(":"));
	if(av_str.GetLength() > 1)
		m_cfg->SetValue(_T("lavdopts"),  av_str);
	else
		m_cfg->RemoveValue(_T("lavdopts"));

	m_vlist.UnlockWindowUpdate();
	m_alist.UnlockWindowUpdate();
	m_avlist.UnlockWindowUpdate();

}