Skip to content

Commit

Permalink
Ajout d'un support des package managers de linux
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperAtraction committed Nov 25, 2023
1 parent 16aa2b1 commit d6283be
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 1 deletion.
19 changes: 19 additions & 0 deletions OSSpecialClasses/SpecialActions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "SpecialActions.hpp"

SpecialActions::SpecialActions()
{

}

QString SpecialActions::obtenirMotDePasse(QString &motDePasse) {
// Créer un dialogue d'entrée de texte pour obtenir le mot de passe
qDebug() << MAIN::mode;
bool ok;
QString texte = QInputDialog::getText(nullptr, "Authentification", "Mot de passe :", QLineEdit::Password, QString(), &ok);

if (ok && !texte.isEmpty()) {
return texte;
} else {
return "---OLOP---ERROR---OLOP---"; // L'utilisateur a annulé ou n'a pas entré de mot de passe
}
}
14 changes: 14 additions & 0 deletions OSSpecialClasses/SpecialActions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef SPECIALACTIONS_HPP
#define SPECIALACTIONS_HPP

#include "../olop.hpp"
#include <QInputDialog>

class SpecialActions
{
public:
SpecialActions();
static QString obtenirMotDePasse(QString &motDePasse);
};

#endif // SPECIALACTIONS_HPP
66 changes: 66 additions & 0 deletions OSSpecialClasses/SystemAppInstaller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "SpecialActions.hpp"
#include "SystemAppInstaller.hpp"
#include "../olop.hpp"

SystemAppInstaller::SystemAppInstaller()
{

}

int SystemAppInstaller::installsystemapp(int type, QString packagename, QString Dest) {
#ifdef Q_OS_LINUX
// Détecter le gestionnaire de paquets en vérifiant la présence de certains gestionnaires courants
QStringList gestionnaires = {"apt", "dnf", "zypper", "pacman"}; // Ajouté pour alpine apk

QString gestionnaireDetecte;
for (const QString &gestionnaire : gestionnaires) {
QProcess process;
process.start("which", QStringList() << gestionnaire);
process.waitForFinished();

if (process.exitCode() == 0) {
gestionnaireDetecte = gestionnaire;
break;
}
}

if (gestionnaireDetecte.isEmpty()) {
qDebug() << "Aucun gestionnaire de paquets détecté.";
return -1;
}

// Obtenir le mot de passe de l'utilisateur
QString motDePasse=SpecialActions::obtenirMotDePasse(motDePasse);
if (!motDePasse.indexOf("---OLOP---ERROR---OLOP---")) {
qDebug() << "Annulation par l'utilisateur.";
return -1;
}

// Installer le paquet avec le gestionnaire de paquets détecté et le mot de passe de l'utilisateur
// Construire la liste des arguments de la commande sudo
QStringList args;
args << "-S" << gestionnaireDetecte << "install" << "-y" << packagename;

// Installer le paquet avec le gestionnaire de paquets détecté et le mot de passe de l'utilisateur
QProcess process;
process.start("sh", QStringList() << "-c" << "echo '" + motDePasse + "' | sudo -S " + args.join(" "));
process.waitForFinished(-1);

int codeSortie = process.exitCode();
QByteArray sortieStandard = process.readAllStandardOutput();
QByteArray sortieErreur = process.readAllStandardError();

if (codeSortie == 0) {
qDebug() << "Installation de "+packagename+" réussie";
return 0;
} else {
qDebug() << "Erreur lors de l'installation. Code de sortie :" << codeSortie;
qDebug() << "Sortie standard du processus :" << sortieStandard;
qDebug() << "Sortie d'erreur du processus :" << sortieErreur;
return -1;
}
#else
qDebug() << "ERREUR : Impossible d'installer des packages sur un OS inconnu.";
return -1;
#endif
}
14 changes: 14 additions & 0 deletions OSSpecialClasses/SystemAppInstaller.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef SYSTEMAPPINSTALLER_HPP
#define SYSTEMAPPINSTALLER_HPP

#include <QProcess>
#include "olop.hpp"

class SystemAppInstaller
{
public:
SystemAppInstaller();
static int installsystemapp(int type, QString packagename, QString Dest);
};

#endif // SYSTEMAPPINSTALLER_HPP
Binary file modified Olop
Binary file not shown.
6 changes: 6 additions & 0 deletions Olop.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ CONFIG += c++17
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
OSSpecialClasses/SpecialActions.cpp \
OSSpecialClasses/SystemAppInstaller.cpp \
Tabs/home.cpp \
Tabs/newtab.cpp \
Tabs/settings.cpp \
logger.cpp \
main.cpp \
mainwindow.cpp \
olop.cpp

HEADERS += \
OSSpecialClasses/SpecialActions.hpp \
OSSpecialClasses/SystemAppInstaller.hpp \
Tabs/home.h \
Tabs/newtab.h \
Tabs/settings.h \
logger.hpp \
mainwindow.h \
olop.hpp

Expand Down
3 changes: 2 additions & 1 deletion Olop.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 11.0.2, 2023-11-22T18:07:14. -->
<!-- Written by QtCreator 11.0.2, 2023-11-25T16:31:25. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -254,6 +254,7 @@
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/home/superatraction/Documents/Qt C++/build-Olop-Desktop_Qt_6_5_1_GCC_64bit-Debug</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
Expand Down
10 changes: 10 additions & 0 deletions logger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "logger.hpp"
#include <olop.hpp>

extern MAIN OLOP;

Logger::Logger(MAIN nmain)
{
OLOP=nmain;
qDebug() << "Logger initialisé";
}
12 changes: 12 additions & 0 deletions logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef LOGGER_HPP
#define LOGGER_HPP

#include "olop.hpp"

class Logger
{
public:
Logger(MAIN nmain);
};

#endif // LOGGER_HPP
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "mainwindow.h"
#include "olop.hpp"
#include "qapplication.h"
#include "OSSpecialClasses/SystemAppInstaller.hpp"

#define Version "alpha-1.2"
int mode = 1;
Expand Down Expand Up @@ -66,6 +67,7 @@ int main(int argc, char *argv[])
qDebug() << "Démarrage d'Olop...";
MAIN::INIT(1);
mode=1;
SystemAppInstaller::installsystemapp(0, "filetea", "");

// Déclaration des variables
bool* IntentionnallyStop = new bool(false);
Expand Down

0 comments on commit d6283be

Please sign in to comment.