-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrupt.py
More file actions
207 lines (179 loc) · 5.29 KB
/
corrupt.py
File metadata and controls
207 lines (179 loc) · 5.29 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import glob
import random
import os
import re
import msvcrt
import vpk as vpklib
import json
from tqdm import tqdm
from shutil import copyfile
from colorama import init, Fore, Style
init()
class NewVPK(object):
def __init__(self, path):
self.vpk = vpklib.open(path)
self.path = path
self.name = os.path.splitext(path)[0].split("\\")[-1]
self.selectedTypes = None
self.files = None
types = []
for file in self.vpk.items():
#file[0] is the name
fileName, fileExtension = os.path.splitext(file[0])
if not (fileExtension in types):
types.append(fileExtension)
self.types = types
def analyzeToTypes(self):
files = {}
for fileType in self.types:
files[fileType] = []
for file in self.vpk.items():
fileName, fileExtension = os.path.splitext(file[0])
if (fileExtension in self.types):
files[fileExtension].append(file[0])
self.files = files
class WindowsFS(object):
def __init__(self, path):
self.path = path
self.name = os.path.splitext(path[:-1])[0].split("\\")[-1]
self.selectedTypes = None
self.files = None
self.items = [r+f for r,d,f in os.walk(path)]
types = []
for file in self.items:
#file[0] is the name
fileName, fileExtension = os.path.splitext(file)
if not (fileExtension in types):
types.append(fileExtension)
self.types = types
def analyzeToTypes(self):
files = {}
for fileType in self.types:
files[fileType] = []
for file in self.items:
fileName, fileExtension = os.path.splitext(file[0])
if (fileExtension in self.types):
files[fileExtension].append(file[0])
self.files = files
temp = r"D:\FSSTEMP"
try:
os.mkdir(temp)
except:
pass
options = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()-+"
mainOptions = ["Unpack VPK", "Raw File System"]
repackOptions = ["Pack to VPK", "Leave as is"]
def clear():
os.system("cls")
clear()
def choose(arr, message):
enter = True
toggles = [True] * len(arr)
def reprint():
print(Fore.YELLOW + message)
print(Fore.YELLOW + "==Please toggle the types you want, then press enter==")
for i, j in enumerate(arr):
print(Fore.GREEN + "[" + options[i] + "]" + Fore.CYAN + " " + j + " (" + ("x" if toggles[i] else "") + ")")
reprint()
while enter:
if msvcrt.kbhit():
keyhit = msvcrt.getch()
if keyhit == b'\r':
enter = False
else:
key = options.index(keyhit.decode("utf-8"))
if key < len(arr):
toggles[key] = not toggles[key]
clear()
reprint()
types = []
for i, fileType in enumerate(arr):
if toggles[i]:
types.append(fileType)
return types
def choice(arr):
print(Fore.YELLOW + "==Please specify an option==")
for i, j in enumerate(arr):
print(Fore.GREEN + "[" + options[i] + "]" + Fore.CYAN + " " + j)
return options.index(msvcrt.getch().decode("utf-8"))
print(Fore.YELLOW + "==**File System Shuffler**==");
op1 = choice(mainOptions)
clear()
print(Fore.YELLOW + "==**Finished Product**==");
op2 = choice(repackOptions)
clear()
if op1 == 0:
globFiles = glob.glob (r".\*.vpk")
files = []
for file in globFiles:
if re.search(r"\d\d\d.vpk", file) == None:
files.append(file)
if len(files) == 0:
clear()
print(Fore.RED + "No available VPK files in directory.")
os.system("pause")
os.system("exit")
print(Fore.YELLOW + "==**Available Files**==")
fileChosen = files[choice(files)]
vpk = NewVPK(fileChosen)
clear()
vpk.selectedTypes = choose(vpk.types, "==**File Types**==")
vpk.analyzeToTypes()
##START CORRUPTIONS!!!
# use mkdirs
print(Fore.WHITE)
for i, fileType in enumerate(vpk.selectedTypes):
sub = vpk.files[fileType]
description = "{} Files ({} of {})".format(fileType, i+1, len(vpk.selectedTypes))
for file in tqdm(sub, desc=description):
try:
toReplace = sub[random.randint(0,len(sub)-1)]
dest = "./shuffled_" + vpk.name + "/"
os.makedirs(dest + '/'.join(toReplace.split('/')[0:-1]), exist_ok=True)
vpk.vpk.get_file(file).save(dest + toReplace)
except Exception as e:
print(e)
elif op1 == 1:
directories = ["Current Directory"] + glob.glob('./*/')
print(Fore.YELLOW + "==**Available Folders**==")
directoryChosen = directories[choice(directories)]
if directoryChosen == "Current Directory":
directoryChosen = "./"
folder = WindowsFS(directoryChosen)
clear()
folder.selectedTypes = choose(folder.types, "==**File Types**==")
folder.analyzeToTypes()
##START CORRUPTIONS!!!
# use mkdirs
print(Fore.WHITE)
for i, fileType in enumerate(folder.selectedTypes):
sub = folder.files[fileType]
description = "{} Files ({} of {})".format(fileType, i+1, len(folder.selectedTypes))
for file in tqdm(sub, desc=description):
try:
toReplace = sub[random.randint(0,len(sub)-1)]
dest = "./shuffled_" + folder.name + "/"
os.makedirs(dest + '/'.join(toReplace.split('/')[0:-1]), exist_ok=True)
copyfile(file, dest+toReplace)
except Exception as e:
print(e)
os.system("pause")
# temp = "./temp"
# try:
# os.mkdir(temp)
# except:
# print("temp already exists")
# files = glob.glob ("./**/*.wav", recursive=True)
# for file1 in files:
# files.remove(file1)
# i2 = random.randint(0,len(files))
# file2 = files[i2]
# del files[i2]
# #file 1 to temp
# tempfile1 = (temp + "/" + re.search(r"[\w_]+?.wav", file1).group(0))
# print(tempfile1)
# os.rename(file1, tempfile1)
# #file 2 to 1
# os.rename(file2, file1)
# #tempfile to file2
# os.rename(tempfile1, file2)