# Path: allchat/filestore/encrypt.py
# class Encryptor(object):
#     def __init__(self, key, IV):
#         self.key = key
#         self.IV = IV
#         self.blocksize = 16
# 
#     def EncryptStr(self,content):
#         if sys.version_info.major == 2:
#             content = content.encode("utf-8")
#         elif sys.version_info.major == 3:
#             content = bytes(content,"utf-8")
#         while len(content)%self.blocksize != 0:
#             content += b"\0"
#         obj = AES.new(self.key,AES.MODE_CBC,self.IV)
#         return obj.encrypt(content)
# 
#     def DecryptStr(self,content):
#         obj = AES.new(self.key,AES.MODE_CBC,self.IV)
#         content = obj.decrypt(content).strip(b"\0")
#         return content.decode("utf-8")
# 
# Path: allchat/path.py
# def get_single_msg_dir():
# 	return os.path.join(get_project_root(),"Data","single_messages")
# 
# def get_group_msg_dir():
# 	return os.path.join(get_project_root(),"Data","group_messages")
# 
# def get_picture_dir():
# 	return os.path.join(get_project_root(),"Data","picture")
# 
# def get_project_root():
# 	return os.path.dirname(os.path.dirname(__file__))


import os
import time
import hashlib
from multiprocessing import Process, Queue
from .encrypt import Encryptor
from allchat.path import get_single_msg_dir, get_group_msg_dir, get_picture_dir, get_project_root
            conf.write(b"\n".join((encrypt_key,IV)))

    def _get_config(self):
        root = get_project_root()
        conf_path = os.path.join(root, "conf", "blizzard.conf")
        if not os.path.exists(conf_path):
            self._init_config(conf_path)
        with open(conf_path,"rb") as conf:
            configs = conf.read()
            config_dict = dict(tuple(line.split(b"="))
                               for line in configs.split(b"\n"))
        self._encrypt_key = config_dict.get(b"encrypt_key")
        self._IV = config_dict.get(b"IV")

    def __stop_writing(self):
        if self._single_message_proc:
            self._single_message_queue.put(self._terminator)
            self._single_message_proc.join()
        if self._group_message_proc:
            self._group_message_queue.put(self._terminator)
            self._group_message_proc.join()

    def saveSingleMsg(self, sender, receiver, msg):
        if sender and receiver and isinstance(msg, list) and msg[0] and msg[1]:
            users = "&&".join(sorted([sender,receiver]))
            self._single_message_queue.put((sender,users,msg))
            if not self._single_message_proc:
                self._single_message_proc = Process(target=_write_message, 
                                            args=(
                                                self._single_message_queue,

# Path: allchat/filestore/encrypt.py
# class Encryptor(object):
#     def __init__(self, key, IV):
#         self.key = key
#         self.IV = IV
#         self.blocksize = 16
# 
#     def EncryptStr(self,content):
#         if sys.version_info.major == 2:
#             content = content.encode("utf-8")
#         elif sys.version_info.major == 3:
#             content = bytes(content,"utf-8")
#         while len(content)%self.blocksize != 0:
#             content += b"\0"
#         obj = AES.new(self.key,AES.MODE_CBC,self.IV)
#         return obj.encrypt(content)
# 
#     def DecryptStr(self,content):
#         obj = AES.new(self.key,AES.MODE_CBC,self.IV)
#         content = obj.decrypt(content).strip(b"\0")
#         return content.decode("utf-8")
# 
# Path: allchat/path.py
# def get_single_msg_dir():
# 	return os.path.join(get_project_root(),"Data","single_messages")
# 
# def get_group_msg_dir():
# 	return os.path.join(get_project_root(),"Data","group_messages")
# 
# def get_picture_dir():
# 	return os.path.join(get_project_root(),"Data","picture")
# 
# def get_project_root():
# 	return os.path.dirname(os.path.dirname(__file__))


# Path: allchat/filestore/storage.py
import os
import time
import hashlib
from multiprocessing import Process, Queue
from .encrypt import Encryptor
from allchat.path import get_single_msg_dir, get_group_msg_dir, get_picture_dir, get_project_root

            conf.write(b"\n".join((encrypt_key,IV)))

    def _get_config(self):
        root = get_project_root()
        conf_path = os.path.join(root, "conf", "blizzard.conf")
        if not os.path.exists(conf_path):
            self._init_config(conf_path)
        with open(conf_path,"rb") as conf:
            configs = conf.read()
            config_dict = dict(tuple(line.split(b"="))
                               for line in configs.split(b"\n"))
        self._encrypt_key = config_dict.get(b"encrypt_key")
        self._IV = config_dict.get(b"IV")

    def __stop_writing(self):
        if self._single_message_proc:
            self._single_message_queue.put(self._terminator)
            self._single_message_proc.join()
        if self._group_message_proc:
            self._group_message_queue.put(self._terminator)
            self._group_message_proc.join()

    def saveSingleMsg(self, sender, receiver, msg):
        if sender and receiver and isinstance(msg, list) and msg[0] and msg[1]:
            users = "&&".join(sorted([sender,receiver]))
            self._single_message_queue.put((sender,users,msg))
            if not self._single_message_proc:
                self._single_message_proc = Process(target=_write_message, 
                                            args=(
                                                self._single_message_queue,

                                                self._terminator,