You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.2 KiB
C++

#pragma once
#include <lowlevellib.h>
#include "crc32.h"
/************************************************************************
CFM_LoaderClass
Init()
Init opens a stream to "IMAGE" RES:IMG_DATA
IMG_Data is a regular Zipfile
Opens connection to the http server, downloads the crcfile.list
TestFileList()
Loads the complete list into memory out of the IMG_Data Zip
A crc is build and compared against the http crc list.
If the crc unmatch a entry is added to the m_download_queue
DownloadFiles()
HTTP Transfering alle files from the m_download_queue to
the local tmp dir.
Callbackfunction:
int MyHook(
char *file, // current open file
int totalbytes, // total bytes actually read
int totalfiles, // total files processed
int percentcomplete, // current open file percent complete
void *userPtr // your own userdata ptr
);
Return 0 at end of function.
************************************************************************/
class CRedirectFile_Module;
class CFMLoader
{
public:
CFMLoader(void);
virtual ~CFMLoader(void);
friend class CRedirectFile_Module;
/*
* Functioncall sequence
* 1) Init(); --> opens http, retrieves crcfilelist.txt
* 2) TestFileList(); --> builds download list
* 3) DownloadFiles(); --> download unmatched crc files from http
* ...
* On demand call:
*/
void Init(const char * httpserver);
/*
* TestFileList, compares each file's crc with the filecrclist which
* is downloaded from the httpserver
* Returns number of files to be downloaded.
* If parameter list == NULL, the server list from http will be used.
* -1 = failure
*/
int TestFileList(char *list=NULL);
/*
* Test a single file. The File is added to the download list
*/
void TestFile(const char* filename);
/*
* Start downloading
* returns count of sucessfull downloaded files
*/
int DownloadFiles(ReadHookPtr cbfunc=NULL, void * usrPtr=NULL );
/*
* Info methods
*/
int GetApproxDownloadSize(); // returns total amount of byte to be downloaded
int GetCntFiles(); // returns number of files in the transfer queue
char * MakePath(const char* filename); //returns full path to local resources
/*
* Get Streamid to manually load a file
* Example:
* llfile_cur_stream = m_loader.GetCurStream();
* byte *ptr = llfile_LoadToMem("myfile_on_the_stream");
*/
llfile_eSTREAM GetCurStream(){ return m_cur_stream; }
private:
/*
* CRC Item struct.
*/
typedef struct {
char * filename;
crc32l crc;
int size;
} crcEntry;
queue<crcEntry> m_crc_list;
// Stream id
llfile_eSTREAM m_cur_stream;
llfile_eSTREAM m_http_stream;
ReadHookPtr m_cbfunc;
void * m_usrPtr;
queue<char> m_download_queue;
int m_approx_bytes_to_download;
void BuildCrcFileList();
void BuildIconMap();
void BuildIconList();
void BuildBitmapMap();
void BuildBitmapList();
void MakeHttpPath(char *buf, const char *filename );
bool HttpDownloadFile(const char *filename);
void MakeLocalPath(char *buf, const char *filename );
// Return > 0 = file does not match, returns filesize of remotefile
// Return 0 = file matches
// Return -1 = file not found in the crcfilelist
int CompareCrcToHttpList(const char*filename, crc32l crc);
};