📄 plisteditor.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: PListEditor.java
package org.gudy.azureus2.platform.macosx;
import java.io.*;
import org.gudy.azureus2.core3.util.FileUtil;
public class PListEditor
{
private String plistFile;
public PListEditor(String plistFile)
throws IOException
{
this.plistFile = plistFile;
File file = new File(plistFile);
if (!file.exists())
throw new IOException((new StringBuilder()).append("plist file '").append(file).append("' doesn't exist").toString());
if (!file.canWrite())
throw new IOException((new StringBuilder()).append("plist file '").append(file).append("' is read only").toString());
else
return;
}
public void setFileTypeExtensions(String extensions[])
throws IOException
{
StringBuffer value = new StringBuffer();
StringBuffer find = new StringBuffer();
find.append("(?s).*?<key>CFBundleDocumentTypes</key>\\s*<array>.*?<key>CFBundleTypeExtensions</key>\\s*<array>");
for (int i = 0; i < extensions.length; i++)
{
value.append("\n\t\t\t\t<string>");
value.append(extensions[i]);
value.append("</string>");
find.append(".*?");
find.append(extensions[i]);
}
value.append("\n\t\t\t");
find.append(".*?</array>.*");
String match = "(?s)(<key>CFBundleDocumentTypes</key>\\s*<array>.*?<key>CFBundleTypeExtensions</key>\\s*<array>)(.*?)(</array>)";
setValue(find.toString(), match, value.toString());
}
public void setSimpleStringValue(String key, String value)
throws IOException
{
String find = (new StringBuilder()).append("(?s).*?<key>").append(key).append("</key>\\s*").append("<string>").append(value).append("</string>.*").toString();
String match = (new StringBuilder()).append("(?s)(<key>").append(key).append("</key>\\s*").append("<string>)(.*?)(</string>)").toString();
setValue(find, match, value);
}
public void setArrayValues(String key, String valueType, String values[])
throws IOException
{
StringBuffer value = new StringBuffer();
StringBuffer find = new StringBuffer();
find.append((new StringBuilder()).append("(?s).*?<key>").append(key).append("</key>\\s*").append("<array>").toString());
for (int i = 0; i < values.length; i++)
{
find.append((new StringBuilder()).append("\\s*<").append(valueType).append(">").append(values[i]).append("</").append(valueType).append(">").toString());
value.append((new StringBuilder()).append("\n\t\t\t\t<").append(valueType).append(">").toString());
value.append(values[i]);
value.append((new StringBuilder()).append("</").append(valueType).append(">").toString());
}
find.append("\\s*</array>.*");
value.append("\n\t\t\t");
String match = (new StringBuilder()).append("(?s)(<key>").append(key).append("</key>\\s*<array>)(.*?)(</array>)").toString();
setValue(find.toString(), match, value.toString());
}
private boolean isValuePresent(String match)
throws IOException
{
String fileContent = getFileContent();
return fileContent.matches(match);
}
private void setValue(String find, String match, String value)
throws IOException
{
String fileContent = getFileContent();
if (!isValuePresent(find))
{
fileContent = fileContent.replaceFirst(match, (new StringBuilder()).append("$1").append(value).append("$3").toString());
setFileContent(fileContent);
touchFile();
}
}
private String getFileContent()
throws IOException
{
FileReader fr = null;
String s;
fr = new FileReader(plistFile);
int length = 32768;
char buffer[] = new char[length];
int offset = 0;
for (int len = 0; (len = fr.read(buffer, offset, length - offset)) > 0;)
offset += len;
String result = new String(buffer, 0, offset);
s = result;
if (fr != null)
fr.close();
return s;
Exception exception;
exception;
if (fr != null)
fr.close();
throw exception;
}
private void setFileContent(String fileContent)
throws IOException
{
File file;
File backup_file;
boolean ok;
file = new File(plistFile);
backup_file = new File((new StringBuilder()).append(plistFile).append(".bak").toString());
if (file.exists() && !FileUtil.copyFile(file, backup_file))
throw new IOException("Failed to backup plist file prior to modification");
ok = false;
FileWriter fw = null;
fw = new FileWriter(plistFile);
fw.write(fileContent);
if (fw != null)
{
fw.close();
ok = true;
}
break MISSING_BLOCK_LABEL_126;
Exception exception;
exception;
if (fw != null)
{
fw.close();
ok = true;
}
throw exception;
if (ok)
backup_file.delete();
else
if (backup_file.exists())
{
File bork_file = new File((new StringBuilder()).append(plistFile).append(".bad").toString());
file.renameTo(bork_file);
file.delete();
backup_file.renameTo(file);
}
break MISSING_BLOCK_LABEL_272;
Exception exception1;
exception1;
if (ok)
backup_file.delete();
else
if (backup_file.exists())
{
File bork_file = new File((new StringBuilder()).append(plistFile).append(".bad").toString());
file.renameTo(bork_file);
file.delete();
backup_file.renameTo(file);
}
throw exception1;
}
public void touchFile()
{
File file = new File(plistFile);
for (int i = 0; i <= 2; i++)
{
if (file != null)
{
String command[] = {
"touch", file.getAbsolutePath()
};
try
{
Runtime.getRuntime().exec(command);
}
catch (Exception e)
{
e.printStackTrace();
}
}
file = file.getParentFile();
}
}
public static void main(String args[])
{
try
{
PListEditor editor = new PListEditor("/Applications/Vuze.app/Contents/Info.plist");
editor.setFileTypeExtensions(new String[] {
"torrent", "tor", "vuze", "vuz"
});
editor.setSimpleStringValue("CFBundleName", "Vuze");
editor.setSimpleStringValue("CFBundleTypeName", "Vuze Download");
editor.setSimpleStringValue("CFBundleGetInfoString", "Vuze");
editor.setArrayValues("CFBundleURLSchemes", "string", new String[] {
"magnet", "dht"
});
}
catch (Throwable e)
{
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -