-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindowOldStyle.py
677 lines (627 loc) · 33.7 KB
/
MainWindowOldStyle.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
import ctypes
import json
import os
import psutil
import requests
import threading
import time
# import traceback
import webbrowser
#import win32api
#import win32con
#import win32gui_struct
#import win32gui
from PIL import Image as PILImage
from PIL import ImageTk
#from threading import Thread
from tkinter import *
from tkinter import Tk,ttk,font,messagebox
from tkinter.filedialog import askopenfilename
import Difficulty_ScoreAnalyze as dsa
import Functions
import MusyncSavDecode
from HitDelay import HitDelayCheck,HitDelayText
class MusyncSavDecodeGUI(object):
"""docstring for MusyncSavDecodeGUI"""
def __init__(self, version, preVersion, isPreRelease=False, root=None, isTKroot=True):
##Init##
self.version = version
self.preVersion = preVersion
with open('./musync_data/ExtraFunction.cfg','r',encoding='utf8') as confFile:
self.config = json.load(confFile)
root.iconbitmap('./musync_data/Musync.ico')
super(MusyncSavDecodeGUI, self).__init__()
self.isTKroot = isTKroot
root.geometry(f'1000x670+500+300')
self.root = root
self.root.minsize(500, 460)
def fixed_map(option):
return [elm for elm in style.map("Treeview", query_opt=option) if elm[:2] != ("!disabled", "!selected")]
style = ttk.Style()
if 1 :# self.config['SystemDPI'] == 100:
style.configure("Treeview", rowheight=20, font=('霞鹜文楷等宽',13))
style.configure("Treeview.Heading", rowheight=20, font=('霞鹜文楷等宽',15))
style.configure("reload.TButton", font=('霞鹜文楷等宽',16))
# , background='#EEBBBB', foreground='#00CCFF',relief='ridge')
# photo = PhotoImage(file="./skin/F5.png").subsample(5, 4)
style.configure("F5.TButton", font=('霞鹜文楷等宽',16),# background='#EEBBBB')
# image=[photo,style.map("F5.TButton",
image=[style.map("F5.TButton",
foreground=[('pressed', 'red'), ('active', 'blue')],
background=[('pressed', '!disabled', 'black'), ('active', 'white')])
])
style.configure("close.TButton", font=('霞鹜文楷等宽',16), bg="#EEBBBB")
self.font=('霞鹜文楷等宽',16)
# elif self.config['SystemDPI'] == 125:
# else:
# style.configure("Treeview", rowheight=20, font=('霞鹜文楷等宽',11))
# style.configure("Treeview.Heading", rowheight=20, font=('霞鹜文楷等宽',15))
# style.configure("reload.TButton", font=('霞鹜文楷等宽',13.5))
# # , background='#EEBBBB', foreground='#00CCFF',relief='ridge')
# style.configure("F5.TButton", font=('霞鹜文楷等宽',13.5), bg="#EEBBBB")
# self.font=('霞鹜文楷等宽',13.5)
# style.configure("Treeview", foreground=fixed_map("foreground"), background=fixed_map("background"))
# style.configure("Treeview", background="#EFEFEF", foreground="#050505", fieldbackground="red")
if isTKroot == True:
root.title("同步音律喵赛克Steam端本地存档分析")
root['background'] = '#efefef'
self.saveFilePathVar = StringVar()
self.saveFilePathVar.set('Input SaveFile or AnalyzeFile Path (savedata.sav)or(SavAnalyze.json)')
self.analyzeFilePathVar = StringVar()
self.analyzeFilePathVar.set('Input Analyze File Dir (or not)')
self.windowInfo = [root.winfo_x(),root.winfo_y(),root.winfo_width(),root.winfo_height()]
self.saveCount = 0
self.totalSync = 0
self.excludeCount = 0
self.dataSortMethodsort = [None,True]
self.dataSelectMethod = None
self.treeviewColumns = ["SpeedStall",'SongName',"Keys","Difficulty","DifficultyNumber","SyncNumber","Rank","UploadScore","PlayCount","Status"]
self.difficute = 3
self.keys = 0
self.isDLC = 0
self.wh = [0,0]
self.checkGameStartEvent = threading.Event()
self.CheckGameIsStartThread = None
root.protocol("WM_DELETE_WINDOW", self.on_closing)
##Controller##
self.deleteAnalyzeFile = ttk.Button(self.root, text="解码并刷新",command=self.DeleteAnalyzeFile,style='F5.TButton')
self.deleteAnalyzeFile.place(x=10,y=10,width=160,height=30)
self.isGameRunning = Label(self.root, text="游戏未启动", font=self.font,bg='#FF8080')
self.isGameRunning.place(x=30,y=85,width=110,height=30)
self.CountFrameLanel = Label(self.root,text="", relief="groove")
self.CountFrameLanel.place(x=8,y=48,width=164,height=34)
self.PrintLabel0 = Label(self.root, text='显示计数: ', font=self.font, relief="flat")
self.PrintLabel0.place(x=10,y=50,width=100,height=30)
self.saveCountLabel = Label(self.root, text=str(self.saveCount+self.excludeCount), font=self.font, relief="flat")
self.saveCountLabel.place(x=110,y=50,width=60,height=30)
self.saveFilePathEntry = Entry(self.root, textvariable=self.saveFilePathVar, font=self.font, relief="sunken")
self.getSaveFilePath = Button(self.root, text='打开存档', command=self.SelectPath, font=self.font)
self.saveData = ttk.Treeview(self.root, show="headings", columns = self.treeviewColumns)
self.VScroll1 = Scrollbar(self.saveData, orient='vertical', command=self.saveData.yview)
self.saveData.configure(yscrollcommand=self.VScroll1.set)
# self.saveData.tag_configure("NotDLCSong",background='#BBDDFF')
# self.saveData.tag_configure("NotDLCSong",background='#FF0000',foreground='blue')
# self.saveData.tag_configure("IsDLCSong",background='#FDFFAE',foreground='blue')
self.developer = Label(self.root, text=f'Version {self.preVersion if isPreRelease else self.version} | Develop By Ginsakura', font=self.font, relief="groove")
self.gitHubLink = Button(self.root, text='点击打开GitHub仓库 点个Star吧,秋梨膏', command=lambda:webbrowser.open("https://github.com/Ginsakura/MUSYNCSave"), fg='#4BB1DA', anchor="center", font=self.font, relief="groove")
self.initLabel = Label(self.root, text='启动中......', anchor="w", font=self.font, relief="groove")
self.initLabel.place(x=250,y=300,width=500,height=30)
# self.closeWindow = ttk.Button(self.root, text="关闭",command=lambda : self.root.destroy(),style='close.TButton')
# self.closeWindow.place(x=100,y=88,width=90,height=30)
self.difficuteScoreAnalyze = Button(self.root, text="成绩分布",command=lambda:dsa.Analyze(), font=self.font)
self.difficuteScoreAnalyze.place(x=775,y=88,width=90,height=30)
self.totalSyncFrameLabel = Label(self.root, text='', relief="groove")
self.totalSyncFrameLabel.place(x=868,y=48,width=124,height=74)
self.totalSyncTextLabel = Label(self.root, text='综合同步率', anchor="center", font=self.font, relief="flat")
self.totalSyncTextLabel.place(x=870,y=50,width=120,height=30)
self.avgSyncLabel = Label(self.root, text=f'{(self.totalSync / (1 if self.saveCount==0 else self.saveCount)):.6f}%', anchor="w", font=self.font, relief="flat")
self.avgSyncLabel.place(x=870,y=90,width=120,height=30)
#筛选控件
self.selectFrame = Frame(self.root, relief="groove",bd=2)
self.selectFrame.place(x=180,y=50,width=380,height=70)
self.selectLabel0 = Label(self.selectFrame, text="筛选\n控件", anchor="w", font=self.font, relief="flat")
self.selectLabel0.place(x=0,y=5,width=50,height=60)
self.selectPlayedButton = Button(self.selectFrame, text='已游玩', command=lambda:self.SelectMethod('Played'), anchor="w", font=self.font)
self.selectPlayedButton.place(x=50,y=0,width=75,height=30)
self.selectUnplayButton = Button(self.selectFrame, text='未游玩', command=lambda:self.SelectMethod('Unplay'), anchor="w", font=self.font)
self.selectUnplayButton.place(x=50,y=35,width=75,height=30)
self.selectIsFavButton = Button(self.selectFrame, text='已收藏', command=lambda:self.SelectMethod('IsFav'), anchor="w", font=self.font)
self.selectIsFavButton.place(x=125,y=0,width=75,height=30)
self.selectExRankButton = Button(self.selectFrame, text='RankEx', command=lambda:self.SelectMethod('RankEX'), anchor="w", font=self.font)
self.selectExRankButton.place(x=125,y=35,width=75,height=30)
self.selectSRankButton = Button(self.selectFrame, text='RankS', command=lambda:self.SelectMethod('RankS'), anchor="w", font=self.font)
self.selectSRankButton.place(x=200,y=0,width=62,height=30)
self.selectARankButton = Button(self.selectFrame, text='RankA', command=lambda:self.SelectMethod('RankA'), anchor="w", font=self.font)
self.selectARankButton.place(x=200,y=35,width=62,height=30)
self.selectBRankButton = Button(self.selectFrame, text='RankB', command=lambda:self.SelectMethod('RankB'), anchor="w", font=self.font)
self.selectBRankButton.place(x=262,y=0,width=62,height=30)
self.selectCRankButton = Button(self.selectFrame, text='RankC', command=lambda:self.SelectMethod('RankC'), anchor="w", font=self.font)
self.selectCRankButton.place(x=262,y=35,width=62,height=30)
self.select122Button = Button(self.selectFrame, text='黑Ex', command=lambda:self.SelectMethod('Sync122'), anchor="w", font=self.font)
self.select122Button.place(x=324,y=0,width=50,height=30)
self.select120Button = Button(self.selectFrame, text='红Ex', command=lambda:self.SelectMethod('Sync120'), anchor="w", font=self.font)
self.select120Button.place(x=324,y=35,width=50,height=30)
##额外筛选##
self.selectExFrame = Frame(self.root, bd=2, relief="groove")
self.selectExFrame.place(x=570,y=50,width=200,height=70)
self.selectLabel1 = Label(self.selectExFrame, text="额外\n筛选", anchor="w", font=self.font, relief="flat")
self.selectLabel1.place(x=0,y=5,width=50,height=60)
self.selectDLCSong = Button(self.selectExFrame, text=['所\n有','本\n体','扩\n展'][self.isDLC], command=lambda:self.SelectDLCSong(), anchor='w', font=self.font)
self.selectDLCSong.place(x=48,y=0,width=30,height=65)
self.selectKeys = Button(self.selectExFrame, text=['4 & 6 Keys','4 Keys','6 Keys'][self.keys], command=lambda:self.SelectKeys(), anchor='w', font=self.font)
self.selectKeys.place(x=80,y=0,width=[112,72,72][self.keys],height=30)
self.selectDifficute = Button(self.selectExFrame, text=['Easy','Hard',"Inferno",'所有难度'][self.difficute], command=lambda:self.SelectDifficute(), anchor='w', font=self.font)
self.selectDifficute.place(x=80,y=35,width=[52,52,82,92][self.difficute],height=30)
##AutoRun##
self.InitLabel('初始化函数执行中......')
self.UpdateWindowInfo()
self.TreeviewWidthUptate()
self.TreeviewColumnUpdate()
def CheckGameIsStart(event):
count = 0
while event.is_set():
if count%10 == 0:
startTime = time.perf_counter_ns()
# print("Checking Game Is Start?")
try:
for ids in psutil.pids():
if psutil.Process(pid=ids).name() == "MUSYNX.exe":
# self.config["MainExecPath"]
self.isGameRunning["text"] = "游戏已启动"
self.isGameRunning["bg"] = "#98E22B"
break
else:
self.isGameRunning["text"] = "游戏未启动"
self.isGameRunning["bg"] = "#FF8080"
except Exception as e:
print(repr(e))
endTime = time.perf_counter_ns()
print("CheckGameIsStart Run Time: %f ms"%((endTime - startTime)/1000000))
count = 0
time.sleep(0.5)
count += 1
print("Stop Thread: CheckGameIsStart.")
self.checkGameStartEvent.set()
self.CheckGameIsStartThread = threading.Thread(target=CheckGameIsStart, args=(self.checkGameStartEvent, ))
self.CheckGameIsStartThread.start()
threading.Thread(target=self.CheckJsonUpdate).start()
if self.config['DisableCheckUpdate']:
self.gitHubLink.configure(text='更新已禁用 点击打开GitHub仓库页')
else:
threading.Thread(target=self.CheckUpdate).start()
if not os.path.isfile('./musync_data/SaveFilePath.sfp'):
self.GetSaveFile()
else:
self.InitLabel(text="正在读取存档路径……")
with open('./musync_data/SaveFilePath.sfp','r+',encoding='utf8') as sfp:
sfpr = sfp.read()
if not sfpr:
self.GetSaveFile()
elif (not os.path.isfile(sfpr)):
self.InitLabel(text="正在删除存档路径.")
os.remove('./musync_data/SaveFilePath.sfp')
self.GetSaveFile()
else:
self.saveFilePathVar.set(sfpr)
if self.config['EnableAnalyzeWhenStarting']:
self.DeleteAnalyzeFile()
self.CheckFile()
if self.config['EnableDLLInjection']:
self.hitDelay = Button(self.root, text="游玩结算",command=self.HitDelay, font=self.font,bg='#FF5959')
self.hitDelay.place(x=775,y=50,width=90,height=30)
if os.path.isfile('./musync_data/SavAnalyze.json'):
self.DataLoad()
elif os.path.isfile('./musync_data/SavDecode.decode'):
self.InitLabel('解码存档中......')
MusyncSavDecode.MUSYNCSavProcess(decodeFile='./musync_data/SavDecode.decode').Main('decode')
self.DataLoad()
# TK事件重载
def on_closing(self):
self.checkGameStartEvent.clear()
self.CheckGameIsStartThread.join()
self.root.destroy()
# json文件检查
def CheckFile(self):
saveData=None
if os.path.isfile('./musync_data/SavAnalyze.json'):
try:
with open(f'./musync_data/SavAnalyze.json','r+',encoding='utf8') as saveData:
saveDataJson = json.load(saveData)
except Exception as e:
messagebox.showerror("Error", f'SavAnalyze.json文件打开失败\n错误的Json文件格式\n{e}')
os.remove("./musync_data/SavAnalyze.json")
else:
if len(saveDataJson['SaveData']) == 0:
os.remove("./musync_data/SavAnalyze.json")
# select功能组
def SelectKeys(self):
self.keys = (self.keys+1)%3
self.selectKeys.configure(text=['4 & 6Keys','4 Keys','6 Keys'][self.keys])
self.selectKeys.place(width=[102,72,72][self.keys])
self.DataLoad()
self.root.update()
def SelectDifficute(self):
self.difficute = (self.difficute+1)%4
self.selectDifficute.configure(text=['Easy','Hard',"Inferno",'所有难度'][self.difficute])
self.selectDifficute.place(width=[52,52,82,92][self.difficute])
self.DataLoad()
self.root.update()
def SelectDLCSong(self):
self.isDLC = (self.isDLC+1)%3
self.selectDLCSong.configure(text=['所\n有','本\n体','扩\n展'][self.isDLC])
self.selectDLCSong.configure(bg=['#F0F0F0','#FF9B9B','#98E22B'][self.isDLC])
self.DataLoad()
self.root.update()
def SelectMethod(self,method):
if self.dataSelectMethod == method:
self.dataSelectMethod = None
self.SelectButtonGrey(method)
else:
self.SelectButtonGrey(self.dataSelectMethod)
self.dataSelectMethod = method
self.SelectButtonGreen(self.dataSelectMethod)
self.DataLoad()
self.root.update()
def SelectButtonGreen(self,method):
if method == "Played":self.selectPlayedButton.configure(bg='#98E22B')
elif method == "Unplay":self.selectUnplayButton.configure(bg='#98E22B')
elif method == "IsFav":self.selectIsFavButton.configure(bg='#98E22B')
elif method == "Sync122":self.select122Button.configure(bg='#98E22B')
elif method == "Sync120":self.select120Button.configure(bg='#98E22B')
elif method == "RankEX":self.selectExRankButton.configure(bg='#98E22B')
elif method == "RankS":self.selectSRankButton.configure(bg='#98E22B')
elif method == "RankA":self.selectARankButton.configure(bg='#98E22B')
elif method == "RankB":self.selectBRankButton.configure(bg='#98E22B')
elif method == "RankC":self.selectCRankButton.configure(bg='#98E22B')
def SelectButtonGrey(self,method):
if method == "Played":self.selectPlayedButton.configure(bg='#F0F0F0')
elif method == "Unplay":self.selectUnplayButton.configure(bg='#F0F0F0')
elif method == "IsFav":self.selectIsFavButton.configure(bg='#F0F0F0')
elif method == "Sync122":self.select122Button.configure(bg='#F0F0F0')
elif method == "Sync120":self.select120Button.configure(bg='#F0F0F0')
elif method == "RankEX":self.selectExRankButton.configure(bg='#F0F0F0')
elif method == "RankS":self.selectSRankButton.configure(bg='#F0F0F0')
elif method == "RankA":self.selectARankButton.configure(bg='#F0F0F0')
elif method == "RankB":self.selectBRankButton.configure(bg='#F0F0F0')
elif method == "RankC":self.selectCRankButton.configure(bg='#F0F0F0')
def SelectPath(self):
# 使用askdirectory()方法返回文件夹的路径
path_ = askopenfilename(title="打开存档文件", filetypes=(("Sav Files", "*.sav"),("All Files","*.*"),))
if path_ == "":
# 当打开文件路径选择框后点击"取消" 输入框会清空路径,所以使用get()方法再获取一次路径
self.saveFilePathVar.get()
else:
# 实际在代码中执行的路径为“\“ 所以替换一下
path_ = path_.replace("/", "\\")
self.saveFilePathVar.set(path_)
# bind功能组
def DoubleClick(self,event):
e = event.widget # 取得事件控件
itemID = e.identify("item",event.x,event.y) # 取得双击项目id
# state = e.item(itemID,"text") # 取得text参数
songData = e.item(itemID,"values") # 取得values参数
print(songData)
# nroot = Toplevel(self.root)
# nroot.resizable(True, True)
# newWindow = SubWindow(nroot, songData[0], songData[1], songData[2])
def SortClick(self,event):
def TreeviewSortColumn(col):
startTime = time.perf_counter_ns()
if self.dataSortMethodsort[0] == col:
self.dataSortMethodsort[1] = not self.dataSortMethodsort[1]
else:
self.dataSortMethodsort[0] = col
self.dataSortMethodsort[1] = True
if col == 'SyncNumber' or col == 'UploadScore':
l = [(float((self.saveData.set(k, col))[:-1]), k) for k in self.saveData.get_children('')]
elif col == 'PlayCount':
l = [(int(self.saveData.set(k, col)), k) for k in self.saveData.get_children('')]
elif col == 'SongName':
l = [((self.saveData.set(k, col)).lower(), k) for k in self.saveData.get_children('')]
else:
l = [(self.saveData.set(k, col), k) for k in self.saveData.get_children('')]
l.sort(reverse=self.dataSortMethodsort[1])
for index, (val, k) in enumerate(l):
self.saveData.move(k, '', index)
endTime = time.perf_counter_ns()
print("SortClick Run Time: %f ms"%((endTime - startTime)/1000000))
self.TreeviewColumnUpdate()
if isinstance(event, list):
self.dataSortMethodsort[1] = not self.dataSortMethodsort[1]
TreeviewSortColumn(event[0])
for col in self.treeviewColumns:
self.saveData.heading(col, command=lambda _col=col:TreeviewSortColumn(_col))
def StartGame(self,event):
if self.isGameRunning["text"] == '游戏未启动':
os.system('start steam://rungameid/952040')
else:
messagebox.showinfo("Info", '游戏已启动')
def F5Key(self,event):
self.DeleteAnalyzeFile()
# update功能组
def CheckJsonUpdate(self):
startTime = time.perf_counter_ns()
try:
response = requests.get("https://raw.githubusercontent.com/Ginsakura/MUSYNCSave/main/musync_data/songname.update")
githubVersion = response.content.decode('utf8')
with open("./musync_data/SongName.update",'r',encoding='utf8') as snju:
localVersion = snju.read()
print(f" Local Json Version: {localVersion}")
print(f" Terget Json Version: {githubVersion}")
if githubVersion>localVersion:
response = requests.get("https://raw.githubusercontent.com/Ginsakura/MUSYNCSave/main/musync_data/songname.json")
songNameJson = response.json()
with open("./musync_data/SongName.json",'w',encoding='utf8') as snj:
json.dump(songNameJson,snj,indent="",ensure_ascii=False)
with open("./musync_data/SongName.update",'r',encoding='utf8') as snju:
snju.write(githubVersion)
except Exception as e:
messagebox.showerror("Error", f'发生错误: {e}')
if messagebox.askyesno("无法获取谱面信息更新", f'是否前往网页查看是否存在更新?\n(请比对 SongName.update 中的时间是否比本地文件中的时间更大)'):
webbrowser.open("https://raw.githubusercontent.com/Ginsakura/MUSYNCSave/main/musync_data/songname.update")
endTime = time.perf_counter_ns()
print("CheckJsonUpdate Run Time: %f ms"%((endTime - startTime)/1000000))
def CheckUpdate(self):
startTime = time.perf_counter_ns()
localVersion = float(self.version.replace(".","").replace("rc","."))
try:
response = requests.get("https://api.github.com/repos/ginsakura/MUSYNCSave/releases/latest")
# print(response.json())
resJson = response.json()
if "tag_name" in resJson:
tagVersion = response.json()["tag_name"]
tergetVersion = float(tagVersion.replace(".","").replace("rc","."))
elif "message" in resJson:
if resJson["message"][:23] == "API rate limit exceeded":
if messagebox.askyesno("GitHub公共API访问速率已达上限", "是否前往发布页查看是否存在更新?"):
webbrowser.open("https://github.com/Ginsakura/MUSYNCSave/releases/latest")
return
except Exception as e:
messagebox.showerror("Error", f'发生错误: {e}')
tergetVersion = localVersion
# print(localVersion,tergetVersion)
print(' Terget Version : %s'%tagVersion.replace("rc","."))
print(' Local Version : %s'%self.version.replace("rc","."))
print("Local PreVersion : %s"%self.preVersion.replace("pre","."))
if (tergetVersion > localVersion):
self.gitHubLink.configure(text=f'有新版本啦——点此打开下载页面 NewVersion: {tagVersion}', anchor="center")
self.gitHubLink.configure(command=lambda:webbrowser.open(f"https://github.com/Ginsakura/MUSYNCSave/releases/tag/{tagVersion}"))
self.UpdateTip()
else:
self.gitHubLink.configure(text='点击打开GitHub仓库 点个Star吧,秋梨膏', anchor="center")
self.gitHubLink.configure(command=lambda:webbrowser.open("https://github.com/Ginsakura/MUSYNCSave"))
endTime = time.perf_counter_ns()
print("CheckUpdate Run Time: %f ms"%((endTime - startTime)/1000000))
def UpdateTip(self):
if self.gitHubLink.cget('fg') == '#C4245C':
self.gitHubLink.configure(fg='#4BB1DA')
else:
self.gitHubLink.configure(fg='#C4245C')
self.root.after(500,self.UpdateTip)
# 初始化提示框
def InitLabel(self,text,close=False):
self.initLabel.place(x=250,y=300,width=500,height=30)
self.initLabel.configure(text=text, anchor="w")
self.root.update()
if close:
self.initLabel.place(x=-1,width=0)
# 数据分析功能组
def GetSaveFile(self):
startTime = time.perf_counter_ns()
self.InitLabel("正在搜索存档文件中……")
saveFilePath = None
for ids in "DEFCGHIJKLMNOPQRSTUVWXYZAB":
if os.path.isfile(f'{ids}:/Program Files/steam/steamapps/common/MUSYNX/SavesDir/savedata.sav'):
saveFilePath = f"{ids}:/Program Files/steam/steamapps/common/MUSYNX/"
break
elif os.path.isfile(f'{ids}:/SteamLibrary/steamapps/common/MUSYNX/SavesDir/savedata.sav'):
saveFilePath = f"{ids}:/SteamLibrary/steamapps/common/MUSYNX/"
break
elif os.path.isfile(f'{ids}:/steam/steamapps/common/MUSYNX/SavesDir/savedata.sav'):
saveFilePath = f"{ids}:/steam/steamapps/common/MUSYNX/"
break
print("savefilepath:",saveFilePath)
if not saveFilePath == None:
with open('./musync_data/SaveFilePath.sfp','w',encoding="utf8") as sfp:
sfp.write(saveFilePath+'SavesDir/savedata.sav')
self.saveFilePathVar.set(saveFilePath+'SavesDir/savedata.sav')
if self.config['MainExecPath'] != saveFilePath:
self.config['MainExecPath'] = saveFilePath
json.dump(self.config,open('./musync_data/ExtraFunction.cfg','w',encoding='utf8'),indent="",ensure_ascii=False)
else:
self.InitLabel("搜索不到存档文件.")
endTime = time.perf_counter_ns()
print("GetSaveFile Run Time: %f ms"%((endTime - startTime)/1000000))
def DeleteAnalyzeFile(self):
if os.path.isfile("./musync_data/SavAnalyze.json"):
os.remove("./musync_data/SavAnalyze.json")
if os.path.isfile("./musync_data/SavAnalyze.analyze"):
os.remove("./musync_data/SavAnalyze.analyze")
if os.path.isfile("./musync_data/SavDecode.decode"):
os.remove("./musync_data/SavDecode.decode")
self.DataLoad()
def HitDelay(self):
if not HitDelayCheck().DLLCheck():
messagebox.showerror("Error", f'DLL注入失败:软件版本过低或者游戏有更新,\n请升级到最新版或等待开发者发布新的补丁')
else:
nroot = Toplevel(self.root)
nroot.resizable(True, True)
HitDelayText(nroot)
def DataLoad(self):
startTime = time.perf_counter_ns()
self.InitLabel(text="正在分析存档文件中……")
def Rank(sync):
sync = float(sync[0:-1])
if sync < 75:return "C"
elif sync < 95:return "B"
elif sync < 110:return "A"
elif sync < 117:return "S"
elif sync < 120:return "蓝Ex"
elif sync < 122:return "红Ex"
else:return "黑Ex"
if os.path.isfile('./musync_data/SavAnalyze.json'):pass
elif os.path.isfile('./musync_data/SavDecode.decode'):MusyncSavDecode.MUSYNCSavProcess(decodeFile='./musync_data/SavDecode.decode').Main('decode')
else:
if self.saveFilePathVar.get() == 'Input SaveFile or AnalyzeFile Path (savedata.sav)or(SavAnalyze.json)':
self.SelectPath()
MusyncSavDecode.MUSYNCSavProcess(self.saveFilePathVar.get()).Main()
saveData = open(f'./musync_data/SavAnalyze.json','r+',encoding='utf8')
saveDataJson = json.load(saveData)
saveData.close()
self.InitLabel('正在分析存档文件中……')
with open(f'./musync_data/SavAnalyze.json','r',encoding='utf8') as saveData:
saveDataJson = json.load(saveData)
with open("./musync_data/SongName.json",'r',encoding='utf8') as snj:
songNameJson = json.load(snj)
self.root.title(f'同步音律喵赛克Steam端本地存档分析 LastPlay: {saveDataJson["LastPlay"]}')
[self.saveData.delete(ids) for ids in self.saveData.get_children()]
self.saveCount = 0
self.totalSync = 0
for saveLine in saveDataJson['SaveData']:
if not saveLine['SongName'] is None:
if (self.keys==1) and (saveLine['SongName'][1]=='6Key'):continue
elif (self.keys==2) and (saveLine['SongName'][1]=='4Key'):continue
if (self.difficute==0) and (not saveLine['SongName'][2]=='Easy'):continue
elif (self.difficute==1) and (not saveLine['SongName'][2]=='Hard'):continue
elif (self.difficute==2) and (not saveLine['SongName'][2]=='Inferno'):continue
if (self.isDLC==1) and (not saveLine['SongName'][0] in songNameJson["NotDLCSong"]):continue
elif (self.isDLC==2) and (saveLine['SongName'][0] in songNameJson["NotDLCSong"]):continue
if self.dataSelectMethod == "Played":
if (saveLine["PlayCount"] == 0) and (float(saveLine["SyncNumber"][0:-1]) == 0):continue
elif self.dataSelectMethod == "Unplay":
if not ((saveLine["PlayCount"] == 0) and (float(saveLine["SyncNumber"][0:-1]) == 0)):continue
elif self.dataSelectMethod == "IsFav":
if saveLine["Status"] != 'Favo':continue
elif self.dataSelectMethod == "Sync122":
if float(saveLine["SyncNumber"][0:-1]) < 122:continue
elif self.dataSelectMethod == "Sync120":
if (float(saveLine["SyncNumber"][0:-1]) < 120) or (float(saveLine["SyncNumber"][0:-1]) > 122):continue
elif self.dataSelectMethod == "RankEX":
if float(saveLine["SyncNumber"][0:-1]) < 117:continue
elif self.dataSelectMethod == "RankS":
if (float(saveLine["SyncNumber"][0:-1]) < 110) or (float(saveLine["SyncNumber"][0:-1]) >= 117):continue
elif self.dataSelectMethod == "RankA":
if (float(saveLine["SyncNumber"][0:-1]) < 95) or (float(saveLine["SyncNumber"][0:-1]) >= 110):continue
elif self.dataSelectMethod == "RankB":
if (float(saveLine["SyncNumber"][0:-1]) < 75) or (float(saveLine["SyncNumber"][0:-1]) >= 95):continue
elif self.dataSelectMethod == "RankC":
if (float(saveLine["SyncNumber"][0:-1]) == 0) or (float(saveLine["SyncNumber"][0:-1]) >= 75):continue
if saveLine["Status"] in [' ', 'Favo']:
self.saveCount += 1
self.totalSync += float(saveLine["UploadScore"][0:-1])
else:
self.excludeCount += 1
self.saveData.insert('', END, values=(saveLine["SpeedStall"], #谱面号
("" if saveLine["SongName"] is None else saveLine["SongName"][0]), #曲名
("" if saveLine["SongName"] is None else saveLine["SongName"][1]), #键数
("" if saveLine["SongName"] is None else saveLine["SongName"][2]), #难度
("" if saveLine["SongName"] is None else ("" if saveLine["SongName"][3]=="00" else saveLine["SongName"][3])), #等级
saveLine["SyncNumber"], #本地同步率
("" if ((saveLine["PlayCount"] == 0) and (saveLine["UploadScore"] == "0.00000000000000%")) else Rank(saveLine["SyncNumber"])), #Rank
saveLine["UploadScore"], saveLine["PlayCount"], saveLine["Status"]))
# print(songNameJson["NotDLCSong"])
if not self.dataSortMethodsort[0] is None:
self.SortClick(self.dataSortMethodsort)
self.InitLabel('数据展示生成完成.',close=True)
endTime = time.perf_counter_ns()
print("DataLoad Run Time: %f ms"%((endTime - startTime)/1000000))
self.UpdateWindowInfo()
# 控件更新功能组
def TreeviewColumnUpdate(self):
self.saveData.heading("SpeedStall",anchor="center",text="谱面号"+(('⇓' if self.dataSortMethodsort[1] else '⇑') if self.dataSortMethodsort[0]=='SpeedStall' else ''))
self.saveData.heading("SongName",anchor="center",text="曲名"+(('⇓' if self.dataSortMethodsort[1] else '⇑') if self.dataSortMethodsort[0]=='SongName' else ''))
self.saveData.heading("Keys",anchor="center",text="键数"+(('⇓' if self.dataSortMethodsort[1] else '⇑') if self.dataSortMethodsort[0]=='Keys' else ''))
self.saveData.heading("Difficulty",anchor="center",text="难度"+(('⇓' if self.dataSortMethodsort[1] else '⇑') if self.dataSortMethodsort[0]=='Difficulty' else ''))
self.saveData.heading("DifficultyNumber",anchor="center",text="等级"+(('⇓' if self.dataSortMethodsort[1] else '⇑') if self.dataSortMethodsort[0]=='DifficultyNumber' else ''))
self.saveData.heading("SyncNumber",anchor="center",text="同步率"+(('⇓' if self.dataSortMethodsort[1] else '⇑') if self.dataSortMethodsort[0]=='SyncNumber' else ''))
self.saveData.heading("Rank",anchor="center",text="Rank"+(('⇓' if self.dataSortMethodsort[1] else '⇑') if self.dataSortMethodsort[0]=='Rank' else ''))
self.saveData.heading("UploadScore",anchor="center",text="云端同步率"+(('⇓' if self.dataSortMethodsort[1] else '⇑') if self.dataSortMethodsort[0]=='UploadScore' else ''))
self.saveData.heading("PlayCount",anchor="center",text="游玩计数"+(('⇓' if self.dataSortMethodsort[1] else '⇑') if self.dataSortMethodsort[0]=='PlayCount' else ''))
self.saveData.heading("Status",anchor="center",text="Status"+(('⇓ ' if self.dataSortMethodsort[1] else '⇑ ') if self.dataSortMethodsort[0]=='Status' else ' '))
self.root.update()
def TreeviewWidthUptate(self):
self.saveData.column("SpeedStall",anchor="e",width=90)
self.saveData.column("SongName",anchor="w",width=self.windowInfo[2]-771)
self.saveData.column("Keys",anchor="center",width=60)
self.saveData.column("Difficulty",anchor="w",width=65)
self.saveData.column("DifficultyNumber",anchor="center",width=60)
self.saveData.column("SyncNumber",anchor="e",width=80)
self.saveData.column("Rank",anchor="center",width=55)
self.saveData.column("UploadScore",anchor="e",width=160)
self.saveData.column("PlayCount",anchor="e",width=90)
self.saveData.column("Status",anchor="w",width=80)
def UpdateWindowInfo(self):
self.windowInfo = ['root.winfo_x()','root.winfo_y()',self.root.winfo_width(),self.root.winfo_height()]
self.saveFilePathEntry.place(x=170,y=10,width=(self.windowInfo[2]-260),height=30)
self.getSaveFilePath.place(x=(self.windowInfo[2]-90),y=10,width=90,height=30)
self.saveData.place(x=0 ,y=130 ,width=(self.windowInfo[2]-1) ,height=(self.windowInfo[3]-160))
if not self.wh == self.windowInfo[2:]:
self.TreeviewWidthUptate()
self.VScroll1.place(x=self.windowInfo[2]-22, y=1, width=20, height=self.windowInfo[3]-162)
# self.saveCountVar.set()
self.saveCountLabel.configure(text=str(self.saveCount+self.excludeCount))
self.avgSyncLabel.configure(text=f'{(self.totalSync / (1 if self.saveCount==0 else self.saveCount)):.6f}%')
self.developer.place(x=0,y=self.windowInfo[3]-30,width=420,height=30)
self.gitHubLink.place(x=420,y=self.windowInfo[3]-30,width=self.windowInfo[2]-420,height=30)
self.isGameRunning.bind('<Button-1>', self.StartGame)
self.saveData.bind("<Double-1>",self.DoubleClick)
self.saveData.bind("<ButtonRelease-1>",self.SortClick)
self.root.bind("<F5>", self.F5Key)
self.wh = self.windowInfo[2:]
self.root.update()
# if self.after == False:
# self.after = True
# self.root.after(100,self.UpdateWindowInfo)
class SubWindow(object):
def __init__(self, nroot, songID, songName, songDifficute):
##Init##
nroot.iconbitmap('./musync_data/Musync.ico')
super(SubWindow, self).__init__()
self.font=('霞鹜文楷等宽',16)
nroot.geometry(f'1000x630+500+300')
style = ttk.Style()
style.configure("Treeview", rowheight=20, font=('霞鹜文楷等宽',12))
style.configure("Treeview.Heading", rowheight=20, font=('霞鹜文楷等宽',12))
nroot.title(f"{songID}:{songName}:{songDifficute} 全球排行")
nroot['background'] = '#efefef'
self.root = nroot
self.songID = songID
self.globalSync = ttk.Treeview(self.root, show="headings")
self.globalSync.configure(columns = ['SongName',"Difficulty","Rank","SyncNumber"])
self.VScroll = Scrollbar(self.globalSync, orient='vertical', command=self.globalSync.yview)
self.TIPS = Label(self.root, text="这里还没有被实现鸭——", relief="groove", font=('霞鹜文楷等宽',15))
self.TIPS.place(x=10,y=10,width=300,height=30)
##AutoRun##
self.UpdateWindow()
def UpdateWindow(self):
self.root.update()
self.windowInfo = ['root.winfo_x()','root.winfo_y()',root.winfo_width(),root.winfo_height()]
self.globalSync.place(x=10 ,y=10 ,width=(self.windowInfo[2]-20) ,height=(self.windowInfo[3]-20))
self.globalSync.column("SongName",anchor="w",width=100)
self.globalSync.heading("SongName",anchor="center",text="曲名")
self.globalSync.column("Difficulty",anchor="w",width=90)
self.globalSync.heading("Difficulty",anchor="center",text="难度")
self.globalSync.column("Rank",anchor="e",width=90)
self.globalSync.heading("Rank",anchor="center",text="Rank")
self.globalSync.column("SyncNumber",anchor="e",width=70)
self.globalSync.heading("SyncNumber",anchor="center",text="同步率")
self.VScroll.place(x=self.windowInfo[2]-40, y=1, width=20, relheight=1)
if __name__ == '__main__':
version = '0.0.0rc0'
isPreRelease = True
preVersion = "9.9.9pre9"
root = Tk()
ctypes.windll.shcore.SetProcessDpiAwareness(1)
fonts = list(font.families())
Functions.CheckFileBeforeStarting(fonts)
del fonts
Functions.CheckConfig()
with open('./musync_data/ExtraFunction.cfg','r',encoding='utf8') as cfg:
cfg = json.load(cfg)
if cfg['ChangeConsoleStyle']:
Functions.ChangeConsoleStyle()
root.tk.call('tk', 'scaling', 1.25)
root.resizable(False, True) #允许改变窗口高度,不允许改变窗口宽度
window = MusyncSavDecodeGUI(root=root,version=version,preVersion=preVersion,isPreRelease=isPreRelease)
root.update()
root.mainloop()