コード例 #1
0
ファイル: ChmDoc.cpp プロジェクト: seancassell/sumatrapdf
bool ChmDoc::Load(const WCHAR *fileName)
{
    chmHandle = chm_open((WCHAR *)fileName);
    if (!chmHandle)
        return false;

    ParseWindowsData();
    if (!ParseSystemData())
        return false;

    UINT fileCodepage = codepage;
    char header[24] = { 0 };
    if (file::ReadN(fileName, header, sizeof(header))) {
        DWORD lcid = ByteReader(header, sizeof(header)).DWordLE(20);
        fileCodepage = LcidToCodepage(lcid);
    }
    if (!codepage)
        codepage = fileCodepage;
    // if file and #SYSTEM codepage disagree, prefer #SYSTEM's (unless it leads to wrong paths)
    FixPathCodepage(homePath, fileCodepage);
    FixPathCodepage(tocPath, fileCodepage);
    FixPathCodepage(indexPath, fileCodepage);
    if (GetACP() == codepage)
        codepage = CP_ACP;

    if (!HasData(homePath)) {
        const char *pathsToTest[] = {
            "/index.htm", "/index.html", "/default.htm", "/default.html"
        };
        for (int i = 0; i < dimof(pathsToTest); i++) {
            if (HasData(pathsToTest[i])) {
                homePath.SetCopy(pathsToTest[i]);
            }
        }
        if (!HasData(homePath))
            return false;
    }

    return true;
}
コード例 #2
0
ファイル: ChmDoc.cpp プロジェクト: azaleafisitania/sumatrapdf
bool ChmDoc::Load(const WCHAR *fileName)
{
    chmHandle = chm_open((WCHAR *)fileName);
    if (!chmHandle)
        return false;

    ParseWindowsData();
    if (!ParseSystemData())
        return false;

    if (!HasData(homePath)) {
        const char *pathsToTest[] = {
            "/index.htm", "/index.html", "/default.htm", "/default.html"
        };
        for (int i = 0; i < dimof(pathsToTest); i++) {
            if (HasData(pathsToTest[i]))
                homePath.Set(str::Dup(pathsToTest[i]));
        }
    }
    if (!HasData(homePath))
        return false;

    if (!codepage) {
        char header[24];
        if (file::ReadAll(fileName, header, sizeof(header))) {
            DWORD lcid = ByteReader(header, sizeof(header)).DWordLE(20);
            codepage = LcidToCodepage(lcid);
        }
        else
            codepage = CP_CHM_DEFAULT;
    }
    if (GetACP() == codepage)
        codepage = CP_ACP;

    return true;
}