Generated with github copilot.
Problem
Users sometimes get an error that a file already exists when clicking to enable or disable events. This happens because the UI state gets out of sync with the actual file state on disk.
Root Cause
The code uses QFile::rename() to toggle events by renaming files between active and inactive states (e.g., LiveTuningData_Event.json ↔ OFF_LiveTuningData_Event.json).
QFile::rename() fails if the destination file already exists. This can happen when:
- The UI state gets out of sync with the actual file state
- A previous operation partially failed
- Files were manually modified in the filesystem
Solution
Check if the destination file exists and remove it before attempting to rename. This needs to be fixed in three functions:
onEventSwitchChanged() - handles standard events like Cosmic Chaos, Armor Incursion, etc.
onCustomEventSwitchChanged() - handles custom events
onPandemoniumProtocolToggle() - handles Pandemonium Protocol event
Implementation Details
For each function, add checks before the rename operation:
When enabling an event (renaming OFF_file to active file):
// Check if destination already exists and remove it
if (activeFile.exists()) {
if (!activeFile.remove()) {
QMessageBox::critical(this, "Error", QString("Failed to remove existing active file: %1").arg(activeFile.errorString()));
return;
}
}
When disabling an event (renaming active file to OFF_file):
// Check if destination already exists and remove it
if (inactiveFile.exists()) {
if (!inactiveFile.remove()) {
QMessageBox::critical(this, "Error", QString("Failed to remove existing inactive file: %1").arg(inactiveFile.errorString()));
return;
}
}
Files to Modify
MHServerEmuUI/mainwindow.cpp
- Line ~1519-1567:
onEventSwitchChanged()
- Line ~1571-1624:
onCustomEventSwitchChanged()
- Line ~1884-1917:
onPandemoniumProtocolToggle()
Expected Behavior After Fix
- Event toggles will work reliably even when files are out of sync
- Users will no longer see "file already exists" errors
- The application will gracefully handle edge cases where both active and inactive versions exist
Generated with github copilot.
Problem
Users sometimes get an error that a file already exists when clicking to enable or disable events. This happens because the UI state gets out of sync with the actual file state on disk.
Root Cause
The code uses
QFile::rename()to toggle events by renaming files between active and inactive states (e.g.,LiveTuningData_Event.json↔OFF_LiveTuningData_Event.json).QFile::rename()fails if the destination file already exists. This can happen when:Solution
Check if the destination file exists and remove it before attempting to rename. This needs to be fixed in three functions:
onEventSwitchChanged()- handles standard events like Cosmic Chaos, Armor Incursion, etc.onCustomEventSwitchChanged()- handles custom eventsonPandemoniumProtocolToggle()- handles Pandemonium Protocol eventImplementation Details
For each function, add checks before the rename operation:
When enabling an event (renaming OFF_file to active file):
When disabling an event (renaming active file to OFF_file):
Files to Modify
MHServerEmuUI/mainwindow.cpponEventSwitchChanged()onCustomEventSwitchChanged()onPandemoniumProtocolToggle()Expected Behavior After Fix