home *** CD-ROM | disk | FTP | other *** search
- //
- // Dir.cpp
- //+
- // implementation file
- //-
- // rev 11/09/98 gls continue
- // rev 11/02/98 gls
- //
-
- #include "stdafx.h"
- #include "gstg.h"
- #include "Dir.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CDir
-
- IMPLEMENT_DYNCREATE(CDir, CCmdTarget)
-
- CDir::CDir()
- {
- EnableAutomation();
-
- // To keep the application running as long as an OLE automation
- // object is active, the constructor calls AfxOleLockApp.
-
- AfxOleLockApp();
- }
-
- CDir::~CDir()
- {
- // To terminate the application when all objects created with
- // with OLE automation, the destructor calls AfxOleUnlockApp.
-
- AfxOleUnlockApp();
- }
-
-
- void CDir::OnFinalRelease()
- {
- // When the last reference for an automation object is released
- // OnFinalRelease is called. The base class will automatically
- // deletes the object. Add additional cleanup required for your
- // object before calling the base class.
-
- CCmdTarget::OnFinalRelease();
- }
-
-
- BEGIN_MESSAGE_MAP(CDir, CCmdTarget)
- //{{AFX_MSG_MAP(CDir)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- BEGIN_DISPATCH_MAP(CDir, CCmdTarget)
- //{{AFX_DISPATCH_MAP(CDir)
- DISP_FUNCTION(CDir, "Scan", Scan, VT_I4, VTS_BSTR)
- DISP_FUNCTION(CDir, "getFile", getFile, VT_BSTR, VTS_I4)
- DISP_FUNCTION(CDir, "MkDir", MkDir, VT_I4, VTS_BSTR)
- DISP_FUNCTION(CDir, "getFileCount", getFileCount, VT_I4, VTS_NONE)
- DISP_FUNCTION(CDir, "getFileRoot", getFileRoot, VT_BSTR, VTS_BSTR)
- DISP_FUNCTION(CDir, "getDir", getDir, VT_BSTR, VTS_I4)
- DISP_FUNCTION(CDir, "getDirCount", getDirCount, VT_I4, VTS_NONE)
- //}}AFX_DISPATCH_MAP
- END_DISPATCH_MAP()
-
- // Note: we add support for IID_IDir to support typesafe binding
- // from VBA. This IID must match the GUID that is attached to the
- // dispinterface in the .ODL file.
-
- // {9BD4DD41-724E-11D2-9F15-00A0246D0F63}
- static const IID IID_IDir =
- { 0x9bd4dd41, 0x724e, 0x11d2, { 0x9f, 0x15, 0x0, 0xa0, 0x24, 0x6d, 0xf, 0x63 } };
-
- BEGIN_INTERFACE_MAP(CDir, CCmdTarget)
- INTERFACE_PART(CDir, IID_IDir, Dispatch)
- END_INTERFACE_MAP()
-
- // {9BD4DD42-724E-11D2-9F15-00A0246D0F63}
- IMPLEMENT_OLECREATE(CDir, "gstg.Dir", 0x9bd4dd42, 0x724e, 0x11d2, 0x9f, 0x15, 0x0, 0xa0, 0x24, 0x6d, 0xf, 0x63)
-
- // ////////////////////////////////////////////////////////////
- // CDir message handlers
-
- long CDir::Scan(LPCTSTR pszFileSpec)
- {
- BOOL fSuccess = m_ScanDir.Scan( pszFileSpec );
-
- return( fSuccess ? S_OK : S_FALSE );
- }
- // ////////////////////////////////////////////////////////////
- //
- // Get dir from index
- //
- BSTR CDir::getDir(long iDir)
- {
- CString sResult;
-
- m_ScanDir.GetDir( sResult, iDir );
-
- return( sResult.AllocSysString() );
- }
- // ////////////////////////////////////////////////////////////
- //
- // Get count of dir entries from scan
- //
- long CDir::getDirCount()
- {
- return( m_ScanDir.getDirCount() );
- }
- // ////////////////////////////////////////////////////////////
- //
- // Get path to specified file
- //
- BSTR CDir::getFile(long iFile)
- {
- CString sResult;
-
- m_ScanDir.GetFile( sResult, iFile );
-
- return( sResult.AllocSysString() );
- }
- // ////////////////////////////////////////////////////////////
- //
- // Get count of files from a previous scan
- //
- long CDir::getFileCount()
- {
- return( m_ScanDir.getFileCount() );
- }
- // ////////////////////////////////////////////////////////////
- //
- // Create the specified directory - recursively if needed
- //
- long CDir::MkDir(LPCTSTR pszDir)
- {
- ASSERT( pszDir != NULL );
-
- int iSlash = 0; // index to the slash
- CString sDir = pszDir; // copy for manipulation
- CString sMkDir; // running directory to create
-
- while( (iSlash = sDir.Find( '\\' )) != -1 )
- {
- CString sSub = sDir.Left( iSlash+1 ); // get up to slash
- sDir = sDir.Mid( iSlash+1 ); // skip to next
-
- sMkDir += sSub; // keep running total
-
- CreateDirectory( sMkDir, NULL ); // create the intermediate dir
- }
-
- CreateDirectory( pszDir, NULL ); // last one to complete!
-
- return( S_OK );
- }
- // ////////////////////////////////////////////////////////////
- //
- // Helper function to get filename from path
- //
- BSTR CDir::getFileRoot(LPCTSTR pszFilePath)
- {
- char szFName[_MAX_PATH];
- char szExt[_MAX_PATH];
-
- _splitpath( pszFilePath, NULL, NULL, szFName, szExt );
- CString sResult;
- sResult.Format( "%s%s", szFName, szExt );;
-
- return( sResult.AllocSysString() );
- }
- // ////////////////////////////////////////////////////////////
- // ////////////////////////////////////////////////////////////
- // ////////////////////////////////////////////////////////////
-