示例#1
0
bool QuickIndexImpl::Init( const tstring &path, size_t file_number, size_t entry_size, bool read_only )
{
    if (0 == entry_size) {
        return false;
    }
    bool exist = false;
    index_file_path_ = path;//MakePathRegular(path);

    // Write to a temp file
    index_file_path_temp_ = index_file_path_ + _T(".temp");

    if (!IsFileExist(index_file_path_)) {
        if (read_only) {
            return false;
        }
        if (IsFileExist(index_file_path_temp_.c_str())) {
            ::DeleteFile(index_file_path_temp_.c_str());
        }
        DWORD access = GENERIC_READ | GENERIC_WRITE | DELETE;
        HANDLE file = CreateFile(index_file_path_temp_.c_str(), access, NULL, NULL,
            CREATE_ALWAYS, FILE_FLAG_OVERLAPPED, NULL);
        if (INVALID_HANDLE_VALUE == file) {
            return false;
        }
        CloseHandle(file);
        header_ = (QuickIndexHeader*)index_file_.Init(index_file_path_temp_, sizeof(QuickIndexHeader));
        index_file_modify_ = true;
    }
    else {
        exist = true;
        if (GetFileSize(index_file_path_.c_str()) > 0) {
            header_ = (QuickIndexHeader*)index_file_.Init(index_file_path_, 0);
        }
        else {
            header_ = (QuickIndexHeader*)index_file_.Init(index_file_path_, sizeof(QuickIndexHeader));
        }
    }

    if (NULL == header_) {
        return false;
    }

    if (!exist) {
        if (!GenerateHeader(file_number, entry_size)) {
            return false;
        }

        if (!GrowIndexFile()) {
            return false;
        }
    }

    if (!IsHeaderValid()) {
        return false;
    }
    return true;
}
示例#2
0
bool EdiDocument::IsValid(bool doLog) const {
    bool result = IsHeaderValid(doLog); 
    if (result || doLog) {
        for ( size_t row = 0; row < GetNumberRows(); row++ ) {
            for ( size_t col = 0; col < GetColCount(); col++ ) {
                if ( !IsValidValue(row, col, doLog) ) {
                    if ( !doLog )  {
                      return false;
                    } else {
                      result = false;
                    }
                } 
            }
        }
    }
    return result;
};