mirror of
https://github.com/lutris/lutris
synced 2024-10-14 11:42:36 +00:00
Handle registry timestamps as ints or floats
This commit is contained in:
parent
c01f2c9ccc
commit
63347be383
|
@ -113,16 +113,21 @@ class WineRegistry(object):
|
||||||
|
|
||||||
class WineRegistryKey(object):
|
class WineRegistryKey(object):
|
||||||
def __init__(self, key_def):
|
def __init__(self, key_def):
|
||||||
key, timestamp = key_def.strip().rsplit(' ', 1)
|
self.raw_name = key_def[:key_def.index(']') + 1]
|
||||||
self.timestamp = int(timestamp)
|
self.raw_timestamp = key_def[key_def.index(']') + 1:]
|
||||||
|
ts_parts = self.raw_timestamp.strip().split()
|
||||||
|
if len(ts_parts) == 1:
|
||||||
|
self.timestamp = int(ts_parts[0])
|
||||||
|
else:
|
||||||
|
self.timestamp = float("{}.{}".format(ts_parts[0], ts_parts[1]))
|
||||||
self.values = {}
|
self.values = {}
|
||||||
self.name = key.replace('\\\\', '/').strip("[]")
|
self.name = self.raw_name.replace('\\\\', '/').strip("[]")
|
||||||
|
|
||||||
def set_key(self, name, value):
|
def set_key(self, name, value):
|
||||||
self.values[name.strip("\"")] = value.strip()
|
self.values[name.strip("\"")] = value.strip()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "[{0}] {1}".format(self.winname, self.timestamp)
|
return "{0} {1}".format(self.raw_name, self.raw_timestamp)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def winname(self):
|
def winname(self):
|
||||||
|
|
4
tests/fixtures/user.reg
vendored
4
tests/fixtures/user.reg
vendored
|
@ -130,8 +130,8 @@ WINE REGISTRY Version 2
|
||||||
"SnapToDefaultButton"="0"
|
"SnapToDefaultButton"="0"
|
||||||
"SwapMouseButtons"="0"
|
"SwapMouseButtons"="0"
|
||||||
|
|
||||||
[Control Panel\\Sound] 1477412318
|
[Control Panel\\Sound] 1475423303 7943190
|
||||||
#time=1d22edb718040d6
|
#time=1d21cc468677196
|
||||||
"Beep"="Yes"
|
"Beep"="Yes"
|
||||||
|
|
||||||
[Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders] 1477412318
|
[Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders] 1477412318
|
||||||
|
|
|
@ -20,3 +20,7 @@ class TestWineRegistry(TestCase):
|
||||||
def test_can_get_timestamp_as_int(self):
|
def test_can_get_timestamp_as_int(self):
|
||||||
key = self.registry.get_key('Control Panel/Keyboard')
|
key = self.registry.get_key('Control Panel/Keyboard')
|
||||||
self.assertEqual(key.timestamp, 1477412318)
|
self.assertEqual(key.timestamp, 1477412318)
|
||||||
|
|
||||||
|
def test_can_get_timestamp_as_float(self):
|
||||||
|
key = self.registry.get_key('Control Panel/Sound')
|
||||||
|
self.assertEqual(key.timestamp, 1475423303.7943190)
|
||||||
|
|
Loading…
Reference in a new issue