Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <jni.h>
- #include <Windows.h>
- #include <string.h>
- #include "unace/UnACE.h"
- #include "unace/CallbackProc.h"
- #include "throwJNI.h"
- #include "net_sf_junace_UnACE.h"
- #define FILELISTSIZE 32768 // pretty much for this this example:
- // only the commandline can be used to
- // specify files..
- #define COMMENTBUFSIZE 8192 // comments may be up to 32k in size
- // increase it if you want to put that
- // large comments to archives, or if
- // you want to receive all of these large
- // comments (ACE_COMMENT_SMALLBUF returned
- // if comment does not fit into buffer)
- HINSTANCE AceDllInstance;
- CHAR FileList[FILELISTSIZE];
- CHAR CommentBuf[COMMENTBUFSIZE];
- INT (__stdcall *ACEInitDllProc)(pACEInitDllStruc DllData);
- INT (__stdcall *ACEReadArchiveDataProc)(LPSTR ArchiveName, pACEReadArchiveDataStruc ArchiveData);
- INT (__stdcall *ACEListProc)(LPSTR ArchiveName, pACEListStruc List);
- INT (__stdcall *ACETestProc)(LPSTR ArchiveName, pACETestStruc Test);
- INT (__stdcall *ACEExtractProc)(LPSTR ArchiveName, pACEExtractStruc Extract);
- INT CallAceInitDll(void)
- {
- tACEInitDllStruc
- DllData;
- memset(&DllData, 0, sizeof(DllData)); // set all fields to zero
- DllData.GlobalData.MaxArchiveTestBytes = 0x2ffFF; // search for archive
- // header in first 256k
- // of file
- DllData.GlobalData.MaxFileBufSize = 0x2ffFF; // read/write buffer size
- // is 256k
- DllData.GlobalData.Comment.BufSize = sizeof(CommentBuf);
- DllData.GlobalData.Comment.Buf = CommentBuf; // set comment bufffer
- // to receive comments
- // of archive and/or
- // set comments
- DllData.GlobalData.TempDir = "C:\\TEMP"; // set temp dir
- // set callback function pointers
- DllData.GlobalData.InfoCallbackProc = InfoProc;
- DllData.GlobalData.ErrorCallbackProc = ErrorProc;
- DllData.GlobalData.RequestCallbackProc = RequestProc;
- DllData.GlobalData.StateCallbackProc = StateProc;
- return ACEInitDllProc(&DllData);
- }
- JNIEXPORT void JNICALL Java_net_sf_junace_UnACE_nativeACEList
- (JNIEnv *env, jobject jObj1, jstring archiveName, jobject jObj2)
- {
- tACEListStruc List;
- LPSTR str;
- str = (LPSTR)env->GetStringUTFChars(archiveName, NULL);
- if (str == NULL) {
- return; // already thrown OutOfMemoryError
- }
- memset(&List, 0, sizeof(List)); // set all fields to zero
- List.Files.SourceDir = ""; // archive main directory is
- // base directory for FileList
- List.Files.FileList = FileList; // set FileList
- List.Files.ExcludeList = ""; // no files to exclude
- List.Files.FullMatch = 0; // also list files partially matching
- // (for instance: list DIR1\TEST.DAT
- // if FileList specifies TEST.DAT)
- ACEListProc(str, &List);
- env->ReleaseStringUTFChars(archiveName, str); // enable releasing by Garbage Collector
- }
- JNIEXPORT jboolean JNICALL Java_net_sf_junace_UnACE_LoadAceDll
- (JNIEnv *env, jobject)
- {
- AceDllInstance = LoadLibrary(L"UnAceV2.Dll");
- if (AceDllInstance) {
- if (!(ACEInitDllProc = (INT (__stdcall *)(pACEInitDllStruc DllData))
- GetProcAddress(AceDllInstance, "ACEInitDll"))
- || !(ACEReadArchiveDataProc = (INT (__stdcall *)(LPSTR ArchiveName, pACEReadArchiveDataStruc ArchiveData))
- GetProcAddress(AceDllInstance, "ACEReadArchiveData"))
- || !(ACEListProc = (INT (__stdcall *)(LPSTR ArchiveName, pACEListStruc List))
- GetProcAddress(AceDllInstance, "ACEList"))
- || !(ACETestProc = (INT (__stdcall *)(LPSTR ArchiveName, pACETestStruc Test))
- GetProcAddress(AceDllInstance, "ACETest"))
- || !(ACEExtractProc = (INT (__stdcall *)(LPSTR ArchiveName, pACEExtractStruc Extract))
- GetProcAddress(AceDllInstance, "ACEExtract")))
- {
- FreeLibrary(AceDllInstance);
- throwUnsatisfiedLinkError(env, "Could not find function in UnAceV2.Dll!");
- return FALSE;
- }
- CallAceInitDll();
- }
- else
- throwUnsatisfiedLinkError(env, "Can't load UnAceV2.Dll");
- return AceDllInstance != NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment