Ejemplo n.º 1
0
bool CPreviewPlugin::Execute(LPCTSTR szCommand)
{
	TCHAR szFile[ MAX_PATH ] = {};
	lstrcpyn( szFile, szCommand, _countof( szFile ) );
	PathRemoveArgs( szFile );
	TCHAR szParameters[ MAX_PATH * 2 ] = {};
	lstrcpyn( szParameters, szCommand + lstrlen( szFile ), _countof( szParameters ) );
	StrTrim( szParameters, _T(" \t") );
	PathUnquoteSpaces( szFile );

	// Launch new process
	SHELLEXECUTEINFO sei =
	{
		sizeof( SHELLEXECUTEINFO ),
		SEE_MASK_NOCLOSEPROCESS,
		GetDesktopWindow(),
		NULL,
		szFile,
		szParameters,
		NULL,
		SW_SHOWNORMAL
	};
	if ( ! ShellExecuteEx( &sei ) )
		return false;

	// Wait for process exit
	m_hProcess.Attach( sei.hProcess );
	WaitForSingleObject( sei.hProcess, INFINITE );
	m_hProcess.Close();

	return true;
}
Ejemplo n.º 2
0
void BrowsePushed(LPRUNDLG_DATA lprd)
{
    HWND hDlg = lprd->hDlg;
    TCHAR szText[MAX_PATH];

    // Get out of the "synchronized input queues" state
    if (lprd->dwThreadId)
    {
        AttachThreadInput(GetCurrentThreadId(), lprd->dwThreadId, FALSE);
        lprd->dwThreadId = 0;
    }

    GetDlgItemText(hDlg, IDD_COMMAND, szText, ARRAYSIZE(szText));
    PathUnquoteSpaces(szText);

    if (GetFileNameFromBrowse(hDlg, szText, ARRAYSIZE(szText), lprd->lpszWorkingDir,
            MAKEINTRESOURCE(IDS_EXE), MAKEINTRESOURCE(IDS_PROGRAMSFILTER),
            MAKEINTRESOURCE(IDS_BROWSE)))
    {
        PathQuoteSpaces(szText);
        SetDlgItemText(hDlg, IDD_COMMAND, szText);
        EnableOKButton(hDlg, szText);
        // place the focus on OK
        // SetFocus(GetDlgItem(hDlg, IDOK));
        SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, IDOK), TRUE);
    }
}
Ejemplo n.º 3
0
void CPathFinder::SetPath(LPCTSTR szPath, BOOL bIsFolderPath, BOOL bHasArguments)
{
	TCHAR szParamPath[_MAX_PATH];
	TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR];
	TCHAR szName[_MAX_FNAME], szExt[_MAX_EXT];

	// Reset
	_sOriginalPath.Empty();
	_sDriveLabel.Empty();
	_bIsRelative = FALSE;
	_aDir.RemoveAll();
	_sExtName.Empty();
	_aArgs.RemoveAll();

	// Original path
	_sOriginalPath = szPath;

	// Get args and remove them from path
	szParamPath[0] = 0x0;
	_tcscpy(szParamPath, szPath);

	if (bHasArguments)
	{
		_sArgs = PathGetArgs(szParamPath);
		PathRemoveArgs(szParamPath);
	}

	PathUnquoteSpaces(szParamPath);
	if (szParamPath[0] == 0x0) return;

    _tsplitpath(szParamPath, szDrive, szDir, szName, szExt);

	// Drive
	_sDrive = szDrive;

	// Directory
	_sDir = szDir;
	_sDir.Replace('/', '\\');
	if (!_sDir.IsEmpty()) _bIsRelative = (_sDir[0] != '\\');
	
	// FileTitle
	if (bIsFolderPath)
	{
		_sDir = CPathFinder::AddBackSlash(_sDir);
		_sDir += szName;
		_sDir = CPathFinder::AddBackSlash(_sDir);
	}
	else
	{
		_sFileTitle = szName;
	}

	// Get extension name (e.g.: "txt")
	if (IsFilePath())
	{
		_sExtName = szExt;
		_sExtName.Remove('.');
	}
}
Ejemplo n.º 4
0
//************************************
// Method:    GetAutoStartupApplicationPaths
// FullName:  CAutoStartupInfo::GetAutoStartupApplicationPaths
// Access:    private
// Returns:   bool
// Qualifier:
// Parameter: HKEY hKey_i
// Parameter: StringVector & KeyValues_io
//************************************
bool CAutoStartupInfo::GetAutoStartupApplicationPaths( const HKEY hKey_i )
{
    // Key name and key value buffers
    TCHAR szKeyNameBuff[MAX_PATH] = { 0 };
    DWORD dwKeyNameLength = MAX_PATH;

    for( DWORD dwIndex = 0;
            RegEnumValue( hKey_i, dwIndex, szKeyNameBuff, &dwKeyNameLength, 0, 0, 0, 0 ) == ERROR_SUCCESS;
            ++dwIndex )
    {
        CString csKeyValue;
        if( GetRegKeyStringValue( hKey_i, szKeyNameBuff, csKeyValue ))
        {
            if( IsEnvironmentVarPath( csKeyValue ))
            {
                // Get expanded path
                TCHAR szExpandedPath[MAX_PATH] = { 0 };
                ExpandEnvironmentStrings( csKeyValue, szExpandedPath, MAX_PATH );

                // Copy back to original buffer
                csKeyValue = szExpandedPath;
            }

            LPTSTR lptszKeyValueBuff = csKeyValue.GetBufferSetLength( csKeyValue.GetLength() + MAX_PATH );

            // If path is unquoted then quote, because PathRemoveArgs requires paths with spaces to
            // be quoted
            if( !_tcschr( lptszKeyValueBuff, _T( '\"' )))
            {
                PathQuoteSpaces( lptszKeyValueBuff );
            }

            // Remove command line arguments from path
            PathRemoveArgs( lptszKeyValueBuff );

            // Check whether file exists or not, searches for file in the standard paths
            // that are set
            BOOL bFound = PathFileExists( lptszKeyValueBuff );

            // Removes any quotes from path
            PathUnquoteSpaces( lptszKeyValueBuff );

            // If file is a shortcut then resolve to real path
            if( bFound &&
                    Utils::IsShortcut( lptszKeyValueBuff ))
            {
                bFound = Utils::ResolveShortcut( lptszKeyValueBuff );
            }

            csKeyValue.ReleaseBuffer();
            AddAutoStartExePath( csKeyValue );
        }// End if

        dwKeyNameLength = MAX_PATH;
    }// End for

    return true;
}// End GetAutoStartupApplicationPaths
Ejemplo n.º 5
0
void CFilePath_i::SetPath(LPCTSTR szPath, BOOL bIsFolderPath)
{
	TCHAR szParamPath[MAX_PATH];
	TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR];
	TCHAR szName[_MAX_FNAME], szExt[_MAX_EXT];

	// Reset
	m_sOriginalPath.Empty();
	m_sDriveLabel.Empty();
	bool m_bIsRelative = FALSE;
	m_aDir.RemoveAll();
	m_sExtName.Empty();

	// Original path
	m_sOriginalPath = szPath;

	// Get args and remove them from path
	szParamPath[0] = 0x0;
	lstrcpy(szParamPath, szPath);

	PathUnquoteSpaces(szParamPath);
	if (szParamPath[0] == 0x0) return;

	_tsplitpath(szParamPath, szDrive, szDir, szName, szExt);

	// Drive
	m_sDrive = szDrive;

	// Directory
	m_sDir = szDir;
	m_sDir.Replace(_T('/'), _T('\\'));
	if (!_sDir.IsEmpty()) _bIsRelative = (_sDir[0] != _T('\\'));
	
	// FileTitle
	if (bIsFolderPath)
	{
		_sDir = AddBackSlash(_sDir);
		_sDir += szName;
		_sDir = AddBackSlash(_sDir);
	}
	else
	{
		_sFileTitle = szName;
	}

	// Get extension name (e.g.: "txt")
  if (!_sFileTitle.IsEmpty())
	{
		_sExtName = szExt;
		_sExtName.Remove(_T('.'));
	}
}
Ejemplo n.º 6
0
int get_string(HKEY key, TCHAR *value, TCHAR *data, unsigned long datalen, bool expand, bool sanitise, bool must_exist) {
  TCHAR *buffer = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, datalen);
  if (! buffer) {
    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, value, _T("get_string()"), 0);
    return 1;
  }

  ZeroMemory(data, datalen);

  unsigned long type = REG_EXPAND_SZ;
  unsigned long buflen = datalen;

  unsigned long ret = RegQueryValueEx(key, value, 0, &type, (unsigned char *) buffer, &buflen);
  if (ret != ERROR_SUCCESS) {
    HeapFree(GetProcessHeap(), 0, buffer);

    if (ret == ERROR_FILE_NOT_FOUND) {
      if (! must_exist) return 0;
    }

    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(ret), 0);
    return 2;
  }

  /* Paths aren't allowed to contain quotes. */
  if (sanitise) PathUnquoteSpaces(buffer);

  /* Do we want to expand the string? */
  if (! expand) {
    if (type == REG_EXPAND_SZ) type = REG_SZ;
  }

  /* Technically we shouldn't expand environment strings from REG_SZ values */
  if (type != REG_EXPAND_SZ) {
    memmove(data, buffer, buflen);
    HeapFree(GetProcessHeap(), 0, buffer);
    return 0;
  }

  ret = ExpandEnvironmentStrings((TCHAR *) buffer, data, datalen);
  if (! ret || ret > datalen) {
    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_EXPANDENVIRONMENTSTRINGS_FAILED, buffer, error_string(GetLastError()), 0);
    HeapFree(GetProcessHeap(), 0, buffer);
    return 3;
  }

  HeapFree(GetProcessHeap(), 0, buffer);
  return 0;
}
Ejemplo n.º 7
0
int APIENTRY wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nShowCmd )
{
	(void)hInstance;
	(void)hPrevInstance;
	(void)nShowCmd;

	int cmd_num;
	LPWSTR * cmd_args = CommandLineToArgvW( lpCmdLine, &cmd_num );

	std::wstring in;
	std::wstring out;

	for( int i = 0; i < cmd_num; i += 2 )
	{
		LPWSTR arg = cmd_args[i + 0];
		LPWSTR value = cmd_args[i + 1];

		if( wcscmp( arg, L"-in" ) == 0 )
		{
			in = value;
		}
		else if( wcscmp( arg, L"-out" ) == 0 )
		{
			out = value;
		}
	}

	if( in.empty() == true )
	{
		message_error("not found 'in' param\n"
			);

		return 1;
	}

	if( out.empty() == true )
	{
		message_error("not found 'out' param\n"
			);

		return 1;
	}

	WCHAR inCanonicalizeQuote[MAX_PATH];
	ForcePathQuoteSpaces( inCanonicalizeQuote, in.c_str() );
	PathUnquoteSpaces( inCanonicalizeQuote );
	
	FILE * file_in = _wfopen( inCanonicalizeQuote, L"rb" );

	uint32_t magic;
	fread( &magic, sizeof(magic), 1, file_in );

	if( magic != FOURCC('D', 'D', 'S', ' ') )
	{
		message_error("ExtractDXT1 %ls invalid dds magic" 
			, in.c_str()
			);

		return 1;
	}

	DDS_HEADER header;
	fread( &header, sizeof(header), 1, file_in );

	//Check valid structure sizes
	if( header.dwSize != 124 && header.ddspf.dwSize != 32)
	{
		message_error("ExtractDXT1 %ls invalid dds file header" 
			, in.c_str()
			);

		return 1;
	}

	if( (header.dwFlags & DDSD_MIPMAPCOUNT) == DDSD_MIPMAPCOUNT )
	{
		message_error("ExtractDXT1 %ls dds has mipmap" 
			, in.c_str()
			);

		return 1;
	}

	if( (header.ddspf.dwFlags & DDPF_FOURCC) == 0 )
	{
		message_error("ExtractDXT1 dds file no compress" 
			);

		return false;
	}

	if( header.ddspf.dwFourCC != FOURCC('D','X','T','1') )
	{
		message_error("ExtractDXT1 dds file no DXT1" 
			);

		return false;
	}

	uint32_t w = (header.dwWidth + 3) / 4;
	uint32_t h = (header.dwHeight + 3) / 4;

	size_t size = w * h * 1 * 8;
		
	uint8_t * dxt1_byte = new uint8_t [size];
	fread( dxt1_byte, 1, size, file_in );
	fclose( file_in );

	WCHAR outCanonicalizeQuote[MAX_PATH];
	ForcePathQuoteSpaces( outCanonicalizeQuote, out.c_str() );
	PathUnquoteSpaces( outCanonicalizeQuote );

	FILE * file_out = _wfopen( outCanonicalizeQuote, L"wb" );

	fwrite( dxt1_byte, 1, size, file_out );
	fclose( file_out );	
			
	return 0;
}
Ejemplo n.º 8
0
int APIENTRY wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nShowCmd )
{
	(void)hInstance;
	(void)hPrevInstance;
	(void)nShowCmd;

	std::wstring texturepacker_path = parse_kwds( lpCmdLine, L"--texturepacker", std::wstring() );
	std::wstring image_path = parse_kwds( lpCmdLine, L"--image", std::wstring() );
	uint32_t offset_x = parse_kwds( lpCmdLine, L"--offset_x", 0U );
	uint32_t offset_y = parse_kwds( lpCmdLine, L"--offset_y", 0U );
	float width = parse_kwds( lpCmdLine, L"--width", -1.f );
	float height = parse_kwds( lpCmdLine, L"--height", -1.f );
	uint32_t tolerance = parse_kwds( lpCmdLine, L"--tolerance", 200U );

	if( texturepacker_path.empty() == true )
	{
		message_error( "not found 'texturepacker' param\n"
			);

		return 0;
	}

	if( image_path.empty() == true )
	{
		message_error( "not found 'image' param\n"
			);

		return 0;
	}

	std::wstring system_cmd;

	system_cmd += L" --shape-padding 0 ";
	system_cmd += L" --border-padding 0 ";
	system_cmd += L" --padding 0 ";
	system_cmd += L" --disable-rotation ";	
	system_cmd += L" --extrude 0 ";
	system_cmd += L" --trim-mode Polygon ";
	system_cmd += L" --trim-threshold 0 ";	
	system_cmd += L" --tracer-tolerance ";
	system_cmd += L" --max-width 8192 ";
	system_cmd += L" --max-height 8192 ";
	system_cmd += L" --max-size 8192 ";

	std::wstringstream ss;
	ss << tolerance;
	system_cmd += ss.str();
	system_cmd += L" ";

	WCHAR ImagePathCanonicalizeQuote[MAX_PATH];
	ForcePathQuoteSpaces( ImagePathCanonicalizeQuote, image_path );
	
	system_cmd += ImagePathCanonicalizeQuote;

	WCHAR tempPath[MAX_PATH];
	GetTempPath( MAX_PATH, tempPath );

	WCHAR outCanonicalize[MAX_PATH];
	PathCombine( outCanonicalize, tempPath, L"aemovie_temp_texturepacker_sheet.xml" );
	//PathCanonicalize( outCanonicalize, L"%TEMP%/temp_texturepacker_sheet.xml" );
	//PathUnquoteSpaces( outCanonicalize );

	system_cmd += L" --data ";
	system_cmd += outCanonicalize;
	system_cmd += L" --format xml ";
	system_cmd += L" --quiet ";

	STARTUPINFO lpStartupInfo;
	ZeroMemory( &lpStartupInfo, sizeof( STARTUPINFOW ) );
	lpStartupInfo.cb = sizeof( lpStartupInfo );
	lpStartupInfo.wShowWindow = SW_HIDE;

	PROCESS_INFORMATION lpProcessInformation;
	ZeroMemory( &lpProcessInformation, sizeof( PROCESS_INFORMATION ) );

	WCHAR lpCommandLine[32768];
	wcscpy_s( lpCommandLine, system_cmd.c_str() );

	WCHAR TexturePathCanonicalizeQuote[MAX_PATH];
	ForcePathQuoteSpaces( TexturePathCanonicalizeQuote, texturepacker_path );
	PathUnquoteSpaces( TexturePathCanonicalizeQuote );
	
	if( CreateProcess( TexturePathCanonicalizeQuote
		, lpCommandLine
		, NULL
		, NULL
		, FALSE
		, CREATE_NO_WINDOW
		, NULL
		, NULL
		, &lpStartupInfo
		, &lpProcessInformation ) == FALSE )
	{
		message_error( "invalid CreateProcess %ls %ls\n"
			, TexturePathCanonicalizeQuote
			, lpCommandLine
			);

		return 0;
	}

	CloseHandle( lpProcessInformation.hThread );

	WaitForSingleObject( lpProcessInformation.hProcess, INFINITE );

	DWORD exit_code;//Код завершения процесса
	GetExitCodeProcess( lpProcessInformation.hProcess, &exit_code );

	CloseHandle( lpProcessInformation.hProcess );

	if( exit_code != 0 )
	{
		message_error( "invalid Process %ls exit_code %d\n"
			, TexturePathCanonicalizeQuote
			, exit_code
			);

		return 0;
	}

	FILE * f = _wfopen( outCanonicalize, L"rb" );

	if( f == NULL )
	{
		message_error( "invalid _wfopen %ls\n"
			, outCanonicalize
			);

		return 0;
	}

	fseek( f, 0, SEEK_END );
	int f_size = ftell( f );
	rewind( f );

	std::vector<char> v_buffer( f_size );
	char * mf_buffer = &v_buffer[0];

	fread( mf_buffer, 1, f_size, f );
	fclose( f );

	pugi::xml_document doc;

	pugi::xml_parse_result result = doc.load_buffer( mf_buffer, f_size );

	pugi::xml_node xml_sprite = doc.first_element_by_path( "TextureAtlas/sprite" );
	pugi::xml_attribute xml_sprite_x = xml_sprite.attribute( "x" );
	pugi::xml_attribute xml_sprite_y = xml_sprite.attribute( "y" );
	pugi::xml_attribute xml_sprite_w = xml_sprite.attribute( "w" );
	pugi::xml_attribute xml_sprite_h = xml_sprite.attribute( "h" );
	pugi::xml_attribute xml_sprite_oX = xml_sprite.attribute( "oX" );
	pugi::xml_attribute xml_sprite_oY = xml_sprite.attribute( "oY" );
	pugi::xml_attribute xml_sprite_oW = xml_sprite.attribute( "oW" );
	pugi::xml_attribute xml_sprite_oH = xml_sprite.attribute( "oH" );

	uint32_t x = xml_sprite_x.as_uint();
	uint32_t y = xml_sprite_y.as_uint();
	uint32_t w = xml_sprite_w.as_uint();
	uint32_t h = xml_sprite_h.as_uint();
	uint32_t oX = xml_sprite_oX.as_uint();
	uint32_t oY = xml_sprite_oY.as_uint();
	uint32_t oW = xml_sprite_oW.as_uint();
	uint32_t oH = xml_sprite_oH.as_uint();

	pugi::xml_node xml_vertices = doc.first_element_by_path( "TextureAtlas/sprite/vertices" );

	const char * vertices = xml_vertices.child_value();

	std::stringstream ss_vertices( vertices );

	//Sleep( 10000 );

	std::vector<float> positions;

	for( ;; )
	{
		int32_t pos_x;
		int32_t pos_y;
		if( ss_vertices >> pos_x && ss_vertices >> pos_y )
		{
			pos_x -= x;
			pos_y -= y;

			pos_x += offset_x;
			pos_y += offset_y;

			float xf = (float)pos_x;
			float yf = (float)pos_y;

			positions.push_back( xf );
			positions.push_back( yf );
		}
		else
		{
			break;
		}
	}
Ejemplo n.º 9
0
//
// Do checking of the .exe type in the background so the UI doesn't
// get hung up while we scan.  This is particularly important with
// the .exe is over the network or on a floppy.
//
void CheckRunInSeparateThread( LPVOID lpVoid )
{
    LONG lBinaryType;
    DWORD cch;
    LPTSTR lpszFilePart;
    TCHAR szFile[MAX_PATH+1];
    TCHAR szFullFile[MAX_PATH+1];
    TCHAR szExp[MAX_PATH+1];
    HWND hDlg = (HWND)lpVoid;
    BOOL fCheck = TRUE, fEnable = FALSE;

    DebugMsg( DM_TRACE, TEXT("CheckRunInSeparateThread created and running") );

    while( g_bCheckRunInSep )
    {

        WaitForSingleObject( g_hCheckNow, INFINITE );
        ResetEvent( g_hCheckNow );

        if (g_bCheckRunInSep)
        {
            LPRUNDLG_DATA lprd;
            LPTSTR pszT;
            BOOL f16bit = FALSE;

            szFile[0] = TEXT('\0');
            szFullFile[0] = TEXT('\0');
            cch = 0;
            GetWindowText( GetDlgItem( hDlg, IDD_COMMAND ), szFile, MAX_PATH );
            // Remove & throw away arguments
            PathRemoveBlanks(szFile);

            if (PathIsUNC(szFile) || IsRemoteDrive(DRIVEID(szFile)))
            {
                f16bit = TRUE;
                fCheck = FALSE;
                fEnable = TRUE;
                goto ChangeTheBox;
            }

            // if the unquoted sting exists as a file just use it

            if (!PathFileExists(szFile))
            {
                pszT = PathGetArgs(szFile);
                if (*pszT)
                    *(pszT - 1) = TEXT('\0');

                PathUnquoteSpaces(szFile);
            }



            if (szFile[0])
            {
                ExpandEnvironmentStrings( szFile, szExp, MAX_PATH );
                szExp[ MAX_PATH ] = TEXT('\0');

                if (PathIsUNC(szExp) || IsRemoteDrive(DRIVEID(szExp)))
                {
                    f16bit = TRUE;
                    fCheck = FALSE;
                    fEnable = TRUE;
                    goto ChangeTheBox;
                }

                cch = SearchPath(  NULL,
                                   szExp,
                                   TEXT(".EXE"),
                                   MAX_PATH+1,
                                   szFullFile,
                                   &lpszFilePart
                                  );
            }

            if ((cch != 0) && (cch <= MAX_PATH))
            {
                if ( (GetBinaryType( szFullFile, &lBinaryType) &&
                     (lBinaryType==SCS_WOW_BINARY))
                    )
                {
                    f16bit = TRUE;
                    fCheck = FALSE;
                    fEnable = TRUE;
                } else {
                    f16bit = FALSE;
                    fCheck = TRUE;
                    fEnable = FALSE;
                }

            } else {

                f16bit = FALSE;
                fCheck = TRUE;
                fEnable = FALSE;
            }

ChangeTheBox:
            CheckDlgButton( hDlg, IDD_RUNINSEPARATE, fCheck ? 1 : 0 );
            EnableWindow( GetDlgItem( hDlg, IDD_RUNINSEPARATE ), fEnable );

            ENTERCRITICAL;
            lprd = (LPRUNDLG_DATA)GetWindowLong(hDlg, DWL_USER);
            if (lprd)
            {
                if (f16bit)
                    lprd->dwFlags |= RFD_WOW_APP;
                else
                    lprd->dwFlags &= (~RFD_WOW_APP);
            }
            LEAVECRITICAL;

        }

    }

    CloseHandle( g_hCheckNow );
    g_hCheckNow = NULL;
    DebugMsg( DM_TRACE, TEXT("CheckRunInSeparateThread exiting now...") );
    ExitThread( 0 );

}