about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorComradeCrow <comradecrow@vivaldi.net>2023-04-24 13:40:06 -0700
committerComradeCrow <comradecrow@vivaldi.net>2023-04-24 13:40:06 -0700
commit9af660d1fe3506ff129fbb62576a74ec20f9a5f2 (patch)
treebb19b9f3e70fca8abc7fcc1feba877841dfa0b26
parent7ba81cbe9809cfb68bee85bc6f79e798ef7b05ce (diff)
downloadytcpp-9af660d1fe3506ff129fbb62576a74ec20f9a5f2.tar.gz
hotfix
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/sqliteinterface.cpp23
2 files changed, 19 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c3186df..85a79c9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,9 +43,9 @@ add_subdirectory(extern/pybind11)
 find_package(Ytdlp REQUIRED RUNTIME)
 
 if(UNIX)
-    file(TO_CMAKE_PATH "$ENV{HOME}/.local/share/${PROJECT_NAME}/" DEF_APPDATA)
+    file(TO_CMAKE_PATH "$ENV{HOME}/.local/share/${PROJECT_NAME}" DEF_APPDATA)
 elseif(WIN32)
-    file(TO_CMAKE_PATH "$ENV{LOCALAPPDATA}\\${PROJECT_NAME}\\" DEF_APPDATA)
+    file(TO_CMAKE_PATH "$ENV{LOCALAPPDATA}\\${PROJECT_NAME}" DEF_APPDATA)
 else()
     message(SEND_ERROR "OS not recognized !")
     file(TO_CMAKE_PATH "./data" DEF_APPDATA)
diff --git a/src/sqliteinterface.cpp b/src/sqliteinterface.cpp
index 96e4020..1ae59be 100644
--- a/src/sqliteinterface.cpp
+++ b/src/sqliteinterface.cpp
@@ -2,25 +2,36 @@
 #include <iostream>
 #include <cstring>
 #include <filesystem>
+#include <stdexcept>
 #include "sqliteinterface.hpp"
 
+namespace fs = std::filesystem;
+using namespace std;
+
 void openDB() {
 
-    sqlite3 *db;
+    fs::path appdata = DEF_APPDATA;
+    if ( ! fs::exists(appdata) ) {
 
+        error_code ec;
+        fs::create_directories(appdata, ec);
+        cout << ec << endl;
+    }
+    cout << fs::exists(appdata) << endl;
+
+    sqlite3 *db;
 
-    char filename[] = DEF_APPDATA;
-    strcat(filename, "ytcpp.db");
-    int rc = sqlite3_open(filename, &db);
+    fs::path filename = appdata / "ytcpp.db";
+    int rc = sqlite3_open(filename.c_str(), &db);
 
     if( rc ) {
 
         char errmsg[] = "Can't open database: ";
         strcat(errmsg, sqlite3_errmsg(db));
-        std::cerr << errmsg << std::endl;
+        throw runtime_error(errmsg);
     } else {
 
         std::cout << "Opened database successfully" << std::endl;
-        sqlite3_close(db);
     }
+    sqlite3_close(db);
 }
\ No newline at end of file