-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSandboxie.py
More file actions
62 lines (50 loc) · 2.22 KB
/
Sandboxie.py
File metadata and controls
62 lines (50 loc) · 2.22 KB
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
56
57
58
59
60
61
62
import Config, subprocess, shutil, os, codecs, time, shlex
from PyQt4 import QtCore, QtGui
sandboxfile = r'C:\Windows\Sandboxie.ini'
backupfile = r'C:\Windows\Sandboxie_backup.ini'
class SandboxieThread(QtCore.QThread):
def __init__(self, parent=None):
QtCore.QThread.__init__(self, parent)
self.settings = Config.settings
self.delay = int(self.settings.get_option('Settings', 'launch_delay_time'))
self.createdSandboxes = []
def addSandbox(self, sandboxname):
if sandboxname in self.createdSandboxes:
pass
else:
steam_location = self.settings.get_option('Settings', 'steam_location')
sandboxielocation = self.settings.get_option('Settings', 'sandboxie_location')
config = codecs.open(sandboxfile, 'rb', 'UTF-16LE').read()
sandboxstring = u"""\r\n[%s]\r\n""" % sandboxname
sandboxstring += u"""\r\nEnabled=y"""
sandboxstring += u"""\r\nConfigLevel=6"""
sandboxstring += u"""\r\nAutoRecover=y"""
sandboxstring += u"""\r\nAutoDelete=yes"""
sandboxstring += u"""\r\nTemplate=LingerPrograms"""
sandboxstring += u"""\r\nTemplate=AutoRecoverIgnore"""
sandboxstring += u"""\r\nRecoverFolder=%Personal%"""
sandboxstring += u"""\r\nRecoverFolder=%Favorites%"""
sandboxstring += u"""\r\nRecoverFolder=%Desktop%"""
sandboxstring += u"""\r\nOpenFilePath=%s""" % steam_location + os.sep
sandboxstring += u"""\r\nOpenFilePath=%s""" % steam_location + os.sep + 'Steam.exe'
f = codecs.open(sandboxfile, 'wb', 'UTF-16LE')
f.write(config + sandboxstring)
f.close()
self.createdSandboxes.append(sandboxname)
subprocess.call([sandboxielocation + os.sep + 'start.exe', '/reload'])
def addCommands(self, commands):
self.commands = commands
def run(self):
self.runCommands()
def runCommands(self):
for command in self.commands:
# Split command string into space delimited list of arguments.
# I use the shlex module here because it avoids splitting double quoted arugments with spaces inside them
commands_list = shlex.split(command)
subprocess.call(commands_list)
if self.commands.index(command)+1 != len(self.commands):
time.sleep(self.delay)
def backupSandboxieINI():
shutil.copy(sandboxfile, backupfile)
def restoreSandboxieINI():
shutil.copy(backupfile, sandboxfile)