📄 oxunc.h
字号:
// ==========================================================================
// Class Specification : COXUNC
// ==========================================================================
// $Archive:: /MFCEXT/Samples/URLDemo/OXUNC.h $
// Source : R.Mortelmans
// Creation Date : 8th November 1996
// $Author:: Roel $
// $Date:: 18/07/97 17:46 $
// $Revision:: 11 $
// //////////////////////////////////////////////////////////////////////////
// Properties:
// NO Abstract class (does not have any objects)
// YES Derived from CObject
// NO Is a Cwnd.
// NO Two stage creation (constructor & Create())
// NO Has a message map
// NO Needs a resource (template)
// NO Persistent objects (saveable on disk)
// NO Uses exceptions
// //////////////////////////////////////////////////////////////////////////
// Desciption :
// This class encapsulates a full path specification
// A COXUNC object can have three different forms
// - Strict UNC : \\Server\Share\Directory\File.ext
// - Local path : C:\Directory\File.ext
// - URL part : www.periphere.com/directory/file.ext
// A UNC must always start with a double slash
// A URL must be explicitly marked as URL part (URLPart())
// Other COXUNC objects or local paths
// To put a directory in a COXUNC object let it end in a (back)slash
// E.g. C:\Temp\ is a directory
// C:\Test is a file
// Remark:
// This class makes no differences between a slash "/" and a backslash "\"
// If a directory is specified it always ends in a (back)slash
// If the directory is absolute it also starts with a (back)slash
// All public functions which do not start with a verb access only
// the internal structure of the object and do not perform an action
// on the actual file system (like rename, delete etc.)
// Two conversion operators that were present in a previous version of this class
// have been replaced by an explicit function call
// operator const CString() const; -> const CString Full() const;
// operator CString&(); -> CString& Full();
// Prerequisites (necessary conditions):
/////////////////////////////////////////////////////////////////////////////
#ifndef __OXUNC_H__
#define __OXUNC_H__
class COXUNCStandardActor;
class AFX_EXT_CLASS COXUNC : public CObject
{
friend class COXURL;
DECLARE_SERIAL(COXUNC)
// Data members -------------------------------------------------------------
protected:
// ... The full UNC string must be the first data member
CString m_sUNC;
public:
static const TCHAR m_cNull;
// --- NULL character
static const TCHAR m_cSlash;
// --- Slash character
static const TCHAR m_cBackslash;
// --- Backslash character
static const TCHAR m_cColon;
// --- Colon character
static const TCHAR m_cDot;
// --- Dot character
static const LPCTSTR m_pszSlashes;
// --- String containing slash and backslash
static const LPCTSTR m_pszInvalidChars;
// --- String caontaing illegal file characters
static const LPCTSTR m_pszSpecialChars;
// --- String containing valid characters that have a special meaning
protected:
BOOL m_bMainBuilt;
CString m_sServer;
CString m_sShare;
CString m_sDirectory;
CString m_sFile;
BOOL m_bPartsBuilt;
BOOL m_bURLPart;
HRESULT m_nLastError;
COXUNCStandardActor* m_pActor;
private:
// Member functions ---------------------------------------------------------
public:
COXUNC(LPCTSTR pszUNC = NULL, BOOL bURLPart = FALSE);
// --- In : pszURL : Full UNC specification
// bURLPart : Whether this UNC is part of a URL
// --- Out :
// --- Returns :
// --- Effect : Constructor of the object
COXUNC(LPCTSTR pszServer, LPCTSTR pszShare, LPCTSTR pszDirectory, LPCTSTR pszFile, BOOL bURLPart = FALSE);
// --- In : pszServer :
// pszShare :
// pszDirectory :
// pszFile :
// bURLPart : Whether this UNC is part of a URL
// --- Out :
// --- Returns :
// --- Effect : Constructor of the object
COXUNC(const COXUNC& UNC);
// --- In : UNC : Source UNC
// --- Out :
// --- Returns :
// --- Effect : Copy constructor
COXUNC& operator=(const COXUNC& UNC);
COXUNC& operator=(LPCTSTR pszUNC);
// --- In : UNC : Source UNC
// --- Out :
// --- Returns : This object
// --- Effect : Assignment operator
// operator const CString() const;
const CString Full() const;
const CString Server() const;
const CString Share() const;
const CString Directory() const;
const CString File() const;
const CString Base() const;
const CString Extension(BOOL bIncludeDot= TRUE) const;
const BOOL URLPart() const;
const HRESULT LastError() const;
// --- In :
// --- Out :
// --- Returns : The complete UNC or the requested part
// --- Effect : Retrieves the requested value (cannot be changed)
// The Title is the full path specification without the extension
// and it may be abbreviated (some directories replaced by ...)
// The Root is the root directory spoecification of this UNC
operator LPCTSTR();
CString& Full();
CString& Server();
CString& Share();
CString& Directory();
CString& File();
BOOL& URLPart();
HRESULT& LastError();
// --- In :
// --- Out :
// --- Returns : A reference to the complete UNC or the requested part
// --- Effect : Retrieves the requested value
// You can change the value by assigning a new value
// Do not store this reference for later use !
// *** Requesting a UNC in a different form
TCHAR PreferedSlash() const;
// --- In :
// --- Out :
// --- Returns : The prefered slash character (slash or backslash)
// --- Effect : The result depends on whether this a part of a URL ("/") or not ("\")
CString StandardForm() const;
// --- In :
// --- Out :
// --- Returns : A standard form of this UNC
// The standard form uses all backslashes if it not marked a part
// of a URL, otherwise it uses all slashes
// All characters are converted to lower case letters
// The standard form is usefull for comparisons
// --- Effect :
CString FileForm() const;
// --- In :
// --- Out :
// --- Returns : The UNC, but if it specifies a directory, the terminating
// slash is removed. One exception is the root directory,
// this always ends in a slash
// --- Effect :
BOOL IsEmpty() const;
// --- In :
// --- Out :
// --- Returns :
// --- Effect : Clears the contents
void Empty();
// --- In :
// --- Out :
// --- Returns :
// --- Effect : Clears the contents
// *** Helper functions
COXUNC GetRoot() const;
// --- In :
// --- Out :
// --- Returns : The root of this UNC
// --- Effect :
COXUNC GetTitle() const;
// --- In :
// --- Out :
// --- Returns : The title of this UNC (everything without the extension)
// --- Effect :
CString GetAbbreviation(int nMaxLength, BOOL bAtLeastFile = TRUE) const;
// --- In : nMaxLength : The maximum length of return string
// bAtLeastFile : Whether at least the file name should be included
// even when the maximum length is exceeded
// --- Out :
// --- Returns : The abbreviated UNC (some parts will be replaced by "..."
// --- Effect :
// *** General actions
BOOL MakeAbsolute();
// --- In :
// --- Out :
// --- Returns : Whether it succceeded or not (sets LastError())
// --- Effect : Make a relative UNC into an absolute using the current drive and directory
BOOL Exists();
// --- In :
// --- Out :
// --- Returns : Whether it exists or not
// FALSE is also returned in case of an error (sets LastError())
// --- Effect : Checks whether the specified directory or file exists
// Note that when queried whether a directory exists
// and a file with the specified name is found, FALSE is returned
// So both the name and the type (directory/file) must match
BOOL Create();
// --- In :
// --- Out :
// --- Returns : Whether it succeeded or not (sets LastError())
// --- Effect : Creates the specified directory or file
BOOL CreateTemporaryFile(LPCTSTR pszPrefix = NULL);
// --- In : pszPrefix : The prefix that should be used in the file name
// --- Out :
// --- Returns : Whether it succeeded or not (sets LastError())
// --- Effect : Creates an empty file in the temporary directory
BOOL Copy(COXUNC destinationUNC, BOOL bReplaceExisting = FALSE);
// --- In : destinationUNC :
// bReplaceExisting : Whether an already existing destination should be overwritten
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -