-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout d'un support des package managers de linux
- Loading branch information
1 parent
16aa2b1
commit d6283be
Showing
10 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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é"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters