1
1
import psutil
2
2
from pypresence import Presence
3
3
import time
4
-
4
+ import win32api
5
5
6
6
def checkprocess (targetname ):
7
7
for proc in psutil .process_iter ():
@@ -12,6 +12,43 @@ def checkprocess(targetname):
12
12
psutil .ZombieProcess ):
13
13
pass
14
14
return False
15
+ def get_file_properties (fname ):
16
+ """
17
+ Read all properties of the given file return them as a dictionary.
18
+ """
19
+ prop_names = ('Comments' , 'InternalName' , 'ProductName' ,
20
+ 'CompanyName' , 'LegalCopyright' , 'ProductVersion' ,
21
+ 'FileDescription' , 'LegalTrademarks' , 'PrivateBuild' ,
22
+ 'FileVersion' , 'OriginalFilename' , 'SpecialBuild' )
23
+
24
+ props = {'FixedFileInfo' : None , 'StringFileInfo' : None , 'FileVersion' : None }
25
+
26
+ # try:
27
+ # backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc
28
+ fixed_info = win32api .GetFileVersionInfo (fname , '\\ ' )
29
+ props ['FixedFileInfo' ] = fixed_info
30
+ props ['FileVersion' ] = "%d.%d.%d.%d" % (fixed_info ['FileVersionMS' ] / 65536 ,
31
+ fixed_info ['FileVersionMS' ] % 65536 ,
32
+ fixed_info ['FileVersionLS' ] / 65536 ,
33
+ fixed_info ['FileVersionLS' ] % 65536 )
34
+
35
+ # \VarFileInfo\Translation returns list of available (language, codepage)
36
+ # pairs that can be used to retreive string info. We are using only the first pair.
37
+ lang , codepage = win32api .GetFileVersionInfo (fname , '\\ VarFileInfo\\ Translation' )[0 ]
38
+
39
+ # any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle
40
+ # two are language/codepage pair returned from above
41
+
42
+ str_info = {}
43
+ for propName in prop_names :
44
+ str_info_path = u'\\ StringFileInfo\\ %04X%04X\\ %s' % (lang , codepage , propName )
45
+ str_info [propName ] = win32api .GetFileVersionInfo (fname , str_info_path )
46
+
47
+ props ['StringFileInfo' ] = str_info
48
+ # except:
49
+ # pass
50
+
51
+ return props
15
52
16
53
if __name__ == "__main__" :
17
54
@@ -24,14 +61,17 @@ def checkprocess(targetname):
24
61
25
62
client_id = '1013717821122936873' # Fake ID, put your real one here
26
63
RPC = Presence (client_id )
27
- fpd = "flashplayer_32_sa_debug .exe"
64
+ fpd = "flashplayer_debug .exe"
28
65
fp = "flashplayer.exe"
29
66
while True : # The presence will stay on as long as the program is running
30
67
time .sleep (4 )
31
68
32
69
if checkprocess (fpd ) == True :
33
70
print ("Found Debug Build" )
34
71
TYPE = "Debug"
72
+ props = get_file_properties (fpd )
73
+ #VERSION = props['StringFileInfo']['ProductVersion']
74
+ VERSION = props ['FileVersion' ]
35
75
if DebugRunning == False and RPCRun == False :
36
76
RPC .connect ()
37
77
RPCRun = True
@@ -48,6 +88,9 @@ def checkprocess(targetname):
48
88
if checkprocess (fp ) == True :
49
89
print ("Found Standalone Build" )
50
90
TYPE = "Standard"
91
+ props = get_file_properties (fp )
92
+ #VERSION = props['StringFileInfo']['ProductVersion']
93
+ VERSION = props ['FileVersion' ]
51
94
if StandaloneRunning == False and RPCRun == False :
52
95
RPC .connect ()
53
96
RPCRun = True
@@ -62,6 +105,7 @@ def checkprocess(targetname):
62
105
RPC .close ()
63
106
64
107
if DebugRunning == True and StandaloneRunning == True :
65
- TYPE = "Multiple Running"
108
+ TYPE = "Multiple Running"
109
+ VERSION = "Multiple Running"
66
110
if RPCRun == True :
67
111
RPC .update (state = "Idle" , details = "Not Quite Dead Yet." , large_image = "afp32_big" , large_text = f"Version { VERSION } ({ TYPE } )" )
0 commit comments