コード例 #1
0
 bool LaunchProcess(const CommandLine& cmdline,
     const LaunchOptions& options,
     ProcessHandle* process_handle)
 {
     return LaunchProcess(cmdline.GetCommandLineString(),
         options, process_handle);
 }
コード例 #2
0
    bool GetAppOutput(const CommandLine& cl, std::string* output)
    {
        HANDLE out_read = NULL;
        HANDLE out_write = NULL;

        SECURITY_ATTRIBUTES sa_attr;
        // Set the bInheritHandle flag so pipe handles are inherited.
        sa_attr.nLength = sizeof(SECURITY_ATTRIBUTES);
        sa_attr.bInheritHandle = TRUE;
        sa_attr.lpSecurityDescriptor = NULL;

        // Create the pipe for the child process's STDOUT.
        if(!CreatePipe(&out_read, &out_write, &sa_attr, 0))
        {
            NOTREACHED() << "Failed to create pipe";
            return false;
        }

        // Ensure we don't leak the handles.
        win::ScopedHandle scoped_out_read(out_read);
        win::ScopedHandle scoped_out_write(out_write);

        // Ensure the read handle to the pipe for STDOUT is not inherited.
        if(!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0))
        {
            NOTREACHED() << "Failed to disabled pipe inheritance";
            return false;
        }

        std::wstring writable_command_line_string(cl.GetCommandLineString());

        // Now create the child process
        PROCESS_INFORMATION proc_info = { 0 };
        STARTUPINFO start_info = { 0 };

        start_info.cb = sizeof(STARTUPINFO);
        start_info.hStdOutput = out_write;
        // Keep the normal stdin and stderr.
        start_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
        start_info.hStdError = GetStdHandle(STD_ERROR_HANDLE);
        start_info.dwFlags |= STARTF_USESTDHANDLES;

        // Create the child process.
        if(!CreateProcess(NULL,
            &writable_command_line_string[0],
            NULL, NULL,
            TRUE, // Handles are inherited.
            0, NULL, NULL, &start_info, &proc_info))
        {
            NOTREACHED() << "Failed to start process";
            return false;
        }

        // We don't need the thread handle, close it now.
        CloseHandle(proc_info.hThread);

        // Close our writing end of pipe now. Otherwise later read would not be able
        // to detect end of child's output.
        scoped_out_write.Close();

        // Read output from the child process's pipe for STDOUT
        const int kBufferSize = 1024;
        char buffer[kBufferSize];

        for(;;)
        {
            DWORD bytes_read = 0;
            BOOL success = ReadFile(out_read, buffer, kBufferSize,
                &bytes_read, NULL);
            if(!success || bytes_read==0)
            {
                break;
            }
            output->append(buffer, bytes_read);
        }

        // Let's wait for the process to finish.
        WaitForSingleObject(proc_info.hProcess, INFINITE);
        CloseHandle(proc_info.hProcess);

        return true;
    }
コード例 #3
0
ファイル: PixiePVT.cpp プロジェクト: RichardMarks/Pixie
void PixiePVTMain()
	{
	ImageFormat_PNG::Register();
	ImageFormat_JPG::Register();
	ImageFormat_GIF::Register();
	ImageFormat_TGA::Register();

	Platform::GetPlatform_Screen()->SetFullscreen(false);

	ResourceManager resourceManager;
	InputManager inputManager;
	inputManager.HideCursor();

	CommandLine cmd;
	
	StringId filename=cmd.GetCommandLineString(0);

	if (Platform::GetPlatform_FileSystem())
		{	
		Platform_FileSystem_File* file=Platform::GetPlatform_FileSystem()->CreateFileObject(filename.GetString());
		if (!file->Exists())
			{
			return;
			}
		delete file;
		}
	else
		{
		return;
		}

	if (!VerifyFilename(filename.GetString()))
		{
		return;
		}

	bool fullscreen=false;
	int screenWidth=Platform::GetPlatform_Screen()->GetWidth();
	int screenHeight=Platform::GetPlatform_Screen()->GetHeight();
	Array<StringId> files;
	StringId path=GetPath(filename);
	StringId filenameOnly=GetFilename(filename);
	Platform_FileSystem_Directory* directory=Platform::GetPlatform_FileSystem()->CreateDirectoryObject(path.GetString());
	int fileIndex=0;
	for (int i=0; i<directory->GetFileCount(); i++)
		{
		const char* name=directory->GetFile(i);
		if (VerifyFilename(name))
			{
			char buffer[4096];
			SNPrintF(buffer,4096,"%s/%s",path.GetString(),name);	
			files.Add(StringId(buffer));
			if (filenameOnly==StringId(name))
				{
				fileIndex=i;
				}
			}
		}
	delete directory;

	float cel=0;

	Resource_BitmapStrip bitmap;
	Screen* screen=LoadImage(0,filename, bitmap, fullscreen);

	FrameTime frameTime;

	bool exitFlag=false;
	while (!exitFlag)
		{
		cel+=frameTime.Update()*5;
		DrawBackground(screen->GetBackBuffer());
		int x=(screen->GetBackBuffer().GetWidth()-bitmap.GetWidth((int)cel))/2;
		int y=(screen->GetBackBuffer().GetHeight()-bitmap.GetHeight((int)cel))/2;
		if (x>0 || y>0)
			{
			int w=screen->GetBackBuffer().GetWidth();
			int h=screen->GetBackBuffer().GetHeight();
			screen->GetBackBuffer().Fill(0,0,x,h,0);
			screen->GetBackBuffer().Fill(w-x,0,w,h,0);
			screen->GetBackBuffer().Fill(x,0,w-x,y,0);
			screen->GetBackBuffer().Fill(x,h-y,w-x,h,0);
			}
		bitmap.Blit((int)cel,screen->GetBackBuffer(),x,y);
		screen->Present();

		inputManager.Update();
		if (inputManager.WasKeyPressed(KEY_ESCAPE))
			{
			exitFlag=true;
			}
		if (inputManager.WasKeyPressed(KEY_SPACE))
			{
			fileIndex++;
			if (fileIndex>=files.GetItemCount())
				{
				fileIndex=0;
				}
			
			screen=LoadImage(screen, files.Get(fileIndex),bitmap, fullscreen);
			cel=0;
			}
		if (inputManager.WasKeyPressed(KEY_BACK))
			{
			fileIndex--;
			if (fileIndex<0)
				{
				fileIndex=files.GetItemCount()-1;
				}
			screen=LoadImage(screen,files.Get(fileIndex),bitmap,fullscreen);
			cel=0;
			}

		// Toggle between fullscreen and windowed mode on Alt+Enter
		if (inputManager.IsKeyDown(KEY_MENU) && inputManager.WasKeyPressed(KEY_RETURN))
			{
			fullscreen=!fullscreen;
			delete screen;
			screen=new Screen(screenWidth,screenHeight);
			screen->SetFullscreen(fullscreen);
			screen->SetInterpolationMode(false);
			screen=LoadImage(screen, files.Get(fileIndex),bitmap, fullscreen);
			inputManager.RestoreCursor();
			}

		
		if (Platform::GetPlatform_OS())
			{
			Platform::GetPlatform_OS()->OsYield();
			if (Platform::GetPlatform_OS()->ExitRequested())
				{
				exitFlag=true;
				}
			}

		}

	delete screen;
	}