⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 path.cpp

📁 cab文件压缩、解压程序源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//---------------------------------------------------------------------------
// Copyright (C) 1998, Interscope Ltd. All rights reserved.
// Reproduction or distribution of this program, or any portion of it, 
// is permitted only if this header is kept as it is.
// For more information, contact:
//
// Interscope Ltd., 5 Culturii St., 5th Floor, 4800 Baia Mare, RO
//    Phone/Fax: +40-62-215023
//    E-mail: office@interscope.ro
//
//   $Author: Levente Farkas $
//     $Date: 9/14/98 4:34a $
//  $Modtime: 9/14/98 4:34a $
// $Revision: 120 $
//  $Archive: /Interscope/Callisto/Path.Cpp $
// $Workfile: Path.Cpp $
//-----------------------------------------------------------------------

#ifdef __STDAFX__
#include "StdAfx.H"
#endif

#include <Direct.H>
#include <StdLib.H>
#include <StdIO.H>
#include <IO.H>
#include <ShlObj.H>

#ifndef __MFC__
#include "Trace.H"
#endif

#include "AssertX.H"
#include "StringHelper.Hpp"
#include "OSVersion.Hpp"
#include "Registry.Hpp"
#include "Reminder.Hpp"
#include "Path.Hpp"


//--- Debugee --------------------------------------------------------------

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#ifdef __MFC__
#define new DEBUG_NEW
#endif // __MFC__
#endif // _DEBUG


//-------------------------------------------------------------
// Pre     :
// Post    : 
// Globals :
// I/O     :
// Task    : Create a string of length nDigits containing random digits
//-------------------------------------------------------------
static string RandomDigits(int nDigits)
{
    // Keep the number of digits in a rational limit
    ASSERTX(nDigits >  0);
    ASSERTX(nDigits < 20);
    
	int    nDigits2 = nDigits;
	string Digits;
    TCHAR  next_8_digits[9];
    while(nDigits2 > 0)
    {
        SPRINTF(next_8_digits,_T("%08lx"),GetTickCount());

        for(int i=0; i<8; i++)
        {
            Digits += next_8_digits[i];
            if(--nDigits2 == 0)
                break;
        }
    }

    int last_digit =rand();
    if(last_digit < 0)
        last_digit =(-last_digit);
    last_digit %= 10;
    Digits[nDigits - 1] ='0' + last_digit;
    
	return Digits;
}

//-------------------------------------------------------------
// Pre     :
// Post    : 
// Globals :
// I/O     :
// Task    : Helper function for the various CPath constructors. 
//           Initializes the data members and establishes various
//           class invariants
//-------------------------------------------------------------
inline void CPath::Init()
{
	m_dwFindFileAttributes =0;
	m_hFindFile =NULL;
}

//-------------------------------------------------------------
// Pre     :
// Post    : 
// Globals :
// I/O     :
// Task    : Helper function for the various CPath destructors.
//           Cleans up varios internals
//-------------------------------------------------------------
inline void CPath::Exit()
{
	if(m_hFindFile != NULL)
    {
		FindClose(m_hFindFile);
        m_hFindFile =NULL;
    }
}

//-------------------------------------------------------------
// Pre     :
// Post    : 
// Globals :
// I/O     :
// Task    : Constructs a path
//-------------------------------------------------------------
CPath::CPath()
{
	Init();
    Empty();
}

//-------------------------------------------------------------
// Pre     :
// Post    : 
// Globals :
// I/O     :
// Task    : Constructs a path as copy of another
//-------------------------------------------------------------
CPath::CPath(const CPath& rPath)
{
	Init();
	m_strPath =rPath.m_strPath;
}

//-------------------------------------------------------------
// Pre     :
// Post    : 
// Globals :
// I/O     :
// Task    : Constructs a path and points it 2 lpszPath
//-------------------------------------------------------------
CPath::CPath(LPCTSTR lpszPath)
{
	Init();
    m_strPath =lpszPath ? lpszPath : _T("");
}

//-------------------------------------------------------------
// Pre     :
// Post    : 
// Globals :
// I/O     :
// Task    : Constructs a path and points it 2 strPath
//-------------------------------------------------------------
CPath::CPath(const string& strPath)
{
    Init();
    m_strPath =strPath;
}

//-------------------------------------------------------------
// Pre     :
// Post    : 
// Globals :
// I/O     :
// Task    : Constructs a path and points it 2 specified 
//           special directory
//-------------------------------------------------------------
CPath::CPath(SpecialDirectoryType eInitialDir)
{
	Init();
    switch(eInitialDir)
    {	
        // Application's current directory	 
        case CURRENT_DIRECTORY:
            CurrentDirectory();
            break;
        // Windows directory
        case WINDOWS_DIRECTORY:
            WindowsDirectory();
            break;
        // Windows' system directory    
        case SYSTEM_DIRECTORY:
            SystemDirectory();
            break;
        // The root directory of system drive
        case SYSTEM_DRIVE_ROOT_DIRECTORY:
            SystemDriveRootDirectory();
            break;
        // The directory where the executable of this app is
        case MODULE_DIRECTORY:
            #ifdef __MFC__
            ModuleDirectory();
            #else
            ASSERTX(FALSE);
            #endif
            break;
        // Windows temp directory
		case TEMP_DIRECTORY:
			TempDirectory();
			break;

        // Program files directory
        case PROGRAM_FILES_DIRECTORY:
            ProgramFilesDirectory();
            break;
        // Common files directory
        case COMMON_FILES_DIRECTORY:
            CommonFilesDirectory();
            break;
        // Accessories directory
        case ACCESSORIES_DIRECTORY:
            AccessoriesDirectory();
            break;
        // Media directory
        case MEDIA_DIRECTORY:
            MediaDirectory();
            break;
        // INF directory
        case DEVICE_DIRECTORY:
            DeviceDirectory();
            break;

        // User specific directories
        case USER_DESKTOP_DIRECTORY:
            UserDesktopDirectory();
            break;
        case USER_FAVORITES_DIRECTORY:
            UserFavoritesDirectory();
            break;
        case USER_FONTS_DIRECTORY:
            UserFontsDirectory();
            break;
        case USER_NETHOOD_DIRECTORY:
            UserNetworkNeighbourhoodDirectory();
            break;
        case USER_DOCUMENTS_DIRECTORY:
            UserDocumentsDirectory();
            break;
        case USER_RECENT_DIRECTORY:
            UserRecentDirectory();
            break;
        case USER_SENDTO_DIRECTORY:
            UserSendToDirectory();
            break;
        case USER_RECYCLE_DIRECTORY:
            UserRecycleBinDirectory();
            break;
        case USER_APPLICATION_DATA_DIRECTORY:
            UserApplicationDataDirectory();
            break;
        case USER_TEMPLATES_DIRECTORY:
            UserTemplatesDirectory();
            break;
        case USER_STARTMENU_DIRECTORY:
            UserStartMenuDirectory();
            break;
        case USER_STARTMENU_STARTUP_DIRECTORY:
            UserStartMenuStartupDirectory();
            break;
        case USER_STARTMENU_PROGRAMS_DIRECTORY:
            UserStartMenuProgramsDirectory();
            break;

        // Directories common 2 all users
        case COMMON_DESKTOP_DIRECTORY:
            CommonDesktopDirectory();
            break;
        case COMMON_STARTMENU_DIRECTORY:
            CommonStartMenuDirectory();
            break;
        case COMMON_STARTMENU_STARTUP_DIRECTORY:
            CommonStartMenuStartupDirectory();
            break;
        case COMMON_STARTMENU_PROGRAMS_DIRECTORY:
            CommonStartMenuProgramsDirectory();
            break;

        // Unknown special directory constant    
        default:
            // Accept only constants we know about
            ASSERTX(FALSE);
    }
}

//-------------------------------------------------------------
// Pre     :
// Post    : 
// Globals :
// I/O     :
// Task    : Cleanup and destruct a path object
//-------------------------------------------------------------
CPath::~CPath()
{
	Exit();
}

//-------------------------------------------------------------
// Pre     :
// Post    : Return TRUE if paths are equal
// Globals :
// I/O     :
// Task    : Check if the two path are the same
//-------------------------------------------------------------
BOOL CPath::operator ==(const CPath& rPath) const
{
    // Get fully qualified versions of the paths
	string FullyQualified1;
    string FullyQualified2;
	
	GetFullyQualified(FullyQualified1);
	rPath.GetFullyQualified(FullyQualified2);
	
    // Compare them
	return STRICMP(FullyQualified1.c_str(),FullyQualified2.c_str()) == 0;
}

//-------------------------------------------------------------
// Pre     :
// Post    : Return TRUE if paths are different
// Globals :
// I/O     :
// Task    : Check if the two path are different
//-------------------------------------------------------------
BOOL CPath::operator !=(const CPath& rPath) const
{
    return !(*this == rPath);
}

//-------------------------------------------------------------
// Pre     :
// Post    : 
// Globals :
// I/O     :
// Task    : Assign a path 2 another
//-------------------------------------------------------------
CPath& CPath::operator =(const CPath& rPath)
{                   
	if(this != &rPath)
		m_strPath =rPath.m_strPath;
		    
    return *this;
}

//-------------------------------------------------------------
// Pre     :
// Post    : Return the path, so that assignements can be chained
// Globals :
// I/O     :
// Task    : Assign a string 2 a path
//-------------------------------------------------------------
CPath& CPath::operator =(LPCTSTR lpszPath)
{
    m_strPath =lpszPath ? lpszPath : _T("");
    return *this;
}

//-------------------------------------------------------------
// Pre     :
// Post    : Return the path, so that assignements can be chained
// Globals :
// I/O     :
// Task    : Assign a string 2 a path
//-------------------------------------------------------------
CPath& CPath::operator =(const string& strPath)
{
    m_strPath =strPath;
    return *this;
}

//-------------------------------------------------------------
// Pre     :
// Post    : Converts path 2 string
// Globals :
// I/O     :
// Task    : Convert path 2 string
//           Warning: because this pointer 2 string point in the data
//           of this class, it is possible 2 cast the result of this 
//           function in any non-constant pointer and alter the data.
//           Very dangerous
//-------------------------------------------------------------
CPath::operator LPCTSTR() const
{
    return (LPCTSTR)m_strPath.c_str();
}

//-------------------------------------------------------------
// Pre     :
// Post    : Returns the drive component without a colon, e.g. "c"
//           Returns the directory component with a leading backslash, 
//              but no trailing backslash, e.g. "\dir\subdir"
//           Returns name compleletely without delimiters, e.g "letter"
//           Returns extension completely without delimiters, e.g. "doc"
// Globals :
// I/O     :
// Task    : Return the individual components of this path. 
//           For any given argument, you can pass NULL if you are not 
//           interested in that component.
//           Do not rely on pNames being <= 8 characters, extensions 
//           being <= 3 characters, or drives being 1 character
//-------------------------------------------------------------
void CPath::GetComponents(string* pDrive, 
                       	  string* pDirectory, 
                       	  string* pName, 
                          string* pExtension) const
{
    TCHAR buff_drive[_MAX_DRIVE + 1];
    TCHAR buff_dir  [_MAX_DIR   + 1];
    TCHAR buff_name [_MAX_FNAME + 1];
    TCHAR buff_ext  [_MAX_EXT   + 1];

    ZeroMemory(buff_drive,sizeof(buff_drive));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -