📄 cfile.cpp
字号:
#include "CFile.hpp"
#include "CString.hpp"
bool CFile::Open(LPTSTR File,Mode CMode,DWORD Beh)
{
Close();
WasCreatd = FALSE;
SECURITY_ATTRIBUTES sa;
sa.nLength=sizeof(sa);
sa.lpSecurityDescriptor=NULL;
sa.bInheritHandle=FALSE;
BOOL Rt=((handle=CreateFile(
File, // pointer to name of the file
(CMode == RdOnly)?GENERIC_READ:GENERIC_READ|GENERIC_WRITE, // access (read-write) mode
(CMode == RdOnly)
?((CMode == Shared) ?FILE_SHARE_READ:0)
:((CMode == Shared) ? FILE_SHARE_READ|FILE_SHARE_WRITE:0), // share mode
&sa, // pointer to security descriptor
Beh, // how to create
FILE_ATTRIBUTE_NORMAL, // file attributes
NULL // handle to file with attributes to copy
)) != INVALID_HANDLE_VALUE);
if (Rt && Beh==OPEN_ALWAYS) {
WasCreatd = (GetLastError()!=ERROR_ALREADY_EXISTS);
}
return (Rt==TRUE);
}
bool CFile::Close()
{
BOOL Rt=TRUE;
if ( IsOpen() ) Rt = CloseHandle(handle);
handle=INVALID_HANDLE_VALUE;
return Rt==TRUE;
}
bool CFile::SetSize(DWORD Size)
{
if (Seek(Size,SEEK_SET)!=Size) return FALSE;
return SetEndOfFile(handle)==TRUE;
}
/***
* strnicmp
**************************************************************/
int lstrnicmp (LPTSTR s1x, LPTSTR s2x, int maxlen)
{
LPTSTR s1;
LPTSTR s2;
s1=(LPTSTR)s1x;
s2=(LPTSTR)s2x;
while ( ( (unsigned char) toupper(*s1) == (unsigned char) toupper(*s2) ) && *s1 && *s2 && maxlen>1) {
s1++;
s2++;
maxlen--;
};
return ((int) toupper(*s1)- (int) toupper(*s2));
}
// Wild matching function
bool Wild(LPTSTR pattern, LPTSTR string)
{
int nlit=0;
while (*pattern) {
switch (*pattern) {
case '*':
pattern++;
if (*pattern == 0) {
while (*string && *string!='.') string++;
return ((*string) ? false : true);
}
nlit=0;
while ((pattern[nlit] != 0) && (pattern[nlit] != '*') && (pattern[nlit] != '?') ) nlit++;
while (1) {
if (lstrnicmp(string,pattern, nlit) == 0) break;
string++;
if ( *string == 0) return false;
}
break;
case '?':
if (*string == 0) return false;
pattern++;
string++;
break;
default:
if (toupper(*pattern) != toupper(*string)) return false;
pattern++;
string++;
break;
}
}
return ((*string) ? false : true);
}
CString GetWindowsDirectory()
{
CString ret;
ret.SetLen(MAX_PATH);
ret.SetLen(::GetWindowsDirectory(ret.Ptr(),MAX_PATH));
return ret;
}
CString GetTempDirectory()
{
CString ret;
ret.SetLen(MAX_PATH);
ret.SetLen(::GetTempPath(MAX_PATH,ret.Ptr()));
return ret;
}
// To Delete files
bool DeleteFile(CString& c)
{
return ::DeleteFile(c.Ptr())==TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -