Beispiel #1
0
//
// Write a string to the logfile.
//
void appendToLogfile(const char* text, int logLevel)
{
    word mjd;
    byte hour;
    byte min;
    byte sec;
    word year;
    byte month;
    byte day;
    byte weekday;
    char str[20];
    dword tempTick;

    if (logLevel > LOGLEVEL) return;

    if (logFD != NULL)
    {
        TAP_GetTime( &mjd, &hour, &min, &sec);
        TAP_ExtractMjd(mjd, &year, &month, &day, &weekday);
        tempTick = TAP_GetTick();
        //sprintf(str,"%02d-%02d-%04d %02d:%02d:%02d - ", day, month, year, hour, min, sec);
        sprintf(str,"%02d:%02d:%02d %i - ", hour, min, sec, tempTick);
        TAP_Hdd_Fwrite((void*)str, strlen(str), 1, logFD);
        TAP_Hdd_Fwrite((void*)text, strlen(text), 1, logFD);
        TAP_Hdd_Fwrite((void*)"\r\n", strlen("\r\n"), 1, logFD);
        logByteCount += strlen(text) + strlen("\r\n");
    }
}
Beispiel #2
0
void Settings_Save()
{
	TYPE_File* fp;

	TAP_Hdd_ChangeDir( ".." );
	TAP_Hdd_ChangeDir( ".." );
	TAP_Hdd_ChangeDir( "ProgramFiles" );
	if ( !TAP_Hdd_Exist( "Settings" ) )
		TAP_Hdd_Create( "Settings", ATTR_FOLDER );
	TAP_Hdd_ChangeDir( "Settings" );

	if ( !TAP_Hdd_Exist( settingsFile ) )
		TAP_Hdd_Create( settingsFile, ATTR_NORMAL );

	if ( fp = TAP_Hdd_Fopen(settingsFile) )
	{
		int version = INI_VERSION;
		int zero[64];
		memset( zero, 0, sizeof(zero) );
		TAP_Hdd_Fwrite( &version, 1, sizeof(version), fp );
		TAP_Hdd_Fwrite( &settings, 1, sizeof(settings), fp );
		TAP_Hdd_Fwrite( zero, 1, sizeof(zero), fp );
		TAP_Hdd_Fclose( fp );
	}
}
Beispiel #3
0
bool HDD_Write(void *data, dword length, TYPE_File *f)
{
  TRACEENTER();

  static byte           block[512];
  static byte           *b = block;
  bool                  success = TRUE;
  dword                 blen;

  // flush buffer
  if(length == 0)
  {
    if(b > block)
    {
      success = (TAP_Hdd_Fwrite(block, sizeof(block), 1, f) == 1);
      b = block;
    }
  }
  // can't buffer data
  else if(length > sizeof(block)) success = (TAP_Hdd_Fwrite(data, length, 1, f) == 1);
  else
  {
    blen = sizeof(block) - (b - block);

    // not enough space in buffer
    if(length > blen)
    {
      // fill rest of buffer
      memcpy(b, data, blen);
      success = (TAP_Hdd_Fwrite(block, sizeof(block), 1, f) == 1);

      //(byte *) data += blen;
      data = (byte*)data + blen;

      length -= blen;
      b = block;
    }

    // new buffer
    if(b == block) memset(block, 0, sizeof(block));

    // enough space in buffer
    memcpy(b, data, length);
    b += length;
  }

  TRACEEXIT();
  return success;
}
Beispiel #4
0
void closeLogfile(void)
{
	if (logFD != NULL)
	{
		char buff[512];
		int rem;

		memset(buff, 0, sizeof buff);
		// Space pad the end of the last 512 byte block as the Toppy writes in 512 bytes blocks
		TAP_Hdd_Fseek(logFD, logByteCount, SEEK_SET);
		strcpy(buff, "********** End Of File **********\r\n");
		TAP_Hdd_Fwrite((void*)buff, strlen(buff), 1, logFD);
		/*
		rem = logByteCount % 512;
		if (rem > 0)
		{
			memset(buff, 0, rem+1);
			TAP_Hdd_Fwrite(buff, rem, 1, logFD);
		}
		*/

		//TAP_Hdd_Fwrite((void*)"\r\n", strlen("\r\n"), 1, logFD);
		//logByteCount += 2;

		// goto the start of the file and write length marker
		//TAP_Hdd_Fseek(logFD, 0, SEEK_SET);
		//TAP_Hdd_Fwrite(&_logSig, sizeof _logSig, 1, logFD);

		//TAP_Hdd_Fseek(logFD, _logSig.logSize, SEEK_SET);
		//TAP_Hdd_Fwrite((void *)"************** end of file *************\n", 41, 1, logFD);

		TAP_Hdd_Fclose(logFD);
		logFD = NULL;
	}	
}
Beispiel #5
0
void openLogfile()
{

	if (logFD != NULL)
	{
		TAP_Print("openLogfile: attempting to open file that's already open\r\n");
		return;
	}

	logFD = TAP_Hdd_Fopen((char *)LOGFILENAME);
	if (logFD == NULL)
	{
		//TAP_Print("File doesn't exist. Creating log file...\r\n");
		TAP_Hdd_Create((char *)LOGFILENAME, ATTR_NORMAL);
		logFD = TAP_Hdd_Fopen((char *)LOGFILENAME);
		//write the header stuff identifying this machine/firmware
		logByteCount = sizeof logByteCount;
		//TAP_Hdd_Fwrite((void *)logByteCount, logByteCount, 1, logFD);
		TAP_Hdd_Fwrite((void *)"4    ", logByteCount, 1, logFD);
		//TAP_Print("File marker written...\r\n");
	}
	else 
	{
		// goto the end of the file
		//TAP_Hdd_Fseek(logFD, 0, SEEK_END);
	}
}
//----------------
//
void WriteDatFile( TYPE_File *writeFile )
{
    char* currentDir;
     
    appendToLogfile("WriteDatFile: Started.", INFO);
    appendToLogfile("WriteDatFile: GetCurrentDir called.", WARNING);
    currentDir = GetCurrentDir();  // Store the current  directory.

    appendStringToLogfile("WriteDatFile: GetCurrentDir returned=%s.",currentDir, WARNING);
    appendStringToLogfile("WriteDatFile: Moving to=%s.",TAPIniDir, WARNING);
    GotoPath(TAPIniDir);           // Go to the Project Directory.
    
	if ( TAP_Hdd_Exist( PLAYDATA_FILENAME ) ) TAP_Hdd_Delete( PLAYDATA_FILENAME );	// Just delete any old copies

    appendToLogfile("WriteDatFile: Creating DATA file.", ERR);
	TAP_Hdd_Create( PLAYDATA_FILENAME, ATTR_PROGRAM );						// Create the file

    appendToLogfile("WriteDatFile: Opening DATA file.", ERR);
	writeFile = TAP_Hdd_Fopen( PLAYDATA_FILENAME );
	if ( writeFile == NULL ) return; 										// Check we can open it

    appendToLogfile("WriteDatFile: Writing to DATA file.", ERR);
	TAP_Hdd_Fwrite( playDataBuffer_ini, PLAYBACKDATA_BUFFER_SIZE_ini, 1, writeFile );	// dump the whole buffer in one hit

    appendToLogfile("WriteDatFile: Closing DATA file.", ERR);
	TAP_Hdd_Fclose( writeFile );

    appendStringToLogfile("WriteDatFile: Returning to=%s.",currentDir, WARNING);
	GotoPath(currentDir);            // Return to the original directory.

    TAP_MemFree( currentDir );   // Free allocated memory.
    
    appendToLogfile("WriteDatFile: Finished.", INFO);
}
Beispiel #7
0
//
// Close the logfile.
//
void closeLogfile()
{
    if (logFD != NULL)
    {
        // Make the end of the logfile stop on a 512 byte boundary.
        appendToLogfile("********** End of logfile **********", INFO);
        while ((logByteCount % 512) != 510)
        {
            TAP_Hdd_Fwrite(" ", 1, 1, logFD);
            logByteCount++;
        }
        TAP_Hdd_Fwrite((void*)"\r\n", strlen("\r\n"), 1, logFD);
        logByteCount += 2;

        TAP_Hdd_Fclose(logFD);
        logFD = NULL;
    }
}
Beispiel #8
0
//----------------
//
void WriteIniFile( TYPE_File *writeFile )
{
	GotoPath(SETTINGS_FOLDER);
	if ( TAP_Hdd_Exist( OPTIONS_FILENAME ) ) TAP_Hdd_Delete( OPTIONS_FILENAME );	// Just delete any old copies

	TAP_Hdd_Create( OPTIONS_FILENAME, ATTR_PROGRAM );				// Create the file

	writeFile = TAP_Hdd_Fopen( OPTIONS_FILENAME );
	if ( writeFile == NULL ) return; 										// Check we can open it

	TAP_Hdd_Fwrite( dataBuffer_ini, DATA_BUFFER_SIZE_ini, 1, writeFile );		// dump the whole buffer in one hit

	TAP_Hdd_Fclose( writeFile );
}
Beispiel #9
0
void appendToLogfile(const char* text)
{	
    word mjd; byte hour; byte min; byte sec; 
	word year; byte month; byte day; byte weekday;
    char str[20]; 

	//TAP_Print("Appending to log file...\r\n");
	openLogfile();

	if (logFD != NULL)
	{
		TAP_Hdd_Fseek(logFD, logByteCount, SEEK_SET);

        TAP_GetTime( &mjd, &hour, &min, &sec);
        TAP_ExtractMjd(mjd, &year, &month, &day, &weekday);
		sprintf(str,"%02d-%02d-%04d %02d:%02d:%02d - ", day, month, year, hour, min, sec);
		TAP_Hdd_Fwrite((void*)str, strlen(str), 1, logFD);
		TAP_Hdd_Fwrite((void*)text, strlen(text), 1, logFD);
		TAP_Hdd_Fwrite((void*)"\r\n", strlen("\r\n"), 1, logFD);
		logByteCount += strlen(str) + strlen(text) + strlen("\r\n");
		closeLogfile();
	}
	
}
Beispiel #10
0
// ------------------------------ SaveBitmap ------------------------------------
//
bool SaveBitmap (char *strName, int width, int height, byte* pBuffer )
{
  TYPE_File             *pFile;

  if( !pBuffer || !strName ) return FALSE;

  TAP_Hdd_Create( strName, ATTR_NORMAL );
  pFile = TAP_Hdd_Fopen( strName );
  if ( !pFile ) return FALSE;

  // Write Header
  BMP_WriteHeader( pFile, width, height );

  // write bitmap data
  TAP_Hdd_Fwrite (pBuffer, width*3, height, pFile);
  HDD_TouchFile  (pFile);
  TAP_Hdd_Fclose (pFile);

  return TRUE;
}
Beispiel #11
0
void tmLogEvent(void)
{
	char	tmBuffer[TM_EVENT_BUFFER_SIZE];

	TYPE_File* fp;

	memset (tmBuffer, 0, TM_EVENT_BUFFER_SIZE);

	TAP_SPrint( tmBuffer, "%02u:%02u:%02u %02u/%02u/%04u, %3u,  %3u, %3u       %02u:%02u:%02u %02u/%02u/%04u, %3u,  %3u, %3u\r\n", hourLast, minLast, secLast, dayLast, monthLast, yearLast, signalLevelLast, signalQualityLast, timersLast, hour, min, sec, day, month, year, signalLevel, signalQuality, timers);

	if (fp = TAP_Hdd_Fopen (TM_FILENAME))
	{
		TAP_Hdd_Fseek (fp, tmBufferOffset, 0);

		TAP_Hdd_Fwrite (tmBuffer, 1, strlen(tmBuffer), fp);

		TAP_Hdd_Fclose (fp);

		tmBufferOffset += strlen(tmBuffer);

		tmNumberOfEvents++;

		if (tmBufferOffset >= (TM_FILE_MAX_LENGTH - TM_EVENT_BUFFER_SIZE))
		{
			ShowMessageWin("Log File Full","Exiting!");

			TAP_Exit();

			return;
		}
	}
	else
	{
		ShowMessageWin("Error! - Unable to open file","Exiting!");

		TAP_Exit();

		return;
	}
}
bool HDD_SetCryptFlag (TYPE_File *fp, byte CryptFlag)
{
  dword                 FilePos;
  tRECHeaderInfo        RECHeaderInfo;
  byte                  Buffer [2048];
  TYPE_File             f;

  if (fp == NULL || fp->handle == NULL) return FALSE;

  InitTAPAPIFix();

  FilePos = TAP_Hdd_Ftell (fp);

  if (TAP_Hdd_Fseek (fp, 0, SEEK_SET) != 0) return FALSE;

  if (TAP_Hdd_Fread (Buffer, sizeof(Buffer), 1, fp) != 1 || TAP_Hdd_Fseek (fp, 0, SEEK_SET) != 0) return FALSE;

  HDD_DecodeRECHeader (Buffer, &RECHeaderInfo);

  f = *fp;

  fp->crypt = CryptFlag;
  ((tFileSlot *) fp->handle)->Scrambled = (CryptFlag ? 1 : 0);
  ((tFileSlot *) fp->handle)->CryptFlag = CryptFlag;
  RECHeaderInfo.CryptFlag = CryptFlag;

  HDD_EncodeRECHeader (Buffer, &RECHeaderInfo, RECHeaderInfo.HeaderType);

  if (TAP_Hdd_Fwrite (Buffer, sizeof(Buffer), 1, fp) != 1)
  {
    *fp = f;
    return FALSE;
  }

  return (TAP_Hdd_Fseek (fp, FilePos, SEEK_SET) == FilePos);
}
void LogEntryGeneric(char *ProgramName, bool Console, char *Text)
{
    TRACEENTER();

    char                 *s;
    int                   l;
    TYPE_File             *File;
    char                  TimeResult[40];
    char                  CRLF[] = {'\r', '\n'};
    byte                  Sec;
    byte                 *ISOText;

#define FILENAME      "TAPSystem.log"

    if(!ProgramName || !Text)
    {
        TRACEEXIT();
        return;
    }

    HDD_TAP_PushDir();
    if(!HDD_ChangeDir("/ProgramFiles/Settings"))
    {
        HDD_ChangeDir("/ProgramFiles");
        if(!TAP_Hdd_Exist("Settings")) TAP_Hdd_Create("Settings", ATTR_FOLDER);
        HDD_ChangeDir("Settings");
    }

    l = strlen(ProgramName) + strlen(Text) + 4;
    s = TAP_MemAlloc(l);
    if(s)
    {
        memset(s, 0, l);
        TAP_SPrint(s, "%s: %s", ProgramName, Text);
        StrToISOAlloc(s, &ISOText);
        if(ISOText)
        {
            TimeFormat(Now(&Sec), Sec, TIMESTAMP_YMDHMS, TimeResult);
            strcat(TimeResult, " ");

            if(!TAP_Hdd_Exist(FILENAME)) TAP_Hdd_Create(FILENAME, ATTR_NORMAL);
            if((File = TAP_Hdd_Fopen(FILENAME)) != NULL)
            {
                TAP_Hdd_Fseek(File, 0, SEEK_END);
                TAP_Hdd_Fwrite(TimeResult, strlen(TimeResult), 1, File);
                TAP_Hdd_Fwrite(ISOText, strlen(ISOText), 1, File);
                TAP_Hdd_Fwrite(CRLF, 2, 1, File);
                TAP_Hdd_Fclose(File);
            }

            if(Console)
            {
                TAP_PrintNet("%s%s\n", TimeResult, ISOText);
            }

            TAP_MemFree(ISOText);
        }
        TAP_MemFree(s);
    }
    HDD_TAP_PopDir();

    TRACEEXIT();
}
int LogoManager_UpdateLIL(void)
{
  TRACEENTER();

  typedef struct
  {
    ulong64             ChannelID;
    char                Name[MAXLOGONAME+1];
  }tNewIDs;

  int                   nTvSvc, nRadioSvc;
  int                   i;
  TYPE_TapChInfo        chInfo;
  char                  s[255], LogoName[MAX_SvcName + 1];
  SYSTEM_TYPE           SystemType;
  tFlashSatTable        SatInfo;

  word                  SatPos;
  ulong64               ChannelID;
  tNewIDs              *NewIDs;
  int                   NewIDCount;

  SystemType = GetSystemType();

  HDD_TAP_PushDir();
  HDD_ChangeDir(LOGOROOT);

  TAP_Channel_GetTotalNum(&nTvSvc, &nRadioSvc);
  NewIDs = TAP_MemAlloc((nTvSvc + nRadioSvc) * sizeof(tNewIDs));
  NewIDCount = 0;

  INIOpenFile(LILNAME, NULL);

  for(i = 0; i < nTvSvc; i++)
  {
    TAP_Channel_GetInfo(SVC_TYPE_Tv, i, &chInfo);
    FlashSatTablesGetInfo(chInfo.satIdx, &SatInfo);

    switch(SystemType)
    {
      case ST_S:
      case ST_TMSS:
      {
        SatPos = SatInfo.SatPosition;
        break;
      }

      default:
        SatPos = 0;
        break;
    }

    ChannelID = LogoManager_CalculateChannelID(SatPos, chInfo.orgNetId, chInfo.tsId, chInfo.svcId);
    TAP_SPrint(s, "%16.16llx", ChannelID);
    if(!INIKeyExists(s))
    {
      NewIDs[NewIDCount].ChannelID = ChannelID;
      strcpy(NewIDs[NewIDCount].Name, LogoManager_ChannelNameToLogoName(chInfo.chName, LogoName, sizeof(LogoName)));
      if(NewIDs[NewIDCount].Name[0]) NewIDCount++;
    }
  }

  for(i = 0; i < nRadioSvc; i++)
  {
    TAP_Channel_GetInfo(SVC_TYPE_Radio, i, &chInfo);
    FlashSatTablesGetInfo(chInfo.satIdx, &SatInfo);

    switch(SystemType)
    {
      case ST_S:
      case ST_TMSS:
      {
        SatPos = SatInfo.SatPosition;
        break;
      }

      default:
        SatPos = 0;
        break;
    }

    ChannelID = LogoManager_CalculateChannelID(SatPos, chInfo.orgNetId, chInfo.tsId, chInfo.svcId);
    TAP_SPrint(s, "%16.16llx", ChannelID);
    if(!INIKeyExists(s))
    {
      NewIDs[NewIDCount].ChannelID = ChannelID;
      TAP_SPrint(NewIDs[NewIDCount].Name, "r_%s", LogoManager_ChannelNameToLogoName(chInfo.chName, LogoName, sizeof(LogoName)));
      if(NewIDs[NewIDCount].Name[0]) NewIDCount++;
    }
  }

  INICloseFile();

  if(NewIDCount > 0)
  {
    TYPE_File          *f;
    word                year;
    byte                month, day, weekDay;

    if(!TAP_Hdd_Exist(LILNAME)) TAP_Hdd_Create(LILNAME, ATTR_NORMAL);
    f = TAP_Hdd_Fopen(LILNAME);

    if(!f)
    {
      HDD_TAP_PopDir();
      if(LogoManager_CB) LogoManager_CB(-1, 3);

      TRACEEXIT();
      return -1;
    }

    TAP_Hdd_Fseek(f, 0, SEEK_END);
    TAP_ExtractMjd(Now(NULL) >> 16, &year, &month, &day, &weekDay);
    TAP_SPrint(s, "\n\n# Added %4.4d-%2.2d-%2.2d\n", year, month, day);
    TAP_Hdd_Fwrite(s, 1, strlen(s), f);

    for(i = 0; i < NewIDCount; i++)
    {
      TAP_SPrint(s, "%16.16llx=%s\n", NewIDs[i].ChannelID, NewIDs[i].Name);
      TAP_Hdd_Fwrite(s, 1, strlen(s), f);
    }
    TAP_Hdd_Fclose(f);
    if(LogoManager_CB) LogoManager_CB(5, NewIDCount);

  }
Beispiel #15
0
void tmInitialise(void)
{
	char tmBuffer[TM_FILE_BLOCK_SIZE];
	char hddBuffer[1];

	byte i;

	TYPE_File* fp;

	memset (tmBuffer, 0, TM_FILE_BLOCK_SIZE);

	if (!TAP_Hdd_Exist (TM_FILENAME))
	{
		TAP_Hdd_Create (TM_FILENAME, ATTR_NORMAL);

		if (fp = TAP_Hdd_Fopen (TM_FILENAME))
		{
			for (i = 0; i < TM_FILE_MAX_LENGTH / TM_FILE_BLOCK_SIZE; i++)
			{
				TAP_Hdd_Fwrite (tmBuffer, 1, TM_FILE_BLOCK_SIZE, fp);
			}

			TAP_Hdd_Fseek (fp, 0, 0);

			TAP_Hdd_Fwrite (TM_INFO, 1, sizeof(TM_INFO), fp);

			tmBufferOffset = sizeof(TM_INFO) - 1;

			tmNumberOfEvents = 0;

			TAP_Hdd_Fclose (fp);
		}
	}
	else
	{
		if (fp = TAP_Hdd_Fopen (TM_FILENAME))
		{
			tmBufferOffset = 0;
			tmExitFL = FALSE;

			while
			(
				(tmExitFL == FALSE)
				&&
				(tmBufferOffset < TM_FILE_MAX_LENGTH)
			)
			{
				TAP_Hdd_Fseek (fp, tmBufferOffset, 0);

				TAP_Hdd_Fread (hddBuffer, 1, 1, fp);

				if(hddBuffer[0] != 0)
				{
					tmBufferOffset++;

					if(hddBuffer[0] == 0x0A)
					{
						tmNumberOfEvents++;
					}
				}
				else
				{
					tmExitFL = TRUE;
				}
			}

			tmNumberOfEvents -= 2;

			TAP_Hdd_Fclose (fp);

			if (tmBufferOffset >= (TM_FILE_MAX_LENGTH - TM_EVENT_BUFFER_SIZE))
			{
				ShowMessageWin("Log File Full","Exiting!");

				TAP_Exit();

				return;
			}
		}
	}

	ShowMessageWin("Time Monitor Tap v1.0","Started");
}
void LogoManager_LogoCacheRebuild(void)
{
  TRACEENTER();

  char                  ID[4];
  dword                 Version;
  TYPE_File            *f, *fLogo;
  int                   i, j, k, NrFiles;
  TYPE_FolderEntry      FolderEntry;
  dword                 LogoIndex;
  byte                 *PixelData, *TempBuffer;
  dword                 BufferSize, CompressedSize;
  TYPE_GrData          *grData;
  int                   LogosConverted;
  char                  LogoPath[FBLIB_DIR_SIZE];

  if(LogoManager_CB) LogoManager_CB(2, -1);

  //Step 1: Kill the current cache
  HDD_TAP_PushDir();
  HDD_ChangeDir(LOGOROOT);
  TAP_Hdd_Delete(LOGOCACHE);

  //Step 2: iterate through all directories and count the number of logos
  LogoManager_NrLogos = 0;
  for(i = LGST_3pgstyle; i < LGST_NRITEMS; i++)
  {
    for(j = LGAR_43; j < LGAR_NRITEMS; j++)
    {
      if(HDD_ChangeDir(LogoManager_GetDirectory(i, j, LogoPath)))
      {
        NrFiles = TAP_Hdd_FindFirst(&FolderEntry, "qtl|qsl|ibl");
        for(k = 0; k < NrFiles; k++)
        {
          if(FolderEntry.attr == ATTR_NORMAL)
          {
            FixInvalidFileName(FolderEntry.name);
            LogoManager_NrLogos++;
          }
          TAP_Hdd_FindNext(&FolderEntry);
        }
      }
    }
  }
  if(LogoManager_CB) LogoManager_CB(3, LogoManager_NrLogos);


  //Step 3: build the basic cache file
  LogosConverted = 0;
  if(LogoManager_LogoData) TAP_MemFree(LogoManager_LogoData);
  LogoManager_LogoData = TAP_MemAlloc(LogoManager_NrLogos * sizeof(tLogoData));
  if(LogoManager_LogoData)
  {
    memset(LogoManager_LogoData, 0, LogoManager_NrLogos * sizeof(tLogoData));
    HDD_ChangeDir(LOGOROOT);
    if(!TAP_Hdd_Exist(LOGOCACHE)) TAP_Hdd_Create(LOGOCACHE, ATTR_NORMAL);
    f = TAP_Hdd_Fopen(LOGOCACHE);
    if(f)
    {
      strcpy(ID, LOGOCACHEID);
      Version = LOGOCACHEVERSION;

      TAP_Hdd_Fwrite(ID, 4, 1, f);
      TAP_Hdd_Fwrite(&Version, sizeof(dword), 1, f);
      TAP_Hdd_Fwrite(&LogoManager_NrLogos, sizeof(dword), 1, f);
      TAP_Hdd_Fwrite(LogoManager_LogoData, sizeof(tLogoData), LogoManager_NrLogos, f);

      //Step 4: iterate through all directories again, compress the data and save it to the cache
      LogoIndex = 0;
      for(i = LGST_3pgstyle; i < LGST_NRITEMS; i++)
      {
        for(j = LGAR_43; j < LGAR_NRITEMS; j++)
        {
          if(HDD_ChangeDir(LogoManager_GetDirectory(i, j, LogoPath)))
          {
            NrFiles = TAP_Hdd_FindFirst(&FolderEntry, "qtl|qsl|ibl");
            for(k = 0; k < NrFiles; k++)
            {
              if(LogoManager_CB) LogoManager_CB(2, LogosConverted * 100 / LogoManager_NrLogos);

              if(FolderEntry.attr == ATTR_NORMAL)
              {
                LogoManager_LogoData[LogoIndex].ChannelID = 0;
                strncpy(LogoManager_LogoData[LogoIndex].LogoName, FolderEntry.name, MAXLOGONAME);
                LogoManager_LogoData[LogoIndex].LogoName[MAXLOGONAME] = '\0';
                LogoManager_LogoData[LogoIndex].LogoName[strlen(LogoManager_LogoData[LogoIndex].LogoName) - 4] = '\0';
                LogoManager_LogoData[LogoIndex].Style  = i;

                if(StringEndsWith(FolderEntry.name, ".qtl")) LogoManager_LogoData[LogoIndex].Size = LGSZ_qtl;
                if(StringEndsWith(FolderEntry.name, ".qsl")) LogoManager_LogoData[LogoIndex].Size = LGSZ_qsl;
                if(StringEndsWith(FolderEntry.name, ".ibl")) LogoManager_LogoData[LogoIndex].Size = LGSZ_ibl;

                LogoManager_LogoData[LogoIndex].Aspect = j;
                LogoManager_LogoData[LogoIndex].grData = NULL;

                fLogo = TAP_Hdd_Fopen(FolderEntry.name);
                if(fLogo)
                {
                  BufferSize = TAP_Hdd_Flen(fLogo) - 8;
                  PixelData = TAP_MemAlloc(BufferSize + 8);
                  TempBuffer = TAP_MemAlloc(sizeof(TYPE_GrData) + BufferSize);
                  if(PixelData && TempBuffer)
                  {
                    TAP_Hdd_Fread(PixelData, BufferSize + 8, 1, fLogo);
                    CompressedSize = CompressTFD(&PixelData[8], BufferSize, &TempBuffer[sizeof(TYPE_GrData)], 0x0001, 0xffff, NULL);
                    TAP_Put16bit(&TempBuffer[sizeof(TYPE_GrData) + 0x0e], 0xffff);

                    grData = (TYPE_GrData*)TempBuffer;
                    grData->version        = 1;
                    grData->reserved       = 0;
                    grData->dataFormat     = OSD_1555;
                    grData->compessMethod  = COMPRESS_Tfp;
                    grData->data           = NULL;
                    grData->dataSize       = BufferSize;
                    grData->width          = TAP_Get32bit(&PixelData[0]);
                    grData->height         = TAP_Get32bit(&PixelData[4]);

                    LogoManager_LogoData[LogoIndex].CachePosition = TAP_Hdd_Ftell(f);
                    LogoManager_LogoData[LogoIndex].grDataSize    = sizeof(TYPE_GrData) + CompressedSize;
                    TAP_Hdd_Fwrite(grData, LogoManager_LogoData[LogoIndex].grDataSize, 1, f);
                    LogoIndex++;
                  }
                  if(PixelData) TAP_MemFree(PixelData);
                  if(TempBuffer) TAP_MemFree(TempBuffer);
                  TAP_Hdd_Fclose(fLogo);
                }
                else
                {
                  if(LogoManager_CB) LogoManager_CB(-1, 2);
                }
                LogosConverted++;
              }
              TAP_Hdd_FindNext(&FolderEntry);
            }
          }
        }
      }

      //Step 5: if the LIL exists, read and update the ChannelID of all Logos

      //Step 6: rewrite the cache structure to update all pointers
      TAP_Hdd_Fseek(f, sizeof(ID) + sizeof(dword) + sizeof(dword), SEEK_SET);
      TAP_Hdd_Fwrite(LogoManager_LogoData, sizeof(tLogoData), LogoManager_NrLogos, f);
      TAP_Hdd_Fclose(f);
    }
  }
  HDD_TAP_PopDir();
  if(LogoManager_CB) LogoManager_CB(4, 0);

  TRACEEXIT();
}