Переглянути джерело

bumped to version 0.2 and corrected bugs

Nicole Portas 4 тижнів тому
батько
коміт
62a26fbc6a
3 змінених файлів з 499 додано та 499 видалено
  1. 450 450
      MainWindow.cpp
  2. 1 1
      Makefile
  3. 48 48
      main.cpp

+ 450 - 450
MainWindow.cpp

@@ -9,453 +9,453 @@
  */
 
 
-#include "MainWindow.hpp"
-#include <iostream>
-#include <filesystem>
-#include <archive.h>
-#include <archive_entry.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <cstdlib>
-#include <cstdio>
-#include <algorithm>
-#include <chrono>
-#include <iomanip>
-#include <sstream>
-#include <set>
-
-namespace fs = std::filesystem;
-
-MainWindow::MainWindow()
-: m_HeaderBar(), m_MainLayout(Gtk::ORIENTATION_VERTICAL, 0), m_Notebook(),
-  m_BottomBox(Gtk::ORIENTATION_HORIZONTAL, 10), m_StatusLabel("Ready."), 
-  m_CheckDebugMode("Enable Debug Logging"), m_VBoxBackup(Gtk::ORIENTATION_VERTICAL, 10),
-  m_LabelBackupInstruction("<span size='large' weight='bold'>Backup</span>"),
-  m_CheckThemesBackup("GTK Themes"), m_CheckIconsBackup("Icons"),
-  m_CheckWallpapersBackup("Wallpapers"), m_CheckExtensionsBackup("GNOME Extensions"),
-  m_CheckDconfBackup("GNOME Settings"), m_ButtonBackup("Start Backup"),
-  m_VBoxRestore(Gtk::ORIENTATION_VERTICAL, 10),
-  m_LabelRestoreInstruction("<span size='large' weight='bold'>Restore from Vault</span>"),
-  m_ButtonSelectVault("Select .gbk Vault File"), m_LabelSelectedVault("No vault selected"),
-  m_CheckThemesRestore("GTK Themes"), m_CheckIconsRestore("Icons"),
-  m_CheckWallpapersRestore("Wallpapers"), m_CheckExtensionsRestore("GNOME Extensions"),
-  m_CheckDconfRestore("GNOME Settings"), m_CheckDryRunRestore("Dry Run"),
-  m_ButtonRestore("Start Restore"), m_WorkerRunning(false), m_JobSuccess(true), 
-  m_IsDebugMode(false), m_LastJobWasRestore(false)
-{
-    m_Dispatcher.connect(sigc::mem_fun(*this, &MainWindow::on_dispatcher_ping));
-    set_default_size(1000, 700);
-    m_HeaderBar.set_title("GnomeSettingsVault 0.1");
-    m_HeaderBar.set_show_close_button(true);
-    set_titlebar(m_HeaderBar);
-
-    m_LabelBackupInstruction.set_use_markup(true);
-    m_LabelRestoreInstruction.set_use_markup(true);
-
-    m_RefTextBuffer = Gtk::TextBuffer::create();
-    auto selection_tag = m_RefTextBuffer->create_tag("selection_orange");
-    selection_tag->property_background() = "#ff8c00";
-    selection_tag->property_foreground() = "#000000";
-    
-    m_LogView.set_buffer(m_RefTextBuffer);
-    m_LogView.set_editable(false);
-    m_LogView.set_cursor_visible(true);
-    m_LogView.set_can_focus(true);
-    
-    m_RefTextBuffer->signal_mark_set().connect([this, selection_tag](const Gtk::TextBuffer::iterator& iter, const Glib::RefPtr<Gtk::TextMark>& mark){
-        Gtk::TextBuffer::iterator start, end;
-        if (m_RefTextBuffer->get_selection_bounds(start, end)) {
-            m_RefTextBuffer->apply_tag(selection_tag, start, end);
-        } else {
-            m_RefTextBuffer->remove_tag(selection_tag, m_RefTextBuffer->begin(), m_RefTextBuffer->end());
-        }
-    });
-
-    m_LogView.override_background_color(Gdk::RGBA("#1e1e1e")); 
-    m_LogView.override_color(Gdk::RGBA("#dcdcdc"));
-    
-    m_RefTextBuffer->create_mark("last_line", m_RefTextBuffer->end());
-    m_ScrolledWindow.add(m_LogView);
-    m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
-
-    m_VBoxBackup.set_border_width(20);
-    m_VBoxBackup.pack_start(m_LabelBackupInstruction, Gtk::PACK_SHRINK);
-    m_VBoxBackup.pack_start(m_CheckThemesBackup, Gtk::PACK_SHRINK);
-    m_VBoxBackup.pack_start(m_CheckIconsBackup, Gtk::PACK_SHRINK);
-    m_VBoxBackup.pack_start(m_CheckWallpapersBackup, Gtk::PACK_SHRINK);
-    m_VBoxBackup.pack_start(m_CheckExtensionsBackup, Gtk::PACK_SHRINK);
-    m_VBoxBackup.pack_start(m_CheckDconfBackup, Gtk::PACK_SHRINK);
-    m_VBoxBackup.pack_end(m_ButtonBackup, Gtk::PACK_SHRINK);
-    
-    m_VBoxRestore.set_border_width(20);
-    m_VBoxRestore.pack_start(m_LabelRestoreInstruction, Gtk::PACK_SHRINK);
-    m_VBoxRestore.pack_start(m_ButtonSelectVault, Gtk::PACK_SHRINK);
-    m_VBoxRestore.pack_start(m_LabelSelectedVault, Gtk::PACK_SHRINK);
-    m_VBoxRestore.pack_start(m_CheckThemesRestore, Gtk::PACK_SHRINK);
-    m_VBoxRestore.pack_start(m_CheckIconsRestore, Gtk::PACK_SHRINK);
-    m_VBoxRestore.pack_start(m_CheckWallpapersRestore, Gtk::PACK_SHRINK);
-    m_VBoxRestore.pack_start(m_CheckExtensionsRestore, Gtk::PACK_SHRINK);
-    m_VBoxRestore.pack_start(m_CheckDconfRestore, Gtk::PACK_SHRINK);
-    m_VBoxRestore.pack_start(m_CheckDryRunRestore, Gtk::PACK_SHRINK);
-    m_VBoxRestore.pack_end(m_ButtonRestore, Gtk::PACK_SHRINK);
-
-    m_Notebook.append_page(m_VBoxBackup, "Backup");
-    m_Notebook.append_page(m_VBoxRestore, "Restore");
-    
-    m_BottomBox.set_border_width(10);
-    m_StatusLabel.set_halign(Gtk::ALIGN_START);
-    m_BottomBox.pack_start(m_StatusLabel, Gtk::PACK_EXPAND_WIDGET);
-    m_BottomBox.pack_end(m_CheckDebugMode, Gtk::PACK_SHRINK);
-
-    m_MainLayout.pack_start(m_Notebook, Gtk::PACK_SHRINK);
-    m_MainLayout.pack_start(m_ScrolledWindow, Gtk::PACK_EXPAND_WIDGET);
-    m_MainLayout.pack_start(m_BottomBox, Gtk::PACK_SHRINK);
-
-    m_ButtonBackup.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_button_backup_clicked));
-    m_ButtonRestore.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_button_restore_clicked));
-    m_ButtonSelectVault.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_button_select_vault_clicked));
-
-    add(m_MainLayout);
-    show_all_children();
-}
-
-MainWindow::~MainWindow() {}
-
-void MainWindow::scan_vault_contents(const std::string& path) {
-    struct archive *a = archive_read_new();
-    struct archive_entry *entry;
-    archive_read_support_format_all(a);
-    archive_read_support_filter_all(a);
-    std::set<std::string> found;
-    if (archive_read_open_filename(a, path.c_str(), 10240) == ARCHIVE_OK) {
-        while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
-            std::string p = archive_entry_pathname(entry);
-            if (p.find("themes.tar.gz") != std::string::npos) found.insert("themes");
-            if (p.find("icons.tar.gz") != std::string::npos) found.insert("icons");
-            if (p.find("wallpapers.tar.gz") != std::string::npos) found.insert("wallpapers");
-            if (p.find("extensions.tar.gz") != std::string::npos) found.insert("extensions");
-            if (p.find("settings.ini") != std::string::npos) found.insert("dconf");
-        }
-    }
-    archive_read_free(a);
-    m_CheckThemesRestore.set_active(found.count("themes"));
-    m_CheckIconsRestore.set_active(found.count("icons"));
-    m_CheckWallpapersRestore.set_active(found.count("wallpapers"));
-    m_CheckExtensionsRestore.set_active(found.count("extensions"));
-    m_CheckDconfRestore.set_active(found.count("dconf"));
-}
-
-void MainWindow::on_button_select_vault_clicked() {
-    Gtk::FileChooserDialog dialog("Choose vault", Gtk::FILE_CHOOSER_ACTION_OPEN);
-    dialog.set_transient_for(*this);
-    dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
-    dialog.add_button("_Open", Gtk::RESPONSE_OK);
-    if (dialog.run() == Gtk::RESPONSE_OK) {
-        m_SelectedVaultPath = dialog.get_filename();
-        m_LabelSelectedVault.set_text("Selected: " + fs::path(m_SelectedVaultPath).filename().string());
-        scan_vault_contents(m_SelectedVaultPath);
-        add_log_ui("Vault loaded.");
-    }
-}
-
-void MainWindow::queue_log(const std::string& message) {
-    // Only write to disk if debug mode is explicitly checked
-    if (m_IsDebugMode) {
-        std::ofstream log_file(std::string(std::getenv("HOME")) + "/GnomeSettingsVault.log", std::ios::app);
-        if (log_file.is_open()) { log_file << message << std::endl; log_file.close(); }
-    }
-    
-    std::lock_guard<std::mutex> lock(m_LogMutex);
-    m_LogQueue.push(message);
-    m_Dispatcher.emit();
-}
-
-void MainWindow::on_dispatcher_ping() {
-    std::lock_guard<std::mutex> lock(m_LogMutex);
-    while (!m_LogQueue.empty()) {
-        std::string msg = m_LogQueue.front();
-        m_LogQueue.pop();
-        if (msg == "__UNLOCK_UI__") {
-            set_ui_locked(false);
-            
-            // Trigger Logout Prompt if it was a successful restore
-            if (m_JobSuccess && m_LastJobWasRestore) {
-                Gtk::MessageDialog dialog(*this, "Restore Complete", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
-                dialog.set_secondary_text("Settings and components have been successfully restored.\n\nGNOME needs to restart to apply all changes smoothly. Would you like to log out now?");
-                if (dialog.run() == Gtk::RESPONSE_YES) {
-                    system("gnome-session-quit --logout --no-prompt &");
-                }
-            }
-        } else {
-            add_log_ui(msg);
-        }
-    }
-}
-
-void MainWindow::add_log_ui(const std::string& message) {
-    m_RefTextBuffer->insert(m_RefTextBuffer->end(), message + "\n");
-    auto mark = m_RefTextBuffer->get_mark("last_line");
-    m_RefTextBuffer->move_mark(mark, m_RefTextBuffer->end());
-    if (m_LogView.get_realized()) m_LogView.scroll_to(mark);
-}
-
-void MainWindow::set_ui_locked(bool locked) {
-    m_ButtonBackup.set_sensitive(!locked);
-    m_ButtonRestore.set_sensitive(!locked);
-    m_ButtonSelectVault.set_sensitive(!locked);
-    m_CheckDebugMode.set_sensitive(!locked);
-    
-    if (!locked) {
-        m_StatusLabel.override_color(m_JobSuccess ? Gdk::RGBA("#44ff44") : Gdk::RGBA("#ff4444"));
-        m_StatusLabel.set_text(m_JobSuccess ? "Job Completed Successfully." : "Job Completed with ERRORS.");
-    }
-}
-
-void MainWindow::run_backup_job(JobConfig config, std::string home_dir) {
-    m_JobSuccess = true; std::error_code ec;
-    queue_log("--- Starting Backup ---");
-    std::string temp_dir = "/tmp/gvault_pack";
-    fs::remove_all(temp_dir, ec);
-    fs::create_directories(temp_dir);
-
-    if (config.themes) if(!create_tar_archive(home_dir + "/.themes", temp_dir + "/themes.tar.gz", false)) m_JobSuccess = false;
-    if (config.icons) if(!create_tar_archive(home_dir + "/.icons", temp_dir + "/icons.tar.gz", false)) m_JobSuccess = false;
-    if (config.wallpapers) {
-        std::string w_dir = get_wallpaper_directory();
-        if(!w_dir.empty()) if(!create_tar_archive(w_dir, temp_dir + "/wallpapers.tar.gz", false)) m_JobSuccess = false;
-    }
-    if (config.extensions) if(!create_tar_archive(home_dir + "/.local/share/gnome-shell/extensions", temp_dir + "/extensions.tar.gz", false)) m_JobSuccess = false;
-    
-    if (config.dconf) { 
-        queue_log("[BACKUP] Exporting GNOME Settings...");
-        if (system(("dconf dump / > " + temp_dir + "/settings.ini").c_str()) != 0) m_JobSuccess = false; 
-    }
-
-    std::string final_file = home_dir + "/" + config.vault_name + ".gbk";
-    queue_log("[BACKUP] Compiling final vault...");
-    if(!create_tar_archive(temp_dir, final_file, true)) m_JobSuccess = false;
-    
-    fs::remove_all(temp_dir, ec);
-    queue_log("__UNLOCK_UI__");
-    m_WorkerRunning = false;
-}
-
-void MainWindow::on_button_backup_clicked() {
-    Gtk::MessageDialog dialog(*this, "Vault Name", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL);
-    Gtk::Entry entry; entry.set_text("GnomeVaultBackup");
-    dialog.get_content_area()->pack_start(entry, Gtk::PACK_SHRINK);
-    dialog.show_all_children();
-    if (dialog.run() == Gtk::RESPONSE_OK) {
-        m_IsDebugMode = m_CheckDebugMode.get_active();
-        m_LastJobWasRestore = false;
-        set_ui_locked(true); m_WorkerRunning = true;
-        m_StatusLabel.override_color(Gdk::RGBA("#ffffff"));
-        m_StatusLabel.set_text("Backup in progress...");
-        
-        JobConfig cfg;
-        cfg.themes = m_CheckThemesBackup.get_active(); cfg.icons = m_CheckIconsBackup.get_active();
-        cfg.wallpapers = m_CheckWallpapersBackup.get_active(); cfg.extensions = m_CheckExtensionsBackup.get_active();
-        cfg.dconf = m_CheckDconfBackup.get_active(); cfg.dry_run = false; cfg.vault_name = entry.get_text();
-        std::thread(&MainWindow::run_backup_job, this, cfg, std::string(std::getenv("HOME"))).detach();
-    }
-}
-
-void MainWindow::run_restore_job(JobConfig config, std::string home_dir) {
-    m_JobSuccess = true; std::error_code ec;
-    queue_log("--- Starting Clean Restore ---");
-
-    auto nuke_leftovers = [&](const std::string& path) {
-        fs::remove_all(path + "_vault_new", ec);
-        fs::remove_all(path + "_vault_old", ec);
-    };
-    nuke_leftovers(home_dir + "/.themes");
-    nuke_leftovers(home_dir + "/.icons");
-    nuke_leftovers(home_dir + "/.local/share/gnome-shell/extensions");
-
-    if (config.extensions && !config.dry_run) {
-        queue_log("[SAFE] Disabling extensions to prevent GNOME crash...");
-        system("gsettings set org.gnome.shell disable-user-extensions true");
-    }
-
-    std::string temp_unpack = "/tmp/gvault_unpack";
-    fs::remove_all(temp_unpack, ec);
-    fs::create_directories(temp_unpack);
-    
-    queue_log("[RESTORE] Unpacking vault structure...");
-    if (!extract_tar_archive(config.custom_restore_path, temp_unpack, false, false)) m_JobSuccess = false;
-
-    std::string work_path = temp_unpack;
-    for (const auto& entry : fs::recursive_directory_iterator(temp_unpack)) {
-        if (entry.path().filename() == "settings.ini") { work_path = entry.path().parent_path().string(); break; }
-    }
-
-    auto atomic_restore = [&](const std::string& arch_name, const std::string& live_path, const std::string& label) {
-        std::string arch_full = work_path + "/" + arch_name + ".tar.gz";
-        if (fs::exists(arch_full)) {
-            queue_log("[RESTORE] Swapping " + label + "...");
-            std::string shadow = live_path + "_vault_new";
-            std::string old_path = live_path + "_vault_old";
-            
-            fs::remove_all(shadow, ec);
-            fs::remove_all(old_path, ec);
-            fs::create_directories(shadow);
-            
-            if (extract_tar_archive(arch_full, shadow, config.dry_run, false)) {
-                if (!config.dry_run) {
-                    sync();
-                    if (fs::exists(live_path)) {
-                        fs::rename(live_path, old_path, ec);
-                        if (ec) { queue_log("  !!! Warning: Could not isolate old " + label + ". Retrying via delete."); fs::remove_all(live_path, ec); }
-                    }
-                    fs::rename(shadow, live_path, ec);
-                    if (ec) { 
-                        queue_log("  !!! ERROR: Rename failed for " + label + "."); 
-                        m_JobSuccess = false; 
-                    } else { 
-                        if (m_IsDebugMode) queue_log("  -> " + label + " swapped successfully."); 
-                        fs::remove_all(old_path, ec); 
-                    }
-                }
-            } else m_JobSuccess = false;
-        }
-    };
-
-    if (config.themes) atomic_restore("themes", home_dir + "/.themes", "Themes");
-    if (config.icons) atomic_restore("icons", home_dir + "/.icons", "Icons");
-    if (config.extensions) atomic_restore("extensions", home_dir + "/.local/share/gnome-shell/extensions", "Extensions");
-    
-    if (config.wallpapers && fs::exists(work_path + "/wallpapers.tar.gz")) {
-        queue_log("[RESTORE] Restoring Wallpapers...");
-        if (!extract_tar_archive(work_path + "/wallpapers.tar.gz", "/", config.dry_run, true)) m_JobSuccess = false;
-    }
-
-    if (config.dconf && fs::exists(work_path + "/settings.ini") && !config.dry_run) {
-        queue_log("[RESTORE] Injecting Dconf settings...");
-        if (system(("dconf load / < " + work_path + "/settings.ini").c_str()) != 0) m_JobSuccess = false;
-    }
-
-    if (config.extensions && !config.dry_run) {
-        queue_log("[SAFE] Re-enabling extensions...");
-        system("gsettings set org.gnome.shell disable-user-extensions false");
-    }
-
-    fs::remove_all(temp_unpack, ec);
-    queue_log("__UNLOCK_UI__");
-}
-
-void MainWindow::on_button_restore_clicked() {
-    if (m_SelectedVaultPath.empty()) return;
-    
-    m_IsDebugMode = m_CheckDebugMode.get_active();
-    m_LastJobWasRestore = true;
-    set_ui_locked(true); m_WorkerRunning = true;
-    
-    m_StatusLabel.override_color(Gdk::RGBA("#ffffff"));
-    m_StatusLabel.set_text("Restore in progress...");
-    
-    JobConfig cfg;
-    cfg.themes = m_CheckThemesRestore.get_active(); cfg.icons = m_CheckIconsRestore.get_active();
-    cfg.wallpapers = m_CheckWallpapersRestore.get_active(); cfg.extensions = m_CheckExtensionsRestore.get_active();
-    cfg.dconf = m_CheckDconfRestore.get_active(); cfg.dry_run = m_CheckDryRunRestore.get_active();
-    cfg.custom_restore_path = m_SelectedVaultPath;
-    
-    std::thread(&MainWindow::run_restore_job, this, cfg, std::string(std::getenv("HOME"))).detach();
-}
-
-bool MainWindow::create_tar_archive(const std::string& source_dir, const std::string& out_filename, bool strip_path) {
-    struct archive *a = archive_write_new();
-    archive_write_add_filter_gzip(a);
-    archive_write_set_format_pax_restricted(a);
-    archive_write_open_filename(a, out_filename.c_str());
-    fs::path base_path = fs::absolute(source_dir);
-    bool ok = true;
-    
-    if (m_IsDebugMode) queue_log("  -> Compressing: " + source_dir);
-
-    for (const auto& dirEntry : fs::recursive_directory_iterator(base_path, fs::directory_options::skip_permission_denied)) {
-        std::string full = dirEntry.path().string();
-        std::string store = strip_path ? fs::relative(dirEntry.path(), base_path).string() : full;
-        if (store == "." || store == "..") continue;
-        struct archive_entry *entry = archive_entry_new();
-        archive_entry_set_pathname(entry, store.c_str());
-        struct stat st;
-        if (lstat(full.c_str(), &st) != 0) { archive_entry_free(entry); ok = false; continue; }
-        archive_entry_copy_stat(entry, &st);
-        if (S_ISLNK(st.st_mode)) {
-             char link_target[4096]; ssize_t len = readlink(full.c_str(), link_target, sizeof(link_target)-1);
-             if (len != -1) { link_target[len]='\0'; archive_entry_set_symlink(entry, link_target); }
-        }
-        archive_write_header(a, entry);
-        if (m_IsDebugMode) queue_log("    -> Packed: " + store);
-        if (S_ISREG(st.st_mode)) {
-            int fd = ::open(full.c_str(), O_RDONLY);
-            if (fd >= 0) {
-                char buff[65536]; ssize_t len;
-                while ((len = ::read(fd, buff, sizeof(buff))) > 0) archive_write_data(a, buff, len);
-                ::close(fd);
-            } else ok = false;
-        }
-        archive_entry_free(entry);
-    }
-    archive_write_close(a); archive_write_free(a);
-    return ok;
-}
-
-bool MainWindow::extract_tar_archive(const std::string& archive_path, const std::string& dest_dir, bool dry_run, bool use_absolute) {
-    struct archive *a = archive_read_new();
-    archive_read_support_format_all(a);
-    archive_read_support_filter_all(a);
-    if (archive_read_open_filename(a, archive_path.c_str(), 10240) != ARCHIVE_OK) return false;
-    int flags = ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_UNLINK | ARCHIVE_EXTRACT_SECURE_NODOTDOT;
-    struct archive_entry *entry;
-    bool status = true;
-    
-    while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
-        std::string stored_path = archive_entry_pathname(entry);
-        if (!use_absolute) {
-            size_t pos = stored_path.find("/.themes/");
-            if (pos == std::string::npos) pos = stored_path.find("/.icons/");
-            if (pos == std::string::npos) pos = stored_path.find("/extensions/");
-            if (pos != std::string::npos) {
-                size_t start = stored_path.find('/', pos + 1);
-                if (start != std::string::npos) stored_path = stored_path.substr(start + 1);
-            }
-        }
-        std::string target = use_absolute ? archive_entry_pathname(entry) : dest_dir + "/" + stored_path;
-        archive_entry_set_pathname(entry, target.c_str());
-        
-        if (dry_run) { 
-            if (m_IsDebugMode) queue_log("    -> [DRY] " + target); 
-            archive_read_data_skip(a); 
-        } else {
-            if (use_absolute && fs::exists(target) && fs::is_regular_file(target)) {
-                int fd = ::open(target.c_str(), O_WRONLY | O_TRUNC);
-                if (fd >= 0) ::close(fd);
-            }
-            if (archive_read_extract(a, entry, flags) != ARCHIVE_OK) {
-                if (!fs::is_directory(target)) {
-                    if (m_IsDebugMode) queue_log("      !!! FAIL: " + std::string(archive_error_string(a)) + " -> " + target);
-                    status = false;
-                }
-            } else {
-                if (m_IsDebugMode) queue_log("    -> Restored: " + target);
-            }
-        }
-    }
-    archive_read_close(a); archive_read_free(a);
-    return status;
-}
-
-std::string MainWindow::get_wallpaper_directory() {
-    char buffer[256]; std::string result = "";
-    FILE* pipe = popen("gsettings get org.gnome.desktop.background picture-uri-dark 2>/dev/null", "r");
-    if (pipe) { while (fgets(buffer, sizeof(buffer), pipe) != nullptr) result += buffer; pclose(pipe); }
-    size_t file_pos = result.find("file://");
-    if (file_pos != std::string::npos) {
-        std::string path = result.substr(file_pos + 7);
-        path.erase(std::remove(path.begin(), path.end(), '\''), path.end());
-        path.erase(std::remove(path.begin(), path.end(), '\n'), path.end());
-        return fs::path(path).parent_path().string();
-    }
-    return "";
-}
+ #include "MainWindow.hpp"
+ #include <iostream>
+ #include <filesystem>
+ #include <archive.h>
+ #include <archive_entry.h>
+ #include <fcntl.h>
+ #include <unistd.h>
+ #include <cstdlib>
+ #include <cstdio>
+ #include <algorithm>
+ #include <chrono>
+ #include <iomanip>
+ #include <sstream>
+ #include <set>
+ 
+ namespace fs = std::filesystem;
+ 
+ MainWindow::MainWindow()
+ : m_HeaderBar(), m_MainLayout(Gtk::ORIENTATION_VERTICAL, 0), m_Notebook(),
+   m_BottomBox(Gtk::ORIENTATION_HORIZONTAL, 10), m_StatusLabel("Ready."), 
+   m_CheckDebugMode("Write Debug Log to Disk (~/GnomeSettingsVault.log)"), m_VBoxBackup(Gtk::ORIENTATION_VERTICAL, 10),
+   m_LabelBackupInstruction("<span size='large' weight='bold'>Backup</span>"),
+   m_CheckThemesBackup("GTK Themes"), m_CheckIconsBackup("Icons"),
+   m_CheckWallpapersBackup("Wallpapers"), m_CheckExtensionsBackup("GNOME Extensions"),
+   m_CheckDconfBackup("GNOME Settings"), m_ButtonBackup("Start Backup"),
+   m_VBoxRestore(Gtk::ORIENTATION_VERTICAL, 10),
+   m_LabelRestoreInstruction("<span size='large' weight='bold'>Restore from Vault</span>"),
+   m_ButtonSelectVault("Select .gbk Vault File"), m_LabelSelectedVault("No vault selected"),
+   m_CheckThemesRestore("GTK Themes"), m_CheckIconsRestore("Icons"),
+   m_CheckWallpapersRestore("Wallpapers"), m_CheckExtensionsRestore("GNOME Extensions"),
+   m_CheckDconfRestore("GNOME Settings"), m_CheckDryRunRestore("Dry Run"),
+   m_ButtonRestore("Start Restore"), m_WorkerRunning(false), m_JobSuccess(true), 
+   m_IsDebugMode(false), m_LastJobWasRestore(false)
+ {
+     m_Dispatcher.connect(sigc::mem_fun(*this, &MainWindow::on_dispatcher_ping));
+     set_default_size(1000, 700);
+     m_HeaderBar.set_title("GnomeSettingsVault 0.2");
+     m_HeaderBar.set_show_close_button(true);
+     set_titlebar(m_HeaderBar);
+ 
+     m_LabelBackupInstruction.set_use_markup(true);
+     m_LabelRestoreInstruction.set_use_markup(true);
+ 
+     m_RefTextBuffer = Gtk::TextBuffer::create();
+     auto selection_tag = m_RefTextBuffer->create_tag("selection_orange");
+     selection_tag->property_background() = "#ff8c00";
+     selection_tag->property_foreground() = "#000000";
+     
+     m_LogView.set_buffer(m_RefTextBuffer);
+     m_LogView.set_editable(false);
+     m_LogView.set_cursor_visible(true);
+     m_LogView.set_can_focus(true);
+     
+     m_RefTextBuffer->signal_mark_set().connect([this, selection_tag](const Gtk::TextBuffer::iterator& iter, const Glib::RefPtr<Gtk::TextMark>& mark){
+         Gtk::TextBuffer::iterator start, end;
+         if (m_RefTextBuffer->get_selection_bounds(start, end)) {
+             m_RefTextBuffer->apply_tag(selection_tag, start, end);
+         } else {
+             m_RefTextBuffer->remove_tag(selection_tag, m_RefTextBuffer->begin(), m_RefTextBuffer->end());
+         }
+     });
+ 
+     m_LogView.override_background_color(Gdk::RGBA("#1e1e1e")); 
+     m_LogView.override_color(Gdk::RGBA("#dcdcdc"));
+     
+     m_RefTextBuffer->create_mark("last_line", m_RefTextBuffer->end());
+     m_ScrolledWindow.add(m_LogView);
+     m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
+ 
+     m_VBoxBackup.set_border_width(20);
+     m_VBoxBackup.pack_start(m_LabelBackupInstruction, Gtk::PACK_SHRINK);
+     m_VBoxBackup.pack_start(m_CheckThemesBackup, Gtk::PACK_SHRINK);
+     m_VBoxBackup.pack_start(m_CheckIconsBackup, Gtk::PACK_SHRINK);
+     m_VBoxBackup.pack_start(m_CheckWallpapersBackup, Gtk::PACK_SHRINK);
+     m_VBoxBackup.pack_start(m_CheckExtensionsBackup, Gtk::PACK_SHRINK);
+     m_VBoxBackup.pack_start(m_CheckDconfBackup, Gtk::PACK_SHRINK);
+     m_VBoxBackup.pack_end(m_ButtonBackup, Gtk::PACK_SHRINK);
+     
+     m_VBoxRestore.set_border_width(20);
+     m_VBoxRestore.pack_start(m_LabelRestoreInstruction, Gtk::PACK_SHRINK);
+     m_VBoxRestore.pack_start(m_ButtonSelectVault, Gtk::PACK_SHRINK);
+     m_VBoxRestore.pack_start(m_LabelSelectedVault, Gtk::PACK_SHRINK);
+     m_VBoxRestore.pack_start(m_CheckThemesRestore, Gtk::PACK_SHRINK);
+     m_VBoxRestore.pack_start(m_CheckIconsRestore, Gtk::PACK_SHRINK);
+     m_VBoxRestore.pack_start(m_CheckWallpapersRestore, Gtk::PACK_SHRINK);
+     m_VBoxRestore.pack_start(m_CheckExtensionsRestore, Gtk::PACK_SHRINK);
+     m_VBoxRestore.pack_start(m_CheckDconfRestore, Gtk::PACK_SHRINK);
+     m_VBoxRestore.pack_start(m_CheckDryRunRestore, Gtk::PACK_SHRINK);
+     m_VBoxRestore.pack_end(m_ButtonRestore, Gtk::PACK_SHRINK);
+ 
+     m_Notebook.append_page(m_VBoxBackup, "Backup");
+     m_Notebook.append_page(m_VBoxRestore, "Restore");
+     
+     m_BottomBox.set_border_width(10);
+     m_StatusLabel.set_halign(Gtk::ALIGN_START);
+     m_BottomBox.pack_start(m_StatusLabel, Gtk::PACK_EXPAND_WIDGET);
+     m_BottomBox.pack_end(m_CheckDebugMode, Gtk::PACK_SHRINK);
+ 
+     m_MainLayout.pack_start(m_Notebook, Gtk::PACK_SHRINK);
+     m_MainLayout.pack_start(m_ScrolledWindow, Gtk::PACK_EXPAND_WIDGET);
+     m_MainLayout.pack_start(m_BottomBox, Gtk::PACK_SHRINK);
+ 
+     m_ButtonBackup.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_button_backup_clicked));
+     m_ButtonRestore.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_button_restore_clicked));
+     m_ButtonSelectVault.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_button_select_vault_clicked));
+ 
+     add(m_MainLayout);
+     show_all_children();
+ }
+ 
+ MainWindow::~MainWindow() {}
+ 
+ void MainWindow::scan_vault_contents(const std::string& path) {
+     struct archive *a = archive_read_new();
+     struct archive_entry *entry;
+     archive_read_support_format_all(a);
+     archive_read_support_filter_all(a);
+     std::set<std::string> found;
+     if (archive_read_open_filename(a, path.c_str(), 10240) == ARCHIVE_OK) {
+         while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
+             std::string p = archive_entry_pathname(entry);
+             if (p.find("themes.tar.gz") != std::string::npos) found.insert("themes");
+             if (p.find("icons.tar.gz") != std::string::npos) found.insert("icons");
+             if (p.find("wallpapers.tar.gz") != std::string::npos) found.insert("wallpapers");
+             if (p.find("extensions.tar.gz") != std::string::npos) found.insert("extensions");
+             if (p.find("settings.ini") != std::string::npos) found.insert("dconf");
+         }
+     }
+     archive_read_free(a);
+     m_CheckThemesRestore.set_active(found.count("themes"));
+     m_CheckIconsRestore.set_active(found.count("icons"));
+     m_CheckWallpapersRestore.set_active(found.count("wallpapers"));
+     m_CheckExtensionsRestore.set_active(found.count("extensions"));
+     m_CheckDconfRestore.set_active(found.count("dconf"));
+ }
+ 
+ void MainWindow::on_button_select_vault_clicked() {
+     Gtk::FileChooserDialog dialog("Choose vault", Gtk::FILE_CHOOSER_ACTION_OPEN);
+     dialog.set_transient_for(*this);
+     dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
+     dialog.add_button("_Open", Gtk::RESPONSE_OK);
+     if (dialog.run() == Gtk::RESPONSE_OK) {
+         m_SelectedVaultPath = dialog.get_filename();
+         m_LabelSelectedVault.set_text("Selected: " + fs::path(m_SelectedVaultPath).filename().string());
+         scan_vault_contents(m_SelectedVaultPath);
+         add_log_ui("Vault loaded.");
+     }
+ }
+ 
+ void MainWindow::queue_log(const std::string& message) {
+     // Only write to disk if debug mode is explicitly checked
+     if (m_IsDebugMode) {
+         std::ofstream log_file(std::string(std::getenv("HOME")) + "/GnomeSettingsVault.log", std::ios::app);
+         if (log_file.is_open()) { log_file << message << std::endl; log_file.close(); }
+     }
+     
+     std::lock_guard<std::mutex> lock(m_LogMutex);
+     m_LogQueue.push(message);
+     m_Dispatcher.emit();
+ }
+ 
+ void MainWindow::on_dispatcher_ping() {
+     std::lock_guard<std::mutex> lock(m_LogMutex);
+     while (!m_LogQueue.empty()) {
+         std::string msg = m_LogQueue.front();
+         m_LogQueue.pop();
+         if (msg == "__UNLOCK_UI__") {
+             set_ui_locked(false);
+             
+             // Trigger Logout Prompt if it was a successful restore
+             if (m_JobSuccess && m_LastJobWasRestore) {
+                 Gtk::MessageDialog dialog(*this, "Restore Complete", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
+                 dialog.set_secondary_text("Settings and components have been successfully restored.\n\nGNOME needs to restart to apply all changes smoothly. Would you like to log out now?");
+                 if (dialog.run() == Gtk::RESPONSE_YES) {
+                     system("gnome-session-quit --logout --no-prompt &");
+                 }
+             }
+         } else {
+             add_log_ui(msg);
+         }
+     }
+ }
+ 
+ void MainWindow::add_log_ui(const std::string& message) {
+     m_RefTextBuffer->insert(m_RefTextBuffer->end(), message + "\n");
+     auto mark = m_RefTextBuffer->get_mark("last_line");
+     m_RefTextBuffer->move_mark(mark, m_RefTextBuffer->end());
+     if (m_LogView.get_realized()) m_LogView.scroll_to(mark);
+ }
+ 
+ void MainWindow::set_ui_locked(bool locked) {
+     m_ButtonBackup.set_sensitive(!locked);
+     m_ButtonRestore.set_sensitive(!locked);
+     m_ButtonSelectVault.set_sensitive(!locked);
+     m_CheckDebugMode.set_sensitive(!locked);
+     
+     if (!locked) {
+         m_StatusLabel.override_color(m_JobSuccess ? Gdk::RGBA("#44ff44") : Gdk::RGBA("#ff4444"));
+         m_StatusLabel.set_text(m_JobSuccess ? "Job Completed Successfully." : "Job Completed with ERRORS.");
+     }
+ }
+ 
+ void MainWindow::run_backup_job(JobConfig config, std::string home_dir) {
+     m_JobSuccess = true; std::error_code ec;
+     queue_log("--- Starting Backup ---");
+     std::string temp_dir = "/tmp/gvault_pack";
+     fs::remove_all(temp_dir, ec);
+     fs::create_directories(temp_dir);
+ 
+     if (config.themes) if(!create_tar_archive(home_dir + "/.themes", temp_dir + "/themes.tar.gz", false)) m_JobSuccess = false;
+     if (config.icons) if(!create_tar_archive(home_dir + "/.icons", temp_dir + "/icons.tar.gz", false)) m_JobSuccess = false;
+     if (config.wallpapers) {
+         std::string w_dir = get_wallpaper_directory();
+         if(!w_dir.empty()) if(!create_tar_archive(w_dir, temp_dir + "/wallpapers.tar.gz", false)) m_JobSuccess = false;
+     }
+     if (config.extensions) if(!create_tar_archive(home_dir + "/.local/share/gnome-shell/extensions", temp_dir + "/extensions.tar.gz", false)) m_JobSuccess = false;
+     
+     if (config.dconf) { 
+         queue_log("[BACKUP] Exporting GNOME Settings...");
+         if (system(("dconf dump / > " + temp_dir + "/settings.ini").c_str()) != 0) m_JobSuccess = false; 
+     }
+ 
+     std::string final_file = home_dir + "/" + config.vault_name + ".gbk";
+     queue_log("[BACKUP] Compiling final vault...");
+     if(!create_tar_archive(temp_dir, final_file, true)) m_JobSuccess = false;
+     
+     fs::remove_all(temp_dir, ec);
+     queue_log("__UNLOCK_UI__");
+     m_WorkerRunning = false;
+ }
+ 
+ void MainWindow::on_button_backup_clicked() {
+     Gtk::MessageDialog dialog(*this, "Vault Name", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL);
+     Gtk::Entry entry; entry.set_text("GnomeVaultBackup");
+     dialog.get_content_area()->pack_start(entry, Gtk::PACK_SHRINK);
+     dialog.show_all_children();
+     if (dialog.run() == Gtk::RESPONSE_OK) {
+         m_IsDebugMode = m_CheckDebugMode.get_active();
+         m_LastJobWasRestore = false;
+         set_ui_locked(true); m_WorkerRunning = true;
+         m_StatusLabel.override_color(Gdk::RGBA("#ffffff"));
+         m_StatusLabel.set_text("Backup in progress...");
+         
+         JobConfig cfg;
+         cfg.themes = m_CheckThemesBackup.get_active(); cfg.icons = m_CheckIconsBackup.get_active();
+         cfg.wallpapers = m_CheckWallpapersBackup.get_active(); cfg.extensions = m_CheckExtensionsBackup.get_active();
+         cfg.dconf = m_CheckDconfBackup.get_active(); cfg.dry_run = false; cfg.vault_name = entry.get_text();
+         std::thread(&MainWindow::run_backup_job, this, cfg, std::string(std::getenv("HOME"))).detach();
+     }
+ }
+ 
+ void MainWindow::run_restore_job(JobConfig config, std::string home_dir) {
+     m_JobSuccess = true; std::error_code ec;
+     queue_log("--- Starting Clean Restore ---");
+ 
+     auto nuke_leftovers = [&](const std::string& path) {
+         fs::remove_all(path + "_vault_new", ec);
+         fs::remove_all(path + "_vault_old", ec);
+     };
+     nuke_leftovers(home_dir + "/.themes");
+     nuke_leftovers(home_dir + "/.icons");
+     nuke_leftovers(home_dir + "/.local/share/gnome-shell/extensions");
+ 
+     if (config.extensions && !config.dry_run) {
+         queue_log("[SAFE] Disabling extensions to prevent GNOME crash...");
+         system("gsettings set org.gnome.shell disable-user-extensions true");
+     }
+ 
+     std::string temp_unpack = "/tmp/gvault_unpack";
+     fs::remove_all(temp_unpack, ec);
+     fs::create_directories(temp_unpack);
+     
+     queue_log("[RESTORE] Unpacking vault structure...");
+     if (!extract_tar_archive(config.custom_restore_path, temp_unpack, false, false)) m_JobSuccess = false;
+ 
+     std::string work_path = temp_unpack;
+     for (const auto& entry : fs::recursive_directory_iterator(temp_unpack)) {
+         if (entry.path().filename() == "settings.ini") { work_path = entry.path().parent_path().string(); break; }
+     }
+ 
+     auto atomic_restore = [&](const std::string& arch_name, const std::string& live_path, const std::string& label) {
+         std::string arch_full = work_path + "/" + arch_name + ".tar.gz";
+         if (fs::exists(arch_full)) {
+             queue_log("[RESTORE] Swapping " + label + "...");
+             std::string shadow = live_path + "_vault_new";
+             std::string old_path = live_path + "_vault_old";
+             
+             fs::remove_all(shadow, ec);
+             fs::remove_all(old_path, ec);
+             fs::create_directories(shadow);
+             
+             if (extract_tar_archive(arch_full, shadow, config.dry_run, false)) {
+                 if (!config.dry_run) {
+                     sync();
+                     if (fs::exists(live_path)) {
+                         fs::rename(live_path, old_path, ec);
+                         if (ec) { queue_log("  !!! Warning: Could not isolate old " + label + ". Retrying via delete."); fs::remove_all(live_path, ec); }
+                     }
+                     fs::rename(shadow, live_path, ec);
+                     if (ec) { 
+                         queue_log("  !!! ERROR: Rename failed for " + label + "."); 
+                         m_JobSuccess = false; 
+                     } else { 
+                         queue_log("  -> " + label + " swapped successfully."); 
+                         fs::remove_all(old_path, ec); 
+                     }
+                 }
+             } else m_JobSuccess = false;
+         }
+     };
+ 
+     if (config.themes) atomic_restore("themes", home_dir + "/.themes", "Themes");
+     if (config.icons) atomic_restore("icons", home_dir + "/.icons", "Icons");
+     if (config.extensions) atomic_restore("extensions", home_dir + "/.local/share/gnome-shell/extensions", "Extensions");
+     
+     if (config.wallpapers && fs::exists(work_path + "/wallpapers.tar.gz")) {
+         queue_log("[RESTORE] Restoring Wallpapers...");
+         if (!extract_tar_archive(work_path + "/wallpapers.tar.gz", "/", config.dry_run, true)) m_JobSuccess = false;
+     }
+ 
+     if (config.dconf && fs::exists(work_path + "/settings.ini") && !config.dry_run) {
+         queue_log("[RESTORE] Injecting Dconf settings...");
+         if (system(("dconf load / < " + work_path + "/settings.ini").c_str()) != 0) m_JobSuccess = false;
+     }
+ 
+     if (config.extensions && !config.dry_run) {
+         queue_log("[SAFE] Re-enabling extensions...");
+         system("gsettings set org.gnome.shell disable-user-extensions false");
+     }
+ 
+     fs::remove_all(temp_unpack, ec);
+     queue_log("__UNLOCK_UI__");
+ }
+ 
+ void MainWindow::on_button_restore_clicked() {
+     if (m_SelectedVaultPath.empty()) return;
+     
+     m_IsDebugMode = m_CheckDebugMode.get_active();
+     m_LastJobWasRestore = true;
+     set_ui_locked(true); m_WorkerRunning = true;
+     
+     m_StatusLabel.override_color(Gdk::RGBA("#ffffff"));
+     m_StatusLabel.set_text("Restore in progress...");
+     
+     JobConfig cfg;
+     cfg.themes = m_CheckThemesRestore.get_active(); cfg.icons = m_CheckIconsRestore.get_active();
+     cfg.wallpapers = m_CheckWallpapersRestore.get_active(); cfg.extensions = m_CheckExtensionsRestore.get_active();
+     cfg.dconf = m_CheckDconfRestore.get_active(); cfg.dry_run = m_CheckDryRunRestore.get_active();
+     cfg.custom_restore_path = m_SelectedVaultPath;
+     
+     std::thread(&MainWindow::run_restore_job, this, cfg, std::string(std::getenv("HOME"))).detach();
+ }
+ 
+ bool MainWindow::create_tar_archive(const std::string& source_dir, const std::string& out_filename, bool strip_path) {
+     struct archive *a = archive_write_new();
+     archive_write_add_filter_gzip(a);
+     archive_write_set_format_pax_restricted(a);
+     archive_write_open_filename(a, out_filename.c_str());
+     fs::path base_path = fs::absolute(source_dir);
+     bool ok = true;
+     
+     queue_log("  -> Compressing: " + source_dir);
+ 
+     for (const auto& dirEntry : fs::recursive_directory_iterator(base_path, fs::directory_options::skip_permission_denied)) {
+         std::string full = dirEntry.path().string();
+         std::string store = strip_path ? fs::relative(dirEntry.path(), base_path).string() : full;
+         if (store == "." || store == "..") continue;
+         struct archive_entry *entry = archive_entry_new();
+         archive_entry_set_pathname(entry, store.c_str());
+         struct stat st;
+         if (lstat(full.c_str(), &st) != 0) { archive_entry_free(entry); ok = false; continue; }
+         archive_entry_copy_stat(entry, &st);
+         if (S_ISLNK(st.st_mode)) {
+              char link_target[4096]; ssize_t len = readlink(full.c_str(), link_target, sizeof(link_target)-1);
+              if (len != -1) { link_target[len]='\0'; archive_entry_set_symlink(entry, link_target); }
+         }
+         archive_write_header(a, entry);
+         queue_log("    -> Packed: " + store);
+         if (S_ISREG(st.st_mode)) {
+             int fd = ::open(full.c_str(), O_RDONLY);
+             if (fd >= 0) {
+                 char buff[65536]; ssize_t len;
+                 while ((len = ::read(fd, buff, sizeof(buff))) > 0) archive_write_data(a, buff, len);
+                 ::close(fd);
+             } else ok = false;
+         }
+         archive_entry_free(entry);
+     }
+     archive_write_close(a); archive_write_free(a);
+     return ok;
+ }
+ 
+ bool MainWindow::extract_tar_archive(const std::string& archive_path, const std::string& dest_dir, bool dry_run, bool use_absolute) {
+     struct archive *a = archive_read_new();
+     archive_read_support_format_all(a);
+     archive_read_support_filter_all(a);
+     if (archive_read_open_filename(a, archive_path.c_str(), 10240) != ARCHIVE_OK) return false;
+     int flags = ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_UNLINK | ARCHIVE_EXTRACT_SECURE_NODOTDOT;
+     struct archive_entry *entry;
+     bool status = true;
+     
+     while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
+         std::string stored_path = archive_entry_pathname(entry);
+         if (!use_absolute) {
+             size_t pos = stored_path.find("/.themes/");
+             if (pos == std::string::npos) pos = stored_path.find("/.icons/");
+             if (pos == std::string::npos) pos = stored_path.find("/extensions/");
+             if (pos != std::string::npos) {
+                 size_t start = stored_path.find('/', pos + 1);
+                 if (start != std::string::npos) stored_path = stored_path.substr(start + 1);
+             }
+         }
+         std::string target = use_absolute ? archive_entry_pathname(entry) : dest_dir + "/" + stored_path;
+         archive_entry_set_pathname(entry, target.c_str());
+         
+         if (dry_run) { 
+             queue_log("    -> [DRY] " + target); 
+             archive_read_data_skip(a); 
+         } else {
+             if (use_absolute && fs::exists(target) && fs::is_regular_file(target)) {
+                 int fd = ::open(target.c_str(), O_WRONLY | O_TRUNC);
+                 if (fd >= 0) ::close(fd);
+             }
+             if (archive_read_extract(a, entry, flags) != ARCHIVE_OK) {
+                 if (!fs::is_directory(target)) {
+                     queue_log("      !!! FAIL: " + std::string(archive_error_string(a)) + " -> " + target);
+                     status = false;
+                 }
+             } else {
+                 queue_log("    -> Restored: " + target);
+             }
+         }
+     }
+     archive_read_close(a); archive_read_free(a);
+     return status;
+ }
+ 
+ std::string MainWindow::get_wallpaper_directory() {
+     char buffer[256]; std::string result = "";
+     FILE* pipe = popen("gsettings get org.gnome.desktop.background picture-uri-dark 2>/dev/null", "r");
+     if (pipe) { while (fgets(buffer, sizeof(buffer), pipe) != nullptr) result += buffer; pclose(pipe); }
+     size_t file_pos = result.find("file://");
+     if (file_pos != std::string::npos) {
+         std::string path = result.substr(file_pos + 7);
+         path.erase(std::remove(path.begin(), path.end(), '\''), path.end());
+         path.erase(std::remove(path.begin(), path.end(), '\n'), path.end());
+         return fs::path(path).parent_path().string();
+     }
+     return "";
+ }

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 # Auto-generated Makefile
 CXX = g++
-CXXFLAGS = -std=c++17 -Wall -I/usr/include/gtkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gtkmm-3.0/include -I/usr/include/giomm-2.4 -I/usr/lib/x86_64-linux-gnu/giomm-2.4/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glibmm-2.4 -I/usr/lib/x86_64-linux-gnu/glibmm-2.4/include -I/usr/include/sigc++-2.0 -I/usr/lib/x86_64-linux-gnu/sigc++-2.0/include -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/gio-unix-2.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/cairomm-1.0 -I/usr/lib/x86_64-linux-gnu/cairomm-1.0/include -I/usr/include/pangomm-1.4 -I/usr/lib/x86_64-linux-gnu/pangomm-1.4/include -I/usr/include/atkmm-1.6 -I/usr/lib/x86_64-linux-gnu/atkmm-1.6/include -I/usr/include/gtk-3.0/unix-print -I/usr/include/gdkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gdkmm-3.0/include -pthread  
+CXXFLAGS = -std=c++17 -Wall -I/usr/include/gtkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gtkmm-3.0/include -I/usr/include/giomm-2.4 -I/usr/lib/x86_64-linux-gnu/giomm-2.4/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/sysprof-6 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glibmm-2.4 -I/usr/lib/x86_64-linux-gnu/glibmm-2.4/include -I/usr/include/sigc++-2.0 -I/usr/lib/x86_64-linux-gnu/sigc++-2.0/include -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/webp -I/usr/include/gio-unix-2.0 -I/usr/include/cloudproviders -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/cairomm-1.0 -I/usr/lib/x86_64-linux-gnu/cairomm-1.0/include -I/usr/include/pangomm-1.4 -I/usr/lib/x86_64-linux-gnu/pangomm-1.4/include -I/usr/include/atkmm-1.6 -I/usr/lib/x86_64-linux-gnu/atkmm-1.6/include -I/usr/include/gtk-3.0/unix-print -I/usr/include/gdkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gdkmm-3.0/include -pthread  
 LDFLAGS = -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lgtk-3 -lgdk-3 -lz -latk-1.0 -lcairo-gobject -lgio-2.0 -lpangomm-1.4 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lcairo -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0  -larchive 
 
 SOURCES = main.cpp MainWindow.cpp

+ 48 - 48
main.cpp

@@ -3,51 +3,51 @@
  * Copyright (C) 2026 Nicole Portas, nicole@equalmass.com
  */
 
-#include "MainWindow.hpp"
-#include <gtkmm/application.h>
-#include <gtk/gtk.h>
-#include <iostream>
-#include <cstdlib>
-#include <sys/stat.h>
-#include <string>
-
-int main(int argc, char *argv[]) {
-    // --- Environment Hijack for Fontconfig ---
-    // This prevents font cache collisions in restricted environments
-    const char* user = std::getenv("USER");
-    std::string safe_cache_dir = std::string("/tmp/gnome-vault-cache-") + (user ? user : "default");
-    mkdir(safe_cache_dir.c_str(), 0777);
-    setenv("XDG_CACHE_HOME", safe_cache_dir.c_str(), 1);
-
-    // --- Identity Setup ---
-    // IMPORTANT: This string MUST match the 'StartupWMClass' in your .desktop file
-    // and ideally the 'Exec' binary name to ensure the icon pins correctly.
-    const std::string app_id = "gnome-vault"; 
-    
-    g_set_prgname(app_id.c_str());
-    g_set_application_name("GnomeSettingsVault");
-
-    if (!gtk_init_check(&argc, &argv)) {
-        std::cerr << "Bloody hell: GTK failed to initialize." << std::endl;
-        return 1;
-    }
-
-    try {
-        // We use a reverse-DNS style ID for the Application object, 
-        // but the WMClass is handled by the prgname set above.
-        auto app = Gtk::Application::create(argc, argv, "com.equalmass.gnomevault");
-        
-        MainWindow window;
-        
-        // Final hammer blow to ensure the window is identified correctly
-        window.set_wmclass(app_id, "GnomeSettingsVault");
-
-        return app->run(window);
-    } catch (const Glib::Error& ex) {
-        std::cerr << "GTK Error: " << ex.what() << std::endl;
-        return 1;
-    } catch (const std::exception& ex) {
-        std::cerr << "Standard Exception: " << ex.what() << std::endl;
-        return 1;
-    }
-}
+ #include "MainWindow.hpp"
+ #include <gtkmm/application.h>
+ #include <gtk/gtk.h>
+ #include <iostream>
+ #include <cstdlib>
+ #include <sys/stat.h>
+ #include <string>
+ 
+ int main(int argc, char *argv[]) {
+     // --- Environment Hijack for Fontconfig ---
+     // This prevents font cache collisions in restricted environments
+     const char* user = std::getenv("USER");
+     std::string safe_cache_dir = std::string("/tmp/gnome-vault-cache-") + (user ? user : "default");
+     mkdir(safe_cache_dir.c_str(), 0777);
+     setenv("XDG_CACHE_HOME", safe_cache_dir.c_str(), 1);
+ 
+     // --- Identity Setup ---
+     // IMPORTANT: This string MUST match the 'StartupWMClass' in your .desktop file
+     // and ideally the 'Exec' binary name to ensure the icon pins correctly.
+     const std::string app_id = "gnome-vault"; 
+     
+     g_set_prgname(app_id.c_str());
+     g_set_application_name("GnomeSettingsVault");
+ 
+     if (!gtk_init_check(&argc, &argv)) {
+         std::cerr << "Bloody hell: GTK failed to initialize." << std::endl;
+         return 1;
+     }
+ 
+     try {
+         // We use a reverse-DNS style ID for the Application object, 
+         // but the WMClass is handled by the prgname set above.
+         auto app = Gtk::Application::create(argc, argv, "com.equalmass.gnomevault");
+         
+         MainWindow window;
+         
+         // Final hammer blow to ensure the window is identified correctly
+         window.set_wmclass(app_id, "GnomeSettingsVault");
+ 
+         return app->run(window);
+     } catch (const Glib::Error& ex) {
+         std::cerr << "GTK Error: " << ex.what() << std::endl;
+         return 1;
+     } catch (const std::exception& ex) {
+         std::cerr << "Standard Exception: " << ex.what() << std::endl;
+         return 1;
+     }
+ }