Пример #1
0
static HRESULT WINAPI ITSS_IStorageImpl_EnumElements(
    IStorage* iface,
    DWORD reserved1,
    void* reserved2,
    DWORD reserved3,
    IEnumSTATSTG** ppenum)
{
    ITSS_IStorageImpl *This = impl_from_IStorage(iface);
    IEnumSTATSTG_Impl* stgenum;

    TRACE("%p %d %p %d %p\n", This, reserved1, reserved2, reserved3, ppenum );

    stgenum = ITSS_create_enum();
    if( !stgenum )
        return E_FAIL;

    chm_enumerate_dir(This->chmfile,
                  This->dir,
                  CHM_ENUMERATE_ALL,
                  ITSS_chm_enumerator,
                  stgenum );

    stgenum->current = stgenum->first;

    *ppenum = &stgenum->IEnumSTATSTG_iface;

    return S_OK;
}
Пример #2
0
/*
 * Class:     org_chm4j_ChmFile
 * Method:    entries
 * Signature: (Ljava/lang/String;I)[Lorg/chm4j/ChmEntry;
 */
JNIEXPORT jobjectArray JNICALL Java_org_chm4j_ChmFile_entries
(JNIEnv *env, jobject jobj, jstring jfilename, jstring jpath, jint flags) {

    // opens the file
    const char *filename = (*env)->GetStringUTFChars(env, jfilename, 0);
    struct chmFile* cFile =  chm_open(filename);
    if(cFile == NULL) {
        J_ThrowException(env, "java/io/IOException", "failed to open the file");
        return NULL;
    }
    (*env)->ReleaseStringUTFChars(env, jfilename, filename);

    // creates java list
    jobject list = J_CreateList(env);
    if(list == NULL) {
        // close the file
        chm_close(cFile);
        J_ThrowException(env, "java/io/IOException", "failed to create entries list");
        return NULL;
    }

    // initializes context
    ENUM_CONTEXT* context = (ENUM_CONTEXT*) malloc(sizeof(ENUM_CONTEXT));
    if(context == NULL) {
        // close the file
        chm_close(cFile);
        J_ThrowException(env, "java/io/IOException", "failed to create entries context");
        return NULL;
    }
    context->env = env;
    context->file = jobj;
    context->list = list;

    // enumerates entries
    const char *path = (*env)->GetStringUTFChars(env, jpath, NULL);
    int enumres = chm_enumerate_dir(cFile, path, (int) flags, listEntries, context);
    (*env)->ReleaseStringUTFChars(env, jpath, path);
    free(context);

    // closes the file
    chm_close(cFile);

    if(enumres != 1) {
        J_ThrowException(env, "java/io/IOException", "failed to list entries");
        return NULL;
    }

    // returns a java array
    jobjectArray array = J_ListToArray(env, list);
    return array;
}