Beispiel #1
0
 def save_profile(self, data):
     inst = ToxEncryptSave.get_instance()
     if inst.has_password():
         data = inst.pass_encrypt(data)
     with open(self._path, 'wb') as fl:
         fl.write(data)
     print('Profile saved successfully')
Beispiel #2
0
 def __init__(self, name):
     Singleton.__init__(self)
     self.path = ProfileHelper.get_path() + str(name) + '.json'
     self.name = name
     if os.path.isfile(self.path):
         with open(self.path, 'rb') as fl:
             data = fl.read()
         inst = ToxEncryptSave.get_instance()
         try:
             if inst.is_data_encrypted(data):
                 data = inst.pass_decrypt(data)
             info = json.loads(str(data, 'utf-8'))
         except Exception as ex:
             info = Settings.get_default_settings()
             log('Parsing settings error: ' + str(ex))
         super(Settings, self).__init__(info)
         self.upgrade()
     else:
         super(Settings, self).__init__(Settings.get_default_settings())
         self.save()
     smileys.SmileyLoader(self)
     self.locked = False
     self.closing = False
     p = pyaudio.PyAudio()
     input_devices = output_devices = 0
     for i in range(p.get_device_count()):
         device = p.get_device_info_by_index(i)
         if device["maxInputChannels"]:
             input_devices += 1
         if device["maxOutputChannels"]:
             output_devices += 1
     self.audio = {'input': p.get_default_input_device_info()['index'] if input_devices else -1,
                   'output': p.get_default_output_device_info()['index'] if output_devices else -1,
                   'enabled': input_devices and output_devices}
Beispiel #3
0
 def __init__(self, name):
     Singleton.__init__(self)
     self.path = ProfileHelper.get_path() + str(name) + '.json'
     self.name = name
     if os.path.isfile(self.path):
         with open(self.path, 'rb') as fl:
             data = fl.read()
         inst = ToxEncryptSave.get_instance()
         try:
             if inst.is_data_encrypted(data):
                 data = inst.pass_decrypt(data)
             info = json.loads(str(data, 'utf-8'))
         except Exception as ex:
             info = Settings.get_default_settings()
             log('Parsing settings error: ' + str(ex))
         super(Settings, self).__init__(info)
         self.upgrade()
     else:
         super(Settings, self).__init__(Settings.get_default_settings())
         self.save()
     smileys.SmileyLoader(self)
     p = pyaudio.PyAudio()
     self.locked = False
     self.audio = {'input': p.get_default_input_device_info()['index'],
                   'output': p.get_default_output_device_info()['index']}
Beispiel #4
0
 def save(self):
     encr = ToxEncryptSave.get_instance()
     if encr.has_password():
         path = settings.ProfileHelper.get_path() + self._name + '.hstr'
         with open(path, 'rb') as fin:
             data = fin.read()
         data = encr.pass_encrypt(bytes(data))
         with open(path, 'wb') as fout:
             fout.write(data)
Beispiel #5
0
 def save(self):
     text = json.dumps(self)
     inst = ToxEncryptSave.get_instance()
     if inst.has_password():
         text = bytes(inst.pass_encrypt(bytes(text, 'utf-8')))
     else:
         text = bytes(text, 'utf-8')
     with open(self.path, 'wb') as fl:
         fl.write(text)
Beispiel #6
0
 def export(self, directory):
     path = settings.ProfileHelper.get_path() + self._name + '.hstr'
     new_path = directory + self._name + '.hstr'
     with open(path, 'rb') as fin:
         data = fin.read()
     encr = ToxEncryptSave.get_instance()
     if encr.has_password():
         data = encr.pass_encrypt(data)
     with open(new_path, 'wb') as fout:
         fout.write(data)
Beispiel #7
0
 def __init__(self, name):
     self._name = name
     chdir(settings.ProfileHelper.get_path())
     path = settings.ProfileHelper.get_path() + self._name + '.hstr'
     if os.path.exists(path):
         decr = ToxEncryptSave.get_instance()
         try:
             with open(path, 'rb') as fin:
                 data = fin.read()
             if decr.is_data_encrypted(data):
                 data = decr.pass_decrypt(data)
                 with open(path, 'wb') as fout:
                     fout.write(data)
         except:
             os.remove(path)
     db = connect(name + '.hstr', timeout=TIMEOUT)
     cursor = db.cursor()
     cursor.execute('CREATE TABLE IF NOT EXISTS friends('
                    '    tox_id TEXT PRIMARY KEY'
                    ')')
     db.close()