-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder.py
93 lines (78 loc) · 3.41 KB
/
decoder.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
import tkinter
from tkinter import filedialog
import time
import os
from os import listdir
from pathlib import Path
# directory = os.listdir(inputPath)
# with open("C:\\Users\\andre\\Documents\\VSCode\\Professor-Layton-Text-Encoding-Changer\\processed\\output.txt", "a") as f:
# for i in directory:
# print(i, file=f)
# subDirectory = os.listdir(inputPath + "\\" + i)
# for j in subDirectory:
# print(j, file=f)
tkinter.Tk().withdraw() # prevents an empty tkinter window from appearing
inputPath = filedialog.askdirectory()
# relative = Path(userSelection)
# inputPath = relative.absolute()
# print("#############################################################################")
# print("\n")
# print("Selected:")
# print(inputPath)
# print("\n")
# print("#############################################################################")
# time.sleep(2)
# inputPath = "C:\\Users\\andre\\Documents\\VSCode\\Professor-Layton-Text-Encoding-Changer\\lt2\\lt2 - JP - Diabolical Box\\data_jp"
outputPath = "C:\\Users\\andre\\Documents\\VSCode\\Professor-Layton-Text-Encoding-Changer\\processed"
# directory = os.listdir(inputPath)
directory = [d for d in os.listdir(inputPath) if os.path.isdir(os.path.join(inputPath, d))]
print(directory)
noOfFolders = 0
noOfFiles = 0
for i in directory:
noOfFolders = noOfFolders + 1
subDirectory = os.listdir(inputPath + "\\" + i)
for j in subDirectory:
noOfFiles = noOfFiles + 1
if os.path.exists(outputPath) == True:
print("Already exists: /processed")
time.sleep(0.5)
else:
os.makedirs(outputPath)
# directory = os.listdir(inputPath)
completedFolders = 0
completedFiles = 1
for i in directory:
outputPath = "C:\\Users\\andre\\Documents\\VSCode\\Professor-Layton-Text-Encoding-Changer\\processed" + "\\" + i
if os.path.isdir(outputPath) == True:
print(f"Already exists: /processed/{i}")
completedFolders = completedFolders + 1
time.sleep(0.5)
else:
os.makedirs(outputPath)
completedFolders = completedFolders + 1
subDirectory = os.listdir(inputPath + "\\" + i)
for j in subDirectory:
fileCheck = "C:\\Users\\andre\\Documents\\VSCode\\Professor-Layton-Text-Encoding-Changer\\processed\\{i}\\{j}"
if os.path.isfile(fileCheck) == True:
print(f"Already exists: processed/{i}/{j}")
completedFiles = completedFiles + 1
else:
file1 = open(f"{inputPath}\\{i}\\{j}", "r", encoding = "shiftjis")
file2 = open(f"C:\\Users\\andre\\Documents\\VSCode\\Professor-Layton-Text-Encoding-Changer\\processed\\{i}\\{j}", "w", encoding="utf8")
l = file1.readline()
while l:
file2.write(l)
l = file1.readline()
file1.close()
file2.close()
print(f"Completed: {completedFolders}/{noOfFolders} {completedFiles}/{noOfFiles}")
completedFiles = completedFiles + 1
# file1 = open("C:\\Users\\andre\\Documents\\VSCode\\Professor-Layton-Text-Encoding-Changer\\original files (Shift-JIS encoding)\\etext\\e1_t0.txt", "r", encoding = "shiftjis")
# file2 = open("C:\\Users\\andre\\Documents\\VSCode\\Professor-Layton-Text-Encoding-Changer\\processed\\e1_t0.txt", "w", encoding="utf8")
# l = file1.readline()
# while l:
# file2.write(l)
# l = file1.readline()
# file1.close()
# file2.close()