/jEdit/tags/jedit-4-1-pre10/installer/Install.java

# · Java · 121 lines · 91 code · 16 blank · 14 comment · 17 complexity · 131ef0b81fbc6edbc12259deadcd369a MD5 · raw file

  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.MetalLookAndFeel;
  15. import java.io.*;
  16. import java.util.Properties;
  17. public class Install
  18. {
  19. public static void main(String[] args)
  20. {
  21. String javaVersion = System.getProperty("java.version");
  22. if(javaVersion.compareTo("1.3") < 0)
  23. {
  24. System.err.println("You are running Java version "
  25. + javaVersion + ".");
  26. System.err.println("This installer requires Java 1.3 or later.");
  27. System.exit(1);
  28. }
  29. if(args.length == 0)
  30. {
  31. MetalLookAndFeel.setCurrentTheme(new JEditMetalTheme());
  32. new SwingInstall();
  33. }
  34. else if(args.length == 1 && args[0].equals("text"))
  35. new ConsoleInstall();
  36. else if(args.length >= 2 && args[0].equals("auto"))
  37. {
  38. new NonInteractiveInstall(args);
  39. }
  40. else
  41. {
  42. System.err.println("Usage:");
  43. System.err.println("java -jar <installer JAR>");
  44. System.err.println("java -jar <installer JAR> text");
  45. System.err.println("java -jar <installer JAR> auto"
  46. + " <install dir> [unix-script=<dir>] [unix-man=<dir>]");
  47. System.err.println("text parameter starts installer in text-only mode.");
  48. System.err.println("auto parameter starts installer in non-interactive mode.");
  49. }
  50. }
  51. public Install()
  52. {
  53. props = new Properties();
  54. try
  55. {
  56. InputStream in = getClass().getResourceAsStream("install.props");
  57. props.load(in);
  58. in.close();
  59. }
  60. catch(IOException io)
  61. {
  62. System.err.println("Error loading 'install.props':");
  63. io.printStackTrace();
  64. }
  65. buf = new byte[32768];
  66. }
  67. public String getProperty(String name)
  68. {
  69. return props.getProperty(name);
  70. }
  71. public int getIntegerProperty(String name)
  72. {
  73. try
  74. {
  75. return Integer.parseInt(props.getProperty(name));
  76. }
  77. catch(Exception e)
  78. {
  79. return -1;
  80. }
  81. }
  82. public void copy(InputStream in, String outfile, Progress progress)
  83. throws IOException
  84. {
  85. File outFile = new File(outfile);
  86. OperatingSystem.getOperatingSystem().mkdirs(outFile.getParent());
  87. BufferedOutputStream out = new BufferedOutputStream(
  88. new FileOutputStream(outFile));
  89. int count;
  90. for(;;)
  91. {
  92. count = in.read(buf,0,Math.min(in.available(),buf.length));
  93. if(count == -1 || count == 0)
  94. break;
  95. out.write(buf,0,count);
  96. if(progress != null)
  97. progress.advance(count);
  98. }
  99. //in.close();
  100. out.close();
  101. }
  102. // private members
  103. private Properties props;
  104. private byte[] buf;
  105. }