bool VFSHandle_ZIP::Open(char *filename, bool create)
{
	OpenLocation(filename,create);

	FindFilename();

	if(IsFile(m_file) == false){
		if(create == true){
			Createfile(m_file);
		}else{
			return false;
		}
	}

	Length();
	return true;
}
/**	Opens a file
 *
 *	@param filename	The name of the file to open
 *	@param create		Whether to create a non-existant file or return false
 *
 *	@returns boolean true or false, depending on whether was able to open
 *
 *	Operation:
 *		-#	The filename will be preceeded by "file://" so move the filename 
 *				pointer forward, past the vfs specific section of the file, and 
 *				to the actual filename itself e.g. file://image.jpg => image.jpg
 *		-#	Opens a filestream with read/write capabilities in binary mode
 *		-#	Sets the handles filename
 *		-#	Attempts to open the file
 *		-#	If successful, calculates the length of the file
 *		-#	returns whether the file was opened successfully
 *
 *	@todo	Add functionality to decide whether to create a new file, if the file requested does not exist
 */
bool VFSHandle_file::Open(std::string filename, bool create )
{
	SetFilename( filename );

	if ( IsFile( m_filename ) == false && create == true ) Createfile( m_filename );

	if ( IsFile( m_filename ) == true )
	{
		m_stream.clear();
		m_stream.open( m_filename.c_str(), std::ios::in | std::ios::out | std::ios::binary );

		Length();

		return ( bool ) m_stream.is_open();
	}

	return false;
}
Example #3
0
int main()
{
    char buff[ 256 ];
    char checksumhex[ SLC_FCRC_MAXHEXSIZE ]; /*0-terminated*/

    do
    {
        /*Get the file name from the user*/
        printf( "\nEnter a file name:\n" );
        gets( buff );
		Createfile(buff);
        /*Calculate the checksum using CalculateFile*/
        if( Calculate_CRC32_Example1( "C:\\Users\\Jahagirdar\\Desktop\\final_load.hex", checksumhex ) != 0 )
            printf( "\nCRC32 checksum calculated using CalculateFile:    %s", checksumhex );
		 //Calculate_CRC32_Example1( "C:\\Users\\Jahagirdar\\Desktop\\final_load.hex", checksumhex);
        /*Calculate the checksum using Update and Final*/
        if( Calculate_CRC32_Example2( "C:\\Users\\Jahagirdar\\Desktop\\final_load.hex", checksumhex ) != 0 )
            printf( "\nCRC32 checksum calculated using Update and Final: %s", checksumhex );
		 //Calculate_CRC32_Example2( "C:\\Users\\Jahagirdar\\Desktop\\final_load.hex", checksumhex );

		check_crc_calculate=Atohex(checksumhex);

	printf("\ncheck crc calculate=%lu %X\n", check_crc_calculate, check_crc_calculate);

		if(check_crc_calculate == check_crc)
			printf( "CRC matching\n");
		else 
			printf( "CRC not matching\n");

        /*Continue?*/
        printf( "\nContinue (Y/N)?" );
        gets( buff );
    } while ( *buff == 'y' || *buff == 'Y' );

    return 0;
}
Example #4
0
int main(int argc,char* argv[])
{
    char *str = new char[MAXSIZE],*p;
    int Port_BDS = atoi(argv[2]);
    int Port_FC = atoi(argv[3]);

    sockfd_BDS = Socket();
    sockfd_FC = Socket();

    struct sockaddr_in servself_addr,client_addr,servBDS_addr;
    struct hostent *host;
    int nread;
    socklen_t len;

    Bind(sockfd_FC,servself_addr,Port_FC);
    Listen(sockfd_FC,5);
    printf("The FS is listening\n");

    bzero(&servBDS_addr,sizeof(servBDS_addr));
    servBDS_addr.sin_family = AF_INET;
    host = gethostbyname(argv[1]);
    memcpy(&servBDS_addr.sin_addr.s_addr,host->h_addr,host->h_length);
    servBDS_addr.sin_port = htons(Port_BDS);
    connect(sockfd_BDS,(struct sockaddr*)&servBDS_addr,sizeof(servBDS_addr));

    initial();
    while (1)
    {
        len = sizeof(client_addr);
        client_sockfd = accept(sockfd_FC,(struct sockaddr *) &client_addr, &len);
        printf("Connect successfully\n");

        bzero(SendToFC,sizeof(SendToFC));
        strcat(SendToFC,CurrentInode.Name);
        strcat(SendToFC," $ ");
        Write(client_sockfd,SendToFC,strlen(SendToFC));
        while (1)
        {
            bzero(ReceFromFC,sizeof(ReceFromFC));
           int n = Read(client_sockfd,ReceFromFC,MAXSIZE);
            Write(STDOUT_FILENO,ReceFromFC,strlen(ReceFromFC));
           // Show(CurrentInode,CurrentData);
            strcpy(str,ReceFromFC);
            p = str;
            str = strtok(str," \n");
            if (0 == strcmp(str,"f")) Format();
            else if (0 == strcmp(str,"mk"))  /*Create a file*/ 
            {
                str = strtok(NULL," \n");
                Createfile(str,0);
            }
            else if (0 == strcmp(str,"mkdir")) /*Create a folder*/
            {
                str = strtok(NULL," \n");
                Createfile(str,1);
            }
            else if (0 == strcmp(str,"rm")) /*Remove a file*/
            {
                str = strtok(NULL," \n");
                 Removefile(str,0);
            }
            else if (0 == strcmp(str,"cd")) /*Change path*/
            {
                str = strtok(NULL," \n");
                Changedir(str);
                HandleError("cdok!\n");
            }
            else if (0 == strcmp(str,"rmdir")) 
            {
                str = strtok(NULL," \n"); /*Remove a folder*/
                Removefile(str,1);
            }
            else if (0 == strcmp(str,"ls")) 
            {
                str = strtok(NULL," \n");
                List(str);
            }
            else if (0 == strcmp(str,"cat")) /*Catch a file*/ 
            {
                str = strtok(NULL," \n");
                Catchfile(str);
                printf("Catch ok!\n");
            }
            else if (0 == strcmp(str,"w")) 
            {
                str = strtok(NULL,"\n");
                WriteData(str);
            }
            else if (0 == strcmp(str,"a")) 
            {
                str = strtok(NULL,"\n");
                Append(str);
            }
            else if (0 == strcmp(str,"exit")) 
                Exit();
            else 
            {
                HandleError("2:Unavailable command\n");
            }
            bzero(SendToFC,sizeof(SendToFC));
            strcat(SendToFC,CurrentInode.Name);
            strcat(SendToFC," $ ");
            Write(client_sockfd,SendToFC,strlen(SendToFC));
        }
        Close(client_sockfd);
    }
    Close(sockfd_BDS);
    Close(sockfd_FC);
}