diff --git a/3d-viewer/3d_cache/3d_cache.cpp b/3d-viewer/3d_cache/3d_cache.cpp index 768f6c20c3..f8247ad004 100644 --- a/3d-viewer/3d_cache/3d_cache.cpp +++ b/3d-viewer/3d_cache/3d_cache.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include @@ -195,8 +196,18 @@ S3D_CACHE::S3D_CACHE() S3D_CACHE::~S3D_CACHE() { + COMMON_SETTINGS* commonSettings = Pgm().GetCommonSettings(); + FlushCache(); + // We'll delete ".3dc" cache files older than this many days + int clearCacheInterval = commonSettings->m_System.clear_3d_cache_interval; + + // An interval of zero means the user doesn't want to ever clear the cache + + if( clearCacheInterval > 0 ) + CleanCacheDir( clearCacheInterval ); + delete m_FNResolver; delete m_Plugins; } @@ -677,6 +688,46 @@ S3DMODEL* S3D_CACHE::GetModel( const wxString& aModelFileName ) return mp; } +void S3D_CACHE::CleanCacheDir( int aNumDaysOld ) +{ + wxDir dir; + wxString fileSpec = wxT( "*.3dc" ); + wxArrayString fileList; // Holds list of ".3dc" files found in cache directory + size_t numFilesFound = 0; + + wxFileName thisFile; + wxDateTime lastAccess, thresholdDate; + wxDateSpan durationInDays; + + // Calc the threshold date above which we delete cache files + durationInDays.SetDays( aNumDaysOld ); + thresholdDate = wxDateTime::Now() - durationInDays; + + // If the cache directory can be found and opened, then we'll try and clean it up + if( dir.Open( m_CacheDir ) ) + { + thisFile.SetPath( m_CacheDir ); // Set the base path to the cache folder + + // Get a list of all the ".3dc" files in the cache directory + numFilesFound = dir.GetAllFiles( m_CacheDir, &fileList, fileSpec ); + + for( unsigned int i = 0; i < numFilesFound; i++ ) + { + // Completes path to specific file so we can get its "last access" date + thisFile.SetFullName( fileList[i] ); + + // Only get "last access" time to compare against. Don't need the other 2 timestamps. + if( thisFile.GetTimes( &lastAccess, nullptr, nullptr ) ) + { + if( lastAccess.IsEarlierThan( thresholdDate ) ) + { + // This file is older than the threshold so delete it + wxRemoveFile( thisFile.GetFullPath() ); + } + } + } + } +} S3D_CACHE* PROJECT::Get3DCacheManager( bool aUpdateProjDir ) { diff --git a/3d-viewer/3d_cache/3d_cache.h b/3d-viewer/3d_cache/3d_cache.h index d59f3964e1..926a33f562 100644 --- a/3d-viewer/3d_cache/3d_cache.h +++ b/3d-viewer/3d_cache/3d_cache.h @@ -183,6 +183,16 @@ public: * @return is a pointer to the render data or NULL if not available */ S3DMODEL* GetModel( const wxString& aModelFileName ); + + /** + * Function Delete up old cache files in cache directory + * + * Deletes ".3dc" files in the cache directory that are older than + * "aNumDaysOld". + * + * @param aNumDaysOld is age threshold to delete ".3dc" cache files + */ + void CleanCacheDir( int aNumDaysOld ); }; #endif // CACHE_3D_H diff --git a/common/dialogs/panel_common_settings.cpp b/common/dialogs/panel_common_settings.cpp index d69a2590ac..b9db7dbfe7 100644 --- a/common/dialogs/panel_common_settings.cpp +++ b/common/dialogs/panel_common_settings.cpp @@ -101,6 +101,7 @@ bool PANEL_COMMON_SETTINGS::TransferDataFromWindow() commonSettings->m_System.autosave_interval = m_SaveTime->GetValue() * 60; commonSettings->m_System.file_history_size = m_fileHistorySize->GetValue(); + commonSettings->m_System.clear_3d_cache_interval = m_Clear3DCacheFilesOlder->GetValue(); commonSettings->m_Graphics.opengl_aa_mode = m_antialiasing->GetSelection(); commonSettings->m_Graphics.cairo_aa_mode = m_antialiasingFallback->GetSelection(); @@ -167,6 +168,8 @@ void PANEL_COMMON_SETTINGS::applySettingsToPanel( COMMON_SETTINGS& aSettings ) m_antialiasing->SetSelection( aSettings.m_Graphics.opengl_aa_mode ); m_antialiasingFallback->SetSelection( aSettings.m_Graphics.cairo_aa_mode ); + m_Clear3DCacheFilesOlder->SetValue( aSettings.m_System.clear_3d_cache_interval ); + int icon_scale_fourths = aSettings.m_Appearance.icon_scale; if( icon_scale_fourths <= 0 ) diff --git a/common/dialogs/panel_common_settings_base.cpp b/common/dialogs/panel_common_settings_base.cpp index a9899db7b8..986a205c46 100644 --- a/common/dialogs/panel_common_settings_base.cpp +++ b/common/dialogs/panel_common_settings_base.cpp @@ -50,27 +50,46 @@ PANEL_COMMON_SETTINGS_BASE::PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWind m_fileHistorySize = new wxSpinCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 100, 0 ); gbSizer1->Add( m_fileHistorySize, wxGBPosition( 1, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + wxBoxSizer* bSizer5; + bSizer5 = new wxBoxSizer( wxHORIZONTAL ); + + m_Clear3DCacheFilesOlder = new wxSpinCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 120, 30 ); + m_Clear3DCacheFilesOlder->SetToolTip( _("3D cache files older than this are deleted.\nIf set to 0, cache clearing is disabled") ); + + bSizer5->Add( m_Clear3DCacheFilesOlder, 0, wxALIGN_CENTER_VERTICAL, 5 ); + + m_staticTextDays = new wxStaticText( this, wxID_ANY, _("Days"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextDays->Wrap( -1 ); + bSizer5->Add( m_staticTextDays, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 ); + + + gbSizer1->Add( bSizer5, wxGBPosition( 2, 1 ), wxGBSpan( 1, 1 ), wxEXPAND, 5 ); + wxStaticText* antialiasingLabel; antialiasingLabel = new wxStaticText( this, wxID_ANY, _("Accelerated graphics:"), wxDefaultPosition, wxDefaultSize, 0 ); antialiasingLabel->Wrap( -1 ); - gbSizer1->Add( antialiasingLabel, wxGBPosition( 3, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + gbSizer1->Add( antialiasingLabel, wxGBPosition( 4, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); wxString m_antialiasingChoices[] = { _("No Antialiasing"), _("Subpixel Antialiasing (High Quality)"), _("Subpixel Antialiasing (Ultra Quality)"), _("Supersampling (2x)"), _("Supersampling (4x)") }; int m_antialiasingNChoices = sizeof( m_antialiasingChoices ) / sizeof( wxString ); m_antialiasing = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_antialiasingNChoices, m_antialiasingChoices, 0 ); m_antialiasing->SetSelection( 0 ); - gbSizer1->Add( m_antialiasing, wxGBPosition( 3, 1 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); + gbSizer1->Add( m_antialiasing, wxGBPosition( 4, 1 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); wxStaticText* antialiasingLabel1; antialiasingLabel1 = new wxStaticText( this, wxID_ANY, _("Fallback graphics:"), wxDefaultPosition, wxDefaultSize, 0 ); antialiasingLabel1->Wrap( -1 ); - gbSizer1->Add( antialiasingLabel1, wxGBPosition( 4, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + gbSizer1->Add( antialiasingLabel1, wxGBPosition( 6, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); wxString m_antialiasingFallbackChoices[] = { _("No Antialiasing"), _("Fast Antialiasing"), _("Balanced Antialiasing"), _("High Quality Antialiasing") }; int m_antialiasingFallbackNChoices = sizeof( m_antialiasingFallbackChoices ) / sizeof( wxString ); m_antialiasingFallback = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_antialiasingFallbackNChoices, m_antialiasingFallbackChoices, 0 ); m_antialiasingFallback->SetSelection( 0 ); - gbSizer1->Add( m_antialiasingFallback, wxGBPosition( 4, 1 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); + gbSizer1->Add( m_antialiasingFallback, wxGBPosition( 6, 1 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); + + m_staticTextClear3DCache = new wxStaticText( this, wxID_ANY, _("3D cache file duration:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextClear3DCache->Wrap( -1 ); + gbSizer1->Add( m_staticTextClear3DCache, wxGBPosition( 2, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxTOP, 5 ); gbSizer1->AddGrowableCol( 1 ); @@ -265,7 +284,6 @@ PANEL_COMMON_SETTINGS_BASE::PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWind this->SetSizer( bPanelSizer ); this->Layout(); - bPanelSizer->Fit( this ); // Connect Events m_textEditorBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_COMMON_SETTINGS_BASE::OnTextEditorClick ), NULL, this ); diff --git a/common/dialogs/panel_common_settings_base.fbp b/common/dialogs/panel_common_settings_base.fbp index e70287a1be..71093ecd6d 100644 --- a/common/dialogs/panel_common_settings_base.fbp +++ b/common/dialogs/panel_common_settings_base.fbp @@ -43,7 +43,7 @@ PANEL_COMMON_SETTINGS_BASE - -1,-1 + 838,485 RESETTABLE_PANEL; widgets/resettable_panel.h; Not forward_declare @@ -408,12 +408,149 @@ + + 5 + 1 + 1 + wxEXPAND + 2 + 1 + + + bSizer5 + wxHORIZONTAL + none + + 5 + wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + 30 + 120 + + 0 + + 0 + + 0 + + 1 + m_Clear3DCacheFilesOlder + 1 + + + protected + 1 + + Resizable + 1 + + wxSP_ARROW_KEYS + ; ; forward_declare + 0 + 3D cache files older than this are deleted. If set to 0, cache clearing is disabled + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Days + 0 + + 0 + + + 0 + + 1 + m_staticTextDays + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 1 0 wxALIGN_CENTER_VERTICAL - 3 + 4 1 1 @@ -477,7 +614,7 @@ 2 1 wxALIGN_CENTER_VERTICAL|wxEXPAND - 3 + 4 1 1 @@ -544,7 +681,7 @@ 1 0 wxALIGN_CENTER_VERTICAL - 4 + 6 1 1 @@ -608,7 +745,7 @@ 2 1 wxALIGN_CENTER_VERTICAL|wxEXPAND - 4 + 6 1 1 @@ -670,6 +807,70 @@ + + 5 + 1 + 0 + wxALIGN_CENTER_VERTICAL|wxTOP + 2 + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + 3D cache file duration: + 0 + + 0 + + + 0 + + 1 + m_staticTextClear3DCache + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + diff --git a/common/dialogs/panel_common_settings_base.h b/common/dialogs/panel_common_settings_base.h index aa8ee0a5ae..023129b6b9 100644 --- a/common/dialogs/panel_common_settings_base.h +++ b/common/dialogs/panel_common_settings_base.h @@ -48,8 +48,11 @@ class PANEL_COMMON_SETTINGS_BASE : public RESETTABLE_PANEL wxSpinCtrl* m_SaveTime; wxStaticText* m_staticTextFileHistorySize; wxSpinCtrl* m_fileHistorySize; + wxSpinCtrl* m_Clear3DCacheFilesOlder; + wxStaticText* m_staticTextDays; wxChoice* m_antialiasing; wxChoice* m_antialiasingFallback; + wxStaticText* m_staticTextClear3DCache; wxTextCtrl* m_textEditorPath; wxBitmapButton* m_textEditorBtn; wxRadioButton* m_defaultPDFViewer; @@ -90,7 +93,7 @@ class PANEL_COMMON_SETTINGS_BASE : public RESETTABLE_PANEL public: - PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 838,485 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); ~PANEL_COMMON_SETTINGS_BASE(); }; diff --git a/common/settings/common_settings.cpp b/common/settings/common_settings.cpp index b793c23e82..a6ca18dabc 100644 --- a/common/settings/common_settings.cpp +++ b/common/settings/common_settings.cpp @@ -172,6 +172,10 @@ COMMON_SETTINGS::COMMON_SETTINGS() : m_params.emplace_back( new PARAM( "system.working_dir", &m_System.working_dir, "" ) ); + + m_params.emplace_back( new PARAM( "system.clear_3d_cache_interval", + &m_System.clear_3d_cache_interval, 30 ) ); + } diff --git a/include/settings/common_settings.h b/include/settings/common_settings.h index 729fd286ad..5bcbb746c0 100644 --- a/include/settings/common_settings.h +++ b/include/settings/common_settings.h @@ -89,6 +89,7 @@ public: wxString pdf_viewer_name; bool use_system_pdf_viewer; wxString working_dir; + int clear_3d_cache_interval; }; COMMON_SETTINGS();