-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwin32_details.py
116 lines (90 loc) · 3.44 KB
/
win32_details.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
# win32-details extension for Nautilus
# Copyright 2022 tfuxu <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
import hashlib
import exiftool
from urllib.parse import unquote
from gi.repository import GObject, Gio, Nautilus, GLib
details_list = [
["File Description", ""],
["Comments", ""],
["File Type", ""],
["File Version", ""],
["Product Name", ""],
["Product Version", ""],
["Legal Copyright", ""],
["File Size", ""],
["Modify Date", ""],
["Language", ""],
["MD5 Hash", ""]
]
tags = [
"EXE:FileDescription",
"EXE:Comments",
"File:FileType",
"EXE:FileVersionNumber",
"EXE:ProductName",
"EXE:ProductVersion",
"EXE:LegalCopyright",
"File:FileSize",
"File:FileModifyDate",
"EXE:LanguageCode"
]
class MorePropsModel(Nautilus.PropertiesModelProvider, GObject.GObject):
def __init__(self):
pass
def log_debug(self, message):
message = f"win32-details: {message}"
variant_message = GLib.Variant("s", message)
GLib.log_variant(None, GLib.LogLevelFlags.LEVEL_DEBUG, GLib.Variant("a{sv}", {"MESSAGE": variant_message}))
def get_models(self, files):
# Check if its just a one file, or couple of files
if len(files) != 1:
self.log_debug("FILES INVASION!!!1")
return
# File path in its URI form
file = files[0]
# Checkings, to ensure that we are dealing with a file and not with a shortcut or a folder
if file.get_uri_scheme() != "file":
return
if file.is_directory():
return
# Check if file has a '.exe' extension
if file.get_uri()[-4:] != ".exe":
return
# Clean details list before doing anything with it
for i, value in enumerate(details_list):
details_list[i][1] = ""
# Convert URI to normal file path
filename = unquote(file.get_uri()[7:])
md5sum = hashlib.md5(filename.encode("utf-8")).hexdigest()
# The parsing machine
with exiftool.ExifToolHelper(common_args=['-G']) as et:
manifest = None
for full_data in et.get_tags([filename], tags=tags):
manifest = full_data
manifest.pop("SourceFile")
for meta, data in manifest.items():
for i, mtags in zip(range(len(tags)), tags):
if meta == mtags:
if type(data) == str:
details_list[i][1] = data.strip()
else:
try:
details_list[i][1] = str(data)
except TypeError as e:
self.log_debug(f"Unexpected data type inside metadata. Exc: {e}")
else:
continue
details_list[-1][1] = md5sum
# Setup ListStore for Nautilus.PropertiesModel content model
self.contentstore = Gio.ListStore.new(item_type=Nautilus.PropertiesItem)
for details_ref in details_list:
list_item = Nautilus.PropertiesItem(
name = details_ref[0],
value = details_ref[1]
)
self.contentstore.append(list_item)
# Return to API handler as Nautilus.PropertiesModel object
return Nautilus.PropertiesModel(title="More Properties",
model=self.contentstore),