~thestr4ng3r/mymcplus

d9e46f00b33c036353e64f9083b80c3fdd54f745 — Florian Märkl 3 years ago 7f7245a
Add Importing PS1 PSV with Test
2 files changed, 33 insertions(+), 2 deletions(-)

M mymcplus/save/format_psv.py
M test/test_memorycard.py
M mymcplus/save/format_psv.py => mymcplus/save/format_psv.py +13 -2
@@ 34,6 34,8 @@ _ps2_header_struct = struct.Struct("<IIIIIIIIII")
_ps2_file_info_struct = struct.Struct("<8s8sII32s")
_ps2_file_offset_struct = struct.Struct("<I")

_ps1_header_struct = struct.Struct("<II20xI4x20s12x")


class PS2FileInfo:
    def __init__(self, d):


@@ 86,9 88,18 @@ def load_ps2(save, f):
        save.set_file(i, file_info.dirent(0), utils.read_fixed(f, file_info.size))



def load_ps1(save, f):
    raise NotImplementedError()
    (save_size, save_offset, _, prod_code) = utils.read_struct(f, _ps1_header_struct)

    dir_mode = ps2mc_dir.DF_RWX | ps2mc_dir.DF_DIR | ps2mc_dir.DF_PSX | ps2mc_dir.DF_EXISTS
    created = modified = ps2mc_dir.tod_now()
    save.set_directory((dir_mode, 0, 1, created, 0, 0, modified, 0, prod_code))

    mode = ps2mc_dir.DF_RWX | ps2mc_dir.DF_FILE \
           | ps2mc_dir.DF_0080 | ps2mc_dir.DF_0400 | ps2mc_dir.DF_EXISTS
    f.seek(save_offset)
    save.set_file(0, (mode, 0, 0, created, 0, 0, modified, 0, prod_code),
                  utils.read_fixed(f, save_size))


def load(save, f):

M test/test_memorycard.py => test/test_memorycard.py +20 -0
@@ 401,3 401,23 @@ def test_import_psv_ps2(monkeypatch, capsys, data, mc02_copy):
    assert output.err == ""

    assert md5(mc_file) == "2872c456bcb647e78aeb3ce29e718309"


def test_import_psv_ps1(monkeypatch, capsys, data, mc02_copy):
    from mymcplus import ps2mc
    from mymcplus import ps2mc_dir
    patch_fixed_time(monkeypatch, ps2mc)
    patch_fixed_time(monkeypatch, ps2mc_dir)

    mc_file = mc02_copy.join("mc02.ps2").strpath
    psv_file = data.join("BASLUS-006623030303030303041.PSV").strpath

    mymc.main(["mymcplus",
               "-i", mc_file,
               "import", psv_file])

    output = capsys.readouterr()
    assert output.out == "Importing " + psv_file + " to BASLUS-006620000000A\n"
    assert output.err == ""

    assert md5(mc_file) == "c9f26130a5de7548248a5fec80593a4d"