예제 #1
0
파일: Preferences.cpp 프로젝트: go4and/lib
bool setRegValue(HKEY root, const wchar_t * path, const wchar_t * name, const char * data, size_t size)
{
    HKEY key;
    LSTATUS res = RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_SET_VALUE, &key);
    if(res != ERROR_SUCCESS)
    {
        if(res == ERROR_FILE_NOT_FOUND)
        {
            DWORD disp;            
            res = RegCreateKeyEx(HKEY_CURRENT_USER, path, 0, 0, 0, KEY_SET_VALUE, 0, &key, &disp);
            if(res != ERROR_SUCCESS)
            {
                MLOG_ERROR("Failed to create key: " << res);
                return false;
            }
        } else {
            MLOG_ERROR("Failed to open key: " << res);
            return false;
        }
    }
    BOOST_SCOPE_EXIT(key) {
        RegCloseKey(key);
    } BOOST_SCOPE_EXIT_END;

    res = RegSetValueEx(key, name, 0, REG_BINARY, mstd::pointer_cast<const BYTE*>(data), size);

    if(res == ERROR_SUCCESS)
        return true;

    MLOG_ERROR("Failed to set value: " << mstd::utf8(name) << ", " << res);

    return false;
}
예제 #2
0
bool GInitContextWindow( const char* title,
		gContextHandles_t& handles )
{
	SDL_Init( SDL_INIT_VIDEO );
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, G_API_MAJOR_VERSION );
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, G_API_MINOR_VERSION );
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, G_API_CONTEXT_PROFILE );

	SDL_CreateWindowAndRenderer( handles.width, handles.height, 
			SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE, 
			&handles.window, &handles.renderer );

	if ( !handles.window ) 
	{
		goto sdl_failure;	
	}

	SDL_SetWindowTitle( handles.window, title );

	handles.context = SDL_GL_CreateContext( handles.window );

	if ( !handles.context )
	{
		goto sdl_failure;	
	}

#ifndef EMSCRIPTEN
	glewExperimental = true;
	GLenum glewErr = glewInit();
	if ( glewErr != GLEW_OK )
	{
		MLOG_ERROR( "Could not initialize GLEW: %s", 
				glewGetErrorString( glewErr ) );
		return false;
	}
#endif

	SDL_RenderPresent( handles.renderer );

	// HACK: error checking is impossible unless this happens;
	// apparently an invalid enumeration exists - possibly
	// in SDL or GLEW's initialization...

	glGetError();

	return true;

sdl_failure:
	MLOG_ERROR( "SDL_Error: %s", SDL_GetError() );
	return false;	
}
예제 #3
0
파일: WindowUtils.cpp 프로젝트: go4and/lib
AutoScroller::AutoScroller(wxWindow * window, wxOrientation orient)
    : window_(window), orient_(orient)
{
    memset(&scrollInfo_, 0, sizeof(scrollInfo_));
    scrollInfo_.cbSize = sizeof(scrollInfo_);
    scrollInfo_.fMask = SIF_ALL;
    BOOL res = GetScrollInfo(window->GetHWND(), winSB(orient_), &scrollInfo_);
    if (!res)
    {
        int err = GetLastError();
        if(err != ERROR_NO_SCROLLBARS)
        {
            MLOG_ERROR("GetScrollInfo failed: " << err << ", msg: " << mstd::out_utf8(winutils::getErrorMessage(err)));
            BOOST_ASSERT(false);
        }
        scrollInfo_.fMask = 0;
    }
}
예제 #4
0
파일: tlogg.c 프로젝트: MoserMichael/cstuff
void LOGG_test()
{
  char buf[512];

  unlink( LOG_FILE );
  unlink( ERR_FILE );
  MLOG_init( MLOG_LEVEL_DEBUG, MLOG_ACTION_TO_FILE, LOG_FILE);
  MLOG_alloc_option( MLOG_ALLOC_TLS_HEAP, 1024 );

  MLOG_TRACE("Not logged");
  MLOG_DEBUG("First post %d", 42 );
  MLOG_INFO("Important message %d %d %d", 42, 42, 42);
  MLOG_ERROR("ERROR ERROR ERROR");


  sprintf( buf, "${BIN_ROOT_DIR}/../scripts/readerrors.pl %s", ERR_FILE );
  printf("%s\n",buf);
  VASSERT( system(buf) == 0 );
}
예제 #5
0
// Once finished, we send the address of gImageTracker to
// gImageTracker->finishEvent(). gImageTracker is a unique_ptr.
static void OnImageRead( char* buffer, int size, void* param )
{
	UNUSED( param );

	if ( !gImageTracker )
	{
		MLOG_ERROR( "%s", "gImageTracker is NULL" );
		return;
	}

	if ( !gImageTracker->finishEvent )
	{
		MLOG_ERROR( "%s", "No finishEvent assigned in gImageTracker!" );
		return;
	}

	wApiImageInfo_t* imageInfo = ( wApiImageInfo_t* ) buffer;

	bool atEnd = gImageTracker->serverImageCount > 0
		&& gImageTracker->iterator >= gImageTracker->serverImageCount;

	if ( atEnd )
	{
		gImageTracker->finishEvent( &gImageTracker );

		return;
	}

	if ( !imageInfo )
	{
		MLOG_ERROR( "%s", "nullptr should NOT be received at this stage" );

		return;
	}

	// A zero size implies an image which couldn't be found, so we
	// take the name from our info and use it to assign an invalid index.
	if ( !size )
	{
		AssignIndex(
			imageInfo,
			gla::atlas_t::no_image_index
		);

		return;
	}

	if ( !gImageTracker->serverImageCount )
	{
		if ( strncmp(
				&imageInfo->name[ 0 ],
				WAPI_IMAGE_SERVER_IMAGE_COUNT,
				strlen( WAPI_IMAGE_SERVER_IMAGE_COUNT ) ) == 0 )
		{
			gImageTracker->serverImageCount = ( size_t ) imageInfo->width;

			// There may not be any needed images for this current bundle.
			// Even if that's the case, the server will still provide its
			// final "ending" call, so here we make sure that atEnd will
			// resolve to true naturally on the final run.
			if ( !gImageTracker->serverImageCount )
			{
				gImageTracker->serverImageCount = 0x7FFFFFFF;
				gImageTracker->iterator = 0x7FFFFFFF;
			}
		}
		else
		{
			MLOG_ERROR(
				"%s",
				"ERROR: first wApiImageInfo_t sent MUST be the header"
			);
		}

		return;
	}

	if ( !imageInfo->width || !imageInfo->height || !imageInfo->bpp )
	{
		MLOG_ERROR(
			"zero portion of metadata received. " DATA_FMT_STRING( 0 ) );
		return;
	}

	size_t imageDataSize = imageInfo->width * imageInfo->height * imageInfo->bpp
		+ sizeof( *imageInfo );

	if ( ( size_t ) size != imageDataSize )
	{
		MLOG_ERROR(
			"buffer size does not match " \
	 		"interpreted metadata criteria. "
			DATA_FMT_STRING( imageDataSize )
		);
		return;
	}

	gla::push_atlas_image(
		*( gImageTracker->destAtlas ),
		( uint8_t* ) &buffer[ sizeof( *imageInfo ) ],
		imageInfo->width,
		imageInfo->height,
		imageInfo->bpp
	);

	AssignIndex(
	 	imageInfo,
		gImageTracker->destAtlas->num_images - 1
	);
}