| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557 |
- /*
- * GnomeSettingsVault - A GNOME configuration backup utility v0.3.4
- * Copyright (C) 2026 Nicole Portas, nicole@equalmass.com
- */
- #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>
- #include <glibmm/miscutils.h>
- #include <glibmm/fileutils.h>
- 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 Settings</span>"),
- m_ButtonSelectDest("Choose Destination Folder"),
- m_LabelBackupPath("No destination selected"),
- 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, 750);
- m_HeaderBar.set_title("GnomeSettingsVault 0.3.4");
- m_HeaderBar.set_show_close_button(true);
- set_titlebar(m_HeaderBar);
- set_wmclass("gnome-vault", "GnomeSettingsVault");
- m_LabelBackupInstruction.set_use_markup(true);
- m_LabelRestoreInstruction.set_use_markup(true);
-
- m_EntryVaultName.set_text("GnomeVaultBackup");
- m_EntryVaultName.set_placeholder_text("Vault filename...");
- m_RefTextBuffer = Gtk::TextBuffer::create();
- m_LogView.set_buffer(m_RefTextBuffer);
- m_LogView.set_editable(false);
- 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);
- // --- Backup Tab Layout ---
- m_VBoxBackup.set_border_width(20);
- m_VBoxBackup.pack_start(m_LabelBackupInstruction, Gtk::PACK_SHRINK);
- m_VBoxBackup.pack_start(m_EntryVaultName, Gtk::PACK_SHRINK);
- m_VBoxBackup.pack_start(m_ButtonSelectDest, Gtk::PACK_SHRINK);
- m_VBoxBackup.pack_start(m_LabelBackupPath, 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);
- // --- Restore Tab Layout ---
- 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_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_ButtonSelectDest.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_button_select_dest_clicked));
- 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::on_button_select_dest_clicked() {
- Gtk::FileChooserDialog dialog("Select Destination Folder", Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
- dialog.set_transient_for(*this);
- dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
- dialog.add_button("_Select", Gtk::RESPONSE_OK);
- if (dialog.run() == Gtk::RESPONSE_OK) {
- m_TargetBackupPath = dialog.get_filename();
- m_LabelBackupPath.set_markup("<b>Target:</b> " + m_TargetBackupPath);
- }
- }
- void MainWindow::on_button_backup_clicked() {
- if (m_TargetBackupPath.empty()) {
- Gtk::MessageDialog err(*this, "Error", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK);
- err.set_secondary_text("You haven't picked a destination folder, bloody hell.");
- err.run();
- return;
- }
- m_IsDebugMode = m_CheckDebugMode.get_active();
- m_LastJobWasRestore = false;
- set_ui_locked(true);
- m_WorkerRunning = true;
- 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 = m_EntryVaultName.get_text();
- cfg.backup_save_path = m_TargetBackupPath;
- std::thread(&MainWindow::run_backup_job, this, cfg, std::string(std::getenv("HOME"))).detach();
- }
- void MainWindow::send_notification(const std::string& title, const std::string& body) {
- auto app = Gtk::Application::get_default();
- auto notification = Gio::Notification::create(title);
- notification->set_body(body);
- app->send_notification(notification);
- }
- 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_") != std::string::npos) found.insert("themes");
- if (p.find("icons_") != 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) {
- 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);
- send_notification("Job Finished", m_JobSuccess ? "Successfully completed." : "Errors detected.");
- if (m_JobSuccess && m_LastJobWasRestore) {
- Gtk::MessageDialog dialog(*this, "Restore Complete", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
- dialog.set_secondary_text("Settings restored. Restart GNOME session 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_ButtonSelectDest.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 Successful." : "Job Failed.");
- }
- }
- void MainWindow::run_backup_job(JobConfig config, std::string home_dir) {
- m_JobSuccess = true;
- std::error_code ec;
- queue_log("--- Starting Backup ---");
- char tpl[] = "/tmp/gvault_pack_XXXXXX";
- if (mkdtemp(tpl) == nullptr) {
- queue_log("!!! ERROR: Failed to create secure temp directory.");
- m_JobSuccess = false;
- m_WorkerRunning = false;
- queue_log("__UNLOCK_UI__");
- return;
- }
- std::string temp_dir(tpl);
- auto pack_h = [&](const std::string& p, const std::string& n) {
- if (fs::exists(p)) {
- if (!create_tar_archive(p, temp_dir + "/" + n, false)) {
- queue_log(" !!! Warning: Minor issues packing " + n + ". Archive still usable.");
- }
- }
- };
- if (config.themes) {
- pack_h(home_dir + "/.themes", "themes_legacy.tar.gz");
- pack_h(home_dir + "/.local/share/themes", "themes_xdg.tar.gz");
- }
- if (config.icons) {
- pack_h(home_dir + "/.icons", "icons_legacy.tar.gz");
- pack_h(home_dir + "/.local/share/icons", "icons_xdg.tar.gz");
- }
- if (config.wallpapers) {
- std::string w = get_wallpaper_directory();
- if (!w.empty()) pack_h(w, "wallpapers.tar.gz");
- }
- if (config.extensions) {
- pack_h(home_dir + "/.local/share/gnome-shell/extensions", "extensions.tar.gz");
- }
- 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_vault = config.backup_save_path + "/" + config.vault_name + ".gbk";
- queue_log("[BACKUP] Compiling final vault to: " + final_vault);
- if (!create_tar_archive(temp_dir, final_vault, true)) {
- m_JobSuccess = false;
- }
- fs::remove_all(temp_dir, ec);
- queue_log("__UNLOCK_UI__");
- m_WorkerRunning = false;
- }
- void MainWindow::run_restore_job(JobConfig config, std::string home_dir) {
- m_JobSuccess = true;
- std::error_code ec;
- queue_log("--- Starting Restore ---");
- auto settings = Gio::Settings::create("org.gnome.shell");
- if (config.extensions && !config.dry_run) {
- settings->set_boolean("disable-user-extensions", true);
- }
- char tpl[] = "/tmp/gvault_unpack_XXXXXX";
- if (mkdtemp(tpl) == nullptr) {
- queue_log("!!! ERROR: Failed to create secure temp directory.");
- m_JobSuccess = false;
- if (config.extensions && !config.dry_run) {
- settings->set_boolean("disable-user-extensions", false);
- }
- m_WorkerRunning = false;
- queue_log("__UNLOCK_UI__");
- return;
- }
- std::string temp_unpack(tpl);
- if (!extract_tar_archive(config.custom_restore_path, temp_unpack, false, false)) {
- m_JobSuccess = false;
- }
- auto atomic_res = [&](const std::string& n, const std::string& lp, const std::string& lbl) {
- std::string arch = temp_unpack + "/" + n + ".tar.gz";
- if (fs::exists(arch)) {
- queue_log("[RESTORE] Swapping " + lbl + "...");
- std::string sh = lp + "_vault_new";
- std::string od = lp + "_vault_old";
- fs::remove_all(sh, ec);
- fs::remove_all(od, ec);
- fs::create_directories(sh);
- if (extract_tar_archive(arch, sh, config.dry_run, false)) {
- if (!config.dry_run) {
- sync();
- bool had_old = fs::exists(lp);
- if (had_old) fs::rename(lp, od, ec);
- fs::rename(sh, lp, ec);
- if (ec) {
- queue_log("!!! FAIL: Rolling back " + lbl);
- if (had_old) fs::rename(od, lp, ec);
- m_JobSuccess = false;
- } else {
- fs::remove_all(od, ec);
- }
- }
- } else {
- m_JobSuccess = false;
- }
- }
- };
- if (config.themes) {
- atomic_res("themes_legacy", home_dir + "/.themes", "Themes (Legacy)");
- atomic_res("themes_xdg", home_dir + "/.local/share/themes", "Themes (XDG)");
- }
- if (config.icons) {
- atomic_res("icons_legacy", home_dir + "/.icons", "Icons (Legacy)");
- atomic_res("icons_xdg", home_dir + "/.local/share/icons", "Icons (XDG)");
- }
- if (config.extensions) {
- atomic_res("extensions", home_dir + "/.local/share/gnome-shell/extensions", "Extensions");
- }
- if (config.wallpapers && fs::exists(temp_unpack + "/wallpapers.tar.gz")) {
- queue_log("[RESTORE] Restoring Wallpapers...");
- if (!extract_tar_archive(temp_unpack + "/wallpapers.tar.gz", "/", config.dry_run, true)) {
- m_JobSuccess = false;
- }
- }
- if (config.dconf && fs::exists(temp_unpack + "/settings.ini") && !config.dry_run) {
- queue_log("[RESTORE] Injecting Dconf...");
- if (system(("dconf load / < '" + temp_unpack + "/settings.ini'").c_str()) != 0) {
- m_JobSuccess = false;
- }
- }
- if (config.extensions && !config.dry_run) {
- settings->set_boolean("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.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& s, const std::string& o, bool strip) {
- struct archive *a = archive_write_new();
- archive_write_add_filter_gzip(a);
- archive_write_set_format_pax_restricted(a);
- if (archive_write_open_filename(a, o.c_str()) != ARCHIVE_OK) return false;
- fs::path bp = fs::absolute(s);
- bool ok = true;
- for (const auto& d : fs::recursive_directory_iterator(bp, fs::directory_options::skip_permission_denied)) {
- std::string f = d.path().string();
- std::string st = strip ? fs::relative(d.path(), bp).string() : f;
- if (st == "." || st == "..") continue;
- struct archive_entry *e = archive_entry_new();
- archive_entry_set_pathname(e, st.c_str());
- struct stat sbuf;
- if (lstat(f.c_str(), &sbuf) != 0) {
- queue_log(" -> Warning (stat): " + st);
- archive_entry_free(e);
- ok = false;
- continue;
- }
- archive_entry_copy_stat(e, &sbuf);
- if (S_ISLNK(sbuf.st_mode)) {
- char t[4096];
- ssize_t l = readlink(f.c_str(), t, 4095);
- if (l != -1) {
- t[l] = '\0';
- archive_entry_set_symlink(e, t);
- }
- }
- if (archive_write_header(a, e) != ARCHIVE_OK) {
- queue_log(" -> Warning (header): " + st);
- archive_entry_free(e);
- ok = false;
- continue;
- }
- queue_log(" -> Packed: " + st);
- if (S_ISREG(sbuf.st_mode)) {
- int fd = ::open(f.c_str(), O_RDONLY);
- if (fd >= 0) {
- char b[65536];
- ssize_t l;
- while ((l = ::read(fd, b, 65536)) > 0) {
- archive_write_data(a, b, l);
- }
- ::close(fd);
- } else {
- ok = false;
- queue_log(" -> Warning (read): " + st);
- }
- }
- archive_entry_free(e);
- }
- archive_write_close(a);
- archive_write_free(a);
- return ok;
- }
- bool MainWindow::extract_tar_archive(const std::string& ap, const std::string& ds, bool dr, bool abs) {
- struct archive *a = archive_read_new();
- archive_read_support_format_all(a);
- archive_read_support_filter_all(a);
- if (archive_read_open_filename(a, ap.c_str(), 10240) != ARCHIVE_OK) return false;
- struct archive_entry *e;
- bool ok = true;
- while (archive_read_next_header(a, &e) == ARCHIVE_OK) {
- std::string sp = archive_entry_pathname(e);
- if (!abs) {
- size_t p = sp.find("/themes/");
- if (p == std::string::npos) p = sp.find("/icons/");
- if (p == std::string::npos) p = sp.find("/extensions/");
- if (p != std::string::npos) {
- size_t s = sp.find('/', p + 1);
- if (s != std::string::npos) sp = sp.substr(s + 1);
- }
- }
- std::string t = abs ? archive_entry_pathname(e) : ds + "/" + sp;
- archive_entry_set_pathname(e, t.c_str());
- if (dr) {
- queue_log(" -> [DRY] " + t);
- archive_read_data_skip(a);
- } else if (archive_read_extract(a, e, ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_UNLINK) != ARCHIVE_OK) {
- if (!fs::is_directory(t)) {
- ok = false;
- queue_log(" -> Warning (extract): " + t);
- }
- } else {
- queue_log(" -> Restored: " + t);
- }
- }
- archive_read_close(a);
- archive_read_free(a);
- return ok;
- }
- std::string MainWindow::get_wallpaper_directory() {
- char b[256];
- std::string r = "";
- FILE *p = popen("gsettings get org.gnome.desktop.background picture-uri-dark 2>/dev/null", "r");
- if (p) {
- while (fgets(b, 256, p))
- r += b;
- pclose(p);
- }
- size_t f = r.find("file://");
- if (f != std::string::npos) {
- std::string path = r.substr(f + 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 "";
- }
|