Skip to content

Commit a14d176

Browse files
committed
优化文件io接口
1 parent a73dc10 commit a14d176

1 file changed

Lines changed: 6 additions & 44 deletions

File tree

DmMain/src/Common/DMHelper.cpp

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -103,54 +103,16 @@ namespace DM
103103

104104
bool CheckFileExistW(const wchar_t *pszFilePath)
105105
{
106-
bool bRet = false;
107-
do
108-
{
109-
if (NULL == pszFilePath
110-
|| 0 == wcslen(pszFilePath))
111-
{
112-
break;
113-
}
114-
115-
FILE *fp = NULL;
116-
_wfopen_s(&fp, pszFilePath, L"rb");
117-
if (!fp)
118-
{
119-
break;
120-
}
121-
122-
fclose(fp);
123-
bRet = true;
124-
} while (FALSE);
125-
return bRet;
106+
WIN32_FILE_ATTRIBUTE_DATA fattr = { 0 };
107+
return GetFileAttributesExW(pszFilePath, GetFileExInfoStandard, &fattr) && 0 == (fattr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
126108
}
127109

128110
DWORD GetFileSizeW(const wchar_t *pszFilePath)
129111
{
130-
DWORD dwSize = 0;
131-
do
132-
{
133-
if (NULL == pszFilePath
134-
||0 == wcslen(pszFilePath))
135-
{
136-
break;
137-
}
138-
139-
FILE *fp = NULL;
140-
_wfopen_s(&fp, pszFilePath, L"rb");
141-
if (!fp)
142-
{
143-
break;
144-
}
145-
146-
DWORD pos = ftell(fp);
147-
fseek(fp, 0, SEEK_END);
148-
dwSize = ftell(fp);
149-
fseek(fp, pos, SEEK_SET);
150-
151-
fclose(fp);
152-
} while (FALSE);
153-
return dwSize;
112+
struct _stat64 st;
113+
if (0 == _wstat64(pszFilePath, &st))
114+
return st.st_size;
115+
return 0;
154116
}
155117

156118
bool GetFileBufW(const wchar_t *pszFilePath, void **ppBuf, DWORD dwSize, DWORD &dwReadSize)

0 commit comments

Comments
 (0)