AutoUpdate.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
omschaub.stuffer.main |
![]() |
![]() |
AZCVSUpdater |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* Created on Nov 3, 2005
* Created by omschaub
*
*/
package omschaub.stuffer.main;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import org.gudy.azureus2.plugins.update.UpdateInstaller;
import org.gudy.azureus2.plugins.update.UpdateManager;
public class AutoUpdate {
private static String getCurrentVersion(){
return Plugin.getPluginInterface().getPluginVersion();
}
private static String getWebVersion(){
String sourceDir = Plugin.getPluginInterface().getPluginDirectoryName() + System.getProperty("file.separator");
String sourceFile = "stuffer_web_version.cache";
String latestVersion = "Not Available";
File configFile = new File(sourceDir + sourceFile);
if (!configFile.isFile()) {
downloadWebVersionFile();
latestVersion = "Not Available";
return latestVersion;
}
BufferedReader input = null;
try {
input = new BufferedReader ( new FileReader(configFile));
String line = null;
while (( line = input.readLine()) != null){
latestVersion=line;
}
}catch (Exception e){
e.printStackTrace();
}
return latestVersion;
}
public static boolean compareStufferVersions(){
return compare(getWebVersion(),getCurrentVersion());
}
public static void downloadWebVersionFile(){
Thread downloadThread = new Thread()
{
public void run()
{
StufferVerGet stufferVerGet = new StufferVerGet();
stufferVerGet.setURL("http://azcvsupdater.sourceforge.net/stuffer/current_version.txt");
stufferVerGet.setDir(Plugin.getPluginInterface().getPluginDirectoryName() + System.getProperty("file.separator"));
stufferVerGet.setFileName("stuffer_web_version.cache");
stufferVerGet.initialize();
stufferVerGet.start();
}
};
downloadThread.setDaemon(true);
downloadThread.start();
}
public static void downloadPluginCache(){
Thread downloadThread = new Thread()
{
public void run()
{
String sourceDir = Plugin.getPluginInterface().getPluginDirectoryName() + System.getProperty("file.separator");
PluginCacheGet plugincache_get = new PluginCacheGet();
plugincache_get.setURL("http://prdownloads.sourceforge.net/azcvsupdater/stuffer_" + getWebVersion() + ".jar?downloads");
plugincache_get.setDir(sourceDir);
plugincache_get.setFileName("plugin.cache");
plugincache_get.initialize();
plugincache_get.start();
}
};
downloadThread.setDaemon(true);
downloadThread.start();
}
public static void downloadPlugin(){
Thread downloadThread = new Thread()
{
public void run()
{
String sourceDir = Plugin.getPluginInterface().getPluginDirectoryName() + System.getProperty("file.separator");
PluginGet pluginGet = new PluginGet();
//pluginGet.setURL("http://unc.dl.sourceforge.net/sourceforge/azcvsupdater/azcvsupdater_" + version_plugin + ".jar");
String mirror = SFMirrorParse.getMirror();
System.out.println("Stuffer Auto Upgrade: Downloading stuffer_" + getWebVersion() + ".jar through SourceForge Mirror: " + mirror);
pluginGet.setURL("http://prdownloads.sourceforge.net/azcvsupdater/stuffer_" + getWebVersion() + ".jar?use_mirror=" + mirror);
pluginGet.setDir(sourceDir);
pluginGet.setFileName("stuffer_" + getWebVersion() + ".jar.new");
pluginGet.initialize("meta");
pluginGet.start();
}
};
downloadThread.setDaemon(true);
downloadThread.start();
}
public static void insertLatest(){
String current_ver = getWebVersion();
String sourceDir = Plugin.getPluginInterface().getPluginDirectoryName() + System.getProperty("file.separator");
String sourceFile = "stuffer_" + current_ver + ".jar.new";
try{
File newVer = new File(sourceDir, sourceFile);
if(!newVer.exists()){
System.out.println("Stuffer Auto Upgrade: New version does not exist.. how did I get here?");
return;
}
String toFile = sourceDir + "stuffer_" + current_ver + ".jar";
UpdateManager um = Plugin.getPluginInterface().getUpdateManager();
UpdateInstaller updateInstaller = um.createInstaller();
updateInstaller.addResource("stuffer_updater" , new FileInputStream (newVer));
updateInstaller.addMoveAction("stuffer_updater" , toFile);
System.out.println("Stuffer Auto Upgrade: Successfully upgraded stuffer to version " + current_ver);
}catch(Exception e){
e.printStackTrace();
}
}
/**
* A small class to compare the version numbers of the Stuffer plugin in the format of x.x
*
* @param string1 -- New version
* @param string2 -- Loaded version
* @return A boolean is returned.. true if string1 is greater than string2
*/
private static boolean compare(final String string1, final String string2){
try{
System.out.println(string1 + " : " + string2);
int beginning1 = string1.indexOf(".");
int beginning2 = string2.indexOf(".");
String temp1 = string1.substring(0,beginning1);
String temp2 = string2.substring(0,beginning2);
System.out.println("First Digit: String1: " + temp1 + " String2: " + temp2);
if(Integer.parseInt(temp1) > Integer.parseInt(temp2)){
return true;
}else if (Integer.parseInt(temp1) == Integer.parseInt(temp2)){
temp1 = string1.substring(beginning1+1,string1.length());
temp2 = string2.substring(beginning2+1,string2.length());
System.out.println("Second Digit: String1: " + temp1 + " String2: " + temp2);
if(Integer.parseInt(temp1) > Integer.parseInt(temp2)){
return true;
}else if (Integer.parseInt(temp1) == Integer.parseInt(temp2)){
return false;
}else return false;
}else return false;
}catch(Exception e){
e.printStackTrace();
}
int beginning1 = string1.indexOf(".");
String beginning1_string = string1.substring(beginning1 + 1,string1.length());
int beginning2 = string2.indexOf(".");
String beginning2_string = string2.substring(beginning2 + 1,string2.length());
String temp1 = string1.substring(0,beginning1);
String temp2 = string2.substring(0,beginning2);
if(Integer.parseInt(temp1) > Integer.parseInt(temp2)){
return true;
}else if (Integer.parseInt(temp1) == Integer.parseInt(temp2)){
int mid1 = beginning1_string.indexOf(".");
String mid1_string = string1.substring(mid1 + 1,string1.length());
mid1_string = mid1_string.substring(mid1_string.indexOf(".")+1,mid1_string.length());
int mid2 = beginning2_string.indexOf(".");
String mid2_string = string2.substring(mid2 + 1,string2.length());
mid2_string = mid2_string.substring(mid2_string.indexOf(".")+1,mid2_string.length());
temp1 = beginning1_string.substring(0,mid1);
temp2 = beginning2_string.substring(0,mid2);
if(Integer.parseInt(temp1) > Integer.parseInt(temp2)){
return true;
}else if (Integer.parseInt(temp1) == Integer.parseInt(temp2)){
if(Integer.parseInt(mid1_string) > Integer.parseInt(mid2_string)){
return true;
}else if (Integer.parseInt(mid1_string) == Integer.parseInt(mid2_string)){
return false;
}else return false;
}else return false;
}else return false;
}
}
The table below shows all metrics for AutoUpdate.java.




