Click here to Skip to main content
15,884,353 members
Articles / Desktop Programming / MFC

The SBJ MVC Framework - The Design View, Responding to Model Change

Rate me:
Please Sign up or sign in to vote.
4.87/5 (22 votes)
19 Mar 2009CPOL13 min read 80.5K   2.4K   51  
A Model-View-Controller Framework that integrates with the MFC Doc/View architecture.
//------------------------------------------------------------------------------
//$Workfile: FileSys.h $
//$Header: /SbjCore/Sys/FileSys.h 4     4/19/07 3:04p Steve $
//
// Stingray Software Extension Classes
// Copyright (C) 1995 Stingray Software Inc,
// All rights reserved
//   		
//
//$Revision: 4 $
//
//@doc
//
//@module FileSys | Renamed Stingray registry class to break full SEC dependency
//
//-----------------------------------------------------------------------------

#pragma once

#ifdef WIN32

#ifndef UNDER_CE

#ifndef _INC_DOS
#include <dos.h>
#endif

#ifndef _INC_DIRECT
#include <direct.h>
#endif

#endif  //UNDER_CE (WindowsCE)

// winbase.h defines this to be (0x100000L) for some reason.
#ifdef GetFreeSpace
#undef GetFreeSpace
#endif

#else

#include "dos.h"
#include "direct.h"

#endif

#define DRIVE_UNDETERMINED 0

namespace SbjCore
{
	namespace Sys
	{
		/** the FileSys class lifted from Stingray to break the Stingray dependency, see Stingray documentation for details.
		*/
		class AFX_EXT_CLASS FileSys : public CObject
		{

		// Constructors
		public:
			
			//@access Creation/Initialization

			//@cmember
			/* Constructs a FileSys object.*/
			FileSys();

			//@access Attributes

		private:

		#ifdef WIN32

			WIN32_FIND_DATA  m_FileInfo;
			HANDLE           m_hFind;

		#else

			struct _find_t	m_FileInfo;

		#endif

			int              m_nMaxFileNameLength;


		// Implementation
		public:
		  virtual ~FileSys();        // Destructor

		  // File/Directory Attributes

		#ifndef WIN32
		#define FILE_ATTRIBUTE_NORMAL CFile::normal
		#endif

			//@cmember,menum
			/* File attributes*/
		  enum Attribute {
			normal    = FILE_ATTRIBUTE_NORMAL,  //@@emem Normal Files (Win32 API version 0x80)
			readOnly  = CFile::readOnly,        //@@emem Read-Only Files
			hidden    = CFile::hidden,          //@@emem Hidden Files
			system    = CFile::system,          //@@emem System Files
			volume    = CFile::volume,          //@@emem Volume Label
			directory  = CFile::directory,      //@@emem Subdirectory Entry
			archive    = CFile::archive,        //@@emem Archive File
			allfiles  = 0xFFFFFFFF				//@@emem All files
		  } ;


			//@access File Operations

			//@cmember
			/* Compares the contents of one file with another.*/
			BOOL CompareFiles(const CString& FileName1, const CString& FileName2, const unsigned long lBuffSize = 10240);
			
			//@cmember
			/* Copies the contents of one file to another.*/
			BOOL CopyFile(const CString& SourceFileName, const CString& DestFileName, const unsigned long lBuffSize = 10240);
			
			//@cmember
			/* Copies more than one file to another subdirectory.*/
			BOOL CopyFiles(const CString& FileSpec, const CString& DestPath, const BOOL bIgnoreErrors = FALSE, const unsigned long eFileAttrib = normal);

			//@cmember
			/* Deletes a files.*/
			BOOL DeleteFile(const CString& FileName);
			
			//@cmember
			/* Deletes specified files (i.e., *.txt).*/
			BOOL DeleteFiles(const CString& FileSpec, const unsigned long eFileAttrib = normal);

			//@cmember
			/* Determines if a file exists.*/
			BOOL FileExists(const CString& PathAndFileName);
			
			//@cmember
			/* Returns the time and date the file was last accessed.*/
			BOOL GetFileAccessTime(const CString& FileName, CTime& time);
			
			//@cmember
			/* Returns the attribute bits for the file.*/
			BOOL GetFileAttribute(const CString& FileName, BYTE& Attribute);

			//@cmember
			/* Returns the time and date the file was created.*/
			BOOL GetFileCreateTime(const CString& FileName, CTime& time);
			
			//@cmember
			/* Returns the time and date the file was last modified.*/
			BOOL GetFileModifyTime(const CString& FileName, CTime& time);
			
			//@cmember
			/* Returns the size of the file in bytes.*/
			BOOL GetFileSize(const CString& FileName, unsigned long& lSize);
			
			//@cmember
			/* Returns the file status.*/
			BOOL GetFileStatus(const CString& FileName, CFileStatus& FileStatus);
			
			//@cmember
			/* Renames a file.*/
			BOOL RenameFile(const CString& OldFileName, const CString& NewFileName);
			

			//@cmember
			/* Returns the time and date the file was created.*/
			BOOL GetFileCreateTime(const CString& FileName, COleDateTime& time);

			//@cmember
			/* Returns the time and date the file was last accessed.*/
			BOOL GetFileAccessTime(const CString& FileName, COleDateTime& time);

			//@cmember
			/* Returns the time and date the file was last modified.*/
			BOOL GetFileModifyTime(const CString& FileName, COleDateTime& time);
			
			//@access Parsing Operations

			//@cmember
			/* Appends a wildcard to a path.*/
			CString AppendWildcard(const CString& Path, const CString& Wildcard);

			//@cmember
			/* Returns the filename without path or extension.*/
			CString GetBaseFileName(const CString& PathAndFileName);

			//@cmember
			/* Returns the extension of the filename.*/
			CString GetExtension(const CString& PathAndFileName);
			
			//@cmember
			/* Returns the filename and extension of a filespec.*/
			CString GetFileName(const CString& PathAndFileName);
			
			//@cmember
			/* Returns the filesystem of the specified filespec.*/
			CString GetFileSystem(const CString& PathAndFileName);
			
			//@cmember
			/* Expands the specified filespec into a full path.*/
			CString GetFullPathName(const CString& PathAndFileName);
			
			//@cmember
			/* Returns the path of the specified filespec.*/
			CString GetPath(const CString& PathAndFileName, const BOOL bIncludeFileSystem = TRUE);
			

			
			//@access Directory Reading Operations

			//@cmember
			/* Returns a list of files based on a filespec.*/
			CStringList* GetDirectory(const CString& SearchString, const unsigned long eFileAttrib, const BOOL bRecurseSubDirs=FALSE, CStringList *pStringList = NULL);

			//@cmember
			/* Returns a single directory entry.*/
			CString* GetDirectoryEntry(const CString& Wildcard = "", const unsigned long eFileAttrib = normal);

			//@cmember
			/* Returns a list of files in the specified directory.*/
			CStringList* GetFileList(const CString& SearchString, const unsigned long eFileAttrib);

			//@cmember
			/* Returns a list of directories in the specified directory.*/
			CStringList* GetSubdirList(const CString& SearchDir, const BOOL bPathInName = TRUE);
			

			
			
			//@access Directory Operations

			//@cmember
			/* Compares the file names, sizes, and contents of two directories.*/
			BOOL CompareDirectories(const CString& PathName1, const CString& PathName2, const BOOL bRecurseSubdirs = FALSE, const BOOL bCompareFileContents = FALSE, const unsigned long eFileAttrib = normal);

			//@cmember
			/* Changes the current working directory.*/
			BOOL ChangeDirectory(const CString& NewDirectory);
			
			//@cmember
			/* Deletes a directory and all its files and subdirectories.*/
			BOOL DeleteDirectory(const CString& Directory, const BOOL bDeleteFilesAndDirs = FALSE);

			//@cmember
			/* Determines if the specified directory exists.*/
			BOOL DirectoryExists(const CString& Path);

			//@cmember
			/* Returns the current directory name.*/
			CString GetCurrentDirectory(const CString& FileSystem = "");

			//@cmember
			/* Returns the number of bytes in all the files in a directory.*/
			LONG GetDirectorySize(const CString& Directory = "", const CString& WildCard = "*.*", const BOOL bRecurseSubdirs = FALSE);

			//@cmember
			/* Creates a subdirectory.*/
			BOOL MakeDirectory(const CString& NewDirectory);
			
			//@cmember
			/* Makes a subdirectory (including all intervening dirs necessary).*/
			BOOL MakePath(const CString& NewDirectory);
			
			//@cmember
			/* Renames a directory.*/
			BOOL RenameDirectory(const CString& OldName, const CString& NewName);
			



			//@access File System Operations

			//@cmember
			/* Changes the current filesystem.*/
			BOOL ChangeFileSystem(const CString& FileSystem);
			
			//@cmember
			/* Returns the current filesystem.*/
			CString GetCurrentFileSystem();
			
			//@cmember
			/* Returns a list of available filesystems.*/
			CStringList* GetFileSystemList();
			
			//@cmember
			/* Returns the type of the specified filesystem.*/
			LONG GetFileSystemType(const CString& FileSystem);
			
			//@cmember
			/* Returns the number of available bytes on the specified filesystem.*/
			LONG GetFreeSpace(const CString& FileSystem);

		#if _MSC_VER >= 1200
			//@cmember
			/* Returns the number of available bytes on the specified filesystem.*/
		#ifndef UNDER_CE
			LONG64 GetFreeSpaceEx(const CString& FileSystem);
		#else
			ULONG GetFreeSpaceEx(const CString& FileSystem);
		#endif  //UNDER_CE (WindowsCE)
		#endif // #_MSC_VER >= 1200

			//@cmember
			/* Returns whether the specified file system exists.*/
			BOOL FileSystemExists(const CString& FileSystemName);
			
			//@cmember
			/* Returns the number of bytes (used and unused) on the specified filesystem.*/
			LONG GetTotalSpace(const CString& FileSystem);

		#if _MSC_VER >= 1200
			//@cmember
			/* Returns the number of bytes (used and unused) on the specified filesystem.*/
		#ifndef UNDER_CE
			LONG64 GetTotalSpaceEx(const CString& FileSystem);
		#else
			ULONG GetTotalSpaceEx(const CString& FileSystem);
		#endif  //UNDER_CE (WindowsCE)
		#endif //_MSC_VER >= 1200

			//@cmember
			/* Returns the volume label of the specified filesystem.*/
			CString GetVolumeLabel(const CString& FileSystem);
			
			//@cmember
			/* Determines if the specified filesystem is writeable.*/
			BOOL IsReadOnlyFileSystem(const CString& FileSystem);
			
			static void Sort(CStringList *pStringList, BOOL bCase = TRUE);
			
			//@cmember
			/* Returns the current directory name.*/
			CString GetModuleDirectory(HINSTANCE hInst = NULL);

			
		protected:
		  BOOL          ChangeFileSystem(const char cFileSystem);
		  BOOL          CloseFile(CFile *pFile) const;
		  BOOL          GetADirectoryEntry(CString &fileName, const CString& Wildcard = "", const unsigned long eFileAttrib = normal);

		}; // FileSys
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
SBJ
United States United States
Real name is Steve Johnson. Programming since 1979. Started on a Heathkit Micro with a DEC LSI-11 and UCSD Pascal. Moved to PCs & DOS as soon as Turbo Pascal became available. Did some Assembly, ISR, TSR etc. All this while working for a Manufacturing Co. for 8 years. Had my own solo Co. doing barcode labeling software for 4 years (terrible business man, all I wanted to do was code). Since then working for various software companies. Moved to Windows around the time of 3.1 with Borland C then C++. Then on to VC++ and MFC, and just about anything I could get my hands on or had to learn for my job, and been at it ever since. Of course recently I've been playing with .NET, ASP, C#, WPF etc.

Comments and Discussions