//----------------------------------------------------------------------------
//
// File:		support.hpp
// Date:		15-Jan-2003
// Programmer:	Marc Rousseau
//
// Description: This file contains startup code for Linux/SDL
//
// Copyright (c) 2000-2004 Marc Rousseau, All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
//
// Revision History:
//
//----------------------------------------------------------------------------

#ifndef SUPPORT_HPP_
#define SUPPORT_HPP_

#include <string>
#include <list>

extern const char FILE_SEPERATOR;

const char *GetCommonPath( );
const char *GetHomePath( );

std::string GetHomePath( const char *path );
std::string CreateHomePath( const char *path = nullptr );

bool IsAbsolutePath( const std::string &filename );
bool IsWriteable( const std::string &filename );

std::list<std::string> GetFiles( const std::string &directory, const std::string &pattern, bool recurse );

// File location utilities - all LocateXYZ functions search the CWD, ~/.ti99sim/<path>, and <install-dir>/<path> for files

std::list<std::string> LocateFiles( const std::string &path, const std::string &pattern );
std::string LocateFile( const std::string &path, const std::string &filename );
std::string LocateCartridge( const std::string &path, const std::string &sha1 );
std::string LocateCartridge( const std::string &path, const std::string &name, const std::list<std::string> &signatures );

bool Is6K( const UINT8 *data, int size );

std::string sha1( const void *data, size_t length );

// OS-specific SHA1 Methods

void *CreateSHA1Context( );
bool UpdateSHA1Context( void *context, const void *data, size_t length );
std::string GetDigest( void *context );
void ReleaseSHA1Context( void *context );

class SHA1Context
{
	void	*context{ nullptr };

public:

	SHA1Context( )
	{
		context = CreateSHA1Context( );
	}

	~SHA1Context( )
	{
		ReleaseSHA1Context( context );
	}

	bool Update( const void *data, size_t length )
	{
		return UpdateSHA1Context( context, data, length );
	}

	std::string Digest( )
	{
		return GetDigest( context );
	}
};

#endif
