From d5d1cf5c700fe68ce5e5611c3b44cc887c74d738 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Fri, 21 May 2010 03:08:14 +0300 Subject: [PATCH] Allow printing image info from JPC-RR commandline Allow easier way to get image data, as binary builds don't have easily usable ImageMaker. --- Changelog.utf8 | 1 + manual.lyx | 11 ++++ manual.txt | 7 ++ org/jpc/j2se/JPCApplication.java | 138 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+) diff --git a/Changelog.utf8 b/Changelog.utf8 index 8cf73d8..74a0050 100644 --- a/Changelog.utf8 +++ b/Changelog.utf8 @@ -4,6 +4,7 @@ Changes since JPC-RR Release 10.7: - Report inner exceptions in saved stack traces. - Set disk library in autoexec file, not from command line. - Keep focus on main window on savestate/loadstate. +- Allow printing image info from JPC-RR commandline. Changes from JPC-RR Release 10.6 to JPC-RR Release 10.7: ======================================================== diff --git a/manual.lyx b/manual.lyx index fa51b5c..b3e04ff 100644 --- a/manual.lyx +++ b/manual.lyx @@ -859,6 +859,17 @@ When emulator is started, command line comes up. and print return values. \end_layout +\begin_layout Itemize +'lsdisks []' Print listing of all known disks. + If is specified, save output to specified file. +\end_layout + +\begin_layout Itemize +'diskinfo [] ' Print Information about + (can be disk name or ID). + If is specified, save output to specified file. +\end_layout + \begin_layout Standard When one gets command line, its useful to load some plugins. See section about plugins. diff --git a/manual.txt b/manual.txt index c548be6..ed8d859 100644 --- a/manual.txt +++ b/manual.txt @@ -452,6 +452,13 @@ commands are known: • 'call [...]': Invoke command via external command interface and print return values. +• 'lsdisks []' Print listing of all known disks. If + is specified, save output to specified file. + +• 'diskinfo [] ' Print Information about + (can be disk name or ID). If is + specified, save output to specified file. + When one gets command line, its useful to load some plugins. See section about plugins. Note: Load runner plugin (PCControl/PCRunner and so) last, as some runners like to start diff --git a/org/jpc/j2se/JPCApplication.java b/org/jpc/j2se/JPCApplication.java index 5327347..154176e 100644 --- a/org/jpc/j2se/JPCApplication.java +++ b/org/jpc/j2se/JPCApplication.java @@ -31,10 +31,12 @@ package org.jpc.j2se; import java.io.*; import javax.swing.*; +import java.util.List; import java.lang.reflect.*; import org.jpc.*; import org.jpc.diskimages.ImageLibrary; +import org.jpc.diskimages.ImageMaker; import org.jpc.diskimages.DiskImage; import org.jpc.pluginsbase.*; @@ -163,6 +165,116 @@ public class JPCApplication pluginManager.registerPlugin(c); } + private static void doListImages(ImageLibrary lib, String restOfCommand) throws IOException + { + PrintStream out = System.out; + boolean doClose = false; + if(restOfCommand != null) { + OutputStream outb = new BufferedOutputStream(new FileOutputStream(restOfCommand)); + out = new PrintStream(outb, false, "UTF-8"); + doClose = true; + } + + //Get present images of any tyype. + String[] images = lib.imagesByType(~0x1L); + for(String i : images) + printImageInfo(out, lib, i, true); + + if(doClose) + out.close(); + } + + + public static void printImageInfo(PrintStream out, ImageLibrary lib, String origName, boolean brief) throws IOException + { + String fileName = lib.searchFileName(origName); + if(fileName == null) { + System.err.println("No image named '" + origName + "' exists."); + return; + } + try { + ImageMaker.ParsedImage pimg = new ImageMaker.ParsedImage(fileName); + String typeString; + switch(pimg.typeCode) { + case 0: + typeString = "floppy "; + break; + case 1: + typeString = "HDD "; + break; + case 2: + typeString = "CD-ROM "; + break; + case 3: + typeString = "BIOS "; + break; + default: + typeString = " "; + break; + } + if(brief) { + out.println("" + (new ImageLibrary.ByteArray(pimg.diskID)) + " " + typeString + " " + origName); + return; + } + + out.println("Name : " + origName); + out.println("File name : " + fileName); + out.println("Type : " + typeString); + if(pimg.typeCode == 0 || pimg.typeCode == 1) { + out.println("Tracks : " + pimg.tracks); + out.println("Sides : " + pimg.sides); + out.println("Sectors : " + pimg.sectors); + out.println("Total sectors : " + pimg.totalSectors); + out.println("Primary extent size: " + pimg.sectorsPresent); + out.println("Storage Method : " + pimg.method); + int actualSectors = 0; + + for(int i = 0; i < pimg.totalSectors; i++) { + if(i < pimg.sectorOffsetMap.length && pimg.sectorOffsetMap[i] > 0) + actualSectors++; + } + out.println("Sectors present : " + actualSectors); + } else if(pimg.typeCode == 2) { + out.println("Total sectors : " + pimg.totalSectors); + } else if(pimg.typeCode == 3) { + out.println("Image Size : " + pimg.rawImage.length); + } + + out.println("Claimed Disk ID : " + (new ImageLibrary.ByteArray(pimg.diskID))); + List comments = pimg.comments; + if(comments != null) { + out.println(""); + out.println("Comments section:"); + out.println(""); + for(String x : comments) + out.println(x); + } + } catch(IOException e) { + errorDialog(e, "Failed to read image", null, "Quit"); + } + } + + + private static void doImageInfo(ImageLibrary lib, String restOfCommand) throws IOException + { + PrintStream out = System.out; + boolean doClose = false; + int sIndex = restOfCommand.indexOf(" "); + if(sIndex > 0) { + String outName = restOfCommand.substring(0, sIndex); + restOfCommand = restOfCommand.substring(sIndex + 1); + OutputStream outb = new BufferedOutputStream(new FileOutputStream(outName)); + out = new PrintStream(outb, false, "UTF-8"); + doClose = true; + } + + printImageInfo(out, lib, restOfCommand, false); + + if(doClose) + out.close(); + } + + public static void doCommand(Plugins pluginManager, String cmd) throws IOException { if(cmd.toLowerCase().startsWith("load ")) { @@ -221,6 +333,32 @@ public class JPCApplication } } DiskImage.setLibrary(new ImageLibrary(library)); + } else if(cmd.toLowerCase().equals("lsdisks") || cmd.toLowerCase().startsWith("lsdisks ")) { + String rest = null; + if(cmd.length() > 8) + rest = cmd.substring(8); + ImageLibrary lib = DiskImage.getLibrary(); + if(lib == null) { + System.err.println("No library loaded"); + return; + } + try { + doListImages(lib, rest); + } catch(Exception e) { + errorDialog(e, "Failed to lisk known images", null, "Dismiss"); + } + } else if(cmd.toLowerCase().startsWith("diskinfo ")) { + String rest = cmd.substring(9); + ImageLibrary lib = DiskImage.getLibrary(); + if(lib == null) { + System.err.println("No library loaded"); + return; + } + try { + doImageInfo(lib, rest); + } catch(Exception e) { + errorDialog(e, "Failed to get information for image", null, "Dismiss"); + } } else { System.err.println("Invalid command"); } -- 2.11.4.GIT