summaryrefslogtreecommitdiff
path: root/NET/worlds/console/LogFile.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-03 16:38:41 -0700
committerFuwn <[email protected]>2021-05-03 16:38:41 -0700
commite1e781bb2135ef78592226f1a3eaba4925702f1f (patch)
tree8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/console/LogFile.java
downloadworlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.tar.xz
worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.zip
:star:HEADmain
Diffstat (limited to 'NET/worlds/console/LogFile.java')
-rw-r--r--NET/worlds/console/LogFile.java330
1 files changed, 330 insertions, 0 deletions
diff --git a/NET/worlds/console/LogFile.java b/NET/worlds/console/LogFile.java
new file mode 100644
index 0000000..d5b581b
--- /dev/null
+++ b/NET/worlds/console/LogFile.java
@@ -0,0 +1,330 @@
+/* */ package NET.worlds.console;
+/* */
+/* */ import NET.worlds.core.IniFile;
+/* */ import NET.worlds.core.Std;
+/* */ import NET.worlds.core.SystemInfo;
+/* */ import java.io.BufferedOutputStream;
+/* */ import java.io.BufferedReader;
+/* */ import java.io.File;
+/* */ import java.io.FileInputStream;
+/* */ import java.io.FileOutputStream;
+/* */ import java.io.IOException;
+/* */ import java.io.InputStream;
+/* */ import java.io.InputStreamReader;
+/* */ import java.io.PrintStream;
+/* */ import java.text.DateFormat;
+/* */ import java.util.Date;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public class LogFile
+/* */ {
+/* 77 */ private static PrintStream out = null;
+/* */
+/* */
+/* 80 */ private static String baseName = null;
+/* */
+/* */
+/* */ private static final String tempSuffix = ".open";
+/* */
+/* */
+/* */ private static final String mailSuffix = ".mail";
+/* */
+/* */
+/* */ private static final String noCloseTag = ", it terminated unexpectedly.\nPlease fill in the box below with an explanation of which\nfeatures you were exercising at the time, then click the\nReport button to automatically email the report to Worlds.\n";
+/* */
+/* */
+/* */ private static final String errorFoundTag = ", it generated a debugging log.\nPlease fill in the box below with an explanation of anything\nunusual that occurred (if anything), then click the Report\nbutton to automatically email the report to Worlds.\n";
+/* */
+/* */
+/* */ private static final String includeEmail = "Also, please include your email address.\n";
+/* */
+/* */
+/* 98 */ private static String mailReason = "error encountered";
+/* 99 */ private static String mailTag = ", it generated a debugging log.\nPlease fill in the box below with an explanation of anything\nunusual that occurred (if anything), then click the Report\nbutton to automatically email the report to Worlds.\n";
+/* */
+/* */
+/* */
+/* */ private static final String iniFile = "worlds.ini";
+/* */
+/* */
+/* */
+/* */
+/* */ public static void open()
+/* */ {
+/* 110 */ baseName = IniFile.gamma().getIniString("logfile", "");
+/* 111 */ if (baseName.length() == 0) {
+/* 112 */ return;
+/* */ }
+/* 114 */ baseName = Gamma.earlyURLUnalias("home:" + baseName);
+/* */
+/* */
+/* 117 */ File f = new File(baseName + ".open");
+/* 118 */ if (f.isFile())
+/* */ {
+/* */
+/* 121 */ if (scanFileForException(f)) {
+/* 122 */ mailReason = "logfile not closed--probable crash";
+/* 123 */ mailTag = ", it terminated unexpectedly.\nPlease fill in the box below with an explanation of which\nfeatures you were exercising at the time, then click the\nReport button to automatically email the report to Worlds.\n";
+/* 124 */ File mf = new File(baseName + ".mail");
+/* 125 */ f.renameTo(mf);
+/* 126 */ mf = null;
+/* */ } else {
+/* 128 */ f.delete();
+/* */ }
+/* */ }
+/* */
+/* 132 */ f = new File(baseName);
+/* 133 */ if (f.isFile()) {
+/* 134 */ f.delete();
+/* */ }
+/* 136 */ f = null;
+/* */
+/* */
+/* 139 */ FileOutputStream FOout = null;
+/* */ try {
+/* 141 */ FOout = new FileOutputStream(baseName + ".open");
+/* */ } catch (IOException e) {
+/* 143 */ System.out.println("Error opening logfile \"" + baseName + "\"");
+/* 144 */ return;
+/* */ }
+/* */
+/* 147 */ out = new PrintStream(new BufferedOutputStream(FOout), true);
+/* */
+/* */
+/* 150 */ System.setOut(out);
+/* 151 */ System.setErr(out);
+/* */
+/* */
+/* */
+/* 155 */ out.println("Logfile of " +
+/* 156 */ DateFormat.getDateTimeInstance().format(new Date()));
+/* 157 */ out.println("Gamma " +
+/* 158 */ Std.getVersion() +
+/* 159 */ ":" +
+/* 160 */ Std.getJavaVersion() +
+/* 161 */ ", build " +
+/* 162 */ Std.getBuildInfo() +
+/* 163 */ " of " +
+/* 164 */ DateFormat.getDateTimeInstance().format(
+/* 165 */ new Date(Std.getBuildDate())));
+/* 166 */ out.println("system info---------------------------------");
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 174 */ SystemInfo.Record(out);
+/* */
+/* 176 */ out.println("worlds.ini----------------------------------");
+/* */
+/* */
+/* */ try
+/* */ {
+/* 181 */ String from = System.getProperty("file.encoding");
+/* 182 */ InputStream in = new FileInputStream("worlds.ini");
+/* 183 */ BufferedReader ini = new BufferedReader(new InputStreamReader(in,
+/* 184 */ from));
+/* */
+/* 186 */ for (String s = ini.readLine(); s != null; s = ini.readLine())
+/* 187 */ out.println(s);
+/* 188 */ ini.close();
+/* */ }
+/* */ catch (IOException localIOException1) {}
+/* 191 */ out.println("--------------------------------------------");
+/* */ }
+/* */
+/* */
+/* */ public static void close()
+/* */ {
+/* 197 */ if (out != null) {
+/* 198 */ out.println("Logfile closed.");
+/* 199 */ out.close();
+/* */ }
+/* */
+/* */
+/* */
+/* 204 */ File f = new File(baseName + ".open");
+/* 205 */ if (scanFileForException(f)) {
+/* 206 */ File mf = new File(baseName + ".mail");
+/* 207 */ f.renameTo(mf);
+/* 208 */ mf = null;
+/* */ } else {
+/* 210 */ File nf = new File(baseName);
+/* 211 */ if (f.isFile())
+/* 212 */ f.renameTo(nf);
+/* 213 */ nf = null;
+/* */ }
+/* 215 */ f = null;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public static void mailLogIfPresent(String server)
+/* */ {
+/* 225 */ DialogReceiver rcvr = new DialogReceiver() {
+/* */ public void dialogDone(Object who, boolean confirmed) {
+/* 227 */ LogMailDialog dlg = (LogMailDialog)who;
+/* 228 */ File f = new File(LogFile.baseName + ".mail");
+/* 229 */ if (f.isFile()) {
+/* 230 */ if (confirmed) {
+/* 231 */ LogFile.sendCrashMail(LogFile.this, f, LogFile.mailReason, dlg.getComment());
+/* */ } else {
+/* 233 */ f.delete();
+/* */ }
+/* */ }
+/* */ }
+/* 237 */ };
+/* 238 */ File f = new File(baseName + ".mail");
+/* 239 */ if (f.isFile())
+/* */ {
+/* 241 */ String tag = "The last time you ran " + Std.getProductName() +
+/* 242 */ mailTag;
+/* 243 */ if (IniFile.gamma().getIniString("LASTCHATNAME", "").length() == 0) {
+/* 244 */ new LogMailDialog(rcvr, tag + "Also, please include your email address.\n");
+/* */ } else {
+/* 246 */ new LogMailDialog(rcvr, tag);
+/* */ }
+/* */ }
+/* */ }
+/* */
+/* */ private static void sendCrashMail(String server, File logFile, String tagLine, String comment)
+/* */ {
+/* 253 */ MailMessage msg = new LogFileMailMessage(server, logFile);
+/* */ try {
+/* 255 */ if (tagLine != null)
+/* 256 */ msg.appendBody(" (" + tagLine + ")");
+/* 257 */ msg.appendBody(".\n\n");
+/* 258 */ if (comment != null) {
+/* 259 */ msg.appendBody("The user reports:\n");
+/* 260 */ msg.appendParagraphs(comment);
+/* 261 */ msg.appendBody("\n\n");
+/* */ }
+/* 263 */ msg.appendBody("The log file reads:\n\n");
+/* */
+/* 265 */ String from = System.getProperty("file.encoding");
+/* 266 */ InputStream in = new FileInputStream(logFile);
+/* 267 */ BufferedReader log = new BufferedReader(new InputStreamReader(in,
+/* 268 */ from));
+/* */
+/* */
+/* 271 */ long fl = logFile.length();
+/* 272 */ if (fl > 64000L) {
+/* 273 */ int lc = 0;
+/* 274 */ long cc = 0L;
+/* */
+/* 276 */ for (String s = log.readLine(); (s != null) && (lc < 2048); s = log
+/* 277 */ .readLine()) {
+/* 278 */ msg.appendBody(s + "\n");
+/* 279 */ lc++;
+/* 280 */ cc += s.length();
+/* */ }
+/* */
+/* 283 */ msg.appendBody("-------------------------------------...\n");
+/* 284 */ msg.appendBody(" Log file too long; skipping center\n");
+/* 285 */ msg.appendBody("...-------------------------------------\n");
+/* */
+/* 287 */ log.skip(fl - (cc + 16030L));
+/* 288 */ log.readLine();
+/* 289 */ for (String s = log.readLine(); s != null; s = log.readLine())
+/* 290 */ msg.appendBody(s + "\n");
+/* */ } else {
+/* 292 */ for (String s = log.readLine(); s != null; s = log.readLine())
+/* 293 */ msg.appendBody(s + "\n");
+/* */ }
+/* 295 */ log.close();
+/* */ } catch (IOException ex) {
+/* 297 */ System.out.println("Error writing logfile to mail note: " + ex);
+/* */ }
+/* 299 */ msg.send();
+/* */ }
+/* */
+/* */ private static boolean scanFileForException(File logFile)
+/* */ {
+/* */ try
+/* */ {
+/* 306 */ String from = System.getProperty("file.encoding");
+/* 307 */ InputStream in = new FileInputStream(logFile);
+/* 308 */ BufferedReader log = new BufferedReader(new InputStreamReader(in,
+/* 309 */ from));
+/* 310 */ for (String s = log.readLine(); s != null; s = log.readLine()) {
+/* 311 */ if ((s.indexOf("\tat NET.worlds") != -1) ||
+/* 312 */ (s.indexOf("\tat java.lang") != -1) ||
+/* 313 */ (s.indexOf("\tat sun.awt") != -1)) {
+/* 314 */ log.close();
+/* 315 */ return true;
+/* */ }
+/* */ }
+/* 318 */ log.close();
+/* */ }
+/* */ catch (IOException localIOException) {}
+/* */
+/* 322 */ return false;
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\LogFile.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file