Search in sources :

Example 16 with VuzeFile

use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.

the class DeviceManagerImpl method exportVuzeFile.

protected VuzeFile exportVuzeFile(DeviceImpl device) throws IOException {
    VuzeFile vf = VuzeFileHandler.getSingleton().create();
    Map map = new HashMap();
    Map device_map = new HashMap();
    map.put("device", device_map);
    device.exportToBEncodedMap(device_map, true);
    vf.addComponent(VuzeFileComponent.COMP_TYPE_DEVICE, map);
    return (vf);
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile)

Example 17 with VuzeFile

use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.

the class CustomizationManagerImpl method main.

public static void main(String[] args) {
    try {
        VuzeFile vf = VuzeFileHandler.getSingleton().create();
        Map config = new HashMap();
        List list = new ArrayList();
        list.add("trout");
        list.add(45);
        config.put("test.a10", "Hello mum");
        config.put("test.a11", new Long(100));
        config.put("test.a13", list);
        Map map = new HashMap();
        map.put("name", "My Proxy Settings");
        map.put("settings", config);
        map.put("restart", new Long(1));
        vf.addComponent(VuzeFileComponent.COMP_TYPE_CONFIG_SETTINGS, map);
        vf.write(new File("C:\\temp\\p_config.vuze"));
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) VuzeFile(com.biglybt.core.vuzefile.VuzeFile)

Example 18 with VuzeFile

use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.

the class CustomizationManagerImpl method initialize.

@Override
public void initialize() {
    synchronized (this) {
        if (initialised) {
            return;
        }
        initialised = true;
    }
    VuzeFileHandler.getSingleton().addProcessor(new VuzeFileProcessor() {

        @Override
        public void process(VuzeFile[] files, int expected_types) {
            for (int i = 0; i < files.length; i++) {
                VuzeFile vf = files[i];
                VuzeFileComponent[] comps = vf.getComponents();
                for (int j = 0; j < comps.length; j++) {
                    VuzeFileComponent comp = comps[j];
                    if (comp.getType() == VuzeFileComponent.COMP_TYPE_CUSTOMIZATION) {
                        try {
                            Map map = comp.getContent();
                            ((CustomizationManagerImpl) getSingleton()).importCustomization(map);
                            comp.setProcessed();
                        } catch (Throwable e) {
                            Debug.printStackTrace(e);
                        }
                    } else if (comp.getType() == VuzeFileComponent.COMP_TYPE_CONFIG_SETTINGS) {
                        try {
                            Map map = comp.getContent();
                            String name = new String((byte[]) map.get("name"));
                            UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
                            String details = MessageText.getString("custom.settings.import", new String[] { name });
                            long res = ui_manager.showMessageBox("custom.settings.import.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                            if (res == UIManagerEvent.MT_YES) {
                                Map<String, Object> config = (Map<String, Object>) map.get("settings");
                                int num_set = 0;
                                for (Map.Entry<String, Object> entry : config.entrySet()) {
                                    String key = entry.getKey();
                                    Object value = entry.getValue();
                                    if (value instanceof Long) {
                                        COConfigurationManager.setParameter(key, (Long) value);
                                    } else if (value instanceof byte[]) {
                                        COConfigurationManager.setParameter(key, (byte[]) value);
                                    } else if (value instanceof List) {
                                        COConfigurationManager.setParameter(key, (List) value);
                                    } else if (value instanceof Map) {
                                        COConfigurationManager.setParameter(key, (Map) value);
                                    } else {
                                        Debug.out("Unsupported entry: " + key + "=" + value);
                                    }
                                    num_set++;
                                }
                                Long l_restart = (Long) map.get("restart");
                                boolean restart = l_restart != null && l_restart != 0;
                                String restart_text = "";
                                if (restart) {
                                    restart_text = "\r\n\r\n" + MessageText.getString("ConfigView.section.security.restart.title");
                                }
                                String res_details = MessageText.getString("custom.settings.import.res", new String[] { String.valueOf(num_set), restart_text });
                                ui_manager.showMessageBox("custom.settings.import.res.title", "!" + res_details + "!", UIManagerEvent.MT_OK);
                            }
                            comp.setProcessed();
                        } catch (Throwable e) {
                            Debug.printStackTrace(e);
                        }
                    }
                }
            }
        }
    });
    File user_dir = FileUtil.getUserFile("custom");
    File app_dir = FileUtil.getApplicationFile("custom");
    loadCustomizations(app_dir);
    if (!user_dir.equals(app_dir)) {
        loadCustomizations(user_dir);
    }
    String active = COConfigurationManager.getStringParameter("customization.active.name", "");
    if (customization_file_map.get(active) == null) {
        // hmm, its been deleted or not set yet. look for new ones
        Iterator it = customization_file_map.keySet().iterator();
        while (it.hasNext()) {
            String name = (String) it.next();
            final String version_key = "customization.name." + name + ".version";
            String existing_version = COConfigurationManager.getStringParameter(version_key, "0");
            if (existing_version.equals("0")) {
                active = name;
                String version = ((String[]) customization_file_map.get(name))[0];
                COConfigurationManager.setParameter("customization.active.name", active);
                COConfigurationManager.setParameter(version_key, version);
                break;
            }
        }
    }
    synchronized (this) {
        current_customization_name = active;
    }
}
Also used : VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent) UIManager(com.biglybt.pif.ui.UIManager) VuzeFileProcessor(com.biglybt.core.vuzefile.VuzeFileProcessor) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) VuzeFile(com.biglybt.core.vuzefile.VuzeFile)

Example 19 with VuzeFile

use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.

the class EngineImpl method getSubscription.

@Override
public Subscription getSubscription() {
    try {
        VuzeFile vf = exportToVuzeFile(true);
        byte[] bytes = vf.exportToBytes();
        String url_str = "vuze://?body=" + new String(bytes, Constants.BYTE_ENCODING);
        boolean is_anon = isAnonymous();
        SubscriptionManager sub_man = SubscriptionManagerFactory.getSingleton();
        Subscription subs = sub_man.createSingletonRSS(vf.getName() + ": " + getName() + " (v" + getVersion() + ")", new URL(url_str), Integer.MAX_VALUE, is_anon);
        return (subs);
    } catch (Throwable e) {
        Debug.out(e);
    }
    return (null);
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile) SubscriptionManager(com.biglybt.core.subs.SubscriptionManager) Subscription(com.biglybt.core.subs.Subscription) URL(java.net.URL)

Example 20 with VuzeFile

use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.

the class EngineImpl method exportToVuzeFile.

public VuzeFile exportToVuzeFile(boolean generic) throws IOException {
    VuzeFile vf = VuzeFileHandler.getSingleton().create();
    vf.addComponent(VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE, exportToBencodedMap(generic));
    return (vf);
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile)

Aggregations

VuzeFile (com.biglybt.core.vuzefile.VuzeFile)36 File (java.io.File)12 VuzeFileHandler (com.biglybt.core.vuzefile.VuzeFileHandler)10 VuzeFileComponent (com.biglybt.core.vuzefile.VuzeFileComponent)9 URL (java.net.URL)9 RSSEngine (com.biglybt.core.metasearch.impl.web.rss.RSSEngine)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)5 IOException (java.io.IOException)5 PluginEngine (com.biglybt.core.metasearch.impl.plugin.PluginEngine)4 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Map (java.util.Map)4 Subscription (com.biglybt.core.subs.Subscription)3 VuzeFileProcessor (com.biglybt.core.vuzefile.VuzeFileProcessor)3 UIManager (com.biglybt.pif.ui.UIManager)3 Engine (com.biglybt.core.metasearch.Engine)2 SubscriptionException (com.biglybt.core.subs.SubscriptionException)2 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)2 ResourceDownloaderFactory (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory)2 InputStream (java.io.InputStream)2