Exemple #1
0
        /*
         * ===========
         * COM_FOpenFile
         *
         * If the requested file is inside a packfile, a new FILE * will be opened
         * into the file.
         * ===========
         */
        public static int COM_FOpenFile(string filename, ref Helper.helper.FILE file)
        {
            int handle = -1;

            return(COM_FindFile(filename, ref handle, ref file));
        }
Exemple #2
0
        /*
        ===========
        COM_FindFile

        Finds the file in the search path.
        Sets com_filesize and one of handle or file
        ===========
        */
        static int COM_FindFile (string filename, ref int handle, ref Helper.helper.FILE file)
        {
	        searchpath_t    search;
	        string          netpath;
	        string          cachepath;
	        pack_t          pak;
	        int             i;
	        int             findtime, cachetime;

/*	        if (file && handle)
		        Sys_Error ("COM_FindFile: both handle and file set");
	        if (!file && !handle)
		        Sys_Error ("COM_FindFile: neither handle or file set");*/
        		
        //
        // search through the path, one element at a time
        //
	        search = com_searchpaths;
	        if (proghack)
	        {	// gross hack to use quake 1 progs with quake 2 maps
		        if (filename.CompareTo("progs.dat") == 0)
			        search = search.next;
	        }

	        for ( ; search != null ; search = search.next)
	        {
	        // is the element a pak file?
		        if (search.pack != null)
		        {
		        // look through all the pak file elements
			        pak = search.pack;
			        for (i=0 ; i<pak.numfiles ; i++)
				        if (pak.files[i].name.CompareTo(filename) == 0)
				        {       // found it!
                            //sys_linux.Sys_Printf ("PackFile: " + pak.filename + " : " + filename + "\n");
                            if (handle != -1)
                            {
                                handle = pak.handle;
                                sys_linux.Sys_FileSeek(pak.handle, pak.files[i].filepos);
                            }
                            else
                            {       // open a new file on the pakfile
                                string pf = pak.filename;
                                if (pf.StartsWith("./"))
                                    pf = pf.Substring(2);

                                StreamResourceInfo si = Application.GetResourceStream(new Uri("InnoveWare;component/" + pf, UriKind.Relative));
                                if (si != null)
                                {
                                    file = new Helper.helper.FILE(si.Stream, pak.filename);
                                }
                                //*file = fopen(pak->filename, "rb");
                                if (file != null)
                                    Helper.helper.fseek(file, pak.files[i].filepos, Helper.helper.SEEK_SET);
                            }

					        com_filesize = pak.files[i].filelen;
					        return com_filesize;
				        }
		        }
	        }
        	
	        sys_linux.Sys_Printf ("FindFile: can't find " + filename + "\n");
        	
	        if (handle != -1)
		        handle = -1;
	        else
		        file = null;
	        com_filesize = -1;
	        return -1;
        }
Exemple #3
0
        /*
         * ===========
         * COM_FindFile
         *
         * Finds the file in the search path.
         * Sets com_filesize and one of handle or file
         * ===========
         */
        static int COM_FindFile(string filename, ref int handle, ref Helper.helper.FILE file)
        {
            searchpath_t search;
            string       netpath;
            string       cachepath;
            pack_t       pak;
            int          i;
            int          findtime, cachetime;

/*	        if (file && handle)
 *                      Sys_Error ("COM_FindFile: both handle and file set");
 *              if (!file && !handle)
 *                      Sys_Error ("COM_FindFile: neither handle or file set");*/

            //
            // search through the path, one element at a time
            //
            search = com_searchpaths;
            if (proghack)
            {           // gross hack to use quake 1 progs with quake 2 maps
                if (filename.CompareTo("progs.dat") == 0)
                {
                    search = search.next;
                }
            }

            for ( ; search != null; search = search.next)
            {
                // is the element a pak file?
                if (search.pack != null)
                {
                    // look through all the pak file elements
                    pak = search.pack;
                    for (i = 0; i < pak.numfiles; i++)
                    {
                        if (pak.files[i].name.CompareTo(filename) == 0)
                        {                       // found it!
                            sys_linux.Sys_Printf("PackFile: " + pak.filename + " : " + filename + "\n");
                            if (handle != -1)
                            {
                                handle = pak.handle;
                                sys_linux.Sys_FileSeek(pak.handle, pak.files[i].filepos);
                            }
                            else
                            {       // open a new file on the pakfile
                                string pf = pak.filename;
                                if (pf.StartsWith("./"))
                                {
                                    pf = pf.Substring(2);
                                }

                                StreamResourceInfo si = Application.GetResourceStream(new Uri("InnoveWare;component/" + pf, UriKind.Relative));
                                if (si != null)
                                {
                                    file        = new Helper.helper.FILE();
                                    file.stream = si.Stream;
                                }
                                //*file = fopen(pak->filename, "rb");
                                if (file != null)
                                {
                                    Helper.helper.fseek(file, pak.files[i].filepos, Helper.helper.SEEK_SET);
                                }
                            }

                            com_filesize = pak.files[i].filelen;
                            return(com_filesize);
                        }
                    }
                }
            }

            sys_linux.Sys_Printf("FindFile: can't find " + filename + "\n");

            if (handle != -1)
            {
                handle = -1;
            }
            else
            {
                file = null;
            }
            com_filesize = -1;
            return(-1);
        }