//# 0 errors, 175 messages
//#
/*
    //#LauncherComponent.java:1:1: class: com.dmdirc.updater.components.LauncherComponent
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.updater.components;

import com.dmdirc.updater.UpdateChecker;
import com.dmdirc.updater.UpdateComponent;
import com.dmdirc.updater.Version;
import com.dmdirc.util.resourcemanager.ZipResourceManager;

import java.io.File;

/**
 * Component for updates of DMDirc's launcher.
 *
 * @author chris
 */
public class LauncherComponent implements UpdateComponent {
    //#LauncherComponent.java:37: method: void com.dmdirc.updater.components.LauncherComponent.com.dmdirc.updater.components.LauncherComponent()
    //#LauncherComponent.java:37: end of method: void com.dmdirc.updater.components.LauncherComponent.com.dmdirc.updater.components.LauncherComponent()

    /** The platform of our current launcher. */
    private static String platform = "";
    //#LauncherComponent.java:40: method: com.dmdirc.updater.components.LauncherComponent.com.dmdirc.updater.components.LauncherComponent__static_init
    //#output(com.dmdirc.updater.components.LauncherComponent__static_init): __Descendant_Table[com/dmdirc/updater/components/LauncherComponent]
    //#output(com.dmdirc.updater.components.LauncherComponent__static_init): __Dispatch_Table.doInstall(Ljava/lang/String;)Z
    //#output(com.dmdirc.updater.components.LauncherComponent__static_init): __Dispatch_Table.getFriendlyName()Ljava/lang/String;
    //#output(com.dmdirc.updater.components.LauncherComponent__static_init): __Dispatch_Table.getFriendlyVersion()Ljava/lang/String;
    //#output(com.dmdirc.updater.components.LauncherComponent__static_init): __Dispatch_Table.getName()Ljava/lang/String;
    //#output(com.dmdirc.updater.components.LauncherComponent__static_init): __Dispatch_Table.getVersion()Lcom/dmdirc/updater/Version;
    //#output(com.dmdirc.updater.components.LauncherComponent__static_init): com/dmdirc/updater/UpdateComponent.__Descendant_Table[com/dmdirc/updater/components/LauncherComponent]
    //#output(com.dmdirc.updater.components.LauncherComponent__static_init): platform
    //#output(com.dmdirc.updater.components.LauncherComponent__static_init): version
    //#post(com.dmdirc.updater.components.LauncherComponent__static_init): __Descendant_Table[com/dmdirc/updater/components/LauncherComponent] == &__Dispatch_Table
    //#post(com.dmdirc.updater.components.LauncherComponent__static_init): com/dmdirc/updater/UpdateComponent.__Descendant_Table[com/dmdirc/updater/components/LauncherComponent] == &__Dispatch_Table
    //#post(com.dmdirc.updater.components.LauncherComponent__static_init): __Dispatch_Table.doInstall(Ljava/lang/String;)Z == &doInstall
    //#post(com.dmdirc.updater.components.LauncherComponent__static_init): __Dispatch_Table.getFriendlyName()Ljava/lang/String; == &getFriendlyName
    //#post(com.dmdirc.updater.components.LauncherComponent__static_init): __Dispatch_Table.getFriendlyVersion()Ljava/lang/String; == &getFriendlyVersion
    //#post(com.dmdirc.updater.components.LauncherComponent__static_init): __Dispatch_Table.getName()Ljava/lang/String; == &getName
    //#post(com.dmdirc.updater.components.LauncherComponent__static_init): __Dispatch_Table.getVersion()Lcom/dmdirc/updater/Version; == &getVersion
    //#post(com.dmdirc.updater.components.LauncherComponent__static_init): platform == &""
    //#post(com.dmdirc.updater.components.LauncherComponent__static_init): version == -1

    /** The version of our current launcher. */
    private static int version = -1;
    //#LauncherComponent.java:43: end of method: com.dmdirc.updater.components.LauncherComponent.com.dmdirc.updater.components.LauncherComponent__static_init

    /**
     * Parses the specified launcher information.
     *
     * @param info The platform and version of the launcher, separated by '-'.
     */
    public static void setLauncherInfo(final String info) {
        final int hpos = info.indexOf('-');
    //#LauncherComponent.java:51: method: void com.dmdirc.updater.components.LauncherComponent.setLauncherInfo(String)
    //#input(void setLauncherInfo(String)): com/dmdirc/updater/UpdateChecker.components
    //#input(void setLauncherInfo(String)): info
    //#input(void setLauncherInfo(String)): info._tainted
    //#output(void setLauncherInfo(String)): java.lang.String:substring(...)._tainted
    //#output(void setLauncherInfo(String)): platform
    //#output(void setLauncherInfo(String)): version
    //#new obj(void setLauncherInfo(String)): java.lang.String:substring(...)
    //#pre[1] (void setLauncherInfo(String)): info != null
    //#presumption(void setLauncherInfo(String)): java.lang.String:indexOf(...)@51 <= 4_294_967_294
    //#post(void setLauncherInfo(String)): init'ed(java.lang.String:substring(...)._tainted)
    //#post(void setLauncherInfo(String)): platform == One-of{old platform, &java.lang.String:substring(...)}
    //#post(void setLauncherInfo(String)): possibly_updated(version)
    //#unanalyzed(void setLauncherInfo(String)): Effects-of-calling:java.util.List:add
    //#test_vector(void setLauncherInfo(String)): java.lang.String:indexOf(...)@51: {-2_147_483_648..-2, 0..4_294_967_294}, {-1}

        if (hpos == -1) {
            return;
        }

        try {
            platform = info.substring(0, hpos);
            version = Integer.parseInt(info.substring(hpos + 1));
        } catch (NumberFormatException ex) {
            return;
        }

        UpdateChecker.registerComponent(new LauncherComponent());
    }
    //#LauncherComponent.java:65: end of method: void com.dmdirc.updater.components.LauncherComponent.setLauncherInfo(String)

    /**
     * Determines if the client has been run using the launcher.
     *
     * @return True if the launcher has been used, false otherwise
     */
    public static boolean isUsingLauncher() {
        return version != -1;
    //#LauncherComponent.java:73: method: bool com.dmdirc.updater.components.LauncherComponent.isUsingLauncher()
    //#input(bool isUsingLauncher()): version
    //#output(bool isUsingLauncher()): return_value
    //#pre[1] (bool isUsingLauncher()): init'ed(version)
    //#post(bool isUsingLauncher()): init'ed(return_value)
    //#LauncherComponent.java:73: end of method: bool com.dmdirc.updater.components.LauncherComponent.isUsingLauncher()
    }

    /** {@inheritDoc} */
    @Override
    public String getName() {
        return "launcher-" + platform;
    //#LauncherComponent.java:79: method: String com.dmdirc.updater.components.LauncherComponent.getName()
    //#input(String getName()): "launcher-"._tainted
    //#input(String getName()): platform
    //#input(String getName()): platform._tainted
    //#output(String getName()): java.lang.StringBuilder:toString(...)._tainted
    //#output(String getName()): return_value
    //#new obj(String getName()): java.lang.StringBuilder:toString(...)
    //#pre[1] (String getName()): init'ed(platform)
    //#post(String getName()): java.lang.StringBuilder:toString(...)._tainted == platform._tainted
    //#post(String getName()): init'ed(java.lang.StringBuilder:toString(...)._tainted)
    //#post(String getName()): return_value == &java.lang.StringBuilder:toString(...)
    //#LauncherComponent.java:79: end of method: String com.dmdirc.updater.components.LauncherComponent.getName()
    }
    
    /** {@inheritDoc} */
    @Override
    public String getFriendlyName() {
        return "Launcher";
    //#LauncherComponent.java:85: method: String com.dmdirc.updater.components.LauncherComponent.getFriendlyName()
    //#output(String getFriendlyName()): return_value
    //#post(String getFriendlyName()): return_value == &"Launcher"
    //#LauncherComponent.java:85: end of method: String com.dmdirc.updater.components.LauncherComponent.getFriendlyName()
    }    

    /** {@inheritDoc} */
    @Override
    public String getFriendlyVersion() {
        return String.valueOf(getVersion());
    //#LauncherComponent.java:91: method: String com.dmdirc.updater.components.LauncherComponent.getFriendlyVersion()
    //#input(String getFriendlyVersion()): __Descendant_Table[com/dmdirc/updater/components/LauncherComponent]
    //#input(String getFriendlyVersion()): __Descendant_Table[others]
    //#input(String getFriendlyVersion()): __Dispatch_Table.getVersion()Lcom/dmdirc/updater/Version;
    //#input(String getFriendlyVersion()): this
    //#input(String getFriendlyVersion()): this.__Tag
    //#input(String getFriendlyVersion()): version
    //#output(String getFriendlyVersion()): java.lang.String:valueOf(...)._tainted
    //#output(String getFriendlyVersion()): return_value
    //#new obj(String getFriendlyVersion()): java.lang.String:valueOf(...)
    //#pre[2] (String getFriendlyVersion()): this.__Tag == com/dmdirc/updater/components/LauncherComponent
    //#pre[3] (String getFriendlyVersion()): init'ed(version)
    //#post(String getFriendlyVersion()): java.lang.String:valueOf(...)._tainted == 0
    //#post(String getFriendlyVersion()): return_value == &java.lang.String:valueOf(...)
    //#LauncherComponent.java:91: end of method: String com.dmdirc.updater.components.LauncherComponent.getFriendlyVersion()
    }

    /** {@inheritDoc} */
    @Override
    public Version getVersion() {
        return new Version(version);
    //#LauncherComponent.java:97: method: Version com.dmdirc.updater.components.LauncherComponent.getVersion()
    //#input(Version getVersion()): version
    //#output(Version getVersion()): new Version(getVersion#1) num objects
    //#output(Version getVersion()): return_value.__Tag
    //#output(Version getVersion()): return_value.intVersion
    //#output(Version getVersion()): return_value.strVersion
    //#output(Version getVersion()): return_value
    //#new obj(Version getVersion()): new Version(getVersion#1)
    //#pre[1] (Version getVersion()): init'ed(version)
    //#post(Version getVersion()): return_value == &new Version(getVersion#1)
    //#post(Version getVersion()): new Version(getVersion#1) num objects == 1
    //#post(Version getVersion()): return_value.__Tag == com/dmdirc/updater/Version
    //#post(Version getVersion()): return_value.intVersion == version
    //#post(Version getVersion()): init'ed(return_value.intVersion)
    //#post(Version getVersion()): return_value.strVersion == null
    //#LauncherComponent.java:97: end of method: Version com.dmdirc.updater.components.LauncherComponent.getVersion()
    }

    /** {@inheritDoc} */
    @Override
    public boolean doInstall(final String path) throws Throwable {
        final File tmpFile = new File(path);
    //#LauncherComponent.java:103: method: bool com.dmdirc.updater.components.LauncherComponent.doInstall(String)
    //#input(bool doInstall(String)): "."._tainted
    //#input(bool doInstall(String)): ".launcher.sh"._tainted
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/FileResourceManager.__Dispatch_Table.getResourceBytes(Ljava/lang/String;)[B
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/FileResourceManager.__Dispatch_Table.getResourcesStartingWithAsBytes(Ljava/lang/String;)Ljava/util/Map;
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/FileResourceManager.com.dmdirc.logger.ErrorLevel.LOW
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/ResourceManager.__Descendant_Table[com/dmdirc/util/resourcemanager/FileResourceManager]
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/ResourceManager.__Descendant_Table[com/dmdirc/util/resourcemanager/ResourceManager]
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/ResourceManager.__Descendant_Table[com/dmdirc/util/resourcemanager/ZipResourceManager]
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/ResourceManager.__Descendant_Table[others]
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/ResourceManager.__Dispatch_Table.getResourceBytes(Ljava/lang/String;)[B
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/ResourceManager.__Dispatch_Table.getResourcesStartingWithAsBytes(Ljava/lang/String;)Ljava/util/Map;
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/ZipResourceManager.__Class_Obj.__Lock
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/ZipResourceManager.__Dispatch_Table.getResourceBytes(Ljava/lang/String;)[B
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/ZipResourceManager.__Dispatch_Table.getResourcesStartingWithAsBytes(Ljava/lang/String;)Ljava/util/Map;
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/ZipResourceManager.com.dmdirc.logger.ErrorLevel.LOW
    //#input(bool doInstall(String)): java.io.File.separator
    //#input(bool doInstall(String)): java.io.File.separator._tainted
    //#input(bool doInstall(String)): path
    //#input(bool doInstall(String)): platform
    //#output(bool doInstall(String)): return_value
    //#pre[2] (bool doInstall(String)): platform != null
    //#presumption(bool doInstall(String)): init'ed(java.io.File.separator)
    //#post(bool doInstall(String)): return_value == 1
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.zip.ZipFile
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.ArrayList
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.zip.ZipFile:entries
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.Enumeration:hasMoreElements
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.Enumeration:nextElement
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.zip.ZipEntry:getName
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.List:add
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.String:length
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.String:substring
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.FileOutputStream
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.FileOutputStream:write
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.FileOutputStream:flush
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.FileOutputStream:close
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:extractResources
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:getResourcesStartingWithAsBytes
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.String:startsWith
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.File
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.File:exists
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.File:isDirectory
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.File:length
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.FileInputStream
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.FileInputStream:read
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.FileInputStream:close
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.Throwable:__curr_excep_obj
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:com.dmdirc.logger.Logger:userError
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.File:listFiles
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.Arrays:asList
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.List:iterator
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.File:isFile
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:getFileListing
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.List:addAll
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.HashMap
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.File:getPath
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.Map:put
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.Map:entrySet
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.Set:iterator
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.Map$Entry:getKey
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:extractResource
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:getResourceBytes
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.String:indexOf
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.String:lastIndexOf
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.StringBuilder:toString
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.File:mkdirs
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.zip.ZipFile:getEntry
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.zip.ZipEntry:isDirectory
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.zip.ZipEntry:getSize
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.util.zip.ZipFile:getInputStream
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.BufferedInputStream
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.BufferedInputStream:read
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.io.BufferedInputStream:close
    //#test_vector(bool doInstall(String)): java.io.File:exists(...)@107: {0}, {1}
    //#test_vector(bool doInstall(String)): java.lang.String:equalsIgnoreCase(...)@104: {1}, {0}
    //#test_vector(bool doInstall(String)): java.lang.String:equalsIgnoreCase(...)@104: {0}, {1}
        if (platform.equalsIgnoreCase("Linux") || platform.equalsIgnoreCase("unix")) {
            final File targetFile = new File(tmpFile.getParent() + File.separator + ".launcher.sh");

            if (targetFile.exists()) {
                targetFile.delete();
            }

            tmpFile.renameTo(targetFile);
            targetFile.setExecutable(true);
            return true;
        } else {
            final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
            ziprm.extractResources("", tmpFile.getParent()+ File.separator);
            new File(path).delete();
            return true;
    //#LauncherComponent.java:118: end of method: bool com.dmdirc.updater.components.LauncherComponent.doInstall(String)
        }
    }

}
    //#LauncherComponent.java:: end of class: com.dmdirc.updater.components.LauncherComponent
