mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-03-07 20:09:55 +03:00
Add ASCII View
Closes #27 but only for SCSI and SATA, NVMe ASCII View is not yet implemented
This commit is contained in:
33
src/main.cpp
33
src/main.cpp
@@ -1,11 +1,44 @@
|
||||
#include "mainwindow.h"
|
||||
#include "asciiview.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTranslator>
|
||||
#include <QLocale>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool isHeadless = false;
|
||||
QString devicePath;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (QString(argv[i]) == "--ascii-view") {
|
||||
isHeadless = true;
|
||||
if (i + 1 < argc) {
|
||||
devicePath = argv[i + 1];
|
||||
} else {
|
||||
std::cerr << "Error: Missing device path after --ascii-view" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isHeadless) {
|
||||
if (geteuid() == 0) {
|
||||
AsciiView asciiview;
|
||||
QVector<unsigned char> driveData = asciiview.readSMARTData(devicePath);
|
||||
std::cout.write(reinterpret_cast<const char*>(driveData.data()), driveData.size());
|
||||
std::cout.flush();
|
||||
} else {
|
||||
std::cerr << "Error: This action requires root privileges!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QApplication a(argc, argv);
|
||||
|
||||
QTranslator translator;
|
||||
|
||||
Reference in New Issue
Block a user