mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Use the Java 7 file API in the IndexedFileSystem.
This commit is contained in:
@@ -7,9 +7,9 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -169,7 +169,7 @@ public final class Server {
|
||||
serviceManager.startAll();
|
||||
|
||||
int releaseNo = context.getRelease().getReleaseNumber();
|
||||
IndexedFileSystem fs = new IndexedFileSystem(new File("data/fs/" + releaseNo), true);
|
||||
IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", Integer.toString(releaseNo)), true);
|
||||
World.getWorld().init(releaseNo, fs, manager);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package org.apollo.fs;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
/**
|
||||
@@ -43,7 +44,7 @@ public final class IndexedFileSystem implements Closeable {
|
||||
* @param readOnly Indicates whether the file system will be read only or not.
|
||||
* @throws FileNotFoundException If the data files could not be found.
|
||||
*/
|
||||
public IndexedFileSystem(File base, boolean readOnly) throws FileNotFoundException {
|
||||
public IndexedFileSystem(Path base, boolean readOnly) throws FileNotFoundException {
|
||||
this.readOnly = readOnly;
|
||||
detectLayout(base);
|
||||
}
|
||||
@@ -71,25 +72,22 @@ public final class IndexedFileSystem implements Closeable {
|
||||
* @param base The base directory.
|
||||
* @throws FileNotFoundException If the data files could not be found.
|
||||
*/
|
||||
private void detectLayout(File base) throws FileNotFoundException {
|
||||
private void detectLayout(Path base) throws FileNotFoundException {
|
||||
int indexCount = 0;
|
||||
for (int index = 0; index < indices.length; index++) {
|
||||
File f = new File(base.getAbsolutePath() + "/main_file_cache.idx" + index);
|
||||
if (f.exists() && !f.isDirectory()) {
|
||||
Path idx = base.resolve("main_file_cache.idx" + index);
|
||||
if (Files.exists(idx) && !Files.isDirectory(idx)) {
|
||||
indexCount++;
|
||||
indices[index] = new RandomAccessFile(f, readOnly ? "r" : "rw");
|
||||
indices[index] = new RandomAccessFile(idx.toFile(), readOnly ? "r" : "rw");
|
||||
}
|
||||
}
|
||||
if (indexCount <= 0) {
|
||||
throw new FileNotFoundException("No index file(s) present.");
|
||||
}
|
||||
|
||||
File oldEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat");
|
||||
File newEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat2");
|
||||
if (oldEngineData.exists() && !oldEngineData.isDirectory()) {
|
||||
data = new RandomAccessFile(oldEngineData, readOnly ? "r" : "rw");
|
||||
} else if (newEngineData.exists() && !oldEngineData.isDirectory()) {
|
||||
data = new RandomAccessFile(newEngineData, readOnly ? "r" : "rw");
|
||||
Path resources = base.resolve("main_file_cache.dat");
|
||||
if (Files.exists(resources) && !Files.isDirectory(resources)) {
|
||||
data = new RandomAccessFile(resources.toFile(), readOnly ? "r" : "rw");
|
||||
} else {
|
||||
throw new FileNotFoundException("No data file present.");
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.apollo.tools;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.apollo.fs.IndexedFileSystem;
|
||||
import org.apollo.fs.decoder.ItemDefinitionDecoder;
|
||||
@@ -1172,7 +1172,7 @@ public final class EquipmentUpdater {
|
||||
|
||||
try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/equipment-"
|
||||
+ release + ".dat")));
|
||||
IndexedFileSystem fs = new IndexedFileSystem(new File("data/fs/" + release), true)) {
|
||||
IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", release), true)) {
|
||||
ItemDefinitionDecoder decoder = new ItemDefinitionDecoder(fs);
|
||||
ItemDefinition[] definitions = decoder.decode();
|
||||
ItemDefinition.init(definitions);
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.apollo.tools;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -32,7 +32,7 @@ public final class NoteUpdater {
|
||||
|
||||
try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/note-"
|
||||
+ release + ".dat")));
|
||||
IndexedFileSystem fs = new IndexedFileSystem(new File("data/fs/" + release), true)) {
|
||||
IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", release), true)) {
|
||||
ItemDefinitionDecoder decoder = new ItemDefinitionDecoder(fs);
|
||||
ItemDefinition[] defs = decoder.decode();
|
||||
ItemDefinition.init(defs);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.apollo.update;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -65,7 +66,7 @@ public final class UpdateService extends Service {
|
||||
public void start() {
|
||||
int release = getContext().getRelease().getReleaseNumber();
|
||||
try {
|
||||
File base = new File("./data/fs/" + release + "/");
|
||||
Path base = Paths.get("data/fs/", Integer.toString(release));
|
||||
for (int i = 0; i < THREADS_PER_REQUEST_TYPE; i++) {
|
||||
workers.add(new JagGrabRequestWorker(dispatcher, new IndexedFileSystem(base, true)));
|
||||
workers.add(new OnDemandRequestWorker(dispatcher, new IndexedFileSystem(base, true)));
|
||||
|
||||
Reference in New Issue
Block a user