AeAssetFile.c++ 1.96 KB
/*****************************************************************************
 *  File:  AeAssetFile.c++ 
 *
 *  File Manager
 *
 ****************************************************************************/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <bstring.h>

#include "AeBankFile.h"
#include "AeWaveFile.h"
#include "AeInstFile.h"
#include "AeAsset.h"


AeAssetFile *
AeAssetFile::NewAssetFile (char * name)
{
    AeAssetFile *	file;
    char * 		dirName;
    char * 		fileName;
    char * 		fileSuffix;

    parseFileString (name, dirName, fileName, fileSuffix);

    // current version only allows opening of .inst and .aifc files
    switch (suffix2type (fileSuffix))
    {
	case kWaveType:
	    file = (AeAssetFile *)new AeWaveFile (name);
	break;

	case kBankFileType:
	    file = NULL;
	break;

	case kInstFileType:
	default:
	    file = (AeAssetFile *)new AeInstFile (name);
	break;
    }

    if (dirName) free (dirName);
    if (fileName) free (fileName);
    if (fileSuffix) free (fileSuffix);

    return file;
}

AeAssetFile::AeAssetFile (char * name)
    : AeFile (name)
{
}


AeAssetFile::~AeAssetFile()
{
}


AeErr
AeAssetFile::Read (AeAsset *&)
{
    assert (False);		// pure virtual function called
    return kAeNoErr;
}


AeErr
AeAssetFile::ReadList (GList<AeAsset *> *&)
{
    assert (False);		// pure virtual function called
    return kAeNoErr;
}


AeErr
AeAssetFile::Write (AeAssetBase *)
{
    assert (False);		// pure virtual function called
    return kAeNoErr;
}


TAssetType
AeAssetFile::suffix2type (char * suffix)
{
    // n64 bank files
    if (strcmp (suffix, "ctl") == 0 ||
	strcmp (suffix, "tbl") == 0 ||
	strcmp (suffix, "sym") == 0)
    {
	return kBankFileType;
    }

    // n64 inst files
    if (strcmp (suffix, "inst") == 0)
    {
	return kInstFileType;
    }

    // sound files
    if (strcmp (suffix, "aifc") == 0 ||
	strcmp (suffix, "aiff") == 0)
    {
	return kWaveType;
    }

    return kUnknownType;
}