Support loading projects from the command line (#2606)

This commit is contained in:
Itay Cohen 2021-02-24 08:10:01 +02:00 committed by GitHub
parent 7491434dc4
commit 42f01fcf5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 4 deletions

View File

@ -4,7 +4,7 @@ Command-line Options
Synopsis
--------
**Cutter** [*options*] [<*filename*>]
**Cutter** [*options*] [<*filename*> | --project <*project*>]
Options
@ -52,6 +52,10 @@ Options
Run script file
.. option:: -p, --project <file>
Load project file
.. option:: -w, --writemode
Open a file in write mode, instead of the default read-only mode.

View File

@ -133,7 +133,7 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
setStyle(new CutterProxyStyle());
#endif // QT_VERSION_CHECK(5, 10, 0) < QT_VERSION
if (clOptions.args.empty()) {
if (clOptions.args.empty() && clOptions.fileOpenOptions.projectFile.isEmpty()) {
// check if this is the first execution of Cutter in this computer
// Note: the execution after the preferences been reset, will be considered as
// first-execution
@ -142,7 +142,8 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
}
mainWindow->displayNewFileDialog();
} else { // filename specified as positional argument
bool askOptions = clOptions.analLevel != AutomaticAnalysisLevel::Ask;
bool askOptions = (clOptions.analLevel != AutomaticAnalysisLevel::Ask)
|| !clOptions.fileOpenOptions.projectFile.isEmpty();
mainWindow->openNewFile(clOptions.fileOpenOptions, askOptions);
}
@ -332,6 +333,10 @@ bool CutterApplication::parseCommandLineOptions()
QCommandLineOption scriptOption("i", QObject::tr("Run script file"), QObject::tr("file"));
cmd_parser.addOption(scriptOption);
QCommandLineOption projectOption({ "p", "project" }, QObject::tr("Load project file"),
QObject::tr("project file"));
cmd_parser.addOption(projectOption);
QCommandLineOption writeModeOption({ "w", "writemode" },
QObject::tr("Open file in write mode"));
cmd_parser.addOption(writeModeOption);
@ -426,6 +431,8 @@ bool CutterApplication::parseCommandLineOptions()
opts.fileOpenOptions.writeEnabled = cmd_parser.isSet(writeModeOption);
}
opts.fileOpenOptions.projectFile = cmd_parser.value(projectOption);
if (cmd_parser.isSet(pythonHomeOption)) {
opts.pythonHome = cmd_parser.value(pythonHomeOption);
}

View File

@ -18,6 +18,7 @@ struct InitialOptions
enum class Endianness { Auto, Little, Big };
QString filename;
QString projectFile;
bool useVA = true;
RVA binLoadAddr = RVA_INVALID;

View File

@ -591,7 +591,13 @@ void MainWindow::displayInitialOptionsDialog(const InitialOptions &options, bool
o->loadOptions(options);
if (skipOptionsDialog) {
o->setupAndStartAnalysis();
if (!options.projectFile.isEmpty()) {
if (!openProject(options.projectFile)) {
displayNewFileDialog();
};
} else {
o->setupAndStartAnalysis();
}
} else {
o->show();
}