modified JUninstaller.java

+ Properties object for preferences, loaded on startup, saved on close
        + MyProgBar on comparison
        + Remaining time calculated on comparison

modified   MyFilesystemParser.java
        + counters for dumped and compared lines

modified   MyProgBar.java
        * now uses long values
        x threw NullPointerException when Graphics g was null
        x some pixel corrections, incl. addition correction if run on EPOC
        + more accessors
This commit is contained in:
mbirth 2005-02-02 18:05:03 +00:00
parent f1c4d1c22e
commit a1d6305b9b
3 changed files with 143 additions and 47 deletions

View File

@ -18,6 +18,10 @@ import java.awt.Point;
import java.awt.SystemColor; import java.awt.SystemColor;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class JUninstaller extends Frame implements ActionListener { public class JUninstaller extends Frame implements ActionListener {
@ -32,6 +36,8 @@ public class JUninstaller extends Frame implements ActionListener {
final Font ftPlain10 = new Font("Dialog", Font.PLAIN, 10); final Font ftPlain10 = new Font("Dialog", Font.PLAIN, 10);
final Font ftBold12 = new Font("Dialog", Font.BOLD, 12); final Font ftBold12 = new Font("Dialog", Font.BOLD, 12);
Properties props = new Properties();
CardLayout clMain = new CardLayout(); CardLayout clMain = new CardLayout();
Panel pnMain = new Panel(clMain); Panel pnMain = new Panel(clMain);
@ -70,6 +76,7 @@ public class JUninstaller extends Frame implements ActionListener {
Label lbSIP = new Label("SCAN IN PROGRESS", Label.CENTER); Label lbSIP = new Label("SCAN IN PROGRESS", Label.CENTER);
Label lbPW = new Label("Please wait...", Label.CENTER); Label lbPW = new Label("Please wait...", Label.CENTER);
Label lbTime = new Label("--:--:--", Label.CENTER); Label lbTime = new Label("--:--:--", Label.CENTER);
MyProgBar progBar = new MyProgBar();
Panel pnView = new Panel(new BorderLayout()); Panel pnView = new Panel(new BorderLayout());
Panel pnDel = new Panel(new BorderLayout()); Panel pnDel = new Panel(new BorderLayout());
@ -92,6 +99,14 @@ public class JUninstaller extends Frame implements ActionListener {
private class MainWindowAdapter extends WindowAdapter { private class MainWindowAdapter extends WindowAdapter {
public void windowClosing(WindowEvent we) { public void windowClosing(WindowEvent we) {
// TODO: Insert commands to execute upon shutdown // TODO: Insert commands to execute upon shutdown
try {
FileOutputStream fos = new FileOutputStream(new File("JUninstaller.prop"));
props.save(fos, "jUninstaller configuration --- DO NOT EDIT");
fos.close();
} catch (IOException ioe) {
ioe.printStackTrace();
MIP.infoPrint("Error saving config");
}
MIP.infoPrint("Goodbye..."); MIP.infoPrint("Goodbye...");
MIP.hide(); MIP.hide();
System.exit(0); System.exit(0);
@ -286,6 +301,17 @@ public class JUninstaller extends Frame implements ActionListener {
setSize(WND_W, WND_H); // set Frame size setSize(WND_W, WND_H); // set Frame size
setLocation((dmScreen.width-WND_W)/2, (dmScreen.height-WND_H)/2); // center Frame setLocation((dmScreen.width-WND_W)/2, (dmScreen.height-WND_H)/2); // center Frame
MIP.busy(APPNAME+" loading..."); MIP.busy(APPNAME+" loading...");
File propFile = new File("JUninstaller.prop");
if (propFile.exists()) {
try {
FileInputStream fis = new FileInputStream(propFile);
props.load(fis);
fis.close();
} catch (IOException ioe) {
ioe.printStackTrace();
MIP.infoPrint("Error loading config");
}
}
doAbout(); doAbout();
btAbout.addActionListener(this); btAbout.addActionListener(this);
@ -334,6 +360,7 @@ public class JUninstaller extends Frame implements ActionListener {
pnScan.add(lbSIP); pnScan.add(lbSIP);
pnScan.add(lbPW); pnScan.add(lbPW);
pnScan.add(lbTime); pnScan.add(lbTime);
progBar.setMode(MyProgBar.PQ2);
btDetails.addActionListener(this); btDetails.addActionListener(this);
btRemove.addActionListener(this); btRemove.addActionListener(this);
@ -374,8 +401,9 @@ public class JUninstaller extends Frame implements ActionListener {
MIP.busy("Scan in progress"); MIP.busy("Scan in progress");
TimerThread thTimer = new TimerThread(); TimerThread thTimer = new TimerThread();
thTimer.start(); thTimer.start();
long count = 0;
try { try {
mfs.dumpAllDrives(); count = mfs.dumpAllDrives();
MIP.infoPrint("Scan complete."); MIP.infoPrint("Scan complete.");
} catch (Exception ex) { } catch (Exception ex) {
MIP.infoPrint("Exception!"); MIP.infoPrint("Exception!");
@ -383,6 +411,7 @@ public class JUninstaller extends Frame implements ActionListener {
if (!mfs.delDump()) { MIP.infoPrint("Delete log failed"); } if (!mfs.delDump()) { MIP.infoPrint("Delete log failed"); }
} }
thTimer.setStop(true); thTimer.setStop(true);
props.put("dump.entries", Long.toString(count));
clMain.show(pnMain, "2"); clMain.show(pnMain, "2");
lbLast.setText("Last scan: "+mfs.getDumpDate()); lbLast.setText("Last scan: "+mfs.getDumpDate());
} }
@ -444,6 +473,8 @@ public class JUninstaller extends Frame implements ActionListener {
File flNew; File flNew;
lbSIP.setText("=== COMPARING FILES ==="); lbSIP.setText("=== COMPARING FILES ===");
pnScan.add(progBar);
pnScan.validate();
clMain.show(pnMain, "3"); clMain.show(pnMain, "3");
MIP.busy("Comparison in progress"); MIP.busy("Comparison in progress");
TimerThread thTimer = new TimerThread(); TimerThread thTimer = new TimerThread();
@ -456,6 +487,8 @@ public class JUninstaller extends Frame implements ActionListener {
ex.printStackTrace(); ex.printStackTrace();
} }
thTimer.setStop(true); thTimer.setStop(true);
pnScan.remove(progBar);
pnScan.validate();
if (diffs > 0) { if (diffs > 0) {
MIP.infoPrint(diffs+" changes found."); MIP.infoPrint(diffs+" changes found.");
do { do {
@ -501,12 +534,46 @@ public class JUninstaller extends Frame implements ActionListener {
long min; long min;
long sec; long sec;
long mil; long mil;
long remTime;
long maxcount = 0;
boolean blProgBar = (lbSIP.getText().indexOf("SCAN") == -1);
double perc;
int idx;
String outtext;
int ctr = 0;
if (blProgBar) {
try {
maxcount = Long.parseLong(props.getProperty("dump.entries"));
} catch (Exception ex) {
ex.printStackTrace();
}
progBar.setMaxValue(maxcount);
}
do { do {
diffTime = System.currentTimeMillis()-startTime; diffTime = System.currentTimeMillis()-startTime;
min = diffTime/60000; min = diffTime/60000;
sec = (diffTime/1000)%60; sec = (diffTime/1000)%60;
mil = (diffTime/10)%100; mil = (diffTime/10)%100;
lbTime.setText(min+":"+((sec<10)?"0":"")+sec+"."+((mil<10)?"0":"")+mil); outtext = min+":"+((sec<10)?"0":"")+sec+"."+((mil<10)?"0":"")+mil;
if (blProgBar && maxcount>0) {
progBar.setPos(mfs.cmpcounter);
perc = (double)mfs.cmpcounter/(double)maxcount;
if (perc>0.1 && ctr>10) {
remTime = (int)((double)diffTime/perc)-diffTime;
min = remTime/60000;
sec = (remTime/1000)%60;
mil = (remTime/10)%100;
outtext += " ("+min+":"+((sec<10)?"0":"")+sec+"."+((mil<10)?"0":"")+mil+")";
ctr = 0;
} else {
idx = lbTime.getText().indexOf(" ");
if (idx>=0) {
outtext += lbTime.getText().substring(lbTime.getText().indexOf(" "));
}
}
ctr++;
}
lbTime.setText(outtext);
try { try {
Thread.sleep(500); Thread.sleep(500);
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -19,6 +19,8 @@ public class MyFilesystemParser {
private String curLine; private String curLine;
private String ignoreDir; private String ignoreDir;
private long counter; private long counter;
public long cmpcounter;
public long dumpcounter;
public MyFilesystemParser(String logfile) { public MyFilesystemParser(String logfile) {
logFile = new File(logfile+".gz"); logFile = new File(logfile+".gz");
@ -45,8 +47,8 @@ public class MyFilesystemParser {
File[] result = new File[1]; File[] result = new File[1];
result[0] = new File("E:\\"); result[0] = new File("E:\\");
return result; return result;
} */ }
*/
public File[] listRoots() { public File[] listRoots() {
int count = 0; int count = 0;
for (char d='A';d<='Z';d++) { for (char d='A';d<='Z';d++) {
@ -155,21 +157,24 @@ public class MyFilesystemParser {
dumpFiles(fw, entries[i]); dumpFiles(fw, entries[i]);
} else if (entries[i].isFile()) { } else if (entries[i].isFile()) {
fw.write((entries[i].getPath()+"\t"+entries[i].length()+"\t"+entries[i].lastModified()+"\r\n").getBytes()); fw.write((entries[i].getPath()+"\t"+entries[i].length()+"\t"+entries[i].lastModified()+"\r\n").getBytes());
dumpcounter++;
} }
} }
fw.flush(); fw.flush();
} }
/** Walks the root-directories of all drives and calls dumpFiles() */ /** Walks the root-directories of all drives and calls dumpFiles() */
public void dumpAllDrives() throws IOException { public long dumpAllDrives() throws IOException {
BufferedOutputStream fw = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(logFile))); BufferedOutputStream fw = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(logFile)));
File[] roots = listRoots(); File[] roots = listRoots();
dumpcounter = 0;
for (int i=0;i<roots.length;i++) { for (int i=0;i<roots.length;i++) {
if (roots[i].canWrite()) { if (roots[i].canWrite()) {
dumpFiles(fw, roots[i]); dumpFiles(fw, roots[i]);
} }
} }
fw.close(); fw.close();
return dumpcounter;
} }
/** Compares file-liste from cmp to actual files on disk and writes changes to out */ /** Compares file-liste from cmp to actual files on disk and writes changes to out */
@ -194,6 +199,7 @@ public class MyFilesystemParser {
out.write(("-\t"+curLine+"\r\n").getBytes()); out.write(("-\t"+curLine+"\r\n").getBytes());
counter++; counter++;
curLine = cmp.readLine(); curLine = cmp.readLine();
cmpcounter++;
fn1 = curLine.substring(0, curLine.indexOf("\t")); fn1 = curLine.substring(0, curLine.indexOf("\t"));
} }
if (!myLine.equals(curLine)) { if (!myLine.equals(curLine)) {
@ -203,6 +209,7 @@ public class MyFilesystemParser {
out.write(("*\t"+myLine+"\r\n").getBytes()); out.write(("*\t"+myLine+"\r\n").getBytes());
counter++; counter++;
curLine = cmp.readLine(); curLine = cmp.readLine();
cmpcounter++;
} else { } else {
// there's a new file on disk // there's a new file on disk
out.write(("+\t"+myLine+"\r\n").getBytes()); out.write(("+\t"+myLine+"\r\n").getBytes());
@ -211,6 +218,7 @@ public class MyFilesystemParser {
} else { } else {
// both entries are equal - never mind, advance to next // both entries are equal - never mind, advance to next
curLine = cmp.readLine(); curLine = cmp.readLine();
cmpcounter++;
} }
} // else if (entries[i].isFile()) } // else if (entries[i].isFile())
} // for (int i=0; i<entries.length; i++) } // for (int i=0; i<entries.length; i++)
@ -224,6 +232,7 @@ public class MyFilesystemParser {
if (redump) dout = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream("$$mfs$$.$$$"))); else dout = null; if (redump) dout = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream("$$mfs$$.$$$"))); else dout = null;
BufferedReader cmp = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(logFile)))); BufferedReader cmp = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(logFile))));
counter = 0; counter = 0;
cmpcounter = 1;
File[] roots = listRoots(); File[] roots = listRoots();
curLine = cmp.readLine(); curLine = cmp.readLine();
for (int i=0;i<roots.length;i++) { for (int i=0;i<roots.length;i++) {

View File

@ -9,28 +9,32 @@ public class MyProgBar extends Component {
final static int WINDOWS = 1; final static int WINDOWS = 1;
final static int PQ1 = 2; final static int PQ1 = 2;
final static int PQ2 = 3; final static int PQ2 = 3;
int minVal; long minVal;
int maxVal; long maxVal;
int curVal; long curVal;
private int systemDelta = 0;
Color fgColor = new Color(0,0,128); Color fgColor = new Color(0,0,128);
Color bgColor = Color.lightGray; Color bgColor = new Color(220,220,220);
Color txColor = Color.white; Color txColor = Color.white;
int Height = 18; int Height = 18;
int Width = 40; int Width = 40;
private int mode; private int mode;
public MyProgBar(int min, int max, int pos, int mode) { public MyProgBar(long min, long max, long pos, int mode) {
this.minVal = min; this.minVal = min;
this.maxVal = max; this.maxVal = max;
this.curVal = pos; this.curVal = pos;
this.mode = mode; this.mode = mode;
if (System.getProperty("os.name").equals("EPOC")) {
this.systemDelta = -1;
}
} }
public MyProgBar(int min, int max, int pos) { public MyProgBar(long min, long max, long pos) {
this(min, max, pos, MyProgBar.WINDOWS); this(min, max, pos, MyProgBar.WINDOWS);
} }
public MyProgBar(int min, int max) { public MyProgBar(long min, long max) {
this(min, max, min, MyProgBar.WINDOWS); this(min, max, min, MyProgBar.WINDOWS);
} }
@ -39,51 +43,67 @@ public class MyProgBar extends Component {
} }
public void paint(Graphics g) { public void paint(Graphics g) {
System.out.println("Object is "+getSize().width+"x"+getSize().height); if (g != null) {
double percentage = (double)(curVal-minVal)/(double)(maxVal-minVal); double percentage = (double)(curVal-minVal)/(double)(maxVal-minVal);
String percString = String.valueOf((int)(percentage*100)) + "%"; String percString = String.valueOf((int)(percentage*100)) + "%";
g.setFont(new Font("Dialog", Font.PLAIN, 10)); g.setFont(new Font("Dialog", Font.PLAIN, 10));
FontMetrics fm = getFontMetrics(g.getFont()); FontMetrics fm = getFontMetrics(g.getFont());
g.setColor(bgColor); int pright = (int)((double)(getSize().width-2)/(maxVal-minVal)*(curVal-minVal));
g.fill3DRect(0,0,getSize().width-1,getSize().height-1, false); g.setColor(bgColor);
g.setColor(fgColor); g.fill3DRect(pright+1,1,getSize().width-2-pright+systemDelta,getSize().height-2+systemDelta, false);
int pright = (int)((double)(getSize().width-2)/(maxVal-minVal)*(curVal-minVal)); g.setColor(fgColor);
g.fill3DRect(1,1,pright,getSize().height-2, true); g.fill3DRect(1,1,pright+systemDelta,getSize().height-2+systemDelta, true);
g.setXORMode(txColor); g.setXORMode(txColor);
int tleft; int tleft;
switch (mode) { switch (mode) {
default: default:
case MyProgBar.WINDOWS: case MyProgBar.WINDOWS:
g.drawString(percString, getSize().width/2-fm.stringWidth(percString)/2, getSize().height/2-fm.getHeight()/2+fm.getAscent()); g.drawString(percString, getSize().width/2-fm.stringWidth(percString)/2, getSize().height/2-fm.getHeight()/2+fm.getAscent());
break; break;
case MyProgBar.PQ1: case MyProgBar.PQ1:
tleft = pright+2; tleft = pright+2;
if (tleft+fm.stringWidth(percString)>=getSize().width-1) tleft = getSize().width-1-fm.stringWidth(percString); if (tleft+fm.stringWidth(percString)>=getSize().width-1) tleft = getSize().width-1-fm.stringWidth(percString);
g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent()); g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent());
break; break;
case MyProgBar.PQ2: case MyProgBar.PQ2:
tleft = (pright-1)/2-fm.stringWidth(percString)/2+1; tleft = (pright-1)/2-fm.stringWidth(percString)/2+1;
if (tleft <= 2) tleft = 2; if (tleft <= 2) tleft = 2;
g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent()); g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent());
break; break;
}
g.setPaintMode();
g.setColor(Color.black);
g.drawRect(0,0,getSize().width-1,getSize().height-1);
} }
g.setPaintMode();
g.setColor(Color.black);
g.drawRect(0,0,getSize().width-1,getSize().height-1);
} }
public void setMinValue(int v) { public void setMinValue(long v) {
minVal = v; minVal = v;
} }
public void setMaxValue(int v) { public void setMaxValue(long v) {
maxVal = v; maxVal = v;
} }
public void setBgColor(Color c) {
bgColor = c;
}
public void setFgColor(Color c) {
fgColor = c;
}
public void setPos(int p) { public void setPos(long p) {
curVal = p; curVal = p;
if (curVal > maxVal) curVal = maxVal;
else if (curVal < minVal ) curVal = minVal;
paint(getGraphics());
}
public void setMode(int m) {
mode = m;
paint(getGraphics()); paint(getGraphics());
} }