使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 4905e2e7537d507f218e8e9595485e09d9f3a2b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//=========================================================
// AsFile.h : head file Code from Notepadre
// Õë¶Ô²»Í¬±àÂë¸ñʽÎļþµÄ¶Áд´¦Àí
//
// Author:asoft
// Modify:2009/07/03
//-----------------------------------------------
// Ó÷¨:
//  ReadÎļþ
//    CFile                    file;
//    HLOCAL                    memBuffer;
//    CAsFile::e_FileType        eFileType   = CAsFile::eAutoFileType;
//    CAsFile::e_FileFormat    eFileFormat = CAsFile::eAutoFileFormat;
//    DWORD                    dwNewSize;
//    TCHAR                    *pBuffer = NULL;
//    CString                    strData;
 
//    TRY
//    {        
//        if ( !file.Open( strXMLPath, CFile::shareDenyWrite | CFile::modeRead ) )
//            return false;
//        memBuffer = CAsFile::Load( &file, eFileType, eFileFormat, dwNewSize );
//        file.Close( );
//        pBuffer = static_cast<TCHAR*> (::LocalLock (memBuffer));
//        _tcscpy_s( strData.GetBuffer( dwNewSize ), dwNewSize, pBuffer );
//        strData.ReleaseBuffer( );
 
//        ::LocalUnlock( memBuffer );
//        ::LocalFree( memBuffer );        
//    }
//    CATCH_ALL(e)
//    {
//        file.Close( );
//        THROW_LAST ();
//    }
//    END_CATCH_ALL
 
//  SaveÎļþ
//    CFile    file;
//
//    TRY
//    {    
//        if ( !file.Open( strFilePath, CFile::modeCreate | CFile::modeWrite ) )
//            return false;
//        CAsFile::Save( strData.GetBuffer( strData.GetLength() ), 
//                    strData.GetLength(), CAsFile::eUTF8, CAsFile::eWindows, &file );
//        file.Close( );
//    }
//    CATCH_ALL(e)
//    {
//        file.Close( );
//        THROW_LAST ();
//    }
//    END_CATCH_ALL
//-----------------------------------------------
//
//=========================================================
 
#pragma once
#include "afx.h"
 
class CAsFile :
    public CObject
{
public:
    CAsFile(void);
    ~CAsFile(void);
 
public:
    enum e_FileType {eANSI, eUnicode, eUnicodeBigEndian, eUTF8, eAutoFileType,
        eINVALID};
    enum e_FileFormat {eWindows, eUNIX, eMacintosh, eAutoFileFormat};
 
    static HLOCAL Load (CFile *pFile, e_FileType &eFileType,
        e_FileFormat &eFileFormat, DWORD &dwNewSize);
    static void Save (const TCHAR *pszText, const DWORD dwChars,
        const e_FileType eFileType, const e_FileFormat eFileFormat,
        CFile *pFile);
 
private:
    static const DWORD m_dwBufferSize;
 
    static void Read (CFile *pFile, unsigned char *pucText,
        const DWORD dwSize);
    static void GetFileType (CFile *pFile, e_FileType &eFileType,
        DWORD &dwSize);
    static DWORD CountBytes (unsigned char *pucText, const DWORD dwSize,
        const e_FileType &eFileType, e_FileFormat &eFileFormat);
    static DWORD CountCharsANSI (const unsigned char *pucText,
        const DWORD dwSize, unsigned __int64 &ui64Windows,
        unsigned __int64 &ui64UNIX, unsigned __int64 &ui64Macintosh);
    static DWORD CountCharsUnicode (const TCHAR *pszText, const DWORD dwSize,
        unsigned __int64 &ui64Windows, unsigned __int64 &ui64UNIX,
        unsigned __int64 &ui64Macintosh);
    // Special case: byte swap whilst counting for efficiencies sake
    static DWORD CountCharsUnicodeBE (TCHAR *pszText,
        const DWORD dwSize, unsigned __int64 &ui64Windows,
        unsigned __int64 &ui64UNIX, unsigned __int64 &ui64Macintosh);
    static DWORD CountCharsUTF8 (const unsigned char *pucText,
        const DWORD dwSize, unsigned __int64 &ui64Windows,
        unsigned __int64 &ui64UNIX, unsigned __int64 &ui64Macintosh);
    inline static wchar_t Swap (wchar_t wc);
    static DWORD CheckUTF8Char (const unsigned char *pucBytes, const DWORD dwCharsLeft);
    static DWORD DecodeUTF8Char (const unsigned char * &pucBytes, wchar_t &wcChar);
    static void LoadUTF8File (CFile *pFile, const e_FileFormat eFileFormat,
        wchar_t *pszText, const DWORD dwSize);
    static void ExpandText (TCHAR *pszText, const DWORD dwSize,
        const DWORD dwChars, const e_FileType eFileType,
        const e_FileFormat eFileFormat);
    static void ZerosToSpaces (TCHAR *pszText, const DWORD dwChars);
    static void SaveHeader (CFile *pFile, const e_FileType eFileType);
    static void FillBuffer (const TCHAR * &lpszText, DWORD &dwCharCount,
        const e_FileType eFileType, const e_FileFormat eFileFormat,
        unsigned char *ucBuffer, const DWORD dwBufferSize, DWORD &dwSize);
 
};