[Pymoul-svn] SF.net SVN: pymoul: [72] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-01-24 23:17:08
|
Revision: 72
http://pymoul.svn.sourceforge.net/pymoul/?rev=72&view=rev
Author: tiran
Date: 2007-01-24 15:17:08 -0800 (Wed, 24 Jan 2007)
Log Message:
-----------
Fixed bug in wdys crypt module. It failed when the data was aligned at 8 bytes.
First version that actually writes graphics and audio ini
Modified Paths:
--------------
pymoul/trunk/src/moul/crypt/whatdoyousee.py
pymoul/trunk/src/moul/file/wdysini.py
pymoul/trunk/src/moul/qt/mainwindow.py
Modified: pymoul/trunk/src/moul/crypt/whatdoyousee.py
===================================================================
--- pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-01-24 22:11:48 UTC (rev 71)
+++ pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-01-24 23:17:08 UTC (rev 72)
@@ -32,12 +32,15 @@
from moul.crypt.xtea import xtea_decrypt
from moul.crypt.xtea import xtea_encrypt
+from moul.log import getLogger
HEADER = "whatdoyousee"
CROSS_REF = (0x6c0a5452, 0x03827d0f, 0x3a170b92, 0x16db7fc2)
CROSS_KEY = struct.pack("<4L", *CROSS_REF)
ENDIAN="<" # little endian (not network/big endian)
+LOG = getLogger('moul.crypt.whatdoyousee')
+
def decryptWDYS(fin):
"""Decrypt whatdoyousee files
@@ -54,9 +57,15 @@
out = []
pos = 0
- while fin:
+ while True:
block = fin.read(8)
- block = xtea_decrypt(CROSS_KEY, block, endian=ENDIAN)
+ if not block:
+ break
+ try:
+ block = xtea_decrypt(CROSS_KEY, block, endian=ENDIAN)
+ except:
+ LOG.exception("xTEA failure at block %r" % block)
+ raise
if length - pos < 8:
out.append(block[:length-pos])
break
@@ -91,6 +100,10 @@
if len(block) < 8:
block = block + '\0' * (8-len(block))
assert len(block) == 8
- block = xtea_encrypt(CROSS_KEY, block, endian=ENDIAN)
+ try:
+ block = xtea_encrypt(CROSS_KEY, block, endian=ENDIAN)
+ except:
+ LOG.exception("xTEA failure at block %r" % block)
+ raise
fout.write(block)
pos += 8
Modified: pymoul/trunk/src/moul/file/wdysini.py
===================================================================
--- pymoul/trunk/src/moul/file/wdysini.py 2007-01-24 22:11:48 UTC (rev 71)
+++ pymoul/trunk/src/moul/file/wdysini.py 2007-01-24 23:17:08 UTC (rev 72)
@@ -168,7 +168,7 @@
def __init__(self, *args, **kwargs):
pass
- def __call__(self, value):
+ def __call__(self, value, debug="unknown"):
return value
class MinMax(Constrain):
@@ -197,13 +197,13 @@
self._min = min
self._max = max
- def __call__(self, value):
+ def __call__(self, value, debug="unknown"):
if not isinstance(value, (int, float)):
- raise ConstrainError(type(value))
+ raise ConstrainError("%s: %s" % (debug,type(value)))
if value < self._min:
- raise ConstrainError("%s < min %s" % (value, self._min))
+ raise ConstrainError("%s: %s < min %s" % (debug, value, self._min))
if value > self._max:
- raise ConstrainError("%s > max %s" % (value, self._max))
+ raise ConstrainError("%s: %s > max %s" % (debug, value, self._max))
return value
class VideoConstrain(MinMax):
@@ -240,9 +240,10 @@
def __init__(self, values):
self._values = values
- def __call__(self, value):
+ def __call__(self, value, debug="unknown"):
if not value in self._values:
- raise ConstrainError("%s not in %s" % (value, str(self._values)))
+ raise ConstrainError("%s: %s not in %s" %
+ (debug, value, str(self._values)))
return value
class _VideoModes(object):
@@ -312,7 +313,6 @@
self._filedata = {}
self._newdata = {}
self._order = []
- self.clear()
self._fpath = None
def clear(self):
@@ -353,10 +353,13 @@
raise ValueError("Full path not set")
bak = orig + ".bak"
new = orig + ".new"
- shutils.copyfile(orig, bak) # make backup
+ shutil.copyfile(orig, bak) # make backup
self.writeEncFile(new) # write new
os.unlink(orig) # stupid windows can't perform an atomic rename
os.rename(new, orig) # move new to orig
+
+ # reread the file again
+ self.parseEncFile(self._fpath)
def parseEncFile(self, fd_name):
"""Read and parse file (fd or file name)
@@ -395,7 +398,11 @@
newkey = key
self._order.append(newkey)
value = line[len(key)+1:].strip()
- value = constrain(convert(value))
+ try:
+ value = constrain(convert(value), debug=key)
+ except: # catch all
+ LOG.exception("convert/constrain error")
+ raise
self._filedata[newkey] = value
break
if not found:
@@ -427,7 +434,11 @@
#key = newkey.replace('__', ' ')
#key = key.replace('_', '.')
convert, constrain = self._options[key]
- value = constrain(convert(value))
+ try:
+ value = constrain(convert(value), debug=key)
+ except: # catch all
+ LOG.exception("convert/constrain error")
+ raise
out.append("%s %s" % (key, value))
out.append('') # new line at EOF
return '\n'.join(out)
@@ -445,6 +456,9 @@
encryptWDYS(data, fd)
if close:
fd.close()
+ else:
+ fd.flush()
+ fd.seek(0)
def _get(self, name):
"""get descriptor helper
@@ -467,6 +481,11 @@
"""set descriptor helper for % sliders
"""
self._newdata[name] = float(value / 100.0)
+
+ def _setboolint(self, name, value):
+ """
+ """
+ self._newdata[name] = int(bool(value))
class AudioIni(ConfFile):
_filename = 'audio.ini'
@@ -484,7 +503,7 @@
'Audio.SetChannelVolume GUI' : (FloatString, MinMax(0.0, 1.0)), # 0-100%, no ui
# microphon missing -> OS mixer
}
- _devices = ['Generic Software', 'Generic Hardware']
+ _devices = ['"Generic Software"', '"Generic Hardware"']
# plus maybe a custom OpenAL v1.1 device
def parserDoneHook(self):
@@ -533,13 +552,13 @@
lambda self, v: self._set('Audio.UseEAX', v),
)
mute = property(lambda self: self._get('Audio.MuteAll'),
- lambda self, v: self._set('Audio.MuteAll', v),
+ lambda self, v: self._setboolint('Audio.MuteAll', v),
)
priority = property(lambda self: self._get('Audio.SetPriorityCutoff'),
lambda self, v: self._set('Audio.SetPriorityCutoff', v),
)
enablevoice = property(lambda self: self._get('Audio.EnableVoiceRecording'),
- lambda self, v: self._set('Audio.EnableVoiceRecording', v),
+ lambda self, v: self._setboolint('Audio.EnableVoiceRecording', v),
)
device = property(_getDevice, _setDevice)
fx = property(lambda self: self._getp('Audio.SetChannelVolume SoundFX'),
@@ -600,7 +619,7 @@
lambda self, v: self._set('Quality.Level', v),
)
shadow_enabled = property(lambda self: self._get('Graphics.Shadow.Enable'),
- lambda self, v: self._set('Graphics.Shadow.Enable', v),
+ lambda self, v: self._setboolint('Graphics.Shadow.Enable', v),
)
shadow = property(lambda self: self._getp('Graphics.Shadow.VisibleDistance'),
lambda self, v: self._setp('Graphics.Shadow.VisibleDistance', v),
Modified: pymoul/trunk/src/moul/qt/mainwindow.py
===================================================================
--- pymoul/trunk/src/moul/qt/mainwindow.py 2007-01-24 22:11:48 UTC (rev 71)
+++ pymoul/trunk/src/moul/qt/mainwindow.py 2007-01-24 23:17:08 UTC (rev 72)
@@ -79,9 +79,9 @@
@param event close event (QCloseEvent)
"""
- if self._dirty:
- event.reject()
- return False
+ #if self._dirty:
+ # event.reject()
+ # return False
self._systray_close()
event.accept()
@@ -158,7 +158,9 @@
def on_graphicsini_save(self):
"""SIGNAL graphicsini_save()
"""
- self._notimplemented()
+ #self._notimplemented()
+ self._graphics_ini.write()
+ self.setDirty(False)
def _graphicsini_setstate(self):
"""Set sliders according to graphics ini settings
@@ -185,6 +187,7 @@
# XXX: fixme
txt = videoModes.getVidModeHuman(idx)
self.lb_screenres.setText(QtCore.QString(txt))
+ self._graphics_ini.screenres = idx
@signalLogDecorator(LOG)
@pyqtSignature("int")
@@ -199,47 +202,56 @@
def on_sl_gra_quality_valueChanged(self, idx):
"""SIGNAL: valueChanged (int)
"""
+ self._graphics_ini.quality = idx
@signalLogDecorator(LOG)
@pyqtSignature("int")
def on_sl_gra_texture_valueChanged(self, idx):
"""SIGNAL: valueChanged (int)
"""
+ self._graphics_ini.texture = idx
@signalLogDecorator(LOG)
@pyqtSignature("int")
def on_sl_gra_antialias_valueChanged(self, idx):
"""SIGNAL: valueChanged (int)
"""
+ self._graphics_ini.antialias = idx
@signalLogDecorator(LOG)
@pyqtSignature("int")
def on_sl_gra_anisotropic_valueChanged(self, idx):
"""SIGNAL: valueChanged (int)
"""
+ self._graphics_ini.anisotropic = idx
@signalLogDecorator(LOG)
@pyqtSignature("int")
def on_sl_gra_shadow_valueChanged(self, idx):
"""SIGNAL: valueChanged (int)
"""
+ self._graphics_ini.shadow = idx
+
@signalLogDecorator(LOG)
@pyqtSignature("int")
- def on_cb_gra_windowed_stateChanged (self, state):
+ def on_cb_gra_windowed_stateChanged(self, state):
"""SIGNAL: stateChanged(int)
"""
+ self._graphics_ini.windowed = state
@signalLogDecorator(LOG)
@pyqtSignature("int")
def on_cb_gra_vsync_stateChanged (self, state):
"""SIGNAL: stateChanged(int)
"""
+ self._graphics_ini.vsync = state
@signalLogDecorator(LOG)
@pyqtSignature("int")
def on_cb_gra_shadow_stateChanged (self, state):
"""SIGNAL: stateChanged(int)
"""
+ self._graphics_ini.shadow_enabled = state
# ************************************************************************
# audio settings
@@ -281,13 +293,16 @@
def on_audioini_save(self):
"""SIGNAL audioini_save()
"""
- self._notimplemented()
+ #self._notimplemented()
+ self._audio_ini.write()
+ self.setDirty(False) # urks
def _audioini_setstate(self):
"""Set sliders according to audio ini settings
"""
aini = self._audio_ini
self.sl_aud_device.setMaximum(aini.numberOfDevices()-1)
+
self.sl_aud_npc.setValue(aini.npc)
self.sl_aud_music.setValue(aini.music)
self.sl_aud_fx.setValue(aini.fx)
@@ -303,18 +318,74 @@
def on_sl_aud_device_valueChanged(self, idx):
"""SIGNAL: valueChanged (int)
"""
- # TODO: fixme
+ self._audio_ini.device = idx
txt = self._audio_ini.getDeviceName(idx)
- self.lb_aud_device.setText(QtCore.QString(txt))
-
+ self.lb_aud_device.setText(QtCore.QString(txt[1:-1]))
+
@signalLogDecorator(LOG)
@pyqtSignature("int")
def on_sl_aud_device_sliderMoved(self, idx):
"""SIGNAL: sliderMoved(int)
"""
txt = self._audio_ini.getDeviceName(idx)
- self.lb_aud_device.setText(QtCore.QString(txt))
+ self.lb_aud_device.setText(QtCore.QString(txt[1:-1]))
+ @signalLogDecorator(LOG)
+ @pyqtSignature("int")
+ def on_sl_aud_npc_valueChanged(self, idx):
+ """SIGNAL: valueChanged (int)
+ """
+ self._audio_ini.npc = idx
+
+ @signalLogDecorator(LOG)
+ @pyqtSignature("int")
+ def on_sl_aud_music_valueChanged(self, idx):
+ """SIGNAL: valueChanged (int)
+ """
+ self._audio_ini.music = idx
+
+ @signalLogDecorator(LOG)
+ @pyqtSignature("int")
+ def on_sl_aud_fx_valueChanged(self, idx):
+ """SIGNAL: valueChanged (int)
+ """
+ self._audio_ini.fx = idx
+
+ @signalLogDecorator(LOG)
+ @pyqtSignature("int")
+ def on_sl_aud_ambience_valueChanged(self, idx):
+ """SIGNAL: valueChanged (int)
+ """
+ self._audio_ini.ambience = idx
+
+ @signalLogDecorator(LOG)
+ @pyqtSignature("int")
+ def on_sl_aud_priority_valueChanged(self, idx):
+ """SIGNAL: valueChanged (int)
+ """
+ self._audio_ini.priority = idx
+
+ @signalLogDecorator(LOG)
+ @pyqtSignature("int")
+ def on_cb_aud_eax_stateChanged (self, state):
+ """SIGNAL: stateChanged(int)
+ """
+ self._audio_ini.eax = state
+
+ @signalLogDecorator(LOG)
+ @pyqtSignature("int")
+ def on_cb_aud_mute_stateChanged (self, state):
+ """SIGNAL: stateChanged(int)
+ """
+ self._audio_ini.mute = state
+
+ @signalLogDecorator(LOG)
+ @pyqtSignature("int")
+ def on_cb_aud_voicechat_stateChanged (self, state):
+ """SIGNAL: stateChanged(int)
+ """
+ self._audio_ini.voicechat = state
+
# ************************************************************************
# time zones
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|