FileDocCategorySizeDatePackage
UIDebugGenerator.javaAPI DocAzureus 3.0.3.49666Mon Jan 08 10:06:24 GMT 2007org.gudy.azureus2.ui.swt.debug

UIDebugGenerator

public class UIDebugGenerator extends Object
author
TuxPaper
created
May 28, 2006

Fields Summary
Constructors Summary
Methods Summary
private static voidaddFilesToZip(java.util.zip.ZipOutputStream out, java.io.File[] files)

		byte[] buf = new byte[1024];
		if (files == null) {
			return;
		}

		for (int j = 0; j < files.length; j++) {
			File file = files[j];

			FileInputStream in;
			try {
				in = new FileInputStream(file);
			} catch (FileNotFoundException e) {
				continue;
			}

			try {
				ZipEntry entry = new ZipEntry(file.getName());
				entry.setTime(file.lastModified());
				out.putNextEntry(entry);
				//	Transfer bytes from the file to the ZIP file
				int len;
				while ((len = in.read(buf)) > 0) {
					out.write(buf, 0, len);
				}

				// Complete the entry
				out.closeEntry();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			try {
				in.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	
public static voidgenerate()

		Display display = Display.getCurrent();
		if (display == null) {
			return;
		}

		// make sure display is up to date
		while (display.readAndDispatch()) {
		}

		Shell[] shells = display.getShells();
		if (shells == null || shells.length == 0) {
			return;
		}

		File path = new File(SystemProperties.getUserPath(), "debug");
		if (!path.isDirectory()) {
			path.mkdir();
		} else {
			try {
				File[] files = path.listFiles();
				for (int i = 0; i < files.length; i++) {
					files[i].delete();
				}
			} catch (Exception e) {
			}
		}

		for (int i = 0; i < shells.length; i++) {
			try {
				Shell shell = shells[i];
				Image image = null;

				if (shell.getData("class") instanceof ObfusticateShell) {
					ObfusticateShell shellClass = (ObfusticateShell) shell.getData("class");

					try {
						image = shellClass.generateObfusticatedImage();
					} catch (Exception e) {
						Debug.out("Obfusticating shell " + shell, e);
					}
				} else {

					Rectangle clientArea = shell.getClientArea();
					image = new Image(display, clientArea.width, clientArea.height);

					GC gc = new GC(shell);
					try {
						gc.copyArea(image, clientArea.x, clientArea.y);
					} finally {
						gc.dispose();
					}
				}

				if (image != null) {
					File file = new File(path, "image-" + i + ".jpg");
					String sFileName = file.getAbsolutePath();

					ImageLoader imageLoader = new ImageLoader();
					imageLoader.data = new ImageData[] { image.getImageData() };
					imageLoader.save(sFileName, SWT.IMAGE_JPEG);
				}
			} catch (Exception e) {
				Logger.log(new LogEvent(LogIDs.GUI, "Creating Obfusticated Image", e));
			}
		}

		InputShell inputShell = new InputShell("UIDebugGenerator.messageask.title",
				"UIDebugGenerator.messageask.text", true);
		String message = inputShell.open();
		if (inputShell.isCanceled()) {
			return;
		} 

		if (message == null || message.length() == 0) {
			Utils.openMessageBox(Utils.findAnyShell(), SWT.OK,
					"UIDebugGenerator.message.cancel", (String[]) null);
			return;
		}

		try {
			File fUserMessage = new File(path, "usermessage.txt");
			FileWriter fw;
			fw = new FileWriter(fUserMessage);

			fw.write(message);

			fw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			File fEvidence = new File(path, "evidence.log");
			FileWriter fw;
			fw = new FileWriter(fEvidence);
			PrintWriter pw = new PrintWriter(fw);

			AEDiagnostics.generateEvidence(pw);

			fw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			File outFile = new File(SystemProperties.getUserPath(), "debug.zip");
			if (outFile.exists()) {
				outFile.delete();
			}

			ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFile));

			// %USERDIR%\logs
			File logPath = new File(SystemProperties.getUserPath(), "logs");
			File[] files = logPath.listFiles(new FileFilter() {
				public boolean accept(File pathname) {
					return pathname.getName().endsWith(".log");
				}
			});
			addFilesToZip(out, files);

			// %USERDIR%
			File userPath = new File(SystemProperties.getUserPath());
			files = userPath.listFiles(new FileFilter() {
				public boolean accept(File pathname) {
					return pathname.getName().endsWith(".log");
				}
			});
			addFilesToZip(out, files);

			// %USERDIR%\debug
			files = path.listFiles();
			addFilesToZip(out, files);

			// recent errors from exe dir
			final long ago = SystemTime.getCurrentTime() - 1000L * 60 * 60 * 24 * 90;
			File azureusPath = new File(SystemProperties.getApplicationPath());
			files = azureusPath.listFiles(new FileFilter() {
				public boolean accept(File pathname) {
					return (pathname.getName().startsWith("hs_err") && pathname.lastModified() > ago);
				}
			});
			addFilesToZip(out, files);

			// recent errors from OSX java log dir
			File javaLogPath = new File(System.getProperty("user.home"), "Library"
					+ File.separator + "Logs" + File.separator + "Java");
			if (javaLogPath.isDirectory()) {
				files = javaLogPath.listFiles(new FileFilter() {
					public boolean accept(File pathname) {
						return (pathname.getName().endsWith("log") && pathname.lastModified() > ago);
					}
				});
				addFilesToZip(out, files);
			}

			boolean bLogToFile = COConfigurationManager.getBooleanParameter("Logging Enable");
			String sLogDir = COConfigurationManager.getStringParameter("Logging Dir",
					"");
			if (bLogToFile && sLogDir != null) {
				File loggingFile = new File(sLogDir, FileLogging.LOG_FILE_NAME);
				if (loggingFile.isFile()) {
					addFilesToZip(out, new File[] { loggingFile });
				}
			}

			out.close();

			if (outFile.exists()) {
				int result = Utils.openMessageBox(Utils.findAnyShell(), SWT.OK
						| SWT.CANCEL | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL,
						"UIDebugGenerator.complete", new String[] { outFile.toString() });

				if (result == SWT.OK) {
					try {
						PlatformManagerFactory.getPlatformManager().showFile(
								outFile.getAbsolutePath());
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	
public static voidobfusticateArea(org.eclipse.swt.widgets.Display display, Image image, Rectangle bounds)

param
image
param
bounds

		GC gc = new GC(image);
		try {
			gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
			gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
			gc.fillRectangle(bounds);
			gc.drawRectangle(bounds);
			int x2 = bounds.x + bounds.width;
			int y2 = bounds.y + bounds.height;
			gc.drawLine(bounds.x, bounds.y, x2, y2);
			gc.drawLine(x2, bounds.y, bounds.x, y2);
		} finally {
			gc.dispose();
		}
	
public static voidobfusticateArea(org.eclipse.swt.widgets.Display display, Image image, Rectangle bounds, java.lang.String text)

param
image
param
bounds
param
text


		if (bounds.isEmpty())
			return;

		if (text == "") {
			obfusticateArea(display, image, bounds);
			return;
		}

		GC gc = new GC(image);
		try {
			gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
			gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
			gc.fillRectangle(bounds);
			gc.drawRectangle(bounds);
			gc.setClipping(bounds);
			gc.drawText(text, bounds.x + 2, bounds.y + 1);
		} finally {
			gc.dispose();
		}
	
public static voidobfusticateArea(Image image, org.eclipse.swt.widgets.Control control, Point shellOffset, java.lang.String text)

param
image
param
control
param
shellOffset
param
text

		Rectangle bounds = control.getBounds();
		Point offset = control.getParent().toDisplay(bounds.x, bounds.y);
		bounds.x = offset.x - shellOffset.x;
		bounds.y = offset.y - shellOffset.y;

		obfusticateArea(control.getDisplay(), image, bounds, text);