-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions.py
176 lines (168 loc) · 6.75 KB
/
Functions.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
import ctypes
import json
import os
import sqlite3 as sql
import winreg
from win32 import win32gui, win32print
from win32.lib import win32con
from win32.win32api import GetSystemMetrics
import FileExport
def GetDpi():
hDC = win32gui.GetDC(0)
relw = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES)
relh = win32print.GetDeviceCaps(hDC, win32con.DESKTOPVERTRES)
w = GetSystemMetrics (0)
h = GetSystemMetrics (1)
real_resolution = [relw,relh]
screen_size = [w,h]
return int(round(real_resolution[0] / screen_size[0], 2) * 100)
def ChangeConsoleStyle():
# print('Changing Console Style...')
with open('./musync_data/ExtraFunction.cfg','r',encoding='utf8') as cfg:
cfg = json.load(cfg)
execPath = cfg['MainExecPath']
execPath = execPath.replace('/','_')+'musynx.exe'
# print(execPath)
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Console',reserved=0, access=winreg.KEY_WRITE)
winreg.CreateKey(regkey,execPath)
regkey.Close()
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, f'Console\\{execPath}',reserved=0, access=winreg.KEY_WRITE)
winreg.SetValueEx(regkey,'CodePage',0,winreg.REG_DWORD,65001)
winreg.SetValueEx(regkey,'WindowSize',0,winreg.REG_DWORD,262174)
winreg.SetValueEx(regkey,'WindowAlpha',0,winreg.REG_DWORD,(cfg['ConsoleAlpha']*255//100))
winreg.SetValueEx(regkey,'FaceName',0,winreg.REG_SZ,'霞鹜文楷等宽')
winreg.SetValueEx(regkey,'FontSize',0,winreg.REG_DWORD,(cfg['ConsoleFontSize'] << 16))
regkey.Close()
def CheckFileBeforeStarting(fonts):
if os.path.exists('./musync/'):
os.rename('./musync/','./musync_data/')
if not os.path.exists('./musync_data/'):
os.makedirs('./musync_data/')
if not os.path.isfile('./musync_data/MUSYNC.ico'):
FileExport.WriteIcon()
if not os.path.isfile('./musync_data/ExtraFunction.cfg'):
cfgData = "{\n\"EnableAcc-Sync\": true,\n\"DisableCheckUpdate\": false,\n\"EnableAnalyzeWhenStarting\": false,\n\"EnableDLLInjection\": true,\n\"SystemDPI\": 100,\n\"EnableDonutChartinHitDelay\": true,\n\"EnableDonutChartinAllHitAnalyze\": true,\n\"EnablePDFofCyanExact\": true,\n\"EnableNarrowDelayInterval\": true,\n\"ConsoleAlpha\": 75,\n\"ConsoleFont\": \"霞鹜文楷等宽\",\n\"ConsoleFontSize\": 36,\n\"MainExecPath\": \"\",\n\"ChangeConsoleStyle\": true,\n\"EnableFramelessWindow\": false,\n\"TransparentColor\": \"#FFFFFF\"\n}"
with open('./musync_data/ExtraFunction.cfg','w',encoding='utf8') as cfg:
cfg.write(cfgData)
del cfgData
if (not os.path.isfile('./musync_data/SongName.json')) or (not os.path.isfile('./musync_data/SongName.update')) or (FileExport.snjU > int(open('./musync_data/songname.update','r').read())):
FileExport.WriteSongNameJson()
if not os.path.isfile('./musync_data/ExtraFunction.cfg'):
json.dump({"DisableCheckUpdate": False,"EnableDLLInjection": False},
open('./musync_data/ExtraFunction.cfg','w'),indent="",ensure_ascii=False)
if not '霞鹜文楷等宽' in fonts:
if not os.path.isfile('./musync_data/LXGW.ttf'):
FileExport.WriteTTF()
os.system(f'{os.getcwd()}/musync_data/LXGW.ttf')
if not os.path.exists("./skin/"):
os.makedirs('./skin/')
if (not os.path.isfile('./musync_data/HitDelayHistory_v2.db')) and os.path.isfile('./musync_data/HitDelayHistory.db'):
db = sql.connect('./musync_data/HitDelayHistory.db')
cur = db.cursor()
testData = cur.execute("SELECT * from HitDelayHistory limit 1")
testData = testData.fetchone()
# print(len(testData))
if len(testData) != 6:
print("记录数据迁移中...")
ndb = sql.connect('./musync_data/HitDelayHistorytemp.db')
ncur = ndb.cursor()
ncur.execute("""CREATE table HitDelayHistory (
SongMapName text Not Null,
RecordTime text Not Null,
AvgDelay float,
AllKeys int,
AvgAcc float,
HitMap text,
PRIMARY KEY ("SongMapName", "RecordTime"))""")
for ids in cur.execute("SELECT * from HitDelayHistory").fetchall():
nameAndTime = ids[0].split("-202")
name = nameAndTime[0]
recordTime = "202%s"%nameAndTime[1]
avgDelay = ids[1]
allKeys = ids[2]
avgAcc = ids[3]
dataList = ids[4]
print("正在迁移%s %s"%(name,recordTime))
ncur.execute("INSERT into HitDelayHistory values(?,?,?,?,?,?)",(name,recordTime,avgDelay,allKeys,avgAcc,dataList))
ndb.commit()
ndb.close()
db.close()
# os.chdir()
os.remove("./musync_data/HitDelayHistory.db")
os.rename("./musync_data/HitDelayHistorytemp.db", "./musync_data/HitDelayHistory_v2.db")
else:
db.close()
os.rename("./musync_data/HitDelayHistory.db", "./musync_data/HitDelayHistory_v2.db")
print("记录数据无需迁移.")
def CheckConfig():
try:
with open('./musync_data/ExtraFunction.cfg','r',encoding='utf8') as cfg:
cfg = json.load(cfg)
except UnicodeDecodeError:
with open('./musync_data/ExtraFunction.cfg','r',encoding='gbk') as cfg:
cfg = json.load(cfg)
json.dump(cfg,open('./musync_data/ExtraFunction.cfg','w',encoding='utf8'),indent="",ensure_ascii=False)
except Exception as e:
raise e
with open('./musync_data/ExtraFunction.cfg','r',encoding='utf8') as cfg:
cfg = json.load(cfg)
isChange = False
if 'EnableAcc-Sync' not in cfg:
cfg['EnableAcc-Sync'] = False
isChange = True
if 'DisableCheckUpdate' not in cfg:
cfg['DisableCheckUpdate'] = False
isChange = True
if 'EnableAnalyzeWhenStarting' not in cfg:
cfg['EnableAnalyzeWhenStarting'] = False
isChange = True
if 'EnableDLLInjection' not in cfg:
cfg['EnableDLLInjection'] = False
isChange = True
if 'EnableDonutChartinHitDelay' not in cfg:
cfg['DonutChartinHitDelay'] = False
isChange = True
if 'EnableDonutChartinAllHitAnalyze' not in cfg:
cfg['EnableDonutChartinAllHitAnalyze'] = False
isChange = True
if 'EnableNarrowDelayInterval' not in cfg:
cfg['EnableNarrowDelayInterval'] = True
isChange = True
if 'ConsoleAlpha' not in cfg:
cfg['ConsoleAlpha'] = 75
isChange = True
if 'ConsoleFont' not in cfg:
cfg['ConsoleFont'] = '霞鹜文楷等宽'
isChange = True
if 'ConsoleFontSize' not in cfg:
cfg['ConsoleFontSize'] = 36
isChange = True
if 'MainExecPath' not in cfg:
cfg['MainExecPath'] = ''
isChange = True
if 'ChangeConsoleStyle' not in cfg:
cfg['ChangeConsoleStyle'] = False
isChange = True
if 'EnableFramelessWindow' not in cfg:
cfg['EnableFramelessWindow'] = False
isChange = True
if 'TransparentColor' not in cfg:
cfg['TransparentColor'] = "#FFFFFF"
isChange = True
dpi = ctypes.windll.shcore.GetScaleFactorForDevice(0) # GetDpi()
if 'SystemDPI' not in cfg:
cfg['SystemDPI'] = dpi
isChange = True
elif dpi != cfg['SystemDPI']:
cfg['SystemDPI'] = dpi
isChange = True
if "DefaultKeys" not in cfg:
cfg["DefaultKeys"] = False
isChange = True
if "DefaultDiffcute" not in cfg:
cfg["DefaultDiffcute"] = 0
isChange = True
if isChange:
json.dump(cfg,open('./musync_data/ExtraFunction.cfg','w',encoding='utf8'),indent="",ensure_ascii=False)
if __name__ == '__main__':
print(GetDpi())