|
22 | 22 | # turing-theme-extractor.py: Extract resources from a Turing Smart Screen theme (.data files) made for Windows app |
23 | 23 | # This program will search and extract PNGs from the theme data and extract theme in the current directory |
24 | 24 | # The PNG can then be re-used to create a theme for System Monitor python program (see Wiki for theme creation) |
| 25 | +# To run for all files of a folder: |
| 26 | +# for file in "FOLDER"/*; do if [ -f "$file" ]; then python turing-theme-extractor.py "$file"; fi; done |
25 | 27 | import mmap |
26 | 28 | import os |
27 | 29 | import sys |
| 30 | +from pathlib import Path |
28 | 31 |
|
29 | 32 | PNG_SIGNATURE = b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A' |
30 | 33 | PNG_IEND = b'\x49\x45\x4E\x44\xAE\x42\x60\x82' |
|
46 | 49 | with open(sys.argv[1], "r+b") as theme_file: |
47 | 50 | mm = mmap.mmap(theme_file.fileno(), 0) |
48 | 51 |
|
| 52 | + theme_name = Path(sys.argv[1]).stem |
| 53 | + |
| 54 | + if not os.path.isdir(theme_name): |
| 55 | + os.makedirs(theme_name) |
| 56 | + |
49 | 57 | # Find PNG signature in binary data |
50 | 58 | start_pos=0 |
51 | 59 | header_found = mm.find(PNG_SIGNATURE, 0) |
|
59 | 67 |
|
60 | 68 | # Extract PNG data to a file |
61 | 69 | theme_file.seek(header_found) |
62 | | - png_file = open('theme_res_' + str(header_found) + '.png', 'wb') |
| 70 | + png_file = open(theme_name + "/" + str(header_found) + '.png', 'wb') |
63 | 71 | png_file.write(theme_file.read(iend_found - header_found + len(PNG_IEND))) |
64 | 72 | png_file.close() |
65 | 73 |
|
66 | | - print("PNG extracted to theme_res_%s.png" % str(header_found)) |
| 74 | + print("PNG extracted to %s/%s.png" % (theme_name, str(header_found))) |
67 | 75 | found_png = found_png + 1 |
68 | 76 |
|
69 | 77 | # Find next PNG signature (if any) |
70 | 78 | header_found = mm.find(PNG_SIGNATURE, iend_found) |
71 | 79 |
|
72 | 80 | print("\n%d PNG files extracted from theme to current directory" % found_png) |
73 | | - |
|
0 commit comments