From b35819468d853ae91f103bb4e1fe88cc838c7908 Mon Sep 17 00:00:00 2001 From: 123Haynes <123haynes@gmail.com> Date: Fri, 7 Nov 2014 10:38:04 +0100 Subject: [PATCH] copied files from the original svn repository (version 1.3) --- build.xml | 74 ++ doctor.txt | 1 + linux32.txt | 1 + linux64.txt | 1 + manifest.mf | 3 + nbproject/build-impl.xml | 700 ++++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/project.properties | 73 ++ nbproject/project.xml | 19 + .../org.jdesktop.application.Application | 1 + src/ca/canucksoftware/novacom/Novacom.java | 206 ++++++ .../novacom/NovacomDrivers.java | 316 ++++++++ .../novacominstaller/DriverDownloader.form | 99 +++ .../novacominstaller/DriverDownloader.java | 123 +++ .../novacominstaller/NovacomInstallerApp.java | 51 ++ .../NovacomInstallerView.form | 87 +++ .../NovacomInstallerView.java | 165 +++++ .../resources/DriverDownloader.properties | 13 + .../resources/NovacomInstallerApp.properties | 12 + .../resources/NovacomInstallerView.properties | 37 + src/ca/canucksoftware/utils/FileUtils.java | 65 ++ src/ca/canucksoftware/utils/OnlineFile.java | 87 +++ .../utils/TextStreamConsumer.java | 51 ++ 23 files changed, 2193 insertions(+) create mode 100644 build.xml create mode 100644 doctor.txt create mode 100644 linux32.txt create mode 100644 linux64.txt create mode 100644 manifest.mf create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/META-INF/services/org.jdesktop.application.Application create mode 100644 src/ca/canucksoftware/novacom/Novacom.java create mode 100644 src/ca/canucksoftware/novacom/NovacomDrivers.java create mode 100644 src/ca/canucksoftware/novacominstaller/DriverDownloader.form create mode 100644 src/ca/canucksoftware/novacominstaller/DriverDownloader.java create mode 100644 src/ca/canucksoftware/novacominstaller/NovacomInstallerApp.java create mode 100644 src/ca/canucksoftware/novacominstaller/NovacomInstallerView.form create mode 100644 src/ca/canucksoftware/novacominstaller/NovacomInstallerView.java create mode 100644 src/ca/canucksoftware/novacominstaller/resources/DriverDownloader.properties create mode 100644 src/ca/canucksoftware/novacominstaller/resources/NovacomInstallerApp.properties create mode 100644 src/ca/canucksoftware/novacominstaller/resources/NovacomInstallerView.properties create mode 100644 src/ca/canucksoftware/utils/FileUtils.java create mode 100644 src/ca/canucksoftware/utils/OnlineFile.java create mode 100644 src/ca/canucksoftware/utils/TextStreamConsumer.java diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..bdecb61 --- /dev/null +++ b/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project NovacomInstaller. + + + diff --git a/doctor.txt b/doctor.txt new file mode 100644 index 0000000..c77ae33 --- /dev/null +++ b/doctor.txt @@ -0,0 +1 @@ +http://palm.cdnetworks.net/rom/touchpad/wd300wifi/webosdoctorp300hstnhwifi.jar diff --git a/linux32.txt b/linux32.txt new file mode 100644 index 0000000..a146e60 --- /dev/null +++ b/linux32.txt @@ -0,0 +1 @@ +https://cdn.downloads.palm.com/sdkdownloads/3.0.0.643/sdkBinaries/palm-novacom_1.0.76_i386.deb diff --git a/linux64.txt b/linux64.txt new file mode 100644 index 0000000..f5889d7 --- /dev/null +++ b/linux64.txt @@ -0,0 +1 @@ +https://cdn.downloads.palm.com/sdkdownloads/3.0.0.643/sdkBinaries/palm-novacom_1.0.76_amd64.deb diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..79384c5 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,700 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..b243321 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=c15f44a5 +build.xml.script.CRC32=c1958190 +build.xml.stylesheet.CRC32=958a1d3e@1.26.2.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=c15f44a5 +nbproject/build-impl.xml.script.CRC32=ff7b33f0 +nbproject/build-impl.xml.stylesheet.CRC32=5c621a33@1.26.2.45 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..669aec5 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,73 @@ +application.desc= +application.homepage= +application.title=Universal Novacom Installer +application.vendor=Jason Robitaille +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/NovacomInstaller.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +file.reference.tar.jar=C:\\Users\\Jason\\NetBeansProjects\\tar.jar +includes=** +jar.compress=false +javac.classpath=\ + ${libs.swing-app-framework.classpath}:\ + ${file.reference.tar.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.5 +javac.target=1.5 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jnlp.codebase.type=local +jnlp.codebase.url=file:/C:/Users/Jason/NetBeansProjects/NovacomInstaller/dist/ +jnlp.descriptor=application +jnlp.enabled=false +jnlp.offline-allowed=false +jnlp.signed=false +main.class=ca.canucksoftware.novacominstaller.NovacomInstallerApp +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..513a53a --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,19 @@ + + + org.netbeans.modules.java.j2seproject + + + NovacomInstaller + 1.6.5 + + + + + + + + + + + + diff --git a/src/META-INF/services/org.jdesktop.application.Application b/src/META-INF/services/org.jdesktop.application.Application new file mode 100644 index 0000000..bc693eb --- /dev/null +++ b/src/META-INF/services/org.jdesktop.application.Application @@ -0,0 +1 @@ +novacominstaller.NovacomInstallerApp \ No newline at end of file diff --git a/src/ca/canucksoftware/novacom/Novacom.java b/src/ca/canucksoftware/novacom/Novacom.java new file mode 100644 index 0000000..c6cae3c --- /dev/null +++ b/src/ca/canucksoftware/novacom/Novacom.java @@ -0,0 +1,206 @@ + +package ca.canucksoftware.novacom; + +import ca.canucksoftware.utils.TextStreamConsumer; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.ResourceBundle; + +/** + * @author Jason Robitaille + */ +public class Novacom { + public static String execPath() { + String novacom = "novacom"; + if(new File("/usr/local/bin/novacom").exists()) { //mac or linux + novacom = "/usr/local/bin/novacom"; + } else if(new File("/opt/nova/bin/novacom").exists()) { //mac or linux + novacom = "/opt/nova/bin/novacom"; + } else { //windows + String programPath32 = System.getenv("ProgramFiles"); + String programPath64 = null; + if(programPath32!=null) { + programPath32 = programPath32.replace("\\", "/").trim(); + if(programPath32.endsWith("(x86)")) { + programPath64 = programPath32.substring(0, + programPath32.lastIndexOf("(x86)")).trim(); + programPath64 = programPath64.replace("\\", "/"); + } + + if(programPath64!=null && new File(programPath64 + "/HP webOS/SDK/bin/novacom.exe").exists()) { + novacom = programPath64 + "/HP webOS/SDK/bin/novacom.exe"; + } else if(new File(programPath32 + "/HP webOS/SDK/bin/novacom.exe").exists()) { + novacom = programPath32 + "/HP webOS/SDK/bin/novacom.exe"; + } else if(programPath64!=null && new File(programPath64 + "/Palm, Inc/novacom.exe").exists()) { + novacom = programPath64 + "/Palm, Inc/novacom.exe"; + } else if(new File(programPath32 + "/Palm, Inc/novacom.exe").exists()) { + novacom = programPath32 + "/Palm, Inc/novacom.exe"; + } else if(programPath64!=null && new File(programPath64 + "/Palm, Inc/novacom/novacom.exe") + .exists()) { + novacom = programPath64 + "/Palm, Inc/novacom/novacom.exe"; + } else if(new File(programPath32 + "/Palm, Inc/novacom/novacom.exe").exists()) { + novacom = programPath32 + "/Palm, Inc/novacom/novacom.exe"; + } else if(programPath64!=null && new File(programPath64 + "/Palm/SDK/bin/novacom.exe").exists()) { + novacom = programPath64 + "/Palm/SDK/bin/novacom.exe"; + } else if(new File(programPath32 + "/Palm/SDK/bin/novacom.exe").exists()) { + novacom = programPath32 + "/Palm/SDK/bin/novacom.exe"; + } else if(programPath64!=null && new File(programPath64 + "/PDK/bin/novacom.exe").exists()) { + novacom = programPath64 + "/PDK/bin/novacom.exe"; + } else if(new File(programPath32 + "/PDK/bin/novacom.exe").exists()) { + novacom = programPath32 + "/PDK/bin/novacom.exe"; + } + } else { + if(new File("C:/Program Files/HP webOS/SDK/bin/novacom.exe").exists()) { + novacom = "C:/Program Files/HP webOS/SDK/bin/novacom.exe"; + } else if(new File("C:/Program Files/Palm, Inc/novacom.exe").exists()) { + novacom = "C:/Program Files/Palm, Inc/novacom.exe"; + } else if(new File("C:/Program Files/Palm, Inc/novacom/novacom.exe").exists()) { + novacom = "C:/Program Files/Palm, Inc/novacom/novacom.exe"; + } else if(new File("C:/Program Files/Palm/SDK/bin/novacom.exe").exists()) { + novacom = "C:/Program Files/Palm/SDK/bin/novacom.exe"; + } else if(new File("C:/Program Files/PDK/bin/novacom.exe").exists()) { + novacom = "C:/Program Files/PDK/bin/novacom.exe"; + } + } + } + return novacom; + } + + public static boolean isInstalled() { + boolean isInstalled = false; + String execPath = execPath(); + if(execPath.equals("novacom")) { + try { + Process p = Runtime.getRuntime().exec("novacom -l"); + OutputStream os = p.getOutputStream(); + os.flush(); + os.close(); + TextStreamConsumer stdout = new TextStreamConsumer(p.getInputStream()); + stdout.start(); + TextStreamConsumer stderr = new TextStreamConsumer(p.getErrorStream()); + stderr.start(); + stdout.waitFor(); + isInstalled = (p.waitFor()==0); + } catch(Exception e) {} + } else { + isInstalled = new File(execPath).exists(); + } + return isInstalled; + } + + public static boolean serviceInstalled() { + boolean installed = false; + if(new File("/opt/Palm/novacom/novacomd").exists()) { //linux + installed = true; + } else if(new File("/opt/nova/bin/novacomd").exists() || + new File("/Library/LaunchDaemons/com.palm.novacomd").exists()) { //mac + installed = true; + }else { //windows + String programPath32 = System.getenv("ProgramFiles"); + String programPath64 = null; + if(programPath32!=null) { + programPath32 = programPath32.replace("\\", "/").trim(); + if(programPath32.endsWith("(x86)")) { + programPath64 = programPath32.substring(0, + programPath32.lastIndexOf("(x86)")).trim(); + programPath64 = programPath64.replace("\\", "/"); + } + if(new File(programPath32 + "/HP webOS/SDK/bin/novacomd/amd64/novacomd.exe").exists() || + new File(programPath32 + "/HP webOS/SDK/bin/novacomd/x86/novacomd.exe").exists() || + new File(programPath32 + "/Palm, Inc/novacom/amd64/novacomd.exe").exists() || + new File(programPath32 + "/Palm, Inc/novacom/x86/novacomd.exe").exists() || + new File(programPath32 + "/Palm/SDK/novacom/amd64/novacomd.exe").exists() || + new File(programPath32 + "/Palm/SDK/novacom/x86/novacomd.exe").exists() || + new File(programPath32 + "/Palm/SDK/bin/novacom/amd64/novacomd.exe").exists() || + new File(programPath32 + "/Palm/SDK/bin/novacom/x86/novacomd.exe").exists()) { + installed = true; + } + if(programPath64 != null) { + if(new File(programPath64 + "/HP webOS/SDK/bin/novacomd/amd64/novacomd.exe").exists() || + new File(programPath64 + "/HP webOS/SDK/bin/novacomd/x86/novacomd.exe").exists() || + new File(programPath64 + "/Palm, Inc/novacom/amd64/novacomd.exe").exists() || + new File(programPath64 + "/Palm, Inc/novacom/x86/novacomd.exe").exists() || + new File(programPath64 + "/Palm/SDK/novacom/amd64/novacomd.exe").exists() || + new File(programPath64 + "/Palm/SDK/novacom/x86/novacomd.exe").exists() || + new File(programPath64 + "/Palm/SDK/bin/novacom/amd64/novacomd.exe").exists() || + new File(programPath64 + "/Palm/SDK/bin/novacom/x86/novacomd.exe").exists()) { + installed = true; + } + } + } else { + if(new File("C:/Program Files/HP webOS/SDK/bin/novacomd/amd64/novacomd.exe").exists() || + new File("C:/Program Files/HP webOS/SDK/bin/novacomd/x86/novacomd.exe").exists() || + new File("C:/Program Files/Palm, Inc/novacom/amd64/novacomd.exe").exists() || + new File("C:/Program Files/Palm, Inc/novacom/x86/novacomd.exe").exists() || + new File("C:/Program Files/Palm/SDK/novacom/amd64/novacomd.exe").exists() || + new File("C:/Program Files/Palm/SDK/novacom/x86/novacomd.exe").exists() || + new File("C:/Program Files/Palm/SDK/bin/novacom/amd64/novacomd.exe").exists() || + new File("C:/Program Files/Palm/SDK/bin/novacom/x86/novacomd.exe").exists()) { + installed = true; + } + } + } + if(!installed) { + try { + Process p = Runtime.getRuntime().exec("novacom -l"); + OutputStream os = p.getOutputStream(); + os.flush(); + os.close(); + TextStreamConsumer stdout = new TextStreamConsumer(p.getInputStream()); + stdout.start(); + TextStreamConsumer stderr = new TextStreamConsumer(p.getErrorStream()); + stderr.start(); + stdout.waitFor(); + installed = (p.waitFor()==0); + } catch(Exception e) {} + } + return installed; + } + + public static void restartService() { + Process restarter = null; + try { + String platform = System.getProperty("os.name").toLowerCase(); + if(platform.contains("windows")) { + restarter = Runtime.getRuntime().exec("net stop novacomd"); + doProcess(restarter); + restarter = Runtime.getRuntime().exec("net start novacomd"); + doProcess(restarter); + } else if(platform.contains("mac")) { + restarter = Runtime.getRuntime().exec("/usr/local/bin/stop-novacomd"); + doProcess(restarter); + restarter = Runtime.getRuntime().exec("/usr/local/bin/start-novacomd"); + doProcess(restarter); + } else if(platform.contains("linux")) { + restarter = Runtime.getRuntime().exec("stop palm-novacomd"); + doProcess(restarter); + restarter = Runtime.getRuntime().exec("killall -v -q novacomd"); + doProcess(restarter); + restarter = Runtime.getRuntime().exec("start palm-novacomd"); + doProcess(restarter); + } + } catch(Exception e) { + e.printStackTrace(); + } + } + + private static boolean doProcess(Process p) throws IOException, InterruptedException { + OutputStream os; + TextStreamConsumer stdout, stderr; + os = p.getOutputStream(); + os.flush(); + os.close(); + stdout = new TextStreamConsumer(p.getInputStream()); + stdout.start(); + stderr = new TextStreamConsumer(p.getErrorStream()); + stderr.start(); + int exitCode = p.waitFor(); + stdout.waitFor(); + stderr.waitFor(); + return (exitCode==0); + } +} diff --git a/src/ca/canucksoftware/novacom/NovacomDrivers.java b/src/ca/canucksoftware/novacom/NovacomDrivers.java new file mode 100644 index 0000000..3913bf8 --- /dev/null +++ b/src/ca/canucksoftware/novacom/NovacomDrivers.java @@ -0,0 +1,316 @@ + +package ca.canucksoftware.novacom; + +import ca.canucksoftware.utils.TextStreamConsumer; +import com.ice.tar.TarEntry; +import com.ice.tar.TarInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.text.NumberFormat; +import java.util.zip.GZIPInputStream; +import javax.swing.JLabel; +import javax.swing.JProgressBar; +import java.util.ResourceBundle; + +/** + * @author Jason Robitaille + */ +public class NovacomDrivers { + private Driver driver; + private JProgressBar pBar; + private JLabel label; + + public NovacomDrivers() { + pBar = null; + label = null; + String os = System.getProperty("os.name").toLowerCase(); + if(os.contains("windows")) { + if(System.getenv("ProgramFiles(x86)")==null) { + driver = Driver.Windows_x86; + } else { + driver = Driver.Windows_x64; + } + } else if(os.contains("mac")) { + driver = Driver.Mac; + } else if(os.contains("linux")) { + if(!is64bitLinux()) { + driver = Driver.Linux_x86; + } else { + driver = Driver.Linux_x64; + } + } + } + + public void setGUI(JLabel lbl, JProgressBar bar) { + label = lbl; + pBar = bar; + } + + private boolean is64bitLinux() { + boolean result = false; + try { + Process p = Runtime.getRuntime().exec("dpkg --print-architecture"); + OutputStream os = p.getOutputStream(); + os.flush(); + os.close(); + TextStreamConsumer stdout = new TextStreamConsumer(p.getInputStream()); + stdout.start(); + TextStreamConsumer stderr = new TextStreamConsumer(p.getErrorStream()); + stderr.start(); + stdout.waitFor(); + result = !stdout.toString().toLowerCase().contains("i386"); + } catch (IOException e) { + System.err.println("Unable to check Linux system architecture"); + } + return result; + } + + public boolean install() { + boolean result = false; + if(driver==Driver.Windows_x86 || driver==Driver.Windows_x64) { + result = installForWindows(); + } else if(driver==Driver.Mac) { + result = installForMac(); + } else if(driver==Driver.Linux_x86 || driver==Driver.Linux_x64) { + result = installForLinux(); + } + return result; + } + + public boolean installForWindows() { + boolean result = false; + File installer = extractInstaller(); + if(installer!=null) { + if(label!=null) { + label.setText("Installing driver..."); + } + String command = "msiexec /i " + installer.getAbsolutePath() + " /passive"; + if(isStandaloneInstalled()) { + command = "msiexec /i " + installer.getAbsolutePath()+ " REINSTALL=ALL REINSTALLMODE=vomus /norestart /passive"; + } + try { + Process p = Runtime.getRuntime().exec(command); + OutputStream os = p.getOutputStream(); + os.flush(); + os.close(); + TextStreamConsumer stdout = new TextStreamConsumer(p.getInputStream()); + stdout.start(); + TextStreamConsumer stderr = new TextStreamConsumer(p.getErrorStream()); + stderr.start(); + result = (p.waitFor()==0); + stdout.waitFor(); + stderr.waitFor(); + installer.delete(); + result = true; + } catch (Exception e) { + System.err.println("Unable to install " + driver.file()); + e.printStackTrace(); + } + } + return result; + } + + public boolean installForMac() { + boolean result = false; + File installer = extractInstaller(); + if(installer!=null) { + if(label!=null) { + label.setText("Installing driver..."); + } + try { + Process p = Runtime.getRuntime().exec("open -W " + installer.getAbsolutePath()); + OutputStream os = p.getOutputStream(); + os.flush(); + os.close(); + TextStreamConsumer stdout = new TextStreamConsumer(p.getInputStream()); + stdout.start(); + TextStreamConsumer stderr = new TextStreamConsumer(p.getErrorStream()); + stderr.start(); + result = (p.waitFor()==0); + stdout.waitFor(); + stderr.waitFor(); + deleteItem(installer); + result = true; + } catch (Exception e) { + System.err.println("Unable to install " + driver.file()); + } + } + return result; + } + + private boolean deleteItem(File path) { + if(path.isDirectory()) { + File[] files = path.listFiles(); + for(int i=0; iInstalling driver..."); + } + if(installer!=null) { + try { + Process p = Runtime.getRuntime().exec("xterm +hold -e sudo dpkg -i " + + installer.getAbsolutePath()); + OutputStream os = p.getOutputStream(); + os.flush(); + os.close(); + TextStreamConsumer stdout = new TextStreamConsumer(p.getInputStream()); + stdout.start(); + TextStreamConsumer stderr = new TextStreamConsumer(p.getErrorStream()); + stderr.start(); + result = (p.waitFor()==0); + stdout.waitFor(); + stderr.waitFor(); + installer.delete(); + result = true; + } catch (Exception e) { + System.err.println("Unable to install " + driver.file()); + e.printStackTrace(); + } + } + } + return result; + } + + private File extractInstaller() { + String tmpFilePath = System.getProperty("java.io.tmpdir"); + File result = new File(tmpFilePath, driver.file()); + if(result.exists()) { + deleteItem(result); + } + NumberFormat nf = NumberFormat.getNumberInstance(); + nf.setGroupingUsed(false); + nf.setMaximumFractionDigits(2); + TarInputStream tis = null; + try { + HttpURLConnection urlCon = (HttpURLConnection) new URL(driver.url()).openConnection(); + urlCon.setInstanceFollowRedirects(true); + urlCon.setRequestProperty("REFERER", driver.url()); + urlCon.connect(); + tis = new TarInputStream(new GZIPInputStream((urlCon.getInputStream()))); + TarEntry entry = tis.getNextEntry(); + byte data[] = new byte[2048]; + int count = 0; + int kbCount = 0; + while(entry!=null) { + if(!entry.getName().endsWith("hp_license_agreement.pdf")) { + File curr = new File(tmpFilePath, entry.getName()); + if(entry.isDirectory()) { + curr.mkdirs(); + } else { + OutputStream out = new BufferedOutputStream(new FileOutputStream(curr)); + while((count = tis.read(data)) != -1) { + if(label!=null) { + if(kbCount<1000) { + pBar.setString(kbCount + " KB"); + } else { + pBar.setString(nf.format(((double) kbCount)/1024.0) + " MB"); + } + } + kbCount+=2; + out.write(data, 0, count); + } + out.flush(); + out.close(); + + if(driver==Driver.Mac) { + try { + Process p = Runtime.getRuntime().exec("chmod ugoa+x " + curr.getAbsolutePath()); + OutputStream os = p.getOutputStream(); + os.flush(); + os.close(); + TextStreamConsumer stdout = new TextStreamConsumer(p.getInputStream()); + stdout.start(); + TextStreamConsumer stderr = new TextStreamConsumer(p.getErrorStream()); + stderr.start(); + p.waitFor(); + stdout.waitFor(); + stderr.waitFor(); + } catch (Exception e) { + System.err.println("Unable to chmod " + curr.getAbsolutePath()); + } + } + } + } + entry = tis.getNextEntry(); + } + tis.close(); + } catch(Exception e) { + e.printStackTrace(); + System.err.println("Unable to extract " + driver.file()); + result = null; + } + return result; + } + + + private boolean isStandaloneInstalled() { + boolean installed = false; + if(new File("/opt/Palm/novacom/novacomd").exists()) { //linux + installed = true; + } else if(new File("/opt/nova/bin/novacomd").exists() || + new File("/Library/LaunchDaemons/com.palm.novacomd").exists()) { //mac + installed = true; + }else { //windows + String programPath32 = System.getenv("ProgramFiles"); + String programPath64 = null; + if(programPath32!=null) { + programPath32 = programPath32.replace("\\", "/").trim(); + if(programPath32.endsWith("(x86)")) { + programPath64 = programPath32.substring(0, + programPath32.lastIndexOf("(x86)")).trim(); + programPath64 = programPath64.replace("\\", "/"); + } + if(new File(programPath32 + "/Palm, Inc/novacom/amd64/novacomd.exe").exists() || + new File(programPath32 + "/Palm, Inc/novacom/x86/novacomd.exe").exists()) { + installed = true; + } + if(programPath64 != null) { + if(new File(programPath64 + "/Palm, Inc/novacom/amd64/novacomd.exe").exists() || + new File(programPath64 + "/Palm, Inc/novacom/x86/novacomd.exe").exists()) { + installed = true; + } + } + } else { + if(new File("C:/Program Files/Palm, Inc/novacom/amd64/novacomd.exe").exists() || + new File("C:/Program Files/Palm, Inc/novacom/x86/novacomd.exe").exists()) { + installed = true; + } + } + } + return installed; + } + + private enum Driver { + Windows_x86("NovacomInstaller_x86.msi", "http://downloads.help.palm.com/opensource/novacom/novacom-win-32.tgz"), + Windows_x64("NovacomInstaller_x64.msi", "http://downloads.help.palm.com/opensource/novacom/novacom-win-64.tgz"), + Mac("NovacomInstaller.pkg", "http://downloads.help.palm.com/opensource/novacom/novacom-mac.tgz"), + Linux_x86("palm-novacom_1.0.76_i386.deb", "http://downloads.help.palm.com/opensource/novacom/novacom-linux-32.tgz"), + Linux_x64("palm-novacom_1.0.76_amd64.deb", "http://downloads.help.palm.com/opensource/novacom/novacom-linux-64.tgz"); + + private String file, url; + Driver(String file, String url) { + this.file = file; + this.url = url; + } + public String file() { return file; } + public String url() { return url; } + } +} diff --git a/src/ca/canucksoftware/novacominstaller/DriverDownloader.form b/src/ca/canucksoftware/novacominstaller/DriverDownloader.form new file mode 100644 index 0000000..bbf0f29 --- /dev/null +++ b/src/ca/canucksoftware/novacominstaller/DriverDownloader.form @@ -0,0 +1,99 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ca/canucksoftware/novacominstaller/DriverDownloader.java b/src/ca/canucksoftware/novacominstaller/DriverDownloader.java new file mode 100644 index 0000000..ead5b45 --- /dev/null +++ b/src/ca/canucksoftware/novacominstaller/DriverDownloader.java @@ -0,0 +1,123 @@ +/* + * WebOSQuickInstallAboutBox.java + */ + +package ca.canucksoftware.novacominstaller; + +import ca.canucksoftware.novacom.NovacomDrivers; +import java.util.Timer; +import java.util.TimerTask; +import javax.swing.JOptionPane; + + +public class DriverDownloader extends javax.swing.JDialog { + private Timer t; + private boolean downloadStarted; + + public DriverDownloader(java.awt.Frame parent) { + super(parent); + initComponents(); + t = new Timer(); + downloadStarted = false; + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLayeredPane1 = new javax.swing.JLayeredPane(); + jProgressBar1 = new javax.swing.JProgressBar(); + jLabel1 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); + org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ca.canucksoftware.novacominstaller.NovacomInstallerApp.class).getContext().getResourceMap(DriverDownloader.class); + setBackground(resourceMap.getColor("transfer.background")); // NOI18N + setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR)); + setForeground(resourceMap.getColor("transfer.foreground")); // NOI18N + setIconImage(null); + setModal(true); + setName("transfer"); // NOI18N + setResizable(false); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowActivated(java.awt.event.WindowEvent evt) { + formWindowActivated(evt); + } + public void windowClosed(java.awt.event.WindowEvent evt) { + formWindowClosed(evt); + } + public void windowOpened(java.awt.event.WindowEvent evt) { + formWindowOpened(evt); + } + }); + + jLayeredPane1.setBackground(resourceMap.getColor("jLayeredPane1.background")); // NOI18N + jLayeredPane1.setForeground(resourceMap.getColor("jLayeredPane1.foreground")); // NOI18N + jLayeredPane1.setName("jLayeredPane1"); // NOI18N + jLayeredPane1.setOpaque(true); + + jProgressBar1.setFont(jProgressBar1.getFont()); + jProgressBar1.setMaximum(1); + jProgressBar1.setName("jProgressBar1"); // NOI18N + jProgressBar1.setString(resourceMap.getString("jProgressBar1.string")); // NOI18N + jProgressBar1.setStringPainted(true); + jProgressBar1.setBounds(50, 60, 200, 30); + jLayeredPane1.add(jProgressBar1, javax.swing.JLayeredPane.DEFAULT_LAYER); + + jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getSize()+1f)); + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N + jLabel1.setName("jLabel1"); // NOI18N + jLabel1.setBounds(30, 10, 240, 40); + jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE) + ); + + pack(); + }// //GEN-END:initComponents + + private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened + }//GEN-LAST:event_formWindowOpened + + private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated + if(!downloadStarted) { + t.schedule(new DoDownload(), 100); + downloadStarted = true; + } + }//GEN-LAST:event_formWindowActivated + + private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed + }//GEN-LAST:event_formWindowClosed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + private javax.swing.JLayeredPane jLayeredPane1; + private javax.swing.JProgressBar jProgressBar1; + // End of variables declaration//GEN-END:variables + + class DoDownload extends TimerTask { + public void run() { + t.cancel(); + NovacomDrivers driver = new NovacomDrivers(); + driver.setGUI(jLabel1, jProgressBar1); + if(driver.install()) { + JOptionPane.showMessageDialog(rootPane, "Driver installed successfully."); + } else { + JOptionPane.showMessageDialog(rootPane, "ERROR: Driver installation failed"); + } + dispose(); + } + } +} diff --git a/src/ca/canucksoftware/novacominstaller/NovacomInstallerApp.java b/src/ca/canucksoftware/novacominstaller/NovacomInstallerApp.java new file mode 100644 index 0000000..12dbcd0 --- /dev/null +++ b/src/ca/canucksoftware/novacominstaller/NovacomInstallerApp.java @@ -0,0 +1,51 @@ +/* + * NovacomInstallerApp.java + */ + +package ca.canucksoftware.novacominstaller; + +import org.jdesktop.application.Application; +import org.jdesktop.application.SingleFrameApplication; + +/** + * The main class of the application. + */ +public class NovacomInstallerApp extends SingleFrameApplication { + + /** + * At startup create and show the main frame of the application. + */ + @Override protected void startup() { + NovacomInstallerView app = new NovacomInstallerView(this); + app.getFrame().setResizable(false); + app.getFrame().setSize(220, 140); + app.getFrame().setTitle("Universal Novacom Installer"); + app.getFrame().setVisible(true); + app.getFrame().requestFocus(); + + show(app); + } + + /** + * This method is to initialize the specified window by injecting resources. + * Windows shown in our application come fully initialized from the GUI + * builder, so this additional configuration is not needed. + */ + @Override protected void configureWindow(java.awt.Window root) { + } + + /** + * A convenient static getter for the application instance. + * @return the instance of NovacomInstallerApp + */ + public static NovacomInstallerApp getApplication() { + return Application.getInstance(NovacomInstallerApp.class); + } + + /** + * Main method launching the application. + */ + public static void main(String[] args) { + launch(NovacomInstallerApp.class, args); + } +} diff --git a/src/ca/canucksoftware/novacominstaller/NovacomInstallerView.form b/src/ca/canucksoftware/novacominstaller/NovacomInstallerView.form new file mode 100644 index 0000000..bbd922a --- /dev/null +++ b/src/ca/canucksoftware/novacominstaller/NovacomInstallerView.form @@ -0,0 +1,87 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/ca/canucksoftware/novacominstaller/NovacomInstallerView.java b/src/ca/canucksoftware/novacominstaller/NovacomInstallerView.java new file mode 100644 index 0000000..c2126c2 --- /dev/null +++ b/src/ca/canucksoftware/novacominstaller/NovacomInstallerView.java @@ -0,0 +1,165 @@ +/* + * NovacomInstallerView.java + */ + +package ca.canucksoftware.novacominstaller; + +import ca.canucksoftware.novacom.NovacomDrivers; +import ca.canucksoftware.utils.TextStreamConsumer; +import org.jdesktop.application.SingleFrameApplication; +import org.jdesktop.application.FrameView; +import javax.swing.JOptionPane; +import java.io.*; +import java.util.TimerTask; +import javax.swing.JFrame; + +/** + * The application's main frame. + */ +public class NovacomInstallerView extends FrameView { + public java.util.Timer t; + + public NovacomInstallerView(SingleFrameApplication app) { + super(app); + initComponents(); + String os = System.getProperty("os.name").toLowerCase(); + if(os.contains("windows")) { + if(System.getenv("ProgramFiles(x86)")==null) { + jLabel2.setText("Windows 32bit"); + } else { + jLabel2.setText("Windows 64bit"); + } + } else if(os.contains("mac")) { + jLabel2.setText("Mac OS"); + } else if(os.contains("linux")) { + if(!is64bitLinux()) { + jLabel2.setText("Linux 32bit"); + } else { + jLabel2.setText("Linux 64bit"); + } + } else { + jLabel2.setText(""); + } + } + + private boolean is64bitLinux() { + boolean result = false; + try { + Process p = Runtime.getRuntime().exec("dpkg --print-architecture"); + OutputStream os = p.getOutputStream(); + os.flush(); + os.close(); + TextStreamConsumer stdout = new TextStreamConsumer(p.getInputStream()); + stdout.start(); + TextStreamConsumer stderr = new TextStreamConsumer(p.getErrorStream()); + stderr.start(); + stdout.waitFor(); + result = !stdout.toString().toLowerCase().contains("i386"); + } catch (IOException e) { + System.err.println("Unable to check Linux system architecture"); + } + return result; + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + mainPanel = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + + mainPanel.setName("mainPanel"); // NOI18N + + org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ca.canucksoftware.novacominstaller.NovacomInstallerApp.class).getContext().getResourceMap(NovacomInstallerView.class); + jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N + jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N + jLabel1.setName("jLabel1"); // NOI18N + + jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N + jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N + jLabel2.setName("jLabel2"); // NOI18N + + jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N + jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N + jButton1.setName("jButton1"); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(jLabel1) + .addGap(18, 18, 18) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(16, Short.MAX_VALUE)) + ); + + setComponent(mainPanel); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + t = new java.util.Timer(); + jButton1.setEnabled(false); + jButton1.setText("Please wait..."); + t.schedule(new DoInstallation(), 200); + }//GEN-LAST:event_jButton1ActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JPanel mainPanel; + // End of variables declaration//GEN-END:variables + + class DoInstallation extends TimerTask { + public void run() { + JFrame mainFrame = NovacomInstallerApp.getApplication().getMainFrame(); + DriverDownloader downloader = new DriverDownloader(mainFrame); + NovacomInstallerApp.getApplication().show(downloader); + jButton1.setEnabled(true); + jButton1.setText("Install Novacom"); + } + } + + class DoctorChooseFilter extends javax.swing.filechooser.FileFilter { + private final String[] okFileExtensions = new String[] {".jar"}; + + public boolean accept(File f) { + for (String extension : okFileExtensions) + if (f.getName().toLowerCase().endsWith(extension) || f.isDirectory()) + return true; + return false; + } + + public String getDescription() { + return "Jar Files (*.jar)"; + } + } +} diff --git a/src/ca/canucksoftware/novacominstaller/resources/DriverDownloader.properties b/src/ca/canucksoftware/novacominstaller/resources/DriverDownloader.properties new file mode 100644 index 0000000..fab6680 --- /dev/null +++ b/src/ca/canucksoftware/novacominstaller/resources/DriverDownloader.properties @@ -0,0 +1,13 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +#NOI18N +jLayeredPane1.background=219, 219, 219 +#NOI18N +transfer.foreground=219, 219, 219 +#NOI18N +transfer.background=219, 219, 219 +#NOI18N +jLayeredPane1.foreground=243, 241, 233 +jLabel1.text=Downloading Novacom Drivers +jProgressBar1.string=Initializing... diff --git a/src/ca/canucksoftware/novacominstaller/resources/NovacomInstallerApp.properties b/src/ca/canucksoftware/novacominstaller/resources/NovacomInstallerApp.properties new file mode 100644 index 0000000..9a429d9 --- /dev/null +++ b/src/ca/canucksoftware/novacominstaller/resources/NovacomInstallerApp.properties @@ -0,0 +1,12 @@ +# Application global resources + +Application.name = Universal Novacom Installer +Application.title = Universal Novacom Installer +Application.version = 1.2.1 +Application.vendor = Jason Robitaille +Application.description = +Application.vendorId = JasonRobitaille +Application.id = Universal Novacom Installer +Application.lookAndFeel = system +#NOI18N +Application.homepage= diff --git a/src/ca/canucksoftware/novacominstaller/resources/NovacomInstallerView.properties b/src/ca/canucksoftware/novacominstaller/resources/NovacomInstallerView.properties new file mode 100644 index 0000000..1a08caf --- /dev/null +++ b/src/ca/canucksoftware/novacominstaller/resources/NovacomInstallerView.properties @@ -0,0 +1,37 @@ + +# @Action resources + +showAboutBox.Action.text = &About... +showAboutBox.Action.shortDescription = Show the application's information dialog + +# status bar resources + +StatusBar.messageTimeout = 5000 +StatusBar.busyAnimationRate = 30 +StatusBar.idleIcon = busyicons/idle-icon.png +StatusBar.busyIcons[0] = busyicons/busy-icon0.png +StatusBar.busyIcons[1] = busyicons/busy-icon1.png +StatusBar.busyIcons[2] = busyicons/busy-icon2.png +StatusBar.busyIcons[3] = busyicons/busy-icon3.png +StatusBar.busyIcons[4] = busyicons/busy-icon4.png +StatusBar.busyIcons[5] = busyicons/busy-icon5.png +StatusBar.busyIcons[6] = busyicons/busy-icon6.png +StatusBar.busyIcons[7] = busyicons/busy-icon7.png +StatusBar.busyIcons[8] = busyicons/busy-icon8.png +StatusBar.busyIcons[9] = busyicons/busy-icon9.png +StatusBar.busyIcons[10] = busyicons/busy-icon10.png +StatusBar.busyIcons[11] = busyicons/busy-icon11.png +StatusBar.busyIcons[12] = busyicons/busy-icon12.png +StatusBar.busyIcons[13] = busyicons/busy-icon13.png +StatusBar.busyIcons[14] = busyicons/busy-icon14.png +jLabel1.text=OS Detected: +jLabel2.text= +#NOI18N +jLabel2.font=Tahoma-Plain-14 +jButton1.text=Install Novacom +#NOI18N +jButton1.font=Tahoma-Plain-18 +diffOS.Action.text= +diffOS.Action.shortDescription= +#NOI18N +jLabel1.font=Tahoma-Plain-12 diff --git a/src/ca/canucksoftware/utils/FileUtils.java b/src/ca/canucksoftware/utils/FileUtils.java new file mode 100644 index 0000000..a6ead53 --- /dev/null +++ b/src/ca/canucksoftware/utils/FileUtils.java @@ -0,0 +1,65 @@ + +package ca.canucksoftware.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import org.jdesktop.application.Application; + +/** + * + * @author Jason + */ +public class FileUtils { + public static File appDirectory() { + File app, dir; + try { + app = new File(Application.getInstance() + .getClass().getProtectionDomain().getCodeSource().getLocation().toURI()); + dir = app.getParentFile(); + } catch(Exception e) { + app = new File(Application.getInstance().getClass().getProtectionDomain() + .getCodeSource().getLocation() + .getPath().replaceAll("%20", " ")); + dir = app.getParentFile(); + } + return dir; + } + + public static void copy(File from, File to) throws IOException { + FileInputStream fis = new FileInputStream(from); + FileOutputStream fos = new FileOutputStream(to); + try { + byte[] buf = new byte[1024]; + int i = 0; + while ((i = fis.read(buf)) != -1) { + fos.write(buf, 0, i); + } + } catch (IOException e) { + throw e; + } finally { + if (fis != null) + fis.close(); + if (fos != null) + fos.close(); + } + } + + public static String getFilename(File file) { + return getFilename(file.getName()); + } + + public static String getFilename(String file) { + String name = file; + int index = name.lastIndexOf("\\"); + if(index>-1) { + name = name.substring(index+1, name.length()); + } else { + index = name.lastIndexOf("/"); + if(index>-1) + name = name.substring(index+1, name.length()); + } + return name; + } +} diff --git a/src/ca/canucksoftware/utils/OnlineFile.java b/src/ca/canucksoftware/utils/OnlineFile.java new file mode 100644 index 0000000..bf05913 --- /dev/null +++ b/src/ca/canucksoftware/utils/OnlineFile.java @@ -0,0 +1,87 @@ + +package ca.canucksoftware.utils; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; + +/** + * @author Jason Robitaille + */ +public class OnlineFile { + private String url; + + public OnlineFile(URL file) { + this(file.toString()); + } + public OnlineFile(String file) { + url = file; + } + + public boolean exists() { + boolean result = false; + try { + HttpURLConnection.setFollowRedirects(false); + HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); + con.setInstanceFollowRedirects(false); + con.setConnectTimeout(3000); + con.setReadTimeout(3000); + con.setRequestMethod("HEAD"); + result = (con.getResponseCode() == HttpURLConnection.HTTP_OK); + } catch (Exception e) { + result = false; + } + return result; + } + + public File download() { + String tmpFilePath = System.getProperty("java.io.tmpdir"); + File output = new File(tmpFilePath, url.substring(url.lastIndexOf("/")+1)); + return download(output); + } + + public File download(File output) { + File result = output; + URLConnection urlCon = null; + if(exists()) { + try { + urlCon = getURL().openConnection(); + urlCon.setRequestProperty("Content-Type", "application/binary"); + if(result.exists()) { + result.delete(); + } + BufferedInputStream bis = new BufferedInputStream(urlCon.getInputStream()); + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(result)); + byte[] buf = new byte[1024]; + int len; + while ((len = bis.read(buf)) > 0){ + bos.write(buf, 0, len); + } + bos.flush(); + bis.close(); + bos.close(); + } catch(Exception e) { + e.printStackTrace(); + if(result.exists()) { + result.delete(); + } + result = null; + } + } else { + if(result.exists()) { + result.delete(); + } + result = null; + } + return result; + } + + @Override + public String toString() { return url; } + public URL getURL() throws MalformedURLException { return new URL(url); } +} diff --git a/src/ca/canucksoftware/utils/TextStreamConsumer.java b/src/ca/canucksoftware/utils/TextStreamConsumer.java new file mode 100644 index 0000000..455bbad --- /dev/null +++ b/src/ca/canucksoftware/utils/TextStreamConsumer.java @@ -0,0 +1,51 @@ + +package ca.canucksoftware.utils; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +/** + * @author Jason Robitaille + */ +public class TextStreamConsumer extends Thread { + private InputStream is; + private String output; + + public TextStreamConsumer(InputStream stream) { + is = stream; + output = null; + } + + @Override + public void run() { + String result = ""; + try { + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String line = br.readLine(); + while(line!=null) { + result += line; + line = br.readLine(); + if(line!=null) { + result += "\n"; + } + } + br.close(); + is.close(); + } catch(Exception e) {} + output = result; + } + + public void waitFor() { + try { + super.join(); + } catch (InterruptedException e) { + System.err.println("TextStreamConsumer thread interrupted"); + } + } + + @Override + public String toString() { + return output; + } +}