From 53bd57cd17fafc2f928891fc70767604a928cc14 Mon Sep 17 00:00:00 2001 From: Moss Date: Wed, 28 Sep 2022 21:02:56 -0400 Subject: [PATCH] Cookies: Refactored Cookies System Now the file that profiles are found from is only set once in one place and the #ifdef statements are inside of the function rather than redefining the same thing multiple times. --- src/main.cpp | 75 +++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 42 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2196791..76c4806 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,9 +25,9 @@ static int sqlite_write_callback(void* data, int argc, char** argv, char** azCol } #ifdef DROPOUT_DL_SQLITE -std::vector get_cookies_from_firefox(bool verbose = false) { +std::vector get_cookies_from_firefox(const std::filesystem::path& firefox_profile_path, bool verbose = false) { - std::fstream firefox_profile_file("firefox_profile"); + std::fstream firefox_profile_file(firefox_profile_path); std::string firefox_profile; std::string auth_cookie; @@ -98,9 +98,9 @@ std::vector get_cookies_from_firefox(bool verbose = false) { } #ifdef DROPOUT_DL_GCRYPT -std::vector get_cookies_from_chrome(bool verbose = false) { +std::vector get_cookies_from_chrome(const std::filesystem::path& chrome_profile_path, bool verbose = false) { - std::fstream chrome_profile_file("chrome_profile"); + std::fstream chrome_profile_file(chrome_profile_path); std::string chrome_profile; std::string auth_cookie; @@ -238,7 +238,7 @@ std::vector get_cookies_from_chrome(bool verbose = false) { #endif #endif -std::vector get_cookies_from_files(bool verbose = false) { +std::vector get_cookies_from_files(const std::filesystem::path& auth_cookie_path, const std::filesystem::path& session_cookie_path, bool verbose = false) { std::fstream auth_cookie_file("auth_cookie"); std::fstream session_cookie_file("session_cookie"); @@ -264,45 +264,36 @@ std::vector get_cookies_from_files(bool verbose = false) { return out; } +std::vector get_cookies(bool verbose = false) { + +#ifdef DROPOUT_DL_SQLITE + std::filesystem::path firefox_profile("firefox_profile"); #ifdef DROPOUT_DL_GCRYPT -std::vector get_cookies(bool verbose = false) { - - if (std::filesystem::is_regular_file("firefox_profile_")) { - return get_cookies_from_firefox(verbose); - } else if (std::filesystem::is_regular_file("chrome_profile")) { - return get_cookies_from_chrome(verbose); - } - else if (std::filesystem::is_regular_file("auth_cookie") && std::filesystem::is_regular_file("session_cookie")){ - return get_cookies_from_files(verbose); - } - else { - std::cerr << "ERROR: dropout.tv cookies could not be found" << std::endl; - exit(1); - } -} -#elif defined(DROPOUT_DL_SQLITE) -std::vector get_cookies(bool verbose = false) { - - if (std::filesystem::is_character_file("firefox_profile")) { - return get_cookies_from_firefox(verbose); - } - else if (std::filesystem::is_character_file("auth_cookie") && std::filesystem::is_character_file("session_cookie")){ - return get_cookies_from_files(verbose); - } - else { - std::cerr << "ERROR: dropout.tv cookies could not be found" << std::endl; - } -} -#else -std::vector get_cookies(bool verbose = false) { - if (std::filesystem::is_character_file("auth_cookie") && std::filesystem::is_character_file("session_cookie")){ - return get_cookies_from_files(verbose); - } - else { - std::cerr << "ERROR: dropout.tv cookies could not be found" << std::endl; - } -} + std::filesystem::path chrome_profile("chrome_profile"); #endif +#endif + std::filesystem::path auth_cookie("auth_cookie"); + std::filesystem::path session_cookie("session_cookie"); + + + #ifdef DROPOUT_DL_SQLITE + if (std::filesystem::exists(firefox_profile)) { + return get_cookies_from_firefox(firefox_profile, verbose); + } else + #ifdef DROPOUT_DL_GCRYPT + if (std::filesystem::exists(chrome_profile)) { + return get_cookies_from_chrome(chrome_profile, verbose); + } else + #endif + #endif + if (std::filesystem::exists(auth_cookie) && std::filesystem::exists(session_cookie)){ + return get_cookies_from_files(auth_cookie, session_cookie, verbose); + } + else { + std::cerr << "ERROR: dropout.tv cookies could not be found" << std::endl; + exit(7); + } +} int main(int argc, char** argv) {