0

Второй этап замены FS на интерфейс FileSystem

This commit is contained in:
2018-03-06 21:20:25 +03:00
parent 66efdfa4e7
commit ff4b1b049b
3 changed files with 35 additions and 19 deletions

View File

@@ -24,7 +24,8 @@ import lwjake2.game.cvar_t;
import lwjake2.qcommon.Cbuf; import lwjake2.qcommon.Cbuf;
import lwjake2.qcommon.Com; import lwjake2.qcommon.Com;
import lwjake2.qcommon.Cvar; import lwjake2.qcommon.Cvar;
import lwjake2.qcommon.FS; import lwjake2.qcommon.FileSystem;
import lwjake2.qcommon.BaseQ2FileSystem;
import lwjake2.qcommon.netadr_t; import lwjake2.qcommon.netadr_t;
import lwjake2.sound.S; import lwjake2.sound.S;
import lwjake2.sys.NET; import lwjake2.sys.NET;
@@ -33,6 +34,8 @@ import lwjake2.sys.Timer;
import lwjake2.util.Lib; import lwjake2.util.Lib;
import lwjake2.util.Math3D; import lwjake2.util.Math3D;
import lwjake2.util.QuakeFile; import lwjake2.util.QuakeFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Dimension; import java.awt.Dimension;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
@@ -50,6 +53,8 @@ abstract class keyfunc_t {
} }
public final class Menu extends Key { public final class Menu extends Key {
private static final Logger logger = LoggerFactory.getLogger(Menu.class);
private static final FileSystem fileSystem = BaseQ2FileSystem.getInstance();
static int m_main_cursor; static int m_main_cursor;
@@ -1906,7 +1911,7 @@ public final class Menu extends Key {
int n; int n;
int isdeveloper = 0; int isdeveloper = 0;
byte b[] = FS.LoadFile("credits"); byte b[] = fileSystem.loadFile("credits");
if (b != null) { if (b != null) {
creditsBuffer = new String(b); creditsBuffer = new String(b);
@@ -1919,7 +1924,7 @@ public final class Menu extends Key {
creditsIndex[n] = null; creditsIndex[n] = null;
credits = creditsIndex; credits = creditsIndex;
} else { } else {
isdeveloper = FS.Developer_searchpath(1); isdeveloper = fileSystem.developer_searchpath(1);
if (isdeveloper == 1) // xatrix if (isdeveloper == 1) // xatrix
credits = xatcredits; credits = xatcredits;
@@ -2167,7 +2172,7 @@ public final class Menu extends Key {
for (i = 0; i < MAX_SAVEGAMES; i++) { for (i = 0; i < MAX_SAVEGAMES; i++) {
m_savestrings[i] = "<EMPTY>"; m_savestrings[i] = "<EMPTY>";
name = FS.Gamedir() + "/save/save" + i + "/server.ssv"; name = fileSystem.getGamedir() + "/save/save" + i + "/server.ssv";
try { try {
f = new QuakeFile(name, "r"); f = new QuakeFile(name, "r");
@@ -2589,7 +2594,7 @@ public final class Menu extends Key {
// ===== // =====
// PGM // PGM
// ROGUE GAMES // ROGUE GAMES
else if (FS.Developer_searchpath(2) == 2) { else if (fileSystem.developer_searchpath(2) == 2) {
if (s_rules_box.curvalue == 2) // tag if (s_rules_box.curvalue == 2) // tag
{ {
s_maxclients_field.statusbar = null; s_maxclients_field.statusbar = null;
@@ -2635,7 +2640,7 @@ public final class Menu extends Key {
// Cvar.SetValue ("coop", s_rules_box.curvalue ); // Cvar.SetValue ("coop", s_rules_box.curvalue );
// PGM // PGM
if ((s_rules_box.curvalue < 2) || (FS.Developer_searchpath(2) != 2)) { if ((s_rules_box.curvalue < 2) || (fileSystem.developer_searchpath(2) != 2)) {
Cvar.SetValue("deathmatch", 1 - (int) (s_rules_box.curvalue)); Cvar.SetValue("deathmatch", 1 - (int) (s_rules_box.curvalue));
Cvar.SetValue("coop", s_rules_box.curvalue); Cvar.SetValue("coop", s_rules_box.curvalue);
Cvar.SetValue("gamerules", 0); Cvar.SetValue("gamerules", 0);
@@ -2699,15 +2704,15 @@ public final class Menu extends Key {
/* /*
* * load the list of map names * * load the list of map names
*/ */
mapsname = FS.Gamedir() + "/maps.lst"; mapsname = fileSystem.getGamedir() + "/maps.lst";
// Check user dir first (default ~/.lwjake2) // Check user dir first (default ~/.lwjake2)
if ((fp = Lib.fopen(mapsname, "r")) == null) { if ((fp = Lib.fopen(mapsname, "r")) == null) {
// Check base dir first (baseq2 folder) // Check base dir first (baseq2 folder)
mapsname = FS.BaseGamedir() + "/maps.lst"; mapsname = fileSystem.getBaseGamedir() + "/maps.lst";
if ((fp = Lib.fopen(mapsname, "r")) == null) { if ((fp = Lib.fopen(mapsname, "r")) == null) {
// Open the pak's maplist // Open the pak's maplist
buffer = FS.LoadFile("maps.lst"); buffer = fileSystem.loadFile("maps.lst");
if (buffer == null) if (buffer == null)
Com.Error(ERR_DROP, "couldn't find maps.lst\n"); Com.Error(ERR_DROP, "couldn't find maps.lst\n");
} else { } else {
@@ -2755,7 +2760,7 @@ public final class Menu extends Key {
fp = null; fp = null;
} else { } else {
FS.FreeFile(buffer); buffer = null;
} }
/* /*
@@ -2776,7 +2781,7 @@ public final class Menu extends Key {
s_rules_box.name = "rules"; s_rules_box.name = "rules";
// PGM - rogue games only available with rogue DLL. // PGM - rogue games only available with rogue DLL.
if (FS.Developer_searchpath(2) == 2) if (fileSystem.developer_searchpath(2) == 2)
s_rules_box.itemnames = dm_coop_names_rogue; s_rules_box.itemnames = dm_coop_names_rogue;
else else
s_rules_box.itemnames = dm_coop_names; s_rules_box.itemnames = dm_coop_names;
@@ -3059,7 +3064,7 @@ public final class Menu extends Key {
// ======= // =======
// ROGUE // ROGUE
else if (FS.Developer_searchpath(2) == 2) { else if (fileSystem.developer_searchpath(2) == 2) {
if (f == s_no_mines_box) { if (f == s_no_mines_box) {
bit = DF_NO_MINES; bit = DF_NO_MINES;
} else if (f == s_no_nukes_box) { } else if (f == s_no_nukes_box) {
@@ -3283,7 +3288,7 @@ public final class Menu extends Key {
// ============ // ============
// ROGUE // ROGUE
if (FS.Developer_searchpath(2) == 2) { if (fileSystem.developer_searchpath(2) == 2) {
s_no_mines_box.type = MTYPE_SPINCONTROL; s_no_mines_box.type = MTYPE_SPINCONTROL;
s_no_mines_box.x = 0; s_no_mines_box.x = 0;
s_no_mines_box.y = y += 10; s_no_mines_box.y = y += 10;
@@ -3354,7 +3359,7 @@ public final class Menu extends Key {
// ======= // =======
// ROGUE // ROGUE
if (FS.Developer_searchpath(2) == 2) { if (fileSystem.developer_searchpath(2) == 2) {
Menu_AddItem(s_dmoptions_menu, s_no_mines_box); Menu_AddItem(s_dmoptions_menu, s_no_mines_box);
Menu_AddItem(s_dmoptions_menu, s_no_nukes_box); Menu_AddItem(s_dmoptions_menu, s_no_nukes_box);
Menu_AddItem(s_dmoptions_menu, s_stack_double_box); Menu_AddItem(s_dmoptions_menu, s_stack_double_box);
@@ -3764,10 +3769,10 @@ public final class Menu extends Key {
* * get a list of directories * * get a list of directories
*/ */
do { do {
path = FS.NextPath(path); path = fileSystem.nextPath(path);
findname = path + "/players/*.*"; findname = path + "/players/*.*";
if ((dirnames = FS.ListFiles(findname, 0, SFF_SUBDIR)) != null) { if ((dirnames = fileSystem.listFiles(findname, 0, SFF_SUBDIR)) != null) {
ndirs = dirnames.length; ndirs = dirnames.length;
break; break;
} }
@@ -3807,7 +3812,7 @@ public final class Menu extends Key {
// verify the existence of at least one pcx skin // verify the existence of at least one pcx skin
scratch = dirnames[i] + "/*.pcx"; scratch = dirnames[i] + "/*.pcx";
pcxnames = FS.ListFiles(scratch, 0, 0); pcxnames = fileSystem.listFiles(scratch, 0, 0);
npcxfiles = pcxnames.length; npcxfiles = pcxnames.length;
// count valid skins, which consist of a skin with a matching "_i" // count valid skins, which consist of a skin with a matching "_i"

View File

@@ -159,7 +159,8 @@ public class BaseQ2FileSystem implements FileSystem {
* *
* Allows enumerating all of the directories in the search path * Allows enumerating all of the directories in the search path
*/ */
private String nextPath(String prevpath) { @Override
public String nextPath(String prevpath) {
searchpath_t s; searchpath_t s;
String prev; String prev;
@@ -180,7 +181,8 @@ public class BaseQ2FileSystem implements FileSystem {
return null; return null;
} }
private String[] listFiles(String findname, int musthave, int canthave) { @Override
public String[] listFiles(String findname, int musthave, int canthave) {
String[] list = new String[0]; String[] list = new String[0];
File[] files = Sys.FindAll(findname, musthave, canthave); File[] files = Sys.FindAll(findname, musthave, canthave);
@@ -470,6 +472,11 @@ public class BaseQ2FileSystem implements FileSystem {
return (fs_userdir != null) ? fs_userdir : Globals.BASEDIRNAME; return (fs_userdir != null) ? fs_userdir : Globals.BASEDIRNAME;
} }
@Override
public String getBaseGamedir() {
return (fs_gamedir != null) ? fs_gamedir : Globals.BASEDIRNAME;
}
@Override @Override
public void execAutoexec() { public void execAutoexec() {
String dir = fs_userdir; String dir = fs_userdir;

View File

@@ -15,10 +15,14 @@ public interface FileSystem {
void execAutoexec(); void execAutoexec();
void createPath(String path); void createPath(String path);
int fileLength(String filename); int fileLength(String filename);
String nextPath(String prevpath);
String[] listFiles(String findname, int musthave, int canthave);
int developer_searchpath(int who); int developer_searchpath(int who);
cvar_t getGamedirVar(); cvar_t getGamedirVar();
void setGamedir(String dir); void setGamedir(String dir);
String getGamedir(); String getGamedir();
String getBaseGamedir();
} }