Repository: lutris/lutris

Issue:
Reicast configuration reset on each run
**Describe the bug**

When running games with Reicast, a user can make configuration changes within the Reicast GUI (for example, those which can't be customized by the Lutris configuration panel) which are preserved in the `~/.reicast/emu.cfg`. Lutris erases this file entirely each time it starts a Reicast game, removing any customization that a user may have done.

**Expected behavior**

* Launch Reicast game.
* Make adjustments to configuration in Reicast GUI.
* Close Reicast game.
* Re-launch Reicast game.
* Verify that configuration adjustments have been preserved.

**Current behavior**

* Launch Reicast game.
* Make adjustments to configuration in Reicast GUI.
* Close Reicast game.
* Re-launch Reicast game.
* Reicast configuration adjustments have been removed.

**Steps to reproduce**

See above.

**Lutris debugging output**

Nothing related to config parsing appears.

**System information**

```
{
  "comment": "Lutris wipes out Reicast configuration on game launch.",
  "system": {
    "gpus": [
      {
        "DRIVER": "i915",
        "PCI_ID": "8086:5916",
        "PCI_SUBSYS_ID": "1028:07A8",
        "PCI_CLASS": "30000",
        "PCI_SLOT_NAME": "0000:00:02.0",
        "MODALIAS": "pci:v00008086d00005916sv00001028sd000007A8bc03sc00i00"
      }
    ],
    "env": {
      "CLUTTER_IM_MODULE": "xim",
      "NVM_DIR": "/home/traack/.nvm",
      "LS_COLORS": "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:",
      "_system_type": "Linux",
      "LESSCLOSE": "/usr/bin/lesspipe %s %s",
      "XDG_MENU_PREFIX": "gnome-",
      "LANG": "en_US.UTF-8",
      "DISPLAY": ":0",
      "rvm_bin_path": "/home/traack/.rvm/bin",
      "GNOME_SHELL_SESSION_MODE": "ubuntu",
      "rvm_version": "1.29.6 (latest)",
      "RUBY_VERSION": "ruby-1.9.3-p286",
      "COLORTERM": "truecolor",
      "NVM_CD_FLAGS": "",
      "GEM_HOME": "/home/traack/.rvm/gems/ruby-1.9.3-p286",
      "DESKTOP_AUTOSTART_ID": "106c81e55257bc54ba157517767836118000000132400024",
      "USERNAME": "traack",
      "XDG_VTNR": "4",
      "GIO_LAUNCHED_DESKTOP_FILE_PID": "13606",
      "SSH_AUTH_SOCK": "/run/user/1000/keyring/ssh",
      "MANDATORY_PATH": "/usr/share/gconf/ubuntu.mandatory.path",
      "XDG_SESSION_ID": "32",
      "GVM_ROOT": "/home/traack/.gvm",
      "USER": "traack",
      "DESKTOP_SESSION": "ubuntu",
      "QT4_IM_MODULE": "xim",
      "TEXTDOMAINDIR": "/usr/share/locale/",
      "DEFAULTS_PATH": "/usr/share/gconf/ubuntu.default.path",
      "PWD": "/home/traack",
      "_system_version": "18.04",
      "HOME": "/home/traack",
      "GUAKE_TAB_UUID": "50ff6971-5284-4226-bcad-6ac030b61822",
      "TEXTDOMAIN": "im-config",
      "rvm_user_install_flag": "1",
      "_system_name": "Ubuntu",
      "SSH_AGENT_PID": "3740",
      "QT_ACCESSIBILITY": "1",
      "XDG_SESSION_TYPE": "x11",
      "XDG_DATA_DIRS": "/usr/share/ubuntu:/home/traack/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop",
      "_system_arch": "x86_64",
      "XDG_SESSION_DESKTOP": "ubuntu",
      "GEM_PATH": "/home/traack/.rvm/gems/ruby-1.9.3-p286:/home/traack/.rvm/gems/ruby-1.9.3-p286@global",
      "rvm_stored_umask": "0002",
      "rvm_loaded_flag": "1",
      "GTK_MODULES": "gail:atk-bridge",
      "rvm_path": "/home/traack/.rvm",
      "WINDOWPATH": "4",
      "TERM": "xterm-256color",
      "VTE_VERSION": "5202",
      "SHELL": "/bin/bash",
      "QT_IM_MODULE": "ibus",
      "XMODIFIERS": "@im=ibus",
      "IM_CONFIG_PHASE": "2",
      "NVM_BIN": "/home/traack/.nvm/versions/node/v10.14.2/bin",
      "XDG_CURRENT_DESKTOP": "ubuntu:GNOME",
      "GPG_AGENT_INFO": "/run/user/1000/gnupg/S.gpg-agent:0:1",
      "GIO_LAUNCHED_DESKTOP_FILE": "/home/traack/.config/autostart/guake.desktop",
      "rvm_prefix": "/home/traack",
      "SHLVL": "1",
      "XDG_SEAT": "seat0",
      "GDMSESSION": "ubuntu",
      "GNOME_DESKTOP_SESSION_ID": "this-is-deprecated",
      "LOGNAME": "traack",
      "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus",
      "XDG_RUNTIME_DIR": "/run/user/1000",
      "XAUTHORITY": "/run/user/1000/gdm/Xauthority",
      "MY_RUBY_HOME": "/home/traack/.rvm/rubies/ruby-1.9.3-p286",
      "XDG_CONFIG_DIRS": "/etc/xdg/xdg-ubuntu:/etc/xdg",
      "PATH": "/home/traack/bin:/home/traack/.gvm/bin:/home/traack/.nvm/versions/node/v10.14.2/bin:/home/traack/bin:/home/traack/.rvm/gems/ruby-1.9.3-p286/bin:/home/traack/.rvm/gems/ruby-1.9.3-p286@global/bin:/home/traack/.rvm/rubies/ruby-1.9.3-p286/bin:/home/traack/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/traack/.rvm/bin:/home/traack/.rvm/bin:/home/traack/.rvm/bin",
      "GVM_VERSION": "1.0.22",
      "GVM_PATH_BACKUP": "/home/traack/.gvm/bin:/home/traack/.nvm/versions/node/v10.14.2/bin:/home/traack/bin:/home/traack/.rvm/gems/ruby-1.9.3-p286/bin:/home/traack/.rvm/gems/ruby-1.9.3-p286@global/bin:/home/traack/.rvm/rubies/ruby-1.9.3-p286/bin:/home/traack/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/traack/.rvm/bin:/home/traack/.rvm/bin",
      "IRBRC": "/home/traack/.rvm/rubies/ruby-1.9.3-p286/.irbrc",
      "SESSION_MANAGER": "local/islander:@/tmp/.ICE-unix/13240,unix/islander:/tmp/.ICE-unix/13240",
      "LESSOPEN": "| /usr/bin/lesspipe %s",
      "GTK_IM_MODULE": "ibus",
      "_": "/usr/bin/lutris"
    },
    "missing_libs": {
      "OPENGL": [
        [],
        []
      ],
      "VULKAN": [
        [],
        []
      ],
      "WINE": [
        [],
        []
      ],
      "GAMEMODE": [
        [
          "libgamemodeauto.so"
        ],
        [
          "libgamemodeauto.so"
        ]
      ]
    },
    "cpus": [
      {
        "processor": "0",
        "vendor_id": "GenuineIntel",
        "cpu family": "6",
        "model": "142",
        "model name": "Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz",
        "stepping": "9",
        "microcode": "0xca",
        "cpu MHz": "790.650",
        "cache size": "3072 KB",
        "physical id": "0",
        "siblings": "4",
        "core id": "0",
        "cpu cores": "2",
        "apicid": "0",
        "initial apicid": "0",
        "fpu": "yes",
        "fpu_exception": "yes",
        "cpuid level": "22",
        "wp": "yes",
        "flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d",
        "bugs": "cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit",
        "bogomips": "5424.00",
        "clflush size": "64",
        "cache_alignment": "64",
        "address sizes": "39 bits physical, 48 bits virtual",
        "power management": ""
      },
      {
        "processor": "1",
        "vendor_id": "GenuineIntel",
        "cpu family": "6",
        "model": "142",
        "model name": "Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz",
        "stepping": "9",
        "microcode": "0xca",
        "cpu MHz": "791.340",
        "cache size": "3072 KB",
        "physical id": "0",
        "siblings": "4",
        "core id": "1",
        "cpu cores": "2",
        "apicid": "2",
        "initial apicid": "2",
        "fpu": "yes",
        "fpu_exception": "yes",
        "cpuid level": "22",
        "wp": "yes",
        "flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d",
        "bugs": "cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit",
        "bogomips": "5424.00",
        "clflush size": "64",
        "cache_alignment": "64",
        "address sizes": "39 bits physical, 48 bits virtual",
        "power management": ""
      },
      {
        "processor": "2",
        "vendor_id": "GenuineIntel",
        "cpu family": "6",
        "model": "142",
        "model name": "Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz",
        "stepping": "9",
        "microcode": "0xca",
        "cpu MHz": "770.337",
        "cache size": "3072 KB",
        "physical id": "0",
        "siblings": "4",
        "core id": "0",
        "cpu cores": "2",
        "apicid": "1",
        "initial apicid": "1",
        "fpu": "yes",
        "fpu_exception": "yes",
        "cpuid level": "22",
        "wp": "yes",
        "flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d",
        "bugs": "cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit",
        "bogomips": "5424.00",
        "clflush size": "64",
        "cache_alignment": "64",
        "address sizes": "39 bits physical, 48 bits virtual",
        "power management": ""
      },
      {
        "processor": "3",
        "vendor_id": "GenuineIntel",
        "cpu family": "6",
        "model": "142",
        "model name": "Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz",
        "stepping": "9",
        "microcode": "0xca",
        "cpu MHz": "798.836",
        "cache size": "3072 KB",
        "physical id": "0",
        "siblings": "4",
        "core id": "1",
        "cpu cores": "2",
        "apicid": "3",
        "initial apicid": "3",
        "fpu": "yes",
        "fpu_exception": "yes",
        "cpuid level": "22",
        "wp": "yes",
        "flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d",
        "bugs": "cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit",
        "bogomips": "5424.00",
        "clflush size": "64",
        "cache_alignment": "64",
        "address sizes": "39 bits physical, 48 bits virtual",
        "power management": ""
      }
    ],
    "drives": [
      {
        "name": "sda",
        "fstype": null,
        "label": null,
        "uuid": null,
        "mountpoint": null,
        "children": [
          {
            "name": "sda1",
            "fstype": "vfat",
            "label": null,
            "uuid": "9082-C00C",
            "mountpoint": "/boot/efi"
          },
          {
            "name": "sda2",
            "fstype": "ext4",
            "label": null,
            "uuid": "53062e32-342a-45c0-924e-ccc0f8c30335",
            "mountpoint": "/boot"
          },
          {
            "name": "sda3",
            "fstype": "crypto_LUKS",
            "label": null,
            "uuid": "072912d8-6bca-4a93-bb92-ddadb65af6d7",
            "mountpoint": null,
            "children": [
              {
                "name": "sda3_crypt",
                "fstype": "LVM2_member",
                "label": null,
                "uuid": "73oED0-nk6L-Ri2d-77KK-dDnk-PbZ5-vi5fhE",
                "mountpoint": null,
                "children": [
                  {
                    "name": "ubuntu--vg-root",
                    "fstype": "ext4",
                    "label": null,
                    "uuid": "03796424-dcef-4851-9010-b3363853104f",
                    "mountpoint": "/"
                  },
                  {
                    "name": "ubuntu--vg-swap_1",
                    "fstype": "swap",
                    "label": null,
                    "uuid": "d610b482-7f74-41d3-bd21-18e067cae0ab",
                    "mountpoint": "[SWAP]"
                  },
                  {
                    "name": "ubuntu--vg-s3blkdev--device0--journal",
                    "fstype": "jbd",
                    "label": null,
                    "uuid": "12a1ccd4-1888-4cc2-b914-5af1e1825286",
                    "mountpoint": null
                  },
                  {
                    "name": "ubuntu--vg-s3blkdev--device0--cache",
                    "fstype": "ext4",
                    "label": null,
                    "uuid": "125a3d54-f6d9-4c1a-a477-c1315ad99606",
                    "mountpoint": "/s3blkdev/cache"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "name": "nbd0",
        "fstype": null,
        "label": null,
        "uuid": null,
        "mountpoint": "/device0"
      }
    ],
    "ram": {
      "mem": {
        "total": "16304792",
        "used": "7201168",
        "free": "1019640",
        "shared": "1497716",
        "buff/cache": "8083984",
        "available": "7380616"
      },
      "swap": {
        "total": "10485756",
        "used": "512",
        "free": "10485244"
      }
    },
    "dist": [
      "Ubuntu",
      "18.04",
      "bionic"
    ],
    "glxinfo": {
      "opengl_es_profile_version": "OpenGL ES 3.2 Mesa 19.0.8",
      "opengl_core_profile_context_flags": "(none)",
      "opengl_vendor": "Intel Open Source Technology Center",
      "direct_rendering": "Yes",
      "opengl_core_profile_profile_mask": "core profile",
      "opengl_es_profile_shading_language_version": "OpenGL ES GLSL ES 3.20",
      "opengl_core_profile_shading_language_version": "4.50",
      "opengl_renderer": "Mesa DRI Intel(R) HD Graphics 620 (Kaby Lake GT2)",
      "opengl_version": "3.0 Mesa 19.0.8",
      "opengl_context_flags": "(none)",
      "display": ":0",
      "screen": "0",
      "opengl_shading_language_version": "1.30",
      "name_of_display": ":0",
      "opengl_core_profile_version": "4.5 (Core Profile) Mesa 19.0.8"
    }
  }
}
```



Discussion:

Resolving patch:
diff --git a/lutris/runners/reicast.py b/lutris/runners/reicast.py
--- a/lutris/runners/reicast.py
+++ b/lutris/runners/reicast.py
@@ -1,7 +1,7 @@
 import re
 import os
 import shutil
-from configparser import ConfigParser
+from configparser import RawConfigParser
 from collections import Counter
 from lutris import settings
 from lutris.runners.runner import Runner
@@ -106,12 +106,16 @@ def get_joypads(self):
 
     @staticmethod
     def write_config(config):
-        parser = ConfigParser()
+        # use RawConfigParser to preserve case-sensitive configs written by Reicast
+        # otherwise, Reicast will write with mixed-case and Lutris will overwrite with all lowercase
+        #   which will confuse Reicast
+        parser = RawConfigParser()
+        parser.optionxform = lambda option: option
 
         config_path = os.path.expanduser("~/.reicast/emu.cfg")
         if system.path_exists(config_path):
             with open(config_path, "r") as config_file:
-                parser.read(config_file)
+                parser.read_file(config_file)
 
         for section in config:
             if not parser.has_section(section):


Test patch: