Beispiel #1
0
def get_filepath_by_message_index(message_index):
    if not ProxyConfig.get_replay_directory():
        return None
    glob_string = "{}/{}-*.bin".format(ProxyConfig.get_replay_directory(),
                                       str(message_index).zfill(4))
    matches = glob.glob(glob_string)
    if len(matches) == 1:
        return matches[0]
    return None
Beispiel #2
0
 def save_message_index():
     if not ProxyConfig.get_replay_directory():
         return
     if not os.path.exists(ProxyConfig.get_replay_directory()):
         return
     target = open(
         "{}/{}".format(ProxyConfig.get_replay_directory(),
                        Replay.message_index_file), 'w')
     target.write(str(Replay.message_index))
     target.close()
Beispiel #3
0
 def read_message_index():
     if not ProxyConfig.get_replay_directory():
         return
     Replay.message_index_filepath = "{}/{}".format(
         ProxyConfig.get_replay_directory(), Replay.message_index_file)
     if not os.path.exists(Replay.message_index_filepath):
         return
     with open(Replay.message_index_filepath, 'r') as fh:
         index = fh.read()
         Replay.message_index = int(index)
Beispiel #4
0
    def read(message_index):
        if not ProxyConfig.get_replay_directory():
            return
        glob_string = "{}/{}-*".format(ProxyConfig.get_replay_directory(),
                                       str(Replay.message_index).zfill(4))
        files = glob(glob_string)
        if len(files) != 1:
            return

        file_path = files[0]
        with open(file_path, 'rb') as fh:
            message = fh.read()
        return message
Beispiel #5
0
    def save(messageid, version, payload):
        if not ProxyConfig.get_replay_directory():
            return
        if not os.path.exists(ProxyConfig.get_replay_directory()):
            os.makedirs(ProxyConfig.get_replay_directory())

        target = open(
            "{}/{}-{}.{}".format(ProxyConfig.get_replay_directory(),
                                 str(Replay.get_next_message_index()).zfill(4),
                                 str(messageid), "bin"), "wb")
        target.write(messageid.to_bytes(2, byteorder="big"))
        target.write(len(payload).to_bytes(3, byteorder="big"))
        target.write(version.to_bytes(2, byteorder="big"))
        target.write(payload)
        target.close()
        Replay.save_message_index()
Beispiel #6
0
 def start():
     if ProxyConfig.get_replay_directory() and not os.path.exists(
             ProxyConfig.get_replay_directory()):
         os.makedirs(ProxyConfig.get_replay_directory())
     Replay.read_message_index()