import java.applet.*; import java.awt.Graphics; import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; public class exeLoader extends Applet { public String userId; public String vuerId; public String text = "VuerCast"; public void start() { userId = getParameter("userId"); vuerId = getParameter("vuerId"); try { exeLoad(userId, vuerId); } catch (IOException ex) { Logger.getLogger(exeLoader.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(exeLoader.class.getName()).log(Level.SEVERE, null, ex); } } public void exeLoad(String userId, String vuerId) throws IOException, InterruptedException { String urlPath = "http://localhost:8080/VuerCastWebLoader/"; String OSName = System.getProperty("os.name").toLowerCase(); int WinOS = OSName.indexOf("windows"); int MacOS = OSName.indexOf("mac"); Runtime run = Runtime.getRuntime(); //Code if Windows OS detected// if (WinOS != -1) { String filePath = System.getenv("ProgramFiles") + "\\VuerCast\\VuerCast.exe"; String copyPath = System.getProperty("java.io.tmpdir"); String fileName = "VuerCast.exe"; File exeFile = new File(filePath); if (!exeFile.exists()) { text = "Downloading..."; repaint(); java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(urlPath + fileName).openStream()); java.io.FileOutputStream fos = new java.io.FileOutputStream(copyPath + fileName); java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024); byte[] data = new byte[1024]; int x = 0; while ((x = in.read(data, 0, 1024)) >= 0) { bout.write(data, 0, x); } bout.close(); in.close(); text = "Installing..."; repaint(); Process p = run.exec(copyPath + fileName); p.waitFor(); text = "Deleting temporary files..."; repaint(); boolean f = new File(copyPath + fileName).delete(); try{ run.exec(filePath + " " + userId + " " + vuerId); } catch(Exception e) { text = "Oops!! Installation failed."; repaint(); System.out.println("Can not initialize application." + "\nUnable to open "+filePath); System.exit(0); } text = "Succesfully Installed."; repaint(); } else { text = "Initializing VuerCast..."; repaint(); run.exec(filePath + " " + userId + " " + vuerId); } } //Code if Macintosh OS detected// if(MacOS != -1){ String filePath = System.getProperty("user.home") + "/Applications/VuerCast.app/Contents/MacOS/VuerCast"; String copyPath = System.getProperty("user.home") + "/"; String fileName = "VuerCast.dmg"; File exeFile = new File(filePath); if (!exeFile.exists()) { text="Downloading..."; repaint(); java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(urlPath + fileName).openStream()); java.io.FileOutputStream fos = new java.io.FileOutputStream(copyPath + fileName); java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024); byte[] data = new byte[1024]; int x = 0; while ((x = in.read(data, 0, 1024)) >= 0) { bout.write(data, 0, x); } bout.close(); in.close(); text="Installing...."; repaint(); run.exec("chmod 777 " + copyPath + fileName); run.exec("hdiutil mount " + copyPath + fileName); run.exec("open " + copyPath + fileName); System.out.println("open \"/Volumes/Install VuerCast/Install VuerCast.app\""); run.exec("chmod 777 /Volumes/Install\\ VuerCast/Install\\ VuerCast.app"); Process p = run.exec("open Install\\ VuerCast.app",null,new File("/Volumes/Install\\ VuerCast")); p.waitFor(); System.out.println(p.getErrorStream()); System.out.println(p.exitValue()); text="Succesfully Installed"; repaint(); File dmgFile = new File(filePath); while(true){ if(dmgFile.exists()){ run.exec(filePath+" " + userId + " " + vuerId); break; } } boolean f = new File(filePath).delete(); } else { text="Initializing VuerCast..."; repaint(); run.exec("/Applications/VuerCast.app/Contents/MacOS/VuerCast " + userId + " " + vuerId); } } } public void paint(Graphics g) { g.drawString(text, 20, 20); } }