/* * Copyright (c) 2005 Alexander Gottwald * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name(s) of the above copyright * holders shall not be used in advertising or otherwise to promote the sale, * use or other dealings in this Software without prior written authorization. */ #define SAVEPOSIX _POSIX_ #undef _POSIX_ #include #include #include #include #define _POSIX_ SAVEPOSIX #include "window/util.h" #include "window/wizard.h" #include "resources/resources.h" #include "config.h" #include #include #include #include #include static bool ContainPrintableChars(const char *Buf, unsigned Nbr) { for (int i=0; i0x20) return true; } return false; } static bool CheckOutput(HANDLE hChildStdoutRd, int hStdOut, HANDLE hConsoleOutput, HWND hConsoleWnd) { DWORD NbrAvail=0; PeekNamedPipe(hChildStdoutRd, NULL, NULL, NULL, &NbrAvail, NULL); if (NbrAvail) { char Buf[128]; size_t Nbr = _read(hStdOut, Buf, sizeof(Buf)); DWORD NbrWritten; WriteConsole(hConsoleOutput, Buf, Nbr, &NbrWritten, NULL); if (hConsoleWnd && ContainPrintableChars(Buf,NbrWritten)) { // Only show console again when there are new characters printed ShowWindow(hConsoleWnd, SW_SHOW ); // make it visible again return true; } } return false; } #define NRINPUTS 50 static int CheckInput(HANDLE hConsoleInput, char *Buf, HWND hConsoleWnd) { INPUT_RECORD Input[NRINPUTS]; DWORD NbrAvail=0; GetNumberOfConsoleInputEvents(hConsoleInput, &NbrAvail); int w=0; if (NbrAvail) { DWORD NbrRead=0; ReadConsoleInput(hConsoleInput, Input, NRINPUTS, &NbrRead); for (int i=0; i 10) TerminateProcess(pi.hProcess, (DWORD)-1); else // Shutdown Xsrv (the soft way!) EnumThreadWindows(pi.dwThreadId, KillWindowsProc, 0); Sleep(500); GetExitCodeProcess(pi.hProcess, &exitcode); } } // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); CloseHandle( pic.hProcess ); } }; int main(int argc, char **argv) { try { InitCommonControls(); CMyWizard dialog; bool skip_wizard = false; for (int i = 1; i < argc; i++) { if (argv[i] == NULL) continue; std::string arg(argv[i]); if (arg == "-load" && i + 1 < argc) { i++; dialog.LoadConfig(argv[i]); continue; } if (arg == "-run" && i + 1 < argc) { i++; dialog.LoadConfig(argv[i]); skip_wizard = true; continue; } } int ret = 0; if (skip_wizard || (ret =dialog.ShowModal()) != 0) dialog.StartUp(); #ifdef _DEBUG printf("return %d\n", ret); #endif return 0; } catch (std::runtime_error &e) { char Message[255]; sprintf(Message,"Failure: %s\n", e.what()); MessageBox(NULL,Message,"Exception",MB_OK); return -1; } }