git-svn-id: svn://db.shs.com.ru/pip@778 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -18,12 +18,16 @@
|
||||
*/
|
||||
#include "pisysteminfo.h"
|
||||
#include "piincludes_p.h"
|
||||
#include "pidir.h"
|
||||
#include "picrc.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
# include "esp_system.h"
|
||||
# include "esp_spi_flash.h"
|
||||
#endif
|
||||
|
||||
#define SALT_SIZE 8
|
||||
|
||||
|
||||
PISystemInfo::PISystemInfo() {
|
||||
processorsCount = 1;
|
||||
@@ -196,3 +200,66 @@ PIVector<PISystemInfo::MountInfo> PISystemInfo::mountInfo() {
|
||||
cache = ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
PIString confDir() {
|
||||
return
|
||||
#ifdef WINDOWS
|
||||
PIDir::home().path() + "/AppData/Local"
|
||||
#elif ANDROID
|
||||
"/mnt/sdcard"
|
||||
#else
|
||||
PIDir::home().path() + "/.config"
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray generateSalt() {
|
||||
PIByteArray ret;
|
||||
piForTimes (SALT_SIZE) {
|
||||
piMSleep(randomi() % 10);
|
||||
randomize();
|
||||
ret << uchar(randomi() % 0x100);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString PISystemInfo::machineKey() {
|
||||
static PIString ret;
|
||||
if (ret.isEmpty()) {
|
||||
PISystemInfo * si = instance();
|
||||
PIByteArray salt;
|
||||
PIString conf = confDir() + "/.pip_machine_salt";
|
||||
if (PIFile::isExists(conf)) {
|
||||
PIFile f(conf, PIIODevice::ReadOnly);
|
||||
f.open();
|
||||
salt = f.readAll();
|
||||
}
|
||||
if (salt.size_s() != SALT_SIZE){
|
||||
salt = generateSalt();
|
||||
PIFile f(conf, PIIODevice::ReadWrite);
|
||||
f.open();
|
||||
f.clear();
|
||||
f.write(salt);
|
||||
}
|
||||
ret = si->OS_name + "_" + si->architecture + "_" + si->hostname + "_" + salt.toHex();
|
||||
/*PIEthernet::InterfaceList il = PIEthernet::interfaces();
|
||||
const PIEthernet::Interface * lo = il.getByAddress("127.0.0.1");
|
||||
if (lo)
|
||||
ret += lo->mac;*/
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint PISystemInfo::machineID() {
|
||||
piCout << confDir();
|
||||
static uint ret = 0;
|
||||
if (ret == 0) {
|
||||
CRC_32 crc = standardCRC_32();
|
||||
ret = crc.calculate(machineKey().toByteArray());
|
||||
piCout << "machineID \"" << machineKey() << "\" =" << PICoutManipulators::Hex << ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user