コード例 #1
0
ファイル: Settings.c プロジェクト: BackupTheBerlios/tap-svn
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
ファイル: Settings.c プロジェクト: BackupTheBerlios/tap-svn
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();
	}
}
コード例 #3
0
ファイル: Tools.c プロジェクト: BackupTheBerlios/tap-svn
bool GotoPath(char *path){
	char *startPos;
	char *endPos;
	bool ready;

	ChangeDirRoot();

	startPos=path;
	if ((*startPos)!='/'){
		// TAP_Print("%s Doesn't start with a /\r\n",startPos);
		return FALSE;
	}
	startPos=startPos+1;
	ready=FALSE;
	while (ready==FALSE){
		endPos=startPos;
		while (((*endPos)!=0) && ((*endPos)!='/')){
			endPos=endPos+1;
		}
		if ((*endPos)==0){
			ready=TRUE;
			// TAP_Print("GotoPath1: going to %s...\r\n", startPos);
			TAP_Hdd_ChangeDir(startPos);
		} else {
			(*endPos)=0;
			// TAP_Print("GotoPath2: going to %s...\r\n", startPos);
			TAP_Hdd_ChangeDir(startPos);
			(*endPos)='/';
			startPos=endPos+1;
		}
	}
	strcpy(_currentDir, path);

	return TRUE;
}	
コード例 #4
0
ファイル: Tools.c プロジェクト: BackupTheBerlios/tap-svn
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;	
}
コード例 #5
0
ファイル: IniFile.c プロジェクト: BackupTheBerlios/tap-svn
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;
}
コード例 #6
0
ファイル: SDS.c プロジェクト: bulletmark/FireBirdLib
void WriteLog(char *s)
{
  HDD_TAP_PushDir();
  TAP_Hdd_ChangeDir(ROOTDIR);
  LogEntry(LOGFILE, "SDS", TRUE, TIMESTAMP_YMDHMS, s);
  HDD_TAP_PopDir();
}
コード例 #7
0
ファイル: Tools.c プロジェクト: BackupTheBerlios/tap-svn
//------------------------------ 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 );
	}

}
コード例 #8
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);
	}
}
コード例 #9
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();
}
コード例 #10
0
ファイル: Tools.c プロジェクト: BackupTheBerlios/tap-svn
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);
}
コード例 #11
0
ファイル: Tools.c プロジェクト: BackupTheBerlios/tap-svn
void GotoRoot(){
	TAP_Hdd_ChangeDir("/");
	_currentDir[0] = '/';
	_currentDir[1] = '\0';
}