Compare commits
10 Commits
bde8026eca
...
9934610c68
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9934610c68 | ||
|
|
c1d47fb32b | ||
|
|
bbb08cbbf8 | ||
|
|
563de6fe5d | ||
|
|
582224244d | ||
|
|
97ed88bd3a | ||
|
|
dc11fd691f | ||
|
|
77ef0710c2 | ||
|
|
b4f8432c4c | ||
|
|
aee543a7b4 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
test
|
||||
build
|
||||
hardwareDB
|
||||
|
||||
@ -1,4 +1,13 @@
|
||||
# Hardware Database
|
||||
Learning C++ while building a universal hardware database that can be referenced for any machine that
|
||||
has already been added.
|
||||
|
||||
See your machine specs? If not - Add Them with a Pull Request!
|
||||
|
||||
Building from source:
|
||||
|
||||
Create a new build directory and enter it with `mkdir build && cd build`.
|
||||
Then run the commands `cmake .. && make`.
|
||||
The new binary is called hardwareDB.
|
||||
make sure to copy the hardware.db from the parent directory, or move the new binary into the parent directory.
|
||||
`mv ../hardware.db .` OR `mv hardwareDB ../` .
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
// void setCPU(){};
|
||||
|
||||
/* this function's Incoming arguments are a pointer to the CPU class
|
||||
"CPU *pCPU" and the new mainclock speed
|
||||
*/
|
||||
void setCPUmainclock(CPU *pCPU, std::string mkey, std::string mmainclock) {
|
||||
pCPU->HardwareSpecs[mkey] = mmainclock;
|
||||
}
|
||||
|
||||
void setCPUboostclock(CPU *pCPU, std::string mkey, std::string mboostclock) {
|
||||
pCPU->HardwareSpecs[mkey] = mboostclock;
|
||||
}
|
||||
|
||||
void setCPUarch(CPU *pCPU, std::string mkey, std::string march) {
|
||||
pCPU->HardwareSpecs[mkey] = march;
|
||||
}
|
||||
|
||||
void setCPUbits(CPU *pCPU, std::string mkey, int mbits) {
|
||||
pCPU->HardwareSpecs[mkey] = mbits;
|
||||
}
|
||||
|
||||
void setCPUcores(CPU *pCPU, std::string mkey, int mcores) {
|
||||
pCPU->HardwareSpecs[mkey] = mcores;
|
||||
}
|
||||
|
||||
void setCPUthreads(CPU *pCPU, std::string mkey, int mthreads) {
|
||||
pCPU->HardwareSpecs[mkey] = mthreads;
|
||||
// create an IF catch to set threads cores * 2 as a fall back
|
||||
}
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
// void setCPU(){};
|
||||
|
||||
/* this function's Incoming arguments are a pointer to the Hardware class
|
||||
"Hardware *pHardware" and the new mainclock speed
|
||||
*/
|
||||
void setHardwaremanufacturer(Hardware *pHardware, std::string mmanufacturer) {
|
||||
// cout << "Coming from the setHardwaremanufacturer function in setHardware" << endl;
|
||||
|
||||
pHardware->manufacturer = mmanufacturer;
|
||||
// cout << "Leaving setHardwaremanufacturer()\n\n";
|
||||
}
|
||||
|
||||
void setHardwarereleasedyear(Hardware *pHardware, int mreleasedyear) {
|
||||
pHardware->releasedyear = mreleasedyear;
|
||||
}
|
||||
|
||||
void setHardwaremodel(Hardware *pHardware, std::string mmodel) {
|
||||
pHardware->model = mmodel;
|
||||
}
|
||||
|
||||
void Hardwaredictadd(CPU *pHardware, std::string mkey, std::string mvalue) {
|
||||
|
||||
// cout << "The incoming key/value is: " << mkey << "/" << mvalue << endl;
|
||||
// cout << "\nThe current manufacturer is: " << pHardware->HardwareSpecs[mkey] << endl;
|
||||
pHardware->HardwareSpecs[mkey] = mvalue;
|
||||
// cout << "The new manufacturer is: " << pHardware->HardwareSpecs[mkey];
|
||||
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
/*
|
||||
* THIS PORTION OF CODE WAS DONATED BY szaszmango from brodie's server!
|
||||
*/
|
||||
|
||||
// This magic returns a vector which contain all the objects created using the CPU class
|
||||
std::vector<CPU> genCPUclasses() {
|
||||
std::vector<CPU> resultCpuList;
|
||||
std::ifstream cpuList{"lists/cpulist", std::ifstream::in};
|
||||
|
||||
if(cpuList.is_open()) {
|
||||
std::cout << "File opened\n";
|
||||
}
|
||||
else { std::cout << "Failed to open file!\n"; }
|
||||
|
||||
std::string line;
|
||||
while (std::getline(cpuList, line)) {
|
||||
CPU cpu;
|
||||
cpu.HardwareSpecs["model"] = line;
|
||||
resultCpuList.push_back(std::move(cpu));
|
||||
std::cout << "Loaded CPU: " << line << std::endl;
|
||||
}
|
||||
|
||||
return resultCpuList;
|
||||
}
|
||||
@ -1,74 +0,0 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
// #define class struct // Uncomment this line to switch all the classes to structs
|
||||
|
||||
// using namespace std;
|
||||
|
||||
class Hardware {
|
||||
|
||||
public:
|
||||
std::string manufacturer;
|
||||
std::string model;
|
||||
int releasedyear;
|
||||
|
||||
// example of how to set a dictionary item
|
||||
// std::string myval = HardwareSpecs.at("manufacturer");
|
||||
|
||||
};
|
||||
|
||||
class Mobo: public Hardware {
|
||||
public:
|
||||
int pciegen;
|
||||
int piceslots;
|
||||
int dimmslots;
|
||||
int dualchannel; // This is an int so 1 = dualchannel and 2 = quad channel
|
||||
int ramspeed;
|
||||
std::string comment;
|
||||
|
||||
std::map<std::string, std::string> HardwareSpecs = {
|
||||
{"manufacturer", "The Gnomes part 2"},
|
||||
{"model", "Honey Bomb"},
|
||||
{"ReleasedYear", "2025"},
|
||||
{"pciegen", "4"},
|
||||
{"pcieslots", "3"},
|
||||
{"dimmslots", "2"},
|
||||
{"ramchannels", "2"},
|
||||
{"ramspeed", "6000"},
|
||||
{"comment", "If on AM5 platform - update BIOS before booting!"},
|
||||
};
|
||||
};
|
||||
|
||||
class CPU: public Hardware {
|
||||
public:
|
||||
std::map<std::string, std::string> HardwareSpecs = {
|
||||
{"manufacturer", "The Gnomes part 2"},
|
||||
{"model", "Honey Bomb"},
|
||||
{"ReleasedYear", "2025"},
|
||||
{"bits", "64"},
|
||||
{"igpu", "false"},
|
||||
{"igpusize", "N/A"},
|
||||
{"cores", "4"},
|
||||
{"threads", "8"},
|
||||
{"l1cache", "32Mb"},
|
||||
{"l2cache", "32Mb"},
|
||||
{"l3cache", "32Mb"},
|
||||
{"pcielanes", "24"},
|
||||
{"maxram", "256Gb"},
|
||||
{"mainclock", "3Ghz"},
|
||||
{"boostclock", "3.2Ghz"},
|
||||
{"architecture", "x86_64"},
|
||||
{"memoryrange", "00:00 - set me!"},
|
||||
{"microcode", "unchanged"},
|
||||
{"kerneldriver", "intel"},
|
||||
{"comment", "If on AM5 platform - update BIOS before booting!"},
|
||||
};
|
||||
};
|
||||
|
||||
class GPU: public Hardware {
|
||||
public:
|
||||
std::map<std::string, GPU> GPUSpecs;
|
||||
// GPUSpecs["Ram"] = GPU { "Ram", "12Gb" };
|
||||
};
|
||||
137
src/main.cpp
137
src/main.cpp
@ -1,53 +1,98 @@
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
#include <sqlite/command.hpp>
|
||||
#include <sqlite/result.hpp>
|
||||
#include <string>
|
||||
#include "lists/hardware.h"
|
||||
#include "lists/cpu.h"
|
||||
#include "include/setcpu.h"
|
||||
#include "include/sethardware.h"
|
||||
#include <sqlite3.h>
|
||||
|
||||
// Begin testing of SQLite3
|
||||
#include <boost/algorithm/string.hpp>
|
||||
/*
|
||||
* Implementing SQLite3 on suggestion from MD.rpm - Thanks MD!
|
||||
*
|
||||
*/
|
||||
//Declare all the functions
|
||||
static int createDB(const char* s);
|
||||
static int createTable(const char* s);
|
||||
static int searchCPUTable(const char* s, std::string msearch, std::string searchtype);
|
||||
static int callback(void* NotUsed, int argc, char** argv, char** azColName);
|
||||
|
||||
// static int createTable(const char* s);
|
||||
|
||||
int main() {
|
||||
|
||||
const char* dir = "hardware.db";
|
||||
const char* dbFile = "hardware.db";
|
||||
sqlite3* hardwareDB;
|
||||
|
||||
createDB(dir);
|
||||
// createTable(dir);
|
||||
std::string msearch;
|
||||
std::string msearchlower;
|
||||
|
||||
createDB(dbFile);
|
||||
|
||||
char quit = '&';
|
||||
char searchby = '&';
|
||||
|
||||
|
||||
|
||||
/* //Create the CPU classes from the cpulist file
|
||||
int counter= 0;
|
||||
auto cpus = genCPUclasses();
|
||||
for (CPU& cpu: cpus) {
|
||||
// cpus[counter].HardwareSpecs["model"] = "value";
|
||||
std::cout << cpu.HardwareSpecs["model"] << " loaded at index: " << counter << std::endl;
|
||||
counter++;
|
||||
while(tolower(quit) != 'q') {
|
||||
std::cout << "\t\t----------=================================--------------\n";
|
||||
std::cout << "\t\t\tWelcome to the Universal Hardware database!\n";
|
||||
std::cout << "\t\t\t\t(S)earch for a part by model name\n";
|
||||
std::cout << "\t\t\t\t(Q)uit hardware database\n->";
|
||||
std::cin >> quit;
|
||||
switch(tolower(quit)) {
|
||||
case 's':
|
||||
std::cout << "-------------------------------\n";
|
||||
std::cout << "\t\t\tWhat would you like to search by?\n";
|
||||
std::cout << "\t\t\t\t(M)odel name\n";
|
||||
std::cout << "\t\t\t\tManufacture(R)\n";
|
||||
std::cout << "\t\t\t\t(Y)ear Released\n";
|
||||
std::cout << "\t\t\t\tMain (C)lock\n";
|
||||
std::cout << "\t\t\t\t(Q)uit\n->";
|
||||
std::cin >> searchby;
|
||||
switch(tolower(searchby)) {
|
||||
case 'm':
|
||||
std::cout << "-------------------------------\n";
|
||||
std::cout << "\t\tEnter part of the model string.\n";
|
||||
std::cout << "\t\tExample: for Intel i75820k you would enter 5820\n->";
|
||||
std::cin >> msearch;
|
||||
msearchlower = boost::algorithm::to_lower_copy(msearch);
|
||||
searchCPUTable(dbFile, msearchlower, "model"); // Replace this string with a variable that is the query grabbed from the user!
|
||||
break;
|
||||
case 'r':
|
||||
std::cout << "-------------------------------\n";
|
||||
std::cout << "\t\tEnter the manufacturer of the CPU.\n";
|
||||
std::cout << "\t\tExample: Intel\n->";
|
||||
std::cin >> msearch;
|
||||
msearchlower = boost::algorithm::to_lower_copy(msearch);
|
||||
searchCPUTable(dbFile, msearchlower, "manufacturer"); // Replace this string with a variable that is the query grabbed from the user!
|
||||
break;
|
||||
case 'y':
|
||||
std::cout << "-------------------------------\n";
|
||||
std::cout << "\t\tEnter the year this CPU was launched.\n";
|
||||
std::cout << "\t\tExample: 2004\n->";
|
||||
std::cin >> msearch;
|
||||
msearchlower = boost::algorithm::to_lower_copy(msearch);
|
||||
searchCPUTable(dbFile, msearchlower, "releasedyear"); // Replace this string with a variable that is the query grabbed from the user!
|
||||
break;
|
||||
case 'c':
|
||||
std::cout << "-------------------------------\n";
|
||||
std::cout << "\t\tEnter the Ghz portion of your main clock speed.\n";
|
||||
std::cout << "\t\tExample: 4\n->";
|
||||
std::cin >> msearch;
|
||||
msearchlower = boost::algorithm::to_lower_copy(msearch);
|
||||
searchCPUTable(dbFile, msearchlower, "mainclock"); // Replace this string with a variable that is the query grabbed from the user!
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'q':
|
||||
break;
|
||||
// default:
|
||||
// break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
//Testing the new dictionaries
|
||||
// cout << "Lets try the setCPU function!\n";
|
||||
// std::cout << "A7800x3d main clock speed is: " << A7800x3d->HardwareSpecs["mainclock"] << std::endl;
|
||||
// setHardwaremanufacturer(A7800x3d, "AMD");
|
||||
// setCPUcores(A7800x3d, "cores", 8);
|
||||
// setCPUthreads(A7800x3d, "threads", 16);
|
||||
// setCPUmainclock(A7800x3d, "mainclock", "4.8 Ghz");
|
||||
// setCPUboostclock(A7800x3d, "boostclock", "5.2 ghz");
|
||||
// cout << "\n\nA7800x3d new main/boost speed is: " << A7800x3d->HardwareSpecs["mainclock"] << "/" << A7800x3d->HardwareSpecs["boostclock"] << endl;
|
||||
// cout << "A7800x3d manufacturer is: " << A7800x3d->HardwareSpecs["manufacturer"] << "\n\n\n";
|
||||
|
||||
|
||||
system("sleep 1s");
|
||||
// system("sleep 1s");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -55,7 +100,6 @@ static int createDB(const char* s) {
|
||||
|
||||
sqlite3* hardwareDB;
|
||||
int exit = 0;
|
||||
|
||||
exit = sqlite3_open(s, &hardwareDB);
|
||||
|
||||
sqlite3_close(hardwareDB);
|
||||
@ -63,3 +107,28 @@ static int createDB(const char* s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int searchCPUTable(const char* s, std::string msearchlower, std::string searchtype) {
|
||||
|
||||
sqlite3* hardwareDB;
|
||||
|
||||
int exit = sqlite3_open(s, &hardwareDB);
|
||||
|
||||
std::string sql = "SELECT * FROM cpu WHERE " + searchtype + " LIKE '%" + msearchlower + "%';";
|
||||
|
||||
sqlite3_exec(hardwareDB, sql.c_str(), callback, NULL, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int callback(void* NotUsed, int argc, char** argv, char** azColName) {
|
||||
// Wrap out ouput so it's easier to read for multiple results
|
||||
std::cout << "=====================" << std::endl;
|
||||
|
||||
for (int i=0; i < argc; i++) {
|
||||
//column name and value
|
||||
std::cout << azColName[i] << ": " << argv[i] << std::endl;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user