Determines if a file can be written. If the file exists, the user is prompted for approval to overwrite. @param file the file to check @return true if the file can be written
(File file)
| 1043 | * @return true if the file can be written |
| 1044 | */ |
| 1045 | public static boolean canWrite(File file) { |
| 1046 | if (OSPRuntime.isJS) |
| 1047 | return true; |
| 1048 | // refuse filenames containing "&" |
| 1049 | if (file.getName().contains("&")) { |
| 1050 | new AsyncDialog().showMessageDialog(null, |
| 1051 | MediaRes.getString("VideoIO.Dialog.BadFileName.Message") + " \n\"&\"" , //$NON-NLS-1$ //$NON-NLS-2$ |
| 1052 | MediaRes.getString("VideoIO.Dialog.BadFileName.Title"), //$NON-NLS-1$ |
| 1053 | JOptionPane.WARNING_MESSAGE, (ev) -> { |
| 1054 | }); |
| 1055 | return false; |
| 1056 | } |
| 1057 | if (file.exists() && !file.canWrite()) { |
| 1058 | JOptionPane.showMessageDialog(null, ControlsRes.getString("Dialog.ReadOnly.Message"), //$NON-NLS-1$ |
| 1059 | ControlsRes.getString("Dialog.ReadOnly.Title"), //$NON-NLS-1$ |
| 1060 | JOptionPane.PLAIN_MESSAGE); |
| 1061 | return false; |
| 1062 | } |
| 1063 | if (file.exists()) { |
| 1064 | int selected = JOptionPane.showConfirmDialog(null, "\"" + file.getName() + "\" " //$NON-NLS-1$ //$NON-NLS-2$ |
| 1065 | + MediaRes.getString("VideoIO.Dialog.FileExists.Message"), //$NON-NLS-1$ |
| 1066 | MediaRes.getString("VideoIO.Dialog.FileExists.Title"), //$NON-NLS-1$ |
| 1067 | JOptionPane.YES_NO_OPTION); |
| 1068 | if (selected != JOptionPane.YES_OPTION) { |
| 1069 | return false; |
| 1070 | } |
| 1071 | } |
| 1072 | return true; |
| 1073 | } |
| 1074 | |
| 1075 | // /** |
| 1076 | // * A Stop-gap method to allow Java-only functionality. |