2022-04-24 08:55:55 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "id_config.h"
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <corecrt_io.h>
|
|
|
|
id_config::id_config()
|
|
|
|
{
|
|
|
|
jsoninit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ID_Config> id_config::GetConfig()
|
|
|
|
{
|
|
|
|
std::vector<ID_Config> configs;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (access(ID_JSON_PATH.c_str(), 0) == 0) {
|
|
|
|
std::ifstream i(ID_JSON_PATH);
|
|
|
|
json j;
|
|
|
|
i >> j;
|
|
|
|
for (json::iterator it = j.begin(); it != j.end(); ++it)
|
|
|
|
{
|
|
|
|
auto tmv = it.value();
|
|
|
|
configs.push_back(to_param(tmv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw "file error";
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
configs.clear();
|
|
|
|
json j = GetDefaultJson();
|
|
|
|
for (json::iterator it = j.begin(); it != j.end(); ++it)
|
|
|
|
{
|
|
|
|
auto tmv = it.value();
|
|
|
|
configs.push_back(to_param(tmv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return configs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void id_config::SaveConfig(std::vector<ID_Config> configs)
|
|
|
|
{
|
|
|
|
json j = json::array();
|
|
|
|
for (int i = 0; i < configs.size(); i++)
|
|
|
|
{
|
2022-05-09 07:47:56 +00:00
|
|
|
j.push_back(to_json({configs[i].vid,configs[i].pid,configs[i].cpu_type,configs[i].driver_type}));
|
2022-04-24 08:55:55 +00:00
|
|
|
}
|
|
|
|
std::ofstream ofs(ID_JSON_PATH);
|
|
|
|
ofs << std::setw(4) << j << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void id_config::SaveConfig(json j)
|
|
|
|
{
|
|
|
|
std::ofstream ofs(ID_JSON_PATH);
|
|
|
|
ofs << std::setw(4) << j << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
json id_config::GetDefaultJson()
|
|
|
|
{
|
|
|
|
json j = json::array();
|
2022-05-09 07:47:56 +00:00
|
|
|
j.push_back(to_json({ 0x3072, 0x239, 3399, 200 }));
|
|
|
|
j.push_back(to_json({ 0x3072, 0x139, 3399, 100 }));
|
|
|
|
j.push_back(to_json({ 0x3072, 0x300, 3288, 300 }));
|
|
|
|
j.push_back(to_json({ 0x3072, 0x400, 3288, 400 }));
|
|
|
|
j.push_back(to_json({ 0x3072, 0x339, 3399, 300 }));
|
|
|
|
j.push_back(to_json({ 0x3072, 0x439, 3399, 400 }));
|
|
|
|
j.push_back(to_json({ 0x31c9, 0x8629,3399, 100 }));
|
|
|
|
j.push_back(to_json({ 0x31c9, 0x8739,3399, 200 }));
|
2022-04-24 08:55:55 +00:00
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
void id_config::jsoninit()
|
|
|
|
{
|
|
|
|
if (access(ID_JSON_PATH.c_str(),0) != 0)
|
|
|
|
{
|
|
|
|
std::ofstream ofs(ID_JSON_PATH);
|
|
|
|
ofs << std::setw(4) << GetDefaultJson() << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
json id_config::to_json(ID_Config param)
|
|
|
|
{
|
|
|
|
return json{
|
|
|
|
{"vid",param.vid},
|
|
|
|
{"pid",param.pid},
|
2022-05-09 07:47:56 +00:00
|
|
|
{"cpu",param.cpu_type},
|
|
|
|
{"type",param.driver_type} };
|
2022-04-24 08:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ID_Config id_config::to_param(json j)
|
|
|
|
{
|
|
|
|
ID_Config tmp;
|
|
|
|
j.at("vid").get_to(tmp.vid);
|
|
|
|
j.at("pid").get_to(tmp.pid);
|
|
|
|
j.at("cpu").get_to(tmp.cpu_type);
|
2022-05-09 07:47:56 +00:00
|
|
|
j.at("type").get_to(tmp.driver_type);
|
2022-04-24 08:55:55 +00:00
|
|
|
return tmp;
|
|
|
|
}
|