-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·126 lines (102 loc) · 4.6 KB
/
main.py
File metadata and controls
executable file
·126 lines (102 loc) · 4.6 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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
'''
Name : QmcDecoder/main.py
Author : Modnar
Date : 2020/02/18
Copyrights (c) 2020 Modnar. All rights reserved.
'''
import os, threading, time, tkinter
from tkinter import filedialog, ttk, messagebox
if not os.path.exists('cache/'):
os.makedirs('cache/')
IS_RUNNING = False
SUFFIXS = {'qmc0', 'qmcogg', 'qmcflac'}
class QmcDecoder:
def __init__(self, titleName):
self.root = tkinter.Tk()
self.root.title(titleName)
self.__add_widgets()
self.root.resizable(False, False)
self.root.mainloop()
def __add_widgets(self):
inputFrame = ttk.Frame(self.root)
outputFrame = ttk.Frame(self.root)
loggingFrame = ttk.Frame(self.root)
inputFrame.grid(padx=5, pady=5, row=0, column=0, sticky='we')
outputFrame.grid(padx=5, pady=5, row=1, column=0, sticky='we')
loggingFrame.grid(padx=5, pady=5, row=0, column=1, rowspan=2)
self.tableView = ttk.Treeview(inputFrame, show='headings', columns=('col',))
self.tableView.column('col', width=300, anchor='center')
self.tableView.heading('col', text='输入文件路径')
self.tableView.grid(padx=3, pady=3, row=0, column=0, sticky='nwe')
chooseInputButton = ttk.Button(inputFrame, text='选择文件', \
command=self.__chooseFiles)
chooseInputButton.grid(padx=3, pady=3, row=1, column=0, sticky='n')
self.entryText = tkinter.StringVar()
self.entryText.set('输入/选择输出文件夹')
self.getOutputEntry = ttk.Entry(outputFrame, textvariable=self.entryText, \
width=30)
self.getOutputEntry.grid(padx=5, pady=5, row=0, column=0, sticky='n')
chooseOutputButton = ttk.Button(outputFrame, text='浏览目录', \
command=self.__chooseDir)
chooseOutputButton.grid(padx=5, pady=5, row=1, column=0, sticky='n')
self.textPanel = tkinter.Text(loggingFrame, width=30, height=20)
self.textPanel.grid(padx=5, pady=5, row=0, column=0, sticky='n')
self.textPanel.config(state=tkinter.DISABLED)
runButton = ttk.Button(loggingFrame, text='RUN !', command=self.__decode)
runButton.grid(padx=5, pady=5, row=1, column=0, sticky='n')
def __chooseFiles(self):
self.filenames = filedialog.askopenfilenames()
passCheck = True
for filename in self.filenames:
if self.__checkFileFailed(filename.split('/')[-1]):
passCheck = False
break
if passCheck:
self.__updateFilenames()
def __updateFilenames(self):
for _ in map(self.tableView.delete, self.tableView.get_children('')):
pass
for i in range(len(self.filenames)):
print(self.filenames[i])
self.tableView.insert('', i, values=(self.filenames[i].split('/')[-1],))
def __chooseDir(self):
self.entryText.set(filedialog.askdirectory())
def __decode(self):
global IS_RUNNING
if IS_RUNNING:
messagebox.showinfo(title='INFORMATION', message='程序执行中,请稍候。')
elif self.getOutputEntry.get() == '':
messagebox.showwarning(title='WARNING', message='请指定结果文件存储目录!')
elif len(self.filenames) == 0:
messagebox.showwarning(title='WARNING', message='请选择要处理的文件!')
else:
IS_RUNNING = True
with open('cache/cache.txt', 'w', encoding='utf-8') as writeFile:
for file_path in self.filenames:
writeFile.write(file_path+'\n')
writeFile.write('\n')
writeFile.write(self.getOutputEntry.get())
self.__updateLogging('Running...')
os.system('./QmcDecoder cache/cache.txt')
#self.updateLogging()
with open('cache/cache.log', 'r') as readFile:
self.__updateLogging(readFile.read())
IS_RUNNING = False
def __checkFileFailed(self, filename):
if filename.split('.')[-1] not in SUFFIXS:
messagebox.showwarning(title='WARNING', \
message='Failed: %s\n请确保输入的是QMC加密文件!' % filename)
return True
return False
def __updateLogging(self, message):
self.textPanel.config(state=tkinter.NORMAL)
self.textPanel.delete('1.0', 'end')
self.textPanel.insert(tkinter.INSERT, message)
self.textPanel.see(tkinter.END)
self.textPanel.config(state=tkinter.DISABLED)
def main():
QmcDecoder('QmcDecoder v1.0')
if __name__ == '__main__':
main()