|
49 | 49 | public class WindowsPlatform extends DefaultPlatform { |
50 | 50 |
|
51 | 51 | static final String APP_NAME = "Processing"; |
| 52 | + static final String[] APP_EXTENSIONS = { ".pde", ".pyde" }; |
52 | 53 | static final String REG_OPEN_COMMAND = |
53 | 54 | System.getProperty("user.dir").replace('/', '\\') + |
54 | 55 | "\\" + APP_NAME.toLowerCase() + ".exe \"%1\""; |
@@ -192,33 +193,36 @@ protected void setAssociations() throws UnsupportedEncodingException { |
192 | 193 | openCommand)) { |
193 | 194 | */ |
194 | 195 |
|
| 196 | + // First create the .pde association |
| 197 | + for (String extension : APP_EXTENSIONS) { |
| 198 | + if (!registerExtension(extension)) { |
| 199 | + Messages.log("Could not associate " + extension + "files, " + |
| 200 | + "turning off auto-associate pref."); |
| 201 | + Preferences.setBoolean("platform.auto_file_type_associations", false); |
| 202 | + } |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + |
| 207 | + private boolean registerExtension(String extension) throws UnsupportedEncodingException { |
195 | 208 | // "To change the settings for the interactive user, store the changes |
196 | 209 | // under HKEY_CURRENT_USER\Software\Classes rather than HKEY_CLASSES_ROOT." |
197 | 210 | // msdn.microsoft.com/en-us/library/windows/desktop/ms724475(v=vs.85).aspx |
198 | 211 | final REGISTRY_ROOT_KEY rootKey = REGISTRY_ROOT_KEY.CURRENT_USER; |
199 | 212 | final String docPrefix = "Software\\Classes\\" + REG_DOC; |
200 | 213 |
|
201 | | - // First create the .pde association |
202 | | - if (WindowsRegistry.createKey(rootKey, "Software\\Classes", ".pde") && |
203 | | - WindowsRegistry.setStringValue(rootKey, "Software\\Classes\\.pde", "", REG_DOC) && |
204 | | - |
205 | | - // Now give files with a .pde extension a name for the explorer |
206 | | - WindowsRegistry.createKey(rootKey, "Software\\Classes", REG_DOC) && |
207 | | - WindowsRegistry.setStringValue(rootKey, docPrefix, "", APP_NAME + " Source Code") && |
208 | | - |
209 | | - // Now associate the 'open' command with the current processing.exe |
210 | | - WindowsRegistry.createKey(rootKey, docPrefix, "shell") && |
211 | | - WindowsRegistry.createKey(rootKey, docPrefix + "\\shell", "open") && |
212 | | - WindowsRegistry.createKey(rootKey, docPrefix + "\\shell\\open", "command") && |
213 | | - WindowsRegistry.setStringValue(rootKey, docPrefix + "\\shell\\open\\command", "", REG_OPEN_COMMAND)) { |
| 214 | + return (WindowsRegistry.createKey(rootKey, "Software\\Classes", extension) && |
| 215 | + WindowsRegistry.setStringValue(rootKey, "Software\\Classes\\" + extension, "", REG_DOC) && |
214 | 216 |
|
215 | | - // everything ok |
216 | | - // hooray! |
| 217 | + // Now give files with a .pde extension a name for the explorer |
| 218 | + WindowsRegistry.createKey(rootKey, "Software\\Classes", REG_DOC) && |
| 219 | + WindowsRegistry.setStringValue(rootKey, docPrefix, "", APP_NAME + " Source Code") && |
217 | 220 |
|
218 | | - } else { |
219 | | - Messages.log("Could not associate files, turning off auto-associate pref."); |
220 | | - Preferences.setBoolean("platform.auto_file_type_associations", false); |
221 | | - } |
| 221 | + // Now associate the 'open' command with the current processing.exe |
| 222 | + WindowsRegistry.createKey(rootKey, docPrefix, "shell") && |
| 223 | + WindowsRegistry.createKey(rootKey, docPrefix + "\\shell", "open") && |
| 224 | + WindowsRegistry.createKey(rootKey, docPrefix + "\\shell\\open", "command") && |
| 225 | + WindowsRegistry.setStringValue(rootKey, docPrefix + "\\shell\\open\\command", "", REG_OPEN_COMMAND)); |
222 | 226 | } |
223 | 227 |
|
224 | 228 |
|
|
0 commit comments