File Source: LauncherComponent.java

     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.updater.components;
    24  
    25  import com.dmdirc.updater.UpdateChecker;
    26  import com.dmdirc.updater.UpdateComponent;
    27  import com.dmdirc.updater.Version;
    28  import com.dmdirc.util.resourcemanager.ZipResourceManager;
    29  
    30  import java.io.File;
    31  
    32  /**
    33   * Component for updates of DMDirc's launcher.
    34   *
    35   * @author chris
    36   */
         /* 
    P/P   *  Method: void com.dmdirc.updater.components.LauncherComponent()
          */
    37  public class LauncherComponent implements UpdateComponent {
    38  
    39      /** The platform of our current launcher. */
             /* 
    P/P       *  Method: com.dmdirc.updater.components.LauncherComponent__static_init
              * 
              *  Postconditions:
              *    platform == &""
              *    version == -1
              */
    40      private static String platform = "";
    41  
    42      /** The version of our current launcher. */
    43      private static int version = -1;
    44  
    45      /**
    46       * Parses the specified launcher information.
    47       *
    48       * @param info The platform and version of the launcher, separated by '-'.
    49       */
    50      public static void setLauncherInfo(final String info) {
                 /* 
    P/P           *  Method: void setLauncherInfo(String)
                  * 
                  *  Preconditions:
                  *    info != null
                  * 
                  *  Presumptions:
                  *    java.lang.String:indexOf(...)@51 <= 232-2
                  * 
                  *  Postconditions:
                  *    init'ed(java.lang.String:substring(...)._tainted)
                  *    platform == One-of{old platform, &amp;java.lang.String:substring(...)}
                  *    possibly_updated(version)
                  * 
                  *  Test Vectors:
                  *    java.lang.String:indexOf(...)@51: {-231..-2, 0..232-2}, {-1}
                  */
    51          final int hpos = info.indexOf('-');
    52  
    53          if (hpos == -1) {
    54              return;
    55          }
    56  
    57          try {
    58              platform = info.substring(0, hpos);
    59              version = Integer.parseInt(info.substring(hpos + 1));
    60          } catch (NumberFormatException ex) {
    61              return;
    62          }
    63  
    64          UpdateChecker.registerComponent(new LauncherComponent());
    65      }
    66  
    67      /**
    68       * Determines if the client has been run using the launcher.
    69       *
    70       * @return True if the launcher has been used, false otherwise
    71       */
    72      public static boolean isUsingLauncher() {
                 /* 
    P/P           *  Method: bool isUsingLauncher()
                  * 
                  *  Preconditions:
                  *    init'ed(version)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    73          return version != -1;
    74      }
    75  
    76      /** {@inheritDoc} */
    77      @Override
    78      public String getName() {
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Preconditions:
                  *    init'ed(platform)
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == platform._tainted
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &amp;java.lang.StringBuilder:toString(...)
                  */
    79          return "launcher-" + platform;
    80      }
    81      
    82      /** {@inheritDoc} */
    83      @Override
    84      public String getFriendlyName() {
                 /* 
    P/P           *  Method: String getFriendlyName()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;"Launcher"
                  */
    85          return "Launcher";
    86      }    
    87  
    88      /** {@inheritDoc} */
    89      @Override
    90      public String getFriendlyVersion() {
                 /* 
    P/P           *  Method: String getFriendlyVersion()
                  * 
                  *  Preconditions:
                  *    init'ed(version)
                  * 
                  *  Postconditions:
                  *    java.lang.String:valueOf(...)._tainted == 0
                  *    return_value == &amp;java.lang.String:valueOf(...)
                  */
    91          return String.valueOf(getVersion());
    92      }
    93  
    94      /** {@inheritDoc} */
    95      @Override
    96      public Version getVersion() {
                 /* 
    P/P           *  Method: Version getVersion()
                  * 
                  *  Preconditions:
                  *    init'ed(version)
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new Version(getVersion#1)
                  *    new Version(getVersion#1) num objects == 1
                  *    return_value.intVersion == version
                  *    init'ed(return_value.intVersion)
                  *    return_value.strVersion == null
                  */
    97          return new Version(version);
    98      }
    99  
   100      /** {@inheritDoc} */
   101      @Override
   102      public boolean doInstall(final String path) throws Throwable {
                 /* 
    P/P           *  Method: bool doInstall(String)
                  * 
                  *  Preconditions:
                  *    platform != null
                  * 
                  *  Presumptions:
                  *    init'ed(java.io.File.separator)
                  * 
                  *  Postconditions:
                  *    return_value == 1
                  * 
                  *  Test Vectors:
                  *    java.io.File:exists(...)@107: {0}, {1}
                  *    java.lang.String:equalsIgnoreCase(...)@104: {1}, {0}
                  *    java.lang.String:equalsIgnoreCase(...)@104: {0}, {1}
                  */
   103          final File tmpFile = new File(path);
   104          if (platform.equalsIgnoreCase("Linux") || platform.equalsIgnoreCase("unix")) {
   105              final File targetFile = new File(tmpFile.getParent() + File.separator + ".launcher.sh");
   106  
   107              if (targetFile.exists()) {
   108                  targetFile.delete();
   109              }
   110  
   111              tmpFile.renameTo(targetFile);
   112              targetFile.setExecutable(true);
   113              return true;
   114          } else {
   115              final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
   116              ziprm.extractResources("", tmpFile.getParent()+ File.separator);
   117              new File(path).delete();
   118              return true;
   119          }
   120      }
   121  
   122  }








SofCheck Inspector Build Version : 2.17854
LauncherComponent.java 2009-Jun-25 01:54:24
LauncherComponent.class 2009-Sep-02 17:04:17