wxTreeItemId CategoryTree::addTextEntry( const wxTreeItemId& p_parent, const DatIndexEntry& p_entry ) { wxTreeItemIdValue cookie; wxTreeItemId previous; auto child = this->GetFirstChild( p_parent, cookie ); while ( child.IsOk( ) ) { auto text = this->GetItemText( child ); // Compare if ( text > p_entry.name( ) ) { break; } // Move to next previous = child; child = this->GetNextChild( p_parent, cookie ); } // This item should be first if there *is* something in this list, but previous is nothing if ( child.IsOk( ) && !previous.IsOk( ) ) { return this->InsertItem( p_parent, 0, p_entry.name( ), this->getImageForEntry( p_entry ) ); } // This item should be squashed in if both child and previous are ok if ( child.IsOk( ) && previous.IsOk( ) ) { return this->InsertItem( p_parent, previous, p_entry.name( ), this->getImageForEntry( p_entry ) ); } // If the above fails, it means we went through the entire list without finding a proper spot return this->AppendItem( p_parent, p_entry.name( ), this->getImageForEntry( p_entry ) ); }
wxTreeItemId CategoryTree::addEntry( const wxTreeItemId& p_parent, const DatIndexEntry& p_entry ) { if ( p_entry.name( ).IsNumber( ) ) { ulong number; p_entry.name( ).ToULong( &number ); return this->addNumberEntry( p_parent, p_entry, number ); } // NaN :) return this->addTextEntry( p_parent, p_entry ); }
int CategoryTree::getImageForEntry( const DatIndexEntry& p_entry ) { switch ( p_entry.fileType( ) ) { case ANFT_ATEX: case ANFT_ATTX: case ANFT_ATEC: case ANFT_ATEP: case ANFT_ATEU: case ANFT_ATET: case ANFT_DDS: case ANFT_JPEG: case ANFT_WEBP: return CategoryTreeImageList::IT_Image; case ANFT_EXE: return CategoryTreeImageList::IT_Executable; case ANFT_DLL: return CategoryTreeImageList::IT_Dll; case ANFT_EULA: case ANFT_StringFile: return CategoryTreeImageList::IT_Text; case ANFT_Bank: case ANFT_Sound: case ANFT_ID3: return CategoryTreeImageList::IT_Sound; case ANFT_FontFile: return CategoryTreeImageList::IT_Font; case ANFT_Bink2Video: return CategoryTreeImageList::IT_Video; default: return CategoryTreeImageList::IT_UnknownFile; } }
bool PreviewPanel::previewFile( DatFile& p_datFile, const DatIndexEntry& p_entry ) { auto entryData = p_datFile.readFile( p_entry.mftEntry( ) ); if ( !entryData.GetSize( ) ) { return false; } // Create file reader auto reader = FileReader::readerForData( entryData, p_datFile, p_entry.fileType( ) ); if ( reader ) { if ( m_currentView ) { // Check if we can re-use the current viewer if ( m_currentDataType == reader->dataType( ) ) { m_currentView->setReader( reader ); return true; } // Destroy the old viewer if ( m_currentView ) { this->GetSizer( )->Remove( 0 ); m_currentView->Destroy( ); } } m_currentView = this->createViewerForDataType( reader->dataType( ), p_datFile ); if ( m_currentView ) { // Workaround for wxWidgets fuckups this->GetSizer( )->Add( m_currentView, wxSizerFlags( ).Expand( ).Proportion( 1 ) ); this->GetSizer( )->Layout( ); this->GetSizer( )->Fit( this ); // Set the reader m_currentView->setReader( reader ); m_currentDataType = reader->dataType( ); return true; } } return false; }
void CategoryTree::addEntry( const DatIndexEntry& p_entry ) { auto category = this->ensureHasCategory( *p_entry.category( ) ); if ( category.IsOk( ) ) { if ( this->IsExpanded( category ) ) { auto node = this->addEntry( category, p_entry ); this->SetItemData( node, new CategoryTreeItem( CategoryTreeItem::DT_Entry, &p_entry ) ); } else { auto itemData = static_cast<CategoryTreeItem*>( this->GetItemData( category ) ); if ( itemData->dataType( ) != CategoryTreeItem::DT_Category ) { return; } itemData->setDirty( true ); } } }