Exemplo n.º 1
0
int getString(CmdLineArgs a, int idx, TCHAR* str){
	int iRet=0;
	if(a.size()<idx+1)
		return 0;
	wcscpy(a[idx+1], str);
	return wcslen(str);
}
Exemplo n.º 2
0
Arquivo: main.cpp Projeto: dquam/Bak3d
//------------------------------------------------------------------------------
int WINAPI WinMain(    HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR     lpCmdLine,
                    int       nCmdShow )
{
    //initNSight();
#ifdef MEMORY_LEAKS_CHECK
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); 
    _CrtSetReportMode ( _CRT_ERROR, _CRTDBG_MODE_DEBUG|_CRTDBG_MODE_WNDW);
#endif

    WNDCLASSEX winClass;
    MSG        uMsg;

    main::g_hInstance = hInstance;

    memset(&uMsg,0,sizeof(uMsg));

    winClass.lpszClassName = "MY_WINDOWS_CLASS";
    winClass.cbSize        = sizeof(WNDCLASSEX);
    winClass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
    winClass.lpfnWndProc   = main::WindowProc;
    winClass.hInstance     = hInstance;
    winClass.hIcon           = LoadIcon(hInstance, (LPCTSTR)IDI_OPENGL_ICON);
    winClass.hIconSm       = LoadIcon(hInstance, (LPCTSTR)IDI_OPENGL_ICON);
    winClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    winClass.lpszMenuName  = NULL;
    winClass.cbClsExtra    = 0;
    winClass.cbWndExtra    = 0;
    
    if(!RegisterClassEx(&winClass) )
        return E_FAIL;

    main::g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS",
                             "Viewer",
                             WS_OVERLAPPEDWINDOW, 0, 0, main::g_winSz[0], main::g_winSz[1], NULL, NULL, 
                             hInstance, NULL );

    if( main::g_hWnd == NULL )
        return E_FAIL;

    ShowWindow( main::g_hWnd, nCmdShow );
    UpdateWindow( main::g_hWnd );

#if defined(USESVCUI) || defined(USEANTTWEAKBAR)
    main::initUIBase();
#endif
    // Initialize the very base of OpenGL
    if(main::initGLBase())
    {
        // Initialize more general stuff... typically what can be declared when using GLUT
        // TODO: replace the lpCmdLine by proper C-style arguments
        CmdLineArgs args;

        std::string exe = args[0];
        //std::replace(exe.begin(),exe.end(),'\\','/');
        //size_t last = exe.rfind('/');
        //if (last != std::string::npos){
        //  g_path = exe.substr(0,last) + std::string("/");
        //}

        main::initGL((int)args.size(), (const char**)&args[0]);

        //---------------------------------------------------------------------------
        // Message pump
        while( uMsg.message != WM_QUIT )
        {
            if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
            { 
                TranslateMessage( &uMsg );
                DispatchMessage( &uMsg );
            }
            else 
            {
                main::idle();
                if(main::g_renderCnt > 0)
                {
                    main::g_renderCnt--;
                    main::display();
                    Sleep(1);
                } else
                    Sleep(10);
            }
        }
    }
    main::shutdown();
    if( main::g_hRC != NULL )
    {
        ReleaseDC( main::g_hWnd, main::g_hDC );
        main::g_hDC = NULL;
    }
    main::shutdownBase();
    UnregisterClass( "MY_WINDOWS_CLASS", hInstance );

#ifdef MEMORY_LEAKS_CHECK
    _CrtDumpMemoryLeaks();
#endif

    return (int)uMsg.wParam;
}
Exemplo n.º 3
0
void CNWNX2App::parseNWNCmdLine()
{
	CmdLineArgs args;

	for (int i = 0; i < args.size(); i++)
	{
		if (stricmp(args[i], "-port") == 0)
		{
			dlg.m_intServerPort = atoi(args[i+1]);
			i++;
		}
		else if (stricmp(args[i], "-module") == 0)
		{
			dlg.m_strModuleName = args[i+1];
			i++;
		}
		else if (stricmp(args[i], "-processwatchdog") == 0)
		{
			if (atoi(args[i+1]) == 0)
				dlg.m_boolWatchdogProcess = false;
			else
				dlg.m_boolWatchdogProcess = true;
			i++;
		}
		else if (stricmp(args[i], "-processinterval") == 0)
		{
			dlg.m_intUpdateIntervalProcess = atoi(args[i+1]);
			i++;
		}
		else if (stricmp(args[i], "-gamespywatchdog") == 0)
		{
			if (atoi(args[i+1]) == 0)
				dlg.m_boolWatchdogGamespy = false;
			else
				dlg.m_boolWatchdogGamespy = true;
			i++;
		}
		else if (stricmp(args[i], "-gamespyinterval") == 0)
		{
			dlg.m_intUpdateIntervalGamespy = atoi(args[i+1]);
			i++;
		}
		else if (stricmp(args[i], "-gamespyretries") == 0)
		{
			dlg.m_intGamespyRetries = atoi(args[i+1]);
			i++;
		}
		else if (stricmp(args[i], "-oldgamespyprotocol") == 0)
		{
			if (atoi(args[i+1]) == 1)
				dlg.m_boolOldGamespyProtocol = true;
			i++;
		}
		else if (stricmp(args[i], "-publicserver") == 0)
		{
			if (atoi(args[i+1]) == 0)
				dlg.m_boolWatchdogGamespy = false;
			strcat(cmdline, args[i]);
			strcat(cmdline, " ");
		}
		else if (stricmp(args[i], "-restartdelay") == 0)
		{
			dlg.m_intRestartDelay = atoi(args[i+1]);
			i++;
		}
		else
		{
			strcat(cmdline, args[i]);
			strcat(cmdline, " ");
		}
	}

	char port[6];
	itoa(dlg.m_intServerPort, port, 10);
	strcat(cmdline, "-port ");
	strcat(cmdline, port);

	if (dlg.m_strModuleName != "")
	{
		strcat(cmdline, " -module ");
		strcat(cmdline, dlg.m_strModuleName);
	}
}
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
  int NoProtect = 0;
  AllowLinear = true;
  double MaxMSE = 4.0;

	CmdLineArgs args;

	if (args.size() == 1)
	{
		Usage();
		return 1;
	}

	const char* InputDir = NULL;
	const char* OutputFilename = "Textures.xpr";

	for (unsigned int i = 1; i < args.size(); ++i)
	{
		if (!stricmp(args[i], "-help") || !stricmp(args[i], "-h") || !stricmp(args[i], "-?"))
		{
			Usage();
			return 1;
		}
		else if (!stricmp(args[i], "-input") || !stricmp(args[i], "-i"))
		{
			InputDir = args[++i];
		}
		else if (!stricmp(args[i], "-output") || !stricmp(args[i], "-o"))
		{
			OutputFilename = args[++i];
		}
    else if (!stricmp(args[i], "-noprotect") || !stricmp(args[i], "-p"))
    {
      NoProtect = 1;
    }
    else if (!stricmp(args[i], "-onlyswizzled") || !stricmp(args[i], "-s"))
    {
      AllowLinear = false;
    }
    else if (!stricmp(args[i], "-quality") || !stricmp(args[i], "-q"))
		{
			++i;
			if (!stricmp(args[i], "min"))
			{
				MaxMSE = DBL_MAX;
			}
			else if (!stricmp(args[i], "low"))
			{
				MaxMSE = 20.0;
			}
			else if (!stricmp(args[i], "normal"))
			{
				MaxMSE = 4.0;
			}
			else if (!stricmp(args[i], "high"))
			{
				MaxMSE = 1.5;
			}
			else if (!stricmp(args[i], "max"))
			{
				MaxMSE = 0.0;
			}
			else
			{
				printf("Unrecognised quality setting: %s\n", args[i]);
			}
		}
		else
		{
			printf("Unrecognised command line flag: %s\n", args[i]);
		}
	}

	// Initialize DirectDraw
	pD3D = Direct3DCreate8(D3D_SDK_VERSION);
	if (pD3D == NULL)
	{
		puts("Cannot init D3D");
		return 1;
	}

	HRESULT hr;
	D3DDISPLAYMODE dispMode;
	D3DPRESENT_PARAMETERS presentParams;

	pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dispMode);

	ZeroMemory(&presentParams, sizeof(presentParams));
	presentParams.Windowed = TRUE;
	presentParams.hDeviceWindow = GetConsoleWindow();
	presentParams.SwapEffect = D3DSWAPEFFECT_COPY;
	presentParams.BackBufferWidth = 8;
	presentParams.BackBufferHeight = 8;
	presentParams.BackBufferFormat = dispMode.Format;

	hr = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParams, &pD3DDevice);
	if (FAILED(hr))
	{
		printf("Cannot init D3D device: %08x\n", hr);
		pD3D->Release();
		return 1;
	}

	char HomeDir[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, HomeDir);

	XPRFile.OutputBuf = (char*)VirtualAlloc(0, 64 * 1024 * 1024, MEM_RESERVE, PAGE_NOACCESS);
	if (!XPRFile.OutputBuf)
	{
		printf("Memory allocation failure: %08x\n", GetLastError());
		pD3DDevice->Release();
		pD3D->Release();
		return 1;
	}

	Bundler.StartBundle();

	// Scan the input directory (or current dir if false) for media files
	ConvertDirectory(InputDir, NULL, MaxMSE);

	VirtualFree(XPRFile.OutputBuf, 0, MEM_RELEASE);

	pD3DDevice->Release();
	pD3D->Release();

	SetCurrentDirectory(HomeDir);
	DWORD attr = GetFileAttributes(OutputFilename);
	if (attr != -1 && (attr & FILE_ATTRIBUTE_DIRECTORY))
	{
		SetCurrentDirectory(OutputFilename);
		OutputFilename = "Textures.xpr";
	}

	printf("\nWriting bundle: %s", OutputFilename);
  int BundleSize = Bundler.WriteBundle(OutputFilename, NoProtect);
	if (BundleSize == -1)
	{
		printf("\nERROR: %08x\n", GetLastError());
		return 1;
	}

	printf("\nUncompressed texture size: %6dkB\nCompressed texture size: %8dkB\nBundle size:             %8dkB\n\nWasted Pixels: %u/%u (%5.2f%%)\n",
		(UncompressedSize + 1023) / 1024, (((CompressedSize + 1023) / 1024) + 3) & ~3, (BundleSize + 1023) / 1024,
		TotalDstPixels - TotalSrcPixels, TotalDstPixels, 100.f * (float)(TotalDstPixels - TotalSrcPixels) / (float)TotalDstPixels);

	return 0;
}
Exemplo n.º 5
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 
    LoadString(hInstance, IDC_SHOWWIN, szWindowClass, MAX_LOADSTRING);

	HWND hwndOld=FindWindow(szWindowClass,NULL);
	// kill request?
	if(hwndOld!=NULL){
		if(wcsicmp(lpCmdLine, L"-kill")==0){
			PostMessage(hwndOld, WM_QUIT, 0, 0);
			return 11;
		}
	}

	DEBUGMSG(1, (L"CmdLine parsing #1: \r\n"));
	//command parsing
	struct cmdList *Liste;
	Liste=NULL;
	CmdLineArgs args;
	for (UINT i = 0; i < args.size(); i++){
		DEBUGMSG(1, (L"%20i: '%s'\r\n", i, args[i]));
		append(&Liste, args[i]);
	}
	getOptions(Liste);
	args.~CmdLineArgs();
	//end of parsing

	// already running?
	if(hwndOld!=NULL){
		//check if new message text?
		if(wcslen(szMessageTextNew) > 0){
			myMsg _mymsg;
			memset(&_mymsg,0,sizeof(myMsg));
			wsprintf( _mymsg.szText, L"%s", szMessageTextNew );
			_mymsg.iVal=0;	//the text message identifier
			//prepare WM_COPYDATA
			COPYDATASTRUCT copyData;
			copyData.dwData=1234;
			copyData.cbData=sizeof(myMsg);
			copyData.lpData=&_mymsg;
			SendMessage(hwndOld, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&copyData);
		}
		if(iProgressValNew!=-1){
			myMsg _mymsg;
			memset(&_mymsg,0,sizeof(myMsg));
			wsprintf( _mymsg.szText, L"%i", iProgressValNew );
			_mymsg.iVal=1;	//the progress message identifier
			//prepare WM_COPYDATA
			COPYDATASTRUCT copyData;
			copyData.dwData=1234;
			copyData.cbData=sizeof(myMsg);
			copyData.lpData=&_mymsg;
			SendMessage(hwndOld, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&copyData);
		}
		ShowWindow(hwndOld, SW_SHOWNORMAL);
		return -1;
	}
	
	//client size
	int maxX = GetSystemMetrics(SM_CXSCREEN);
	int maxY = GetSystemMetrics(SM_CYSCREEN);		//640 ??
	int borderSize = GetSystemMetrics(SM_CXBORDER);
	int minSize = GetSystemMetrics(SM_CYMENU);
	//int yFull = GetSystemMetrics(SM_CYFULLSCREEN);	//554 ??
	RECT rectMax;
	GetWindowRect(GetDesktopWindow(), &rectMax);
	if(xWidth<100 || xWidth>maxX)	// secure width setting
		xWidth=maxX-2*borderSize;
	if(yHeight<minSize)
		yHeight=minSize+2*borderSize;

	if(xPos<borderSize)	//secure x pos
		xPos=borderSize;
	if(yPos<rectMax.top)	//secure y pos
		yPos=rectMax.top;

	//progressBar is attached to bottom of window
	if(bUseProgress){
		//extend window
		xProgressWidth=xWidth;
		yHeight+=yProgressHeight;
		yProgress=yHeight-yProgressHeight;

	}
	// Perform application initialization:
	if (!InitInstance(hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	HACCEL hAccelTable;
	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SHOWWIN));

	// Main message loop:
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}
Exemplo n.º 6
0
std::string getCommandOutPut(const std::string& cmd, CmdLineArgs& cmdArgs, 
								unsigned char* stdinput, const unsigned stdinputlength)
{
	int outfd[2];
	int infd[2];
	int oldstdin, oldstdout;

	pipe(outfd); // Where the parent is going to write to
	pipe(infd); // From where parent is going to read

	oldstdin = dup(0); // Save current stdin
	oldstdout = dup(1); // Save stdout

	close(0);
	close(1);

	dup2(outfd[0], 0); // Make the read end of outfd pipe as stdin
	dup2(infd[1], 1); // Make the write end of infd as stdout

	if(!fork()) {

		//std::cerr<< "No. of cmd args : " << cmdArgs.size() << std::endl;
		char **argv = new char*[2 + cmdArgs.size()];
		argv[0] =  (char*) cmd.c_str();
		int i = 1;
		for(CmdLineArgs::iterator itr = cmdArgs.begin(); itr != cmdArgs.end(); ++itr) { 
			argv[i++] = (char*) itr->c_str();
			std::cerr << "Arg : \n"  << itr->c_str() << "\n";
		}
		argv[i] = 0;

		close(outfd[0]); // Not required for the child
		close(outfd[1]);
		close(infd[0]);
		close(infd[1]);

		execv(argv[0],argv);
	}
	else {
		close(0); close(1);
		dup2(oldstdin, 0);
		dup2(oldstdout, 1);

		close(outfd[0]); // These are being used by the child
		close(infd[1]);

		if( stdinput && stdinputlength ) {
			write(outfd[1],stdinput, stdinputlength ); // Write to child’s stdin
			close(outfd[1]);
		}
		
		char input[1024] = { 0 };
		int bytesRead = 0;
		std::string retVal;
		while( bytesRead = read(infd[0], input, 1024) ) {
			retVal += std::string(input);
			memset(input, 0, sizeof(input));
		}

		//char input[1024] = { 0 };
		//input[read(infd[0], input, 1024)] = 0; // Read from child’s stdout
		//std::string retVal(input);
		
		return retVal;
	}
}
Exemplo n.º 7
0
int _tmain(int argc, _TCHAR* argv[])
{
	// -class "IE6on6SoftKeyBar" -enable -list
	if(argc==1){	// no args
		nclog(L"showFullScreen utility v 1.0 * %s\n", logDateTime());
		printHelp();
		MessageBox(GetDesktopWindow(), L"showFullScreen needs some args. Please see 'showFullScreen.exe.log.txt'", L"showFullScreen", MB_SETFOREGROUND | MB_TOPMOST | MB_OK);
		return -3;
	}

	DEBUGMSG(1, (L"CmdLine parsing #1: \r\n"));
	//command parsing
	struct cmdList *Liste;
	Liste=NULL;
	CmdLineArgs args;
	for (UINT i = 0; i < args.size(); i++){
		DEBUGMSG(1, (L"%20i: '%s'\r\n", i, args[i]));
		append(&Liste, args[i]);
	}
	getOptions(Liste);
	args.~CmdLineArgs();
	//end of parsing

	if(bListWindows){
		nclog(L"showFullScreen utility v 1.0 * %s\n", logDateTime());
		
		ListWindows();
	}

	//look for window
	HWND hWnd=NULL;
	if(wcslen(szWindowClass) && wcslen(szWindowTitle)){
		//window title and class
		hWnd = FindWindow(szWindowClass, szWindowTitle);
	}
	else if(wcslen(szWindowClass)){
		//only window class, ie "WFIcaClient"
		hWnd = FindWindow(szWindowClass, NULL);
	}
	else if(wcslen(szWindowTitle)){
		//only window title
		hWnd = FindWindow(NULL, szWindowTitle);
	}

	HWND hWndTaskbar = FindWindow(L"HHTASKBAR", NULL);
	//sanity restore of HHTASKBAR?
	//ShowWindow(hWndTaskbar, SW_SHOWNORMAL);

	if(hWnd==NULL)
		return -1;	//no window found

	if(bChangeSize){	//change size?
		RECT rectDesktop;
		HRESULT hRes = GetWindowRect(GetDesktopWindow(), &rectDesktop);	//desktopwindow is only the taskbar window!
		// SM_CXFULLSCREEN , SM_CXMAXIMIZED , SM_CXSCREEN 
		int iCX;
		int iCY;
		BOOL bRes;
		if(bShowFullScreen){
			iCX = GetSystemMetrics(SM_CXSCREEN);	// 480
			iCY = GetSystemMetrics(SM_CYSCREEN);	// 640
			bRes = SetWindowPos(hWnd, GetDesktopWindow(), 0, 0, iCX, iCY, SWP_SHOWWINDOW);
			ShowWindow(hWndTaskbar, SW_HIDE);
		}
		else{
			RECT rcMaxScreen;
			SystemParametersInfo(SPI_GETWORKAREA, 0, &rcMaxScreen, SPIF_SENDCHANGE);	// {top=36 bottom=640 left=0 right=480}
			bRes = SetWindowPos(hWnd, GetDesktopWindow(), rcMaxScreen.left, rcMaxScreen.top, rcMaxScreen.right, rcMaxScreen.bottom-rcMaxScreen.top, SWP_SHOWWINDOW);
			ShowWindow(hWndTaskbar, SW_SHOWNORMAL);
		}
	}
	if(iShowHide!=0){	//change show/hide
		switch(iShowHide){
			case 1:
				ShowWindow(hWnd, SW_SHOWNORMAL);
				break;
			case 2:
				ShowWindow(hWnd, SW_HIDE);
				break;
		}
	}
	if(iEnableDisable!=0){	//enable/disbale window
		switch(iEnableDisable){
			case 1:
				EnableWindow(hWnd, TRUE);
				break;
			case 2:
				EnableWindow(hWnd, FALSE);
				break;
		}
	}

	return 0;
}