fix: Python shutdown errors

This commit is contained in:
rtw1x1
2026-01-21 08:50:33 +00:00
parent b72982cc62
commit a31c0bfacf
7 changed files with 32 additions and 29 deletions

View File

@@ -325,30 +325,30 @@ class LoginWindow(ui.ScriptWindow):
def __SaveChannelInfo(self):
try:
file=open("channel.inf", "w")
file.write("%d %d %d" % (self.__GetServerID(), self.__GetChannelID(), self.__GetRegionID()))
with open("channel.inf", "w") as file:
file.write("%d %d %d" % (self.__GetServerID(), self.__GetChannelID(), self.__GetRegionID()))
except:
print "LoginWindow.__SaveChannelInfo - SaveError"
def __LoadChannelInfo(self):
try:
file=open("channel.inf")
lines=file.readlines()
if len(lines)>0:
tokens=lines[0].split()
with open("channel.inf") as file:
lines=file.readlines()
selServerID=int(tokens[0])
selChannelID=int(tokens[1])
if len(tokens) == 3:
regionID = int(tokens[2])
if len(lines)>0:
tokens=lines[0].split()
return regionID, selServerID, selChannelID
selServerID=int(tokens[0])
selChannelID=int(tokens[1])
if len(tokens) == 3:
regionID = int(tokens[2])
return regionID, selServerID, selChannelID
except:
print "LoginWindow.__LoadChannelInfo - OpenError"
return -1, -1, -1
return -1, -1, -1
def __ExitGame(self):
app.Exit()

View File

@@ -27,7 +27,8 @@ class CursorImage(object):
self.LoadImage(imageName)
def __del__(self):
grpImage.Delete(self.handle)
if grpImage and self.handle:
grpImage.Delete(self.handle)
def LoadImage(self, imageName):
try:

View File

@@ -9,21 +9,19 @@ def SaveLastPlayFieldMusic():
global fieldMusic
try:
lastPlayFile=open("BGM/lastplay.inf", "w")
with open("BGM/lastplay.inf", "w") as lastPlayFile:
lastPlayFile.write(fieldMusic)
except IOError:
return
lastPlayFile.write(fieldMusic)
def LoadLastPlayFieldMusic():
global fieldMusic
try:
lastPlayFile=open("BGM/lastplay.inf", "r")
with open("BGM/lastplay.inf", "r") as lastPlayFile:
fieldMusic=lastPlayFile.read()
except IOError:
return
fieldMusic=lastPlayFile.read()

View File

@@ -22,7 +22,8 @@ class LogBoxFile:
self.restore()
def restore(self):
sys.stderr = self.stderrSave
if sys:
sys.stderr = self.stderrSave
def write(self, msg):
self.msg = self.msg + msg

View File

@@ -98,7 +98,8 @@ class Window(object):
self.Hide()
def __del__(self):
wndMgr.Destroy(self.hWnd)
if wndMgr and self.hWnd:
wndMgr.Destroy(self.hWnd)
def RegisterWindow(self, layer):
self.hWnd = wndMgr.Register(self, layer)

View File

@@ -26,11 +26,13 @@ def GetMouseButtonSettings():
def SaveMouseButtonSettings():
global MOUSE_SETTINGS
open("mouse.cfg", "w").write("%s\t%s" % tuple(MOUSE_SETTINGS))
with open("mouse.cfg", "w") as f:
f.write("%s\t%s" % tuple(MOUSE_SETTINGS))
def LoadMouseButtonSettings():
global MOUSE_SETTINGS
tokens = open("mouse.cfg", "r").read().split()
with open("mouse.cfg", "r") as f:
tokens = f.read().split()
if len(tokens) != 2:
raise RuntimeError, "MOUSE_SETTINGS_FILE_ERROR"

View File

@@ -46,10 +46,10 @@ class Sandbox(object):
sys.modules[prevented_module_name] = None
try:
f = open(filename, 'rb')
data = f.read()
code = compile(data, filename, 'exec')
exec code in dic
with open(filename, 'rb') as f:
data = f.read()
code = compile(data, filename, 'exec')
exec code in dic
except Exception, e:
sys.stderr.write(e)
finally: