|
@@ 203-254 (lines=52) @@
|
| 200 |
|
sublime.message_dialog("Skin was successfully installed into \n\n" + dest_folder) |
| 201 |
|
|
| 202 |
|
|
| 203 |
|
class RainmeterInstallSkinFromZipCommand(sublime_plugin.ApplicationCommand): |
| 204 |
|
|
| 205 |
|
def run(self): |
| 206 |
|
# check cache first to determine the default path shown to the user |
| 207 |
|
install_cache_path = os.path.join(sublime.cache_path(), "Rainmeter", "install", "last_entered_zip.cache") |
| 208 |
|
if os.path.exists(install_cache_path) and os.path.isfile(install_cache_path): |
| 209 |
|
with open(install_cache_path, 'r') as cache_handler: |
| 210 |
|
cache_content = cache_handler.read() |
| 211 |
|
default_path = cache_content |
| 212 |
|
|
| 213 |
|
else: |
| 214 |
|
# show some default location from which the user can search from |
| 215 |
|
user = os.path.expanduser("~") |
| 216 |
|
downloads = os.path.join(user, "Downloads") |
| 217 |
|
|
| 218 |
|
if os.path.exists(downloads) and os.path.isdir(downloads): |
| 219 |
|
default_path = downloads |
| 220 |
|
else: |
| 221 |
|
default_path = None |
| 222 |
|
|
| 223 |
|
sublime.active_window().show_input_panel( |
| 224 |
|
"Enter skin zip location:", |
| 225 |
|
default_path, |
| 226 |
|
self.on_zip_path_entered, None, None |
| 227 |
|
) |
| 228 |
|
|
| 229 |
|
def on_zip_path_entered(self, path): |
| 230 |
|
if not os.path.exists(path): |
| 231 |
|
sublime.error_message("The entered path '" + path + "' is not valid. Please check your input.") |
| 232 |
|
return |
| 233 |
|
|
| 234 |
|
if not os.path.isfile(path): |
| 235 |
|
sublime.error_message("The entered path '" + path + "' is not a file. Please check your input.") |
| 236 |
|
return |
| 237 |
|
|
| 238 |
|
if not path.endswith(".zip"): |
| 239 |
|
sublime.error_message("The entered path '" + path + "' is not a zip file. Please check your input.") |
| 240 |
|
return |
| 241 |
|
|
| 242 |
|
# we expect the user to enter a new path which we need to persist |
| 243 |
|
install_cache_path = os.path.join(sublime.cache_path(), "Rainmeter", "install", "last_entered_zip.cache") |
| 244 |
|
if os.path.exists(install_cache_path): |
| 245 |
|
write_mode = 'w' |
| 246 |
|
else: |
| 247 |
|
write_mode = 'x' |
| 248 |
|
os.makedirs(os.path.dirname(install_cache_path)) |
| 249 |
|
|
| 250 |
|
with open(install_cache_path, write_mode) as cache_handler: |
| 251 |
|
cache_handler.write(path) |
| 252 |
|
|
| 253 |
|
from_zip.install_skin_zip_into_skins_folder(path) |
| 254 |
|
sublime.status_message("Skin was successfully installed!") |
| 255 |
|
|
| 256 |
|
|
| 257 |
|
class RainmeterInstallSkinFromGitCommand(sublime_plugin.ApplicationCommand): |
|
@@ 150-200 (lines=51) @@
|
| 147 |
|
# ) |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
class RainmeterInstallSkinFromFolderCommand(sublime_plugin.ApplicationCommand): |
| 151 |
|
|
| 152 |
|
def run(self): |
| 153 |
|
# check cache first to determine the default path shown to the user |
| 154 |
|
install_cache_path = os.path.join(sublime.cache_path(), "Rainmeter", "install", "last_entered_folder.cache") |
| 155 |
|
if os.path.exists(install_cache_path) and os.path.isfile(install_cache_path): |
| 156 |
|
with open(install_cache_path, 'r') as cache_handler: |
| 157 |
|
cache_content = cache_handler.read() |
| 158 |
|
default_path = cache_content |
| 159 |
|
|
| 160 |
|
else: |
| 161 |
|
user = os.path.expanduser("~") |
| 162 |
|
downloads = os.path.join(user, "Downloads") |
| 163 |
|
|
| 164 |
|
if os.path.exists(downloads) and os.path.isdir(downloads): |
| 165 |
|
default_path = downloads |
| 166 |
|
else: |
| 167 |
|
default_path = None |
| 168 |
|
|
| 169 |
|
sublime.active_window().show_input_panel( |
| 170 |
|
"Enter skin folder location:", |
| 171 |
|
default_path, |
| 172 |
|
self.on_folder_path_entered, None, None |
| 173 |
|
) |
| 174 |
|
|
| 175 |
|
def on_folder_path_entered(self, path): |
| 176 |
|
if not os.path.exists(path): |
| 177 |
|
sublime.error_message("The entered path '" + path + "' is not valid. Please check your input.") |
| 178 |
|
return |
| 179 |
|
|
| 180 |
|
if not os.path.isdir(path): |
| 181 |
|
sublime.error_message("The entered path '" + path + "' is not a directory. Please check your input.") |
| 182 |
|
return |
| 183 |
|
|
| 184 |
|
if not folder.find_inis_in_folder(path): |
| 185 |
|
sublime.error_message("The entered path '" + path + "' is not a valid Rainmeter skin. Please check your input.") |
| 186 |
|
return |
| 187 |
|
|
| 188 |
|
# we expect the user to enter a new path which we need to persist |
| 189 |
|
install_cache_path = os.path.join(sublime.cache_path(), "Rainmeter", "install", "last_entered_folder.cache") |
| 190 |
|
if os.path.exists(install_cache_path): |
| 191 |
|
write_mode = 'w' |
| 192 |
|
else: |
| 193 |
|
write_mode = 'x' |
| 194 |
|
os.makedirs(os.path.dirname(install_cache_path)) |
| 195 |
|
|
| 196 |
|
with open(install_cache_path, write_mode) as cache_handler: |
| 197 |
|
cache_handler.write(path) |
| 198 |
|
|
| 199 |
|
dest_folder = folder.install_skin_folder_into_skins_folder(path) |
| 200 |
|
sublime.message_dialog("Skin was successfully installed into \n\n" + dest_folder) |
| 201 |
|
|
| 202 |
|
|
| 203 |
|
class RainmeterInstallSkinFromZipCommand(sublime_plugin.ApplicationCommand): |