|
1
|
|
|
import os.path |
|
2
|
|
|
|
|
3
|
|
|
import sublime |
|
4
|
|
|
|
|
5
|
|
|
# own dependencies |
|
6
|
|
|
from . import logger |
|
7
|
|
|
|
|
8
|
|
|
from .path.program_path_provider import get_cached_program_path |
|
9
|
|
|
from .path.setting_path_provider import get_cached_setting_path |
|
10
|
|
|
from .path.program_drive_provider import get_cached_program_drive |
|
11
|
|
|
from .path.plugin_path_provider import get_cached_plugin_path |
|
12
|
|
|
from .path.addon_path_provider import get_cached_addon_path |
|
13
|
|
|
from .path.skin_path_provider import get_cached_skin_path |
|
14
|
|
|
from .path.prompt_dialog import browse_file, browse_folder |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
def __require_path(path): |
|
18
|
|
|
if not os.path.exists(path): |
|
19
|
|
|
os.makedirs(path) |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
def __copy_on_absence_or_newer(user_path, binary_path): |
|
23
|
|
|
""" |
|
24
|
|
|
. |
|
25
|
|
|
|
|
26
|
|
|
user_path: path of the file in the user directory |
|
27
|
|
|
binary_path: Packages/Rainmeter/xxx path inside the package |
|
28
|
|
|
""" |
|
29
|
|
|
# could be already copied on a previous run |
|
30
|
|
|
need_update = not os.path.exists(user_path) |
|
31
|
|
|
binary = sublime.load_binary_resource(binary_path) |
|
32
|
|
|
|
|
33
|
|
|
# could be a newer version there |
|
34
|
|
|
# only check if no newer is required since expensive |
|
35
|
|
|
# generally happens in consecutive calls without updates |
|
36
|
|
|
if not need_update: |
|
37
|
|
|
need_update = os.path.getsize(user_path) != len(binary) |
|
38
|
|
|
if need_update: |
|
39
|
|
|
logger.info("Newer version of color picker found. Copying data over to '" + user_path + "'") |
|
40
|
|
|
with open(user_path, "wb") as file_handler: |
|
41
|
|
|
file_handler.write(binary) |
|
42
|
|
|
else: |
|
43
|
|
|
logger.info("You are using the most current version of '" + binary_path + "'. Continue loading...") |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
def plugin_loaded(): |
|
47
|
|
|
""" |
|
48
|
|
|
Called automatically from ST3 if plugin is loaded. |
|
49
|
|
|
|
|
50
|
|
|
Is required now due to async call and ignoring sublime.* from main routine |
|
51
|
|
|
""" |
|
52
|
|
|
|
|
53
|
|
|
packages = sublime.packages_path() |
|
54
|
|
|
prompt_dir = os.path.join(packages, "User", "Rainmeter", "path") |
|
55
|
|
|
|
|
56
|
|
|
__require_path(prompt_dir) |
|
57
|
|
|
|
|
58
|
|
|
open_file_dialog_bat = os.path.join(prompt_dir, "open_file_dialog.ps1") |
|
59
|
|
|
open_folder_dialog_bat = os.path.join(prompt_dir, "open_folder_dialog.ps1") |
|
60
|
|
|
|
|
61
|
|
|
__copy_on_absence_or_newer(open_file_dialog_bat, "Packages/Rainmeter/path/open_file_dialog.ps1") |
|
62
|
|
|
__copy_on_absence_or_newer(open_folder_dialog_bat, "Packages/Rainmeter/path/open_folder_dialog.ps1") |
|
63
|
|
|
|
|
64
|
|
|
program_path = get_cached_program_path() |
|
65
|
|
|
if not program_path: |
|
66
|
|
|
""" |
|
67
|
|
|
Open dialog and set program path. |
|
68
|
|
|
|
|
69
|
|
|
Due to cache this might be annoying |
|
70
|
|
|
since I cant call cached stuff |
|
71
|
|
|
before I can assure that the path is correct |
|
72
|
|
|
or just reset the cache |
|
73
|
|
|
""" |
|
74
|
|
|
|
|
75
|
|
|
def on_rainmeter_exe_browsed(message): |
|
76
|
|
|
""" |
|
77
|
|
|
If file is browsed we need to verify that this is the Rainmeter.exe. |
|
78
|
|
|
If it is we need to reset the cache via. |
|
79
|
|
|
""" |
|
80
|
|
|
if os.path.exists(message): |
|
81
|
|
|
# If file is browsed |
|
82
|
|
|
# - verify Rainmeter.exe. |
|
83
|
|
|
# - reset cache |
|
84
|
|
|
# - save new path in settings |
|
85
|
|
|
|
|
86
|
|
|
logger.info("Verified existence of Rainmeter.exe in '" + message + "'.") |
|
87
|
|
|
settings = sublime.load_settings("Rainmeter.sublime-settings") |
|
88
|
|
|
rm_dir = os.path.dirname(message) |
|
89
|
|
|
normed_rm_dir = os.path.normpath(rm_dir) |
|
90
|
|
|
|
|
91
|
|
|
settings.set("rainmeter_path", normed_rm_dir) |
|
92
|
|
|
sublime.save_settings("Rainmeter.sublime-settings") |
|
93
|
|
|
logger.info("Rewrote settings to include rainmeter path.") |
|
94
|
|
|
sublime.message_dialog("Successfully set the Rainmeter application path to '" + normed_rm_dir + "'.") |
|
95
|
|
|
|
|
96
|
|
|
# we have to reset every cache because all are dependent on the program path |
|
97
|
|
|
# at least transitively |
|
98
|
|
|
get_cached_program_path.cache_clear() |
|
99
|
|
|
get_cached_program_drive.cache_clear() |
|
100
|
|
|
get_cached_setting_path.cache_clear() |
|
101
|
|
|
get_cached_skin_path.cache_clear() |
|
102
|
|
|
get_cached_addon_path.cache_clear() |
|
103
|
|
|
get_cached_plugin_path.cache_clear() |
|
104
|
|
|
logger.info("Cleared cache.") |
|
105
|
|
|
|
|
106
|
|
|
elif message == "-1": |
|
107
|
|
|
logger.info("User canceled Rainmeter.exe input.") |
|
108
|
|
|
pass |
|
109
|
|
|
|
|
110
|
|
|
else: |
|
111
|
|
|
# retry by recalling it again. |
|
112
|
|
|
logger.info("No valid Rainmeter.exe found. Retrying again.") |
|
113
|
|
|
browse_file(on_rainmeter_exe_browsed) |
|
114
|
|
|
|
|
115
|
|
|
browse_file(on_rainmeter_exe_browsed) |
|
116
|
|
|
|
|
117
|
|
|
skin_path = get_cached_skin_path() |
|
118
|
|
|
if not skin_path: |
|
119
|
|
|
""" |
|
120
|
|
|
Open folder dialog and set skin path. |
|
121
|
|
|
""" |
|
122
|
|
|
|
|
123
|
|
|
def on_skins_folder_browsed(skin_dir): |
|
124
|
|
|
""".""" |
|
125
|
|
|
logger.info("skin_dir: " + skin_dir) |
|
126
|
|
|
if os.path.exists(skin_dir): |
|
127
|
|
|
# If folder is browsed: |
|
128
|
|
|
# - verify skin folder |
|
129
|
|
|
# - reset cache |
|
130
|
|
|
# - save new path in settings |
|
131
|
|
|
|
|
132
|
|
|
logger.info("Verified existence of Rainmeter Skin folder in '" + skin_dir + "'.") |
|
133
|
|
|
settings = sublime.load_settings("Rainmeter.sublime-settings") |
|
134
|
|
|
normed_skin_dir = os.path.normpath(skin_dir) |
|
135
|
|
|
|
|
136
|
|
|
settings.set("rainmeter_skins_path", normed_skin_dir) |
|
137
|
|
|
sublime.save_settings("Rainmeter.sublime-settings") |
|
138
|
|
|
logger.info("Rewrote settings to include skin path.") |
|
139
|
|
|
sublime.message_dialog("Successfully set the Rainmeter Skins path to '" + skin_dir + "'.") |
|
140
|
|
|
|
|
141
|
|
|
# we have to reset every cache because all are dependent on the program path |
|
142
|
|
|
# at least transitively |
|
143
|
|
|
get_cached_skin_path.cache_clear() |
|
144
|
|
|
logger.info("Cleared cache.") |
|
145
|
|
|
|
|
146
|
|
|
elif skin_dir == "-1": |
|
147
|
|
|
logger.info("User canceled Rainmeter Skin folder input.") |
|
148
|
|
|
pass |
|
149
|
|
|
|
|
150
|
|
|
else: |
|
151
|
|
|
# retry by recalling it again. |
|
152
|
|
|
logger.info("No valid Rainmeter Skin folder found. Retrying again.") |
|
153
|
|
|
browse_folder(on_skins_folder_browsed) |
|
154
|
|
|
|
|
155
|
|
|
browse_folder(on_skins_folder_browsed) |
|
156
|
|
|
|
|
157
|
|
|
padding = 16 |
|
158
|
|
|
logger.info("#PROGRAMPATH#:".ljust(padding) + get_cached_program_path()) # Rainmeter.exe |
|
159
|
|
|
logger.info("#PROGRAMDRIVE#:".ljust(padding) + get_cached_program_drive()) |
|
160
|
|
|
logger.info("#SETTINGSPATH#:".ljust(padding) + get_cached_setting_path()) # Rainmeter.ini |
|
161
|
|
|
logger.info("#SKINSPATH#:".ljust(padding) + get_cached_skin_path()) # Rainmeter/Skins path |
|
162
|
|
|
logger.info("#PLUGINSPATH#:".ljust(padding) + get_cached_plugin_path()) |
|
163
|
|
|
logger.info("#ADDONSPATH#:".ljust(padding) + get_cached_addon_path()) |
|
164
|
|
|
|