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();
}
Example #2
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");
}
Example #3
0
/*
returns a pointer to the open file. A null pointer value indicates an error
The character string mode specifies the type of access requested for the file, as follows: 
"r" 
Opens for reading. If the file does not exist or cannot be found, the fopen call fails. 
"w" 
Opens an empty file for writing. If the given file exists, its contents are destroyed. 
*/
UFILE* fopen(char* name, char* mode)
{
#ifdef _WIN32
	int fd;
#else
	TYPE_File *fd;
#endif
	UFILE *fp;

	//printf("Opening file %s for %c\n", name, *mode);
	//dumpBuffer();

	if (*mode != 'r' && *mode != 'w' && *mode != 'a') {
		return NULL;
	}
	for (fp = _iob; fp < _iob + OPEN_MAX; fp++)
		if ((fp->flag & (_READ | _WRITE)) == 0)
			break;		/* found free slot */
	if (fp >= _iob + OPEN_MAX) {	/* no free slots */
		return NULL;
	}

#ifdef _WIN32
	if (*mode == 'w')
		fd = creat(name, 0666);
	else if (*mode == 'a') {
		if ((fd = open(name, O_WRONLY, 0)) == -1)
			fd = creat(name, 0666);
		lseek(fd, 0L, 2L);
	} else
		fd = open(name, O_RDONLY, 0);
	if (fd == -1) {
		return NULL;
	}
#else
	if (*mode == 'w')
		TAP_Hdd_Create(name, ATTR_NORMAL);   //TAP_Hdd_Delete(name);
	else if (*mode == 'a')
		if (!TAP_Hdd_Exist(name))
			TAP_Hdd_Create(name, ATTR_NORMAL);

	fd = TAP_Hdd_Fopen( name );
	if (fd == 0) {	/* couldn't access name */
		return NULL;
	}
	if (*mode == 'a')
		TAP_Hdd_Fseek(fd, 0L, 2L);
#endif
	fp->fd = fd;
	fp->cnt = 0;
	fp->size = 0;
	fp->base = NULL;
	fp->flag = (*mode == 'r') ? _READ : _WRITE;
#ifdef _TAP
	fp->size = TAP_Hdd_Flen(fd);
	//TAP_Print("file size: %d\r\n", fp->size);
	//fp->flag |= _UNBUF;	//
#endif
	//dumpBuffer();
	return fp;
}