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:
parent
f1c4d1c22e
commit
a1d6305b9b
@ -18,6 +18,10 @@ import java.awt.Point;
|
||||
import java.awt.SystemColor;
|
||||
import java.awt.Toolkit;
|
||||
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 {
|
||||
|
||||
@ -32,6 +36,8 @@ public class JUninstaller extends Frame implements ActionListener {
|
||||
final Font ftPlain10 = new Font("Dialog", Font.PLAIN, 10);
|
||||
final Font ftBold12 = new Font("Dialog", Font.BOLD, 12);
|
||||
|
||||
Properties props = new Properties();
|
||||
|
||||
CardLayout clMain = new CardLayout();
|
||||
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 lbPW = new Label("Please wait...", Label.CENTER);
|
||||
Label lbTime = new Label("--:--:--", Label.CENTER);
|
||||
MyProgBar progBar = new MyProgBar();
|
||||
|
||||
Panel pnView = 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 {
|
||||
public void windowClosing(WindowEvent we) {
|
||||
// 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.hide();
|
||||
System.exit(0);
|
||||
@ -286,6 +301,17 @@ public class JUninstaller extends Frame implements ActionListener {
|
||||
setSize(WND_W, WND_H); // set Frame size
|
||||
setLocation((dmScreen.width-WND_W)/2, (dmScreen.height-WND_H)/2); // center Frame
|
||||
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();
|
||||
|
||||
btAbout.addActionListener(this);
|
||||
@ -334,6 +360,7 @@ public class JUninstaller extends Frame implements ActionListener {
|
||||
pnScan.add(lbSIP);
|
||||
pnScan.add(lbPW);
|
||||
pnScan.add(lbTime);
|
||||
progBar.setMode(MyProgBar.PQ2);
|
||||
|
||||
btDetails.addActionListener(this);
|
||||
btRemove.addActionListener(this);
|
||||
@ -374,8 +401,9 @@ public class JUninstaller extends Frame implements ActionListener {
|
||||
MIP.busy("Scan in progress");
|
||||
TimerThread thTimer = new TimerThread();
|
||||
thTimer.start();
|
||||
long count = 0;
|
||||
try {
|
||||
mfs.dumpAllDrives();
|
||||
count = mfs.dumpAllDrives();
|
||||
MIP.infoPrint("Scan complete.");
|
||||
} catch (Exception ex) {
|
||||
MIP.infoPrint("Exception!");
|
||||
@ -383,6 +411,7 @@ public class JUninstaller extends Frame implements ActionListener {
|
||||
if (!mfs.delDump()) { MIP.infoPrint("Delete log failed"); }
|
||||
}
|
||||
thTimer.setStop(true);
|
||||
props.put("dump.entries", Long.toString(count));
|
||||
clMain.show(pnMain, "2");
|
||||
lbLast.setText("Last scan: "+mfs.getDumpDate());
|
||||
}
|
||||
@ -444,6 +473,8 @@ public class JUninstaller extends Frame implements ActionListener {
|
||||
File flNew;
|
||||
|
||||
lbSIP.setText("=== COMPARING FILES ===");
|
||||
pnScan.add(progBar);
|
||||
pnScan.validate();
|
||||
clMain.show(pnMain, "3");
|
||||
MIP.busy("Comparison in progress");
|
||||
TimerThread thTimer = new TimerThread();
|
||||
@ -456,6 +487,8 @@ public class JUninstaller extends Frame implements ActionListener {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
thTimer.setStop(true);
|
||||
pnScan.remove(progBar);
|
||||
pnScan.validate();
|
||||
if (diffs > 0) {
|
||||
MIP.infoPrint(diffs+" changes found.");
|
||||
do {
|
||||
@ -501,12 +534,46 @@ public class JUninstaller extends Frame implements ActionListener {
|
||||
long min;
|
||||
long sec;
|
||||
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 {
|
||||
diffTime = System.currentTimeMillis()-startTime;
|
||||
min = diffTime/60000;
|
||||
sec = (diffTime/1000)%60;
|
||||
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 {
|
||||
Thread.sleep(500);
|
||||
} catch (Exception ex) {
|
||||
|
@ -19,6 +19,8 @@ public class MyFilesystemParser {
|
||||
private String curLine;
|
||||
private String ignoreDir;
|
||||
private long counter;
|
||||
public long cmpcounter;
|
||||
public long dumpcounter;
|
||||
|
||||
public MyFilesystemParser(String logfile) {
|
||||
logFile = new File(logfile+".gz");
|
||||
@ -45,8 +47,8 @@ public class MyFilesystemParser {
|
||||
File[] result = new File[1];
|
||||
result[0] = new File("E:\\");
|
||||
return result;
|
||||
} */
|
||||
|
||||
}
|
||||
*/
|
||||
public File[] listRoots() {
|
||||
int count = 0;
|
||||
for (char d='A';d<='Z';d++) {
|
||||
@ -155,21 +157,24 @@ public class MyFilesystemParser {
|
||||
dumpFiles(fw, entries[i]);
|
||||
} else if (entries[i].isFile()) {
|
||||
fw.write((entries[i].getPath()+"\t"+entries[i].length()+"\t"+entries[i].lastModified()+"\r\n").getBytes());
|
||||
dumpcounter++;
|
||||
}
|
||||
}
|
||||
fw.flush();
|
||||
}
|
||||
|
||||
/** 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)));
|
||||
File[] roots = listRoots();
|
||||
dumpcounter = 0;
|
||||
for (int i=0;i<roots.length;i++) {
|
||||
if (roots[i].canWrite()) {
|
||||
dumpFiles(fw, roots[i]);
|
||||
}
|
||||
}
|
||||
fw.close();
|
||||
return dumpcounter;
|
||||
}
|
||||
|
||||
/** 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());
|
||||
counter++;
|
||||
curLine = cmp.readLine();
|
||||
cmpcounter++;
|
||||
fn1 = curLine.substring(0, curLine.indexOf("\t"));
|
||||
}
|
||||
if (!myLine.equals(curLine)) {
|
||||
@ -203,6 +209,7 @@ public class MyFilesystemParser {
|
||||
out.write(("*\t"+myLine+"\r\n").getBytes());
|
||||
counter++;
|
||||
curLine = cmp.readLine();
|
||||
cmpcounter++;
|
||||
} else {
|
||||
// there's a new file on disk
|
||||
out.write(("+\t"+myLine+"\r\n").getBytes());
|
||||
@ -211,6 +218,7 @@ public class MyFilesystemParser {
|
||||
} else {
|
||||
// both entries are equal - never mind, advance to next
|
||||
curLine = cmp.readLine();
|
||||
cmpcounter++;
|
||||
}
|
||||
} // else if (entries[i].isFile())
|
||||
} // 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;
|
||||
BufferedReader cmp = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(logFile))));
|
||||
counter = 0;
|
||||
cmpcounter = 1;
|
||||
File[] roots = listRoots();
|
||||
curLine = cmp.readLine();
|
||||
for (int i=0;i<roots.length;i++) {
|
||||
|
100
MyProgBar.java
100
MyProgBar.java
@ -9,28 +9,32 @@ public class MyProgBar extends Component {
|
||||
final static int WINDOWS = 1;
|
||||
final static int PQ1 = 2;
|
||||
final static int PQ2 = 3;
|
||||
int minVal;
|
||||
int maxVal;
|
||||
int curVal;
|
||||
long minVal;
|
||||
long maxVal;
|
||||
long curVal;
|
||||
private int systemDelta = 0;
|
||||
Color fgColor = new Color(0,0,128);
|
||||
Color bgColor = Color.lightGray;
|
||||
Color bgColor = new Color(220,220,220);
|
||||
Color txColor = Color.white;
|
||||
int Height = 18;
|
||||
int Width = 40;
|
||||
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.maxVal = max;
|
||||
this.curVal = pos;
|
||||
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);
|
||||
}
|
||||
|
||||
public MyProgBar(int min, int max) {
|
||||
public MyProgBar(long min, long max) {
|
||||
this(min, max, min, MyProgBar.WINDOWS);
|
||||
}
|
||||
|
||||
@ -39,51 +43,67 @@ public class MyProgBar extends Component {
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
System.out.println("Object is "+getSize().width+"x"+getSize().height);
|
||||
double percentage = (double)(curVal-minVal)/(double)(maxVal-minVal);
|
||||
String percString = String.valueOf((int)(percentage*100)) + "%";
|
||||
g.setFont(new Font("Dialog", Font.PLAIN, 10));
|
||||
FontMetrics fm = getFontMetrics(g.getFont());
|
||||
g.setColor(bgColor);
|
||||
g.fill3DRect(0,0,getSize().width-1,getSize().height-1, false);
|
||||
g.setColor(fgColor);
|
||||
int pright = (int)((double)(getSize().width-2)/(maxVal-minVal)*(curVal-minVal));
|
||||
g.fill3DRect(1,1,pright,getSize().height-2, true);
|
||||
g.setXORMode(txColor);
|
||||
int tleft;
|
||||
switch (mode) {
|
||||
default:
|
||||
case MyProgBar.WINDOWS:
|
||||
g.drawString(percString, getSize().width/2-fm.stringWidth(percString)/2, getSize().height/2-fm.getHeight()/2+fm.getAscent());
|
||||
break;
|
||||
if (g != null) {
|
||||
double percentage = (double)(curVal-minVal)/(double)(maxVal-minVal);
|
||||
String percString = String.valueOf((int)(percentage*100)) + "%";
|
||||
g.setFont(new Font("Dialog", Font.PLAIN, 10));
|
||||
FontMetrics fm = getFontMetrics(g.getFont());
|
||||
int pright = (int)((double)(getSize().width-2)/(maxVal-minVal)*(curVal-minVal));
|
||||
g.setColor(bgColor);
|
||||
g.fill3DRect(pright+1,1,getSize().width-2-pright+systemDelta,getSize().height-2+systemDelta, false);
|
||||
g.setColor(fgColor);
|
||||
g.fill3DRect(1,1,pright+systemDelta,getSize().height-2+systemDelta, true);
|
||||
g.setXORMode(txColor);
|
||||
int tleft;
|
||||
switch (mode) {
|
||||
default:
|
||||
case MyProgBar.WINDOWS:
|
||||
g.drawString(percString, getSize().width/2-fm.stringWidth(percString)/2, getSize().height/2-fm.getHeight()/2+fm.getAscent());
|
||||
break;
|
||||
|
||||
case MyProgBar.PQ1:
|
||||
tleft = pright+2;
|
||||
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());
|
||||
break;
|
||||
case MyProgBar.PQ1:
|
||||
tleft = pright+2;
|
||||
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());
|
||||
break;
|
||||
|
||||
case MyProgBar.PQ2:
|
||||
tleft = (pright-1)/2-fm.stringWidth(percString)/2+1;
|
||||
if (tleft <= 2) tleft = 2;
|
||||
g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent());
|
||||
break;
|
||||
case MyProgBar.PQ2:
|
||||
tleft = (pright-1)/2-fm.stringWidth(percString)/2+1;
|
||||
if (tleft <= 2) tleft = 2;
|
||||
g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent());
|
||||
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;
|
||||
}
|
||||
|
||||
public void setMaxValue(int v) {
|
||||
public void setMaxValue(long v) {
|
||||
maxVal = v;
|
||||
}
|
||||
|
||||
public void setPos(int p) {
|
||||
public void setBgColor(Color c) {
|
||||
bgColor = c;
|
||||
}
|
||||
|
||||
public void setFgColor(Color c) {
|
||||
fgColor = c;
|
||||
}
|
||||
|
||||
public void setPos(long 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());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user