void parse_exception::format_msgs(wiparsestream &is,EParseErros er,dcmapDCSTR errdta) { err = er; line=0;col=0; is.get_pos_info(&line,&col,&strline); filename = is.filename(); sinfo = filename+L" line:"+gsys::to_wstr(line)+L" col:"+gsys::to_wstr(col)+L" "; if(ParseErrors[err] && ParseErrors[err][0]) { if(errdta && errdta[0]) { errordta = errdta; swhat = L"error: " + boost::str(wformat(ParseErrorsParam[err]) % errordta); } else { swhat = L"error: " + (wstring)ParseErrors[err]; } } else { swhat = L"unknown parse error"; } sinfo += swhat; }
int ft_printf(char *format, ...) { char *tmp; va_list arg; int i; int u; u = 0; i = -1; va_start(arg, format); while (format[++i]) { if (format[i] == '%') { tmp = ft_strsub(format, (i + 1), (ft_strlen(format) - i)); if (check_flag(format[i + 1]) != -1) u = u + (wflag(format[i + 1], arg, &i)); else if (check_space(tmp) != -1) u = u + (wspace(tmp, &i, format, arg)); else i = i + (check_nbr(tmp, &u, arg)); } else u = u + (wformat(format[i])); } va_end(arg); return (u); }
/** * Verify the directory exists. * If the directory does not exist, the user will be prompted to create it. * @param parentWnd The parent window for dialogs. * @return @c true if the directory exists, @c false otherwise. */ bool FolderViewer::VerifyDirectory(OS::wnd_t parentWnd) { #ifdef _WIN32 if (fs::exists(path)) { if (fs::is_directory(path)) { return true; } else { MessageBoxW(parentWnd, str(wformat(L"%s\n\n%s") % (const wchar_t*)Str::UW(_("The path is not a directory.")) % path).c_str(), PACKAGE_NAME_L, MB_ICONWARNING); return false; } } else { int resp = MessageBoxW(parentWnd, str(wformat(L"%s\n\n%s\n\n%s") % (const wchar_t*)Str::UW(_("Directory does not exist.")) % path % (const wchar_t*)Str::UW(_("Would you like to create it?"))).c_str(), PACKAGE_NAME_L, MB_ICONQUESTION | MB_YESNO); if (resp == IDYES) { fs::create_directories(path); if (fs::exists(path) && fs::is_directory(path)) { return true; } else { MessageBoxW(parentWnd, Str::UW(_("Failed to create directory.")), PACKAGE_NAME_L, MB_ICONWARNING); return false; } } return false; } #else // Unimplemented. throw UnimplementedExn("FolderViewer::VerifyDirectory"); #endif }
bool threadBlankCheck(int Index) { bool result = false; // bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); struct CAddressRange Addr; Addr.start=0; Addr.end=Chip_Info.ChipSizeInByte; //(L"Blank Checking ..."); // if(is_greater_than_5_0_0) // SetLEDOnOff(SITE_BUSY,Index); SetIOMode(false,Index); result = SerialFlash_rangeBlankCheck(&Addr,Index) ; // m_bOperationResult[Index]=result? 1:RES_BLANK; #if 0 if( !bAuto[Index] ) { m_context.runtime.elapsed_time_of_last_operation = timer.elapsed() ; Log(wformat(L"Operation completed. \n%1% seconds elapsed.")%m_context.runtime.elapsed_time_of_last_operation); CompleteCnt++; if( CompleteCnt==GetDevNum() ) { m_context.runtime.is_operation_on_going = false; m_chip[Index]->ClearCancelOperationFlag(); } if(is_greater_than_5_0_0) m_board->SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); } #endif // SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); // g_is_operation_on_going = false; g_is_operation_successful = result; return result; }
bool threadEraseWholeChip(int Index) { bool result = false; // bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); // if(is_greater_than_5_0_0) // SetLEDOnOff(SITE_BUSY,Index); // Log(L"Erasing a whole chip ..."); // power::CAutoVccPower autopowerVcc(m_usb, m_context.power.vcc,Index); // power::CAutoVppPower autopowerVpp(m_usb, SupportedVpp(),Index); result = SerialFlash_chipErase(Index); // Log(result ? L"A whole chip erased" : L"Error: Failed to erase a whole chip"); // m_bOperationResult[Index]=result? 1:RES_ERASE; #if 0 if( !bAuto[Index] ) { m_context.runtime.is_operation_successful = result; m_context.runtime.elapsed_time_of_last_operation = timer.elapsed() ; Log(wformat(L"Operation completed. \n%1% seconds elapsed.")%m_context.runtime.elapsed_time_of_last_operation); CompleteCnt++; if( CompleteCnt==GetDevNum() ) { m_context.runtime.is_operation_on_going = false; m_chip[Index]->ClearCancelOperationFlag(); } if(is_greater_than_5_0_0) m_board->SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); } #endif // SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); g_is_operation_successful = result; // g_is_operation_on_going = false; return result; }
bool ConsoleHandler::StartShellProcess ( const wstring& strCustomShell, const wstring& strInitialDir, const wstring& strUser, const wstring& strPassword, const wstring& strInitialCmd, const wstring& strConsoleTitle, DWORD dwStartupRows, DWORD dwStartupColumns, bool bDebugFlag ) { wstring strUsername(strUser); wstring strDomain; // shared_ptr<void> userProfileKey; // shared_ptr<void> userEnvironment; // shared_ptr<void> userToken; if (strUsername.length() > 0) { size_t pos = strUsername.find(L'\\'); if (pos != wstring::npos) { strDomain = strUsername.substr(0, pos); strUsername = strUsername.substr(pos+1); } /* // logon user HANDLE hUserToken = NULL; ::LogonUser( strUsername.c_str(), strDomain.length() > 0 ? strDomain.c_str() : NULL, strPassword.c_str(), LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hUserToken); userToken.reset(hUserToken, ::CloseHandle); */ /* ::ImpersonateLoggedOnUser(userToken.get()); wchar_t szComspec[MAX_PATH]; ::GetEnvironmentVariable(L"COMSPEC", szComspec, MAX_PATH); */ /* // load user's profile // seems to be necessary on WinXP for environment strings' expainsion to work properly PROFILEINFO userProfile; ::ZeroMemory(&userProfile, sizeof(PROFILEINFO)); userProfile.dwSize = sizeof(PROFILEINFO); userProfile.lpUserName = const_cast<wchar_t*>(strUser.c_str()); ::LoadUserProfile(userToken.get(), &userProfile); userProfileKey.reset(userProfile.hProfile, bind<BOOL>(::UnloadUserProfile, userToken.get(), _1)); */ /* // load user's environment void* pEnvironment = NULL; ::CreateEnvironmentBlock(&pEnvironment, userToken.get(), FALSE); userEnvironment.reset(pEnvironment, ::DestroyEnvironmentBlock); ::RevertToSelf(); */ } wstring strShellCmdLine(strCustomShell); if (strShellCmdLine.length() == 0) { wchar_t szComspec[MAX_PATH]; ::ZeroMemory(szComspec, MAX_PATH*sizeof(wchar_t)); if (strUsername.length() > 0) { /* // resolve comspec when running as another user wchar_t* pszComspec = reinterpret_cast<wchar_t*>(userEnvironment.get()); while ((pszComspec[0] != L'\x00') && (_wcsnicmp(pszComspec, L"comspec", 7) != 0)) pszComspec += wcslen(pszComspec)+1; if (pszComspec[0] != L'\x00') { strShellCmdLine = (pszComspec + 8); } */ if (strShellCmdLine.length() == 0) strShellCmdLine = L"cmd.exe"; } else { if (::GetEnvironmentVariable(L"COMSPEC", szComspec, MAX_PATH) > 0) { strShellCmdLine = szComspec; } if (strShellCmdLine.length() == 0) strShellCmdLine = L"cmd.exe"; } } if (strInitialCmd.length() > 0) { strShellCmdLine += L" "; strShellCmdLine += strInitialCmd; } wstring strStartupTitle(strConsoleTitle); if (strStartupTitle.length() == 0) { strStartupTitle = L"Console2 command window"; // strStartupTitle = str(wformat(L"Console2 command window 0x%08X") % this); } // wstring strStartupDir((strUsername.length() > 0) ? Helpers::ExpandEnvironmentStringsForUser(userToken, strInitialDir) : Helpers::ExpandEnvironmentStrings(strInitialDir)); wstring strStartupDir((strUsername.length() > 0) ? strInitialDir : Helpers::ExpandEnvironmentStrings(strInitialDir)); if (strStartupDir.length() > 0) { if ((*(strStartupDir.end() - 1) == L'\"') && (*strStartupDir.begin() != L'\"')) { // startup dir name ends with ", but doesn't start with ", the user passed // something like "C:\" as the parameter, it got parsed to C:", remove the trailing " // // This is a common mistake, thus the check... strStartupDir = strStartupDir.substr(0, strStartupDir.length()-1); } // startup dir doesn't end with \, add it if (*(strStartupDir.end() - 1) != L'\\') strStartupDir += L'\\'; // check if startup directory exists DWORD dwDirAttributes = ::GetFileAttributes(strStartupDir.c_str()); if ((dwDirAttributes == INVALID_FILE_ATTRIBUTES) || (dwDirAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { // no directory, use Console.exe directory strStartupDir = Helpers::GetModulePath(NULL); } } // setup the startup info struct STARTUPINFO si; ::ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.lpTitle = const_cast<wchar_t*>(strStartupTitle.c_str()); if (g_settingsHandler->GetConsoleSettings().bStartHidden) { // Starting Windows console window hidden causes problems with // some GUI apps started from Console that use SW_SHOWDEFAULT to // initially show their main window (i.e. the window inherits our // SW_HIDE flag and remains invisible :-) si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; } else { // To avoid invisible GUI windows, default settings will create // a Windows console window far offscreen and hide the window // after it has been created. // // This approach can flash console window's taskbar button and // taskbar button can sometimes remain visible, but nothing is perfect :) si.dwFlags = STARTF_USEPOSITION; si.dwX = 0x7FFF; si.dwY = 0x7FFF; } PROCESS_INFORMATION pi; // we must use CREATE_UNICODE_ENVIRONMENT here, since s_environmentBlock contains Unicode strings DWORD dwStartupFlags = CREATE_NEW_CONSOLE|CREATE_SUSPENDED|CREATE_UNICODE_ENVIRONMENT; // TODO: not supported yet //if (bDebugFlag) dwStartupFlags |= DEBUG_PROCESS; if (strUsername.length() > 0) { if (!::CreateProcessWithLogonW( strUsername.c_str(), strDomain.length() > 0 ? strDomain.c_str() : NULL, strPassword.c_str(), LOGON_WITH_PROFILE, NULL, // const_cast<wchar_t*>(Helpers::ExpandEnvironmentStringsForUser(userToken, strShellCmdLine).c_str()), const_cast<wchar_t*>(strShellCmdLine.c_str()), dwStartupFlags, // userEnvironment.get(), NULL, (strStartupDir.length() > 0) ? const_cast<wchar_t*>(strStartupDir.c_str()) : NULL, &si, &pi)) { throw ConsoleException(str(wformat(Helpers::LoadStringW(IDS_ERR_CANT_START_SHELL_AS_USER)) % strShellCmdLine % strUser)); } } else { if (!::CreateProcess( NULL, const_cast<wchar_t*>(Helpers::ExpandEnvironmentStrings(strShellCmdLine).c_str()), NULL, NULL, FALSE, dwStartupFlags, s_environmentBlock.get(), (strStartupDir.length() > 0) ? const_cast<wchar_t*>(strStartupDir.c_str()) : NULL, &si, &pi)) { throw ConsoleException(str(wformat(Helpers::LoadString(IDS_ERR_CANT_START_SHELL)) % strShellCmdLine)); } } // create shared memory objects CreateSharedObjects(pi.dwProcessId, strUser); CreateWatchdog(); // write startup params m_consoleParams->dwConsoleMainThreadId = pi.dwThreadId; m_consoleParams->dwParentProcessId = ::GetCurrentProcessId(); m_consoleParams->dwNotificationTimeout = g_settingsHandler->GetConsoleSettings().dwChangeRefreshInterval; m_consoleParams->dwRefreshInterval = g_settingsHandler->GetConsoleSettings().dwRefreshInterval; m_consoleParams->dwRows = dwStartupRows; m_consoleParams->dwColumns = dwStartupColumns; m_consoleParams->dwBufferRows = g_settingsHandler->GetConsoleSettings().dwBufferRows; m_consoleParams->dwBufferColumns = g_settingsHandler->GetConsoleSettings().dwBufferColumns; m_hConsoleProcess = shared_ptr<void>(pi.hProcess, ::CloseHandle); // inject our hook DLL into console process if (!InjectHookDLL(pi)) return false; // resume the console process ::ResumeThread(pi.hThread); ::CloseHandle(pi.hThread); // wait for hook DLL to set console handle if (::WaitForSingleObject(m_consoleParams.GetReqEvent(), 10000) == WAIT_TIMEOUT) return false; ::ShowWindow(m_consoleParams->hwndConsoleWindow, SW_HIDE); return true; }