Skip to content

Commit

Permalink
Added the dedicated executable for console operations
Browse files Browse the repository at this point in the history
  • Loading branch information
winseros committed Mar 28, 2022
1 parent cba115b commit 608b4ba
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# PBO Manager change log

## Version 1.4.0
- [Feature] Dedicated executable `pboc.exe` for usage in scripts

## Version 1.3.0
- [Feature] Added the `--no-ui` command line flag for usage in scripts

Expand Down
6 changes: 6 additions & 0 deletions installer/PBOManager.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<ComponentGroup Id="CG_MainFiles">
<ComponentRef Id="C_MainFiles__pboe.dll" />
<ComponentRef Id="C_MainFiles__pbom.exe" />
<ComponentRef Id="C_MainFiles__pboc.exe" />
<ComponentRef Id="C_MainFiles__Qt6Core.dll" />
<ComponentRef Id="C_MainFiles__Qt6Gui.dll" />
<ComponentRef Id="C_MainFiles__Qt6Widgets.dll" />
Expand Down Expand Up @@ -143,6 +144,11 @@
</ProgId>
</Component>

<Component Id="C_MainFiles__pboc.exe" Guid="E7F4C6E0-52EA-42DF-A47F-73B39FBFB36E" Win64="yes">
<File Id="F_MainFiles__pboc.exe" KeyPath="yes" Vital="yes"
Source="$(var.ArtifactsFolder)pboc.exe" />
</Component>

<Component Id="C_MainFiles__Qt6Core.dll" Guid="1D77E778-A132-44DA-BB2C-1A6D275DCB45" Win64="yes">
<File Id="F_MainFiles__Qt6Core.dll" KeyPath="yes" Vital="yes"
Source="$(var.ArtifactsFolder)Qt6Core.dll" />
Expand Down
12 changes: 9 additions & 3 deletions pbom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ add_subdirectory(ui)
add_subdirectory(util)

qt_add_resources(PROJECT_SOURCES res/res.qrc)
qt_add_executable(pbom ${PROJECT_SOURCES} exception.cpp main.cpp res/winapp.rc)
qt_add_executable(pbom ${PROJECT_SOURCES} ${PROJECT_SOURCES_UI} exception.cpp main.cpp res/winapp.rc)
qt_add_executable(pboc ${PROJECT_SOURCES} exception.cpp console.cpp res/console.rc)

target_link_libraries(pbom PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network CLI11)
target_include_directories(pbom PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(pbom PRIVATE WINVER=${WIN32_VER} NOMINMAX)
target_compile_definitions(pbom PRIVATE WINVER=${WIN32_VER} NOMINMAX PBOM_GUI)

target_link_libraries(pboc PRIVATE Qt${QT_VERSION_MAJOR}::Core CLI11)
target_include_directories(pboc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(pboc PRIVATE NOMINMAX)

SET(QT_BINARIES_DIR ${Qt${QT_VERSION_MAJOR}_DIR}/../../..)
if(CMAKE_BUILD_TYPE MATCHES Release)
Expand All @@ -37,6 +42,7 @@ endif()

include(GNUInstallDirs)
install(TARGETS pbom)
install(TARGETS pboc)
install(FILES
${QT_BINARIES_DIR}/bin/Qt6Core${QT_BINARIES_SUFFIX}.dll
${QT_BINARIES_DIR}/bin/Qt6Gui${QT_BINARIES_SUFFIX}.dll
Expand All @@ -60,7 +66,7 @@ install(FILES
${QT_BINARIES_DIR}/../../Tools/OpenSSL/Win_x64/bin/libcrypto-1_1-x64.dll
DESTINATION ${CMAKE_INSTALL_BINDIR})

add_executable(pbom_test ${PROJECT_SOURCES} ${TEST_SOURCES} exception.cpp testmain.cpp)
add_executable(pbom_test ${PROJECT_SOURCES} ${PROJECT_SOURCES_UI} ${TEST_SOURCES} exception.cpp testmain.cpp)
add_test(NAME pbom_test COMMAND pbom_test)
target_link_libraries(pbom_test PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network gtest gmock)
target_include_directories(pbom_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
28 changes: 21 additions & 7 deletions pbom/commandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,34 @@ namespace pboman3 {
};

struct PackCommandBase : Command {
PackCommandBase() : optOutputPath(nullptr), optPrompt(nullptr), optNoUi(nullptr) {
PackCommandBase()
: optOutputPath(nullptr)
#ifdef PBOM_GUI
, optPrompt(nullptr)
, optNoUi(nullptr)
#endif
{
}

string outputPath;
Option* optOutputPath;
#ifdef PBOM_GUI
Option* optPrompt;
Option* optNoUi;
#endif

bool hasOutputPath() const {
return !!*optOutputPath;
}

#ifdef PBOM_GUI
bool prompt() const {
return !!*optPrompt;
}

bool noUi() const {
return !!*optNoUi;
}
#endif
};

struct CommandPack : PackCommandBase {
Expand All @@ -69,13 +78,14 @@ namespace pboman3 {
"The directory to write the resulting PBO(s)")
->check(ExistingDirectory);

#ifdef PBOM_GUI
optPrompt = command->add_flag("-p,--prompt",
"Show a UI dialog for the output directory selection")
->excludes(optOutputPath);

optNoUi = command->add_flag("-u,--no-ui", "Run the application without the GUI")
->excludes(optPrompt);

->excludes(optPrompt);
#endif
}
};

Expand All @@ -92,17 +102,20 @@ namespace pboman3 {
optOutputPath = command->add_option("-o,--output-directory", outputPath,
"The directory to write the PBO(s) contents")
->check(ExistingDirectory);

#ifdef PBOM_GUI
optPrompt = command->add_flag("-p,--prompt",
"Show a UI dialog for the output directory selection");

optNoUi = command->add_flag("-u,--no-ui", "Run the application without the GUI")
->excludes(optPrompt);
->excludes(optPrompt);
#endif
}
};

struct Result {
#ifdef PBOM_GUI
CommandOpen open;
#endif

CommandPack pack;

Expand All @@ -115,8 +128,9 @@ namespace pboman3 {

shared_ptr<Result> build() const {
auto result = make_shared<Result>();

#ifdef PBOM_GUI
result->open.configure(app_);
#endif
result->pack.configure(app_);
result->unpack.configure(app_);

Expand Down
87 changes: 87 additions & 0 deletions pbom/console.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <QScopedPointer>
#include <QTimer>
#include <CLI/CLI.hpp>
#include "commandline.h"
#include "model/pbomodel.h"
#include "exception.h"
#include "model/task/packtask.h"
#include "model/task/unpacktask.h"
#include "util/log.h"

#define LOG(...) LOGGER("Main", __VA_ARGS__)

using namespace std;

namespace pboman3 {
int RunConsolePackOperation(const QStringList& folders, const QString& outputDir) {
util::UseLoggingMessagePattern();
for (const QString& folder : folders) {
//don't parallelize to avoid mess in the console
model::task::PackTask task(folder, outputDir);
task.execute([] { return false; });
}
return 0;
}

int RunConsoleUnpackOperation(const QStringList& folders, const QString& outputDir) {
util::UseLoggingMessagePattern();
for (const QString& folder : folders) {
//don't parallelize to avoid mess in the console
model::task::UnpackTask task(folder, outputDir);
task.execute([] { return false; });
}
return 0;
}

int RunWithCliOptions(int argc, char* argv[]) {
using namespace CLI;
using namespace pboman3;

int exitCode;
App cli;
const CommandLine cmd(&cli);
const shared_ptr<CommandLine::Result> commandLine = cmd.build();
CLI11_PARSE(cli, argc, argv)

if (commandLine->pack.hasBeenSet()) {
QString outputDir;
if (commandLine->pack.hasOutputPath())
outputDir = CommandLine::toQt(commandLine->pack.outputPath);
else
outputDir = QDir::currentPath();

const QStringList folders = CommandLine::toQt(commandLine->pack.folders);
exitCode = RunConsolePackOperation(folders, outputDir);
} else if (commandLine->unpack.hasBeenSet()) {
QString outputDir;
if (commandLine->unpack.hasOutputPath())
outputDir = CommandLine::toQt(commandLine->unpack.outputPath);
else
outputDir = QDir::currentPath();

const QStringList files = CommandLine::toQt(commandLine->unpack.files);
exitCode = RunConsoleUnpackOperation(files, outputDir);
} else {
//should not normally get here; if did - CLI11 was misconfigured somewhere
cout << cli.help();
exitCode = 1;
}
return exitCode;
}

int RunMain(int argc, char* argv[]) {
const int exitCode = RunWithCliOptions(argc, argv);
return exitCode;
}
}


int main(int argc, char* argv[]) {
try {
const int res = pboman3::RunMain(argc, argv);
return res;
} catch (const pboman3::AppException& ex) {
LOG(critical, "Unexpected exception has been thrown:", ex);
throw ex;
}
}
4 changes: 2 additions & 2 deletions pbom/io/bb/unpacktaskbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace pboman3::io {

void UnpackTaskBackend::unpackFileNode(const PboNode* rootNode, const PboNode* childNode,
const Cancel& cancel) const {
LOG(info, "Unpack the node", childNode->title())
LOG(debug, "Unpack the node", childNode->title())

QString filePath;
try {
Expand Down Expand Up @@ -52,7 +52,7 @@ namespace pboman3::io {
return;
}

LOG(info, "Writing to file system")
LOG(debug, "Writing to file system")
childNode->binarySource->writeToFs(&file, cancel);

file.close();
Expand Down
2 changes: 1 addition & 1 deletion pbom/model/task/unpacktask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace pboman3::model::task {
try {
const DocumentReader reader(pboPath_);
*document = reader.read();
LOG(info, "The document:", *document)
LOG(debug, "The document:", *document)
return true;
} catch (const DiskAccessException& ex) {
LOG(warning, "Got error while opening the file:", ex)
Expand Down
Binary file added pbom/res/console.ico
Binary file not shown.
1 change: 1 addition & 0 deletions pbom/res/console.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
35355 ICON res/console.ico
Binary file added pbom/res/console512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions pbom/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
list(APPEND PROJECT_SOURCES
list(APPEND PROJECT_SOURCES_UI
"ui/progresswidget/progresswidget.cpp"
"ui/treewidget/deleteop.cpp"
"ui/treewidget/treewidget.cpp"
Expand Down Expand Up @@ -36,7 +36,7 @@ list(APPEND PROJECT_SOURCES
"ui/updatesdialog.ui"
"ui/updatesdialog.cpp")

set(PROJECT_SOURCES ${PROJECT_SOURCES} PARENT_SCOPE)
set(PROJECT_SOURCES_UI ${PROJECT_SOURCES_UI} PARENT_SCOPE)

list(APPEND TEST_SOURCES
"ui/__test__/fscollector__test.cpp"
Expand Down

0 comments on commit 608b4ba

Please sign in to comment.