SmaugWizard/Backup/
SmaugWizard/Backup/L/
SmaugWizard/Boards/
SmaugWizard/Building/
SmaugWizard/Corpses/
SmaugWizard/Councils/
SmaugWizard/Deity/
SmaugWizard/Gods/
SmaugWizard/MudProgs/
SmaugWizard/Player/L/
SmaugWizard/Src/
SmaugWizard/Src/res/
/****************************************************************************
 * [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame      |				*
 * -----------------------------------------------------------|   \\._.//	*
 * SmaugWiz (C) 1998 by Russ Pillsbury (Windows NT version)   |   (0...0)	*
 * -----------------------------------------------------------|    ).:.(	*
 * SMAUG (C) 1994, 1995, 1996 by Derek Snider                 |    {o o}	*
 * -----------------------------------------------------------|   / ' ' \	*
 * SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus,      |~'~.VxvxV.~'~*
 * Scryn, Swordbearer, Rennard, Tricops, and Gorog.           |				*
 * ------------------------------------------------------------------------ *
 * Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael        *
 * Chastain, Michael Quan, and Mitchell Tse.                                *
 * Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,          *
 * Michael Seifert, Hans Henrik Staerfeldt, Tom Madsen, and Katja Nyboe.    *
 ****************************************************************************/
// SmaugFiles.cpp

#include	"stdafx.h"
#include	"smaug.h"
#include	"SmaugFiles.h"

CString CSmaugFiles::MakeBackupName (const char* n)
{
	CString		b = n;
	int	pos = b.Find ('.');
	if (pos >= 0) then
		b = b.Left (pos);
	b += ".bak";

	return b;
}


BOOL CSmaugFiles::CreatePlayerDirectory (CString& Path, const char* name,
										 BOOL bBackup /* = FALSE */)
{
	SmaugDirType	dir = bBackup ? SD_BACKUP_DIR : SD_PLAYER_DIR;
	CString	Dr = FileTable.GetDir (dir) + '/' + name [0];
	Path = Dr + '/' + name;

	CFileStatus		St;
	CFile::GetStatus (Dr, St);

	BOOL	bChanged = FALSE;
	if (St.m_attribute != 0x10) {				// if not dir
		if (! ::CreateDirectory (Dr, NULL)) {
			CString	Msg;
			Path = FileTable.MakeName (dir, name);
			if (bBackup) {
				Msg.Format ("Saving Backup for Player %s in backup "
					"directory root.", name);
			} else {
				Msg.Format ("Saving Player %s in player directory root.",
					name);
			}
			bug (Msg);
			bChanged = TRUE;
		}
	}
	Path += bBackup ? ".bak" : ".dat";
	return bChanged;
}


BOOL CSmaugFiles::Exists (const char* Fname)
{
	CFileStatus		St;

	return CFile::GetStatus (Fname, St);
}


int CSmaugFiles::Remove (const char* Fname)
{
	TRY CFile::Remove (Fname);
	CATCH (CFileException, ex)
		return ex->m_cause;
	END_CATCH

	return 0;
}


int CSmaugFiles::Rename (const char* OldName, const char* NewName)
{
	TRY CFile::Rename (OldName, NewName);
	CATCH (CFileException, ex)
		return ex->m_cause;
	END_CATCH

	return 0;
}