status_t RemoveRepositoryJob::Execute() { BPackageRoster roster; BRepositoryConfig repoConfig; status_t result = roster.GetRepositoryConfig(fRepositoryName, &repoConfig); if (result != B_OK) { if (result == B_ENTRY_NOT_FOUND) { BString error = BString("repository '") << fRepositoryName << "' not found!"; SetErrorString(error); } return result; } BString question = BString("Really remove the repository '") << fRepositoryName << "'?"; bool yes = fContext.DecisionProvider().YesNoDecisionNeeded("", question, "yes", "no", "no"); if (!yes) return B_CANCELED; BEntry repoConfigEntry = repoConfig.Entry(); if ((result = repoConfigEntry.Remove()) != B_OK) return result; BRepositoryCache repoCache; if (roster.GetRepositoryCache(fRepositoryName, &repoCache) == B_OK) { BEntry repoCacheEntry = repoCache.Entry(); if ((result = repoCacheEntry.Remove()) != B_OK) return result; } return B_OK; }
char* ERR_error_string(unsigned long errNumber, char* buffer) { static char* msg = (char*)"Please supply a buffer for error string"; if (buffer) { SetErrorString(YasslError(errNumber), buffer); return buffer; } return msg; }
/** Call the first suitable method refferenced by the VclMethod object. * Keyword arguments are not allowed as they cannot be mapped to arguemnts to a * VCL method. */ static PyObject *VclMethod_Call(TVclMethod* self, PyObject *args, PyObject *keywds) { try { if(keywds != NULL) return SetErrorString(PyExc_TypeError, self->Methods[0]->Name + "() does not accept keyword arguments"); return ToPyObject(CallMethod(NULL, self->Instance, self->Methods, args)); return ToPyObject(CallMethod(NULL, self->Object->Instance, self->Methods, args)); } catch(...) { return PyVclHandleException(); } }
/** Exception handling helper function. Called from a catch(...) section and converts an active * C++/Delphi exception to a Python exception. */ PyObject* PyVclHandleException() { try { throw; } catch(EListError &E) { SetErrorString(PyExc_IndexError, E.Message); } catch(Exception &E) { SetErrorString(PyVclException, E.Message); } catch(std::exception &E) { PyErr_SetString(PyVclException, E.what()); } catch(...) { PyErr_SetString(PyVclException, "Unknown exception"); } return NULL; }
/** Retrieve a type, function or global variable from the global vcl object. * The name is searched in this ordier: * 1. Check the cache if the object already exists and used it if it does. * Global variables as Application always exist here. * 2. Search for type in custom list of available types. * 3. Try to retrieve it as a registered class in Delphi. * 4. Try to create it as a global function. * At last the object is stored in the cache for fast retrievel next time. * A Python exception is thrown if no variable, type or function with the given name is found. * \return New reference */ static PyObject* GlobalVcl_GetAttro(PyObject *self, PyObject *attr_name) { try { PyObject *Result = PyObject_GenericGetAttr(self, attr_name); if(Result != NULL) return Result; PyErr_Clear(); String Name = PyUnicode_AsUnicode(attr_name); TRttiType *Type = Context.GetType(LookUpClass(Name)); if(Type == NULL) { TClass Class = GetClass(Name); if(Class) Type = Context.GetType(Class); } if(Type != NULL) { // if(Class->InheritsFrom(__classid(Exception))) Result = VclType_Create(Type); } else Result = VclFunction_Create(Name); if(Result == NULL) { SetErrorString(PyExc_AttributeError, "VCL has no global attribute '" + Name + "'"); return NULL; } PyObject_GenericSetAttr(self, attr_name, Result); return Result; } catch(...) { return PyVclHandleException(); } }
BOOL CFileTextLines::Load(const CString& sFilePath, int lengthHint /* = 0*/) { m_LineEndings = EOL_AUTOLINE; m_UnicodeType = CFileTextLines::AUTOTYPE; RemoveAll(); m_endings.clear(); if(lengthHint != 0) { Reserve(lengthHint); } if (PathIsDirectory(sFilePath)) { m_sErrorString.Format(IDS_ERR_FILE_NOTAFILE, (LPCTSTR)sFilePath); return FALSE; } if (!PathFileExists(sFilePath)) { //file does not exist, so just return SUCCESS return TRUE; } CAutoFile hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL); if (!hFile) { SetErrorString(); return FALSE; } LARGE_INTEGER fsize; if (!GetFileSizeEx(hFile, &fsize)) { SetErrorString(); return false; } if (fsize.HighPart) { // file is way too big for us m_sErrorString.LoadString(IDS_ERR_FILE_TOOBIG); return FALSE; } // If new[] was done for type T delete[] must be called on a pointer of type T*, // otherwise the behavior is undefined. // +1 is to address possible truncation when integer division is done wchar_t* pFileBuf = new wchar_t[fsize.LowPart/sizeof(wchar_t) + 1]; DWORD dwReadBytes = 0; if (!ReadFile(hFile, pFileBuf, fsize.LowPart, &dwReadBytes, NULL)) { delete [] pFileBuf; SetErrorString(); return FALSE; } if (m_UnicodeType == CFileTextLines::AUTOTYPE) { m_UnicodeType = this->CheckUnicodeType(pFileBuf, dwReadBytes); } if (m_LineEndings == EOL_AUTOLINE) { m_LineEndings = CheckLineEndings(pFileBuf, min(10000, dwReadBytes)); } hFile.CloseHandle(); if (m_UnicodeType == CFileTextLines::BINARY) { m_sErrorString.Format(IDS_ERR_FILE_BINARY, (LPCTSTR)sFilePath); delete [] pFileBuf; return FALSE; } // we may have to convert the file content if ((m_UnicodeType == UTF8)||(m_UnicodeType == UTF8BOM)) { int ret = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pFileBuf, dwReadBytes, NULL, 0); wchar_t * pWideBuf = new wchar_t[ret]; int ret2 = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pFileBuf, dwReadBytes, pWideBuf, ret); if (ret2 == ret) { delete [] pFileBuf; pFileBuf = pWideBuf; dwReadBytes = ret2; } else delete [] pWideBuf; } else if (m_UnicodeType == ASCII) { int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)pFileBuf, dwReadBytes, NULL, 0); wchar_t * pWideBuf = new wchar_t[ret]; int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)pFileBuf, dwReadBytes, pWideBuf, ret); if (ret2 == ret) { delete [] pFileBuf; pFileBuf = pWideBuf; dwReadBytes = ret2; } else delete [] pWideBuf; } // fill in the lines into the array wchar_t * pTextBuf = pFileBuf; wchar_t * pLineStart = pFileBuf; if (m_UnicodeType == UNICODE_LE) { // UTF16 have two bytes per char dwReadBytes/=2; } if ((m_UnicodeType == UTF8BOM)||(m_UnicodeType == UNICODE_LE)) { // ignore the BOM ++pTextBuf; ++pLineStart; --dwReadBytes; } for (DWORD i = 0; i<dwReadBytes; ++i) { if (*pTextBuf == '\r') { if ((i + 1) < dwReadBytes) { if (*(pTextBuf+1) == '\n') { // crlf line ending CString line(pLineStart, (int)(pTextBuf-pLineStart)); Add(line, EOL_CRLF); pLineStart = pTextBuf+2; ++pTextBuf; ++i; } else { // cr line ending CString line(pLineStart, (int)(pTextBuf-pLineStart)); Add(line, EOL_CR); pLineStart =pTextBuf+1; } } } else if (*pTextBuf == '\n') { // lf line ending CString line(pLineStart, (int)(pTextBuf-pLineStart)); Add(line, EOL_LF); pLineStart =pTextBuf+1; } ++pTextBuf; } if (pLineStart < pTextBuf) { CString line(pLineStart, (int)(pTextBuf-pLineStart)); Add(line, EOL_NOENDING); m_bReturnAtEnd = false; } else m_bReturnAtEnd = true; delete [] pFileBuf; return TRUE; }