Skip to content

Commit 982756a

Browse files
committed
support opening file/dir with argv
1 parent be9d4d9 commit 982756a

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

headers/layouts/mainwindow.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class CMainWindow : public MainWindowInit
4545

4646
public:
4747
void OnIndexFileAccepted( GameDataInfo info );
48+
void OpenPath( fs::path path );
4849

4950
protected:
5051
virtual void closeEvent( QCloseEvent* event ) override;

sources/layouts/mainwindow.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,56 @@ void CMainWindow::ShowError( const QString& message, const QString& details )
606606
this->m_ErrorBoxWidget.SetVisible( true );
607607
}
608608

609+
// Externally commanded to open a path, might be a directory or file
610+
void CMainWindow::OpenPath( fs::path path )
611+
{
612+
if ( fs::exists( path ) == false )
613+
{
614+
QString convertedPath = QString::fromStdString( path.generic_string() );
615+
this->ShowError( tr( "Could not open non-existent path <code>%1</code>.")
616+
.arg( convertedPath ),
617+
this->m_Model.GetError() );
618+
return;
619+
}
620+
621+
path = fs::canonical( path );
622+
623+
if ( fs::is_directory( path ) )
624+
{
625+
GameDataInfo detectedGameInfo{};
626+
detectedGameInfo.SetGameDataPath( path );
627+
628+
if ( detectedGameInfo.WasGameDetected() == false )
629+
{
630+
fs::path path_data = path / "Data";
631+
if ( fs::exists( path_data ) && fs::is_directory( path_data ) )
632+
{
633+
path = path_data;
634+
detectedGameInfo.SetGameDataPath( path_data );
635+
}
636+
}
637+
638+
if ( detectedGameInfo.WasGameDetected() == false )
639+
{
640+
QString convertedPath = QString::fromStdString( path.generic_string() );
641+
this->ShowError( tr( "Could not detect any compatible game in the directory "
642+
"(<code>%1</code>)." ).arg( convertedPath ),
643+
this->m_Model.GetError() );
644+
}
645+
else
646+
{
647+
this->OnIndexFileAccepted( detectedGameInfo );
648+
}
649+
}
650+
else
651+
{
652+
this->m_LastOpenDir =
653+
QString::fromStdString( path.parent_path().generic_string() );
654+
655+
this->LoadPackage( path );
656+
}
657+
}
658+
609659
void CMainWindow::OnFileOpen()
610660
{
611661
const fs::path filePath =

sources/uncso2app.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ CUnCSO2App::CUnCSO2App( int& argc, char** argv ) : QApplication( argc, argv )
1515
}
1616

1717
this->m_pMainWindow = std::make_unique<CMainWindow>();
18+
if ( argc > 1 && argv[argc - 1][0] )
19+
{
20+
this->m_pMainWindow->OpenPath( fs::path( argv[argc - 1] ) );
21+
}
1822
this->m_pMainWindow->show();
1923
}
2024

0 commit comments

Comments
 (0)