Update to spice2x-25-04-25 (pre-apply)
> broken commit
This commit is contained in:
+106
-13
@@ -19,10 +19,16 @@ Config::Config() {
|
||||
this->status = false;
|
||||
if (CONFIG_PATH_OVERRIDE.length() > 0) {
|
||||
this->configLocation = CONFIG_PATH_OVERRIDE;
|
||||
log_info("cfg", "using custom config file: {}", this->configLocation.string());
|
||||
} else {
|
||||
this->configLocation = std::string(getenv("APPDATA")) + "\\spicetools.xml";
|
||||
this->configLocation = std::filesystem::path(_wgetenv(L"APPDATA")) / L"spicetools.xml";
|
||||
// avoids logging the expanded appdata path as it contains user name
|
||||
log_info("cfg", "using global config file: %appdata%\\spicetools.xml");
|
||||
}
|
||||
|
||||
this->configLocationTemp = this->configLocation;
|
||||
this->configLocationTemp.replace_extension(L"tmp");
|
||||
|
||||
tinyxml2::XMLError configLoadError, *previousConfigLoadError = nullptr;
|
||||
|
||||
do {
|
||||
@@ -42,7 +48,7 @@ Config::Config() {
|
||||
this->firstFillConfigFile();
|
||||
break;
|
||||
case tinyxml2::XMLError::XML_ERROR_FILE_COULD_NOT_BE_OPENED:
|
||||
log_fatal("cfg", "could not open config file: {}", this->configLocation);
|
||||
log_fatal("cfg", "could not open config file: {}", this->configLocation.string());
|
||||
break;
|
||||
case tinyxml2::XMLError::XML_ERROR_FILE_NOT_FOUND:
|
||||
this->createConfigFile();
|
||||
@@ -57,7 +63,7 @@ Config::Config() {
|
||||
case tinyxml2::XMLError::XML_ERROR_PARSING_UNKNOWN:
|
||||
case tinyxml2::XMLError::XML_ERROR_MISMATCHED_ELEMENT:
|
||||
case tinyxml2::XMLError::XML_ERROR_PARSING:
|
||||
log_warning("cfg", "Couldn't read config file: {}", this->configLocation);
|
||||
log_warning("cfg", "Couldn't read config file: {}", this->configLocation.string());
|
||||
this->createConfigFile();
|
||||
this->firstFillConfigFile();
|
||||
break;
|
||||
@@ -147,12 +153,14 @@ bool Config::addGame(Game &game) {
|
||||
auto analogType = (int) BAT_NONE;
|
||||
double debounce_up = 0.0;
|
||||
double debounce_down = 0.0;
|
||||
int velocity_threshold = 0;
|
||||
bool invert = false;
|
||||
tinyxml2::XMLError attrError = gameButtonNode->QueryIntAttribute("vkey", &vKey);
|
||||
const char *devid = gameButtonNode->Attribute("devid");
|
||||
gameButtonNode->QueryIntAttribute("analogtype", &analogType);
|
||||
gameButtonNode->QueryDoubleAttribute("debounce_up", &debounce_up);
|
||||
gameButtonNode->QueryDoubleAttribute("debounce_down", &debounce_down);
|
||||
gameButtonNode->QueryIntAttribute("velocity_threshold", &velocity_threshold);
|
||||
gameButtonNode->QueryBoolAttribute("invert", &invert);
|
||||
if (attrError != tinyxml2::XMLError::XML_SUCCESS) {
|
||||
gameButtonsNode->DeleteChild(gameButtonNode);
|
||||
@@ -163,6 +171,7 @@ bool Config::addGame(Game &game) {
|
||||
gameButtonNode->SetAttribute("devid", button->getDeviceIdentifier().c_str());
|
||||
gameButtonNode->SetAttribute("debounce_up", debounce_up);
|
||||
gameButtonNode->SetAttribute("debounce_down", debounce_down);
|
||||
gameButtonNode->SetAttribute("velocity_threshold", velocity_threshold);
|
||||
gameButtonNode->SetAttribute("invert", invert);
|
||||
gameButtonsNode->InsertEndChild(gameButtonNode);
|
||||
} else {
|
||||
@@ -170,6 +179,7 @@ bool Config::addGame(Game &game) {
|
||||
button->setAnalogType((ButtonAnalogType) analogType);
|
||||
button->setDebounceUp(debounce_up);
|
||||
button->setDebounceDown(debounce_down);
|
||||
button->setVelocityThreshold(velocity_threshold);
|
||||
button->setInvert(invert);
|
||||
if (devid) {
|
||||
button->setDeviceIdentifier(devid);
|
||||
@@ -188,6 +198,7 @@ bool Config::addGame(Game &game) {
|
||||
gameButtonNode->SetAttribute("analogtype", (int) it.getAnalogType());
|
||||
gameButtonNode->SetAttribute("debounce_up", it.getDebounceUp());
|
||||
gameButtonNode->SetAttribute("debounce_down", it.getDebounceDown());
|
||||
gameButtonNode->SetAttribute("velocity_threshold", it.getVelocityThreshold());
|
||||
gameButtonNode->SetAttribute("invert", it.getInvert());
|
||||
gameButtonNode->SetAttribute("devid", it.getDeviceIdentifier().c_str());
|
||||
gameButtonsNode->InsertEndChild(gameButtonNode);
|
||||
@@ -226,12 +237,18 @@ bool Config::addGame(Game &game) {
|
||||
bool deadzone_mirror = false;
|
||||
bool invert = false;
|
||||
bool smoothing = false;
|
||||
int multiplier = 1;
|
||||
bool relative_mode = false;
|
||||
int delay_buffer_depth = 0;
|
||||
tinyxml2::XMLError err1 = gameAnalogNode->QueryIntAttribute("index", &index);
|
||||
gameAnalogNode->QueryFloatAttribute("sensivity", &sensitivity);
|
||||
gameAnalogNode->QueryFloatAttribute("deadzone", &deadzone);
|
||||
gameAnalogNode->QueryBoolAttribute("deadzone_mirror", &deadzone_mirror);
|
||||
gameAnalogNode->QueryBoolAttribute("invert", &invert);
|
||||
gameAnalogNode->QueryBoolAttribute("smoothing", &smoothing);
|
||||
gameAnalogNode->QueryIntAttribute("multiplier", &multiplier);
|
||||
gameAnalogNode->QueryBoolAttribute("relative", &relative_mode);
|
||||
gameAnalogNode->QueryIntAttribute("delay", &delay_buffer_depth);
|
||||
const char *devid = gameAnalogNode->Attribute("devid");
|
||||
|
||||
if (err1 != tinyxml2::XMLError::XML_SUCCESS || !devid) {
|
||||
@@ -245,6 +262,9 @@ bool Config::addGame(Game &game) {
|
||||
gameAnalogNode->SetAttribute("deadzone_mirror", it.getDeadzoneMirror());
|
||||
gameAnalogNode->SetAttribute("invert", it.getInvert());
|
||||
gameAnalogNode->SetAttribute("smoothing", it.getSmoothing());
|
||||
gameAnalogNode->SetAttribute("multiplier", it.getMultiplier());
|
||||
gameAnalogNode->SetAttribute("relative", it.isRelativeMode());
|
||||
gameAnalogNode->SetAttribute("delay", it.getDelayBufferDepth());
|
||||
gameAnalogsNode->InsertEndChild(gameAnalogNode);
|
||||
} else {
|
||||
it.setIndex(static_cast<unsigned short int>(index));
|
||||
@@ -254,6 +274,9 @@ bool Config::addGame(Game &game) {
|
||||
it.setDeadzoneMirror(deadzone_mirror);
|
||||
it.setInvert(invert);
|
||||
it.setSmoothing(smoothing);
|
||||
it.setMultiplier(multiplier);
|
||||
it.setRelativeMode(relative_mode);
|
||||
it.setDelayBufferDepth(delay_buffer_depth);
|
||||
}
|
||||
} else {
|
||||
gameAnalogNode = this->configFile.NewElement("analog");
|
||||
@@ -264,6 +287,9 @@ bool Config::addGame(Game &game) {
|
||||
gameAnalogNode->SetAttribute("deadzone_mirror", it.getDeadzoneMirror());
|
||||
gameAnalogNode->SetAttribute("invert", it.getInvert());
|
||||
gameAnalogNode->SetAttribute("smoothing", it.getSmoothing());
|
||||
gameAnalogNode->SetAttribute("multiplier", it.getMultiplier());
|
||||
gameAnalogNode->SetAttribute("relative", it.isRelativeMode());
|
||||
gameAnalogNode->SetAttribute("delay", it.getDelayBufferDepth());
|
||||
gameAnalogNode->SetAttribute("devid", it.getDeviceIdentifier().c_str());
|
||||
gameAnalogsNode->InsertEndChild(gameAnalogNode);
|
||||
}
|
||||
@@ -397,6 +423,7 @@ bool Config::addGame(Game &game) {
|
||||
gameButtonNode->SetAttribute("analogtype", it.getAnalogType());
|
||||
gameButtonNode->SetAttribute("debounce_up", it.getDebounceUp());
|
||||
gameButtonNode->SetAttribute("debounce_down", it.getDebounceDown());
|
||||
gameButtonNode->SetAttribute("velocity_threshold", it.getVelocityThreshold());
|
||||
gameButtonNode->SetAttribute("invert", it.getInvert());
|
||||
gameButtonNode->SetAttribute("devid", it.getDeviceIdentifier().c_str());
|
||||
gameButtonsNode->InsertEndChild(gameButtonNode);
|
||||
@@ -414,6 +441,9 @@ bool Config::addGame(Game &game) {
|
||||
gameAnalogNode->SetAttribute("deadzone_mirror", it.getDeadzoneMirror());
|
||||
gameAnalogNode->SetAttribute("invert", it.getInvert());
|
||||
gameAnalogNode->SetAttribute("smoothing", it.getSmoothing());
|
||||
gameAnalogNode->SetAttribute("multiplier", it.getMultiplier());
|
||||
gameAnalogNode->SetAttribute("relative", it.isRelativeMode());
|
||||
gameAnalogNode->SetAttribute("delay", it.getDelayBufferDepth());
|
||||
gameAnalogsNode->InsertEndChild(gameAnalogNode);
|
||||
}
|
||||
|
||||
@@ -442,7 +472,7 @@ bool Config::addGame(Game &game) {
|
||||
}
|
||||
|
||||
// save config
|
||||
this->configFile.SaveFile(this->configLocation.c_str(), false);
|
||||
this->saveConfigFile();
|
||||
|
||||
// return success
|
||||
return true;
|
||||
@@ -494,6 +524,7 @@ bool Config::updateBinding(const Game &game, const Button &button, int alternati
|
||||
gameButtonNode->SetAttribute("analogtype", (int) button.getAnalogType());
|
||||
gameButtonNode->SetAttribute("debounce_up", button.getDebounceUp());
|
||||
gameButtonNode->SetAttribute("debounce_down", button.getDebounceDown());
|
||||
gameButtonNode->SetAttribute("velocity_threshold", button.getVelocityThreshold());
|
||||
gameButtonNode->SetAttribute("invert", button.getInvert());
|
||||
gameButtonNode->SetAttribute("devid", button.getDeviceIdentifier().c_str());
|
||||
break;
|
||||
@@ -509,19 +540,47 @@ bool Config::updateBinding(const Game &game, const Button &button, int alternati
|
||||
gameButtonNode->SetAttribute("analogtype", 0);
|
||||
gameButtonNode->SetAttribute("debounce_up", 0.0);
|
||||
gameButtonNode->SetAttribute("debounce_down", 0.0);
|
||||
gameButtonNode->SetAttribute("velocity_threshold", 0);
|
||||
gameButtonNode->SetAttribute("invert", false);
|
||||
gameButtonNode->SetAttribute("devid", "");
|
||||
gameButtonsNode->InsertEndChild(gameButtonNode);
|
||||
}
|
||||
}
|
||||
|
||||
// for MIDI notes, need to keep velocity threshold consistent for all bindings
|
||||
// ;MIDI; is a unique prefix that we use at rawinput layer to identify MIDI devices
|
||||
const bool fixup_other_buttons =
|
||||
(button.getAnalogType() == (int)BAT_NONE &&
|
||||
!button.getDeviceIdentifier().empty() &&
|
||||
button.getDeviceIdentifier().find(";MIDI;", 0) == 0);
|
||||
if (fixup_other_buttons) {
|
||||
gameButtonNode = gameButtonsNode->FirstChildElement("button");
|
||||
while (gameButtonNode != nullptr) {
|
||||
const char *devid = gameButtonNode->Attribute("devid");
|
||||
if (button.getDeviceIdentifier() == devid) {
|
||||
int other_vKey = 0;
|
||||
int other_vel = 0;
|
||||
int other_type = 0;
|
||||
gameButtonNode->QueryIntAttribute("velocity_threshold", &other_vel);
|
||||
gameButtonNode->QueryIntAttribute("vkey", &other_vKey);
|
||||
gameButtonNode->QueryIntAttribute("analogtype", &other_type);
|
||||
if (other_vKey == button.getVKey() &&
|
||||
other_type == button.getAnalogType() &&
|
||||
other_vel != button.getVelocityThreshold()) {
|
||||
gameButtonNode->SetAttribute("velocity_threshold", button.getVelocityThreshold());
|
||||
}
|
||||
}
|
||||
gameButtonNode = gameButtonNode->NextSiblingElement("button");
|
||||
}
|
||||
}
|
||||
|
||||
// check if button was not found
|
||||
if (button_count == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// save config
|
||||
this->configFile.SaveFile(this->configLocation.c_str(), false);
|
||||
this->saveConfigFile();
|
||||
|
||||
// return success
|
||||
return true;
|
||||
@@ -579,6 +638,9 @@ bool Config::updateBinding(const Game &game, const Analog &analog) {
|
||||
gameAnalogNode->SetAttribute("deadzone_mirror", analog.getDeadzoneMirror());
|
||||
gameAnalogNode->SetAttribute("invert", analog.getInvert());
|
||||
gameAnalogNode->SetAttribute("smoothing", analog.getSmoothing());
|
||||
gameAnalogNode->SetAttribute("multiplier", analog.getMultiplier());
|
||||
gameAnalogNode->SetAttribute("relative", analog.isRelativeMode());
|
||||
gameAnalogNode->SetAttribute("delay", analog.getDelayBufferDepth());
|
||||
gameAnalogNode->SetAttribute("devid", analog.getDeviceIdentifier().c_str());
|
||||
} else {
|
||||
gameAnalogNode = this->configFile.NewElement("analog");
|
||||
@@ -588,11 +650,14 @@ bool Config::updateBinding(const Game &game, const Analog &analog) {
|
||||
gameAnalogNode->SetAttribute("deadzone_mirror", analog.getDeadzoneMirror());
|
||||
gameAnalogNode->SetAttribute("invert", analog.getInvert());
|
||||
gameAnalogNode->SetAttribute("smoothing", analog.getSmoothing());
|
||||
gameAnalogNode->SetAttribute("multiplier", analog.getMultiplier());
|
||||
gameAnalogNode->SetAttribute("relative", analog.isRelativeMode());
|
||||
gameAnalogNode->SetAttribute("delay", analog.getDelayBufferDepth());
|
||||
gameAnalogNode->SetAttribute("devid", analog.getDeviceIdentifier().c_str());
|
||||
gameAnalogsNode->InsertEndChild(gameAnalogNode);
|
||||
}
|
||||
|
||||
this->configFile.SaveFile(this->configLocation.c_str(), false);
|
||||
this->saveConfigFile();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -633,7 +698,7 @@ bool Config::updateBinding(const Game &game, ConfigKeypadBindings &keypads) {
|
||||
gameKeypadNode->SetAttribute("cardpath1", reinterpret_cast<const char *>(keypads.card_paths[0].u8string().c_str()));
|
||||
gameKeypadNode->SetAttribute("cardpath2", reinterpret_cast<const char *>(keypads.card_paths[1].u8string().c_str()));
|
||||
|
||||
this->configFile.SaveFile(this->configLocation.c_str(), false);
|
||||
this->saveConfigFile();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -701,7 +766,7 @@ bool Config::updateBinding(const Game &game, const Light &light, int alternative
|
||||
}
|
||||
|
||||
// save config
|
||||
this->configFile.SaveFile(this->configLocation.c_str(), false);
|
||||
this->saveConfigFile();
|
||||
|
||||
// return success
|
||||
return true;
|
||||
@@ -760,7 +825,7 @@ bool Config::updateBinding(const Game &game, const Option &option) {
|
||||
gameOptionsNode->InsertEndChild(gameOptionNode);
|
||||
}
|
||||
|
||||
this->configFile.SaveFile(this->configLocation.c_str(), false);
|
||||
this->saveConfigFile();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -806,11 +871,13 @@ std::vector<Button> Config::getButtons(const std::string &gameName) {
|
||||
auto analogType = (int) BAT_NONE;
|
||||
double debounce_up = 0.0;
|
||||
double debounce_down = 0.0;
|
||||
int velocity_threshold = 0;
|
||||
bool invert = false;
|
||||
gameButtonNode->QueryIntAttribute("vkey", &vKey);
|
||||
gameButtonNode->QueryIntAttribute("analogtype", &analogType);
|
||||
gameButtonNode->QueryDoubleAttribute("debounce_up", &debounce_up);
|
||||
gameButtonNode->QueryDoubleAttribute("debounce_down", &debounce_down);
|
||||
gameButtonNode->QueryIntAttribute("velocity_threshold", &velocity_threshold);
|
||||
gameButtonNode->QueryBoolAttribute("invert", &invert);
|
||||
const char *devid = gameButtonNode->Attribute("devid");
|
||||
|
||||
@@ -824,6 +891,7 @@ std::vector<Button> Config::getButtons(const std::string &gameName) {
|
||||
alt.setAnalogType((ButtonAnalogType) analogType);
|
||||
alt.setDebounceUp(debounce_up);
|
||||
alt.setDebounceDown(debounce_down);
|
||||
alt.setVelocityThreshold(velocity_threshold);
|
||||
alt.setInvert(invert);
|
||||
if (devid) {
|
||||
alt.setDeviceIdentifier(std::string(devid));
|
||||
@@ -835,13 +903,13 @@ std::vector<Button> Config::getButtons(const std::string &gameName) {
|
||||
|
||||
// if no alternative was found
|
||||
if (!alternative_found) {
|
||||
|
||||
// create button and add to list
|
||||
auto &button = buttons.emplace_back(buttonNodeName);
|
||||
button.setVKey((unsigned short) vKey);
|
||||
button.setAnalogType((ButtonAnalogType) analogType);
|
||||
button.setDebounceUp(debounce_up);
|
||||
button.setDebounceDown(debounce_down);
|
||||
button.setVelocityThreshold(velocity_threshold);
|
||||
button.setInvert(invert);
|
||||
if (devid) {
|
||||
button.setDeviceIdentifier(devid);
|
||||
@@ -985,12 +1053,18 @@ std::vector<Analog> Config::getAnalogs(const std::string &gameName) {
|
||||
bool deadzone_mirror = false;
|
||||
bool invert = false;
|
||||
bool smoothing = false;
|
||||
int multiplier = 1;
|
||||
bool relative_mode = false;
|
||||
int delay_buffer_depth = 0;
|
||||
gameAnalogNode->QueryIntAttribute("index", &index);
|
||||
gameAnalogNode->QueryFloatAttribute("sensivity", &sensitivity);
|
||||
gameAnalogNode->QueryFloatAttribute("deadzone", &deadzone);
|
||||
gameAnalogNode->QueryBoolAttribute("deadzone_mirror", &deadzone_mirror);
|
||||
gameAnalogNode->QueryBoolAttribute("invert", &invert);
|
||||
gameAnalogNode->QueryBoolAttribute("smoothing", &smoothing);
|
||||
gameAnalogNode->QueryIntAttribute("multiplier", &multiplier);
|
||||
gameAnalogNode->QueryBoolAttribute("relative", &relative_mode);
|
||||
gameAnalogNode->QueryIntAttribute("delay", &delay_buffer_depth);
|
||||
const char *devid = gameAnalogNode->Attribute("devid");
|
||||
|
||||
// create analog and add to list
|
||||
@@ -1001,6 +1075,9 @@ std::vector<Analog> Config::getAnalogs(const std::string &gameName) {
|
||||
analog.setDeadzoneMirror(deadzone_mirror);
|
||||
analog.setInvert(invert);
|
||||
analog.setSmoothing(smoothing);
|
||||
analog.setMultiplier(multiplier);
|
||||
analog.setRelativeMode(relative_mode);
|
||||
analog.setDelayBufferDepth(delay_buffer_depth);
|
||||
if (devid) {
|
||||
analog.setDeviceIdentifier(devid);
|
||||
}
|
||||
@@ -1136,7 +1213,7 @@ std::vector<Option> Config::getOptions(Game *game) {
|
||||
|
||||
bool Config::createConfigFile() {
|
||||
std::ofstream ofsConfig;
|
||||
ofsConfig.open(this->configLocation);
|
||||
ofsConfig.open(this->configLocationTemp);
|
||||
if (!ofsConfig.is_open() || ofsConfig.fail() || ofsConfig.bad()) {
|
||||
this->status = false;
|
||||
return false;
|
||||
@@ -1146,7 +1223,7 @@ bool Config::createConfigFile() {
|
||||
}
|
||||
|
||||
bool Config::firstFillConfigFile() {
|
||||
this->configFile.LoadFile(this->configLocation.c_str());
|
||||
this->configFile.LoadFile(this->configLocationTemp.c_str());
|
||||
this->configFile.Clear();
|
||||
|
||||
tinyxml2::XMLNode *declarationNode = this->configFile.NewDeclaration();
|
||||
@@ -1155,6 +1232,22 @@ bool Config::firstFillConfigFile() {
|
||||
tinyxml2::XMLNode *rootNode = this->configFile.NewElement("games");
|
||||
this->configFile.InsertEndChild(rootNode);
|
||||
|
||||
this->configFile.SaveFile(this->configLocation.c_str(), false);
|
||||
this->saveConfigFile();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Config::saveConfigFile() {
|
||||
// create a .tmp file and write to it...
|
||||
const auto xml_result = this->configFile.SaveFile(this->configLocationTemp.c_str(), false);
|
||||
if (xml_result != tinyxml2::XMLError::XML_SUCCESS) {
|
||||
log_info("cfg", "failed to write file: {}", this->configLocationTemp.string());
|
||||
return;
|
||||
}
|
||||
// copy the .tmp file to the main file...
|
||||
if (CopyFileW(this->configLocationTemp.c_str(), this->configLocation.c_str(), false) == 0) {
|
||||
log_warning("cfg", "CopyFileA failed: 0x{:08x}", GetLastError());
|
||||
return;
|
||||
}
|
||||
// delete the .tmp file (not critical if this fails)
|
||||
DeleteFileW(this->configLocationTemp.c_str());
|
||||
}
|
||||
Reference in New Issue
Block a user