import os, hashlib

mopath_old = "S:\\Mod Organizer\\"
mopath_new = "C:\\Users\\Fedora\\Downloads\\Mod Organizer v1_3_11-1334-1-3-11\\ModOrganizer\\"


def extractBase(p, i):
    s = p.split("\\")
    r = ""

    for n,e in enumerate(s):
        r = r + e if n > i else r
        r = r + "\\" if n > i and n != len(s)-1 else r
    return r


mopath_old_files = [extractBase(e, 1) for e in os.popen("dir \"%s\" /s /a:-d /b" % mopath_old).read().split("\n")]
mopath_new_files = [extractBase(e, 5) for e in os.popen("dir \"%s\" /s /a:-d /b" % mopath_new).read().split("\n")]

mopath_present_files = [x for x in mopath_old_files if x in mopath_new_files]
mopath_missing_files = [x for x in mopath_old_files if x not in mopath_new_files]

io_failure = False

for present_file in mopath_present_files:
    if present_file == "": continue
    present_file_old = mopath_old + present_file
    present_file_new = mopath_new + present_file

    io_old = open(present_file_old, "rb")
    io_new = open(present_file_new, "rb")

    hash_old = hashlib.new("sha1")
    hash_new = hashlib.new("sha1")

    buffer_old = io_old.read(1)
    buffer_new = io_old.read(1)

    if buffer_old and buffer_new:
        hash_old.update(buffer_old)
        hash_new.update(buffer_new)

        if io_failure:
            io_failure = False
            print("==== END IO FAILURE  ====\n\n\n\n\n")

    else:

        if not io_failure: 
            io_failure = True
            print("\n\n\n\n\n==== FILE IO FAILURE ====")

        print(present_file_old)
        print(present_file_new)
        print("")



        io_old.close()
        io_new.close()
        continue

    buffer_old = io_old.read(1024)

    while buffer_old:
        hash_old.update(buffer_old)
        buffer_old = io_old.read(1024)

    buffer_new = io_new.read(1024)

    while buffer_new:
        hash_new.update(buffer_new)
        buffer_new = io_new.read(1024)

    digest_old, digest_new = hash_old.hexdigest(), hash_new.hexdigest()

    discrepancy_message = ""

    if digest_old != digest_new:
        print()
        print("{0} IS NOT {1}".format(digest_old, digest_new))
        print("OLD:",present_file_old)
        print("NEW:",present_file_new)
        print()



    io_old.close()
    io_new.close()








Edit Report
Pub: 10 Dec 2018 19:41 UTC
Edit: 10 Dec 2018 19:46 UTC
Views: 90