📄 pluginupdateplugin.java
字号:
int pos = common_prefix.lastIndexOf("/");
if (pos == -1)
common_prefix = "";
else
common_prefix = common_prefix.substring(0, pos + 1);
zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(target_jar_zip)));
_L2:
ZipEntry entry;
String name;
OutputStream entry_os;
File origin;
File initial_target;
File final_target;
boolean is_plugin_properties;
entry = zis.getNextEntry();
if (entry == null)
break; /* Loop/switch isn't completed */
name = entry.getName();
entry_os = null;
origin = null;
initial_target = null;
final_target = null;
is_plugin_properties = false;
if (name.length() >= common_prefix.length() && !name.equals("azureus.sig") && !name.endsWith("/"))
{
boolean skip_file = false;
String file_name = entry.getName().substring(common_prefix.length());
if (selected_platform != null && file_name.indexOf("platform/") != -1)
{
String bit_to_remove = (new StringBuilder()).append("platform/").append(selected_platform).toString();
int pp = file_name.indexOf(bit_to_remove);
if (pp != -1)
file_name = (new StringBuilder()).append(file_name.substring(0, pp)).append(file_name.substring(pp + bit_to_remove.length() + 1)).toString();
else
skip_file = true;
}
File install_root;
File origin_root;
if (file_name.startsWith("shared/lib"))
{
update.setRestartRequired(2);
unloadable = false;
if (plugin.getPluginState().isShared())
{
origin_root = prog_dir;
install_root = target_prog_dir;
} else
{
origin_root = user_dir;
install_root = target_user_dir;
}
} else
{
origin_root = plugin_dir;
install_root = target_plugin_dir;
}
origin = new File(origin_root, file_name);
initial_target = new File(install_root, file_name);
final_target = initial_target;
if (origin.exists())
if (file_name.indexOf('/') == -1 && (file_name.toLowerCase().endsWith(".properties") || file_name.toLowerCase().endsWith(".config")))
{
is_plugin_properties = file_name.toLowerCase().equals("plugin.properties");
String old_file_name = file_name;
file_name = (new StringBuilder()).append(file_name).append("_").append(target_version).toString();
final_target = new File(install_root, file_name);
log.log(1, (new StringBuilder()).append("saving new file '").append(old_file_name).append("'as '").append(file_name).append("'").toString());
} else
if (isVersioned(file_name))
{
log.log(1, (new StringBuilder()).append("Version '").append(file_name).append("' already present, skipping").toString());
skip_file = true;
} else
{
log.log(1, (new StringBuilder()).append("overwriting '").append(file_name).append("'").toString());
File backup = new File(origin.getParentFile(), (new StringBuilder()).append(origin.getName()).append(".bak").toString());
if (force_indirect_install)
{
if (backup.exists())
installer.addRemoveAction(backup.getAbsolutePath());
installer.addMoveAction(origin.getAbsolutePath(), backup.getAbsolutePath());
} else
{
if (backup.exists())
backup.delete();
if (!initial_target.renameTo(backup))
{
log.log(1, (new StringBuilder()).append(" failed to backup '").append(file_name).append("', deferring until restart").toString());
if (installer == null)
{
update.setRestartRequired(2);
installer = update.getCheckInstance().createInstaller();
}
File tmp = new File(initial_target.getParentFile(), (new StringBuilder()).append(initial_target.getName()).append(".tmp").toString());
tmp.delete();
installer.addMoveAction(tmp.getAbsolutePath(), initial_target.getAbsolutePath());
final_target = tmp;
}
}
}
if (!skip_file)
{
FileUtil.mkdirs(final_target.getParentFile());
entry_os = new FileOutputStream(final_target);
}
}
byte buffer[] = new byte[0x10000];
do
{
int len = zis.read(buffer);
if (len <= 0)
break;
if (entry_os != null)
entry_os.write(buffer, 0, len);
} while (true);
if (entry_os != null)
entry_os.close();
break MISSING_BLOCK_LABEL_2060;
Exception exception1;
exception1;
if (entry_os != null)
entry_os.close();
throw exception1;
List props_to_delete;
Map props_to_replace;
Map props_to_insert;
File tmp_file;
LineNumberReader lnr;
PrintWriter tmp;
if (!is_plugin_properties)
break MISSING_BLOCK_LABEL_3103;
Properties old_props = new Properties();
Properties new_props = new Properties();
props_to_delete = new ArrayList();
props_to_replace = new HashMap();
props_to_insert = new HashMap();
try
{
FileInputStream fis = new FileInputStream(origin);
old_props.load(fis);
try
{
fis.close();
}
catch (Throwable e) { }
fis = new FileInputStream(final_target);
new_props.load(fis);
try
{
fis.close();
}
catch (Throwable e) { }
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
new_props.put("plugin.version", target_version);
String prop_names[] = {
"plugin.name", "plugin.names", "plugin.class", "plugin.classes", "plugin.version", "plugin.langfile"
};
for (int z = 0; z < prop_names.length; z++)
{
String prop_name = prop_names[z];
String old_name = old_props.getProperty(prop_name);
String new_name = new_props.getProperty(prop_name);
if (new_name == null)
continue;
if (prop_name.equals("plugin.name"))
props_to_delete.add("plugin.names");
else
if (prop_name.equals("plugin.names"))
props_to_delete.add("plugin.name");
else
if (prop_name.equals("plugin.class"))
props_to_delete.add("plugin.classes");
else
if (prop_name.equals("plugin.classes"))
props_to_delete.add("plugin.class");
if (old_name == null)
{
props_to_insert.put(prop_name, new_name);
continue;
}
if (!new_name.equals(old_name))
props_to_replace.put(prop_name, new_name);
}
if (force_indirect_install)
tmp_file = initial_target;
else
tmp_file = new File(initial_target.getParentFile(), (new StringBuilder()).append(initial_target.getName()).append(".tmp").toString());
lnr = null;
tmp = null;
lnr = new LineNumberReader(new FileReader(origin));
tmp = new PrintWriter(new FileWriter(tmp_file));
String pn;
String pv;
for (Iterator it = props_to_insert.keySet().iterator(); it.hasNext(); tmp.println((new StringBuilder()).append(pn).append("=").append(pv).toString()))
{
pn = (String)it.next();
pv = (String)props_to_insert.get(pn);
log.log((new StringBuilder()).append(" Inserting property:").append(pn).append("=").append(pv).toString());
}
do
{
String line = lnr.readLine();
if (line == null)
break;
int ep = line.indexOf('=');
if (ep != -1)
{
String pn = line.substring(0, ep).trim();
if (props_to_delete.contains(pn))
{
log.log((new StringBuilder()).append(" Deleting property:").append(pn).toString());
} else
{
String rv = (String)props_to_replace.get(pn);
if (rv != null)
{
log.log((new StringBuilder()).append(" Replacing property:").append(pn).append(" with ").append(rv).toString());
tmp.println((new StringBuilder()).append(pn).append("=").append(rv).toString());
} else
{
tmp.println(line);
}
}
} else
{
tmp.println(line);
}
} while (true);
lnr.close();
if (tmp != null)
tmp.close();
break MISSING_BLOCK_LABEL_2865;
Exception exception2;
exception2;
lnr.close();
if (tmp != null)
tmp.close();
throw exception2;
File bak_file = new File(origin.getParentFile(), (new StringBuilder()).append(origin.getName()).append(".bak").toString());
if (force_indirect_install)
{
if (bak_file.exists())
installer.addRemoveAction(bak_file.getAbsolutePath());
installer.addMoveAction(origin.getAbsolutePath(), bak_file.getAbsolutePath());
} else
{
if (bak_file.exists())
bak_file.delete();
if (!initial_target.renameTo(bak_file))
throw new IOException((new StringBuilder()).append("Failed to rename '").append(initial_target.toString()).append("' to '").append(bak_file.toString()).append("'").toString());
if (!tmp_file.renameTo(initial_target))
{
bak_file.renameTo(initial_target);
throw new IOException((new StringBuilder()).append("Failed to rename '").append(tmp_file.toString()).append("' to '").append(initial_target.toString()).append("'").toString());
}
bak_file.delete();
}
continue; /* Loop/switch isn't completed */
LineNumberReader lnr;
if (final_target == null || !final_target.getName().equalsIgnoreCase("update.txt"))
continue; /* Loop/switch isn't completed */
update_txt_found = true;
lnr = null;
lnr = new LineNumberReader(new FileReader(final_target));
do
{
String line = lnr.readLine();
if (line == null)
break;
log.log(1, line);
} while (true);
if (lnr != null)
lnr.close();
continue; /* Loop/switch isn't completed */
Throwable e;
e;
Debug.printStackTrace(e);
if (lnr != null)
lnr.close();
if (true) goto _L2; else goto _L1
Exception exception3;
exception3;
if (lnr != null)
lnr.close();
throw exception3;
_L1:
zis.close();
break MISSING_BLOCK_LABEL_3245;
Exception exception4;
exception4;
zis.close();
throw exception4;
if (unloadable)
{
String plugin_id = plugin.getPluginID();
PluginInterface plugins[] = plugin.getPluginManager().getPlugins();
boolean plugin_unloadable = true;
for (int j = 0; j < plugins.length; j++)
{
PluginInterface pi = plugins[j];
if (pi.getPluginID().equals(plugin_id))
plugin_unloadable &= pi.getPluginState().isUnloadable();
}
if (!plugin_unloadable)
{
log.log((new StringBuilder()).append("Switching unloadability for ").append(plugin_id).append(" as changed during update").toString());
update.setRestartRequired(2);
unloadable = false;
}
}
if (force_indirect_install)
{
addInstallationActions(installer, target_plugin_dir, plugin_dir);
addInstallationActions(installer, target_prog_dir, prog_dir);
addInstallationActions(installer, target_user_dir, user_dir);
} else
if (unloadable)
{
log.log("Plugin initialising, please wait... ");
plugin.getPluginState().reload();
log.log("... initialisation complete.");
}
Boolean b_disable = (Boolean)update.getCheckInstance().getProperty(3);
if (update_txt_found || b_disable == null || !b_disable.booleanValue())
{
String msg = (new StringBuilder()).append("Version ").append(version).append(" of plugin '").append(update.getName()).append("' ").append("installed successfully").toString();
if (update_txt_found)
msg = (new StringBuilder()).append(msg).append(" - See update log for details").toString();
log.logAlertRepeatable(update_txt_found ? 2 : 1, msg);
}
update.complete();
break MISSING_BLOCK_LABEL_3690;
Throwable e;
e;
String msg = (new StringBuilder()).append("Version ").append(version).append(" of plugin '").append(update.getName()).append("' ").append("failed to install - ").append(e.getMessage()).toString();
log.logAlertRepeatable(3, msg);
update.complete();
break MISSING_BLOCK_LABEL_3690;
Exception exception5;
exception5;
update.complete();
throw exception5;
}
protected void addInstallationActions(UpdateInstaller installer, File from_file, File to_file)
throws UpdateException
{
if (from_file.isDirectory())
{
File files[] = from_file.listFiles();
if (files != null)
{
for (int i = 0; i < files.length; i++)
addInstallationActions(installer, files[i], new File(to_file, files[i].getName()));
}
} else
{
installer.addMoveAction(from_file.getAbsolutePath(), to_file.getAbsolutePath());
}
}
protected boolean isVersioned(String name)
{
int pos = name.lastIndexOf('_');
if (pos == -1 || name.endsWith("_"))
return false;
String rem = name.substring(pos + 1);
pos = rem.lastIndexOf('.');
if (pos != -1)
rem = rem.substring(0, pos);
for (int i = 0; i < rem.length(); i++)
{
char c = rem.charAt(i);
if (c != '.' && !Character.isDigit(c))
return false;
}
return true;
}
protected void logMultiLine(String indent, List lines)
{
for (int i = 0; i < lines.size(); i++)
log.log(1, (new StringBuilder()).append(indent).append((String)lines.get(i)).toString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -