show additional plugins in plugins dialog (closes #327)
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
@ -7,6 +9,8 @@ import java.util.Scanner;
|
||||
import android.app.Activity;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class IITC_Settings extends Activity {
|
||||
@ -46,24 +50,36 @@ public class IITC_Settings extends Activity {
|
||||
}
|
||||
if (s != null)
|
||||
src = s.hasNext() ? s.next() : "";
|
||||
String header = src.substring(src.indexOf("==UserScript=="),
|
||||
src.indexOf("==/UserScript=="));
|
||||
// remove new line comments and replace with space
|
||||
// this way we get double spaces instead of newline + double slash
|
||||
header = header.replace("\n//", " ");
|
||||
// get a list of key-value...split on multiple spaces
|
||||
String[] attributes = header.split(" +");
|
||||
String plugin_name = "not found";
|
||||
for (int j = 0; j < attributes.length; j++) {
|
||||
// search for name and use the value
|
||||
if (attributes[j].equals("@name"))
|
||||
plugin_name = attributes[j + 1];
|
||||
}
|
||||
String plugin_name = getPluginName(src);
|
||||
asset_list.add(plugin_name);
|
||||
// real value
|
||||
asset_values.add(asset_array[i]);
|
||||
}
|
||||
|
||||
// load additional plugins from <storage-path>/IITC_Mobile/plugins/
|
||||
String iitc_path = Environment.getExternalStorageDirectory().getPath()
|
||||
+ "/IITC_Mobile/";
|
||||
File directory = new File(iitc_path + "plugins/");
|
||||
File[] files = directory.listFiles();
|
||||
if (files != null) {
|
||||
Scanner s = null;
|
||||
String src = "";
|
||||
for (int i = 0; i < files.length; ++i) {
|
||||
try {
|
||||
s = new Scanner(files[i]).useDelimiter("\\A");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.d("iitcm", "failed to parse file " + files[i]);
|
||||
}
|
||||
if (s != null)
|
||||
src = s.hasNext() ? s.next() : "";
|
||||
String plugin_name = getPluginName(src);
|
||||
asset_list.add("[User] " + plugin_name);
|
||||
// real value
|
||||
asset_values.add(files[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
bundle.putStringArray("ASSETS",
|
||||
(String[]) asset_list.toArray(new String[0]));
|
||||
@ -76,6 +92,24 @@ public class IITC_Settings extends Activity {
|
||||
.replace(android.R.id.content, settings).commit();
|
||||
}
|
||||
|
||||
// parse header for @name of plugin
|
||||
public String getPluginName(String src) {
|
||||
String header = src.substring(src.indexOf("==UserScript=="),
|
||||
src.indexOf("==/UserScript=="));
|
||||
// remove new line comments and replace with space
|
||||
// this way we get double spaces instead of newline + double slash
|
||||
header = header.replace("\n//", " ");
|
||||
// get a list of key-value...split on multiple spaces
|
||||
String[] attributes = header.split(" +");
|
||||
String plugin_name = "not found";
|
||||
for (int j = 0; j < attributes.length; j++) {
|
||||
// search for name and use the value
|
||||
if (attributes[j].equals("@name"))
|
||||
plugin_name = attributes[j + 1];
|
||||
}
|
||||
return plugin_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
Reference in New Issue
Block a user