RASCSI/src/raspberrypi/filepath.cpp
Uwe Seimet 45cd5e58d1
Inheritance hierarchy improvements, reduced dependencies to Disk class (#662)
* Fixed buster compile-time issue

* Host services inherit from ModePageDevice

* Call base class

* Visibility update

* Updated includes

* Updated dispatcher

* Added TODOs

* Logging update

* Code cleanup

* Use namespace instead of class for ScsiDefs

* Renaming

* Cleanup

* Use dispatcher template in order to remove duplicate code

* Updated all dispatchers

* Clean up commands

* Removed duplicate code

* Removed duplicate code

* Updated template definition

* Fixed typo

* Fixed warning

* Code cleanup

* Device list must be static

* Cleanup

* Logging update

* Added comments

* Cleanup

* Base class update

* SCSIBR is not a subclass of Disk anymore, but of PrimaryDevice

* Updated includes

* Fixed compile-time issue on the Pi

* Header file cleanup

* Interface cleanup

* Removed wrong override

* include file cleanup

* Removed obsolete usage of streams

* Removed more stream usages

* Stream usage cleanup

* Include cleanup

* Renaming

* Include cleanup

* Interface update
2022-02-13 13:30:02 -06:00

141 lines
2.8 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//---------------------------------------------------------------------------
//
// X68000 EMULATOR "XM6"
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2012-2020 GIMONS
// [ File path (subset) ]
//
//---------------------------------------------------------------------------
#include "os.h"
#include "filepath.h"
#include "config.h"
#include "fileio.h"
//===========================================================================
//
// File path
//
//===========================================================================
Filepath::Filepath()
{
// Clear
Clear();
}
Filepath::~Filepath()
{
}
Filepath& Filepath::operator=(const Filepath& path)
{
// Set path (split internally)
SetPath(path.GetPath());
return *this;
}
void Filepath::Clear()
{
// Clear the path and each part
m_szPath[0] = _T('\0');
m_szDir[0] = _T('\0');
m_szFile[0] = _T('\0');
m_szExt[0] = _T('\0');
}
//---------------------------------------------------------------------------
//
// File settings (user) for MBCS
//
//---------------------------------------------------------------------------
void Filepath::SetPath(const char *path)
{
ASSERT(path);
ASSERT(strlen(path) < _MAX_PATH);
// Copy pathname
strcpy(m_szPath, (char *)path);
// Split
Split();
}
//---------------------------------------------------------------------------
//
// Split paths
//
//---------------------------------------------------------------------------
void Filepath::Split()
{
// Initialize the parts
m_szDir[0] = _T('\0');
m_szFile[0] = _T('\0');
m_szExt[0] = _T('\0');
// Split
char *pDir = strdup(m_szPath);
char *pDirName = dirname(pDir);
char *pBase = strdup(m_szPath);
char *pBaseName = basename(pBase);
char *pExtName = strrchr(pBaseName, '.');
// Transmit
if (pDirName) {
strcpy(m_szDir, pDirName);
strcat(m_szDir, "/");
}
if (pExtName) {
strcpy(m_szExt, pExtName);
}
if (pBaseName) {
strcpy(m_szFile, pBaseName);
}
// Release
free(pDir);
free(pBase);
}
//---------------------------------------------------------------------------
//
// File name + extension acquisition
// The returned pointer is temporary. Copy immediately.
//
//---------------------------------------------------------------------------
const char *Filepath::GetFileExt() const
{
// Merge into static buffer
strcpy(FileExt, m_szExt);
// Return as LPCTSTR
return (const char *)FileExt;
}
BOOL Filepath::Save(Fileio *fio, int /*ver*/)
{
ASSERT(fio);
return TRUE;
}
BOOL Filepath::Load(Fileio *fio, int /*ver*/)
{
ASSERT(fio);
return TRUE;
}
//---------------------------------------------------------------------------
//
// Filename and extension
//
//---------------------------------------------------------------------------
TCHAR Filepath::FileExt[_MAX_FNAME + _MAX_DIR];