Skip to content

Commit

Permalink
bugfix: Fixed config name was changed when inserting media (fixes #1564)
Browse files Browse the repository at this point in the history
- The config name was always changed when inserting media into a drive (floppy, CD, whdload). However, this should not happen if we already had a config file loaded earlier.
  • Loading branch information
midwan committed Jan 4, 2025
1 parent 998f1ef commit cf5e541
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 37 deletions.
12 changes: 6 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ std::string get_filename_extension(const TCHAR* filename)
return fName.substr(pos, fName.length());
}

extern void SetLastActiveConfig(const char* filename);
extern void set_last_active_config(const char* filename);

static void parse_cmdline (int argc, TCHAR **argv)
{
Expand Down Expand Up @@ -1074,7 +1074,7 @@ static void parse_cmdline (int argc, TCHAR **argv)
strncat(savestate_fname, txt, MAX_DPATH - 1);
savestate_state = STATE_DORESTORE;
}
SetLastActiveConfig(txt);
set_last_active_config(txt);
xfree(txt);
#endif
}
Expand Down Expand Up @@ -1157,7 +1157,7 @@ static void parse_cmdline (int argc, TCHAR **argv)
add_file_to_mru_list(lstMRUWhdloadList, std::string(txt));
whdload_prefs.whdload_filename = std::string(txt);
whdload_auto_prefs(&currprefs, txt);
SetLastActiveConfig(txt);
set_last_active_config(txt);
}
else if (_tcscmp(txt2.c_str(), ".uss") == 0)
{
Expand All @@ -1175,7 +1175,7 @@ static void parse_cmdline (int argc, TCHAR **argv)
savestate_state = STATE_DORESTORE;
currprefs.start_gui = false;
}
SetLastActiveConfig(txt);
set_last_active_config(txt);
}
else if (_tcscmp(txt2.c_str(), ".cue") == 0
|| _tcscmp(txt2.c_str(), ".iso") == 0
Expand All @@ -1184,7 +1184,7 @@ static void parse_cmdline (int argc, TCHAR **argv)
write_log("CDTV/CD32... %s\n", txt);
add_file_to_mru_list(lstMRUCDList, std::string(txt));
cd_auto_prefs(&currprefs, txt);
SetLastActiveConfig(txt);
set_last_active_config(txt);
}
else if (_tcscmp(txt2.c_str(), ".adf") == 0
|| _tcscmp(txt2.c_str(), ".adz") == 0
Expand Down Expand Up @@ -1226,7 +1226,7 @@ static void parse_cmdline (int argc, TCHAR **argv)
{
write_log("No configuration file found for %s, inserting disk in DF0: with default settings\n", txt);
disk_insert(0, txt);
SetLastActiveConfig(txt);
set_last_active_config(txt);
currprefs.start_gui = false;
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ extern void signal_segv(int signum, siginfo_t* info, void* ptr);
extern void signal_buserror(int signum, siginfo_t* info, void* ptr);
extern void signal_term(int signum, siginfo_t* info, void* ptr);

extern void SetLastActiveConfig(const char* filename);
extern void set_last_active_config(const char* filename);

std::string home_dir;
std::string current_dir;
Expand Down Expand Up @@ -329,7 +329,13 @@ int max_uae_height;

extern "C" int main(int argc, char* argv[]);

void SetLastActiveConfig(const char* filename)
void set_last_loaded_config(const char* filename)
{
extract_filename(filename, last_loaded_config);
remove_file_extension(last_loaded_config);
}

void set_last_active_config(const char* filename)
{
extract_filename(filename, last_active_config);
remove_file_extension(last_active_config);
Expand Down Expand Up @@ -3141,8 +3147,8 @@ int target_cfgfile_load(struct uae_prefs* p, const char* filename, int type, con
if (strlen(p->floppyslots[i].df) > 0)
add_file_to_mru_list(lstMRUDiskList, std::string(p->floppyslots[i].df));
}

SetLastActiveConfig(filename);
set_last_loaded_config(filename);
set_last_active_config(filename);
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/osdep/amiberry_whdbooter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "midiemu.h"
#include "registry.h"

extern void SetLastActiveConfig(const char* filename);
extern void set_last_active_config(const char* filename);
extern std::string current_dir;
extern char last_loaded_config[MAX_DPATH];

Expand Down
16 changes: 8 additions & 8 deletions src/osdep/gui/PanelConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void InitConfigsList()
}
}

class ConfigButtonActionListener : public gcn::ActionListener
class ConfigActionListener : public gcn::ActionListener
{
public:
void action(const gcn::ActionEvent& actionEvent) override
Expand Down Expand Up @@ -113,7 +113,7 @@ class ConfigButtonActionListener : public gcn::ActionListener
}
};

static ConfigButtonActionListener* configButtonActionListener;
static ConfigActionListener* configActionListener;

static Uint32 last_click_time = 0;
class ConfigsListActionListener : public gcn::ActionListener
Expand Down Expand Up @@ -159,7 +159,7 @@ static ConfigsListActionListener* configsListActionListener;

void InitPanelConfig(const struct config_category& category)
{
configButtonActionListener = new ConfigButtonActionListener();
configActionListener = new ConfigActionListener();
configsListActionListener = new ConfigsListActionListener();

lblName = new gcn::Label("Name:");
Expand All @@ -185,21 +185,21 @@ void InitPanelConfig(const struct config_category& category)
cmdLoad->setBaseColor(gui_base_color);
cmdLoad->setForegroundColor(gui_foreground_color);
cmdLoad->setId("ConfigLoad");
cmdLoad->addActionListener(configButtonActionListener);
cmdLoad->addActionListener(configActionListener);

cmdSave = new gcn::Button("Save");
cmdSave->setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
cmdSave->setBaseColor(gui_base_color);
cmdSave->setForegroundColor(gui_foreground_color);
cmdSave->setId("ConfigSave");
cmdSave->addActionListener(configButtonActionListener);
cmdSave->addActionListener(configActionListener);

cmdDelete = new gcn::Button("Delete");
cmdDelete->setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
cmdDelete->setBaseColor(gui_base_color);
cmdDelete->setForegroundColor(gui_foreground_color);
cmdDelete->setId("CfgDelete");
cmdDelete->addActionListener(configButtonActionListener);
cmdDelete->addActionListener(configActionListener);

const int list_width = category.panel->getWidth() - 2 * DISTANCE_BORDER - SCROLLBAR_WIDTH - 2;
const int list_height = category.panel->getHeight() - 2 * DISTANCE_BORDER - 2 * lblName->getHeight() - 3 * DISTANCE_NEXT_Y - 2 * BUTTON_HEIGHT;
Expand Down Expand Up @@ -259,7 +259,7 @@ void ExitPanelConfig()
delete cmdSave;
delete cmdDelete;

delete configButtonActionListener;
delete configActionListener;

delete lblName;
delete txtName;
Expand Down Expand Up @@ -335,7 +335,7 @@ bool HelpPanelConfig(std::vector<std::string>& helptext)
helptext.emplace_back("scan for a configuration file of the same \"Name\" as the disk image or .lha archive");
helptext.emplace_back("being loaded. After you load a floppy disk image or whdload archive, and Start the ");
helptext.emplace_back(R"(emulation, you can use the "F12" key to show the GUI, and in this panel the "Name")");
helptext.emplace_back("field for the configuartion will be filled correctly. Do not change this, as it will");
helptext.emplace_back("field for the configuration will be filled correctly. Do not change this, as it will");
helptext.emplace_back("stop auto-config from working. You may change the description if you desire.");
helptext.emplace_back(" ");
helptext.emplace_back("To delete the currently selected configuration file from the disk (and the list),");
Expand Down
6 changes: 4 additions & 2 deletions src/osdep/gui/PanelFloppy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ class FloppyActionListener : public gcn::ActionListener
RefreshDiskListModel();

AdjustDropDownControls();
SetLastActiveConfig(tmp.c_str());
if (!last_loaded_config[0])
set_last_active_config(tmp.c_str());
}
}
cmdDFxSelect[i]->requestFocus();
Expand Down Expand Up @@ -309,7 +310,8 @@ class FloppyActionListener : public gcn::ActionListener
bIgnoreListChange = true;
cboDFxFile[i]->setSelected(0);
bIgnoreListChange = false;
SetLastActiveConfig(element.c_str());
if (!last_loaded_config[0])
set_last_active_config(element.c_str());
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/osdep/gui/PanelHD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ class CDButtonActionListener : public gcn::ActionListener

RefreshCDListModel();
AdjustDropDownControls();
SetLastActiveConfig(tmp.c_str());
if (!last_loaded_config[0])
set_last_active_config(tmp.c_str());
}
}
cmdCDSelectFile->requestFocus();
Expand Down Expand Up @@ -352,7 +353,8 @@ class CDFileActionListener : public gcn::ActionListener
bIgnoreListChange = true;
cboCDFile->setSelected(0);
bIgnoreListChange = false;
SetLastActiveConfig(element.c_str());
if (!last_loaded_config[0])
set_last_active_config(element.c_str());
}
}
}
Expand Down
30 changes: 18 additions & 12 deletions src/osdep/gui/PanelQuickstart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ class QSCDActionListener : public gcn::ActionListener

RefreshCDListModel();
AdjustDropDownControls();
SetLastActiveConfig(tmp.c_str());
if (!last_loaded_config[0])
set_last_active_config(tmp.c_str());
}
}
cmdCDSelect->requestFocus();
Expand Down Expand Up @@ -401,7 +402,8 @@ class QSCDActionListener : public gcn::ActionListener
bIgnoreListChange = true;
cboCDFile->setSelected(0);
bIgnoreListChange = false;
SetLastActiveConfig(element.c_str());
if (!last_loaded_config[0])
set_last_active_config(element.c_str());
}
}
}
Expand Down Expand Up @@ -443,7 +445,8 @@ class QSWHDLoadActionListener : public gcn::ActionListener
whdload_auto_prefs(&changed_prefs, whdload_prefs.whdload_filename.c_str());

AdjustDropDownControls();
SetLastActiveConfig(whdload_prefs.whdload_filename.c_str());
if (!last_loaded_config[0])
set_last_active_config(whdload_prefs.whdload_filename.c_str());
}
cmdWhdloadSelect->requestFocus();
}
Expand Down Expand Up @@ -547,9 +550,10 @@ class QSDiskActionListener : public gcn::ActionListener
void action(const gcn::ActionEvent& actionEvent) override
{
int sub;
auto action = actionEvent.getSource();
for (auto i = 0; i < 2; ++i)
{
if (actionEvent.getSource() == chkqsDFx[i])
if (action == chkqsDFx[i])
{
//---------------------------------------
// Drive enabled/disabled
Expand All @@ -559,7 +563,7 @@ class QSDiskActionListener : public gcn::ActionListener
else
changed_prefs.floppyslots[i].dfxtype = DRV_NONE;
}
else if (actionEvent.getSource() == chkqsDFxWriteProtect[i])
else if (action == chkqsDFxWriteProtect[i])
{
//---------------------------------------
// Write-protect changed
Expand All @@ -579,7 +583,7 @@ class QSDiskActionListener : public gcn::ActionListener
}
DISK_reinsert(i);
}
else if (actionEvent.getSource() == cboqsDFxType[i])
else if (action == cboqsDFxType[i])
{
const auto selectedType = cboqsDFxType[i]->getSelected();
const int dfxtype = todfxtype(i, selectedType - 1, &sub);
Expand All @@ -596,15 +600,15 @@ class QSDiskActionListener : public gcn::ActionListener
changed_prefs.floppyslots[i].dfxsubtypeid[0] = 0;
}
}
else if (actionEvent.getSource() == cmdqsDFxInfo[i])
else if (action == cmdqsDFxInfo[i])
{
//---------------------------------------
// Show info about current disk-image
//---------------------------------------
if (changed_prefs.floppyslots[i].dfxtype != DRV_NONE && strlen(changed_prefs.floppyslots[i].df) > 0)
DisplayDiskInfo(i);
}
else if (actionEvent.getSource() == cmdqsDFxEject[i])
else if (action == cmdqsDFxEject[i])
{
//---------------------------------------
// Eject disk from drive
Expand All @@ -613,7 +617,7 @@ class QSDiskActionListener : public gcn::ActionListener
strncpy(changed_prefs.floppyslots[i].df, "", MAX_DPATH);
AdjustDropDownControls();
}
else if (actionEvent.getSource() == cmdqsDFxSelect[i])
else if (action == cmdqsDFxSelect[i])
{
//---------------------------------------
// Select disk for drive
Expand All @@ -635,12 +639,13 @@ class QSDiskActionListener : public gcn::ActionListener
RefreshDiskListModel();

AdjustDropDownControls();
SetLastActiveConfig(tmp.c_str());
if (!last_loaded_config[0])
set_last_active_config(tmp.c_str());
}
}
cmdqsDFxSelect[i]->requestFocus();
}
else if (actionEvent.getSource() == cboqsDFxFile[i])
else if (action == cboqsDFxFile[i])
{
//---------------------------------------
// Disk image from list selected
Expand Down Expand Up @@ -669,7 +674,8 @@ class QSDiskActionListener : public gcn::ActionListener
bIgnoreListChange = true;
cboqsDFxFile[i]->setSelected(0);
bIgnoreListChange = false;
SetLastActiveConfig(element.c_str());
if (!last_loaded_config[0])
set_last_active_config(element.c_str());
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/osdep/gui/PanelWHDLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class WHDLoadActionListener : public gcn::ActionListener
bIgnoreListChange = false;
}
whdload_auto_prefs(&changed_prefs, whdload_prefs.whdload_filename.c_str());
SetLastActiveConfig(whdload_prefs.whdload_filename.c_str());
if (!last_loaded_config[0])
set_last_active_config(whdload_prefs.whdload_filename.c_str());
}
refresh_all_panels();
}
Expand Down
3 changes: 2 additions & 1 deletion src/osdep/gui/gui_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ extern void load_default_theme();
extern void apply_theme();
extern void apply_theme_extras();

extern void SetLastActiveConfig(const char* filename);
extern void SetLastLoadedConfig(const char* filename);
extern void set_last_active_config(const char* filename);

extern void addromfiles(UAEREG* fkey, gcn::DropDown* d, const TCHAR* path, int type1, int type2);

Expand Down

0 comments on commit cf5e541

Please sign in to comment.