⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fs.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        } catch (IOException ioe) {        }        return null;    }    /*     * FreeFile     */    public static void FreeFile(byte[] buffer) {        buffer = null;    }    static final int IDPAKHEADER = (('K' << 24) + ('C' << 16) + ('A' << 8) + 'P');    static class dpackheader_t {        int ident; // IDPAKHEADER        int dirofs;        int dirlen;    }    static final int MAX_FILES_IN_PACK = 4096;    // buffer for C-Strings char[56]    static byte[] tmpText = new byte[packfile_t.NAME_SIZE];    /*     * LoadPackFile     *      * Takes an explicit (not game tree related) path to a pak file.     *      * Loads the header and directory, adding the files at the beginning of the     * list so they override previous pack files.     */    static pack_t LoadPackFile(String packfile) {        dpackheader_t header;        Hashtable newfiles;        RandomAccessFile file;        int numpackfiles = 0;        pack_t pack = null;        //		unsigned checksum;        //        try {        	file = new RandomAccessFile(packfile, "r");        	FileChannel fc = file.getChannel();            ByteBuffer packhandle = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length());            packhandle.order(ByteOrder.LITTLE_ENDIAN);             fc.close();                        if (packhandle == null || packhandle.limit() < 1)                return null;            //            header = new dpackheader_t();            header.ident = packhandle.getInt();            header.dirofs = packhandle.getInt();            header.dirlen = packhandle.getInt();            if (header.ident != IDPAKHEADER)                Com.Error(Defines.ERR_FATAL, packfile + " is not a packfile");            numpackfiles = header.dirlen / packfile_t.SIZE;            if (numpackfiles > MAX_FILES_IN_PACK)                Com.Error(Defines.ERR_FATAL, packfile + " has " + numpackfiles                        + " files");            newfiles = new Hashtable(numpackfiles);            packhandle.position(header.dirofs);            // parse the directory            packfile_t entry = null;            for (int i = 0; i < numpackfiles; i++) {                packhandle.get(tmpText);                entry = new packfile_t();                entry.name = new String(tmpText).trim();                entry.filepos = packhandle.getInt();                entry.filelen = packhandle.getInt();                newfiles.put(entry.name.toLowerCase(), entry);            }        } catch (IOException e) {            Com.DPrintf(e.getMessage() + '\n');            return null;        }        pack = new pack_t();        pack.filename = new String(packfile);        pack.handle = file;        pack.numfiles = numpackfiles;        pack.files = newfiles;        Com.Printf("Added packfile " + packfile + " (" + numpackfiles                + " files)\n");        return pack;    }    /*     * AddGameDirectory     *      * Sets fs_gamedir, adds the directory to the head of the path, then loads     * and adds pak1.pak pak2.pak ...     */    static void AddGameDirectory(String dir) {        int i;        searchpath_t search;        pack_t pak;        String pakfile;        fs_gamedir = new String(dir);        //        // add the directory to the search path        // ensure fs_userdir is first in searchpath        search = new searchpath_t();        search.filename = new String(dir);        if (fs_searchpaths != null) {            search.next = fs_searchpaths.next;            fs_searchpaths.next = search;        } else {            fs_searchpaths = search;        }        //        // add any pak files in the format pak0.pak pak1.pak, ...        //        for (i = 0; i < 10; i++) {            pakfile = dir + "/pak" + i + ".pak";            if (!(new File(pakfile).canRead()))                continue;            pak = LoadPackFile(pakfile);            if (pak == null)                continue;            search = new searchpath_t();            search.pack = pak;            search.filename = "";            search.next = fs_searchpaths;            fs_searchpaths = search;        }    }    /*     * Gamedir     *      * Called to find where to write a file (demos, savegames, etc)     * this is modified to <user.home>/.jake2      */    public static String Gamedir() {        return (fs_userdir != null) ? fs_userdir : Globals.BASEDIRNAME;    }    /*     * BaseGamedir     *      * Called to find where to write a downloaded file     */    public static String BaseGamedir() {        return (fs_gamedir != null) ? fs_gamedir : Globals.BASEDIRNAME;    }    /*     * ExecAutoexec     */    public static void ExecAutoexec() {        String dir = fs_userdir;        String name;        if (dir != null && dir.length() > 0) {            name = dir + "/autoexec.cfg";        } else {            name = fs_basedir.string + '/' + Globals.BASEDIRNAME                    + "/autoexec.cfg";        }        int canthave = Defines.SFF_SUBDIR | Defines.SFF_HIDDEN                | Defines.SFF_SYSTEM;        if (Sys.FindAll(name, 0, canthave) != null) {            Cbuf.AddText("exec autoexec.cfg\n");        }    }    /*     * SetGamedir     *      * Sets the gamedir and path to a different directory.     */    public static void SetGamedir(String dir) {        searchpath_t next;        if (dir.indexOf("..") != -1 || dir.indexOf("/") != -1                || dir.indexOf("\\") != -1 || dir.indexOf(":") != -1) {            Com.Printf("Gamedir should be a single filename, not a path\n");            return;        }        //        // free up any current game dir info        //        while (fs_searchpaths != fs_base_searchpaths) {            if (fs_searchpaths.pack != null) {                try {                    fs_searchpaths.pack.handle.close();                } catch (IOException e) {                    Com.DPrintf(e.getMessage() + '\n');                }                // clear the hashtable                fs_searchpaths.pack.files.clear();                fs_searchpaths.pack.files = null;                fs_searchpaths.pack = null;            }            next = fs_searchpaths.next;            fs_searchpaths = null;            fs_searchpaths = next;        }        //        // flush all data, so it will be forced to reload        //        if ((Globals.dedicated != null) && (Globals.dedicated.value == 0.0f))            Cbuf.AddText("vid_restart\nsnd_restart\n");        fs_gamedir = fs_basedir.string + '/' + dir;        if (dir.equals(Globals.BASEDIRNAME) || (dir.length() == 0)) {            Cvar.FullSet("gamedir", "", CVAR_SERVERINFO | CVAR_NOSET);            Cvar.FullSet("game", "", CVAR_LATCH | CVAR_SERVERINFO);        } else {            Cvar.FullSet("gamedir", dir, CVAR_SERVERINFO | CVAR_NOSET);            if (fs_cddir.string != null && fs_cddir.string.length() > 0)                AddGameDirectory(fs_cddir.string + '/' + dir);            AddGameDirectory(fs_basedir.string + '/' + dir);        }    }    /*     * Link_f     *      * Creates a filelink_t     */    public static void Link_f() {        filelink_t entry = null;        if (Cmd.Argc() != 3) {            Com.Printf("USAGE: link <from> <to>\n");            return;        }        // see if the link already exists        for (Iterator it = fs_links.iterator(); it.hasNext();) {            entry = (filelink_t) it.next();            if (entry.from.equals(Cmd.Argv(1))) {                if (Cmd.Argv(2).length() < 1) {                    // delete it                    it.remove();                    return;                }                entry.to = new String(Cmd.Argv(2));                return;            }        }        // create a new link if the <to> is not empty        if (Cmd.Argv(2).length() > 0) {            entry = new filelink_t();            entry.from = new String(Cmd.Argv(1));            entry.fromlength = entry.from.length();            entry.to = new String(Cmd.Argv(2));            fs_links.add(entry);        }    }    /*     * ListFiles     */    public static String[] ListFiles(String findname, int musthave, int canthave) {        String[] list = null;        File[] files = Sys.FindAll(findname, musthave, canthave);        if (files != null) {            list = new String[files.length];            for (int i = 0; i < files.length; i++) {                list[i] = files[i].getPath();            }        }        return list;    }    /*     * Dir_f     */    public static void Dir_f() {        String path = null;        String findname = null;        String wildcard = "*.*";        String[] dirnames;        if (Cmd.Argc() != 1) {            wildcard = Cmd.Argv(1);        }        while ((path = NextPath(path)) != null) {            String tmp = findname;            findname = path + '/' + wildcard;            if (tmp != null)                tmp.replaceAll("\\\\", "/");            Com.Printf("Directory of " + findname + '\n');            Com.Printf("----\n");            dirnames = ListFiles(findname, 0, 0);            if (dirnames != null) {                int index = 0;                for (int i = 0; i < dirnames.length; i++) {                    if ((index = dirnames[i].lastIndexOf('/')) > 0) {                        Com.Printf(dirnames[i].substring(index + 1, dirnames[i]                                .length()) + '\n');                    } else {                        Com.Printf(dirnames[i] + '\n');                    }                }            }            Com.Printf("\n");        }    }    /*     * Path_f     */    public static void Path_f() {        searchpath_t s;        filelink_t link;        Com.Printf("Current search path:\n");        for (s = fs_searchpaths; s != null; s = s.next) {            if (s == fs_base_searchpaths)                Com.Printf("----------\n");            if (s.pack != null)                Com.Printf(s.pack.filename + " (" + s.pack.numfiles                        + " files)\n");            else                Com.Printf(s.filename + '\n');        }        Com.Printf("\nLinks:\n");        for (Iterator it = fs_links.iterator(); it.hasNext();) {            link = (filelink_t) it.next();            Com.Printf(link.from + " : " + link.to + '\n');        }    }    /*     * NextPath     *      * Allows enumerating all of the directories in the search path     */    public static String NextPath(String prevpath) {        searchpath_t s;        String prev;        if (prevpath == null || prevpath.length() == 0)            return fs_gamedir;        prev = fs_gamedir;        for (s = fs_searchpaths; s != null; s = s.next) {            if (s.pack != null)                continue;            if (prevpath == prev)                return s.filename;            prev = s.filename;        }        return null;    }    /*     * InitFilesystem     */    public static void InitFilesystem() {        Cmd.AddCommand("path", new xcommand_t() {            public void execute() {                Path_f();            }        });        Cmd.AddCommand("link", new xcommand_t() {            public void execute() {                Link_f();            }        });        Cmd.AddCommand("dir", new xcommand_t() {            public void execute() {                Dir_f();            }        });        fs_userdir = System.getProperty("user.home") + "/.jake2";        FS.CreatePath(fs_userdir + "/");        FS.AddGameDirectory(fs_userdir);        //        // basedir <path>        // allows the game to run from outside the data tree        //        fs_basedir = Cvar.Get("basedir", ".", CVAR_NOSET);        //        // cddir <path>        // Logically concatenates the cddir after the basedir for        // allows the game to run from outside the data tree        //        setCDDir();        //        // start up with baseq2 by default        //        AddGameDirectory(fs_basedir.string + '/' + Globals.BASEDIRNAME);        // any set gamedirs will be freed up to here        markBaseSearchPaths();        // check for game override        fs_gamedirvar = Cvar.Get("game", "", CVAR_LATCH | CVAR_SERVERINFO);        if (fs_gamedirvar.string.length() > 0)            SetGamedir(fs_gamedirvar.string);    }    /**     * set baseq2 directory     */    static void setCDDir() {        fs_cddir = Cvar.Get("cddir", "", CVAR_ARCHIVE);        if (fs_cddir.string.length() > 0)            AddGameDirectory(fs_cddir.string);    }        static void markBaseSearchPaths() {        // any set gamedirs will be freed up to here        fs_base_searchpaths = fs_searchpaths;    }    //	RAFAEL    /*     * Developer_searchpath     */    public static int Developer_searchpath(int who) {        int ch;        // PMM - warning removal        //	 char *start;        searchpath_t s;        if (who == 1) // xatrix            ch = 'x';        else if (who == 2)            ch = 'r';        for (s = fs_searchpaths; s != null; s = s.next) {            if (s.filename.indexOf("xatrix") != -1)                return 1;            if (s.filename.indexOf("rogue") != -1)                return 2;        }        return 0;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -