<s> from PyQt4 . QtCore import * <EOL> from . protocol . key import * <EOL> from . constants import * <EOL> from struct import * <EOL> import os <EOL> import os . path <EOL> class Config : <EOL> def loadKeys ( self ) : <EOL> try : <EOL> with open ( self . keyFileLocation , '<STR_LIT:rb>' ) as keyFile : <EOL> numKeys = unpack ( '<STR_LIT>' , keyFile . read ( <NUM_LIT:1> ) ) [ <NUM_LIT:0> ] <EOL> for i in range ( numKeys ) : <EOL> k = Key ( ) <EOL> k . loadFromFile ( keyFile ) <EOL> self . keys . append ( k ) <EOL> except FileNotFoundError : <EOL> pass <EOL> def saveKeys ( self ) : <EOL> if not os . path . exists ( KEYS_LOCATION ) : <EOL> os . makedirs ( KEYS_LOCATION ) <EOL> with open ( self . keyFileLocation , '<STR_LIT:wb>' ) as keyFile : <EOL> keyFile . write ( pack ( "<STR_LIT>" , len ( self . keys ) ) ) <EOL> for k in self . keys : <EOL> k . writeToFile ( keyFile ) <EOL> def loadFromQtSettings ( self ) : <EOL> self . settings = QSettings ( ) <EOL> self . firstTime = self . settings . value ( "<STR_LIT>" , '<STR_LIT:True>' ) <EOL> if self . firstTime == '<STR_LIT:False>' : <EOL> self . keyFileLocation = self . settings . value ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if self . keyFileLocation != "<STR_LIT>" : <EOL> self . loadKeys ( ) <EOL> self . geometry = self . settings . value ( "<STR_LIT>" , None ) <EOL> else : <EOL> self . geometry = None <EOL> if self . geometry is None : <EOL> self . geometry = QRect ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . port = int ( self . settings . value ( "<STR_LIT>" , DEFAULT_PORT_NUMBER ) ) <EOL> def saveToQtSettings ( self ) : <EOL> self . settings . setValue ( "<STR_LIT>" , self . geometry ) <EOL> self . settings . setValue ( "<STR_LIT>" , '<STR_LIT:False>' ) <EOL> self . settings . setValue ( "<STR_LIT>" , KEYS_FILE ) <EOL> self . settings . setValue ( "<STR_LIT>" , self . port ) <EOL> self . saveKeys ( ) <EOL> def __init__ ( self ) : <EOL> self . keys = [ ] <EOL> self . keyFileLocation = KEYS_FILE </s>
