1 Commits
Author SHA1 Message Date
BlackAngelTV e0c292624c Initial commit 2026-08-24 19:06:29 +00:00
24 changed files with 51 additions and 3187 deletions

No files matched your search

+31 -13
View File
@@ -1,16 +1,34 @@
build/
.cache/
# ---> C++
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.a
*.dylib
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
Makefile
compile_commands.json
.vscode/
.idea/
*.swp
*~
.DS_Store
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
-47
View File
@@ -1,47 +0,0 @@
cmake_minimum_required(VERSION 3.20)
project(PackageManager VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
# Find Qt6
find_package(Qt6 REQUIRED COMPONENTS Widgets)
# Main executable
set(SOURCES
src/main.cpp
src/MainWindow.cpp
src/PluginManager.cpp
src/HistoryManager.cpp
src/PackageModel.cpp
)
set(HEADERS
include/IPackageManager.h
include/MainWindow.h
include/PluginManager.h
include/HistoryManager.h
include/PackageModel.h
)
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PRIVATE include)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Widgets)
# Plugins
add_subdirectory(plugins/pacman)
add_subdirectory(plugins/apt)
add_subdirectory(plugins/pkg)
add_subdirectory(plugins/universal)
# Install
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME})
# Plugin install directory
set(PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}/plugins")
install(CODE "file(MAKE_DIRECTORY \"\${PLUGIN_DIR}\")")
+18
View File
@@ -0,0 +1,18 @@
MIT License
Copyright (c) 2026 FWS
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
+2 -304
View File
@@ -1,305 +1,3 @@
# PackageMapper 📦
# FWS---PacManage
Gestionnaire de paquets unifié avec support d'extensions pour Arch Linux.
## Fonctionnalités
- 🔍 **Recherche globale** de paquets
- 📦 **Installation** de paquets
- 🗑️ **Suppression** de paquets
- 🔄 **Mise à jour** individuelle ou globale
- 📋 **Historique** de toutes les actions
- 🔌 **Système de plugins** extensible (pacman, apt, pkg...)
## Architecture
```
package-manager/
├── CMakeLists.txt # Build root
├── include/
│ ├── IPackageManager.h # Plugin interface
│ ├── MainWindow.h # GUI principal
│ ├── PluginManager.h # Loader de plugins .so
│ ├── HistoryManager.h # Historique des actions
│ └── PackageModel.h # Modèle Qt pour la liste
├── src/
│ ├── main.cpp
│ ├── MainWindow.cpp
│ ├── PluginManager.cpp
│ ├── HistoryManager.cpp
│ └── PackageModel.cpp
└── plugins/
├── pacman/ # Plugin Arch Linux (défaut)
├── apt/ # Plugin Debian/Ubuntu
├── pkg/ # Plugin FreeBSD
└── universal/ # Plugin universel (multi-source + compilation)
```
## Compilation (Arch Linux)
### Dépendances
```bash
# Qt6
sudo pacman -S qt6-base cmake gcc
# Ou tout d'un coup :
sudo pacman -S qt6-base cmake gcc base-devel
```
### Build
```bash
# Cloner ou copier le projet
cd package-manager
# Créer le dossier de build
mkdir -p build && cd build
# Configurer
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
# Compiler
make -j$(nproc)
# Installer (optionnel)
sudo make install
```
### Lancer
```bash
# Depuis le dossier build
./PackageMapper
# Ou depuis /usr/bin après install
PackageMapper
```
## Plugin Universal 🌍
Le plugin **universal** est le plus puissant. Il essaie automatiquement **toutes les sources disponibles** :
### Sources supportées :
| Source | Commande | Description |
|--------|----------|-------------|
| **pacman** | `pacman -S` | Arch Linux natif |
| **apt** | `apt install` | Debian/Ubuntu |
| **dnf** | `dnf install` | Fedora/RHEL |
| **yum** | `yum install` | Ancien RHEL/CentOS |
| **zypper** | `zypper install` | openSUSE |
| **xbps** | `xbps-install` | Void Linux |
| **apk** | `apk add` | Alpine |
| **pkg** | `pkg install` | FreeBSD |
| **brew** | `brew install` | Homebrew (macOS/Linux) |
| **scoop** | `scoop install` | Windows |
| **Flatpak** | `flatpak install` | Cross-distro sandbox |
| **Snap** | `snap install` | Ubuntu/autres |
| **AUR** | `makepkg -si` | Arch User Repository |
| **Nix** | `nix-env -i` | NixOS/nixpkgs |
| **GitHub** | `git clone + build` | Auto-détecte le build system |
### Ordre de priorité :
1. Flatpak (si le paquet existe)
2. Snap (si le paquet existe)
3. AUR (si makepkg disponible)
4. Gestionnaire natif (pacman/apt/dnf/etc.)
5. Nix (si nix-env disponible)
6. **GitHub / Compilation source** (dernier recours)
### Compilation source automatique :
Si aucun paquet n'est trouvé, le plugin :
1. Cherche le repo GitHub le plus populaire
2. Clone le dépôt
3. Détecte le build system (CMake, Meson, Make, Cargo, Go, npm, pip)
4. Compile et installe automatiquement
```bash
# Installer le plugin universal
make universal_plugin
cp plugins/universal/libuniversal.so ~/.local/lib/PackageMapper/plugins/
```
## Installation des plugins
Les plugins sont des bibliothèques partagées `.so` qui s'auto-chargent.
### Emplacements recherchés (par ordre) :
1. `~/.local/lib/PackageMapper/plugins/`
2. `/usr/lib/PackageMapper/plugins/`
3. `/usr/local/lib/PackageMapper/plugins/`
4. `./plugins/` (relatif à l'exécutable)
### Compiler uniquement les plugins
```bash
cd build
make pacman_plugin
make apt_plugin
make pkg_plugin
```
### Installer les plugins
```bash
# Pour l'utilisateur courant
mkdir -p ~/.local/lib/PackageMapper/plugins
cp build/plugins/pacman/libpacman.so ~/.local/lib/PackageMapper/plugins/
cp build/plugins/apt/libapt.so ~/.local/lib/PackageMapper/plugins/
cp build/plugins/pkg/libpkg.so ~/.local/lib/PackageMapper/plugins/
```
## Créer un plugin
Pour ajouter un nouveau gestionnaire de paquets :
1. Créer un dossier dans `plugins/votre_mgr/`
2. Créer un fichier CMakeLists.txt
3. Implémenter l'interface `IPackageManager`
4. Exporter les fonctions `createPlugin()` et `destroyPlugin()`
### Template minimal
```cpp
#include "IPackageManager.h"
class MonPlugin : public IPackageManager {
public:
std::string getName() const override { return "mon-gestionnaire"; }
std::string getVersion() const override { return "1.0.0"; }
std::string getDescription() const override { return "Description"; }
bool canSearch() const override { return true; }
bool canInstall() const override { return true; }
bool canRemove() const override { return true; }
bool canUpdate() const override { return true; }
bool canListInstalled() const override { return true; }
bool isAvailable() const override { return system("which mon_mgr > /dev/null 2>&1") == 0; }
std::vector<PackageInfo> search(const std::string& query) override {
// Implémenter la recherche
return {};
}
bool install(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override {
// Implémenter l'installation
return false;
}
bool remove(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override {
return false;
}
bool update(const std::string& packageName = "",
std::function<void(const std::string&)> progressCallback) override {
return false;
}
std::vector<PackageInfo> listInstalled() override { return {}; }
};
extern "C" {
IPackageManager* createPlugin() { return new MonPlugin(); }
void destroyPlugin(IPackageManager* plugin) { delete plugin; }
}
```
## Interface graphique
L'interface utilise **Qt6** avec un thème sombre :
- Barre de recherche en haut
- Sélecteur de plugin
- Liste des paquets à gauche
- Détails du paquet sélectionné à droite
- Boutons d'action (installer, supprimer, mettre à jour)
- Barre de progression
- Historique des actions
- Menu avec raccourcis clavier
### Aperçu de l'interface
```
┌──────────────────────────────────────────────────────────────────────────────────────┐
│ Fichier Outils Aide │
├──────────────────────────────────────────────────────────────────────────────────────┤
│ ┌──────────────┐ ┌─────────────────────────────────────────────┐ ┌────────────┐ │
│ │ pacman 1.0.0 ▼│ │ 🔍 Rechercher un paquet... │ │ Rechercher │ │
│ └──────────────┘ └─────────────────────────────────────────────┘ └────────────┘ │
├──────────────────────────────────────────────────────────────────────────────────────┤
│ [📦 Installer] [🗑️ Supprimer] [🔄 Mettre à jour] [⬆️ Tout mettre à jour] │
├──────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────┐ ┌────────────────────────────────────────────┐ │
│ │ 📦 firefox 128.0 │ │ │ │
│ │ ✅ Installé │ │ ╔══════════════════════════════════════╗ │ │
│ ├─────────────────────────────────┤ │ ║ firefox ║ │ │
│ │ 📦 chromium 127.0.6533 │ │ ║ Version: 128.0 ║ │ │
│ ├─────────────────────────────────┤ │ ║ Dépôt: extra ║ │ │
│ │ 📦 vlc 3.0.21 │ │ ║ Taille: 289.4 MB ║ │ │
│ │ ✅ Installé 🔄 Mise à jour │ │ ║ ║ │ │
│ ├─────────────────────────────────┤ │ ║ Navigateur web rapide et sécurisé ║ │ │
│ │ 📦 gimp 2.10.38 │ │ ║ basé sur le moteur Gecko de ║ │ │
│ ├─────────────────────────────────┤ │ ║ Mozilla. ║ │ │
│ │ 📦 neovim 0.10.1 │ │ ╚══════════════════════════════════════╝ │ │
│ ├─────────────────────────────────┤ │ │ │
│ │ 📦 tmux 3.4 │ │ │ │
│ └─────────────────────────────────┘ └────────────────────────────────────────────┘ │
│ │
├──────────────────────────────────────────────────────────────────────────────────────┤
│ [🔄 Rafraîchir les sources] [📋 Historique] │
├──────────────────────────────────────────────────────────────────────────────────────┤
│ Plugin: pacman | Paquets trouvés: 6 | Éléments en historique: 12 │
└──────────────────────────────────────────────────────────────────────────────────────┘
Legende: 📦 = paquet ✅ = installé 🔄 = mise à jour disponible
```
### Fenêtre Historique
```
┌──────────────────────────────────────────────────────┐
│ 📋 Historique des actions │
├──────────────────────────────────────────────────────┤
│ ┌────────────────────────────────────────────────┐ │
│ │ [2026-08-24 14:32:01] install: firefox (pacman)│ │
│ │ [2026-08-24 14:32:15] install: vim (pacman) │ │
│ │ [2026-08-24 14:33:02] update: vlc (pacman) │ │
│ │ [2026-08-24 14:35:10] remove: gimp (pacman) │ │
│ │ [2026-08-24 14:40:22] install: neovim (pacman)│ │
│ └────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────┐ │
│ │ 🗑️ Effacer l'historique │ │
│ └─────────────────────┘ │
└──────────────────────────────────────────────────────┘
```
## Héritage des plugins
L'interface `IPackageManager` définit :
| Méthode | Description |
|---------|-------------|
| `getName()` | Nom du gestionnaire |
| `getVersion()` | Version du plugin |
| `getDescription()` | Description |
| `canSearch()` | Supporte la recherche |
| `canInstall()` | Supporte l'installation |
| `canRemove()` | Supporte la suppression |
| `canUpdate()` | Supporte la mise à jour |
| `canListInstalled()` | Supporte le listage |
| `isAvailable()` | Vérifie si le gestionnaire est installé |
| `search(query)` | Recherche de paquets |
| `install(name, callback)` | Installation |
| `remove(name, callback)` | Suppression |
| `update(name, callback)` | Mise à jour |
| `listInstalled()` | Liste des paquets installés |
## Licence
MIT
Gestionnaire de paquet pour FWS
-30
View File
@@ -1,30 +0,0 @@
#!/bin/bash
set -e
echo "🔨 Compilation de PackageMapper..."
# Create build directory
mkdir -p build
cd build
# Configure
echo "⚙️ Configuration CMake..."
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
# Build everything
echo "🏗️ Compilation..."
make -j$(nproc)
echo ""
echo "✅ Compilation terminée !"
echo ""
echo "📋 Pour lancer :"
echo " ./PackageMapper"
echo ""
echo "📋 Pour installer :"
echo " sudo make install"
echo ""
echo "📋 Pour copier les plugins (user mode) :"
echo " mkdir -p ~/.local/lib/PackageMapper/plugins"
echo " cp plugins/*/lib*.so ~/.local/lib/PackageMapper/plugins/"
echo ""
-35
View File
@@ -1,35 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include <ctime>
#include <fstream>
#include <sstream>
#include <iostream>
struct HistoryEntry {
std::string timestamp;
std::string action; // "install", "remove", "update"
std::string package;
std::string plugin;
bool success;
};
class HistoryManager {
public:
HistoryManager(const std::string& historyFile = "~/.local/share/PackageMapper/history.csv");
~HistoryManager();
void record(const HistoryEntry& entry);
const std::vector<HistoryEntry>& getHistory() const;
void clear();
void save();
void load();
private:
std::string m_historyFile;
std::vector<HistoryEntry> m_history;
std::string expandPath(const std::string& path);
std::string getCurrentTimestamp();
};
-54
View File
@@ -1,54 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include <functional>
// Information about a single package
struct PackageInfo {
std::string name;
std::string version;
std::string description;
std::string repository;
std::string size;
std::string installedSize;
bool installed = false;
bool updateAvailable = false;
};
// Abstract interface for all package manager plugins
class IPackageManager {
public:
virtual ~IPackageManager() = default;
// Identity
virtual std::string getName() const = 0;
virtual std::string getVersion() const = 0;
virtual std::string getDescription() const = 0;
// Capabilities
virtual bool canSearch() const = 0;
virtual bool canInstall() const = 0;
virtual bool canRemove() const = 0;
virtual bool canUpdate() const = 0;
virtual bool canListInstalled() const = 0;
// Operations
virtual std::vector<PackageInfo> search(const std::string& query) = 0;
virtual bool install(const std::string& packageName,
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
virtual bool remove(const std::string& packageName,
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
virtual bool update(const std::string& packageName = "",
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
virtual std::vector<PackageInfo> listInstalled() = 0;
// Check if the package manager is available on the system
virtual bool isAvailable() const = 0;
};
// Plugin entry point types
extern "C" {
IPackageManager* createPlugin();
void destroyPlugin(IPackageManager* plugin);
}
-111
View File
@@ -1,111 +0,0 @@
#pragma once
#include <QMainWindow>
#include <QStackedWidget>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QLabel>
#include <QComboBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QProgressBar>
#include <QStatusBar>
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QTabWidget>
#include <QTextEdit>
#include <QThread>
#include "IPackageManager.h"
#include "PluginManager.h"
#include "HistoryManager.h"
#include "PackageModel.h"
class SearchWorker : public QThread {
Q_OBJECT
public:
SearchWorker(IPackageManager* pm, const std::string& query);
void run() override;
signals:
void finished(std::vector<PackageInfo> results);
private:
IPackageManager* m_pm;
std::string m_query;
};
class InstallWorker : public QThread {
Q_OBJECT
public:
InstallWorker(IPackageManager* pm, const std::string& package, bool remove = false);
void run() override;
signals:
void progress(const QString& message);
void finished(bool success);
private:
IPackageManager* m_pm;
std::string m_package;
bool m_remove;
};
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget* parent = nullptr);
~MainWindow();
private slots:
void onSearch();
void onInstall();
void onRemove();
void onUpdate();
void onUpdateAll();
void onRefresh();
void onPluginChanged(int index);
void onSearchFinished(std::vector<PackageInfo> results);
void onInstallFinished(bool success);
void onPackageSelected(int row);
void onToggleInstalledView();
void onShowHistory();
private:
void setupUI();
void setupMenuBar();
void updatePackageInfo(const PackageInfo& pkg);
void updateStatusBar();
void loadPlugins();
void performSearch(const std::string& query);
void performInstall(const std::string& package);
void performRemove(const std::string& package);
// UI Elements
QLineEdit* m_searchBar;
QPushButton* m_searchButton;
QComboBox* m_pluginSelector;
QListWidget* m_packageList;
QLabel* m_packageName;
QLabel* m_packageVersion;
QLabel* m_packageRepo;
QLabel* m_packageSize;
QLabel* m_packageDescription;
QPushButton* m_installButton;
QPushButton* m_removeButton;
QPushButton* m_updateButton;
QPushButton* m_updateAllButton;
QPushButton* m_refreshButton;
QPushButton* m_historyButton;
QProgressBar* m_progressBar;
QTabWidget* m_mainTabs;
QTextEdit* m_historyView;
QStackedWidget* m_stackedWidget;
// Backend
PluginManager* m_pluginManager;
HistoryManager* m_historyManager;
PackageModel* m_packageModel;
IPackageManager* m_currentPlugin;
std::vector<PackageInfo> m_currentResults;
PackageInfo m_selectedPackage;
};
-34
View File
@@ -1,34 +0,0 @@
#pragma once
#include <QObject>
#include <QAbstractListModel>
#include <QVariant>
#include <vector>
#include "IPackageManager.h"
class PackageModel : public QAbstractListModel {
Q_OBJECT
public:
enum Roles {
NameRole = Qt::UserRole + 1,
VersionRole,
DescriptionRole,
RepositoryRole,
InstalledRole,
SizeRole,
UpdateAvailableRole
};
explicit PackageModel(QObject* parent = nullptr);
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
void setPackages(const std::vector<PackageInfo>& packages);
void clear();
PackageInfo getPackage(int row) const;
private:
std::vector<PackageInfo> m_packages;
};
-45
View File
@@ -1,45 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include <dlfcn.h>
#include "IPackageManager.h"
struct PluginInfo {
std::string path;
std::string name;
IPackageManager* instance = nullptr;
void* handle = nullptr;
bool loaded = false;
};
class PluginManager {
public:
PluginManager();
~PluginManager();
// Load plugins from a directory
void loadPluginsFromDirectory(const std::string& directory);
// Load a specific plugin
bool loadPlugin(const std::string& path);
// Unload all plugins
void unloadAll();
// Get loaded plugins
const std::vector<PluginInfo>& getPlugins() const;
// Get a plugin by index
IPackageManager* getPlugin(size_t index) const;
// Get plugin count
size_t getPluginCount() const;
// Find plugin by name
IPackageManager* findPlugin(const std::string& name) const;
private:
std::vector<PluginInfo> m_plugins;
std::vector<std::string> m_searchPaths;
};
-25
View File
@@ -1,25 +0,0 @@
#!/bin/bash
set -e
PLUGIN_DIR="$HOME/.local/lib/PackageMapper/plugins"
echo "📦 Installation des plugins..."
mkdir -p "$PLUGIN_DIR"
# Find and copy all plugin .so files
for plugin in build/plugins/*/lib*.so; do
if [ -f "$plugin" ]; then
cp "$plugin" "$PLUGIN_DIR/"
echo " ✅ Installé: $(basename $plugin)"
fi
done
# Universal plugin (priority)
if [ -f "build/plugins/universal/libuniversal.so" ]; then
echo " 🌍 Plugin universal chargé"
fi
echo ""
echo "📁 Plugins installés dans: $PLUGIN_DIR"
echo "🔄 Redémarrez PackageMapper pour charger les nouveaux plugins."
-8
View File
@@ -1,8 +0,0 @@
add_library(apt_plugin SHARED apt_plugin.cpp)
target_include_directories(apt_plugin PRIVATE ${CMAKE_SOURCE_DIR}/include)
set_target_properties(apt_plugin PROPERTIES
PREFIX ""
OUTPUT_NAME "apt"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/PackageMapper/plugins"
)
install(TARGETS apt_plugin DESTINATION lib/PackageMapper/plugins)
-146
View File
@@ -1,146 +0,0 @@
#include "IPackageManager.h"
#include <array>
#include <memory>
#include <stdexcept>
#include <string>
#include <cstdio>
#include <sstream>
static std::string exec(const char* cmd) {
std::array<char, 256> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe) throw std::runtime_error("popen() failed");
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}
class AptPlugin : public IPackageManager {
public:
std::string getName() const override { return "apt"; }
std::string getVersion() const override { return "1.0.0"; }
std::string getDescription() const override {
return "Gestionnaire de paquets Debian/Ubuntu (apt)";
}
bool canSearch() const override { return true; }
bool canInstall() const override { return true; }
bool canRemove() const override { return true; }
bool canUpdate() const override { return true; }
bool canListInstalled() const override { return true; }
bool isAvailable() const override {
return system("which apt > /dev/null 2>&1") == 0;
}
std::vector<PackageInfo> search(const std::string& query) override {
std::vector<PackageInfo> results;
std::string output = exec(("apt-cache search " + query + " 2>&1").c_str());
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (line.empty()) continue;
PackageInfo pkg;
size_t spacePos = line.find(' ');
if (spacePos != std::string::npos) {
pkg.name = line.substr(0, spacePos);
pkg.description = line.substr(spacePos + 1);
pkg.installed = isPackageInstalled(pkg.name);
pkg.repository = "debian";
results.push_back(pkg);
}
}
return results;
}
bool install(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override {
if (progressCallback) progressCallback("Installation de " + packageName + "...");
std::string output = exec(("sudo apt install -y " + packageName + " 2>&1").c_str());
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
}
return isPackageInstalled(packageName);
}
bool remove(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override {
if (progressCallback) progressCallback("Suppression de " + packageName + "...");
std::string output = exec(("sudo apt remove -y " + packageName + " 2>&1").c_str());
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
}
return !isPackageInstalled(packageName);
}
bool update(const std::string& packageName = "",
std::function<void(const std::string&)> progressCallback = nullptr) override {
if (packageName.empty()) {
if (progressCallback) progressCallback("Mise à jour des paquets...");
exec("sudo apt update 2>&1");
exec("sudo apt upgrade -y 2>&1");
return true;
} else {
if (progressCallback) progressCallback("Mise à jour de " + packageName + "...");
exec(("sudo apt install --only-upgrade -y " + packageName + " 2>&1").c_str());
return true;
}
}
std::vector<PackageInfo> listInstalled() override {
std::vector<PackageInfo> results;
std::string output = exec("dpkg --get-selections | grep -v deinstall 2>&1");
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (line.empty()) continue;
PackageInfo pkg;
size_t tabPos = line.find('\t');
if (tabPos != std::string::npos) {
pkg.name = line.substr(0, tabPos);
pkg.installed = true;
results.push_back(pkg);
}
}
return results;
}
private:
bool isPackageInstalled(const std::string& name) {
return system(("dpkg -l " + name + " > /dev/null 2>&1").c_str()) == 0;
}
};
extern "C" {
IPackageManager* createPlugin() {
return new AptPlugin();
}
void destroyPlugin(IPackageManager* plugin) {
delete plugin;
}
}
-8
View File
@@ -1,8 +0,0 @@
add_library(pacman_plugin SHARED pacman_plugin.cpp)
target_include_directories(pacman_plugin PRIVATE ${CMAKE_SOURCE_DIR}/include)
set_target_properties(pacman_plugin PROPERTIES
PREFIX ""
OUTPUT_NAME "pacman"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/PackageMapper/plugins"
)
install(TARGETS pacman_plugin DESTINATION lib/PackageMapper/plugins)
-187
View File
@@ -1,187 +0,0 @@
#include "IPackageManager.h"
#include <array>
#include <memory>
#include <stdexcept>
#include <string>
#include <cstdio>
#include <iostream>
#include <sstream>
// Helper to run shell commands and capture output
static std::string exec(const char* cmd) {
std::array<char, 256> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe) throw std::runtime_error("popen() failed");
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}
class PacmanPlugin : public IPackageManager {
public:
std::string getName() const override { return "pacman"; }
std::string getVersion() const override { return "1.0.0"; }
std::string getDescription() const override {
return "Gestionnaire de paquets natif d'Arch Linux";
}
bool canSearch() const override { return true; }
bool canInstall() const override { return true; }
bool canRemove() const override { return true; }
bool canUpdate() const override { return true; }
bool canListInstalled() const override { return true; }
bool isAvailable() const override {
return system("which pacman > /dev/null 2>&1") == 0;
}
std::vector<PackageInfo> search(const std::string& query) override {
std::vector<PackageInfo> results;
std::string cmd = "pacman -Ss " + query + " 2>&1";
std::string output = exec(cmd.c_str());
std::istringstream iss(output);
std::string line;
std::string currentRepo;
while (std::getline(iss, line)) {
if (line.empty()) continue;
// Repository line: repo/name version
if (line[0] != ' ' && line[0] != '\t') {
PackageInfo pkg;
size_t slashPos = line.find('/');
size_t spacePos = line.find(' ', slashPos);
if (slashPos != std::string::npos) {
pkg.repository = line.substr(0, slashPos);
pkg.name = line.substr(slashPos + 1, spacePos - slashPos - 1);
if (spacePos != std::string::npos) {
size_t nextSpace = line.find(' ', spacePos + 1);
pkg.version = line.substr(spacePos + 1, nextSpace - spacePos - 1);
}
}
pkg.installed = isPackageInstalled(pkg.name);
results.push_back(pkg);
currentRepo = pkg.name;
}
// Description line (starts with spaces)
else if (!results.empty()) {
std::string desc = line;
// Trim leading spaces
size_t start = desc.find_first_not_of(" \t");
if (start != std::string::npos) {
desc = desc.substr(start);
}
results.back().description = desc;
}
}
return results;
}
bool install(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override {
if (progressCallback) progressCallback("Installation de " + packageName + "...");
std::string cmd = "sudo pacman -S --noconfirm " + packageName + " 2>&1";
std::string output = exec(cmd.c_str());
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
}
return isPackageInstalled(packageName);
}
bool remove(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override {
if (progressCallback) progressCallback("Suppression de " + packageName + "...");
std::string cmd = "sudo pacman -R --noconfirm " + packageName + " 2>&1";
std::string output = exec(cmd.c_str());
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
}
return !isPackageInstalled(packageName);
}
bool update(const std::string& packageName = "",
std::function<void(const std::string&)> progressCallback = nullptr) override {
if (packageName.empty()) {
if (progressCallback) progressCallback("Mise à jour de tous les paquets...");
std::string cmd = "sudo pacman -Syu --noconfirm 2>&1";
exec(cmd.c_str());
return true;
} else {
if (progressCallback) progressCallback("Mise à jour de " + packageName + "...");
std::string cmd = "sudo pacman -S --noconfirm " + packageName + " 2>&1";
exec(cmd.c_str());
return true;
}
}
std::vector<PackageInfo> listInstalled() override {
std::vector<PackageInfo> results;
std::string output = exec("pacman -Q 2>&1");
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (line.empty()) continue;
PackageInfo pkg;
size_t spacePos = line.find(' ');
size_t dashPos = line.find('-');
// Handle package names with hyphens (version starts after last pair of hyphens)
size_t lastDash = line.rfind('-');
size_t secondLastDash = line.rfind('-', lastDash - 1);
if (secondLastDash != std::string::npos && lastDash != std::string::npos) {
pkg.name = line.substr(0, secondLastDash);
pkg.version = line.substr(secondLastDash + 1);
} else if (spacePos != std::string::npos) {
pkg.name = line.substr(0, spacePos);
pkg.version = line.substr(spacePos + 1);
}
pkg.installed = true;
results.push_back(pkg);
}
return results;
}
private:
bool isPackageInstalled(const std::string& name) {
std::string cmd = "pacman -Qi " + name + " > /dev/null 2>&1";
return system(cmd.c_str()) == 0;
}
};
extern "C" {
IPackageManager* createPlugin() {
return new PacmanPlugin();
}
void destroyPlugin(IPackageManager* plugin) {
delete plugin;
}
}
-8
View File
@@ -1,8 +0,0 @@
add_library(pkg_plugin SHARED pkg_plugin.cpp)
target_include_directories(pkg_plugin PRIVATE ${CMAKE_SOURCE_DIR}/include)
set_target_properties(pkg_plugin PROPERTIES
PREFIX ""
OUTPUT_NAME "pkg"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/PackageMapper/plugins"
)
install(TARGETS pkg_plugin DESTINATION lib/PackageMapper/plugins)
-149
View File
@@ -1,149 +0,0 @@
#include "IPackageManager.h"
#include <array>
#include <memory>
#include <stdexcept>
#include <string>
#include <cstdio>
#include <sstream>
static std::string exec(const char* cmd) {
std::array<char, 256> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe) throw std::runtime_error("popen() failed");
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}
class PkgPlugin : public IPackageManager {
public:
std::string getName() const override { return "pkg"; }
std::string getVersion() const override { return "1.0.0"; }
std::string getDescription() const override {
return "Gestionnaire de paquets FreeBSD (pkg)";
}
bool canSearch() const override { return true; }
bool canInstall() const override { return true; }
bool canRemove() const override { return true; }
bool canUpdate() const override { return true; }
bool canListInstalled() const override { return true; }
bool isAvailable() const override {
return system("which pkg > /dev/null 2>&1") == 0;
}
std::vector<PackageInfo> search(const std::string& query) override {
std::vector<PackageInfo> results;
std::string output = exec(("pkg search " + query + " 2>&1").c_str());
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (line.empty()) continue;
PackageInfo pkg;
// pkg search format: name-version [repo]
size_t dashPos = line.rfind('-');
size_t spacePos = line.find(' ');
if (dashPos != std::string::npos && spacePos != std::string::npos) {
pkg.name = line.substr(0, dashPos);
pkg.version = line.substr(dashPos + 1, spacePos - dashPos - 1);
pkg.repository = "freebsd";
pkg.installed = isPackageInstalled(pkg.name);
results.push_back(pkg);
}
}
return results;
}
bool install(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override {
if (progressCallback) progressCallback("Installation de " + packageName + "...");
std::string output = exec(("sudo pkg install -y " + packageName + " 2>&1").c_str());
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
}
return isPackageInstalled(packageName);
}
bool remove(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override {
if (progressCallback) progressCallback("Suppression de " + packageName + "...");
std::string output = exec(("sudo pkg delete -y " + packageName + " 2>&1").c_str());
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
}
return !isPackageInstalled(packageName);
}
bool update(const std::string& packageName = "",
std::function<void(const std::string&)> progressCallback = nullptr) override {
if (packageName.empty()) {
if (progressCallback) progressCallback("Mise à jour de tous les paquets...");
exec("sudo pkg upgrade -y 2>&1");
return true;
} else {
if (progressCallback) progressCallback("Mise à jour de " + packageName + "...");
exec(("sudo pkg install -y " + packageName + " 2>&1").c_str());
return true;
}
}
std::vector<PackageInfo> listInstalled() override {
std::vector<PackageInfo> results;
std::string output = exec("pkg query '%n-%v' 2>&1");
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (line.empty()) continue;
PackageInfo pkg;
size_t dashPos = line.rfind('-');
if (dashPos != std::string::npos) {
pkg.name = line.substr(0, dashPos);
pkg.version = line.substr(dashPos + 1);
pkg.installed = true;
results.push_back(pkg);
}
}
return results;
}
private:
bool isPackageInstalled(const std::string& name) {
return system(("pkg info " + name + " > /dev/null 2>&1").c_str()) == 0;
}
};
extern "C" {
IPackageManager* createPlugin() {
return new PkgPlugin();
}
void destroyPlugin(IPackageManager* plugin) {
delete plugin;
}
}
-8
View File
@@ -1,8 +0,0 @@
add_library(universal_plugin SHARED universal_plugin.cpp)
target_include_directories(universal_plugin PRIVATE ${CMAKE_SOURCE_DIR}/include)
set_target_properties(universal_plugin PROPERTIES
PREFIX ""
OUTPUT_NAME "universal"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/PackageMapper/plugins"
)
install(TARGETS universal_plugin DESTINATION lib/PackageMapper/plugins)
-948
View File
@@ -1,948 +0,0 @@
#include "IPackageManager.h"
#include <array>
#include <memory>
#include <stdexcept>
#include <string>
#include <cstdio>
#include <sstream>
#include <vector>
#include <map>
#include <functional>
#include <cstring>
// ============================================================================
// Helper: run shell commands
// ============================================================================
static std::string exec(const char* cmd, bool captureStderr = true) {
std::array<char, 4096> buffer;
std::string result;
std::string fullCmd = std::string(cmd) + (captureStderr ? " 2>&1" : " 2>/dev/null");
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(fullCmd.c_str(), "r"), pclose);
if (!pipe) return "";
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}
static bool commandExists(const char* cmd) {
std::string check = std::string("which ") + cmd + " > /dev/null 2>&1";
return system(check.c_str()) == 0;
}
// ============================================================================
// Detected package managers
// ============================================================================
struct DetectedManager {
std::string name;
std::string installCmd;
std::string searchCmd;
std::string removeCmd;
std::string updateCmd;
std::string listCmd;
std::string isInstalledCheck; // command to check if a pkg is installed
bool available = false;
};
// ============================================================================
// Source repository info
// ============================================================================
struct SourceRepo {
std::string url;
std::string type; // "github", "gitlab", "git", "tarball", "raw"
std::string name;
std::string branch;
bool found = false;
};
// ============================================================================
// Universal Plugin Implementation
// ============================================================================
class UniversalPlugin : public IPackageManager {
public:
UniversalPlugin() {
detectManagers();
detectExtras();
}
// --- IPackageManager interface ---
std::string getName() const override { return "universal"; }
std::string getVersion() const override { return "2.0.0"; }
std::string getDescription() const override {
return "Gestionnaire universel - pacman, apt, dnf, pkg, zypper, xbps, "
"Flatpak, Snap, AppImage, AUR, Nix, GitHub, compilation source";
}
bool canSearch() const override { return true; }
bool canInstall() const override { return true; }
bool canRemove() const override { return true; }
bool canUpdate() const override { return true; }
bool canListInstalled() const override { return true; }
bool isAvailable() const override { return true; } // Toujours dispo
// -------------------------------------------------------------------------
// SEARCH: essaie tout ce qui est disponible
// -------------------------------------------------------------------------
std::vector<PackageInfo> search(const std::string& query) override {
std::vector<PackageInfo> results;
// 1) Chercher dans le gestionnaire natif
for (auto& mgr : m_managers) {
if (!mgr.available) continue;
auto pkgs = searchWithManager(mgr, query);
for (auto& p : pkgs) {
p.repository = mgr.name;
results.push_back(p);
}
}
// 2) Chercher dans Flatpak
if (m_hasFlatpak) {
auto pkgs = searchFlatpak(query);
for (auto& p : pkgs) {
p.repository = "flatpak";
results.push_back(p);
}
}
// 3) Chercher dans Snap
if (m_hasSnap) {
auto pkgs = searchSnap(query);
for (auto& p : pkgs) {
p.repository = "snap";
results.push_back(p);
}
}
// 4) Chercher sur GitHub
auto githubPkgs = searchGitHub(query);
for (auto& p : githubPkgs) {
p.repository = "github";
results.push_back(p);
}
// 5) Chercher dans AUR
if (m_hasAUR) {
auto pkgs = searchAUR(query);
for (auto& p : pkgs) {
p.repository = "aur";
results.push_back(p);
}
}
// 6) Chercher dans Nix
if (m_hasNix) {
auto pkgs = searchNix(query);
for (auto& p : pkgs) {
p.repository = "nix";
results.push_back(p);
}
}
return results;
}
// -------------------------------------------------------------------------
// INSTALL: essaie la meilleure source
// -------------------------------------------------------------------------
bool install(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override {
if (progressCallback) progressCallback("🔍 Recherche de la meilleure source pour " + packageName + "...");
// 1) Vérifier si c'est un Flatpak
if (m_hasFlatpak && isFlatpakPackage(packageName)) {
return installFlatpak(packageName, progressCallback);
}
// 2) Vérifier si c'est un Snap
if (m_hasSnap && isSnapPackage(packageName)) {
return installSnap(packageName, progressCallback);
}
// 3) Vérifier si c'est dans AUR
if (m_hasAUR && isAURPackage(packageName)) {
return installAUR(packageName, progressCallback);
}
// 4) Vérifier dans le gestionnaire natif
for (auto& mgr : m_managers) {
if (!mgr.available) continue;
if (isPackageInManager(mgr, packageName)) {
if (progressCallback) progressCallback("📦 Installation via " + mgr.name + "...");
return installWithManager(mgr, packageName, progressCallback);
}
}
// 5) Essayer Nix
if (m_hasNix && isNixPackage(packageName)) {
return installNix(packageName, progressCallback);
}
// 6) Dernier recours: GitHub / compilation source
if (progressCallback) progressCallback("⚙️ Pas de paquet trouvé, tentative depuis GitHub/source...");
return installFromSource(packageName, progressCallback);
}
// -------------------------------------------------------------------------
// REMOVE
// -------------------------------------------------------------------------
bool remove(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) override {
// Essayer chaque gestionnaire
for (auto& mgr : m_managers) {
if (!mgr.available) continue;
if (isInstalledWithManager(mgr, packageName)) {
if (progressCallback) progressCallback("🗑️ Suppression via " + mgr.name + "...");
return removeWithManager(mgr, packageName, progressCallback);
}
}
// Flatpak
if (m_hasFlatpak) {
std::string check = "flatpak list --columns=application | grep -i " + packageName + " > /dev/null 2>&1";
if (system(check.c_str()) == 0) {
return removeFlatpak(packageName, progressCallback);
}
}
// Snap
if (m_hasSnap) {
std::string check = "snap list " + packageName + " > /dev/null 2>&1";
if (system(check.c_str()) == 0) {
return removeSnap(packageName, progressCallback);
}
}
if (progressCallback) progressCallback("❌ Paquet non trouvé dans aucune source");
return false;
}
// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
bool update(const std::string& packageName = "",
std::function<void(const std::string&)> progressCallback = nullptr) override {
if (packageName.empty()) {
// Update all via le gestionnaire natif
for (auto& mgr : m_managers) {
if (!mgr.available) continue;
if (progressCallback) progressCallback("🔄 Mise à jour via " + mgr.name + "...");
std::string cmd = "sudo " + mgr.updateCmd + " 2>&1";
exec(cmd.c_str());
}
// Flatpak
if (m_hasFlatpak) {
if (progressCallback) progressCallback("🔄 Mise à jour Flatpak...");
exec("flatpak update -y 2>&1");
}
// Snap
if (m_hasSnap) {
if (progressCallback) progressCallback("🔄 Mise à jour Snap...");
exec("sudo snap refresh 2>&1");
}
return true;
}
// Update spécifique
for (auto& mgr : m_managers) {
if (!mgr.available) continue;
if (isInstalledWithManager(mgr, packageName)) {
if (progressCallback) progressCallback("🔄 Mise à jour via " + mgr.name + "...");
std::string cmd = "sudo " + mgr.installCmd + " " + packageName + " 2>&1";
exec(cmd.c_str());
return true;
}
}
return false;
}
// -------------------------------------------------------------------------
// LIST INSTALLED
// -------------------------------------------------------------------------
std::vector<PackageInfo> listInstalled() override {
std::vector<PackageInfo> results;
for (auto& mgr : m_managers) {
if (!mgr.available) continue;
auto pkgs = listInstalledWithManager(mgr);
for (auto& p : pkgs) {
p.repository = mgr.name;
results.push_back(p);
}
}
if (m_hasFlatpak) {
auto pkgs = listInstalledFlatpak();
for (auto& p : pkgs) {
p.repository = "flatpak";
results.push_back(p);
}
}
if (m_hasSnap) {
auto pkgs = listInstalledSnap();
for (auto& p : pkgs) {
p.repository = "snap";
results.push_back(p);
}
}
return results;
}
// --- Public helpers ---
std::vector<std::string> getAvailableManagers() const {
std::vector<std::string> list;
for (const auto& mgr : m_managers) {
if (mgr.available) list.push_back(mgr.name);
}
if (m_hasFlatpak) list.push_back("flatpak");
if (m_hasSnap) list.push_back("snap");
if (m_hasAUR) list.push_back("aur");
if (m_hasNix) list.push_back("nix");
return list;
}
private:
// =========================================================================
// Detection
// =========================================================================
void detectManagers() {
// pacman (Arch)
m_managers.push_back({
"pacman", "pacman -S --noconfirm", "pacman -Ss",
"pacman -R --noconfirm", "pacman -Syu --noconfirm",
"pacman -Q", "pacman -Qi", commandExists("pacman")
});
// apt (Debian/Ubuntu)
m_managers.push_back({
"apt", "apt install -y", "apt search",
"apt remove -y", "apt update && apt upgrade -y",
"dpkg --get-selections", "dpkg -l", commandExists("apt")
});
// dnf (Fedora/RHEL)
m_managers.push_back({
"dnf", "dnf install -y", "dnf search",
"dnf remove -y", "dnf upgrade -y",
"dnf list installed", "rpm -q", commandExists("dnf")
});
// yum (ancien RHEL/CentOS)
m_managers.push_back({
"yum", "yum install -y", "yum search",
"yum remove -y", "yum update -y",
"yum list installed", "rpm -q", commandExists("yum") && !commandExists("dnf")
});
// zypper (openSUSE)
m_managers.push_back({
"zypper", "zypper install -y", "zypper search",
"zypper remove -y", "zypper update -y",
"zypper packages -i", "rpm -q", commandExists("zypper")
});
// xbps (Void Linux)
m_managers.push_back({
"xbps-install", "xbps-install -y", "xbps-query -Rs",
"xbps-remove -y", "xbps-install -Su",
"xbps-query -l", "xbps-query -i", commandExists("xbps-install")
});
// apk (Alpine)
m_managers.push_back({
"apk", "apk add", "apk search",
"apk del", "apk upgrade",
"apk list --installed", "apk info -e", commandExists("apk")
});
// pkg (FreeBSD)
m_managers.push_back({
"pkg", "pkg install -y", "pkg search",
"pkg delete -y", "pkg upgrade -y",
"pkg query '%n-%v'", "pkg info", commandExists("pkg")
});
// brew (macOS/Linux)
m_managers.push_back({
"brew", "brew install", "brew search",
"brew uninstall", "brew upgrade",
"brew list", "brew list", commandExists("brew")
});
// scoop (Windows)
m_managers.push_back({
"scoop", "scoop install", "scoop search",
"scoop uninstall", "scoop update",
"scoop list", "scoop info", commandExists("scoop")
});
}
void detectExtras() {
m_hasFlatpak = commandExists("flatpak");
m_hasSnap = commandExists("snap");
m_hasAUR = commandExists("makepkg");
m_hasNix = commandExists("nix-env");
m_hasCurl = commandExists("curl");
m_hasGit = commandExists("git");
m_hasMake = commandExists("make");
m_hasCMake = commandExists("cmake");
m_hasGcc = commandExists("gcc") || commandExists("g++");
}
// =========================================================================
// Native manager operations
// =========================================================================
std::vector<PackageInfo> searchWithManager(const DetectedManager& mgr, const std::string& query) {
std::vector<PackageInfo> results;
std::string cmd = mgr.searchCmd + " " + query + " 2>&1";
std::string output = exec(cmd.c_str());
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (line.empty() || line[0] == ' ' || line[0] == '\t') continue;
if (line.find("error") != std::string::npos ||
line.find("warning") != std::string::npos) continue;
PackageInfo pkg;
// Parse common formats: "name version - description" or "name version description"
size_t spacePos = line.find(' ');
if (spacePos != std::string::npos) {
pkg.name = line.substr(0, spacePos);
size_t nextSpace = line.find(' ', spacePos + 1);
if (nextSpace != std::string::npos) {
pkg.version = line.substr(spacePos + 1, nextSpace - spacePos - 1);
size_t descStart = line.find_first_not_of(" \t", nextSpace);
if (descStart != std::string::npos) {
pkg.description = line.substr(descStart);
}
} else {
pkg.version = line.substr(spacePos + 1);
}
pkg.installed = isInstalledWithManager(mgr, pkg.name);
results.push_back(pkg);
}
}
return results;
}
bool installWithManager(const DetectedManager& mgr, const std::string& pkg,
std::function<void(const std::string&)> progressCallback) {
std::string cmd = "sudo " + mgr.installCmd + " " + pkg + " 2>&1";
std::string output = exec(cmd.c_str());
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
}
return isInstalledWithManager(mgr, pkg);
}
bool removeWithManager(const DetectedManager& mgr, const std::string& pkg,
std::function<void(const std::string&)> progressCallback) {
std::string cmd = "sudo " + mgr.removeCmd + " " + pkg + " 2>&1";
exec(cmd.c_str());
return !isInstalledWithManager(mgr, pkg);
}
bool isInstalledWithManager(const DetectedManager& mgr, const std::string& pkg) {
std::string cmd = mgr.isInstalledCheck + " " + pkg + " > /dev/null 2>&1";
return system(cmd.c_str()) == 0;
}
bool isPackageInManager(const DetectedManager& mgr, const std::string& pkg) {
std::string cmd = mgr.searchCmd + " " + pkg + " 2>&1 | grep -qi " + pkg;
std::string output = exec(cmd.c_str());
return !output.empty();
}
std::vector<PackageInfo> listInstalledWithManager(const DetectedManager& mgr) {
std::vector<PackageInfo> results;
std::string output = exec((mgr.listCmd + " 2>&1").c_str());
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (line.empty()) continue;
PackageInfo pkg;
size_t spacePos = line.find(' ');
if (spacePos != std::string::npos) {
pkg.name = line.substr(0, spacePos);
pkg.version = line.substr(spacePos + 1);
pkg.installed = true;
results.push_back(pkg);
}
}
return results;
}
// =========================================================================
// Flatpak
// =========================================================================
bool isFlatpakPackage(const std::string& pkg) {
std::string cmd = "flatpak search " + pkg + " --columns=application 2>/dev/null | grep -qi " + pkg;
return !exec(cmd.c_str()).empty();
}
std::vector<PackageInfo> searchFlatpak(const std::string& query) {
std::vector<PackageInfo> results;
std::string output = exec(("flatpak search " + query + " 2>&1").c_str());
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (line.empty()) continue;
PackageInfo pkg;
size_t tabPos = line.find('\t');
if (tabPos != std::string::npos) {
pkg.name = line.substr(0, tabPos);
size_t nextTab = line.find('\t', tabPos + 1);
if (nextTab != std::string::npos) {
pkg.description = line.substr(tabPos + 1, nextTab - tabPos - 1);
}
pkg.installed = isFlatpakInstalled(pkg.name);
results.push_back(pkg);
}
}
return results;
}
bool isFlatpakInstalled(const std::string& pkg) {
std::string cmd = "flatpak list --columns=application | grep -q '^" + pkg + "$'";
return system(cmd.c_str()) == 0;
}
bool installFlatpak(const std::string& pkg,
std::function<void(const std::string&)> progressCallback) {
if (progressCallback) progressCallback("📦 Installation Flatpak: " + pkg + "...");
exec(("flatpak install -y flathub " + pkg + " 2>&1").c_str());
return isFlatpakInstalled(pkg);
}
bool removeFlatpak(const std::string& pkg,
std::function<void(const std::string&)> progressCallback) {
if (progressCallback) progressCallback("🗑️ Suppression Flatpak: " + pkg + "...");
exec(("flatpak uninstall -y " + pkg + " 2>&1").c_str());
return !isFlatpakInstalled(pkg);
}
std::vector<PackageInfo> listInstalledFlatpak() {
std::vector<PackageInfo> results;
std::string output = exec("flatpak list --columns=application,version 2>&1");
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (line.empty()) continue;
PackageInfo pkg;
size_t tabPos = line.find('\t');
if (tabPos != std::string::npos) {
pkg.name = line.substr(0, tabPos);
pkg.version = line.substr(tabPos + 1);
pkg.installed = true;
results.push_back(pkg);
}
}
return results;
}
// =========================================================================
// Snap
// =========================================================================
bool isSnapPackage(const std::string& pkg) {
std::string cmd = "snap find " + pkg + " 2>&1 | head -5 | grep -qi " + pkg;
return !exec(cmd.c_str()).empty();
}
std::vector<PackageInfo> searchSnap(const std::string& query) {
std::vector<PackageInfo> results;
std::string output = exec(("snap find " + query + " 2>&1").c_str());
std::istringstream iss(output);
std::string line;
bool headerSkipped = false;
while (std::getline(iss, line)) {
if (line.empty()) continue;
if (!headerSkipped) { headerSkipped = true; continue; } // skip header
PackageInfo pkg;
size_t tabPos = line.find('\t');
if (tabPos != std::string::npos) {
pkg.name = line.substr(0, tabPos);
pkg.installed = isSnapInstalled(pkg.name);
results.push_back(pkg);
}
}
return results;
}
bool isSnapInstalled(const std::string& pkg) {
std::string cmd = "snap list " + pkg + " > /dev/null 2>&1";
return system(cmd.c_str()) == 0;
}
bool installSnap(const std::string& pkg,
std::function<void(const std::string&)> progressCallback) {
if (progressCallback) progressCallback("📦 Installation Snap: " + pkg + "...");
exec(("sudo snap install " + pkg + " 2>&1").c_str());
return isSnapInstalled(pkg);
}
bool removeSnap(const std::string& pkg,
std::function<void(const std::string&)> progressCallback) {
if (progressCallback) progressCallback("🗑️ Suppression Snap: " + pkg + "...");
exec(("sudo snap remove " + pkg + " 2>&1").c_str());
return !isSnapInstalled(pkg);
}
std::vector<PackageInfo> listInstalledSnap() {
std::vector<PackageInfo> results;
std::string output = exec("snap list 2>&1");
std::istringstream iss(output);
std::string line;
bool headerSkipped = false;
while (std::getline(iss, line)) {
if (line.empty()) continue;
if (!headerSkipped) { headerSkipped = true; continue; }
PackageInfo pkg;
size_t tabPos = line.find('\t');
if (tabPos != std::string::npos) {
pkg.name = line.substr(0, tabPos);
pkg.installed = true;
results.push_back(pkg);
}
}
return results;
}
// =========================================================================
// AUR (Arch User Repository)
// =========================================================================
bool isAURPackage(const std::string& pkg) {
if (m_hasCurl) {
std::string cmd = "curl -s \"https://aur.archlinux.org/rpc/v5/info/" + pkg + "\" 2>&1 | grep -q '\"results\"'";
return system(cmd.c_str()) == 0;
}
return false;
}
std::vector<PackageInfo> searchAUR(const std::string& query) {
std::vector<PackageInfo> results;
if (!m_hasCurl) return results;
std::string cmd = "curl -s \"https://aur.archlinux.org/rpc/v5/search/" + query + "\" 2>&1";
std::string output = exec(cmd.c_str());
// Simple JSON parse for AUR results
size_t pos = 0;
while ((pos = output.find("\"Name\":\"", pos)) != std::string::npos) {
size_t start = pos + 8;
size_t end = output.find("\"", start);
if (end != std::string::npos) {
PackageInfo pkg;
pkg.name = output.substr(start, end - start);
// Find description
size_t descPos = output.find("\"Description\":\"", end);
if (descPos != std::string::npos) {
size_t descStart = descPos + 15;
size_t descEnd = output.find("\"", descStart);
if (descEnd != std::string::npos) {
pkg.description = output.substr(descStart, descEnd - descStart);
}
}
// Find version
size_t verPos = output.find("\"Version\":\"", end);
if (verPos != std::string::npos) {
size_t verStart = verPos + 11;
size_t verEnd = output.find("\"", verStart);
if (verEnd != std::string::npos) {
pkg.version = output.substr(verStart, verEnd - verStart);
}
}
pkg.repository = "aur";
pkg.installed = isAURInstalled(pkg.name);
results.push_back(pkg);
pos = end;
}
}
return results;
}
bool isAURInstalled(const std::string& pkg) {
std::string cmd = "pacman -Qi " + pkg + " > /dev/null 2>&1";
return system(cmd.c_str()) == 0;
}
bool installAUR(const std::string& pkg,
std::function<void(const std::string&)> progressCallback) {
if (progressCallback) progressCallback("⚙️ Clonage depuis AUR: " + pkg + "...");
std::string tmpDir = "/tmp/aur-build-" + pkg;
std::string cloneCmd = "rm -rf " + tmpDir + " && git clone https://aur.archlinux.org/" + pkg + ".git " + tmpDir;
exec(cloneCmd.c_str());
if (progressCallback) progressCallback("⚙️ Compilation avec makepkg...");
std::string buildCmd = "cd " + tmpDir + " && makepkg -si --noconfirm 2>&1";
std::string output = exec(buildCmd.c_str());
if (progressCallback) {
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty()) progressCallback(line);
}
}
// Cleanup
exec(("rm -rf " + tmpDir).c_str());
return isAURInstalled(pkg);
}
// =========================================================================
// Nix
// =========================================================================
bool isNixPackage(const std::string& pkg) {
std::string cmd = "nix-env -qaP " + pkg + " 2>&1 | grep -qi " + pkg;
return !exec(cmd.c_str()).empty();
}
std::vector<PackageInfo> searchNix(const std::string& query) {
std::vector<PackageInfo> results;
std::string output = exec(("nix-env -qaP " + query + " 2>&1").c_str());
std::istringstream iss(output);
std::string line;
while (std::getline(iss, line)) {
if (line.empty()) continue;
PackageInfo pkg;
size_t spacePos = line.find(' ');
size_t tabPos = line.find('\t');
if (tabPos != std::string::npos) {
// Format: "nixpkgs.package-name package-name-version"
std::string fullPath = line.substr(0, tabPos);
size_t lastDot = fullPath.rfind('.');
if (lastDot != std::string::npos) {
pkg.name = fullPath.substr(lastDot + 1);
}
pkg.version = line.substr(tabPos + 1);
pkg.repository = "nix";
pkg.installed = isNixInstalled(pkg.name);
results.push_back(pkg);
}
}
return results;
}
bool isNixInstalled(const std::string& pkg) {
std::string cmd = "nix-env -q " + pkg + " > /dev/null 2>&1";
return system(cmd.c_str()) == 0;
}
bool installNix(const std::string& pkg,
std::function<void(const std::string&)> progressCallback) {
if (progressCallback) progressCallback("📦 Installation Nix: " + pkg + "...");
exec(("nix-env -iA nixpkgs." + pkg + " 2>&1").c_str());
return isNixInstalled(pkg);
}
// =========================================================================
// GitHub search
// =========================================================================
std::vector<PackageInfo> searchGitHub(const std::string& query) {
std::vector<PackageInfo> results;
if (!m_hasCurl) return results;
std::string cmd = "curl -s 'https://api.github.com/search/repositories?q=" + query + "&sort=stars&per_page=5' 2>&1";
std::string output = exec(cmd.c_str());
size_t pos = 0;
while ((pos = output.find("\"full_name\":\"", pos)) != std::string::npos) {
size_t start = pos + 13;
size_t end = output.find("\"", start);
if (end != std::string::npos) {
PackageInfo pkg;
std::string fullName = output.substr(start, end - start);
size_t slashPos = fullName.find('/');
pkg.name = (slashPos != std::string::npos) ? fullName.substr(slashPos + 1) : fullName;
pkg.repository = "github";
// Find description
size_t descPos = output.find("\"description\":\"", end);
if (descPos != std::string::npos && descPos < end + 500) {
size_t dStart = descPos + 16;
size_t dEnd = output.find("\"", dStart);
if (dEnd != std::string::npos) {
pkg.description = output.substr(dStart, dEnd - dStart);
}
}
pkg.version = "source";
pkg.installed = false;
results.push_back(pkg);
pos = end;
}
}
return results;
}
// =========================================================================
// GitHub / Source compilation
// =========================================================================
SourceRepo findSourceRepo(const std::string& query) {
SourceRepo repo;
if (m_hasCurl) {
// Search GitHub API
std::string cmd = "curl -s \"https://api.github.com/search/repositories?q=" + query + "&sort=stars&per_page=1\" 2>&1";
std::string output = exec(cmd.c_str());
// Parse JSON for html_url
size_t urlPos = output.find("\"html_url\":\"");
if (urlPos != std::string::npos) {
size_t start = urlPos + 12;
size_t end = output.find("\"", start);
if (end != std::string::npos) {
repo.url = output.substr(start, end - start);
repo.type = "github";
repo.found = true;
}
}
// Parse name
size_t namePos = output.find("\"full_name\":\"");
if (namePos != std::string::npos) {
size_t start = namePos + 13;
size_t end = output.find("\"", start);
if (end != std::string::npos) {
repo.name = output.substr(start, end - start);
}
}
}
return repo;
}
bool installFromSource(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) {
SourceRepo repo = findSourceRepo(packageName);
if (!repo.found) {
if (progressCallback) progressCallback("❌ Aucune source trouvée pour " + packageName);
return false;
}
if (progressCallback) progressCallback("📥 Clonage depuis " + repo.url + "...");
std::string tmpDir = "/tmp/source-build-" + packageName;
std::string cloneCmd = "rm -rf " + tmpDir + " && git clone --depth 1 " + repo.url + " " + tmpDir;
exec(cloneCmd.c_str());
if (progressCallback) progressCallback("⚙️ Détection du système de build...");
// Try different build systems
bool success = false;
// CMake
if (!success && fileExists(tmpDir + "/CMakeLists.txt")) {
if (progressCallback) progressCallback("🔨 Build CMake...");
exec(("mkdir -p " + tmpDir + "/build").c_str());
exec(("cd " + tmpDir + "/build && cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local 2>&1").c_str());
exec(("cd " + tmpDir + "/build && make -j$(nproc) 2>&1").c_str());
success = exec(("cd " + tmpDir + "/build && sudo make install 2>&1").c_str()).find("error") == std::string::npos;
}
// Meson
if (!success && fileExists(tmpDir + "/meson.build")) {
if (progressCallback) progressCallback("🔨 Build Meson...");
exec(("cd " + tmpDir + " && meson setup build --prefix=/usr/local 2>&1").c_str());
exec(("cd " + tmpDir + "/build && ninja 2>&1").c_str());
success = exec(("cd " + tmpDir + "/build && sudo ninja install 2>&1").c_str()).find("error") == std::string::npos;
}
// Autotools (configure)
if (!success && fileExists(tmpDir + "/configure")) {
if (progressCallback) progressCallback("🔨 Build Autotools...");
exec(("cd " + tmpDir + " && ./configure --prefix=/usr/local 2>&1").c_str());
exec(("cd " + tmpDir + " && make -j$(nproc) 2>&1").c_str());
success = exec(("cd " + tmpDir + " && sudo make install 2>&1").c_str()).find("error") == std::string::npos;
}
// Makefile
if (!success && fileExists(tmpDir + "/Makefile")) {
if (progressCallback) progressCallback("🔨 Build Make...");
exec(("cd " + tmpDir + " && make -j$(nproc) 2>&1").c_str());
success = exec(("cd " + tmpDir + " && sudo make install 2>&1").c_str()).find("error") == std::string::npos;
}
// Cargo (Rust)
if (!success && fileExists(tmpDir + "/Cargo.toml")) {
if (progressCallback) progressCallback("🔨 Build Cargo (Rust)...");
success = exec(("cd " + tmpDir + " && cargo build --release 2>&1 && sudo cargo install --path . 2>&1").c_str()).find("error") == std::string::npos;
}
// Go
if (!success && fileExists(tmpDir + "/go.mod")) {
if (progressCallback) progressCallback("🔨 Build Go...");
success = exec(("cd " + tmpDir + " && go build -o /usr/local/bin/" + packageName + " . 2>&1").c_str()).find("error") == std::string::npos;
}
// npm (Node.js)
if (!success && fileExists(tmpDir + "/package.json")) {
if (progressCallback) progressCallback("🔨 Build npm (Node.js)...");
exec(("cd " + tmpDir + " && npm install 2>&1").c_str());
success = exec(("cd " + tmpDir + " && sudo npm install -g . 2>&1").c_str()).find("error") == std::string::npos;
}
// pip (Python)
if (!success && (fileExists(tmpDir + "/setup.py") || fileExists(tmpDir + "/pyproject.toml"))) {
if (progressCallback) progressCallback("🔨 Build pip (Python)...");
success = exec(("cd " + tmpDir + " && sudo pip install . 2>&1").c_str()).find("error") == std::string::npos;
}
// Cleanup
exec(("rm -rf " + tmpDir).c_str());
if (success) {
if (progressCallback) progressCallback("✅ " + packageName + " installé depuis source !");
} else {
if (progressCallback) progressCallback("❌ Échec de la compilation de " + packageName);
}
return success;
}
bool fileExists(const std::string& path) {
std::string cmd = "test -f " + path + " && echo yes || echo no";
std::string result = exec(cmd.c_str());
return result.find("yes") != std::string::npos;
}
// =========================================================================
// Data members
// =========================================================================
std::vector<DetectedManager> m_managers;
bool m_hasFlatpak = false;
bool m_hasSnap = false;
bool m_hasAUR = false;
bool m_hasNix = false;
bool m_hasCurl = false;
bool m_hasGit = false;
bool m_hasMake = false;
bool m_hasCMake = false;
bool m_hasGcc = false;
};
// ============================================================================
// Plugin entry points
// ============================================================================
extern "C" {
IPackageManager* createPlugin() {
return new UniversalPlugin();
}
void destroyPlugin(IPackageManager* plugin) {
delete plugin;
}
}
-98
View File
@@ -1,98 +0,0 @@
#include "HistoryManager.h"
#include <filesystem>
#include <cstring>
#include <iomanip>
namespace fs = std::filesystem;
HistoryManager::HistoryManager(const std::string& historyFile)
: m_historyFile(expandPath(historyFile)) {
load();
}
HistoryManager::~HistoryManager() {
save();
}
std::string HistoryManager::expandPath(const std::string& path) {
if (path.empty()) return path;
std::string result = path;
if (result[0] == '~') {
const char* home = getenv("HOME");
if (home) {
result = std::string(home) + result.substr(1);
}
}
// Ensure directory exists
auto dir = fs::path(result).parent_path();
if (!fs::exists(dir)) {
fs::create_directories(dir);
}
return result;
}
std::string HistoryManager::getCurrentTimestamp() {
auto now = std::time(nullptr);
auto* tm = std::localtime(&now);
char buffer[64];
std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", tm);
return std::string(buffer);
}
void HistoryManager::record(const HistoryEntry& entry) {
HistoryEntry e = entry;
if (e.timestamp.empty()) {
e.timestamp = getCurrentTimestamp();
}
m_history.push_back(e);
save();
}
const std::vector<HistoryEntry>& HistoryManager::getHistory() const {
return m_history;
}
void HistoryManager::clear() {
m_history.clear();
save();
}
void HistoryManager::save() {
std::ofstream file(m_historyFile);
if (!file.is_open()) return;
file << "timestamp,action,package,plugin,success\n";
for (const auto& entry : m_history) {
file << entry.timestamp << ","
<< entry.action << ","
<< entry.package << ","
<< entry.plugin << ","
<< (entry.success ? "1" : "0") << "\n";
}
}
void HistoryManager::load() {
std::ifstream file(m_historyFile);
if (!file.is_open()) return;
std::string line;
std::getline(file, line); // skip header
while (std::getline(file, line)) {
std::istringstream ss(line);
HistoryEntry entry;
std::string successStr;
std::getline(ss, entry.timestamp, ',');
std::getline(ss, entry.action, ',');
std::getline(ss, entry.package, ',');
std::getline(ss, entry.plugin, ',');
std::getline(ss, successStr, ',');
entry.success = (successStr == "1");
m_history.push_back(entry);
}
}
-731
View File
@@ -1,731 +0,0 @@
#include "MainWindow.h"
#include <QMessageBox>
#include <QHeaderView>
#include <QSplitter>
#include <QFrame>
#include <QScrollArea>
#include <QStyle>
#include <QDesktopServices>
#include <QUrl>
// Worker threads
SearchWorker::SearchWorker(IPackageManager* pm, const std::string& query)
: m_pm(pm), m_query(query) {}
void SearchWorker::run() {
auto results = m_pm->search(m_query);
emit finished(results);
}
InstallWorker::InstallWorker(IPackageManager* pm, const std::string& package, bool remove)
: m_pm(pm), m_package(package), m_remove(remove) {}
void InstallWorker::run() {
bool success;
if (m_remove) {
success = m_pm->remove(m_package, [this](const std::string& msg) {
emit progress(QString::fromStdString(msg));
});
} else {
success = m_pm->install(m_package, [this](const std::string& msg) {
emit progress(QString::fromStdString(msg));
});
}
emit finished(success);
}
// MainWindow implementation
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
m_pluginManager = new PluginManager();
m_historyManager = new HistoryManager();
m_packageModel = new PackageModel(this);
m_currentPlugin = nullptr;
setupUI();
setupMenuBar();
loadPlugins();
updateStatusBar();
}
MainWindow::~MainWindow() {
delete m_pluginManager;
delete m_historyManager;
}
void MainWindow::setupUI() {
QWidget* centralWidget = new QWidget(this);
QVBoxLayout* mainLayout = new QVBoxLayout(centralWidget);
mainLayout->setContentsMargins(10, 10, 10, 10);
// Top bar: Plugin selector + Search
QHBoxLayout* topBar = new QHBoxLayout();
m_pluginSelector = new QComboBox();
m_pluginSelector->setMinimumWidth(150);
m_pluginSelector->setToolTip("Sélectionner le gestionnaire de paquets");
connect(m_pluginSelector, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &MainWindow::onPluginChanged);
topBar->addWidget(m_pluginSelector);
m_searchBar = new QLineEdit();
m_searchBar->setPlaceholderText("🔍 Rechercher un paquet...");
m_searchBar->setMinimumHeight(36);
m_searchBar->setStyleSheet(
"QLineEdit {"
" padding: 8px 16px;"
" font-size: 14px;"
" border: 2px solid #3a3a3a;"
" border-radius: 20px;"
" background: #2a2a2a;"
" color: #ffffff;"
"}"
"QLineEdit:focus {"
" border-color: #6c63ff;"
"}"
);
connect(m_searchBar, &QLineEdit::returnPressed, this, &MainWindow::onSearch);
topBar->addWidget(m_searchBar, 1);
m_searchButton = new QPushButton("Rechercher");
m_searchButton->setMinimumHeight(36);
m_searchButton->setStyleSheet(
"QPushButton {"
" background: #6c63ff;"
" color: white;"
" border: none;"
" padding: 8px 24px;"
" border-radius: 20px;"
" font-weight: bold;"
" font-size: 14px;"
"}"
"QPushButton:hover {"
" background: #5a52d5;"
"}"
);
connect(m_searchButton, &QPushButton::clicked, this, &MainWindow::onSearch);
topBar->addWidget(m_searchButton);
mainLayout->addLayout(topBar);
// Progress bar
m_progressBar = new QProgressBar();
m_progressBar->setVisible(false);
m_progressBar->setStyleSheet(
"QProgressBar {"
" border: 1px solid #3a3a3a;"
" border-radius: 5px;"
" text-align: center;"
" color: white;"
" background: #2a2a2a;"
"}"
"QProgressBar::chunk {"
" background: #6c63ff;"
" border-radius: 5px;"
"}"
);
mainLayout->addWidget(m_progressBar);
// Main content area
QSplitter* splitter = new QSplitter(Qt::Horizontal);
// Left panel: Package list
QWidget* leftPanel = new QWidget();
QVBoxLayout* leftLayout = new QVBoxLayout(leftPanel);
// Action buttons
QHBoxLayout* buttonBar = new QHBoxLayout();
m_installButton = new QPushButton("📦 Installer");
m_installButton->setEnabled(false);
m_installButton->setStyleSheet(
"QPushButton { background: #4caf50; color: white; border: none; "
"padding: 6px 16px; border-radius: 8px; font-weight: bold; }"
"QPushButton:hover { background: #43a047; }"
"QPushButton:disabled { background: #555; color: #888; }"
);
connect(m_installButton, &QPushButton::clicked, this, &MainWindow::onInstall);
buttonBar->addWidget(m_installButton);
m_removeButton = new QPushButton("🗑️ Supprimer");
m_removeButton->setEnabled(false);
m_removeButton->setStyleSheet(
"QPushButton { background: #f44336; color: white; border: none; "
"padding: 6px 16px; border-radius: 8px; font-weight: bold; }"
"QPushButton:hover { background: #e53935; }"
"QPushButton:disabled { background: #555; color: #888; }"
);
connect(m_removeButton, &QPushButton::clicked, this, &MainWindow::onRemove);
buttonBar->addWidget(m_removeButton);
m_updateButton = new QPushButton("🔄 Mettre à jour");
m_updateButton->setEnabled(false);
m_updateButton->setStyleSheet(
"QPushButton { background: #ff9800; color: white; border: none; "
"padding: 6px 16px; border-radius: 8px; font-weight: bold; }"
"QPushButton:hover { background: #f57c00; }"
"QPushButton:disabled { background: #555; color: #888; }"
);
connect(m_updateButton, &QPushButton::clicked, this, &MainWindow::onUpdate);
buttonBar->addWidget(m_updateButton);
m_updateAllButton = new QPushButton("⬆️ Tout mettre à jour");
m_updateAllButton->setEnabled(false);
m_updateAllButton->setStyleSheet(
"QPushButton { background: #2196f3; color: white; border: none; "
"padding: 6px 16px; border-radius: 8px; font-weight: bold; }"
"QPushButton:hover { background: #1e88e5; }"
"QPushButton:disabled { background: #555; color: #888; }"
);
connect(m_updateAllButton, &QPushButton::clicked, this, &MainWindow::onUpdateAll);
buttonBar->addWidget(m_updateAllButton);
leftLayout->addLayout(buttonBar);
// Package list
m_packageList = new QListWidget();
m_packageList->setStyleSheet(
"QListWidget {"
" background: #1e1e1e;"
" border: 1px solid #3a3a3a;"
" border-radius: 8px;"
" padding: 4px;"
" font-size: 13px;"
"}"
"QListWidget::item {"
" padding: 8px 12px;"
" border-bottom: 1px solid #2a2a2a;"
" color: #e0e0e0;"
"}"
"QListWidget::item:selected {"
" background: #3a3a5a;"
" color: white;"
"}"
"QListWidget::item:hover {"
" background: #2a2a3a;"
"}"
);
connect(m_packageList, &QListWidget::currentRowChanged,
this, &MainWindow::onPackageSelected);
leftLayout->addWidget(m_packageList);
splitter->addWidget(leftPanel);
// Right panel: Package details
QWidget* rightPanel = new QWidget();
QVBoxLayout* rightLayout = new QVBoxLayout(rightPanel);
// Package info cards
QFrame* infoCard = new QFrame();
infoCard->setStyleSheet(
"QFrame {"
" background: #1e1e1e;"
" border: 1px solid #3a3a3a;"
" border-radius: 12px;"
" padding: 16px;"
"}"
);
QVBoxLayout* infoLayout = new QVBoxLayout(infoCard);
m_packageName = new QLabel("Sélectionnez un paquet");
m_packageName->setStyleSheet("font-size: 20px; font-weight: bold; color: #6c63ff;");
infoLayout->addWidget(m_packageName);
m_packageVersion = new QLabel("");
m_packageVersion->setStyleSheet("font-size: 14px; color: #aaa;");
infoLayout->addWidget(m_packageVersion);
m_packageRepo = new QLabel("");
m_packageRepo->setStyleSheet("font-size: 12px; color: #888;");
infoLayout->addWidget(m_packageRepo);
m_packageSize = new QLabel("");
m_packageSize->setStyleSheet("font-size: 12px; color: #888;");
infoLayout->addWidget(m_packageSize);
m_packageDescription = new QLabel("");
m_packageDescription->setWordWrap(true);
m_packageDescription->setStyleSheet("font-size: 13px; color: #ccc; margin-top: 10px;");
infoLayout->addWidget(m_packageDescription);
rightLayout->addWidget(infoCard);
rightLayout->addStretch();
splitter->addWidget(rightPanel);
splitter->setSizes({600, 400});
mainLayout->addWidget(splitter, 1);
// Bottom bar
QHBoxLayout* bottomBar = new QHBoxLayout();
bottomBar->addStretch();
m_refreshButton = new QPushButton("🔄 Rafraîchir les sources");
m_refreshButton->setStyleSheet(
"QPushButton { background: #607d8b; color: white; border: none; "
"padding: 6px 16px; border-radius: 8px; }"
"QPushButton:hover { background: #546e7a; }"
);
connect(m_refreshButton, &QPushButton::clicked, this, &MainWindow::onRefresh);
bottomBar->addWidget(m_refreshButton);
m_historyButton = new QPushButton("📋 Historique");
m_historyButton->setStyleSheet(
"QPushButton { background: #795548; color: white; border: none; "
"padding: 6px 16px; border-radius: 8px; }"
"QPushButton:hover { background: #6d4c41; }"
);
connect(m_historyButton, &QPushButton::clicked, this, &MainWindow::onShowHistory);
bottomBar->addWidget(m_historyButton);
mainLayout->addLayout(bottomBar);
setCentralWidget(centralWidget);
// Status bar
statusBar()->setStyleSheet("color: #888; font-size: 12px;");
statusBar()->showMessage("Prêt");
// Dark theme
setStyleSheet(
"QMainWindow { background: #121212; }"
"QWidget { background: #121212; color: #e0e0e0; }"
"QComboBox {"
" background: #2a2a2a;"
" border: 2px solid #3a3a3a;"
" border-radius: 8px;"
" padding: 6px 12px;"
" color: white;"
"}"
"QComboBox::drop-down { border: none; }"
"QComboBox QAbstractItemView {"
" background: #2a2a2a;"
" color: white;"
" selection-background-color: #6c63ff;"
"}"
);
}
void MainWindow::setupMenuBar() {
QMenuBar* menuBar = this->menuBar();
menuBar->setStyleSheet(
"QMenuBar { background: #1a1a1a; color: white; }"
"QMenuBar::item:selected { background: #3a3a3a; }"
"QMenu { background: #2a2a2a; color: white; }"
"QMenu::item:selected { background: #6c63ff; }"
);
// File menu
QMenu* fileMenu = menuBar->addMenu("Fichier");
fileMenu->addAction("Quitter", this, &QWidget::close);
// Tools menu
QMenu* toolsMenu = menuBar->addMenu("Outils");
toolsMenu->addAction("Rafraîchir les sources", this, &MainWindow::onRefresh);
toolsMenu->addAction("Historique", this, &MainWindow::onShowHistory);
// Help menu
QMenu* helpMenu = menuBar->addMenu("Aide");
helpMenu->addAction("À propos", [this]() {
QMessageBox::about(this, "PackageMapper",
"<h2>PackageMapper v1.0.0</h2>"
"<p>Gestionnaire de paquets unifié avec support d'extensions.</p>"
"<p>Système de plugins : chargez des gestionnaires supplémentaires "
"pour gérer apt, pkg, et bien d'autres.</p>"
);
});
}
void MainWindow::loadPlugins() {
m_pluginSelector->clear();
// Try to load from default paths
m_pluginManager->loadPluginsFromDirectory("/usr/lib/PackageMapper/plugins");
m_pluginManager->loadPluginsFromDirectory("/usr/local/lib/PackageMapper/plugins");
char* home = getenv("HOME");
if (home) {
std::string userPluginDir = std::string(home) + "/.local/lib/PackageMapper/plugins";
m_pluginManager->loadPluginsFromDirectory(userPluginDir);
}
size_t count = m_pluginManager->getPluginCount();
if (count == 0) {
m_pluginSelector->addItem("Aucun plugin chargé");
m_currentPlugin = nullptr;
statusBar()->showMessage("⚠️ Aucun plugin trouvé. Compilez un plugin (pacman, apt, pkg...)");
return;
}
for (size_t i = 0; i < count; i++) {
IPackageManager* pm = m_pluginManager->getPlugin(i);
if (pm) {
std::string label = pm->getName() + " (" + pm->getVersion() + ")";
if (!pm->isAvailable()) {
label += " ⚠️ Non disponible";
}
m_pluginSelector->addItem(QString::fromStdString(label));
}
}
onPluginChanged(0);
}
void MainWindow::onPluginChanged(int index) {
if (index < 0 || index >= static_cast<int>(m_pluginManager->getPluginCount())) {
m_currentPlugin = nullptr;
return;
}
m_currentPlugin = m_pluginManager->getPlugin(index);
if (!m_currentPlugin) return;
bool available = m_currentPlugin->isAvailable();
m_searchButton->setEnabled(available);
m_searchBar->setEnabled(available);
m_refreshButton->setEnabled(available && m_currentPlugin->canSearch());
m_updateAllButton->setEnabled(available && m_currentPlugin->canUpdate());
updateStatusBar();
statusBar()->showMessage(
QString("Plugin: %1 - %2")
.arg(QString::fromStdString(m_currentPlugin->getName()))
.arg(available ? "✅ Disponible" : "❌ Non disponible")
);
}
void MainWindow::onSearch() {
if (!m_currentPlugin || !m_currentPlugin->isAvailable()) {
QMessageBox::warning(this, "Erreur", "Aucun plugin disponible.");
return;
}
std::string query = m_searchBar->text().toStdString();
if (query.empty()) {
QMessageBox::information(this, "Info", "Entrez un terme de recherche.");
return;
}
statusBar()->showMessage("🔍 Recherche en cours...");
m_progressBar->setVisible(true);
m_progressBar->setRange(0, 0); // Indeterminate
m_packageList->clear();
SearchWorker* worker = new SearchWorker(m_currentPlugin, query);
connect(worker, &SearchWorker::finished, this, &MainWindow::onSearchFinished);
connect(worker, &SearchWorker::finished, worker, &QObject::deleteLater);
worker->start();
}
void MainWindow::onSearchFinished(std::vector<PackageInfo> results) {
m_progressBar->setVisible(false);
m_currentResults = results;
m_packageList->clear();
for (const auto& pkg : results) {
QString label = QString("📦 %1 %2").arg(
QString::fromStdString(pkg.name),
QString::fromStdString(pkg.version)
);
if (pkg.installed) {
label += " ✅ Installé";
}
if (pkg.updateAvailable) {
label += " 🔄 Mise à jour disponible";
}
m_packageList->addItem(label);
}
statusBar()->showMessage(
QString("📋 %1 paquet(s) trouvé(s)").arg(results.size()));
}
void MainWindow::onPackageSelected(int row) {
if (row < 0 || row >= static_cast<int>(m_currentResults.size())) {
m_installButton->setEnabled(false);
m_removeButton->setEnabled(false);
m_updateButton->setEnabled(false);
return;
}
m_selectedPackage = m_currentResults[row];
updatePackageInfo(m_selectedPackage);
m_installButton->setEnabled(
m_currentPlugin && m_currentPlugin->canInstall() && !m_selectedPackage.installed);
m_removeButton->setEnabled(
m_currentPlugin && m_currentPlugin->canRemove() && m_selectedPackage.installed);
m_updateButton->setEnabled(
m_currentPlugin && m_currentPlugin->canUpdate() && m_selectedPackage.updateAvailable);
}
void MainWindow::updatePackageInfo(const PackageInfo& pkg) {
m_packageName->setText(QString::fromStdString(pkg.name));
m_packageVersion->setText(
QString("Version: %1").arg(QString::fromStdString(pkg.version)));
m_packageRepo->setText(
QString("Dépôt: %1").arg(QString::fromStdString(pkg.repository)));
m_packageSize->setText(
QString("Taille: %1").arg(QString::fromStdString(pkg.size)));
m_packageDescription->setText(QString::fromStdString(pkg.description));
}
void MainWindow::onInstall() {
if (m_selectedPackage.name.empty()) return;
performInstall(m_selectedPackage.name);
}
void MainWindow::onRemove() {
if (m_selectedPackage.name.empty()) return;
performRemove(m_selectedPackage.name);
}
void MainWindow::onUpdate() {
if (m_selectedPackage.name.empty()) return;
statusBar()->showMessage(
QString("🔄 Mise à jour de %1...").arg(QString::fromStdString(m_selectedPackage.name)));
m_progressBar->setVisible(true);
m_progressBar->setRange(0, 0);
auto* worker = new InstallWorker(m_currentPlugin, m_selectedPackage.name, false);
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
statusBar()->showMessage(msg);
});
connect(worker, &InstallWorker::finished, [this](bool success) {
m_progressBar->setVisible(false);
if (success) {
statusBar()->showMessage("✅ Mise à jour terminée");
m_historyManager->record({"", "update", m_selectedPackage.name,
m_currentPlugin->getName(), true});
} else {
statusBar()->showMessage("❌ Échec de la mise à jour");
m_historyManager->record({"", "update", m_selectedPackage.name,
m_currentPlugin->getName(), false});
}
});
connect(worker, &InstallWorker::finished, worker, &QObject::deleteLater);
worker->start();
}
void MainWindow::onUpdateAll() {
if (!m_currentPlugin || !m_currentPlugin->isAvailable()) return;
statusBar()->showMessage("🔄 Mise à jour de tous les paquets...");
m_progressBar->setVisible(true);
m_progressBar->setRange(0, 0);
auto* worker = new InstallWorker(m_currentPlugin, "", false);
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
statusBar()->showMessage(msg);
});
connect(worker, &InstallWorker::finished, [this](bool success) {
m_progressBar->setVisible(false);
if (success) {
statusBar()->showMessage("✅ Tous les paquets sont à jour");
} else {
statusBar()->showMessage("❌ Erreur lors de la mise à jour globale");
}
});
connect(worker, &InstallWorker::finished, worker, &QObject::deleteLater);
worker->start();
}
void MainWindow::onRefresh() {
if (!m_currentPlugin || !m_currentPlugin->isAvailable()) return;
statusBar()->showMessage("🔄 Rafraîchissement des sources...");
m_progressBar->setVisible(true);
m_progressBar->setRange(0, 0);
auto* worker = new InstallWorker(m_currentPlugin, "", false);
connect(worker, &InstallWorker::finished, [this](bool) {
m_progressBar->setVisible(false);
statusBar()->showMessage("✅ Sources rafraîchies");
});
connect(worker, &InstallWorker::finished, worker, &QObject::deleteLater);
worker->start();
}
void MainWindow::performSearch(const std::string& query) {
statusBar()->showMessage("🔍 Recherche...");
m_progressBar->setVisible(true);
m_progressBar->setRange(0, 0);
SearchWorker* worker = new SearchWorker(m_currentPlugin, query);
connect(worker, &SearchWorker::finished, this, &MainWindow::onSearchFinished);
connect(worker, &SearchWorker::finished, worker, &QObject::deleteLater);
worker->start();
}
void MainWindow::performInstall(const std::string& package) {
statusBar()->showMessage(
QString("📦 Installation de %1...").arg(QString::fromStdString(package)));
m_progressBar->setVisible(true);
m_progressBar->setRange(0, 0);
auto* worker = new InstallWorker(m_currentPlugin, package, false);
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
statusBar()->showMessage(msg);
});
connect(worker, &InstallWorker::finished, [this](bool success) {
m_progressBar->setVisible(false);
if (success) {
statusBar()->showMessage(
QString("✅ %1 installé avec succès").arg(
QString::fromStdString(m_selectedPackage.name)));
m_historyManager->record({"", "install", m_selectedPackage.name,
m_currentPlugin->getName(), true});
} else {
statusBar()->showMessage(
QString("❌ Échec de l'installation de %1").arg(
QString::fromStdString(m_selectedPackage.name)));
m_historyManager->record({"", "install", m_selectedPackage.name,
m_currentPlugin->getName(), false});
}
});
connect(worker, &InstallWorker::finished, worker, &QObject::deleteLater);
worker->start();
}
void MainWindow::performRemove(const std::string& package) {
QMessageBox::StandardButton reply = QMessageBox::question(this,
"Confirmation",
QString("Voulez-vous vraiment supprimer %1 ?").arg(
QString::fromStdString(package)),
QMessageBox::Yes | QMessageBox::No);
if (reply != QMessageBox::Yes) return;
statusBar()->showMessage(
QString("🗑️ Suppression de %1...").arg(QString::fromStdString(package)));
m_progressBar->setVisible(true);
m_progressBar->setRange(0, 0);
auto* worker = new InstallWorker(m_currentPlugin, package, true);
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
statusBar()->showMessage(msg);
});
connect(worker, &InstallWorker::finished, [this](bool success) {
m_progressBar->setVisible(false);
if (success) {
statusBar()->showMessage(
QString("✅ %1 supprimé avec succès").arg(
QString::fromStdString(m_selectedPackage.name)));
m_historyManager->record({"", "remove", m_selectedPackage.name,
m_currentPlugin->getName(), true});
} else {
statusBar()->showMessage(
QString("❌ Échec de la suppression de %1").arg(
QString::fromStdString(m_selectedPackage.name)));
m_historyManager->record({"", "remove", m_selectedPackage.name,
m_currentPlugin->getName(), false});
}
});
connect(worker, &InstallWorker::finished, worker, &QObject::deleteLater);
worker->start();
}
void MainWindow::onShowHistory() {
QDialog dialog(this);
dialog.setWindowTitle("📋 Historique des actions");
dialog.setMinimumSize(600, 400);
dialog.setStyleSheet(
"QDialog { background: #1a1a1a; }"
"QLabel { color: white; }"
);
QVBoxLayout* layout = new QVBoxLayout(&dialog);
QTextEdit* textEdit = new QTextEdit();
textEdit->setReadOnly(true);
textEdit->setStyleSheet(
"QTextEdit { background: #1e1e1e; color: #e0e0e0; border: 1px solid #3a3a3a; "
"border-radius: 8px; padding: 8px; font-family: monospace; font-size: 13px; }"
);
const auto& history = m_historyManager->getHistory();
if (history.empty()) {
textEdit->setPlainText("Aucune action enregistrée.");
} else {
QString text;
for (const auto& entry : history) {
text += QString("[%1] %2: %3 (%4) - %5\n")
.arg(QString::fromStdString(entry.timestamp))
.arg(QString::fromStdString(entry.action))
.arg(QString::fromStdString(entry.package))
.arg(QString::fromStdString(entry.plugin))
.arg(entry.success ? "✅ Succès" : "❌ Échec");
}
textEdit->setPlainText(text);
}
layout->addWidget(textEdit);
QPushButton* clearBtn = new QPushButton("🗑️ Effacer l'historique");
clearBtn->setStyleSheet(
"QPushButton { background: #f44336; color: white; border: none; "
"padding: 8px 16px; border-radius: 8px; }"
"QPushButton:hover { background: #e53935; }"
);
connect(clearBtn, &QPushButton::clicked, [&dialog, this]() {
m_historyManager->clear();
dialog.close();
});
layout->addWidget(clearBtn);
dialog.exec();
}
void MainWindow::updateStatusBar() {
if (!m_currentPlugin) {
statusBar()->showMessage("Aucun plugin chargé");
return;
}
QString info = QString("Plugin: %1 | Paquets trouvés: %2 | Éléments en historique: %3")
.arg(QString::fromStdString(m_currentPlugin->getName()))
.arg(m_currentResults.size())
.arg(m_historyManager->getHistory().size());
statusBar()->showMessage(info);
}
void MainWindow::onToggleInstalledView() {
if (!m_currentPlugin || !m_currentPlugin->isAvailable()) return;
statusBar()->showMessage("📦 Chargement des paquets installés...");
m_progressBar->setVisible(true);
m_progressBar->setRange(0, 0);
SearchWorker* worker = new SearchWorker(m_currentPlugin, "");
connect(worker, &SearchWorker::finished, [this](std::vector<PackageInfo> results) {
m_progressBar->setVisible(false);
std::vector<PackageInfo> installed;
for (const auto& pkg : results) {
if (pkg.installed) installed.push_back(pkg);
}
onSearchFinished(installed);
statusBar()->showMessage(
QString("📦 %1 paquet(s) installé(s)").arg(installed.size()));
});
connect(worker, &SearchWorker::finished, worker, &QObject::deleteLater);
worker->start();
}
void MainWindow::onInstallFinished(bool success) {
m_progressBar->setVisible(false);
if (success) {
statusBar()->showMessage(
QString("✅ %1 installé avec succès").arg(
QString::fromStdString(m_selectedPackage.name)));
m_historyManager->record({"", "install", m_selectedPackage.name,
m_currentPlugin->getName(), true});
} else {
statusBar()->showMessage(
QString("❌ Échec de l'installation de %1").arg(
QString::fromStdString(m_selectedPackage.name)));
m_historyManager->record({"", "install", m_selectedPackage.name,
m_currentPlugin->getName(), false});
}
}
-58
View File
@@ -1,58 +0,0 @@
#include "PackageModel.h"
PackageModel::PackageModel(QObject* parent) : QAbstractListModel(parent) {}
int PackageModel::rowCount(const QModelIndex& parent) const {
Q_UNUSED(parent);
return static_cast<int>(m_packages.size());
}
QVariant PackageModel::data(const QModelIndex& index, int role) const {
if (!index.isValid() || index.row() >= static_cast<int>(m_packages.size())) {
return QVariant();
}
const PackageInfo& pkg = m_packages[index.row()];
switch (role) {
case NameRole: return QString::fromStdString(pkg.name);
case VersionRole: return QString::fromStdString(pkg.version);
case DescriptionRole: return QString::fromStdString(pkg.description);
case RepositoryRole: return QString::fromStdString(pkg.repository);
case InstalledRole: return pkg.installed;
case SizeRole: return QString::fromStdString(pkg.size);
case UpdateAvailableRole: return pkg.updateAvailable;
default: return QVariant();
}
}
QHash<int, QByteArray> PackageModel::roleNames() const {
return {
{NameRole, "name"},
{VersionRole, "version"},
{DescriptionRole, "description"},
{RepositoryRole, "repository"},
{InstalledRole, "installed"},
{SizeRole, "size"},
{UpdateAvailableRole, "updateAvailable"}
};
}
void PackageModel::setPackages(const std::vector<PackageInfo>& packages) {
beginResetModel();
m_packages = packages;
endResetModel();
}
void PackageModel::clear() {
beginResetModel();
m_packages.clear();
endResetModel();
}
PackageInfo PackageModel::getPackage(int row) const {
if (row >= 0 && row < static_cast<int>(m_packages.size())) {
return m_packages[row];
}
return PackageInfo{};
}
-124
View File
@@ -1,124 +0,0 @@
#include "PluginManager.h"
#include <filesystem>
#include <iostream>
#include <cstdlib>
namespace fs = std::filesystem;
PluginManager::PluginManager() {
// Default search paths
char* home = getenv("HOME");
if (home) {
m_searchPaths.push_back(std::string(home) + "/.local/lib/PackageMapper/plugins");
}
m_searchPaths.push_back("/usr/lib/PackageMapper/plugins");
m_searchPaths.push_back("/usr/local/lib/PackageMapper/plugins");
// Also check relative to executable
m_searchPaths.push_back("./plugins");
// Load from all search paths
for (const auto& path : m_searchPaths) {
if (fs::exists(path) && fs::is_directory(path)) {
loadPluginsFromDirectory(path);
}
}
}
PluginManager::~PluginManager() {
unloadAll();
}
void PluginManager::loadPluginsFromDirectory(const std::string& directory) {
try {
for (const auto& entry : fs::directory_iterator(directory)) {
if (entry.is_regular_file()) {
auto ext = entry.path().extension().string();
if (ext == ".so" || ext == ".dylib") {
loadPlugin(entry.path().string());
}
}
}
} catch (const fs::filesystem_error& e) {
std::cerr << "Error scanning plugin directory: " << e.what() << std::endl;
}
}
bool PluginManager::loadPlugin(const std::string& path) {
void* handle = dlopen(path.c_str(), RTLD_NOW);
if (!handle) {
std::cerr << "Failed to load plugin: " << path << " - " << dlerror() << std::endl;
return false;
}
using CreateFunc = IPackageManager* (*)();
using DestroyFunc = void (*)(IPackageManager*);
auto createFunc = reinterpret_cast<CreateFunc>(dlsym(handle, "createPlugin"));
auto destroyFunc = reinterpret_cast<DestroyFunc>(dlsym(handle, "destroyPlugin"));
if (!createFunc || !destroyFunc) {
std::cerr << "Invalid plugin: " << path << " (missing entry points)" << std::endl;
dlclose(handle);
return false;
}
IPackageManager* instance = createFunc();
if (!instance) {
std::cerr << "Plugin returned null: " << path << std::endl;
dlclose(handle);
return false;
}
PluginInfo info;
info.path = path;
info.name = instance->getName();
info.instance = instance;
info.handle = handle;
info.loaded = true;
m_plugins.push_back(info);
std::cout << "Loaded plugin: " << info.name << " from " << path << std::endl;
return true;
}
void PluginManager::unloadAll() {
for (auto& plugin : m_plugins) {
if (plugin.instance && plugin.handle) {
using DestroyFunc = void (*)(IPackageManager*);
auto destroyFunc = reinterpret_cast<DestroyFunc>(dlsym(plugin.handle, "destroyPlugin"));
if (destroyFunc) {
destroyFunc(plugin.instance);
}
dlclose(plugin.handle);
plugin.instance = nullptr;
plugin.handle = nullptr;
plugin.loaded = false;
}
}
m_plugins.clear();
}
const std::vector<PluginInfo>& PluginManager::getPlugins() const {
return m_plugins;
}
IPackageManager* PluginManager::getPlugin(size_t index) const {
if (index < m_plugins.size() && m_plugins[index].loaded) {
return m_plugins[index].instance;
}
return nullptr;
}
size_t PluginManager::getPluginCount() const {
return m_plugins.size();
}
IPackageManager* PluginManager::findPlugin(const std::string& name) const {
for (const auto& plugin : m_plugins) {
if (plugin.name == name && plugin.loaded) {
return plugin.instance;
}
}
return nullptr;
}
-16
View File
@@ -1,16 +0,0 @@
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
app.setApplicationName("PackageMapper");
app.setApplicationVersion("1.0.0");
app.setOrganizationName("Freebuff");
MainWindow window;
window.setWindowTitle("PackageMapper - Gestionnaire de Paquets");
window.resize(1000, 700);
window.show();
return app.exec();
}