-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRedumpVerifier.py
170 lines (138 loc) · 5.11 KB
/
RedumpVerifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import os
import hashlib
import sys
import datetime
dats = os.listdir("./dat")
read_size = 1024
hash = hashlib.md5()
gameVerified = False
line_number = 0
romList = list()
romListRedumpName = list()
romListHash = list()
def getAllFiles(dirName):
files = os.listdir(dirName)
allFiles = list()
for entry in files:
fullpath = os.path.join(dirName, entry)
if os.path.isdir(fullpath):
allFiles = allFiles + getAllFiles(fullpath)
else:
allFiles.append(fullpath)
return allFiles
def verify(files):
global romList, romListRedumpName, romListHash
for file in files:
gameVerified = False
iso = file.replace("\"", "")
print("\nISO: " + iso)
hash = hashlib.md5()
print("Calculating hash...")
with open(iso, "rb") as f:
data = f.read(read_size)
while data:
hash.update(data)
data = f.read(read_size)
hash = hash.hexdigest()
romList.append(file)
for dat in dats:
line_number = 0
data = ""
with open("dat/" + dat, "r") as f:
data = f.readlines()
for line in data:
line_number += 1
if hash in line:
print("\n"
+ "ISO's MD5 hash: " + hash
+ "\n"
+ "Game Verified, ISO's MD5 matches Redump hash"
)
name_line = line_number
while "<description>" not in data[name_line]:
name_line -= 1
gameName = data[name_line]\
.replace("<description>", "")\
.replace("</description>", "")\
.replace("\t", "")
print("Redump game name: " + gameName
+ "\n"
+ "----------------------------------------")
gameVerified = True
if gameVerified:
romListRedumpName.append(gameName)
break
if not gameVerified:
print("ISO's MD5: " + hash
+ "\n"
+ "ISO's MD5 doesn't match any Redump hash"
+ "\n"
+ "\n"
+ "----------------------------------------"
)
romListRedumpName.append("Not verified")
romListHash.append(hash)
# --------------------------------------------------------------------------- #
# Check for updates #
with open("dat/_last_update", "r") as f:
last_update_time = f.read()
if (int(str(datetime.date.today()).split("-")[1]) >
int(last_update_time.split("-")[1])) \
| (int(str(datetime.date.today()).split("-")[0]) >
int(last_update_time.split("-")[0])):
print("DATs haven't been updated in at least one month")
i = input("Do you want to update them? (y/n) > ")
if i == "y":
exec(open("dat_updater.py").read())
else:
pass
if len(sys.argv) > 1:
for i in sys.argv[1:]:
if os.path.isfile(i.replace("\"", "")): # if input is a file
input_file = list()
input_file.append(i)
verify(input_file)
elif os.path.isdir(i.replace("\"", "")): # if input is a folder
inputFolder = i.replace("\"", "")
inputFiles = getAllFiles(inputFolder)
verify(inputFiles)
else:
print("Something went wrong...")
# if len(sys.argv) < 2:
print("\n\nSummary:\n")
for rom in romList:
print(os.path.basename(rom) + " - " +
romListRedumpName[romList.index(rom)])
print(romListHash[romList.index(rom)])
input()
else:
print(""
+ "============ Redump verifier - version 1.9 ==============\n"
+ "------------ Github.com/normalgamer --------------\n"
+ "\n"
+ "Drag 'n Drop your ISO or folder\n"
+ "If you want to verify multiple items, separate them by an"
+ "asterisk ( * )\n"
+ "\n"
)
userInput = input("> ")
userInput = userInput.split("*")
for i in userInput:
print(i)
if os.path.isfile(i.replace("\"", "")): # if input is a file
input_file = list()
input_file.append(i)
verify(input_file)
elif os.path.isdir(i.replace("\"", "")): # if input is a folder
inputFolder = i.replace("\"", "")
inputFiles = getAllFiles(inputFolder)
verify(inputFiles)
else:
print("Something went wrong...")
# if len(sys.argv) < 2:
print("\n\nSummary:\n")
for rom in romList:
print(os.path.basename(rom) + " - " +
romListRedumpName[romList.index(rom)])
print(romListHash[romList.index(rom)])
input()