Skip to content

Commit

Permalink
Archives: lil refactor; replace listeners with a message bus
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Mar 9, 2024
1 parent eba1366 commit dcd6cbb
Show file tree
Hide file tree
Showing 25 changed files with 517 additions and 516 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.shade.decima.model.app.impl.HZDPackfileProvider;
import com.shade.decima.model.base.CoreBinary;
import com.shade.decima.model.packfile.Packfile;
import com.shade.decima.model.packfile.PackfileBase;
import com.shade.decima.model.packfile.PackfileManager;
import com.shade.decima.model.packfile.PackfileProvider;
import com.shade.decima.model.packfile.prefetch.PrefetchUpdater;
Expand Down Expand Up @@ -42,8 +41,8 @@ public class Project implements Closeable {
this.container = container;
this.typeRegistry = new RTTITypeRegistry(container);
this.coreFileReader = new CoreBinary.Reader(typeRegistry);
this.packfileManager = new PackfileManager();
this.oodle = Oodle.acquire(container.getCompressorPath());
this.packfileManager = new PackfileManager(oodle);

mountDefaults();
}
Expand All @@ -58,13 +57,13 @@ private void mountDefaults() throws IOException {

Arrays.stream(packfileProvider.getPackfiles(this)).parallel().forEach(info -> {
try {
packfileManager.mount(info, oodle);
packfileManager.mountPackfile(info);
} catch (IOException e) {
log.error("Can't mount packfile '{}'", info.path(), e);
}
});

log.info("Found and mounted {} packfiles in {} ms", packfileManager.getPackfiles().size(), System.currentTimeMillis() - start);
log.info("Found and mounted {} packfiles in {} ms", packfileManager.getArchives().size(), System.currentTimeMillis() - start);
}

@NotNull
Expand Down Expand Up @@ -118,7 +117,7 @@ public Map<Long, long[]> listFileLinks() throws IOException {
final long[][] refs = new long[files.length][];

for (int i = 0; i < files.length; i++) {
hashes[i] = PackfileBase.getPathHash(PackfileBase.getNormalizedPath(files[i].str("Path")));
hashes[i] = Packfile.getPathHash(Packfile.getNormalizedPath(files[i].str("Path")));
}

for (int i = 0, j = 0; i < files.length; i++, j++) {
Expand Down Expand Up @@ -176,8 +175,8 @@ private Stream<String> getPrefetchFiles() throws IOException {
final RTTIObject[] files = list.get("Files");

return Stream.concat(
Arrays.stream(files).map(entry -> PackfileBase.getNormalizedPath(entry.str("Path"))),
Arrays.stream(files).map(entry -> PackfileBase.getNormalizedPath(entry.str("Path")) + ".stream")
Arrays.stream(files).map(entry -> Packfile.getNormalizedPath(entry.str("Path"))),
Arrays.stream(files).map(entry -> Packfile.getNormalizedPath(entry.str("Path")) + ".stream")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.shade.util.Nullable;

import java.io.IOException;
import java.util.Collection;
import java.util.UUID;

public interface ProjectManager {
Expand All @@ -28,6 +29,9 @@ static ProjectManager getInstance() {
@NotNull
ProjectContainer[] getProjects();

@NotNull
Collection<Project> getOpenProjects();

@NotNull
Project openProject(@NotNull ProjectContainer container) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.prefs.Preferences;

@Service(ProjectManager.class)
Expand Down Expand Up @@ -78,6 +76,15 @@ public ProjectContainer[] getProjects() {
.toArray(ProjectContainer[]::new);
}

@NotNull
@Override
public Collection<Project> getOpenProjects() {
return projects.values().stream()
.map(info -> info.project)
.filter(Objects::nonNull)
.toList();
}

@NotNull
@Override
public synchronized Project openProject(@NotNull ProjectContainer container) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.nio.file.Path;

public interface Archive extends Closeable {
@NotNull
ArchiveManager getManager();

@NotNull
String getId();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.shade.decima.model.archive;

import com.shade.util.NotNull;

import java.io.Closeable;
import java.util.Collection;

public interface ArchiveManager extends Closeable {
@NotNull
ArchiveFile getFile(@NotNull String identifier);

@NotNull
Collection<? extends Archive> getArchives();
}
Loading

0 comments on commit dcd6cbb

Please sign in to comment.