PageRenderTime 48ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/installer/Install.java

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