Project

Profile

Help

Revision 1b421251

ID1b4212512c922e4ffbf3a2205a00b0cc1d17bbdd
Parent d649dc79
Child 14a02284

Added by Vincent Le Goff 9 months ago

Force the conversion in utf-8 for world configuration

View differences:

src/world.py
117 117
        path = self.path
118 118
        path = os.path.join(path, "config.set")
119 119
        if os.path.exists(path):
120
            file = open(path, "r", encoding="utf-8")
121
            content = file.read()
122
            file.close()
120
            try:
121
                with open(path, "r", encoding="utf-8") as file:
122
                    content = file.read()
123
            except UnicodeDecodeError:
124
                with open(path, "r", encoding="latin-1") as file:
125
                    content = file.read()
126
                    to_save = True
123 127

  
124 128
            # Execute the script
125 129
            self.sharp_engine.execute(content, variables=False)
......
199 203
        content = "\n".join(lines) + "\n"
200 204
        path = self.path
201 205
        path = os.path.join(path, "config.set")
202
        file = open(path, "w")
203
        file.write(content)
204
        file.close()
206
        with open(path, "w", encoding="utf-8") as file:
207
            file.write(content)
205 208

  
206 209
    def remove(self):
207 210
        """Remove the world."""

Also available in: Unified diff