Exemple #1
0
wxFSFile* wxZipFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
{
    wxString right = GetRightLocation(location);
    wxString left = GetLeftLocation(location);
    wxZipInputStream *s;

    if (right.Contains(wxT("./")))
    {
        if (right.GetChar(0) != wxT('/')) right = wxT('/') + right;
        wxFileName rightPart(right, wxPATH_UNIX);
        rightPart.Normalize(wxPATH_NORM_DOTS, wxT("/"), wxPATH_UNIX);
        right = rightPart.GetFullPath(wxPATH_UNIX);
    }

    if (right.GetChar(0) == wxT('/')) right = right.Mid(1);

    // a new wxFileSystem object is needed here to avoid infinite recursion
    wxFSFile *leftFile = wxFileSystem().OpenFile(left);
    if (!leftFile)
       return NULL;

    s = new wxZipFSInputStream(leftFile);
    if (s && s->IsOk())
    {
       bool found = false;
       while (!found)
       {
           wxZipEntry *ent = s->GetNextEntry();
           if (!ent)
               break;
           if (ent->GetInternalName() == right)
               found = true;
           delete ent;
       }
       if (found)
           return new wxFSFile(s,
                            left + wxT("#zip:") + right,
                            GetMimeTypeFromExt(location),
                            GetAnchor(location)
#if wxUSE_DATETIME
                            , wxDateTime(wxFileModificationTime(left))
#endif // wxUSE_DATETIME
                            );
    }

    delete s;
    return NULL;
}
void tst_QMessageAuthenticationCode::result_incremental()
{
    QFETCH(QCryptographicHash::Algorithm, algo);
    QFETCH(QByteArray, key);
    QFETCH(QByteArray, message);
    QFETCH(QByteArray, code);

    int index = message.length() / 2;
    QByteArray leftPart(message.mid(0, index));
    QByteArray rightPart(message.mid(index));

    QCOMPARE(leftPart + rightPart, message);

    QMessageAuthenticationCode mac(algo);
    mac.setKey(key);
    mac.addData(leftPart);
    mac.addData(rightPart);
    QByteArray result = mac.result();

    QCOMPARE(result, code);
}
Exemple #3
0
wxFSFile* wxArchiveFSHandler::OpenFile(
        wxFileSystem& WXUNUSED(fs),
        const wxString& location)
{
    wxString right = GetRightLocation(location);
    wxString left = GetLeftLocation(location);
    wxString protocol = GetProtocol(location);
    wxString key = left + wxT("#") + protocol + wxT(":");

    if (right.Contains(wxT("./")))
    {
        if (right.GetChar(0) != wxT('/')) right = wxT('/') + right;
        wxFileName rightPart(right, wxPATH_UNIX);
        rightPart.Normalize(wxPATH_NORM_DOTS, wxT("/"), wxPATH_UNIX);
        right = rightPart.GetFullPath(wxPATH_UNIX);
    }

    if (right.GetChar(0) == wxT('/')) right = right.Mid(1);

    if (!m_cache)
        m_cache = new wxArchiveFSCache;

    const wxArchiveClassFactory *factory;
    factory = wxArchiveClassFactory::Find(protocol);
    if (!factory)
        return NULL;

    wxArchiveFSCacheData *cached = m_cache->Get(key);
    if (!cached)
    {
        wxFSFile *leftFile = m_fs.OpenFile(left);
        if (!leftFile)
            return NULL;
        cached = m_cache->Add(key, *factory, leftFile->DetachStream());
        delete leftFile;
    }

    wxArchiveEntry *entry = cached->Get(right);
    if (!entry)
        return NULL;

    wxInputStream *leftStream = cached->NewStream();
    if (!leftStream)
    {
        wxFSFile *leftFile = m_fs.OpenFile(left);
        if (!leftFile)
            return NULL;
        leftStream = leftFile->DetachStream();
        delete leftFile;
    }

    wxArchiveInputStream *s = factory->NewStream(leftStream);
    if ( !s )
        return NULL;

    s->OpenEntry(*entry);

    if (!s->IsOk())
    {
        delete s;
        return NULL;
    }

#if WXWIN_COMPATIBILITY_2_6 && wxUSE_ZIPSTREAM
    if (factory->IsKindOf(CLASSINFO(wxZipClassFactory)))
        ((wxZipInputStream*)s)->m_allowSeeking = true;
#endif // WXWIN_COMPATIBILITY_2_6

    return new wxFSFile(s,
                        key + right,
                        wxEmptyString,
                        GetAnchor(location)
#if wxUSE_DATETIME
                        , entry->GetDateTime()
#endif // wxUSE_DATETIME
                        );
}
Exemple #4
0
/*
        Open one file, probe to see if there is several file with contiguous name
        and handle them as one big file if that's the case

        If multi is set to probe, return value will be APPEND if there is several files, dont_append if one
        if multi is set to dont_append, file won't be auto appended even if they exist
*/
uint8_t fileParser::open( const char *filename,FP_TYPE *multi )
{

        uint32_t decimals = 0;               // number of decimals
        char *left = NULL, *right = NULL; // parts of filename (after splitting)

        uint8_t count = 0;                  // number of follow-ups
        uint32_t base=0;
        bool splitFile=false;
//        int i = 0;      
        // index (general use)
        if(*multi!=FP_DONT_APPEND)
        {
            aprintf("Checking if there are several files...\n");
            splitFile=ADM_splitSequencedFile(filename, &left, &right,&decimals,&base);
            if(splitFile)
            {   
                aprintf("left:<%s>, right=<%s>,base=%" PRIu32",digit=%" PRIu32"\n",left,right,base,decimals);
            }else       
            {
                aprintf("No.\n");
            }
        }
        // ____________________
        // Single loading
        // ____________________
        if( false ==splitFile )
        {
                fdIo newFd;
                aprintf( "\nSimple loading: \n" );
                _curFd = 0;
                FILE *f=NULL;
                // open file
                if(! (f = ADM_fopen(filename, "rb")) )
                  { return 0; }
                newFd.file=f;
                // calculate file-size
                fseeko( f, 0, SEEK_END );
                 newFd.fileSize = ftello( f );
                fseeko( f, 0, SEEK_SET );
                 newFd.fileSizeCumul=0;
                _size=newFd.fileSize;
                listOfFd.append(newFd);
                aprintf( " file: %s, size: %" PRIu64"\n", filename, newFd.fileSize );
                aprintf( " found 1 files \n" );
                aprintf( "Done \n" );
                return 1;
        }
        // ____________________
        // Multi loading
        // ____________________
        uint32_t tabSize;
        std::string leftPart(left);
        std::string rightPart(right);
        delete [] left;
        delete [] right;
        left=NULL;
        right=NULL;
    
        aprintf( "\nAuto adding: \n" );
        uint32_t current=base;
        _curFd = 0;
        uint64_t total=0;
        
        // build match string
        char match[16];
        match[0]='%';
        match[1]='0';
        sprintf(match+2,"%d",decimals); // snprintf instead ...
        strcat(match,"d");
        match[15]=0;
        aprintf("Using %s as match string\n",match);
        char number[16];
        while(1)
        {
                sprintf(number,match,current);
                std::string middle(number);
                std::string outName=leftPart+middle+rightPart;
                aprintf("Checking %s\n",outName.c_str());

                // open file
                FILE *f= ADM_fopen(outName.c_str(), "rb");
                if(!f)
                {
                        // we need at least one file!
                        if( !count  )
                          { return 0; }
                        else
                          { 
                                printf( " file: %s not found. \n", outName.c_str() ); 
                                break; 
                          }
                }

                // calculate file-size
                fdIo myFd;
                myFd.file=f;
                myFd.fileSize=ADM_fileSize(outName.c_str());
                myFd.fileSizeCumul = total;
                total+=  myFd.fileSize;

                aprintf( " file %d: %s, size: %" PRIu64"\n", (count + 1), outName.c_str(),
                                            myFd.fileSize );

                listOfFd.append(myFd);
                count++;
                current++;
        } 

      
        _size=total;
        // clean up
        if(*multi==FP_PROBE)
        {
                if(count>1)
                        *multi=FP_APPEND;       //
                else
                        *multi=FP_DONT_APPEND;
        }

        aprintf( " found %d files \n", count );
        aprintf( "Done \n" );
        return 1;
} // fileParser::open()