Skip to content

Commit

Permalink
Refactor C++ code #61, (automatically create Videos output directory…
Browse files Browse the repository at this point in the history
… when path not exists).
  • Loading branch information
vmdocua committed Dec 8, 2023
1 parent a2d1086 commit f0b087c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Capture/videocapture/VideoCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
/************************************************************************************************/

#include <iostream>
#include <filesystem>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
Expand All @@ -65,6 +66,7 @@
using std::cerr;
using std::cout;
using std::endl;
namespace fs = std::filesystem;

/* ######################### begin common ############################# */

Expand Down Expand Up @@ -390,6 +392,20 @@ struct VideoDevice {
int channelIndex = -1;
};

bool checkOutDir(bool verbose, const std::string& outDir) {
if( !fs::exists(outDir)) {
_VERBOSE("Output path not exists, creating...");
if (fs::create_directories(outDir)) {
_VERBOSE("Done.");
return true;
} else {
_VERBOSE("Failed create output path: " << outDir);
return false;
}
}
return true;
}

bool findTargetVideoDevice(const AppConfig& cfg,
const AppOpts& opts,
VideoDevice& vd) {
Expand Down Expand Up @@ -545,6 +561,11 @@ int main(int argc, char* argv[]) {
}

_VERBOSE("Output path: " << opts.outPath);
if( !checkOutDir(verbose, opts.outPath) ) {
// invalid output path
cerr << "ERROR[009]: Failed create/locate output path: " << opts.outPath << endl;
return -9;
}

// calculated options
VideoDevice targetDev;
Expand Down

0 comments on commit f0b087c

Please sign in to comment.