//# 0 errors, 103 messages
//#
/*
    //#ClientComponent.java:1:1: class: com.dmdirc.updater.components.ClientComponent
    //#ClientComponent.java:1:1: method: com.dmdirc.updater.components.ClientComponent.com.dmdirc.updater.components.ClientComponent__static_init
 * 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.Main;
import com.dmdirc.config.IdentityManager;
import com.dmdirc.updater.UpdateComponent;
import com.dmdirc.updater.Version;
import com.dmdirc.util.resourcemanager.DMDircResourceManager;

import java.io.File;

/**
 * Represents the client component, which covers the core client resources.
 * 
 * @author chris
 */
public class ClientComponent implements UpdateComponent {
    //#ClientComponent.java:38: method: void com.dmdirc.updater.components.ClientComponent.com.dmdirc.updater.components.ClientComponent()
    //#ClientComponent.java:38: end of method: void com.dmdirc.updater.components.ClientComponent.com.dmdirc.updater.components.ClientComponent()

    /** {@inheritDoc} */
    @Override
    public String getName() {
        return "client";
    //#ClientComponent.java:43: method: String com.dmdirc.updater.components.ClientComponent.getName()
    //#output(String getName()): return_value
    //#post(String getName()): return_value == &"client"
    //#ClientComponent.java:43: end of method: String com.dmdirc.updater.components.ClientComponent.getName()
    }
    
    /** {@inheritDoc} */
    @Override
    public String getFriendlyName() {
        return "DMDirc client";
    //#ClientComponent.java:49: method: String com.dmdirc.updater.components.ClientComponent.getFriendlyName()
    //#output(String getFriendlyName()): return_value
    //#post(String getFriendlyName()): return_value == &"DMDirc client"
    //#ClientComponent.java:49: end of method: String com.dmdirc.updater.components.ClientComponent.getFriendlyName()
    }

    /** {@inheritDoc} */
    @Override
    public Version getVersion() {
        return new Version(getFriendlyVersion());
    //#ClientComponent.java:55: method: Version com.dmdirc.updater.components.ClientComponent.getVersion()
    //#input(Version getVersion()): __Descendant_Table[com/dmdirc/updater/components/ClientComponent]
    //#input(Version getVersion()): __Descendant_Table[others]
    //#input(Version getVersion()): __Dispatch_Table.getFriendlyVersion()Ljava/lang/String;
    //#input(Version getVersion()): this
    //#input(Version getVersion()): this.__Tag
    //#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[2] (Version getVersion()): this.__Tag == com/dmdirc/updater/components/ClientComponent
    //#presumption(Version getVersion()): com.dmdirc.config.ConfigManager:getOption(...)@61 != null
    //#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()): init'ed(return_value.intVersion)
    //#post(Version getVersion()): init'ed(return_value.strVersion)
    //#unanalyzed(Version getVersion()): Effects-of-calling:com.dmdirc.config.IdentityManager:getGlobalConfig
    //#unanalyzed(Version getVersion()): Effects-of-calling:com.dmdirc.config.ConfigManager:getOption
    //#unanalyzed(Version getVersion()): Effects-of-calling:java.lang.String:matches
    //#unanalyzed(Version getVersion()): Effects-of-calling:java.lang.Integer:parseInt
    //#ClientComponent.java:55: end of method: Version com.dmdirc.updater.components.ClientComponent.getVersion()
    }

    /** {@inheritDoc} */
    @Override
    public String getFriendlyVersion() {
        return IdentityManager.getGlobalConfig().getOption("version", "version");
    //#ClientComponent.java:61: method: String com.dmdirc.updater.components.ClientComponent.getFriendlyVersion()
    //#ClientComponent.java:61: Warning: method not available - call not analyzed
    //#    call on ConfigManager com.dmdirc.config.IdentityManager:getGlobalConfig()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.updater.components.ClientComponent
    //#    method: String getFriendlyVersion()
    //#    unanalyzed callee: ConfigManager com.dmdirc.config.IdentityManager:getGlobalConfig()
    //#ClientComponent.java:61: Warning: method not available - call not analyzed
    //#    call on String com.dmdirc.config.ConfigManager:getOption(String, String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.updater.components.ClientComponent
    //#    method: String getFriendlyVersion()
    //#    unanalyzed callee: String com.dmdirc.config.ConfigManager:getOption(String, String)
    //#output(String getFriendlyVersion()): return_value
    //#presumption(String getFriendlyVersion()): com.dmdirc.config.IdentityManager:getGlobalConfig(...)@61 != null
    //#post(String getFriendlyVersion()): init'ed(return_value)
    //#ClientComponent.java:61: end of method: String com.dmdirc.updater.components.ClientComponent.getFriendlyVersion()
    }

    /** {@inheritDoc} */
    @Override
    public boolean doInstall(final String path) {
        final File tmpFile = new File(path);
    //#ClientComponent.java:67: method: bool com.dmdirc.updater.components.ClientComponent.doInstall(String)
    //#input(bool doInstall(String)): "  "._tainted
    //#input(bool doInstall(String)): ""._tainted
    //#input(bool doInstall(String)): "&#10;"._tainted
    //#input(bool doInstall(String)): ".DMDirc.jar"._tainted
    //#input(bool doInstall(String)): "A new version of DMDirc has been downloaded, but as you&#10;do not seem to ... e manually, please replace the&#10;existing DMDirc.jar file, located at:&#10; "._tainted
    //#input(bool doInstall(String)): "A new version of DMDirc has been downloaded, but as you&#10;do not seem to ... update manually, please extract the&#10;new DMDirc.jar file, located at:&#10; "._tainted
    //#input(bool doInstall(String)): "over your existing DMDirc install located in:&#10;"._tainted
    //#input(bool doInstall(String)): "with the following file:&#10;"._tainted
    //#input(bool doInstall(String)): com/dmdirc/ui/interfaces/UIController.__Descendant_Table[com/dmdirc/ui/interfaces/UIController]
    //#input(bool doInstall(String)): com/dmdirc/ui/interfaces/UIController.__Descendant_Table[others]
    //#input(bool doInstall(String)): com/dmdirc/ui/interfaces/UIController.__Dispatch_Table.showMessageDialog(Ljava/lang/String;Ljava/lang/String;)V
    //#input(bool doInstall(String)): com/dmdirc/updater/components/LauncherComponent.version
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/DMDircResourceManager.__Class_Obj.__Lock
    //#input(bool doInstall(String)): com/dmdirc/util/resourcemanager/DMDircResourceManager.com.dmdirc.logger.ErrorLevel.MEDIUM
    //#input(bool doInstall(String)): java.io.File.separator
    //#input(bool doInstall(String)): java.io.File.separator._tainted
    //#input(bool doInstall(String)): path
    //#output(bool doInstall(String)): return_value
    //#pre[1] (bool doInstall(String)): init'ed(com/dmdirc/updater/components/LauncherComponent.version)
    //#presumption(bool doInstall(String)): com.dmdirc.Main:getUI(...).__Tag@98 == com/dmdirc/ui/interfaces/UIController
    //#presumption(bool doInstall(String)): com.dmdirc.Main:getUI(...)@98 != 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.lang.Thread:currentThread
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.Thread:getContextClassLoader
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.ClassLoader:getResource
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.net.URL:getProtocol
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.String:equals
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.net.URL:getPath
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.System:getProperty
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.lang.String:startsWith
    //#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.lang.String:lastIndexOf
    //#unanalyzed(bool doInstall(String)): Effects-of-calling:java.net.URLDecoder:decode
    //#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
    //#test_vector(bool doInstall(String)): com/dmdirc/updater/components/LauncherComponent.version: {-2_147_483_648..-2, 0..4_294_967_295}, {-1}
    //#test_vector(bool doInstall(String)): java.io.File:exists(...)@70: {0}, {1}
    //#test_vector(bool doInstall(String)): java.lang.String:equals(...)@82: {0}, {1}
        final File targetFile = new File(tmpFile.getParent() + File.separator + ".DMDirc.jar");
        
        if (targetFile.exists()) {
            targetFile.delete();
        }
        
        tmpFile.renameTo(targetFile);
        
        if (!LauncherComponent.isUsingLauncher()) {
            final String message;
            if (DMDircResourceManager.isRunningFromJar()) {
                message = "A new version of DMDirc has been downloaded, but as you\n"
                    + "do not seem to be using the DMDirc launcher, it will\n"
                    + "not be installed automatically.\n\n"
                    + "To install this update manually, please replace the\n"
                    + "existing DMDirc.jar file, located at:\n"
                    + " " + DMDircResourceManager.getCurrentWorkingDirectory() + "\n"
                    + "with the following file:\n"
                    + "  " + targetFile.getAbsolutePath();
            } else {
                message = "A new version of DMDirc has been downloaded, but as you\n"
                    + "do not seem to be using the DMDirc launcher, it will\n"
                    + "not be installed automatically.\n\n"
                    + "To install this update manually, please extract the\n"
                    + "new DMDirc.jar file, located at:\n"
                    + " " + targetFile.getAbsolutePath() + "\n"
                    + "over your existing DMDirc install located in:\n"
                    + "  " + DMDircResourceManager.getCurrentWorkingDirectory();
            }
            
            Main.getUI().showMessageDialog("Client update downloaded", message);
    //#ClientComponent.java:98: Warning: method not available - call not analyzed
    //#    call on UIController com.dmdirc.Main:getUI()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.updater.components.ClientComponent
    //#    method: bool doInstall(String)
    //#    unanalyzed callee: UIController com.dmdirc.Main:getUI()
    //#ClientComponent.java:98: Warning: method not available - call not analyzed
    //#    call on void showMessageDialog(String, String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.updater.components.ClientComponent
    //#    method: bool doInstall(String)
    //#    unanalyzed callee: void showMessageDialog(String, String)
        }
        
        return true;
    //#ClientComponent.java:101: end of method: bool com.dmdirc.updater.components.ClientComponent.doInstall(String)
    }

}
    //#output(com.dmdirc.updater.components.ClientComponent__static_init): __Descendant_Table[com/dmdirc/updater/components/ClientComponent]
    //#output(com.dmdirc.updater.components.ClientComponent__static_init): __Dispatch_Table.doInstall(Ljava/lang/String;)Z
    //#output(com.dmdirc.updater.components.ClientComponent__static_init): __Dispatch_Table.getFriendlyName()Ljava/lang/String;
    //#output(com.dmdirc.updater.components.ClientComponent__static_init): __Dispatch_Table.getFriendlyVersion()Ljava/lang/String;
    //#output(com.dmdirc.updater.components.ClientComponent__static_init): __Dispatch_Table.getName()Ljava/lang/String;
    //#output(com.dmdirc.updater.components.ClientComponent__static_init): __Dispatch_Table.getVersion()Lcom/dmdirc/updater/Version;
    //#output(com.dmdirc.updater.components.ClientComponent__static_init): com/dmdirc/updater/UpdateComponent.__Descendant_Table[com/dmdirc/updater/components/ClientComponent]
    //#post(com.dmdirc.updater.components.ClientComponent__static_init): __Descendant_Table[com/dmdirc/updater/components/ClientComponent] == &__Dispatch_Table
    //#post(com.dmdirc.updater.components.ClientComponent__static_init): com/dmdirc/updater/UpdateComponent.__Descendant_Table[com/dmdirc/updater/components/ClientComponent] == &__Dispatch_Table
    //#post(com.dmdirc.updater.components.ClientComponent__static_init): __Dispatch_Table.doInstall(Ljava/lang/String;)Z == &doInstall
    //#post(com.dmdirc.updater.components.ClientComponent__static_init): __Dispatch_Table.getFriendlyName()Ljava/lang/String; == &getFriendlyName
    //#post(com.dmdirc.updater.components.ClientComponent__static_init): __Dispatch_Table.getFriendlyVersion()Ljava/lang/String; == &getFriendlyVersion
    //#post(com.dmdirc.updater.components.ClientComponent__static_init): __Dispatch_Table.getName()Ljava/lang/String; == &getName
    //#post(com.dmdirc.updater.components.ClientComponent__static_init): __Dispatch_Table.getVersion()Lcom/dmdirc/updater/Version; == &getVersion
    //#ClientComponent.java:: end of method: com.dmdirc.updater.components.ClientComponent.com.dmdirc.updater.components.ClientComponent__static_init
    //#ClientComponent.java:: end of class: com.dmdirc.updater.components.ClientComponent
