-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtools.py
More file actions
88 lines (64 loc) · 2.29 KB
/
Copy pathtools.py
File metadata and controls
88 lines (64 loc) · 2.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
import os
import sys
# print(filePath)
# d = {'username': '123131231', 'passwd': '1233333', 'ip': '120.1.1.1'}
class cache:
homePath = os.path.expanduser("~")
cachePath = os.path.join(homePath, ".cache", "zkNet")
filePath = os.path.join(cachePath, "zkNet.cache")
def checkCache(self) -> bool:
if os.path.exists(self.filePath):
return True
else:
return False
def cacheInfo(self, infoDict: dict[str, str]):
dictStr = ""
for k, v in infoDict.items():
dictStr += "%s = %s\n" % (k, v)
if not os.path.exists(self.cachePath):
os.makedirs(self.cachePath)
with open(self.filePath, "w", encoding="utf-8") as f:
f.write(dictStr)
def readCache(self) -> dict[str, str] | None:
if not os.path.exists(self.filePath):
return None
with open(self.filePath, "r", encoding="utf-8") as f:
dictStr = f.read()
rDict = {}
for line in dictStr.strip().splitlines():
k, v = tuple(i.strip() for i in line.split("="))
rDict[k] = v
return rDict
def removeCache(self):
if os.path.exists(self.filePath):
os.remove(self.filePath)
if os.listdir(self.cachePath) == []:
os.rmdir(self.cachePath)
# 可能被杀软误杀
class startup4Win:
homePath = os.path.expanduser("~")
zkNetPath = os.path.realpath(sys.argv[0])
batPath = r"AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
batPath = os.path.join(homePath, batPath, "zkNet.bat")
batContent = r'start "" "%s"' % zkNetPath
def updateStartup(self, startup: bool):
if not startup:
self.delStartup()
return
if not self.checkStartup():
self.addStartup()
def checkStartup(self) -> bool:
if not os.path.exists(self.batPath):
return False
with open(self.batPath, "r") as f:
content = f.read()
if content != self.batContent:
return False
return True
def addStartup(self):
with open(self.batPath, "w") as f:
f.write(self.batContent)
def delStartup(self):
if os.path.exists(self.batPath):
os.remove(self.batPath)
# addToStartup4Win()