home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
WTJ9403.ZIP
/
WILDASS
/
SOURCE
/
APPINFO.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-12
|
10KB
|
399 lines
// appinfo.cpp
//
// update: 1.00 08-Aug-93 tw
#include <afxwin.h>
#include <afxext.h>
#include <stdlib.h>
#include <direct.h>
#include "appinfo.h"
#include "app.h"
#include "resource.h"
#define new DEBUG_NEW
CApplication::CApplication()
{
m_strAppPath = "";
m_strAppTitle = "";
m_strAppArgs = "";
m_strAppInitialDir = "";
m_nRunState = 2;
}
CApplication::CApplication( const CApplication& rApp )
{
m_strAppPath = rApp.m_strAppPath;
m_strAppTitle = rApp.m_strAppTitle;
m_strAppArgs = rApp.m_strAppArgs;
m_strAppInitialDir = rApp.m_strAppInitialDir;
m_nRunState = rApp.m_nRunState;
}
CApplication::CApplication(
const char * pszAppPath,
const char * pszAppTitle,
const char * pszAppArgs,
const char * pszAppInitialDir,
int nRunState
)
{
m_strAppPath = pszAppPath;
// if no title give, buidl one from the
// path
if ( ! pszAppTitle )
{
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath( m_strAppPath, drive, dir, fname, ext );
m_strAppTitle = fname;
}
else
{
m_strAppTitle = pszAppTitle;
}
m_strAppArgs = pszAppArgs;
m_strAppInitialDir = pszAppInitialDir;
m_nRunState = nRunState;
}
void
CApplication::Description(
const char * pszAppPath,
const char * pszAppTitle,
const char * pszAppArgs,
const char * pszAppInitialDir,
int nRunState
)
{
m_strAppPath = pszAppPath;
m_strAppTitle = pszAppTitle;
m_strAppArgs = pszAppArgs;
m_strAppInitialDir = pszAppInitialDir;
m_nRunState = nRunState;
}
const char *
CApplication::Title() const
{
return m_strAppTitle;
}
const char *
CApplication::Path() const
{
return m_strAppPath;
}
const char *
CApplication::Args() const
{
return m_strAppArgs;
}
const char *
CApplication::InitialDir() const
{
return m_strAppInitialDir;
}
int
CApplication::RunState() const
{
return m_nRunState;
}
BOOL
CApplication::ReadProfile( const char * pszTag, int nProfileIndex )
{
CMyApp * pApp = (CMyApp*)AfxGetApp();
CString strPath("path"), strArgs("args"), strDir("dir"), strTitle("title");
CString strState("state");
char szTmp[10];
strPath += itoa( nProfileIndex, szTmp, 10 );
strArgs += itoa( nProfileIndex, szTmp, 10 );
strDir += itoa( nProfileIndex, szTmp, 10 );
strTitle += itoa( nProfileIndex, szTmp, 10 );
strState += itoa( nProfileIndex, szTmp, 10 );
m_strAppPath = pApp->GetProfileString( pszTag, strPath );
if ( m_strAppPath.IsEmpty() )
return FALSE;
m_strAppTitle = pApp->GetProfileString( pszTag, strTitle );
m_strAppArgs = pApp->GetProfileString( pszTag, strArgs );
m_strAppInitialDir = pApp->GetProfileString( pszTag, strDir );
m_nRunState = pApp->GetProfileInt( pszTag, strState, 2 );
return TRUE;
}
void
CApplication::DumpProfile( const char * pszTag, int nProfileIndex )
{
CMyApp * pApp = (CMyApp*)AfxGetApp();
CString strPath("path"), strArgs("args"), strDir("dir"), strTitle("title");
CString strState("state");
char szTmp[10];
strPath += itoa( nProfileIndex, szTmp, 10 );
strArgs += itoa( nProfileIndex, szTmp, 10 );
strDir += itoa( nProfileIndex, szTmp, 10 );
strTitle += itoa( nProfileIndex, szTmp, 10 );
strState += itoa( nProfileIndex, szTmp, 10 );
VERIFY( pApp->WriteProfileString( pszTag, strPath, Path() ));
VERIFY( pApp->WriteProfileString( pszTag, strArgs, Args() ));
VERIFY( pApp->WriteProfileString( pszTag, strDir, InitialDir() ));
VERIFY( pApp->WriteProfileString( pszTag, strTitle, Title() ));
VERIFY( pApp->WriteProfileInt( pszTag, strState, RunState() ));
}
void
CApplication::Run() const
{
// get the current directory, switch
// to the applications default directory
char szCWD[_MAX_PATH];
int nDrive;
if ( ! m_strAppInitialDir.IsEmpty() )
{
_getcwd( szCWD, _MAX_PATH );
nDrive = _getdrive();
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath( m_strAppPath, drive, dir, fname, ext );
_chdrive( drive[0]-65 );
_chdir( dir );
}
// try to run this application
// and notify user if anything isn`t
// working as expected
UINT nReturn = WinExec( Path(), SW_SHOW );
// if this was a failure..
if ( nReturn < 32 )
AfxMessageBox( CString("Problem running:") + Path() );
// return to our path
if ( ! m_strAppInitialDir.IsEmpty() )
{
_chdrive( nDrive );
_chdir( szCWD );
}
}
// ******************* application list
CApplicationList::CApplicationList()
{
m_nIcon = 0;
m_strIconFile = "";
// m_hIcon = 0;
}
void
CApplicationList::Icon( const char * pszIconFile, UINT nIcon )
{
m_strIconFile = pszIconFile;
m_nIcon = nIcon;
}
HICON
CApplicationList::Icon() const
{
// if we have an icon file, try to use this one
if ( ! m_strIconFile.IsEmpty() )
{
HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), m_strIconFile, m_nIcon );
if ( hIcon!=NULL && hIcon!=(HICON)1 )
return hIcon;
}
// if this didnt work, check if this is an empty,
// a one-app or a mutiple app group
if ( GetCount() == 0 )
{
return AfxGetApp()->LoadIcon( IDI_GROUPEMPTY );
}
if ( GetCount()==1 )
{
CApplication *pApp = (CApplication*)GetHead();
HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), pApp->Path(), 0 );
if ( hIcon!=NULL && hIcon!=(HICON)1 )
return hIcon;
}
// in all other cases, retur the group icon
return AfxGetApp()->LoadIcon( IDI_GROUP );
}
const CString&
CApplicationList::IconFile() const
{
return m_strIconFile;
}
UINT
CApplicationList::IconID() const
{
return m_nIcon;
}
CApplicationList::~CApplicationList()
{
RemoveAll();
}
//POSITION
//CApplicationList::AddTail( CApplication* newElement )
//{
// return CObList::AddTail( newElement );
//}
void
CApplicationList::ReadProfile( int nProfileIndex )
{
CString strTag("AppList");
char szTmp[10];
strTag += itoa( nProfileIndex, szTmp, 10 );
// read the icon to use
CMyApp * pApp =(CMyApp*)AfxGetApp();
m_strIconFile = pApp->GetProfileString( strTag, "IconFile" );
// if ( ! m_strIconFile.IsEmpty() )
// {
m_nIcon = pApp->GetProfileInt( strTag, "IconID", 0 );
// m_hIcon = ExtractIcon( AfxGetInstanceHandle(), m_strIconFile, m_nIcon );
// }
int iEntry = 0;
while( TRUE )
{
CApplication * pApp = new CApplication();
if ( ! pApp->ReadProfile( strTag, iEntry ))
{
delete pApp;
return;
}
else
{
AddTail( pApp );
}
iEntry++;
}
}
void
CApplicationList::DumpProfile( int nProfileIndex )
{
CString strTag("AppList");
char szTmp[10];
strTag += itoa( nProfileIndex, szTmp, 10 );
POSITION pos;
// empty this profile section, so that
// no old entries stay in there
// the CWinApp fxn will assert in this case,
// so we are using the SDK fxn for that
CString strFile = AfxGetAppName() + CString(".ini");
WritePrivateProfileString( strTag, NULL, NULL, strFile );
// dump the icon info
CMyApp * pApp =(CMyApp*)AfxGetApp();
pApp->WriteProfileString( strTag, "IconFile", m_strIconFile );
pApp->WriteProfileInt( strTag, "IconID", m_nIcon );
int iEntry;
for ( iEntry=0,pos=GetHeadPosition(); pos!=NULL; iEntry++ )
{
CApplication * pApp = GetNext( pos );
pApp->DumpProfile( strTag, iEntry );
}
}
void
CApplicationList::Add( CApplicationList* pNewList )
{
for ( POSITION pos = pNewList->GetHeadPosition(); pos!=NULL; )
{
AddTail( new CApplication( *pNewList->GetNext(pos) ) );
}
// transfer icon inco
m_strIconFile = pNewList->IconFile();
m_nIcon = pNewList->IconID();
}
// Add a single application (this is a drag n drop message)
void
CApplicationList::Add( const char * pszPath )
{
AddTail( new CApplication( pszPath ) );
// in case we didn`t have a group icon yet, create one
if ( m_strIconFile.IsEmpty() )
{
// does this app have an icon ?
HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), pszPath, 0 );
if ( hIcon!=0 && hIcon!=(HICON)1 )
{
m_strIconFile = pszPath;
m_nIcon = 0;
}
}
}
void
CApplicationList::RemoveAll()
{
for ( POSITION pos=GetHeadPosition(); pos!=NULL; )
{
CApplication * pApp = GetNext( pos );
delete pApp;
}
CObList::RemoveAll();
// remove the icon info
m_strIconFile="";
m_nIcon = 0;
}
// avoid casts in usage
CApplication*&
CApplicationList::GetNext( POSITION& rPos )
{
return (CApplication*&)CObList::GetNext( rPos );
}
CApplication*
CApplicationList::GetNext( POSITION& rPos ) const
{
return (CApplication*)CObList::GetNext( rPos );
}
CApplication*&
CApplicationList::GetAt( POSITION pos )
{
return (CApplication*&)CObList::GetAt( pos );
}
CApplication*
CApplicationList::GetAt( POSITION pos ) const
{
return (CApplication*)CObList::GetAt( pos );
}