about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt11
-rw-r--r--src/main.cpp9
-rw-r--r--src/sqliteinterface.cpp25
-rw-r--r--src/sqliteinterface.hpp2
4 files changed, 42 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f3dda8a..c3186df 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,8 +42,19 @@ add_subdirectory(extern/pybind11)
 
 find_package(Ytdlp REQUIRED RUNTIME)
 
+if(UNIX)
+    file(TO_CMAKE_PATH "$ENV{HOME}/.local/share/${PROJECT_NAME}/" DEF_APPDATA)
+elseif(WIN32)
+    file(TO_CMAKE_PATH "$ENV{LOCALAPPDATA}\\${PROJECT_NAME}\\" DEF_APPDATA)
+else()
+    message(SEND_ERROR "OS not recognized !")
+    file(TO_CMAKE_PATH "./data" DEF_APPDATA)
+endif()
+
+
 add_executable(${PROJECT_NAME} src/main.cpp src/tui.cpp src/invapi.cpp src/YtdlpWrapper.cpp src/sqliteinterface.cpp)
 target_include_directories(${PROJECT_NAME} PRIVATE src)
+target_compile_definitions(${PROJECT_NAME} PRIVATE DEF_APPDATA="${DEF_APPDATA}")
 
 target_link_libraries(${PROJECT_NAME} 
     PRIVATE cpr::cpr
diff --git a/src/main.cpp b/src/main.cpp
index 992761a..c08ba75 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -10,6 +10,7 @@
 #include "tui.hpp"
 #include "invapi.hpp"
 #include "YtdlpWrapper.hpp"
+#include "sqliteinterface.hpp"
 
 
 namespace py = pybind11;
@@ -17,9 +18,11 @@ using namespace std;
 
 int main() {
 
-    YtdlpWrapper yt;
-    nlohmann::json j = yt.getJsonSearch("the very thought of you");
-    cout << j << endl;
+    // YtdlpWrapper yt;
+    // nlohmann::json j = yt.getJsonSearch("the very thought of you");
+    // cout << j << endl;
+
+    openDB();
 
     // vector<string> instances = getInstances();
     // for (auto i: instances) {
diff --git a/src/sqliteinterface.cpp b/src/sqliteinterface.cpp
index 6b244dc..96e4020 100644
--- a/src/sqliteinterface.cpp
+++ b/src/sqliteinterface.cpp
@@ -1,3 +1,26 @@
-#include <string>
 #include <sqlite3.h>
+#include <iostream>
+#include <cstring>
+#include <filesystem>
 #include "sqliteinterface.hpp"
+
+void openDB() {
+
+    sqlite3 *db;
+
+
+    char filename[] = DEF_APPDATA;
+    strcat(filename, "ytcpp.db");
+    int rc = sqlite3_open(filename, &db);
+
+    if( rc ) {
+
+        char errmsg[] = "Can't open database: ";
+        strcat(errmsg, sqlite3_errmsg(db));
+        std::cerr << errmsg << std::endl;
+    } else {
+
+        std::cout << "Opened database successfully" << std::endl;
+        sqlite3_close(db);
+    }
+}
\ No newline at end of file
diff --git a/src/sqliteinterface.hpp b/src/sqliteinterface.hpp
index 6a38d2c..4a18f85 100644
--- a/src/sqliteinterface.hpp
+++ b/src/sqliteinterface.hpp
@@ -3,5 +3,5 @@
 #include <string>
 #include <sqlite3.h>
  
-
+void openDB();
 #endif  
\ No newline at end of file