Esempio n. 1
0
char* FindTapDir()
{
	TYPE_File	fp;

	if ( _tapDirPtr != NULL )
		return _tapDirPtr;

	TAP_Hdd_ChangeDir("..");
	TAP_Hdd_FindFirst( &fp );

	// TAP_Print("Tapdir: fp.name = %s\r\n", fp.name);

	if ( strcmp( fp.name, "__ROOT__" ) == 0 )
	{
		strcpy(_tapDir, "/ProgramFiles");
		TAP_Hdd_ChangeDir("ProgramFiles");
	} else {
		strcpy(_tapDir, "/ProgramFiles/Auto Start");
		TAP_Hdd_ChangeDir("Auto Start");
	}

	_tapDirPtr = _tapDir;
	// TAP_Print("Tapdir: _tapDirPtr = %s\r\n", _tapDirPtr);

	return _tapDirPtr;	
}
Esempio n. 2
0
//------------------------------ ChangeDirRoot --------------------------------------
//
void	ChangeDirRoot()
{
	TYPE_File	fp;
	int		iNdx;

	iNdx = 0;
	TAP_Hdd_FindFirst( &fp );

    //	Loop until Root found allow maximum of 20 levels

	while ( ( strcmp( fp.name, "__ROOT__" ) != 0 ) && ( iNdx < 20 ) )
	{
		TAP_Hdd_ChangeDir( ".." );
		TAP_Hdd_FindFirst( &fp );
	}

}
Esempio n. 3
0
bool CurrentDirStartCluster (dword* cluster)
{
    TYPE_File file;

    // '.' should be the first entry, so find it
    memset (&file, 0, sizeof (file));
    if (TAP_Hdd_FindFirst (&file))
    {
       while (strcmp (file.name, ".") && TAP_Hdd_FindNext (&file)) {};
    }

    // return starting cluster of this directory
    *cluster = file.startCluster;

    return (strcmp (file.name, ".") == 0);
}
Esempio n. 4
0
void schMoveService(void)
{
	char	logBuffer[LOG_BUFFER_SIZE];
	char	fileStr[200];
	char	folderStr[200];
	static	char	schMoveActualFileName[128];
	static	char	schMoveNewFileName[128];
	int	fileNumber = 0;
	char	fileNumberStr[10];
	int	totalFileCount = 0, i = 0;
	TYPE_PlayInfo	CurrentPlaybackInfo;
	char	playInfoOverRun[512];
	TYPE_RecInfo	CurrentRecordInfo0;
	char	rec0InfoOverRun[512];
	TYPE_RecInfo	CurrentRecordInfo1;
	char	rec1InfoOverRun[512];
	char	CurrentPlaybackFileName[TS_FILE_NAME_SIZE];
	char	CurrentRecord0FileName[SCH_REC_FILE_NAME_SIZE];
	char	CurrentRecord1FileName[SCH_REC_FILE_NAME_SIZE];
	bool	schFileFound = FALSE;
	static	TYPE_File	tempFile;
	static	dword	schMoveCurrentTime = 0;
	static	byte	schMoveIndex = 0;
	static	bool	schMoveExpired = FALSE;
	static	bool	schMoveSuccessful = FALSE;
	static	bool	moveFailed = FALSE;
	int	result = 0;
	bool	schMoveResult = FALSE;
	dword	moveStartTimeInMins = 0, fileStartTimeInMins = 0;

	char	buffer1[256];

	switch(schMoveServiceSV)
	{
	/*--------------------------------------------------*/
	case SCH_MOVE_SERVICE_INITIALISE:

		if(schFileRetreiveMoveData() > 0)
		{
		}
		else
		{
		}

		schMoveServiceSV = SCH_MOVE_SERVICE_WAIT_TO_CHECK;

		break;
	/*--------------------------------------------------*/
	case SCH_MOVE_SERVICE_WAIT_TO_CHECK:

		if
		(
			(schTimeSec == 40)
			&&
			(schMainTotalValidMoves > 0)
			&&
			(schStartUpCounter > SCH_MAIN_DELAY_MOVE_ALARM)
			&&
			(schKeepServiceSV == SCH_KEEP_SERVICE_WAIT_TO_CHECK)
		)
		{

			schMoveIndex = schMainTotalValidMoves - 1;

			schMoveCurrentTime = (schTimeMjd << 16) + (schTimeHour << 8) + schTimeMin;

			schMoveExpired = FALSE;

			moveFailed = FALSE;

			schMoveServiceSV = SCH_MOVE_SERVICE_CHECK_MOVE;
		}

		break;
	/*--------------------------------------------------*/
	case SCH_MOVE_SERVICE_CHECK_MOVE:

		if (schMoveCurrentTime >= schMoveData[schMoveIndex].moveEndTime)
		{
			schMoveSuccessful = FALSE;

			schMoveServiceSV = SCH_MOVE_SERVICE_CHECK_ARCHIVE;
		}
		else
		{
			schMoveServiceSV = SCH_MOVE_SERVICE_NEXT_MOVE;
		}

		break;
	/*--------------------------------------------------*/
	case SCH_MOVE_SERVICE_CHECK_ARCHIVE:

		memset(schMoveActualFileName, 0 , sizeof(schMoveActualFileName));

		if(GotoDataFiles() == TRUE)
		{
			moveStartTimeInMins = schMainConvertTimeToMins(schMoveData[schMoveIndex].moveStartTime);

			totalFileCount = TAP_Hdd_FindFirst(&tempFile); 

			schFileFound = FALSE;
			for ( i=1; ((i <= totalFileCount) && (schFileFound == FALSE)) ; i++ )
			{
				fileStartTimeInMins = (tempFile.mjd * 24 * 60) + (tempFile.hour * 60) + tempFile.min;

				if
				(
					((moveStartTimeInMins - 1) <= fileStartTimeInMins)
					&&
					(tempFile.attr == ATTR_TS)
					&&
					(strlen(schMoveData[schMoveIndex].moveFileName) > 4)
					&&
					(strncmp(tempFile.name, schMoveData[schMoveIndex].moveFileName, (strlen(schMoveData[schMoveIndex].moveFileName) - 4)) == 0)
				)
				{
					strcpy(schMoveActualFileName, tempFile.name);

					schFileFound = TRUE;			
				}
				else
				{
					TAP_Hdd_FindNext(&tempFile);
				}
			}

			if(schFileFound == TRUE)
			{
				schMoveServiceSV = SCH_MOVE_SERVICE_CHECK_TARGET_FOLDER;
			}
			else
			{
				schMoveServiceSV = SCH_MOVE_SERVICE_MOVE_NOT_SUCCESSFUL;
			}
		}
		else
		{
			schMoveServiceSV = SCH_MOVE_SERVICE_MOVE_NOT_SUCCESSFUL;
		}

		break;
	/*--------------------------------------------------*/
	case SCH_MOVE_SERVICE_CHECK_TARGET_FOLDER:

		memset(schMoveNewFileName, 0 , sizeof(schMoveNewFileName));

		sprintf( folderStr, "DataFiles/%s", schMoveData[schMoveIndex].moveFolder );
		if(GotoPath(folderStr) == TRUE)
		{
			if (TAP_Hdd_Exist( schMoveActualFileName ) == FALSE)
			{
				schMoveServiceSV = SCH_MOVE_SERVICE_PERFORM_MOVE;
			}
			else
			{
				fileNumber = 2;

				sprintf(fileNumberStr, "-%d", fileNumber);

				if(strlen(schMoveActualFileName) > 4)
				{
					strncpy(schMoveNewFileName, schMoveActualFileName,(strlen(schMoveActualFileName) - 4));
					strcat(schMoveNewFileName, fileNumberStr);
					strcat(schMoveNewFileName, ".rec");
			
					while
					(
						(TAP_Hdd_Exist( schMoveNewFileName ) == TRUE)
						&&
						(fileNumber < 100)
					)
					{
						fileNumber++;

						memset(fileNumberStr, 0 , sizeof(fileNumberStr));
						sprintf(fileNumberStr, "-%d", fileNumber);
						
						memset(schMoveNewFileName, 0 , sizeof(schMoveNewFileName));
						strncpy(schMoveNewFileName, schMoveActualFileName,(strlen(schMoveActualFileName) - 4));
						strcat(schMoveNewFileName, fileNumberStr);
						strcat(schMoveNewFileName, ".rec");
					}
				}
				else
				{
					fileNumber = 100;
				}

				if(fileNumber < 100)
				{
					schMoveServiceSV = SCH_MOVE_SERVICE_PERFORM_MOVE;
				}
				else
				{
					schMoveServiceSV = SCH_MOVE_SERVICE_MOVE_NOT_SUCCESSFUL;
				}
			}
		}
		else
		{
			schMoveServiceSV = SCH_MOVE_SERVICE_MOVE_NOT_SUCCESSFUL;
		}

		break;
	/*--------------------------------------------------*/
	case SCH_MOVE_SERVICE_PERFORM_MOVE:

		schMoveSuccessful = FALSE;

		if(GotoDataFiles() == TRUE)
		{
			TAP_Hdd_GetPlayInfo (&CurrentPlaybackInfo);
			TAP_Hdd_GetRecInfo (0, &CurrentRecordInfo0);
			TAP_Hdd_GetRecInfo (1, &CurrentRecordInfo1);

			memset(CurrentPlaybackFileName,0,TS_FILE_NAME_SIZE);
			if(CurrentPlaybackInfo.playMode == PLAYMODE_Playing)
			{
				strcpy(CurrentPlaybackFileName,CurrentPlaybackInfo.file->name);
			}

			memset(CurrentRecord0FileName,0,SCH_REC_FILE_NAME_SIZE);
			if
			(
				(CurrentRecordInfo0.recType == RECTYPE_Normal)
				&&
				(schMoveData[schMoveIndex].moveStartTime == CurrentRecordInfo0.startTime)
			)
			{
				strcpy(CurrentRecord0FileName,CurrentRecordInfo0.fileName);
			}

			memset(CurrentRecord1FileName,0,SCH_REC_FILE_NAME_SIZE);
			if
			(
				(CurrentRecordInfo1.recType == RECTYPE_Normal)
				&&
				(schMoveData[schMoveIndex].moveStartTime == CurrentRecordInfo1.startTime)
			)
			{
				strcpy(CurrentRecord1FileName,CurrentRecordInfo1.fileName);
			}

			if
			(
				(strcmp(CurrentPlaybackFileName, schMoveActualFileName) != 0)
				&&
				(strcmp(CurrentRecord0FileName, schMoveActualFileName) != 0)
				&&
				(strcmp(CurrentRecord1FileName, schMoveActualFileName) != 0)
			)
			{
				if(strlen(schMoveNewFileName) > 0)
				{
					if(TAP_Hdd_Rename(schMoveActualFileName, schMoveNewFileName) == TRUE)
					{
						memset(schMoveActualFileName, 0 , sizeof(schMoveActualFileName));
						strcpy(schMoveActualFileName, schMoveNewFileName);
					}
				}

				sprintf( folderStr, "/DataFiles/%s", schMoveData[schMoveIndex].moveFolder );
#ifndef WIN32
				if(schMainApiMoveAvailable == TRUE)
				{
					schMoveResult = TAP_Hdd_ApiMove( "/DataFiles", folderStr, schMoveActualFileName );
				}
				else if(schMainDebugMoveAvailable == TRUE)
				{
					sprintf( fileStr, "/DataFiles/%s", schMoveActualFileName );

					schMoveResult = TAP_Hdd_DebugMove( fileStr, folderStr );
				}
				else
				{
				}

#else
				schMoveResult = TRUE;	// For the SDK
#endif
				if(schMoveResult == TRUE)
				{
					schMoveSuccessful = TRUE;

					schMoveData[schMoveIndex].moveEnabled = FALSE;

					schMoveExpired = TRUE;				// Delete this move when all moves checked
				}
			}
		}

		if(schMoveSuccessful == TRUE)
		{
			schMoveServiceSV = SCH_MOVE_SERVICE_NEXT_MOVE;
		}
		else
		{
			schMoveServiceSV = SCH_MOVE_SERVICE_MOVE_NOT_SUCCESSFUL;
		}

		break;
	/*--------------------------------------------------*/
	case SCH_MOVE_SERVICE_MOVE_NOT_SUCCESSFUL:

		schMoveData[schMoveIndex].moveFailedCount++;

		if(schMoveData[schMoveIndex].moveFailedCount >= 3)
		{
			schMoveData[schMoveIndex].moveEnabled = FALSE;

			schMoveExpired = TRUE;				// Delete this move when all moves checked

			moveFailed = TRUE;

//			memset(logBuffer,0,LOG_BUFFER_SIZE);
//			sprintf( logBuffer, "Failed (Move to be deleted): %s    Count: %d", schMoveData[schMoveIndex].moveFileName, schMoveData[schMoveIndex].moveFailedCount  );
//			logStoreEvent(logBuffer);		
		}
		else
		{
//			memset(logBuffer,0,LOG_BUFFER_SIZE);
//			sprintf( logBuffer, "Failed: %s    Count: %d", schMoveData[schMoveIndex].moveFileName, schMoveData[schMoveIndex].moveFailedCount  );
//			logStoreEvent(logBuffer);		
		}

		schMoveServiceSV = SCH_MOVE_SERVICE_NEXT_MOVE;

		break;
	/*--------------------------------------------------*/
	case SCH_MOVE_SERVICE_NEXT_MOVE:

		if(schMoveIndex > 0)
		{
			schMoveIndex--;

			schMoveServiceSV = SCH_MOVE_SERVICE_CHECK_MOVE;
		}
		else
		{
			if(schMoveExpired == TRUE)
			{
				schMoveServiceSV = SCH_MOVE_SERVICE_DELETE_EXPIRED_MOVES;
			}
			else
			{
				schMoveServiceSV = SCH_MOVE_SERVICE_COMPLETE;
			}
		}

		break;
	/*--------------------------------------------------*/
	case SCH_MOVE_SERVICE_DELETE_EXPIRED_MOVES:

		schWriteMoveList();

//		memset(logBuffer,0,LOG_BUFFER_SIZE);
//		sprintf( logBuffer, "Move list updated" );
//		logStoreEvent(logBuffer);		

		if (moveFailed == FALSE)
		{
			schMoveServiceSV = SCH_MOVE_SERVICE_COMPLETE;
		}
		else
		{
			schMoveServiceSV = SCH_MOVE_LOG_ARCHIVE;
		}

		break;
	/*--------------------------------------------------*/
	case SCH_MOVE_LOG_ARCHIVE:

		logArchive();

		schMoveServiceSV = SCH_MOVE_SERVICE_COMPLETE;

		break;
	/*--------------------------------------------------*/
	case SCH_MOVE_SERVICE_COMPLETE:

		if(schTimeSec != 40)
		{
			schMoveServiceSV = SCH_MOVE_SERVICE_WAIT_TO_CHECK;
		}

		break;
	/*--------------------------------------------------*/
	default:

		break;
	/*--------------------------------------------------*/
	}
}
Esempio n. 5
0
void AutoStartPage::Save()
{
	if ( m_taps.size() == 0 )
	{
		MessageBox::Show( messageBoxTitle, "No TAPs are installed in Auto Start", "OK" );
		return;
	}

	// Set current directory to ProgramFiles
	if ( !TAP_Hdd_ChangeDir( programFilesPath ) )
	{
		MessageBox::Show( messageBoxTitle, "ProgramFiles directory could not be found", "OK" );
		return;
	}

	// display a progress box
	ProgressBox progress( "Please wait", "Reordering Auto Start TAPs" );
	progress.OnOpen();

	string errors;
	string warnings;

	bool reorder = false;
	// Get the current filenames of each of the TAPs
	if ( !TAP_Hdd_ChangeDir( autoStartPath ) )
	{
		progress.OnClose();
		MessageBox::Show("Reorder TAPs", "Failed to find Auto Start folder", "OK");
		return;
	}
	for ( unsigned int i = 0; i < m_taps.size(); ++i )
	{
		if ( m_taps[i].index != i )
			reorder = true;
		if ( !TAP_Hdd_Exist( (char*)m_taps[i].filename.c_str() ) )
		{
			int extOffset = m_taps[i].filename.size()-3;
			if ( extOffset > 0)
			{
				m_taps[i].filename[extOffset] = m_taps[i].filename[extOffset] == 't' ? 'n' : 't';
			}
		}
	}

	if (reorder)
	{
		TAP_Hdd_ChangeDir("..");
		// Create a temporary Auto Start and move all TAPs there
		TAP_Hdd_Create( tempAutoStartName, ATTR_FOLDER );
		if ( !TAP_Hdd_ChangeDir( tempAutoStartName ) )
		{
			progress.OnClose();
			MessageBox::Show( messageBoxTitle, "Failed to create Temp Auto Start folder", "OK");
			return;
		}
		// Move the TAPs to the Temporary Auto Start directory
		short int stepSize = 50/m_taps.size();
		for ( unsigned int i = 0; i < m_taps.size(); ++i )
		{
			TRACE1("Moving %s\n",(char*)m_taps[i].filename.c_str());
			progress.StepProgress( stepSize, "Preparing " + m_taps[i].name );
			HDD_Move( (char*)m_taps[i].filename.c_str(), "/ProgramFiles/Auto Start", "/ProgramFiles/Temp Auto Start" );
			if ( !TAP_Hdd_Exist( (char*)m_taps[i].filename.c_str() ) )
			{
				// TAP wasn't moved, flag the failure and
				if ( warnings.size() > 0 )
					warnings += ", ";
				warnings += m_taps[i].name;
				m_taps[i].spare = false;
				progress.StepProgress( stepSize );
			}
			else
				m_taps[i].spare = true;
		}
		TRACE("Done moving\n");

		// Now move them back into Auto Start in the order the user has requested
		if ( !TAP_Hdd_ChangeDir( "/ProgramFiles/Auto Start" ) )
		{
			progress.OnClose();
			MessageBox::Show("Reorder TAPs", "Failed to find Auto Start folder", "OK");
			return;
		}
		int count = 0;
		for ( unsigned int i = 0; i < m_taps.size(); ++i )
		{
			if ( m_taps[i].spare )
			{
				TRACE1("Moving TAP %s\n",(char*)m_taps[i].filename.c_str());
				progress.StepProgress( stepSize, "Reordering " + m_taps[i].name );
				HDD_Move((char*)m_taps[i].filename.c_str(), "/ProgramFiles/Temp Auto Start", "/ProgramFiles/Auto Start");
				if ( !TAP_Hdd_Exist( (char*)m_taps[i].filename.c_str() ) )
				{
					if ( errors.size() > 0 )
						errors += ", ";
					errors += m_taps[i].name;
				}
				++count;
			}
		}
	}

	// Finally, deal with enabled and disabled
	for ( unsigned int i = 0; i < m_taps.size(); ++i )
	{
		int extOffset = m_taps[i].filename.size()-3;
		string tapName = m_taps[i].filename;
		tapName[extOffset] = 't';
		string napName = m_taps[i].filename;
		napName[extOffset] = 'n';
		if ( m_taps[i].enabled )
		{
			// ensure TAP is enabled
			if ( TAP_Hdd_Exist( (char*)tapName.c_str() ) )
				TAP_Hdd_Delete( (char*)napName.c_str() );
			else
				TAP_Hdd_Rename( (char*)napName.c_str(), (char*)tapName.c_str() );
		}
		else
		{
			// ensure TAP is disabled
			if ( TAP_Hdd_Exist( (char*)tapName.c_str() ) )
			{
				TAP_Hdd_Delete( (char*)napName.c_str() );
				TAP_Hdd_Rename( (char*)tapName.c_str(), (char*)napName.c_str() );
			}
		}
	}

	// Delete Temp Auto Start if the directory is empty
	if ( TAP_Hdd_ChangeDir( "/ProgramFiles/Temp Auto Start" ) )
	{
		TYPE_File file;
		dword totalEntry = TAP_Hdd_FindFirst( &file );
		while ( totalEntry-- )
		{
			// ignore ., .. and deleted files
			if ( file.attr != ATTR_PARENTFOLDER && file.attr != ATTR_THISFOLDER && file.attr != ATTR_DELETEDFILE )
				break;
			if ( totalEntry==0 || TAP_Hdd_FindNext( &file ) == 0 )
			{
				TAP_Hdd_ChangeDir("..");
				TAP_Hdd_Delete( tempAutoStartName );
				break;
			}
		}
	}

	progress.OnClose();

	// report any errors
	if ( errors.size() || warnings.size() )
	{
		if ( errors.size() > 0 )
			MessageBox::Show("Reorder TAPs", "The following TAPs could not be reordered:\n" + errors + "Check the Temp Auto Start folder", "OK");
		else if ( warnings.size() > 0 )
			MessageBox::Show("Reorder TAPs", "The following TAPs could not be reordered:\n" + warnings, "OK");
	}
	else
	{
		if ( MessageBox::Show("Reorder TAPs", "Finished", HDD_isAnyRecording() ? "OK" : "OK\nReboot" ) == 2 )
			Reboot(false);
	}
}
Esempio n. 6
0
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();
}
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();
}
Esempio n. 8
0
char* GetCurrentDir(void)
{
    dword cluster;
    char* path;
    TYPE_File file;
    char* temp;
                    
    appendToLogfile("GetCurrentDir: started.");

    path = TAP_MemAlloc (2);

    if (path == NULL) 
    {
             appendToLogfile("GetCurrentDir: TAP_MemAlloc (2) failed.");
             return NULL;
    }         
    appendToLogfile("GetCurrentDir: after memalloc.");

    strcpy (path, "");
    path[0]='\0';

    // while we have a '.' entry we work up the tree matching starting clusters
    while (CurrentDirStartCluster (&cluster))
    {
//        TYPE_File file;
        // move into parent directory and look for a starting cluster match
        TAP_Hdd_ChangeDir ("..");
        memset (&file, 0, sizeof (file));
        if (TAP_Hdd_FindFirst (&file))
        {
            while ((cluster != file.startCluster) && TAP_Hdd_FindNext (&file)) {};
        }
        // if we have a match prepend it to the path
        if (cluster == file.startCluster)
        {
//            char* temp;

            temp = TAP_MemAlloc (strlen (path) + strlen (file.name) + 2);

            // no memory - back to starting directory and return NULL
            if (temp == NULL)
            {
                appendToLogfile("GetCurrentDir: TAP_MemAlloc (strlen path) failed.");
                TAP_Hdd_ChangeDir (file.name);
                if (strlen (path)) TAP_Hdd_ChangeDir (&path[1]);
                TAP_MemFree (path);
                return NULL;
            }

            appendStringToLogfile("GetCurrentDir: Match on file=%s",file.name);

            // There's an issue where we may find the "." directory entry instead of the subdir -
            // so for now, let's ignore it.   5 Nov 2005
            if (strcmp(file.name,".")!=0)
            {
               strcpy (temp, "/");
               strcat (temp, file.name);
               strcat (temp, path);
               TAP_MemFree (path);
               path = temp;
               appendStringToLogfile("GetCurrentDir: Path now=%s",path);
            }
        }
        else
        {
            // directory structure inconsistent, shouldn't get here
            // problem - we can't get back to our starting directory
            TAP_MemFree (path);
            appendStringToLogfile("GetCurrentDir: Bombed out.",file.name);
            return NULL;
        }
    }
    if (strlen (path))
    {
        // finally we put ourselves back in our starting directory
        //TAP_Hdd_ChangeDir (&path[1]);
        appendToLogfile("GetCurrentDir: Found current directory.");
        appendStringToLogfile("GetCurrentDir: It's %s.",path);
        GotoPath(path);
    }
    else
    {
        // We're at the root
        strcpy (path, "/");
        appendStringToLogfile("GetCurrentDir: Found at ROOT.",file.name);
    }

    return (path);
}