EvilNumber EvilNumber::_SelfDivide( const EvilNumber & val ) { if (val.mType == mType) { if (mType == evil_number_float) { this->mValue.fVal = this->mValue.fVal / val.mValue.fVal; } else if (mType == evil_number_int) { // make sure we can do things like 2 / 4 = 0.5f this->mValue.fVal = double(this->mValue.iVal) / double(val.mValue.iVal); mType = evil_number_float; // check if its possibly a integer CheckIntegrity(); } } else { // we assume that the val argument is the opposite of the 'this' type if (mType == evil_number_float) { this->mValue.fVal = this->mValue.fVal / double(val.mValue.iVal); } else if (mType == evil_number_int) { double tVal = (double)mValue.iVal; // normal integer number this->mValue.fVal = tVal / val.mValue.fVal; mType = evil_number_float; } else { assert(false); // crash } // check if we are a integer CheckIntegrity(); } return *this; }
/* public ZBasicString<A>::Resize Resizes this string. If the string size is shrunk, removes the excess characters. If the string size is grown, the provided character is appended that many times. Will allocate storage if necessary. @param _newSize - the new size of this string @param _value - the value to append if size increases @return (void) */ void Resize(size_t _newSize, const char& _value) { StringArray.PopBack(); //Remove null terminator StringArray.Resize(_newSize + 1, _value); //Include room to replace the null terminator StringArray.At(this->Length()) = ZBASICSTRING_NULL_TERMINATOR; CheckIntegrity(); }
/* Default constructor. Constructs an empty string. */ ZBasicString() : StringArray(ZBASICSTRING_DEFAULT_CAPACITY + 1) { //Make sure we have our null terminator StringArray.PushBack(ZBASICSTRING_NULL_TERMINATOR); CheckIntegrity(); }
/* Parameterized constructor. Constructs an empty string with the specified capacity (not including the null terminator). */ explicit ZBasicString(size_t _capacity) : StringArray(_capacity + 1) { //Make sure we have our null terminator StringArray.PushBack(ZBASICSTRING_NULL_TERMINATOR); CheckIntegrity(); }
EvilNumber EvilNumber::_SelfSubtract( const EvilNumber & val ) { if (val.mType == mType) { if (mType == evil_number_float) { this->mValue.fVal = this->mValue.fVal - val.mValue.fVal; } else if (mType == evil_number_int) { this->mValue.iVal = this->mValue.iVal - val.mValue.iVal; } } else { // we assume that the val argument is the opposite of the 'this' type if (mType == evil_number_float) { this->mValue.fVal = this->mValue.fVal - double(val.mValue.iVal); } else if (mType == evil_number_int) { double tVal = (double)mValue.iVal; // normal integer number this->mValue.fVal = tVal - val.mValue.fVal; mType = evil_number_float; } else { assert(false); // crash } // check if we are a integer CheckIntegrity(); } return *this; }
EvilNumber EvilNumber::_SelfModulus( const EvilNumber & val ) { if (val.mType == mType) { if (mType == evil_number_float) { this->mValue.iVal = (int64)(this->mValue.fVal) % (int64)(val.mValue.fVal); mType = evil_number_int; } else if (mType == evil_number_int) { this->mValue.iVal = this->mValue.iVal % val.mValue.iVal; mType = evil_number_int; } } else { // we assume that the val argument is the opposite of the 'this' type if (mType == evil_number_float) { this->mValue.iVal = (int64)(this->mValue.fVal) % val.mValue.iVal; mType = evil_number_int; } else if (mType == evil_number_int) { this->mValue.iVal = this->mValue.iVal % (int64)(val.mValue.fVal); mType = evil_number_int; } else { assert(false); // crash } // check if we are a integer CheckIntegrity(); } return *this; }
void BProcess::PushLooper(SLooper* looper) { m_lock.LockQuick(); //printf("Pushing looper %p, top is %p\n", looper, m_idleLooper); #if CHECK_INTEGRITY ErrFatalErrorIf(looper->GetNext()!= NULL, "Pushing a looper with non-NULL next!"); // Check that looper isn't already on stack. SLooper* pos = m_idleLooper; while (pos) { ErrFatalErrorIf(pos == looper, "Looper pushed on idle stack twice!"); pos = pos->GetNext(); } #endif if (m_idleLooper) { looper->SetNext(m_idleLooper); m_idleLooper = looper; } else { ErrFatalErrorIf(looper->GetNext() != NULL, "Pushing looper with non-NULL next!"); m_idleLooper = looper; } m_idleCount++; CheckIntegrity(); m_lock.Unlock(); }
BOOL Octree::Index(RGBQUAD * Palette, OctreeElement * pEl) { CheckIntegrity(); if (!pEl) { pEl=pTopElement; CurrentIndex=0; if (!pEl) return TRUE; // for we have done } if (pEl->Pixels) { if (CurrentIndex>=MaxLeaves) { ERROR3("CurrentIndex>=MaxLeaves in Octree::Index"); CurrentIndex=0; } pEl->Index=CurrentIndex; Palette[CurrentIndex].rgbRed=(BYTE)(pEl->R); Palette[CurrentIndex].rgbGreen=(BYTE)(pEl->G); Palette[CurrentIndex].rgbBlue=(BYTE)(pEl->B); CurrentIndex++; } else { pEl->Index=-1; } for (INT32 c=0; c<8; c++) if (pEl->pChildren[c]) if (!Index(Palette, pEl->pChildren[c])) return FALSE; return TRUE; }
ZBasicString(const ZBasicString<B>& _other, size_t _start, size_t _end) : StringArray(_other.Array(), _start, _end) { if (_start == _end || StringArray.Back() != ZBASICSTRING_NULL_TERMINATOR) StringArray.PushBack(ZBASICSTRING_NULL_TERMINATOR); CheckIntegrity(); }
/* public ZBasicString<A>::Insert Insert function. Inserts a string into this string. @param _index - index to insert at @param _other - string to insert @return (void) @assert - if index is invalid */ void Insert(const size_t _index, const ZBasicString<A>& _other) { size_t index = BoundsCheck(_index, Length() + 1); StringArray.Insert(index, _other.Array(), 0, _other.Length()); CheckIntegrity(); }
/* Parameterized constructor. This constructor will initialize a copy of the provided string, but it will only copy in as many characters as defined. The null terminator at the end is not required. If a null terminator is present before the end of the string, the string will be shortened such that the first encountered null terminator is at the end of the string. @param _string - the string to initialize to @param _count - the number of chars in the string */ ZBasicString(const char *_string, const size_t _count) : StringArray(_string, _count, _count + 1) { StringArray.PushBack(ZBASICSTRING_NULL_TERMINATOR); StringArray.Resize(strlen(StringArray.Data()) + 1); CheckIntegrity(); }
/* public ZBasicString<A>::Insert Insert function. Inserts a character into this string. @param _index - index to insert at @param _char - character to insert @return (void) @assert - if index is invalid */ void Insert(const size_t _index, const char& _char) { size_t index = BoundsCheck(_index, Length() + 1); StringArray.Insert(index, _char); CheckIntegrity(); }
explicit ZBasicString(const ZArray<char, B>& _array) : StringArray(_array.Data(), _array.Size(), _array.Capacity() + 1) { StringArray.PushBack(ZBASICSTRING_NULL_TERMINATOR); StringArray.Resize(strlen(StringArray.Data()) + 1); CheckIntegrity(); }
bool BProcess::PopLooper(SLooper* looper, nsecs_t when) { bool poped = false; bool spawnLooper = false; // Only remove a 'looper' if the looper is at the top of the stack and // if the 'when' is greater than the next event time and if there are // more than one looper to handle incoming messages. m_lock.LockQuick(); //printf("PopLooper %p: top=%p, when=%Ld, nextTime=%Ld, count=%d\n", // looper, m_idleLooper, when, m_nextEventTime, m_idleCount); CheckIntegrity(); if (m_idleLooper && (looper == m_idleLooper) && (when >= m_nextEventTime) && (m_idleCount > 1)) { SLooper* pop = m_idleLooper; m_idleLooper = m_idleLooper->GetNext(); pop->SetNext(NULL); m_idleCount--; poped = true; } nsecs_t nextTime = m_pendingHandlers ? m_pendingHandlers->NextMessageTime(NULL) : B_INFINITE_TIMEOUT; if ((m_idleCount == 1 || m_loopers < m_minLoopers) && (m_loopers < m_maxLoopers) && (approx_SysGetRunTime() >= nextTime)) { status_t status = SLooper::SpawnLooper(); if (status == B_OK) { IncrementLoopers(); //bout << "Just called SLooper::SpawnLooper! status = " << strerror(status) << endl; } } CheckIntegrity(); m_lock.Unlock(); // We have to have at least one looper around to accept transactions // from remote teams. Otherwise system go boom boom! Do not lock // while making a call to SpawnLooper!!! return poped; }
/* Parameterized constructor. This constructor will initialize a copy of the provided null-terminated string. @param _string - the null-terminated string to initialize to */ ZBasicString(const char *_string) : StringArray( _string != NULL ? strlen(_string) + 1 : 1) { //Set the string array size equal to the starting capacity, copy, and set null terminator StringArray.Resize(StringArray.Capacity()); memmove(StringArray.Data(), _string, Length() * sizeof(char)); StringArray.Data()[Length()] = ZBASICSTRING_NULL_TERMINATOR; CheckIntegrity(); }
/* public ZBasicString<A>::Erase Erase function. Erases characters between the given indices. @param _start - the starting index @param __end - the ending index index (exclusive) @return (void) @assert - if _start or _end out of bounds if _end < _start */ void Erase(const size_t _start, const size_t _end) { if (_start == _end) return; size_t start = BoundsCheck(_start, Length()); size_t end = BoundsCheck(_end, Length() + 1); #if !ZSTL_DISABLE_RUNTIME_CHECKS ZSTL_ASSERT(start <= end, "ZBasicString: Cannot erase with _end < _start!"); #endif StringArray.Erase(start, end); CheckIntegrity(); }
SLooper* BProcess::UnsafePopLooper() { SLooper* pop = m_idleLooper; if (pop != NULL) { m_idleLooper = m_idleLooper->GetNext(); pop->SetNext(NULL); m_idleCount--; } CheckIntegrity(); //printf("Unsafe popping looper %p\n", pop); return pop; }
// ****************************************************************** // * CxbxRtlFreeDebug - Debug track RTL free // ****************************************************************** BOOL CxbxRtlFreeDebug(HANDLE Heap, DWORD Flags, PVOID pMem, char *pFile, int Line) { BOOL Ret = FALSE; if (pMem == NULL) { return TRUE; } g_MemoryMutex.Lock(); CXBX_MEMORY_BLOCK *pFree = RemoveMemoryBlock(pMem); if(pFree == NULL) { printf("CxbxRtlFreeDebug: free on non-existent block: 0x%.08X! " "Possibly a multiple free.\n" " File: %s\n" " Line: %d\n", pMem, pFile, Line); } else { if(!CheckIntegrity(pFree)) { printf("CxbxRtlFreeDebug: Free on damaged block\n" " Block : 0x.%08X\n" " Allocation\n" " File: %s\n" " Line: %d\n" " Free\n" " File: %s\n" " Line: %d\n", pFree->pMem, pFree->pFile, pFree->Line, pFile, Line); } Ret = NtDll::RtlFreeHeap(Heap, Flags, GetMemStart(pFree)); free(pFree->pFile); free(pFree); } g_MemoryMutex.Unlock(); return Ret; }
// ****************************************************************** // * CxbxFreeDebug - Debug track free // ****************************************************************** void CxbxFreeDebug(void *pMem, char *pFile, int Line) { if (pMem == NULL) { return; } g_MemoryMutex.Lock(); CXBX_MEMORY_BLOCK *pFree = RemoveMemoryBlock(pMem); if(pFree == NULL) { printf("CxbxFreeDebug: free on non-existent block: 0x%.08X! " "Possibly a multiple free.\n" " File: %s\n" " Line: %d\n", pMem, pFile, Line); } else { if(!CheckIntegrity(pFree)) { printf("CxbxFreeDebug: Free on damaged block\n" " Block : 0x.%08X\n" " Allocation\n" " File: %s\n" " Line: %d\n" " Free\n" " File: %s\n" " Line: %d\n", pFree->pMem, pFree->pFile, pFree->Line, pFile, Line); } free(GetMemStart(pFree)); free(pFree->pFile); free(pFree); } g_MemoryMutex.Unlock(); }
// ****************************************************************** // * CxbxAllocDump - Dump the memory allocations // ****************************************************************** void CxbxAllocDump(bool DumpData) { g_MemoryMutex.Lock(); CXBX_MEMORY_BLOCK *pCur; printf("******************************************************\n" "* Dumping memory allocations *\n" "******************************************************\n"); for(pCur = g_pFirstBlock; pCur; pCur = pCur->pNext) { printf("\n" " Block: 0x%.08X\n" " Size : %d\n" " File : %s\n" " Line : %d\n" " Type : %s\n", pCur->pMem, pCur->Size, pCur->pFile, pCur->Line, pCur->Type == CXBX_ALLOC_NORMAL ? "NORMAL" : "RTL"); CheckIntegrity(pCur); } g_MemoryMutex.Unlock(); }
bool BProcess::RemoveLooper(SLooper* looper) { bool removed = false; m_lock.LockQuick(); if (m_shutdown || (m_loopers > m_minLoopers && m_idleLooper)) { // This looper is allowed to exit. removed = true; DecrementLoopers(); SLooper* prev = NULL; SLooper* pos = m_idleLooper; while (pos != NULL && pos != looper) { prev = pos; pos = pos->GetNext(); } // remove references to the looper if it is on the idle list. if (pos) { if (prev) prev->SetNext(pos->GetNext()); else m_idleLooper = pos->GetNext(); pos->SetNext(NULL); m_idleCount--; } } CheckIntegrity(); m_lock.Unlock(); return removed; }
// Refresh the projects list. bool WorkspaceInfo::Refresh(void) { // If the internal project integrity is good, then no refresh is needed. if (CheckIntegrity()) return true; // Delete everything. RemoveAll(); // First, get a pointer to the dispatch for the Projects collection CComPtr<IDispatch> pDispProjects; VERIFY_OK(m_pApplication->get_Projects(&pDispProjects)); CComQIPtr<IProjects, &IID_IProjects> pProjects(pDispProjects); // Get the number of projects in the collection long projectCount; VERIFY_OK(pProjects->get_Count(&projectCount)); // Iterate all the projects. for (long i = 1; i < projectCount + 1; i++) { CComVariant Vari = i; // Get the next project CComPtr<IGenericProject> pGenProject; VERIFY_OK(pProjects->Item(Vari, &pGenProject)); CComQIPtr<IGenericProject, &IID_IGenericProject> pProject(pGenProject); // Get the project name. CComBSTR bszStr; VERIFY_OK(pProject->get_FullName(&bszStr)); CString projectName = bszStr; Add(projectName); } // Rename a misnamed add-on file. CString oldFilename = m_workspaceLocation + "ExtraFiles.PFO"; CString wuFilename = GetExtraFilename(); rename(oldFilename, wuFilename); // Is there an add-on file? CStdioFile file; if (file.Open(wuFilename, CFile::modeRead) == TRUE) { CString line; // Count the number of extra projects. while (1) { // Read in a project name. if (!file.ReadString(line)) break; // Check the integrity. Add(line); } // Close the file. file.Close(); } // Build the file array. m_fileList.Sort(); // Rebuilt stuff. return false; }
void FilesystemWidget::ShowContextMenu(const QPoint&) { auto* selection = m_tree_view->selectionModel(); if (!selection->hasSelection()) return; auto* item = m_tree_model->itemFromIndex(selection->selectedIndexes()[0]); QMenu* menu = new QMenu(this); EntryType type = item->data(ENTRY_TYPE).value<EntryType>(); DiscIO::Partition partition = type == EntryType::Disc ? DiscIO::PARTITION_NONE : GetPartitionFromID(item->data(ENTRY_PARTITION).toInt()); QString path = item->data(ENTRY_NAME).toString(); const bool is_filesystem_root = (type == EntryType::Disc && m_volume->GetPartitions().empty()) || type == EntryType::Partition; if (type == EntryType::Dir || is_filesystem_root) { AddAction(menu, tr("Extract Files..."), this, [this, partition, path] { auto folder = SelectFolder(); if (!folder.isEmpty()) ExtractDirectory(partition, path, folder); }); } if (is_filesystem_root) { AddAction(menu, tr("Extract System Data..."), this, [this, partition] { auto folder = SelectFolder(); if (folder.isEmpty()) return; if (ExtractSystemData(partition, folder)) QMessageBox::information(nullptr, tr("Success"), tr("Successfully extracted system data.")); else QMessageBox::critical(nullptr, tr("Error"), tr("Failed to extract system data.")); }); } switch (type) { case EntryType::Disc: AddAction(menu, tr("Extract Entire Disc..."), this, [this, path] { auto folder = SelectFolder(); if (folder.isEmpty()) return; if (m_volume->GetPartitions().empty()) { ExtractPartition(DiscIO::PARTITION_NONE, folder); } else { for (DiscIO::Partition& p : m_volume->GetPartitions()) { if (const std::optional<u32> partition_type = m_volume->GetPartitionType(p)) { const std::string partition_name = DiscIO::DirectoryNameForPartitionType(*partition_type); ExtractPartition(p, folder + QChar(u'/') + QString::fromStdString(partition_name)); } } } }); break; case EntryType::Partition: AddAction(menu, tr("Extract Entire Partition..."), this, [this, partition] { auto folder = SelectFolder(); if (!folder.isEmpty()) ExtractPartition(partition, folder); }); if (m_volume->IsEncryptedAndHashed()) { menu->addSeparator(); AddAction(menu, tr("Check Partition Integrity"), this, [this, partition] { CheckIntegrity(partition); }); } break; case EntryType::File: AddAction(menu, tr("Extract File..."), this, [this, partition, path] { auto dest = QFileDialog::getSaveFileName(this, tr("Save File to")); if (!dest.isEmpty()) ExtractFile(partition, path, dest); }); break; case EntryType::Dir: // Handled above the switch statement break; } menu->exec(QCursor::pos()); }
void Swap(ZBasicString<B>& _other) { StringArray.Swap(_other.StringArray); CheckIntegrity(); }
ZBasicString(const ZBasicString<B>& _other) : StringArray(_other.Array()) { CheckIntegrity(); }
// ****************************************************************** // * CxbxRtlReallocDebug - Debug track RTL realloc // ****************************************************************** void *CxbxRtlReallocDebug(HANDLE Heap, DWORD Flags, PVOID pMem, SIZE_T Bytes, char *pFile, int Line) { void *pRetMem = NULL; g_MemoryMutex.Lock(); CXBX_MEMORY_BLOCK *pRealloc = FindMemoryBlock(pMem); if(pRealloc == NULL) { printf("CxbxRtlRealloc: realloc on non-existent block: 0x%.08X! " " File: %s\n" " Line: %d\n", pMem, pFile, Line); } else { if(!CheckIntegrity(pRealloc)) { printf("CxbxRtlReallocDebug: Realloc on damaged block\n" " Block : 0x.%08X\n" " Allocation\n" " Size: %d\n" " File: %s\n" " Line: %d\n" " Reallocation\n" " Size: %d\n" " File: %s\n" " Line: %d\n", pRealloc->pMem, pRealloc->pFile, pRealloc->Size, pRealloc->Line, Bytes, pFile, Line); } void *pNewMem = NtDll::RtlReAllocateHeap(Heap, Flags, GetMemStart(pRealloc), Bytes + 2 * sizeof(MEMORY_GUARD)); free(pRealloc->pFile); free(pRealloc); if(!pNewMem) { printf("CxbxRtlReallocDebug: Reallocation failed\n" " Heap : 0x%.08X\n" " Flags : 0x%.08X\n" " pMem : 0x%.08X\n" " Bytes : %d\n" " File : %s\n" " Line : %d\n", Heap, Flags, pMem, Bytes, pFile, Line); } else { CXBX_MEMORY_BLOCK *pBlock = InsertMemoryBlock(pNewMem, Bytes, pFile, Line, CXBX_ALLOC_RTL); pRetMem = pBlock->pMem; } } g_MemoryMutex.Unlock(); return pRetMem; }
/* Destructor. */ ~ZBasicString() { CheckIntegrity(); }