-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathRequiem.java
More file actions
271 lines (257 loc) · 9.51 KB
/
Requiem.java
File metadata and controls
271 lines (257 loc) · 9.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import java.io.*;
import java.util.*;
import java.util.logging.*;
/*
* Requiem.java
*
* Created on May 31, 2008, 4:58 PM
*/
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.awt.event.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
/**
*
* @author Razzmatazz
*/
public class Requiem extends javax.swing.JFrame {
private static final Logger log = Logger.getLogger(Requiem.class.getName());
// set by drag&drop in MacConfig, command args in main routine below
static java.util.List<File> dragDropFiles = null;
int successes;
Vector<String> errors;
/** Creates new form Requiem */
public Requiem() {
initComponents();
successes = 0;
errors = new Vector<String>();
new DropTarget(this, new DropTargetAdapter() {
public void dragEnter(DropTargetDragEvent e) {
jDropBorder.setVisible(true);
}
public void dragExit(DropTargetEvent e) {
jDropBorder.setVisible(false);
}
@SuppressWarnings("unchecked")
public void drop(DropTargetDropEvent e) {
jDropBorder.setVisible(false);
try {
e.acceptDrop(e.getSourceActions()); // TODO: huh? But it works...
log.info("dropped " + e.getTransferable().getTransferData(DataFlavor.javaFileListFlavor));
processDroppedFiles((java.util.List<File>)e.getTransferable().getTransferData(DataFlavor.javaFileListFlavor));
} catch (UnsupportedFlavorException f) {
log.log(Level.WARNING, "drop failed; ignoring " + e, f);
} catch (IOException f) {
log.log(Level.WARNING, "drop failed; ignoring " + e, f);
}
}
});
}
/** This method is called from within the constructor to
* initialize the form.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane = new javax.swing.JScrollPane();
jScrollPane.setPreferredSize(new Dimension(800,600));
tabFiles = new javax.swing.JTable() {
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component comp = super.prepareRenderer(renderer, row, column);
Color c = Color.white;
if (column == 1) {
String value = (String) getValueAt(row, 1);
if (value.equals("queued")) {
// white
} else if (value.equals("looking for DRM") || value.equals("working")) {
c = new Color(0xff, 0xff, 0x00); // yellow
} else if (value.equals("DRM removed")) {
c = new Color(0x66, 0xcc, 0x66); // light green
} else {
c = new Color(0xff, 0x99, 0x99); // light red
}
}
comp.setBackground(c);
return comp;
}
};
tabFiles.setSelectionForeground(new Color(0x00, 0x00, 0xff)); // blue
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Requiem 4.1");
tabFiles.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"File", "State"
}
) {
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
});
tabFiles.getColumnModel().getColumn(0).setPreferredWidth(1000);
tabFiles.getColumnModel().getColumn(1).setPreferredWidth(500);
jScrollPane.setViewportView(tabFiles);
getContentPane().add(jScrollPane);
jDropBorder = new JPanel();
jDropBorder.setBorder(BorderFactory.createLineBorder(new Color(161,204,255), 3));
jDropBorder.setOpaque(false);
jDropBorder.setVisible(false);
setGlassPane(jDropBorder);
pack();
}
private void startDecrypt() {
(new Thread() {@Override public void run() { doDecryptWorker(); } }).start();
}
class GuiNotifier implements Notifier {
Notifier chain;
GuiNotifier(Notifier n) {
chain = n;
}
HashMap<File,Integer> row_map = new HashMap<File,Integer>();
public void check(File a) {
chain.check(a);
String filename = a.getName();
DefaultTableModel model = (DefaultTableModel)tabFiles.getModel();
if (model.getRowCount() > 0 &&
model.getValueAt(model.getRowCount() - 1, 1).equals("looking for DRM")) {
model.setValueAt(filename, model.getRowCount() - 1, 0);
} else {
Vector<String> row = new Vector<String>();
row.add(filename);
row.add("looking for DRM");
model.addRow(row);
}
}
public void nodrm(File a) {
chain.nodrm(a);
}
public void queue(File a) {
chain.queue(a);
DefaultTableModel model = (DefaultTableModel)tabFiles.getModel();
model.setValueAt("queued", model.getRowCount() - 1, 1);
row_map.put(a, model.getRowCount() - 1);
}
public void error(File a, String msg) {
chain.error(a, msg);
DefaultTableModel model = (DefaultTableModel)tabFiles.getModel();
model.setValueAt(msg, model.getRowCount() - 1, 1);
row_map.put(a, model.getRowCount() - 1);
errors.add(a.getName() + " (" + msg + ")");
}
public void noMoreChecks() {
chain.noMoreChecks();
// remove the last check we did, if any
DefaultTableModel model = (DefaultTableModel)tabFiles.getModel();
if (model.getRowCount() > 0 &&
model.getValueAt(model.getRowCount() - 1, 1).equals("looking for DRM")) {
model.removeRow(model.getRowCount() - 1);
}
}
public void work(File a) {
chain.work(a);
int row = row_map.get(a);
tabFiles.getModel().setValueAt("working", row, 1);
}
public void success(File a) {
chain.success(a);
int row = row_map.get(a);
tabFiles.getModel().setValueAt("DRM removed", row, 1);
successes++;
}
public void failure(File a, String msg) {
chain.failure(a, msg);
if (msg.startsWith("java.lang.RuntimeException: ")) msg = msg.substring(28);
int row = row_map.get(a);
tabFiles.getModel().setValueAt(msg, row, 1);
errors.add(a.getName() + " (" + msg + ")");
}
}
GuiNotifier notifier;
void addNotifier() {
UnDrmQueue.notifier = notifier = new GuiNotifier(UnDrmQueue.notifier);
}
void processDroppedFiles(java.util.List<File> files) {
UnDrmQueue.queueBegin();
UnDrmQueue.queueList(files);
UnDrmQueue.queueEnd();
}
private void doDecryptWorker() {
try {
// process initial work, if any
boolean fromLibrary = false;
if (dragDropFiles != null) {
processDroppedFiles(dragDropFiles);
} else if (!Config.isShiftDown()) {
String[] args = new String[]{};
if (System.getProperty("requiem.outputlib") != null) {
args = new String[]{System.getProperty("requiem.outputlib")};
}
ModifyLib.queue(args);
fromLibrary = true;
}
// now loop doing and waiting for more work
while (true) {
UnDrmQueue.go();
int msgIcon;
String finishMessage;
String trash = System.getProperty("os.name").equals("Mac OS X") ? "trash" : "recycle bin";
if (successes == 0) {
finishMessage = "";
} else if (successes == 1) {
finishMessage = "Successfully removed DRM from 1 file.";
finishMessage += "\r\nThe DRM-laden file has been moved to the " + trash + ".";
} else {
finishMessage = "Successfully removed DRM from " + successes + " files.";
finishMessage += "\r\nThe DRM-laden files have been moved to the " + trash + ".";
}
if (errors.size() == 0) {
msgIcon = JOptionPane.INFORMATION_MESSAGE;
if (successes == 0) {
finishMessage = fromLibrary ? "No DRM found in library" : "No DRM found in files";
}
} else {
msgIcon = JOptionPane.WARNING_MESSAGE;
finishMessage += "\r\nThe following files could not be decrypted:";
final int MAX_ERRORS = 20;
for (int i = 0; i < errors.size() && i < MAX_ERRORS; i++) {
finishMessage += "\r\n"+errors.elementAt(i);
}
if (errors.size() > MAX_ERRORS) {
finishMessage += "\r\n...";
}
}
JOptionPane.showMessageDialog(rootPane, finishMessage, "Finished", msgIcon);
fromLibrary = false;
}
} catch (Exception ex) {
log.log(Level.SEVERE, "", ex);
JOptionPane.showMessageDialog(rootPane, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String args[]) {
Config.guiMods();
if (args.length > 0) {
// Windows does drag/drop by adding the file to the command line
dragDropFiles = new ArrayList<File>();
for (String file_name : args) {
log.info("input file " + file_name);
dragDropFiles.add(new File(file_name));
}
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Requiem r = new Requiem();
r.addNotifier();
r.setVisible(true);
r.startDecrypt();
}
});
}
private javax.swing.JScrollPane jScrollPane;
private javax.swing.JTable tabFiles;
private JPanel jDropBorder;
}