Issue #383 Improved Firefox browser cache handling

Loading progressbar for cache
This commit is contained in:
Jindra Pet��k
2013-09-12 19:11:10 +02:00
parent cff6dff13d
commit 5e2bac3959
6 changed files with 100 additions and 25 deletions
+3
View File
@@ -82,6 +82,9 @@ public abstract class CacheEntry {
public String getHeader(String header) {
Map<String, String> m = getResponseHeaders();
if(m == null){
return null;
}
for (String k : m.keySet()) {
if (k.toLowerCase().equals(header.toLowerCase())) {
return m.get(k);
@@ -50,7 +50,6 @@ public class CacheMap {
if (mb.hash == 0) {
continue;
}
MetaData m = mb.getMetaData();
mapBuckets.add(mb);
}
}
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2013 petrik
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.browsers.cache.firefox;
/**
*
* @author petrik
*/
public class IncompatibleVersionException extends Exception {
public IncompatibleVersionException(int version) {
super("Incompatible version: "+version);
}
}
@@ -38,6 +38,8 @@ public class MapBucket extends CacheEntry {
if (metadata == null) {
try {
metadata = new MetaData(getMetaDataStream());
}catch(IncompatibleVersionException ie){
} catch (IOException ex) {
Logger.getLogger(MapBucket.class.getName()).log(Level.SEVERE, null, ex);
}
@@ -69,6 +71,9 @@ public class MapBucket extends CacheEntry {
return null;
}
String responseHead = m.response.get("response-head");
if(responseHead==null){
return null;
}
String headers[] = responseHead.split("\r\n");
Map<String, String> ret = new HashMap<>();
for (int h = 1; h < headers.length; h++) {
+4 -1
View File
@@ -24,9 +24,12 @@ public class MetaData {
public String request;
public Map<String, String> response;
public MetaData(InputStream is) throws IOException {
public MetaData(InputStream is) throws IOException, IncompatibleVersionException {
CacheInputStream cis = new CacheInputStream(is);
majorVersion = cis.readInt16();
if(majorVersion!=1){
throw new IncompatibleVersionException(majorVersion);
}
minorVersion = cis.readInt16();
location = cis.readInt32();
fetchCount = cis.readInt32();
@@ -45,9 +45,11 @@ import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileFilter;
/**
@@ -60,6 +62,10 @@ public class LoadFromCacheFrame extends AppFrame implements ActionListener {
private JTextField searchField;
private List<CacheImplementation> caches;
private List<CacheEntry> entries;
private JProgressBar progressBar;
JButton saveButton;
JButton refreshButton;
JButton openButton;
public LoadFromCacheFrame() {
setSize(900, 600);
@@ -101,17 +107,17 @@ public class LoadFromCacheFrame extends AppFrame implements ActionListener {
JPanel buttonsPanel = new JPanel(new FlowLayout());
JButton openButton = new JButton(translate("button.open"));
openButton = new JButton(translate("button.open"));
openButton.setActionCommand("OPEN");
openButton.addActionListener(this);
buttonsPanel.add(openButton);
JButton saveButton = new JButton(translate("button.save"));
saveButton = new JButton(translate("button.save"));
saveButton.setActionCommand("SAVE");
saveButton.addActionListener(this);
buttonsPanel.add(saveButton);
JButton refreshButton = new JButton(translate("button.refresh"));
refreshButton = new JButton(translate("button.refresh"));
refreshButton.setActionCommand("REFRESH");
refreshButton.addActionListener(this);
buttonsPanel.add(refreshButton);
@@ -124,6 +130,10 @@ public class LoadFromCacheFrame extends AppFrame implements ActionListener {
browsersPanel.add(firefoxLabel);
buttonsPanel.setAlignmentX(0.5f);
progressBar = new JProgressBar();
progressBar.setAlignmentX(0.5f);
progressBar.setIndeterminate(true);
bottomPanel.add(progressBar);
bottomPanel.add(buttonsPanel);
browsersPanel.setAlignmentX(0.5f);
bottomPanel.add(browsersPanel);
@@ -131,33 +141,59 @@ public class LoadFromCacheFrame extends AppFrame implements ActionListener {
infoLabel.setAlignmentX(0.5f);
bottomPanel.add(infoLabel);
cnt.add(bottomPanel, BorderLayout.SOUTH);
progressBar.setVisible(false);
openButton.setEnabled(false);
saveButton.setEnabled(false);
refresh();
}
private void refresh() {
if (caches == null) {
caches = new ArrayList<>();
for (String b : CacheReader.availableBrowsers()) {
caches.add(CacheReader.getBrowserCache(b));
}
} else {
for (CacheImplementation c : caches) {
c.refresh();
}
}
entries = new ArrayList<>();
for (CacheImplementation c : caches) {
List<CacheEntry> list=c.getEntries();
if(list!=null){
for (CacheEntry en : c.getEntries()) {
String contentType = en.getHeader("Content-Type");
if ("application/x-shockwave-flash".equals(contentType)) {
entries.add(en);
progressBar.setVisible(true);
openButton.setEnabled(false);
saveButton.setEnabled(false);
refreshButton.setEnabled(false);
new SwingWorker<Object, Object>() {
@Override
protected Object doInBackground() throws Exception {
if (caches == null) {
caches = new ArrayList<>();
for (String b : CacheReader.availableBrowsers()) {
caches.add(CacheReader.getBrowserCache(b));
}
} else {
for (CacheImplementation c : caches) {
c.refresh();
}
}
entries = new ArrayList<>();
for (CacheImplementation c : caches) {
List<CacheEntry> list = c.getEntries();
if (list != null) {
for (CacheEntry en : c.getEntries()) {
String contentType = en.getHeader("Content-Type");
if ("application/x-shockwave-flash".equals(contentType)) {
entries.add(en);
}
}
}
}
filter();
return null;
}
}
filter();
@Override
protected void done() {
openButton.setEnabled(true);
saveButton.setEnabled(true);
refreshButton.setEnabled(true);
progressBar.setVisible(false);
}
}.execute();
}
@SuppressWarnings("unchecked")