Advertisement
Guest User

tf2idle defrag

a guest
Nov 3rd, 2012
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 23.21 KB | None | 0 0
  1. import Config, subprocess, webbrowser, shutil, os, ctypes
  2. from PyQt4 import QtCore, QtGui
  3. from sets import Set
  4.  
  5. import Sandboxie
  6. from AccountDialog import AccountDialogWindow
  7. from GroupsDialog import GroupsDialogWindow
  8. from Common import returnResourcePath
  9. from Common import curry
  10.  
  11. class Worker(QtCore.QThread):
  12.     def __init__(self, parent = None):
  13.         QtCore.QThread.__init__(self, parent)
  14.  
  15.     def run(self):
  16.         self.settings = Config.settings
  17.         steam_location = self.settings.get_option('Settings', 'steam_location')
  18.         secondary_steamapps_location = self.settings.get_option('Settings', 'secondary_steamapps_location')
  19.         gcfs = ['team fortress 2 client content.gcf', 'team fortress 2 content.gcf', 'team fortress 2 materials.gcf']
  20.  
  21.         if not os.path.exists(steam_location + os.sep + 'steamapps' + os.sep):
  22.             self.returnMessage('Path does not exist', 'The Steam folder path does not exist. Please check settings')
  23.         elif not os.path.exists(secondary_steamapps_location):
  24.             self.returnMessage('Path does not exist', 'The secondary Steam folder path does not exist. Please check settings')
  25.         else:
  26.             self.emit(QtCore.SIGNAL('StartedCopyingGCFs'))
  27.             try:
  28.                 percentage = 0
  29.                 for file in gcfs:
  30.                     shutil.copy(steam_location + os.sep + 'steamapps' + os.sep + file, secondary_steamapps_location)
  31.                     percentage += 33
  32.                     self.emit(QtCore.SIGNAL('CopyingGCFsPercentage'), percentage)
  33.             except:
  34.                 self.returnMessage('File copy error', 'The GCFs could not be copied')
  35.             self.emit(QtCore.SIGNAL('FinishedCopyingGCFs'))
  36.             self.returnMessage('Info', 'Finished updating GCFs. Remember to start the backup Steam installation unsandboxed to finish the update process')
  37.        
  38.     def returnMessage(self, title, message):
  39.         self.emit(QtCore.SIGNAL('returnMessage'), title, message)
  40.  
  41. class AccountsView(QtGui.QWidget):
  42.     def __init__(self, mainwindow):
  43.         QtGui.QWidget.__init__(self)
  44.         self.mainwindow = mainwindow
  45.         self.settings = Config.settings
  46.         self.toolBars = []
  47.         self.accountButtons = []
  48.         self.chosenGroupAccounts = []
  49.         self.createdSandboxes = []
  50.         self.sandboxieINIIsModified = False
  51.         self.copyingGCFs = False
  52.         self.percentage = 0
  53.  
  54.         self.updateWindow(construct = True)
  55.  
  56.     def updateWindow(self, construct=False):
  57.         self.mainwindow.htoolBar.clear()
  58.         self.mainwindow.vtoolBar.clear()
  59.        
  60.         # Add vertical toolbar actions 
  61.  
  62.         addAccountIcon = QtGui.QIcon()
  63.         addAccountIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/add_account.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  64.         self.addAccountAction = self.mainwindow.vtoolBar.addAction(addAccountIcon, 'Add account')
  65.         QtCore.QObject.connect(self.addAccountAction, QtCore.SIGNAL('triggered()'), self.openAccountDialog)
  66.        
  67.         editAccountIcon = QtGui.QIcon()
  68.         editAccountIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/edit_account.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  69.         self.editAccountAction = self.mainwindow.vtoolBar.addAction(editAccountIcon, 'Edit account')
  70.         QtCore.QObject.connect(self.editAccountAction, QtCore.SIGNAL('triggered()'), curry(self.openAccountDialog, editAccount=True))
  71.        
  72.         removeAccountIcon = QtGui.QIcon()
  73.         removeAccountIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/remove_account.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  74.         self.deleteAccountsAction = self.mainwindow.vtoolBar.addAction(removeAccountIcon, 'Delete account')
  75.         QtCore.QObject.connect(self.deleteAccountsAction, QtCore.SIGNAL('triggered()'), self.deleteAccounts)
  76.        
  77.         self.mainwindow.vtoolBar.addSeparator()
  78.        
  79.         selectGroupIcon = QtGui.QIcon()
  80.         selectGroupIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/select_group.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  81.         self.selectGroupsAction = self.mainwindow.vtoolBar.addAction(selectGroupIcon, 'Select Groups')
  82.         QtCore.QObject.connect(self.selectGroupsAction, QtCore.SIGNAL('triggered()'), self.selectGroups)
  83.        
  84.         viewBackpackIcon = QtGui.QIcon()
  85.         viewBackpackIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/backpack.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  86.         self.viewBackpackAction = self.mainwindow.vtoolBar.addAction(viewBackpackIcon, 'View backpack')
  87.         QtCore.QObject.connect(self.viewBackpackAction, QtCore.SIGNAL('triggered()'), self.openBackpack)
  88.        
  89.         # Add horizontal toolbar actions
  90.         switchToLogViewIcon = QtGui.QIcon()
  91.         switchToLogViewIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/arrow_right.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  92.         self.switchToLogViewAction = self.mainwindow.htoolBar.addAction(switchToLogViewIcon, 'Drop log view')
  93.         QtCore.QObject.connect(self.switchToLogViewAction, QtCore.SIGNAL('triggered()'), self.changeMainWindowView)
  94.        
  95.         self.mainwindow.htoolBar.addSeparator()
  96.        
  97.         startIdleIcon = QtGui.QIcon()
  98.         startIdleIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/start_idle.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  99.         self.startIdleAction = self.mainwindow.htoolBar.addAction(startIdleIcon, 'Start idling')
  100.         QtCore.QObject.connect(self.startIdleAction, QtCore.SIGNAL('triggered()'), curry(self.startUpAccounts, action='idle'))
  101.        
  102.         startIdleUnsandboxedIcon = QtGui.QIcon()
  103.         startIdleUnsandboxedIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/start_idle_unsandboxed.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  104.         self.startIdleUnsandboxedAction = self.mainwindow.htoolBar.addAction(startIdleUnsandboxedIcon, 'Idle unsandboxed')
  105.         QtCore.QObject.connect(self.startIdleUnsandboxedAction, QtCore.SIGNAL('triggered()'), curry(self.startUpAccounts, action='idle_unsandboxed'))
  106.        
  107.         startTF2Icon = QtGui.QIcon()
  108.         startTF2Icon.addPixmap(QtGui.QPixmap(returnResourcePath('images/start_tf2.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  109.         self.startTF2Action = self.mainwindow.htoolBar.addAction(startTF2Icon, 'Start TF2')
  110.         QtCore.QObject.connect(self.startTF2Action, QtCore.SIGNAL('triggered()'), curry(self.startUpAccounts, action='start_TF2'))
  111.        
  112.         startSteamIcon = QtGui.QIcon()
  113.         startSteamIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/start_steam.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  114.         self.startSteamAction = self.mainwindow.htoolBar.addAction(startSteamIcon, 'Start Steam')
  115.         QtCore.QObject.connect(self.startSteamAction, QtCore.SIGNAL('triggered()'), curry(self.startUpAccounts, action='start_steam'))
  116.        
  117.         startProgramIcon = QtGui.QIcon()
  118.         startProgramIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/start_program.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  119.         self.startProgramAction = self.mainwindow.htoolBar.addAction(startProgramIcon, 'Start Program')
  120.         QtCore.QObject.connect(self.startProgramAction, QtCore.SIGNAL('triggered()'), self.startProgram)
  121.        
  122.         self.mainwindow.htoolBar.addSeparator()
  123.        
  124.         terminateSandboxIcon = QtGui.QIcon()
  125.         terminateSandboxIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/terminate.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  126.         self.terminateSandboxAction = self.mainwindow.htoolBar.addAction(terminateSandboxIcon, 'Terminate sandbox')
  127.         QtCore.QObject.connect(self.terminateSandboxAction, QtCore.SIGNAL('triggered()'), curry(self.modifySandboxes, action='/terminate'))
  128.        
  129.         emptySandboxIcon = QtGui.QIcon()
  130.         emptySandboxIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/delete_sandbox.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  131.         self.emptySandboxAction = self.mainwindow.htoolBar.addAction(emptySandboxIcon, 'Empty sandbox')
  132.         QtCore.QObject.connect(self.emptySandboxAction, QtCore.SIGNAL('triggered()'), curry(self.modifySandboxes, action='delete_sandbox_silent'))
  133.  
  134.         self.mainwindow.htoolBar.addSeparator()
  135.        
  136.         startDefragIcon = QtGui.QIcon()
  137.         startDefragIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/defrag.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  138.         self.startDefragAction = self.mainwindow.htoolBar.addAction(startDefragIcon, 'Defrag Accounts')
  139.         QtCore.QObject.connect(self.startDefragAction, QtCore.SIGNAL('triggered()'), curry(self.startUpAccounts, action='start_Defrag'))
  140.        
  141.         self.mainwindow.htoolBar.addSeparator()
  142.  
  143.         updateGCFsIcon = QtGui.QIcon()
  144.         if self.copyingGCFs:
  145.             progressimage = returnResourcePath('images/updating_gcfs_%spercent.png' % self.percentage)
  146.             updateGCFsIcon.addPixmap(QtGui.QPixmap(progressimage), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  147.             self.updateGCFsAction = self.mainwindow.htoolBar.addAction(updateGCFsIcon, 'Updating GCFs')
  148.         else:
  149.             updateGCFsIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/update_gcfs.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
  150.             self.updateGCFsAction = self.mainwindow.htoolBar.addAction(updateGCFsIcon, 'Update GCFs')
  151.             QtCore.QObject.connect(self.updateGCFsAction, QtCore.SIGNAL('triggered()'), self.updateGCFs)
  152.  
  153.         if construct:
  154.             self.gridLayout = QtGui.QGridLayout(self)
  155.             self.gridLayout.setMargin(0)
  156.            
  157.             self.verticalLayout = QtGui.QVBoxLayout()
  158.             self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
  159.            
  160.             # Add keyboard shortcut to select all account boxes
  161.             QtGui.QShortcut(QtGui.QKeySequence('Ctrl+A'), self.mainwindow, self.SelectAllAccounts)
  162.  
  163.             QtCore.QMetaObject.connectSlotsByName(self)
  164.  
  165.         self.updateAccountBoxes()
  166.  
  167.     def changeMainWindowView(self):
  168.         self.mainwindow.changeView('log')
  169.  
  170.     def updateAccountBoxes(self):
  171.         # Get selected accounts and remove all account boxes
  172.         checkedbuttons = []
  173.         for widget in self.accountButtons:
  174.             if widget.isChecked():
  175.                 checkedbuttons.append(str(widget.text()))
  176.             widget.close()
  177.             del widget
  178.  
  179.         self.accountButtons = []
  180.         row = 0
  181.         column = 0
  182.         numperrow = int(self.settings.get_option('Settings', 'ui_no_of_columns'))
  183.         ui_account_box_font_size = self.settings.get_option('Settings', 'ui_account_box_font_size')
  184.         ui_account_box_icon_size = int(self.settings.get_option('Settings', 'ui_account_box_icon_size'))
  185.         ui_account_box_icon = self.settings.get_option('Settings', 'ui_account_box_icon')
  186.  
  187.         # Sort account boxes alphabetically
  188.         sortedlist = []
  189.         for account in list(Set(self.settings.get_sections()) - Set(['Settings'])):
  190.             if self.settings.get_option(account, 'account_nickname') != '':
  191.                 sortedlist.append((self.settings.get_option(account, 'account_nickname'), account))
  192.             else:
  193.                 sortedlist.append((self.settings.get_option(account, 'steam_username'), account))
  194.  
  195.         for account in sorted(sortedlist):
  196.             accountname = account[0]
  197.             commandLinkButton = QtGui.QCommandLinkButton(self)
  198.             commandLinkButton.setObjectName(self.settings.get_option(account[1], 'steam_username'))
  199.             icon = QtGui.QIcon()
  200.             if ui_account_box_icon != '':
  201.                 icon.addPixmap(QtGui.QPixmap(ui_account_box_icon))
  202.             else:
  203.                 icon.addPixmap(QtGui.QPixmap(returnResourcePath('images/unselected_button.png')), QtGui.QIcon.Selected, QtGui.QIcon.Off)
  204.                 icon.addPixmap(QtGui.QPixmap(returnResourcePath('images/selected_button.png')), QtGui.QIcon.Selected, QtGui.QIcon.On)
  205.             commandLinkButton.setIcon(icon)
  206.             commandLinkButton.setIconSize(QtCore.QSize(ui_account_box_icon_size, ui_account_box_icon_size))
  207.             commandLinkButton.setCheckable(True)
  208.             commandLinkButton.setChecked(accountname in checkedbuttons or self.settings.get_option(account[1], 'steam_username') in self.chosenGroupAccounts)
  209.             commandLinkButton.setStyleSheet('font: %spt "TF2 Build";' % ui_account_box_font_size)
  210.             commandLinkButton.setText(accountname)
  211.             self.accountButtons.append(commandLinkButton)
  212.             self.gridLayout.addWidget(commandLinkButton, row, column, 1, 1)
  213.             column += 1
  214.             if column == numperrow:
  215.                 row += 1
  216.                 column = 0
  217.  
  218.     def mousePressEvent(self, event):
  219.         button = event.button()
  220.         # Uncheck all account boxes on mouse right click
  221.         if button == 2:
  222.             for account in self.accountButtons:
  223.                 account.setChecked(False)
  224.    
  225.     def SelectAllAccounts(self):
  226.         for account in self.accountButtons:
  227.             account.setChecked(True)
  228.    
  229.     def returnSelectedAccounts(self):
  230.         selectedList = []
  231.         for account in self.accountButtons:
  232.             if account.isChecked():
  233.                 selectedList.append(str(account.objectName()))
  234.         self.emit(QtCore.SIGNAL('returnedSelectedAccounts(PyQt_PyObject)'), selectedList)
  235.    
  236.     def openAccountDialog(self, editAccount=False):
  237.         if editAccount:
  238.             checkedbuttons = []
  239.             for widget in self.accountButtons:
  240.                 if widget.isChecked():
  241.                     checkedbuttons.append('Account-' + str(widget.objectName()))
  242.             if len(checkedbuttons) == 0:
  243.                 QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to edit')
  244.             else:
  245.                 dialogWindow = AccountDialogWindow(accounts=checkedbuttons)
  246.                 dialogWindow.setModal(True)
  247.                 dialogWindow.exec_()
  248.                 self.updateAccountBoxes()
  249.         else:
  250.             dialogWindow = AccountDialogWindow()
  251.             dialogWindow.setModal(True)
  252.             dialogWindow.exec_()
  253.             self.updateAccountBoxes()
  254.  
  255.     def deleteAccounts(self):
  256.         checkedbuttons = []
  257.         for widget in self.accountButtons:
  258.             if widget.isChecked():
  259.                 checkedbuttons.append(str(widget.objectName()))
  260.         if len(checkedbuttons) == 0:
  261.             QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to delete')
  262.         else:
  263.             reply = QtGui.QMessageBox.warning(self, 'Warning', 'Are you sure to want to delete these accounts?', QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
  264.             if reply == QtGui.QMessageBox.Yes:
  265.                 for account in checkedbuttons:
  266.                     self.settings.remove_section('Account-' + account)
  267.                 self.updateAccountBoxes()
  268.    
  269.     def selectGroups(self):
  270.         dialogWindow = GroupsDialogWindow()
  271.         dialogWindow.setModal(True)
  272.         dialogWindow.exec_()
  273.         self.chosenGroupAccounts = dialogWindow.returnAccounts()
  274.         self.updateAccountBoxes()
  275.         # Remove group accounts from selection after updating window
  276.         self.chosenGroupAccounts = []
  277.    
  278.     def startUpAccounts(self, action):
  279.         easy_sandbox_mode = self.settings.get_option('Settings', 'easy_sandbox_mode')
  280.         self.commands = []
  281.  
  282.         # Get selected accounts
  283.         checkedbuttons = []
  284.         for widget in self.accountButtons:
  285.             if widget.isChecked():
  286.                 checkedbuttons.append(str(widget.objectName()))
  287.  
  288.         # Error dialogs if no accounts selected
  289.         if len(checkedbuttons) == 0:
  290.             if action == 'idle':
  291.                 QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to idle')
  292.             elif action == 'idle_unsandboxed':
  293.                 QtGui.QMessageBox.information(self, 'No account selected', 'Please select an account to idle')
  294.             elif action == 'start_steam':
  295.                 QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to start Steam with')
  296.             elif action == 'start_TF2':
  297.                 QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to start TF2 with')
  298.  
  299.         # Error dialog if > 1 accounts selected and trying to run them all unsandboxed
  300.         elif action == 'idle_unsandboxed' and len(checkedbuttons) > 1:
  301.             QtGui.QMessageBox.information(self, 'Too many accounts selected', 'Please select one account to idle')
  302.         # Error dialog if easy sandbox mode is on and program isn't run with elevated privileges
  303.         elif easy_sandbox_mode == 'yes' and action != 'idle_unsandboxed' and not self.runAsAdmin():
  304.             QtGui.QMessageBox.information(self, 'Easy sandbox mode requires admin', 'TF2Idle requires admin privileges to create/modify sandboxes. Please run the program as admin.')
  305.         else:
  306.             steamlocation = self.settings.get_option('Settings', 'steam_location')
  307.             secondary_steamapps_location = self.settings.get_option('Settings', 'secondary_steamapps_location')
  308.             sandboxielocation = self.settings.get_option('Settings', 'sandboxie_location')
  309.  
  310.             for account in checkedbuttons:
  311.                 username = self.settings.get_option('Account-' + account, 'steam_username')
  312.                 password = self.settings.get_option('Account-' + account, 'steam_password')
  313.                 sandboxname = self.settings.get_option('Account-' + account, 'sandbox_name')
  314.                 if self.settings.get_option('Account-' + account, 'sandbox_install') == '' and easy_sandbox_mode == 'yes':
  315.                     sandbox_install = secondary_steamapps_location
  316.                 else:
  317.                     sandbox_install = self.settings.get_option('Account-' + account, 'sandbox_install')
  318.                 # Check if account has launch parameters that override main parameters
  319.                 if self.settings.has_option('Account-' + account, 'launch_options') and self.settings.get_option('Account-' + account, 'launch_options') != '':
  320.                     steamlaunchcommand = self.settings.get_option('Account-' + account, 'launch_options')
  321.                 else:
  322.                     steamlaunchcommand = self.settings.get_option('Settings', 'launch_options')
  323.  
  324.                 if not self.sandboxieINIIsModified and easy_sandbox_mode == 'yes':
  325.                     Sandboxie.backupSandboxieINI()
  326.                     self.mainwindow.sandboxieINIHasBeenModified()
  327.                    
  328.                 if action == 'start_Defrag':
  329.                     command = r'"%s/Steam.exe" -login %s %s' % (sandbox_install, username, password)
  330.                     if easy_sandbox_mode == 'yes' and self.settings.get_option('Account-' + account, 'sandbox_install') == '':
  331.                         self.commandthread.addSandbox('TF2Idle' + username)
  332.                         self.createdSandboxes.append(username)
  333.                         command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, 'TF2Idle' + username, command)
  334.                     else:
  335.                         command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, sandboxname, command)
  336.                     #Right here add script to launch steam://defrag/440
  337.  
  338.                 if action == 'idle':
  339.                     command = r'"%s/Steam.exe" -login %s %s -applaunch 440 %s' % (sandbox_install, username, password, steamlaunchcommand)
  340.                     if easy_sandbox_mode == 'yes' and self.settings.get_option('Account-' + account, 'sandbox_install') == '':
  341.                         self.commandthread.addSandbox('TF2Idle' + username)
  342.                         self.createdSandboxes.append(username)
  343.                         command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, 'TF2Idle' + username, command)
  344.                     else:
  345.                         command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, sandboxname, command)
  346.  
  347.                 elif action == 'idle_unsandboxed':
  348.                     command = r'"%s/Steam.exe" -login %s %s -applaunch 440 %s' % (steamlocation, username, password, steamlaunchcommand)
  349.  
  350.                 elif action == 'start_steam':
  351.                     command = r'"%s/Steam.exe" -login %s %s' % (sandbox_install, username, password)
  352.                     if easy_sandbox_mode == 'yes' and self.settings.get_option('Account-' + account, 'sandbox_install') == '':
  353.                         self.commandthread.addSandbox('TF2Idle' + username)
  354.                         self.createdSandboxes.append(username)
  355.                         command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, 'TF2Idle' + username, command)
  356.                     else:
  357.                         command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, sandboxname, command)
  358.  
  359.                 elif action == 'start_TF2':
  360.                     command = r'"%s/Steam.exe" -login %s %s -applaunch 440' % (sandbox_install, username, password)
  361.                     if easy_sandbox_mode == 'yes' and self.settings.get_option('Account-' + account, 'sandbox_install') == '':
  362.                         self.commandthread.addSandbox('TF2Idle' + username)
  363.                         self.createdSandboxes.append(username)
  364.                         command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, 'TF2Idle' + username, command)
  365.                     else:
  366.                         command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, sandboxname, command)
  367.  
  368.                 self.commands.append(command)
  369.             self.commandthread = Sandboxie.SandboxieThread()
  370.             self.commandthread.addCommands(self.commands)
  371.             self.commandthread.start()
  372.    
  373.     def openBackpack(self):
  374.         # Get selected accounts
  375.         checkedbuttons = []
  376.         for widget in self.accountButtons:
  377.             if widget.isChecked():
  378.                 checkedbuttons.append(str(widget.objectName()))
  379.  
  380.         # Error dialog if no accounts selected
  381.         if len(checkedbuttons) == 0:
  382.             QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to view backpack')
  383.         else:
  384.             backpack_viewer = self.settings.get_option('Settings', 'backpack_viewer')
  385.             if backpack_viewer == 'Backpack.tf':
  386.                 url = 'http://backpack.tf/id/%(ID)s'
  387.             elif backpack_viewer == 'OPTF2':
  388.                 url = 'http://optf2.com/tf2/user/%(ID)s'
  389.             elif backpack_viewer == 'Steam':
  390.                 url = 'http://steamcommunity.com/id/%(ID)s/inventory'
  391.             elif backpack_viewer == 'TF2B':
  392.                 url = 'http://tf2b.com/tf2/%(ID)s'
  393.             elif backpack_viewer == 'TF2Items':
  394.                 url = 'http://www.tf2items.com/id/%(ID)s'
  395.             for account in checkedbuttons:
  396.                 webbrowser.open(url % {'ID': self.settings.get_option('Account-' + account, 'steam_vanityid')})
  397.    
  398.     def modifySandboxes(self, action):
  399.         # Get selected accounts
  400.         checkedbuttons = []
  401.         for widget in self.accountButtons:
  402.             if widget.isChecked():
  403.                 checkedbuttons.append(str(widget.objectName()))
  404.  
  405.         # Error dialog if no accounts selected
  406.         if len(checkedbuttons) == 0:
  407.             if action == '/terminate':
  408.                 QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to terminate its sandbox')
  409.             else:
  410.                 QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to delete its sandbox contents')
  411.         else:
  412.             sandboxie_location = self.settings.get_option('Settings', 'sandboxie_location')
  413.             for account in checkedbuttons:
  414.                 if account in self.createdSandboxes:
  415.                     command = r'"%s/Start.exe" /box:%s %s' % (sandboxie_location, 'TF2Idle' + account, action)
  416.                     returnCode = subprocess.call(command)
  417.                     self.createdSandboxes.remove(account)
  418.                 elif self.settings.get_option('Account-' + account, 'sandbox_name') != '':
  419.                     command = r'"%s/Start.exe" /box:%s %s' % (sandboxie_location, self.settings.get_option('Account-' + account, 'sandbox_name'), action)
  420.                     returnCode = subprocess.call(command)
  421.  
  422.     def startProgram(self):
  423.         # Get selected accounts
  424.         checkedbuttons = []
  425.         for widget in self.accountButtons:
  426.             if widget.isChecked():
  427.                 checkedbuttons.append(str(widget.objectName()))
  428.  
  429.         # Error dialog if no accounts selected
  430.         if len(checkedbuttons) == 0:
  431.             QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account sandbox to launch a program in')
  432.         else:
  433.             program = QtGui.QFileDialog.getOpenFileName(self, 'Choose program to launch sandboxed', filter = 'Programs (*.exe *.bat *.msi *.jar)')
  434.             if program:
  435.                 sandboxie_location = self.settings.get_option('Settings', 'sandboxie_location')
  436.                 for account in checkedbuttons:
  437.                     if account in self.createdSandboxes:
  438.                         accountname = 'TF2Idle' + account
  439.                     elif self.settings.get_option('Account-' + account, 'sandbox_name') != '':
  440.                         accountname = self.settings.get_option('Account-' + account, 'sandbox_name')
  441.                     command = r'"%s/Start.exe" /box:%s %s' % (sandboxie_location, self.settings.get_option('Account-' + account, 'sandbox_name'), program)
  442.                     returnCode = subprocess.call(command)
  443.  
  444.     def updateGCFs(self):
  445.         def Dialog(title, message):
  446.             QtGui.QMessageBox.information(self, title, message)
  447.  
  448.         self.thread = Worker()
  449.         QtCore.QObject.connect(self.thread, QtCore.SIGNAL('returnMessage'), Dialog)
  450.         QtCore.QObject.connect(self.thread, QtCore.SIGNAL('StartedCopyingGCFs'), curry(self.changeGCFLockState, lock=True))
  451.         QtCore.QObject.connect(self.thread, QtCore.SIGNAL('CopyingGCFsPercentage'), self.changeGCFPercentage)
  452.         QtCore.QObject.connect(self.thread, QtCore.SIGNAL('FinishedCopyingGCFs'), curry(self.changeGCFLockState, lock=False))
  453.         self.thread.start()
  454.  
  455.     def changeGCFLockState(self, lock):
  456.         if lock:
  457.             self.copyingGCFs = True
  458.         else:
  459.             self.copyingGCFs = False
  460.         self.updateWindow()
  461.  
  462.     def changeGCFPercentage(self, percentage):
  463.         self.percentage = percentage
  464.         self.updateWindow()
  465.  
  466.     def runAsAdmin(self):
  467.         try:
  468.             is_admin = os.getuid() == 0
  469.         except AttributeError:
  470.             is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
  471.         return is_admin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement