PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/installer/Install.java

#
Java | 117 lines | 87 code | 16 blank | 14 comment | 17 complexity | 9b021f49be1ef63850faa099f4b04343 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * Install.java - Main class of the installer
  3. *
  4. * Originally written by Slava Pestov for the jEdit installer project. This work
  5. * has been placed into the public domain. You may use this work in any way and
  6. * for any purpose you wish.
  7. *
  8. * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN THE
  9. * IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE, ASSUMES
  10. * _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE RESULTING FROM THE USE, MODIFICATION,
  11. * OR REDISTRIBUTION OF THIS SOFTWARE.
  12. */
  13. package installer;
  14. import javax.swing.plaf.metal.*;
  15. import javax.swing.*;
  16. import java.io.*;
  17. import java.util.Properties;
  18. public class Install
  19. {
  20. public static void main(String[] args)
  21. {
  22. String javaVersion = System.getProperty("java.version");
  23. if(javaVersion.compareTo("1.3") < 0)
  24. {
  25. System.err.println("You are running Java version "
  26. + javaVersion + ".");
  27. System.err.println("This installer requires Java 1.3 or later.");
  28. System.exit(1);
  29. }
  30. if(args.length == 0)
  31. new SwingInstall();
  32. else if(args.length == 1 && args[0].equals("text"))
  33. new ConsoleInstall();
  34. else if(args.length >= 2 && args[0].equals("auto"))
  35. new NonInteractiveInstall(args);
  36. else
  37. {
  38. System.err.println("Usage:");
  39. System.err.println("java -jar <installer JAR>");
  40. System.err.println("java -jar <installer JAR> text");
  41. System.err.println("java -jar <installer JAR> auto"
  42. + " <install dir> [unix-script=<dir>] [unix-man=<dir>]");
  43. System.err.println("text parameter starts installer in text-only mode.");
  44. System.err.println("auto parameter starts installer in non-interactive mode.");
  45. }
  46. }
  47. public Install()
  48. {
  49. props = new Properties();
  50. try
  51. {
  52. InputStream in = getClass().getResourceAsStream("/installer/install.props");
  53. props.load(in);
  54. in.close();
  55. }
  56. catch(IOException io)
  57. {
  58. System.err.println("Error loading 'install.props':");
  59. io.printStackTrace();
  60. }
  61. buf = new byte[32768];
  62. }
  63. public String getProperty(String name)
  64. {
  65. return props.getProperty(name);
  66. }
  67. public int getIntegerProperty(String name)
  68. {
  69. try
  70. {
  71. return Integer.parseInt(props.getProperty(name));
  72. }
  73. catch(Exception e)
  74. {
  75. return -1;
  76. }
  77. }
  78. public void copy(InputStream in, String outfile, Progress progress)
  79. throws IOException
  80. {
  81. File outFile = new File(outfile);
  82. OperatingSystem.getOperatingSystem().mkdirs(outFile.getParent());
  83. BufferedOutputStream out = new BufferedOutputStream(
  84. new FileOutputStream(outFile));
  85. int count;
  86. for(;;)
  87. {
  88. count = in.read(buf,0,Math.min(in.available(),buf.length));
  89. if(count == -1 || count == 0)
  90. break;
  91. out.write(buf,0,count);
  92. if(progress != null)
  93. progress.advance(count);
  94. }
  95. //in.close();
  96. out.close();
  97. }
  98. // private members
  99. private Properties props;
  100. private byte[] buf;
  101. }