]> git.sesse.net Git - nageru/commitdiff
Make it possible to change the working directory.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 19 Oct 2018 18:43:28 +0000 (20:43 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 19 Oct 2018 18:43:28 +0000 (20:43 +0200)
db.cpp
db.h
flags.cpp
flags.h
main.cpp
mainwindow.cpp

diff --git a/db.cpp b/db.cpp
index 77e3b73e09e9417dcea301528db398fdc8beb666..9b0de352fda7bafb3ae8c107181325bdefca7508 100644 (file)
--- a/db.cpp
+++ b/db.cpp
@@ -4,11 +4,11 @@
 
 using namespace std;
 
-DB::DB(const char *filename)
+DB::DB(const std::string &filename)
 {
-       int ret = sqlite3_open(filename, &db);
+       int ret = sqlite3_open(filename.c_str(), &db);
        if (ret != SQLITE_OK) {
-               fprintf(stderr, "%s: %s\n", filename, sqlite3_errmsg(db));
+               fprintf(stderr, "%s: %s\n", filename.c_str(), sqlite3_errmsg(db));
                exit(1);
        }
 
diff --git a/db.h b/db.h
index 13a7e510535fc0cdb2421cc7ce011d5ef982fe73..40a6602d937f1945995ad5d34c2b020f9de92b3e 100644 (file)
--- a/db.h
+++ b/db.h
@@ -4,10 +4,11 @@
 #include "state.pb.h"
 
 #include <sqlite3.h>
+#include <string>
 
 class DB {
 public:
-       explicit DB(const char *filename);
+       explicit DB(const std::string &filename);
        DB(const DB &) = delete;
 
        StateProto get_state();
index b3b59fab41f0fd30d99c934e1cad0ea2f8c24175..c10f9d7a390c0435fc76f21494de10ae076eeb4d 100644 (file)
--- a/flags.cpp
+++ b/flags.cpp
@@ -28,6 +28,7 @@ void usage()
        fprintf(stderr, "                                  2 = default (realtime 720p on fast embedded GPUs)\n");
        fprintf(stderr, "                                  3 = good (realtime 720p on GTX 970 or so)\n");
        fprintf(stderr, "                                  4 = best (not realtime on any current GPU)\n");
+       fprintf(stderr, "  -d, --working-directory DIR     where to store frames and database\n");
 }
 
 void parse_flags(int argc, char * const argv[])
@@ -36,11 +37,12 @@ void parse_flags(int argc, char * const argv[])
                { "help", no_argument, 0, OPTION_HELP },
                { "slow-down-input", no_argument, 0, OPTION_SLOW_DOWN_INPUT },
                { "interpolation-quality", required_argument, 0, 'q' },
+               { "working-directory", required_argument, 0, 'd' },
                { 0, 0, 0, 0 }
        };
        for ( ;; ) {
                int option_index = 0;
-               int c = getopt_long(argc, argv, "q:", long_options, &option_index);
+               int c = getopt_long(argc, argv, "q:d:", long_options, &option_index);
 
                if (c == -1) {
                        break;
@@ -52,6 +54,9 @@ void parse_flags(int argc, char * const argv[])
                case 'q':
                        global_flags.interpolation_quality = atoi(optarg);
                        break;
+               case 'd':
+                       global_flags.working_directory = optarg;
+                       break;
                case OPTION_HELP:
                        usage();
                        exit(0);
diff --git a/flags.h b/flags.h
index ea4d423ed5dd6768dcf93b197de3076e84f89285..8b2563c0f6017b9af04d1a424bb47e450a3bb4c7 100644 (file)
--- a/flags.h
+++ b/flags.h
@@ -5,6 +5,7 @@
 
 struct Flags {
        std::string stream_source;
+       std::string working_directory = ".";
        bool slow_down_input = false;
        int interpolation_quality = 2;
 };
index 1266c2ab13e546cf329a1b91f5142c6a9e436e7c..bf9757533fa5a1fd7d46473e9c411ec70c9f5663 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -50,7 +50,8 @@ int64_t current_pts = 0;
 string filename_for_frame(unsigned stream_idx, int64_t pts)
 {
        char filename[256];
-       snprintf(filename, sizeof(filename), "frames/cam%d-pts%09ld.jpeg", stream_idx, pts);
+       snprintf(filename, sizeof(filename), "%s/frames/cam%d-pts%09ld.jpeg",
+               global_flags.working_directory.c_str(), stream_idx, pts);
        return filename;
 }
 
index 559894271e8b9ed808ddb7ac7efcc06e34d405f5..198a6313ee3237b908cf3ae8d2481b2f7d7523d2 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "clip_list.h"
 #include "disk_space_estimator.h"
+#include "flags.h"
 #include "player.h"
 #include "post_to_main_thread.h"
 #include "timebase.h"
@@ -29,7 +30,7 @@ extern vector<int64_t> frames[MAX_STREAMS];
 
 MainWindow::MainWindow()
        : ui(new Ui::MainWindow),
-         db("futatabi.db")
+         db(global_flags.working_directory + "/futatabi.db")
 {
        global_mainwindow = this;
        ui->setupUi(this);