Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenMW 0.47 #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/java/parser/json/JsonReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class JsonReader {
private static final String PLUGIN_ENABLED_KEY = "enabled";
private static final String FILE_EXTENSION = "extension";
private static final String IS_PLUGIN_ESP_KEY = "isPluginEsp";
private static final String GAME_FILES_KEY = "gameFiles";
private static final String DATA_KEY = "dataPath";
private static final String PLUGINS_KEY = "plugins";

Expand All @@ -31,6 +32,7 @@ public static void saveFile(List<PluginInfo> loadedFile, String path, String dat
JSONObject c = new JSONObject();
c.put(NAME_PLUGIN_KEY, loadedFile.get(i).name);
c.put(NAME_BSA_KEY, loadedFile.get(i).nameBsa);
c.put(GAME_FILES_KEY, loadedFile.get(i).gameFiles);
c.put(FILE_EXTENSION, loadedFile.get(i).pluginExtension);
c.put(IS_PLUGIN_ESP_KEY, loadedFile.get(i).isPluginEsp);
c.put(PLUGIN_ENABLED_KEY, loadedFile.get(i).enabled);
Expand Down Expand Up @@ -83,6 +85,7 @@ public static List<PluginInfo> loadFile(String jsonFilePath) {
PluginInfo ti = new PluginInfo();
ti.name = obj.getString(NAME_PLUGIN_KEY);
ti.nameBsa = obj.getString(NAME_BSA_KEY);
ti.gameFiles = obj.getString(GAME_FILES_KEY);
ti.enabled = obj.getBoolean(PLUGIN_ENABLED_KEY);
ti.pluginExtension = obj.getString(FILE_EXTENSION);
ti.isPluginEsp = obj.getBoolean(IS_PLUGIN_ESP_KEY);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/plugins/PluginInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class PluginInfo {
public String name = "";
public String pluginExtension="";
public String nameBsa = "";
public String gameFiles = "";
public boolean isPluginEsp = false;
public boolean enabled = false;
public PluginInfo(){
Expand Down
34 changes: 11 additions & 23 deletions app/src/main/java/plugins/PluginReader.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
package plugins;

import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.nio.MappedByteBuffer;
import java.io.RandomAccessFile;
import java.io.IOException;

import java.nio.channels.FileChannel;

public class PluginReader {

public static String read(String path) throws IOException {

FileInputStream file = new FileInputStream(path);

BufferedInputStream bis = new BufferedInputStream(file);

byte[] buffer = new byte[8192];

bis.read(buffer, 0, buffer.length);

String line = new String(buffer);
public static String read(String path) throws IOException {
RandomAccessFile random = new RandomAccessFile(path, "r");
byte[] buff = new byte[4096];
random.read(buff);

String line = new String(buff);
StringBuilder builder = new StringBuilder();

if (!line.contains("TES3")) // make sure this actually is a real TES3 data file
return "";

int count = line.split("MAST").length;
if (count > 0)
for (int i = 0; i < count; i++) {
Expand Down Expand Up @@ -53,15 +44,12 @@ else if (data[i].contains(".omwaddon")) {
}

} catch (Exception e) {

}
}

if (path.contains("Bloodmoon.esm")) {
builder.append("Tribunal.esm \n");
}

bis.close();
file.close();
random.close();

return builder.toString();
}
}
37 changes: 17 additions & 20 deletions app/src/main/java/plugins/PluginsStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private void addNewFiles() throws JSONException, IOException {
PluginInfo pluginData = new PluginInfo();
pluginData.name = f.getName();
pluginData.nameBsa = f.getName().split("\\.")[0] + ".bsa";
pluginData.gameFiles = PluginReader.read(dataPath + "/" + pluginData.name);
pluginData.isPluginEsp = f.getName().endsWith(".ESP") || f.getName().endsWith(".esp");
pluginData.pluginExtension = FileUtils.getFileName(f.getName(), true);
pluginsList.add(pluginData);
Expand Down Expand Up @@ -114,33 +115,29 @@ public int compare(PluginInfo f1, PluginInfo f2)

//Dependency sort
//iterate until no sorting of files occurs
try {
while (movedFiles)
while (movedFiles)
{
movedFiles = false;
//iterate each file, obtaining a reference to it's gamefiles list
for (int i = 0; i < fileCount; i++)
{
movedFiles = false;
//iterate each file, obtaining a reference to it's gamefiles list
for (int i = 0; i < fileCount; i++)
String gamefiles = pluginsList.get(i).gameFiles;
//iterate each file after the current file, verifying that none of it's
//dependencies appear.
for (int j = i + 1; j < fileCount; j++)
{
String gamefiles = PluginReader.read(PreferenceManager.getDefaultSharedPreferences(activity).getString("data_files", "") + "/" + pluginsList.get(i).name);
//iterate each file after the current file, verifying that none of it's
//dependencies appear.
for (int j = i + 1; j < fileCount; j++)
if (gamefiles.contains(pluginsList.get(j).name)
|| (gamefiles.isEmpty()
&& pluginsList.get(j).name.contains("Morrowind.esm"))) // Hack: implicit dependency on Morrowind.esm for dependency-less files
{
if (gamefiles.contains(pluginsList.get(j).name)
|| (gamefiles.isEmpty()
&& pluginsList.get(j).name.contains("Morrowind.esm"))) // Hack: implicit dependency on Morrowind.esm for dependency-less files
{
move(pluginsList, j, i);
move(pluginsList, j, i);

movedFiles = true;
}
movedFiles = true;
}
if (movedFiles)
break;
}
if (movedFiles)
break;
}
} catch (IOException e) {
e.printStackTrace();
}
Collections.sort(pluginsList, (p1, p2) -> Boolean.compare(p1.isPluginEsp, p2.isPluginEsp));
}
Expand Down