//////////////////////////////////////////////////////////// /// Load a font from a file //////////////////////////////////////////////////////////// bool FontLoader::LoadFontFromFile(const std::string& Filename, unsigned int CharSize, std::wstring Charset, Font& LoadedFont) { // Check if Freetype is correctly initialized if (!myLibrary) { std::cerr << "Failed to load font \"" << Filename << "\", FreeType has not been initialized" << std::endl; return false; } // Create a new font face from the specified file FT_Face FontFace; FT_Error Error = FT_New_Face(myLibrary, Filename.c_str(), 0, &FontFace); if (Error) { std::cerr << "Failed to load font \"" << Filename << "\" (" << GetErrorDesc(Error) << ")" << std::endl; return false; } // Create the bitmap font Error = CreateBitmapFont(FontFace, CharSize, Charset, LoadedFont); if (Error) std::cerr << "Failed to load font \"" << Filename << "\" (" << GetErrorDesc(Error) << ")" << std::endl; // Delete the font FT_Done_Face(FontFace); return Error == 0; }
//////////////////////////////////////////////////////////// /// Load the font from a file in memory //////////////////////////////////////////////////////////// bool FontLoader::LoadFontFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize, std::wstring Charset, Font& LoadedFont) { // Check if Freetype is correctly initialized if (!myLibrary) { std::cerr << "Failed to load font from memory, FreeType has not been initialized" << std::endl; return false; } // Create a new font face from the specified memory data FT_Face FontFace; FT_Error Error = FT_New_Memory_Face(myLibrary, reinterpret_cast<const FT_Byte*>(Data), static_cast<FT_Long>(SizeInBytes), 0, &FontFace); if (Error) { std::cerr << "Failed to load font from memory (" << GetErrorDesc(Error) << ")" << std::endl; return false; } // Create the bitmap font Error = CreateBitmapFont(FontFace, CharSize, Charset, LoadedFont); if (Error) std::cerr << "Failed to load font from memory (" << GetErrorDesc(Error) << ")" << std::endl; // Delete the font FT_Done_Face(FontFace); return Error == 0; }
void SupportProc::function_ErrorDesc(Inbound &inbound) { Net::PTPSupport::ErrorDescInput input; if( !inbound.getInput(input) ) return inbound.send_error(ptp); StrLen desc=GetErrorDesc(input.error_id); uint8 len=(uint8)Min(desc.len,Net::PTPSupport::ErrorDescOutput::MaxLen); Tailed<Net::PTPSupport::ErrorDescOutput> output(MutatePtr<const uint8>(desc.ptr),len); log("SupportErrorDesc(#;,#;,#;) : #;",input.service_id,input.function_id,input.error_id,desc); inbound.send_info(output,ptp); }
void CRUTask::HandlePredecessorFailure(CRUTask &task) { RUASSERT (0 != task.GetStatus()); // If there is already something wrong, don't touch me if (0 != this->GetStatus()) { return; } // The error's text will be printed only for the Refresh tasks. CRUException &ex = GetErrorDesc(); ex.SetError(IDS_RU_TASK_PREDECESSOR_PROBLEM); ex.AddArgument(this->GetTaskName()); ex.AddArgument(task.GetTaskName()); }
RpcGet RpcRequest::Execute() { if(!shouldExecute) return RpcGet(); shouldExecute = false; String request; if(json) { ContentType("application/json"); static Atomic id; Json json; json("jsonrpc", "2.0") ("method", method); if(data.out.GetCount()) { JsonArray a; for(int i = 0; i < data.out.GetCount(); i++) { const Value& v = data.out[i]; if(v.Is<RawJsonText>()) a.CatRaw(v.To<RawJsonText>().json); else a << JsonRpcData(v); } json("params", a); } else if(data.out_map.GetCount()) { Json m; for(int i = 0; i < data.out_map.GetCount(); i++) { const Value& v = data.out_map.GetValue(i); String key = (String)data.out_map.GetKey(i); if(v.Is<RawJsonText>()) m.CatRaw(key, v.To<RawJsonText>().json); else m(key, JsonRpcData(v)); } json("params", m); } json("id", id); AtomicInc(id); request = ~json; } else { ContentType("text/xml"); request = XmlHeader(); request << XmlTag("methodCall")(XmlTag("methodName")(method) + FormatXmlRpcParams(data.out)); } if(sLogRpcCalls) { if(sLogRpcCallsCompress) RLOG("=== XmlRpc call request:\n" << CompressLog(request)); else RLOG("=== XmlRpc call request:\n" << request); } String response; New(); if(shorted) response = RpcExecuteShorted(request); else response = Post(request).Execute(); if(sLogRpcCalls) { if(sLogRpcCallsCompress) RLOG("=== XmlRpc call response:\n" << CompressLog(response)); else RLOG("=== XmlRpc call response:\n" << response); } RpcGet h; if(IsNull(response)) { faultCode = RPC_CLIENT_HTTP_ERROR; faultString = GetErrorDesc(); error = "Http request failed: " + faultString; LLOG(error); h.v = ErrorValue(error); return h; } if(json) { try { Value r = ParseJSON(response); if(IsValueMap(r)) { ValueMap m = r; Value result = m["result"]; if(!result.IsVoid()) { data.in.Clear(); data.in.Add(result); data.ii = 0; h.v = result; return h; } Value e = m["error"]; if(IsValueMap(e)) { Value c = e["code"]; Value m = e["message"]; if(IsNumber(c) && IsString(m)) { faultCode = e["code"]; faultString = e["message"]; error.Clear(); error << "Failed '" << faultString << "' (" << faultCode << ')'; LLOG(s); h.v = ErrorValue(error); return h; } } } String s; faultString = "Invalid response"; faultCode = RPC_CLIENT_RESPONSE_ERROR; error = faultString; LLOG(error); h.v = ErrorValue(error); return h; } catch(CParser::Error e) { String s; faultString = e; faultCode = RPC_CLIENT_JSON_ERROR; error.Clear(); error << "JSON Error: " << faultString; LLOG(error); h.v = ErrorValue(error); return h; } } else { XmlParser p(response); try { p.ReadPI(); p.PassTag("methodResponse"); if(p.Tag("fault")) { Value m = ParseXmlRpcValue(p); if(IsValueMap(m)) { ValueMap mm = m; faultString = mm["faultString"]; faultCode = mm["faultCode"]; error.Clear(); error << "Failed '" << faultString << "' (" << faultCode << ')'; LLOG(s); h.v = ErrorValue(error); return h; } } else { data.in = ParseXmlRpcParams(p); data.ii = 0; p.PassEnd(); } } catch(XmlError e) { String s; faultString = e; faultCode = RPC_CLIENT_XML_ERROR; error.Clear(); error << "XML Error: " << faultString; LLOG(error << ": " << p.GetPtr()); h.v = ErrorValue(error); return h; } h.v = data.in.GetCount() ? data.in[0] : Null; return h; } }
bool Pop3::Login() { try { if(host.IsEmpty()) throw Exc(t_("Hostname is not specified.")); if(user.IsEmpty()) throw Exc(t_("Username is not specified.")); if(pass.IsEmpty()) throw Exc(t_("Password is nor specified.")); if(proxy_host.GetCount()) { String host_port = host; host_port << ':' << Nvl(port, ssl ? 995 : 110); String data; data << "CONNECT " << host_port << " HTTP/1.1\r\n" << "Host: " << host_port << "\r\n"; if(!IsNull(proxy_username)) data << "Proxy-Authorization: Basic " << Base64Encode(proxy_username + ':' + proxy_password) << "\r\n"; data << "\r\n"; LLOG("Trying to connect proxy " << proxy_host << ":" << proxy_port); if(!Connect(proxy_host, proxy_port)) throw Exc("Unable to connect the proxy"); LLOG("About to send proxy request:\n" << data); if(!PutAll(data)) throw Exc("Unable to send request to the proxy"); String response; for(;;) { String l = GetLine(); if(l.GetCount() == 0) break; LLOG("< " << l); if(response.GetCount() == 0) response = l; } LLOG("Proxy response: " << response); if(!response.StartsWith("HTTP") || response.Find(" 2") < 0) throw Exc("Invalid proxy reply: " + response); LLOG("Connected via proxy"); } else if(!Connect(host, Nvl(port, ssl ? 995 : 110))) throw Exc(GetErrorDesc()); LLOG(Format(t_("Opening connection to %s:%d."), host, port)); if(ssl) { if(!StartSSL()) throw Exc(t_("Couldn't start SSL session.")); LLOG(t_("SSL session successfully started.")); } // Receive server greetings. if(!PutGet(Null)) throw Exc(GetLastError()); if(!Authenticate()) throw Exc(GetLastError()); } catch (Exc e) { error = e; LLOG("-- " + e); Logout(); return false; } return online = true; }
BOOL InstallWorkerThread::Install() { // some preliminar checks before the real installation // --------------------------------------------------- m_pWnd->UpdateStatus( TEXT("Checking if it's possible to install the printer and the drivers")); BOOL bInstalled; if (!CheckPrinterInstalled(bInstalled, m_strPrinterName)) { m_pWnd->ErrorMessage( TEXT("Cannot check if a printer with the same name already exist!")); return FALSE; } if (bInstalled) { m_pWnd->ErrorMessage(TEXT("Printer name is already in use!")); return FALSE; } uint kDriver; PDRIVER_INFO_3 pinfoDrivers = NULL; if (!CheckPrinterDriverInstalled(pinfoDrivers, kDriver, emfDRIVER_NAME)) { m_pWnd->ErrorMessage( TEXT("Cannot check if a driver with the same name already exist!")); return FALSE; } if (pinfoDrivers != NULL) { free(pinfoDrivers); // we're not really intetested to them BOOL bYes = m_pWnd->YesNoMessage( TEXT("'%ws' drivers are already installed on your system.\n") TEXT("Press \"No\" to keep your current drivers.") TEXT("\n\nTo upgrade, close all applications using '%ws'") TEXT(" drivers and components, and then press \"Yes\"."), emfDRIVER_NAME, emfPRINTER_NAME); if (!bYes) return FALSE; } // we're ready to start the real installation! // ------------------------------------------- m_pWnd->UpdateStatus(TEXT("Installing EMF virtual printer as '%ws'..."), m_strPrinterName); if (!DoAllUninstall() || !DoAllInstall(m_strPrinterName, m_strSourceDir)) { LPTSTR pDesc = GetErrorDesc(g_lastError); TCHAR buf[1024]; StringCchPrintf( buf, 1024, TEXT("%ws\nInstallation aborted.\n\nError code: %d\nError description: %ws"), g_strInstallerError, g_lastError, pDesc); // show the message to the user m_pWnd->ErrorMessage(buf); //strFree(g_strInstallerError); //LocalFree(pDesc); return FALSE; } return TRUE; }