Skip to content

Commit f48eaf4

Browse files
committed
save last index file dir
1 parent 25e5a8e commit f48eaf4

4 files changed

Lines changed: 33 additions & 7 deletions

File tree

headers/layouts/loadindexdialog.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CLoadIndexDialog : public QDialog, public Ui::LoadIndexDialog
1515
Q_OBJECT
1616

1717
public:
18-
CLoadIndexDialog( CMainWindow* pParent = nullptr );
18+
CLoadIndexDialog( CMainWindow* pParent, const QString& lastIndexDir = {} );
1919

2020
private slots:
2121
void OnBrowseGameDir();
@@ -28,4 +28,5 @@ private slots:
2828

2929
private:
3030
GameDataInfo m_DetectedGameInfo;
31+
QString m_LastIndexDir;
3132
};

headers/layouts/mainwindow.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ private slots:
123123

124124
QString m_LastOpenDir;
125125
QString m_LastExtractDir;
126+
QString m_LastIndexDir;
126127

127128
bool m_bShouldDecrypt;
128129
bool m_bShouldDecompress;

sources/layouts/loadindexdialog.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#include "mainwindow.hpp"
77

8-
CLoadIndexDialog::CLoadIndexDialog( CMainWindow* pParent /*= nullptr*/ )
9-
: QDialog( pParent ), m_DetectedGameInfo()
8+
CLoadIndexDialog::CLoadIndexDialog( CMainWindow* pParent, const QString& lastIndexDir /*= {}*/ )
9+
: QDialog( pParent ), m_LastIndexDir( lastIndexDir ), m_DetectedGameInfo()
1010
{
1111
this->setupUi( this );
1212

@@ -22,22 +22,35 @@ CLoadIndexDialog::CLoadIndexDialog( CMainWindow* pParent /*= nullptr*/ )
2222

2323
this->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
2424

25-
if ( QProcessEnvironment::systemEnvironment()
25+
if ( this->m_LastIndexDir.isEmpty() == false
26+
&& fs::is_directory( this->m_LastIndexDir.toStdString() ) == true )
27+
{
28+
this->leGameDir->setText( this->m_LastIndexDir );
29+
}
30+
else if ( QProcessEnvironment::systemEnvironment()
2631
.contains( QStringLiteral( "FLATPAK_ID" ) ) )
2732
{
2833
// On Flatpak one cannot manually enter a path from host,
2934
// so by default block text entry (only in constructor, so that
3035
// if the user wipes the field contents later manually, they'll
3136
// still be able to input something manually from then on)
3237
this->leGameDir->setEnabled( false );
33-
this->OnGameDirLineEdited( this->leGameDir->text() );
3438
}
39+
40+
this->OnGameDirLineEdited( this->leGameDir->text() );
3541
}
3642

3743
void CLoadIndexDialog::OnBrowseGameDir()
3844
{
45+
QString dir = QDir::homePath();
46+
if ( this->m_LastIndexDir.isEmpty() == false
47+
&& fs::is_directory( this->m_LastIndexDir.toStdString() ) == true )
48+
{
49+
dir = this->m_LastIndexDir;
50+
}
51+
3952
QString szDirPath = QFileDialog::getExistingDirectory(
40-
this, tr( "Select the game's directory" ), QDir::homePath() );
53+
this, tr( "Select the game's directory" ), dir );
4154

4255
if ( szDirPath.isEmpty() == true )
4356
{

sources/layouts/mainwindow.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ CMainWindow::CMainWindow( QWidget* pParent )
4141
m_ErrorBoxWidget( this->errorBox, this->errorBoxMsg, this->errorBoxBtn ),
4242
m_StatusWidget( this->lblStatus, this->pbStatus ),
4343
m_LastOpenDir( QDir::homePath() ), m_LastExtractDir( QDir::homePath() ),
44+
m_LastIndexDir( QDir::homePath() ),
4445
m_bShouldDecrypt( true ), m_bShouldDecompress( true )
4546
{
4647
this->SetLoadedFilename();
@@ -96,6 +97,7 @@ void CMainWindow::OnIndexFileAccepted( GameDataInfo info )
9697

9798
// FIXME: index entry is loaded as a package
9899
// this->AddToRecentFiles( info.GetGameDataPath() );
100+
this->m_LastIndexDir = QString::fromStdString( info.GetGameDataPath().generic_string() );
99101
this->SetLoadedFilename( info.GetGameDataPath().generic_string() );
100102
}
101103

@@ -537,6 +539,11 @@ void CMainWindow::ValidateLastDirs()
537539
{
538540
this->m_LastExtractDir = QDir::homePath();
539541
}
542+
543+
if ( fs::is_directory( this->m_LastIndexDir.toStdString() ) == false )
544+
{
545+
this->m_LastIndexDir = {};
546+
}
540547
}
541548

542549
void CMainWindow::LoadSettings()
@@ -571,6 +578,8 @@ void CMainWindow::LoadSettings()
571578
settings.value( QStringLiteral( "lastopendir" ) ).toString();
572579
this->m_LastExtractDir =
573580
settings.value( QStringLiteral( "lastextractdir" ) ).toString();
581+
this->m_LastIndexDir =
582+
settings.value( QStringLiteral( "lastindexdir" ) ).toString();
574583
settings.endGroup();
575584

576585
this->PostLoadSettings();
@@ -610,6 +619,8 @@ void CMainWindow::SaveSettings()
610619
settings.setValue( QStringLiteral( "lastopendir" ), this->m_LastOpenDir );
611620
settings.setValue( QStringLiteral( "lastextractdir" ),
612621
this->m_LastExtractDir );
622+
settings.setValue( QStringLiteral( "lastindexdir" ),
623+
this->m_LastIndexDir );
613624
settings.endGroup();
614625
}
615626

@@ -690,7 +701,7 @@ void CMainWindow::OnFileOpen()
690701

691702
void CMainWindow::OnIndexFileOpen()
692703
{
693-
CLoadIndexDialog( this ).exec();
704+
CLoadIndexDialog( this, this->m_LastIndexDir ).exec();
694705
}
695706

696707
void CMainWindow::OnRecentFileOpen()

0 commit comments

Comments
 (0)