@@ -214,8 +214,6 @@ void CNPAPreferences::OnComboTextChange(UINT, int, CWindow)
214214 m_ButtonRemoveInstance.EnableWindow (false );
215215 m_ButtonRenameInstance.EnableWindow (true );
216216 }
217-
218-
219217}
220218
221219void CNPAPreferences::OnBnClickedAdd (UINT, int , CWindow)
@@ -477,6 +475,18 @@ void CNPAPreferences::config_export(pfc::string8 &fn) {
477475 }
478476}
479477
478+ static t_size find_instance (const pfc::string8 &name, instance_item &out, t_size &index) {
479+ for (t_size i = 0 ; i < g_cfg_instance_list.get_count (); i++) {
480+ const instance_item &item = g_cfg_instance_list.get_item (i);
481+ if (item.name == name) {
482+ index = i;
483+ out = item;
484+ return true ;
485+ }
486+ }
487+ return false ;
488+ }
489+
480490void CNPAPreferences::config_import (pfc::string8 &fn) {
481491 Json::Value root;
482492 try {
@@ -506,17 +516,36 @@ void CNPAPreferences::config_import(pfc::string8 &fn) {
506516 return ;
507517 }
508518
509- m_ComboBoxInstance.ResetContent ();
510- IEvents::Clear ();
511- g_cfg_instance_list.remove_all ();
512-
519+ bool wasempty;
520+ if (m_ComboBoxInstance.GetCount () == 0 ) {
521+ wasempty = true ;
522+ }
523+ else {
524+ wasempty = false ;
525+ }
526+
527+ console::info (" NPA: Starting import" );
528+ pfc::string8 s;
513529 for (const auto &item : items) {
514- g_cfg_instance_list.add_item (item);
530+ instance_item ex;
531+ t_size index;
532+ if (find_instance (item.name , ex, index)) {
533+ console::info (s << " NPA: Updating instance '" << item.name << " '" );
534+ g_cfg_instance_list.replace_item (index, ex);
535+ }
536+ else {
537+ console::info (s << " NPA: Adding instance: '" << item.name << " '" );
538+ g_cfg_instance_list.add_item (item);
539+ m_ComboBoxInstance.AddString (CA2CT (item.name ));
540+ }
541+ s.reset ();
515542 IEvents::UpdateInstance (&item);
516- m_ComboBoxInstance.AddString (CA2CT (item.name ));
517543 }
544+ console::info (" NPA: Import done" );
518545
519- ComboInstanceSelect (0 );
546+ if (wasempty) {
547+ ComboInstanceSelect (0 );
548+ }
520549
521550}
522551
0 commit comments