示例#1
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 );
	}
}
示例#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;
}
示例#3
0
INILOCATION INILocateFile(char *FileName, char *AppName)
{
  TRACEENTER();

  INILOCATION           location = INILOCATION_NotFound;
  char                  dir[200] = "";

  if(FileName)
  {
    //Current directory?
    if(TAP_Hdd_Exist(FileName)) location = INILOCATION_AtCurrentDir;
    //Else search (which automatically activates tapapifix)
    else
    {
      HDD_TAP_GetCurrentDir(dir);

      if(HDD_ChangeDir("/ProgramFiles"))
      {
        //Try /ProgramFiles
        if(TAP_Hdd_Exist(FileName))
        {
          location = INILOCATION_AtProgramFiles;
          strcpy(dir, "/ProgramFiles");
        }

        if(HDD_ChangeDir("Settings"))
        {
          //Try /ProgramFiles/Settings
          if(TAP_Hdd_Exist(FileName))
          {
            location = INILOCATION_AtSettings;
            strcpy(dir, "/ProgramFiles/Settings");
          }

          //Try /ProgramFiles/Settings/<AppName>
          if(AppName && *AppName && (*AppName != '/') && HDD_ChangeDir(AppName) && TAP_Hdd_Exist(FileName))
          {
            location = INILOCATION_AtAppName;
            dir[0] = '\0';
          }
        }
      }
    }
  }

  //Restore the directory where the file has been found
  if(*dir) HDD_ChangeDir(dir);

  TRACEEXIT();
  return location;
}
示例#4
0
void CreateRootDir(void)
{
  TRACEENTER();

  //Check & Create Folders
  HDD_TAP_PushDir();
  HDD_ChangeDir("/ProgramFiles");
  if(!TAP_Hdd_Exist("Settings")) TAP_Hdd_Create("Settings", ATTR_FOLDER);
  HDD_ChangeDir("Settings");
  if(!TAP_Hdd_Exist("SDS")) TAP_Hdd_Create("SDS", ATTR_FOLDER);
  HDD_TAP_PopDir();

  TRACEEXIT();
}
//----------------
//
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);
}
示例#6
0
//-----------------------------------------------------------------------
//
void PerformMove(void)
{
     bool moveres;
          
     appendToLogfile("PerformMove: Started.", INFO);
     
     // Call the move routine and track the result code.
     #ifdef WIN32
            moveres = TRUE;
     #else
            appendToLogfile("PerformMove: Calling TAP_Hdd_Move", WARNING);
            appendStringToLogfile("PerformMove: Calling TAP_Hdd_Move GlbSourceDir: %s",GlbSourceDir, WARNING);
            appendStringToLogfile("PerformMove: Calling TAP_Hdd_Move GlbTargetDir: %s",GlbTargetDir, WARNING);
            appendStringToLogfile("PerformMove: Calling TAP_Hdd_Move GlbSourceFile: %s",GlbSourceFile, WARNING);
            moveres = TAP_Hdd_Move( GlbSourceDir, GlbTargetDir, GlbSourceFile);
            appendToLogfile("PerformMove: TAP_Hdd_Move finished.", WARNING);
     #endif


     // Check and handle the result of the move routine.
     // Check the file actually moved via file exists.
     #ifdef WIN32  // If testing on Windows platform, assume success rather than physically deleting file.
     if (FALSE)
     #else  
     appendToLogfile("PerformMove: Calling TAP_Hdd_Exist", WARNING);
     if (TAP_Hdd_Exist(GlbSourceFile))  // If the file/folder still exists in the current directory, then the move didn't work.
     #endif
     {
         ShowMessageWin( rgn, "File/Folder Move Failed.", "Failed to move file/folder:", GlbSourceFile, 400 );
         fileMoved = FALSE;
     }
     else
     {
         fileMoved = TRUE;
         myfiles[CurrentDirNumber][chosenLine]->isNew = FALSE;   // Clear the 'new' flag for this file.
     }    
     returnFromMove = TRUE;   // Force a closer of the Move window, and refresh the list.
     
/*     
     ShowMessageWin( rgn, "Move Test #1.", "Moving Test.rec", "to MINE folder", 400 );
     moveres = TAP_Hdd_Move( "DataFiles", "DataFiles/Mine", "Test.rec");
   
     ShowMessageWin( rgn, "Move Test #2.", "Moving MINE folder", "to MINE2 folder", 400 );
     moveres = TAP_Hdd_Move( "DataFiles", "DataFiles/Mine2", "Mine");
     
     ShowMessageWin( rgn, "Move Test #3.", "Moving Test2.rec", "to .. folder", 400 );
     moveres = TAP_Hdd_Move( "DataFiles/Mine2", "DataFiles/Mine2/..", "Test2.rec");
*/   
     appendToLogfile("PerformMove: Finished.", WARNING);
     
}     
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;
}
示例#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 );
}
char *LogoManager_GetPathToLogoByChannelID(ulong64 ChannelID, tLogoStyle LogoStyle, tLogoSize LogoSize, tLogoAspect LogoAR, char *LogoPath)
{
  TRACEENTER();

  char                  s[20], LP[FBLIB_DIR_SIZE];

  if(LogoPath)
  {
    LogoManager_Initialize(LogoManager_CB);

    TAP_SPrint(LogoPath, "%s/", LogoManager_GetDirectory(LogoStyle, LogoAR, LP));

    HDD_TAP_PushDir();
    HDD_ChangeDir(LOGOROOT);
    if(TAP_Hdd_Exist(LILNAME))
    {
      TAP_SPrint(s, "%16.16llx", ChannelID);
      INIOpenFile(LILNAME, NULL);
      INIGetString(s, &LogoPath[strlen(LogoPath)], "", 40);
      INICloseFile();
      HDD_TAP_PopDir();

      switch(LogoSize)
      {
        case LGSZ_qtl: strcat(LogoPath, ".qtl"); break;
        case LGSZ_ibl: strcat(LogoPath, ".ibl"); break;
        case LGSZ_qsl: strcat(LogoPath, ".qsl"); break;
          default:
            break;
      }

      TRACEEXIT();
      return LogoPath;
    }
    HDD_TAP_PopDir();
  }

  TRACEEXIT();
  return "";
}
示例#10
0
//------------
//
void DeleteFileFolder(void)
{
     char str[TS_FILE_NAME_SIZE];
     
     if (myfiles[CurrentDirNumber][chosenLine]->isPlaying)
        TAP_Hdd_StopTs();  // Stop the current playback to allow us to delete the file.
     TAP_Hdd_Delete(myfiles[CurrentDirNumber][chosenLine]->name);
     
     // Check if the delete was successful.
#ifdef WIN32
     if (FALSE)
#else  
     if (TAP_Hdd_Exist(myfiles[CurrentDirNumber][chosenLine]->name))  // Delete didn't work
#endif
     {
         TAP_SPrint(str,myfiles[CurrentDirNumber][chosenLine]->name);
         ShowMessageWin( rgn, "File Deletion Failed.", "Failed to delete file:", str, 400 );
         fileDeleted = FALSE;
     }
     else
         fileDeleted = TRUE;
     
}
示例#11
0
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;
}
示例#12
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 );
}
示例#13
0
void DeletePlayData( void )
{   // Will delete the playback progress file, and then recreate a new one.
    char* currentDir;
    int i;
     
    appendToLogfile("DeletePlayData: Started.", INFO);

    appendToLogfile("DeletePlayData: GetCurrentDir called.", WARNING);
    currentDir = GetCurrentDir();  // Store the current  directory.
    appendStringToLogfile("DeletePlayData: GetCurrentDir returned=%s.",currentDir, WARNING);
    appendStringToLogfile("DeletePlayData: Moving to=%s.",TAPIniDir, WARNING);
    GotoPath(TAPIniDir);           // Go to the Project Directory.

    appendToLogfile("DeletePlayData: Deleting DATA file.", ERR);
	if ( TAP_Hdd_Exist( PLAYDATA_FILENAME ) ) TAP_Hdd_Delete( PLAYDATA_FILENAME );	// Just delete any old copies

    appendToLogfile("DeletePlayData: Calling LoadPlayData.", ERR);
    LoadPlayData();  // Recreate and reload the new information.

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

    // Got through all of our current files and remove any progress information.
    for (i=1; i <= numberOfFiles; i += 1)
    {
        myfiles[CurrentDirNumber][i]->hasPlayed = FALSE;  // Reset indicator to show that file has not been played.
        myfiles[CurrentDirNumber][i]->currentBlock = 0;
        myfiles[CurrentDirNumber][i]->totalBlock   = 1;   // Set to 1 to ensure no division by 0 errors.
    }   

    ShowMessageWin( rgn, "All Progress Info Cleared.", "Removed playback information", "for all recorded files.", 400 );

    TAP_MemFree( currentDir );   // Free allocated memory.

    appendToLogfile("DeletePlayData: Finished.", INFO);
}
示例#14
0
//------------
//
void MoveAFile(char* sourceDir, char* destDir, char* sourceFile, dword attr)
{
     bool fileAlreadyExists;
     char targetDir[500];
	 char currentFileName[256], baseFileName[256], title1[50], title2[50], str1[256], str2[256], fileName[256], counter[6];
	 int  fileIncrement;       // A counter used in case we need to append a number to an already existing file name. 

     

     appendToLogfile("MoveAFile: Started.", WARNING);
 	 
      // If we try to move a file and there is already an existing file in the target directory
	 // with the same name, we will append an incrementing counter to the file name. (eg. news-1.rec  news-23.rec)
	 fileAlreadyExists = FALSE;          // Flag to indicate that the renamed file already exists.
	 fileIncrement     = 0;              // Counter in case we need to append a number to an already existing file name.

     if (attr != ATTR_FOLDER)
     {
         strncpy( currentFileName, sourceFile, 256 );   // Copy the current filename
         strncpy( fileName,        sourceFile, 256 );   // Copy the current filename
         strncpy( baseFileName,    sourceFile, 256 );   // Copy the current filename
    	 StripFileName( baseFileName );                       // Strip off the ".rec"
         strncpy( fileName, baseFileName, 256 );              // Copy the stripped off filename in case we need to rename on a move.
    	 strcat( fileName, REC_STRING );	                  // Append ".rec" to the base filename
     }

     // Perform check that the Move routine is available for this firmware.
     #ifdef WIN32
     #else
     if (!TAP_Hdd_Move_Available())
     {
         ShowMessageWin( rgn, "Move NOT available.", "This firmware does not support", "the move function via Archive.", 400 );
         returnFromMove = TRUE;   // Force a closer of the Move window, and refresh the list.
         return;
     }
     #endif
    
     appendToLogfile("MoveAFile: Creating target filename.", WARNING);
     
     // Create the fully qualified target directory name.  
     //
     // Start with the Source Directory 
     strcpy(targetDir, sourceDir);
     // Add the intermediate "/"
     strcat(targetDir, "/" );
     // Add the target directory.
     strcat(targetDir, destDir);

     // Check in the target directory to make sure a file with the same name doesn't already exists.
     //
     // Change to the target directory.
     appendStringToLogfile("MoveAFile: Changing to targetdir: %s.",targetDir, WARNING);
     GotoPath( targetDir );
     // Check for the same file.
     appendStringToLogfile("MoveAFile: Calling TAP_Hdd_Exist for:%s",sourceFile, WARNING);
     fileAlreadyExists = TAP_Hdd_Exist(sourceFile);

     // If we're moving a file and the target already exists, try to rename it - if the config option #28 has been set to allow rename..
     while ((fileAlreadyExists) && (fileIncrement < 99999) && (attr != ATTR_FOLDER) && (RenameOnMoveOption!=3))
     {
         fileIncrement++;         // Increase the counter for the number to append to the filename.
         appendIntToLogfile("MoveAFile: fileAlreadyExists loop:%d",fileIncrement, WARNING);
         sprintf(counter, "-%d", fileIncrement);        // Create the counter text
         strncpy( fileName, baseFileName, 256);         // Copy back the original filename
         strcat(  fileName, counter);                   // Append the counter text to the filename
 	     strcat(  fileName, REC_STRING );	            // Append the ".rec" to the end.
         appendStringToLogfile("MoveAFile: fileAlreadyExists loop calling TAP_Hdd_Exist for: %s", fileName, WARNING);
         fileAlreadyExists = TAP_Hdd_Exist(fileName);   // Check if the file exists.
         appendToLogfile("MoveAFile: fileAlreadyExists loop TAP_Hdd_Exist finished", WARNING);
     }

     // Return to the original directory.
     appendStringToLogfile("MoveAFile: Changing to sourceDir: %s.",sourceDir, WARNING);
     GotoPath( sourceDir );
     
    // Set up appropriate text strings for message windows, depending on whether it's a file or folder. 
     switch (attr)
     {
           case ATTR_FOLDER: TAP_SPrint(title1, "Folder Move Failed.");
                             TAP_SPrint(title2, "");
                             TAP_SPrint(str1,   "Same folder already exists:");
                             TAP_SPrint(str2,   "");
                             break;
                
           default:          TAP_SPrint(title1, "File Move Failed.");
                             TAP_SPrint(title2, "File Move Conflict.");
                             TAP_SPrint(str1,   "Same file already exists.");
                             TAP_SPrint(str2,   "Same file already exists.  Rename to:");
                             break;
     }
     
     // Copy source and destination information to Global variables so that they are available for the actual move routine.
     strncpy( GlbSourceFile, sourceFile, 256 );   // Copy the source filename
     strncpy( GlbSourceDir,  sourceDir,  256 );   // Copy the source directory
     strncpy( GlbTargetDir,  targetDir,  256 );   // Copy the target directory
     
     // If the target file already exists in the target directory we can't move.
     if (fileAlreadyExists)
     {
         ShowMessageWin( rgn, title1, str1, sourceFile, 400 );
         fileMoved      = FALSE;
         returnFromMove = FALSE;   // Don't close the Move window to give user a chance to choose a different folder.
         return;                   // Jump out of this routine as we can't do the move.
     }

     // Check if we needed to rename the file in the target directory.
     if (fileIncrement > 0) 
     {
         strncpy( GlbRenamedFile, fileName, 256 );   // Copy the renamed filename into the Global variable
         // Check the config option #28 to see if the Rename On Move requires a confirmation or not.
         if (RenameOnMoveOption == 0)   // Need to display a confirmation panel.
         {
                  DisplayYesNoWindow(title2, str2, fileName, "Yes", "No", 1, &ReturnFromMoveRenameYesNo );
                  fileMoved      = FALSE;
                  returnFromMove = FALSE;   // Don't close the Move window until after the Yes/No window.
                  return;                   // Jump out of this routine as Move will be done after Yes/No window.
         }
         else   // Otherwise call routine as if we said "Yes" on the confirmation window.
         {
                  ReturnFromMoveRenameYesNo( TRUE );
                  return;                    // Jump out of this routine as we've already done the move in the ReturnFromMoveRenameYesNo routine.
         }
         
     }
     
     // Call the routine to perform the actual move.
     PerformMove();

     appendToLogfile("MoveAFile: Finished.", WARNING);
   
}
示例#15
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;
	/*--------------------------------------------------*/
	}
}
示例#16
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);
	}
}
示例#17
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;
}
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);

  }
示例#19
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;
}
示例#20
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();
}
示例#22
0
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();
}
示例#23
0
//------------
//
void ReturnFromRenameKeyboard( char *str, bool success)
{
    char str1[200], str2[200];
    int  result;
    
    returnFromRename = TRUE;
    

    if ( success == TRUE)
	{
	    if (currentFile.attr != ATTR_FOLDER) strcat( str, tagStr );	//ensure the file name is of the correct format by appending ".rec" or ".rec.del"
        if (strcmp(currentFile.name,str)!=0) fileRenamed=TRUE; // File name was changed.
        
        if (fileRenamed) // Check that another file doesn't already exist with the new name.
        {
              if (TAP_Hdd_Exist(str))
              {
                  // Message already exists
                  ShowMessageWin( rgn, "Rename Failed.", "A File or Folder with that name", "already exists.", 400 );
              }
              else
              {
              	   // Rename the file.
#ifdef WIN32  // If testing on WIN32 platform don't do rename as not yet implemented in the TAP SDK.
                   result=0;
#else
              	   result=TAP_Hdd_Rename(currentFile.name,str);
#endif          
              	   if (result==0)
                   {
                      // Need to update the playedFiles to update new filename.
                      
                      strcpy( currentFile.name, str );           // Update the display if we were successful.
                      strcpy( myfiles[CurrentDirNumber][chosenLine]->name, str );   // Update the array of files if we were successful.
                      if (IsFileRec(myfiles[CurrentDirNumber][chosenLine]->name, myfiles[CurrentDirNumber][chosenLine]->attr)) FormatSortName(myfiles[CurrentDirNumber][chosenLine]->sortName,str);
                      else 
                      {
                          strcpy( currentFolder.name, str );                     // Update the display if we were successful.
                          strcpy( myfolders[myfiles[CurrentDirNumber][chosenLine]->directoryNumber]->name, str );      // Update the array of folders if we were successful.
                          strcpy( myfiles[CurrentDirNumber][chosenLine]->sortName,str);
                      }
    	              infoCommandOption = INFO_OK_OPTION;                        // Highlight the "OK" Info Window option
    	              fileRenamed = TRUE;
                   }
                   else
                   {
                      TAP_SPrint(str1,"Error renaming: '%s'", currentFile.name);
                      TAP_SPrint(str2,"to: '%s'", str);
                      ShowMessageWin( rgn, "Rename Failed.", str1, str2, 500 ); 
    	              infoCommandOption = INFO_RENAME_OPTION; // Highlight the "RENAME" Info Window option
                   }   
    	           DisplayArchiveInfoWindow();  // Refresh the info window.
              }   
        }
	}
	else
	{
       	infoCommandOption = INFO_RENAME_OPTION; // Highlight the "RENAME" Info Window option
    }

}