示例#1
0
void Settings_Load()
{
	TYPE_File* fp;
	bool validSettings = FALSE;

	TAP_Hdd_ChangeDir( ".." );
	TAP_Hdd_ChangeDir( ".." );
	TAP_Hdd_ChangeDir( "ProgramFiles" );
	TAP_Hdd_ChangeDir( "Settings" );

	if ( fp = TAP_Hdd_Fopen(settingsFile) )
	{
		int version = 0;
		TAP_Hdd_Fread( &version, 1, sizeof(version), fp );
		if ( version == INI_VERSION )
		{
			TAP_Hdd_Fread( &settings, 1, sizeof(settings), fp );
			validSettings = TRUE;
		}
		TAP_Hdd_Fclose( fp );
	}

	if ( !validSettings )
	{
		Settings_Reset();
		Settings_Save();
	}
}
示例#2
0
bool ReadConfigurationFile( void )
{
	TYPE_File *readFile = NULL;
	int	i = 0;
	dword	fileLength = 0;
	bool	schSaveIniFile = FALSE;

	GotoPath( SETTINGS_FOLDER );
	if ( ! TAP_Hdd_Exist( OPTIONS_FILENAME ) )
	{
		GotoTapDir();
		TAP_Hdd_ChangeDir( PROJECT_DIRECTORY );
		if ( ! TAP_Hdd_Exist( OPTIONS_FILENAME ) ) return FALSE;

		schSaveIniFile = TRUE;
	}
	
	readFile = TAP_Hdd_Fopen( OPTIONS_FILENAME );
	if ( readFile == NULL ) return FALSE;						// and we can open it ok

	dataBuffer_ini = TAP_MemAlloc( DATA_BUFFER_SIZE_ini );				// Read the data in one hit (quicker), then process from RAM
	memset( dataBuffer_ini, '\0', DATA_BUFFER_SIZE_ini );				// set the whole buffer to the string termination character (null)
	dataBufferPtr_ini = 0;

	fileLength = TAP_Hdd_Flen( readFile );						// how big is the file
	if ( fileLength > DATA_BUFFER_SIZE_ini  ) fileLength = DATA_BUFFER_SIZE_ini;	// ensure we don't overflow the buffer
	
	TAP_Hdd_Fread( dataBuffer_ini, fileLength, 1, readFile );			// grab all the data from the file

	TAP_Hdd_Fclose( readFile );

	if(SetConfigurationVariables() == FALSE)
	{
		TAP_MemFree( dataBuffer_ini );						// must return the memory back to the heap

		SaveConfigurationToFile();
	}
	else
	{
		TAP_MemFree( dataBuffer_ini );						// must return the memory back to the heap
	}

	if(schSaveIniFile == TRUE)
	{
		SaveConfigurationToFile();

		GotoTapDir();
		TAP_Hdd_ChangeDir( PROJECT_DIRECTORY );

		if ( TAP_Hdd_Exist( OPTIONS_FILENAME ) ) TAP_Hdd_Delete( OPTIONS_FILENAME );
	}

	return TRUE;
}
TYPE_File *HDD_FappendOpen (char *filename)
{
  TYPE_File *file;
  char buffer[512];
  dword pos, blks, i;
  char *end;

  InitTAPAPIFix();

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

  if ((file = TAP_Hdd_Fopen(filename)))
  {
    if (TAP_Hdd_Fseek(file, 0, SEEK_SET) != 0)
    {
      TAP_Hdd_Fclose(file);
      file = NULL;
    }
    else
    {
      pos = 0;

      do
      {
        memset(buffer, 0, sizeof(buffer));
        blks = TAP_Hdd_Fread(&buffer, sizeof(buffer), 1, file);

        for (i = 0, end = buffer; i < sizeof(buffer); i++)
          if (buffer[i] == '\0')
          {
            end = buffer + i;
            break;
          }

        if (i < sizeof(buffer)) break;
        else pos += sizeof(buffer);
      }
      while (blks == 1);

      pos += end - buffer;

      if (TAP_Hdd_Fseek(file, pos, SEEK_SET) != pos)
      {
        TAP_Hdd_Fclose(file);
        file = NULL;
      }
    }
  }

  return file;
}
bool StringDBLoadFromFile(tStringDB *StringDB, TYPE_File *f)
{
  TRACEENTER();

  dword                 l, p;

  if(!StringDB || !f)
  {
    TRACEEXIT();
    return FALSE;
  }

  TAP_MemFree(StringDB->DB);

  //DB Size
  TAP_Hdd_Fread(&l, sizeof(dword), 1, f);
  StringDB->DB = TAP_MemAlloc(l);

  if(!StringDB->DB)
  {
    StringDB->DBSize = 0;
    TAP_Hdd_Fclose(f);

    TRACEEXIT();
    return FALSE;
  }
  StringDB->DBSize = l;
  StringDB->DBEnd = l + StringDB->DB - 1;

  //Current pointer
  TAP_Hdd_Fread(&p, sizeof(dword), 1, f);
  StringDB->DBPtr = p + StringDB->DB;

  TAP_Hdd_Fread(StringDB->DB, 1, l, f);

  TRACEEXIT();
  return TRUE;
}
示例#5
0
//------------
//
void ReadLogoFile()
{
	TYPE_File	*logoFile;
	TYPE_logoArray *logoPointer;
	dword		dataSize;
	byte		*junkBuffer;
	char		channelName[CHANNEL_NAME_SIZE];
	int i; //+++

//	TAP_Hdd_ChangeDir("UK TAP Project");
	GotoPath( TAPIniDir );
	if ( ! TAP_Hdd_Exist( "logo.dat" ) ) return;						// check our logo file exits in the current directory
	
	logoFile = TAP_Hdd_Fopen( "logo.dat" );
	if ( logoFile == NULL ) return;										// and we can open it ok

    junkBuffer = TAP_MemAlloc(LOGO_DATA_SIZE);							// create a place to read in unwanted logos
	
	while ( TAP_Hdd_Ftell( logoFile ) < TAP_Hdd_Flen( logoFile ) )		// Keep reading logos until we reach the end of file
	{
		TAP_Hdd_Fread( channelName, CHANNEL_NAME_SIZE, 1, logoFile );	// read the channel name
		if ( findChannelPointer( channelName, &logoPointer ) )			// cross referece the array to find this entry
		{																// if the channel exists ->
			TAP_Hdd_Fread( logoPointer->logo, LOGO_DATA_SIZE, 1, logoFile );	// read the logo bitmap
			logoPointer->processedFlag = TRUE;							// mark this channel as having a logo in the cache
		}
		else
		{																// else channel doesn't appear in service list ->
			TAP_Hdd_Fread( junkBuffer, LOGO_DATA_SIZE, 1, logoFile );	// must read the logo, otherwise read pointer will get stuck
		}
	}

	TAP_Hdd_Fclose( logoFile );
//	TAP_Hdd_ChangeDir("..");											// return to original directory
	TAP_MemFree( junkBuffer );
}
void LogoManager_ProcessLILAdd(char *AddFileName)
{
  TRACEENTER();

  TYPE_File            *f;
  int                   fs;
  char                 *Text, Line[80];

  HDD_TAP_PushDir();
  HDD_ChangeDir(LOGOROOT);
  INIOpenFile(LILNAME, NULL);

  f = TAP_Hdd_Fopen(AddFileName);
  if(f)
  {
    fs = TAP_Hdd_Flen(f);
    Text = TAP_MemAlloc(fs+1);
    if(Text)
    {
      TAP_Hdd_Fread(Text, 1, fs, f);
      Text[fs] = '\0';

      while(*Text)
      {
        ExtractLine(Text, Line);
        if(Line[0] == '0' && Line[1] == 'x' && Line[18] == '=')
        {
          LowerCase(Line);
          Line[18] = '\0';
          INISetString(&Line[2], &Line[19]);
        }
      }
      TAP_MemFree(Text);
    }
    TAP_Hdd_Fclose(f);
  }

  INISaveFile(LILNAME, INILOCATION_AtCurrentDir, NULL);
  INICloseFile();
  HDD_TAP_PopDir();

  TRACEEXIT();
}
bool ReadDatFile( void )
{
	TYPE_File *readFile;
	int i;
	dword fileLength;

    appendToLogfile("ReadDatFile: Started.", INFO);

	GotoPath( TAPIniDir );
	if ( ! TAP_Hdd_Exist( PLAYDATA_FILENAME ) ) 
    {
         appendToLogfile("ReadDatFile: no PLAYDATA file found.", ERR);
         return FALSE;			// check the ini file exits in the current directory
    }     
	
	readFile = TAP_Hdd_Fopen( PLAYDATA_FILENAME );
	if ( readFile == NULL ) return FALSE;								// and we can open it ok

	playDataBuffer_ini = TAP_MemAlloc( PLAYBACKDATA_BUFFER_SIZE_ini );	// Read the data in one hit (quicker), then process from RAM
	memset( playDataBuffer_ini, '\0', PLAYBACKDATA_BUFFER_SIZE_ini );	// set the whole buffer to the string termination character (null)
	playDataBufferPtr_ini = 0;

	fileLength = TAP_Hdd_Flen( readFile );								// how big is the file
	if ( fileLength > PLAYBACKDATA_BUFFER_SIZE_ini  ) fileLength = PLAYBACKDATA_BUFFER_SIZE_ini;	// ensure we don't overflow the buffer
	
	TAP_Hdd_Fread( playDataBuffer_ini, fileLength, 1, readFile );			// grab all the data from the file

	TAP_Hdd_Fclose( readFile );

	SetDatVariables();

	TAP_MemFree( playDataBuffer_ini );										// must return the memory back to the heap

    appendToLogfile("ReadDatFile: Finished.", INFO);

	return TRUE;
}
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 AutoStartPage::PopulateList()
{
	m_taps.clear();

	// Get a list of TAPs in the current Auto Start
	TAP_Hdd_ChangeDir( autoStartPath );

	TYPE_File file;

	int index = 0;
	for ( dword totalEntry = TAP_Hdd_FindFirst( &file ); totalEntry > 0; )
	{
		if ( file.attr == ATTR_NORMAL )
		{
			char* ext = strrchr(file.name, '.');
			if ( ext )
			{
				// ensure we're only looking at .tap files
				++ext;
				bool enabled = stricmp( ext, "tap" ) == 0;
				if ( enabled || stricmp( ext, "nap" ) == 0 )
				{
					// that we can open
					TYPE_File* f = TAP_Hdd_Fopen( file.name );
					if ( f )
					{
						// read the TAP header
						tTAPHeader header;
						memset( &header, 0, sizeof(header) );
						TAP_Hdd_Fread( &header, sizeof(header), 1, f );
						TAP_Hdd_Fclose( f );
						// ensure that it's actually a TAP format file
						if ( strncmp( header.Signature, "TFAPMIPS", 8 ) == 0 )
						{
							m_taps.push_back(AutoStartTAP());
							AutoStartTAP& t = m_taps.back();
							// store the filename with the extension .tap in the order array
							*ext = 't';
							t.index = index;
							t.filename = file.name;
							t.enabled = enabled;
							t.id = header.TAPID;
							t.name = header.Name;
							// and generate the text that will be shown in the footer
							t.footer.format( "%s\n%s\n%s\n", header.Description, header.AuthorName, header.EtcStr );
							++index;
						}
					}
				}
			}
		}

		dword currentEntry = TAP_Hdd_FindNext( &file );
		if ( totalEntry == currentEntry || currentEntry == 0 )
			break;
	}

	// Remove the Loading message and redraw the window contents
	DiscardItems();
	for (unsigned int i=0; i < m_taps.size(); ++i)
		AddItem(new TAPListItem(this, i));
	AddItem(new FooterActionListItem(this, &Commit, "Press OK to save the new TAP order\nTAPs will be loaded in this order next time the unit wakes from standby", 0, "", "Save Changes"));
	AddItem(new FooterActionListItem(this, &Backup, "Press OK to backup the TAP order and enabled state as listed above", 0, "", "Backup"));
	AddItem(new FooterActionListItem(this, &Restore, "Press OK to restore the previous backup to the list above\nThis does not save changes to disk", 0, "", "Restore"));

	Draw();
}
示例#10
0
TYPE_File *HDD_FappendOpen(char *FileName)
{
  TRACEENTER();

  TYPE_File            *file;
  char                  buffer[512];
  dword                 pos, blks, i;
  char                 *end;
  char                  TAPPath[FBLIB_DIR_SIZE], Name[FBLIB_DIR_SIZE];

  if(!FileName || !*FileName)
  {
    TRACEEXIT();
    return NULL;
  }

  ConvertPathType(FileName, TAPPath, PF_TAPPathOnly);
  ConvertPathType(FileName, Name, PF_FileNameOnly);

  HDD_TAP_PushDir();
  if(*TAPPath) HDD_ChangeDir(TAPPath);

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

  if((file = TAP_Hdd_Fopen(Name)))
  {
    if(TAP_Hdd_Fseek(file, 0, SEEK_SET) != 0)
    {
      TAP_Hdd_Fclose(file);
      file = NULL;
    }
    else
    {
      pos = 0;

      do
      {
        memset(buffer, 0, sizeof(buffer));
        blks = TAP_Hdd_Fread(&buffer, sizeof(buffer), 1, file);

        for(i = 0, end = buffer; i < sizeof(buffer); i++)
          if(buffer[i] == '\0')
          {
            end = buffer + i;
            break;
          }

        if(i < sizeof(buffer)) break;
        else pos += sizeof(buffer);
      }
      while(blks == 1);

      pos += end - buffer;

      if(TAP_Hdd_Fseek(file, pos, SEEK_SET) != pos)
      {
        TAP_Hdd_Fclose(file);
        file = NULL;
      }
    }
  }

  HDD_TAP_PopDir();

  TRACEEXIT();
  return file;
}
示例#11
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();
}