Beispiel #1
0
void ArcAPI::load() {
  load_libs(add_trailing_slash(Far::get_plugin_module_path()) + L"*.dll");
  find_sfx_modules(add_trailing_slash(Far::get_plugin_module_path()) + L"*.sfx");
  if (arc_libs.empty() || sfx_modules.empty()) {
    wstring _7zip_path;
    Key _7zip_key;
    _7zip_key.open_nt(HKEY_CURRENT_USER, L"Software\\7-Zip", KEY_QUERY_VALUE, false) && _7zip_key.query_str_nt(_7zip_path, L"Path");
    if (_7zip_path.empty())
      _7zip_key.open_nt(HKEY_LOCAL_MACHINE, L"Software\\7-Zip", KEY_QUERY_VALUE, false) && _7zip_key.query_str_nt(_7zip_path, L"Path");
    if (!_7zip_path.empty()) {
      if (arc_libs.empty())
        load_libs(add_trailing_slash(_7zip_path) + L"7z.dll");
      if (sfx_modules.empty())
        find_sfx_modules(add_trailing_slash(_7zip_path) + L"*.sfx");
    }
  }
  if (arc_libs.empty()) {
    wstring _7z_dll_path;
    IGNORE_ERRORS(_7z_dll_path = search_path(L"7z.dll"));
    if (!_7z_dll_path.empty())
      load_libs(_7z_dll_path);
  }
  for (unsigned i = 0; i < arc_libs.size(); i++) {
    const ArcLib& arc_lib = arc_libs[i];

    UInt32 num_formats;
    if (arc_lib.GetNumberOfFormats) {
      if (arc_lib.GetNumberOfFormats(&num_formats) != S_OK)
        num_formats = 0;
    }
    else
      num_formats = 1;

    for (UInt32 idx = 0; idx < num_formats; idx++) {
      ArcFormat arc_format;
      arc_format.lib_index = i;
      ArcType type;
      if (arc_lib.get_bytes_prop(idx, NArchive::kClassID, type) != S_OK) continue;
      arc_lib.get_string_prop(idx, NArchive::kName, arc_format.name);
      if (arc_lib.get_bool_prop(idx, NArchive::kUpdate, arc_format.updatable) != S_OK)
        arc_format.updatable = false;
      arc_lib.get_bytes_prop(idx, NArchive::kStartSignature, arc_format.start_signature);
      arc_lib.get_string_prop(idx, NArchive::kExtension, arc_format.extension_list);
      ArcFormats::const_iterator existing_format = arc_formats.find(type);
      if (existing_format == arc_formats.end() || arc_libs[existing_format->second.lib_index].version < arc_lib.version)
        arc_formats[type] = arc_format;
    }
  }
  // unload unused libraries
  set<unsigned> used_libs;
  for_each(arc_formats.begin(), arc_formats.end(), [&] (const pair<ArcType, ArcFormat>& arc_format) {
    used_libs.insert(arc_format.second.lib_index);
  });
  for (unsigned i = 0; i < arc_libs.size(); i++) {
    if (used_libs.count(i) == 0) {
      FreeLibrary(arc_libs[i].h_module);
      arc_libs[i].h_module = nullptr;
    }
  }
}
Beispiel #2
0
int main(int argc, char** argv)   {
  bool have_prompt = false;
  bool do_execute = false;
  std::vector<char*> args;
  std::vector<char*> libs;
  int first_arg = 1;
  int ret;

  if ( argc>first_arg && strncmp(argv[first_arg],"-p",2)==0 )  {
    have_prompt = true;
    args.push_back(argv[0]);
    ++first_arg;
  }
  else if ( argc>first_arg && strncmp(argv[first_arg],"-e",2)==0 )  {
    do_execute = true;
    ++first_arg;
  }
  for(int i=first_arg; i<argc; ++i)  {
    if ( 0 == ::strcmp(argv[i],"-L") )
      libs.push_back(argv[++i]);
    else
      args.push_back(argv[i]);
  }
  if ( !have_prompt && args.size()>0 )  {
    libs.push_back((char*)"libDDG4Python");
    if ( 0 == (ret=load_libs(libs)) )   {
      DD4hep::DDPython::instance().setArgs(args.size(), &args[0]);
      DD4hep::DDPython::instance().setMainThread();
      DD4hep::DDPython::instance().runFile(args[0]);
      if ( do_execute )
        return gInterpreter->ProcessLine("PyDDG4::execute()");
      else 
        return 0;
    }
    return ret;
  }
  if ( 0 == (ret=load_libs(libs)) )   {
    ::printf("+++ Calling now Py_Main...\n");
    ret = DD4hep::DDPython::run_interpreter(args.size(), &args[0]);
    //::printf("+++ Return code Py_Main=%d\n",ret);
  }
  return ret;
}
Beispiel #3
0
static int create_loader(srs_plugin_t *plugin)
{
    const char *failed;

    MRP_UNUSED(plugin);

    mrp_clear(&loader);

    if (check_config(&loader) != 0) {
        mrp_log_error("Failed to get configuration (%d: %s).", errno,
                      strerror(errno));
        return FALSE;
    }

    if ((failed = load_libs(&loader)) != NULL) {
        mrp_log_error("Failed to preload library '%s'.", failed);
        return FALSE;
    }
    else
        return TRUE;
}
Beispiel #4
0
int main(int argc, char **argv) {
   
   int i = 0;
   int jvm_argc = 0;
   int main_argc = 0;
   int jvm_argv_index = 0;
   int main_argv_index = 0;
   char ** jvm_argv = (char**)malloc(argc*sizeof(char*)+1); /* plus one for classpath */
   char ** main_argv = (char**)malloc(argc*sizeof(char*));
   char *main_class_name = NULL;
   jobject main_class = NULL;
   char *p = NULL;
   int  doexit = 1;
   int result = 0;
	JNIEnv* env = NULL;
   
   int  classpath_index = -1;   
   const char* classpath_from_env = getenv("CLASSPATH");
   if(classpath_from_env != NULL) {
      
      int len = strlen("-Djava.class.path=") + strlen(classpath_from_env) + 1;
      jvm_argv[jvm_argv_index] = (char*)malloc(len);
      sprintf(jvm_argv[jvm_argv_index],"-Djava.class.path=%s", classpath_from_env);
      classpath_index = jvm_argv_index;
      jvm_argv_index++;
      jvm_argc++;
   }
   
   for(i=1; i < argc; i++) {
      if ( strcmp(argv[i], "-noexit") == 0 ) {
         doexit=0;
      } else if ( strncmp(argv[i], "-X", 2) == 0 ) {
         jvm_argc++;
         jvm_argv[jvm_argv_index++] = argv[i]+2;
      } else if (strcmp(argv[i],"-cp") == 0 ) {
         i++;
         if(i >= argc) {
            fprintf(stderr, "Missing classpath for -cp options\n");
            exit(1);
         }
         if (classpath_index < 0) {
            int len = strlen("-Djava.class.path=") + strlen(argv[i]) + 1;
            jvm_argv[jvm_argv_index] = (char*)malloc(len);
            sprintf(jvm_argv[jvm_argv_index],"-Djava.class.path=%s", argv[i]);
            classpath_index = jvm_argv_index;
            jvm_argc++;
            jvm_argv_index++;
         } else {
            char *tmp = jvm_argv[classpath_index];
            int len = strlen(tmp) + strlen(argv[i]) + 2;
            jvm_argv[classpath_index] = (char*)malloc(len);
            sprintf(jvm_argv[classpath_index],"%s:%s", tmp, argv[i]);
            free(tmp);
         }
      } else {
         if(main_class_name == NULL) {
            main_class_name = argv[i];
         } else {
            main_argc++;
            main_argv[main_argv_index++] = argv[i];
         }
      }
   }
   
   if(main_class_name == NULL) {
      fprintf(stderr,"no main class defined\n");
      exit(1);
   }
   
   
	env = create_vm(jvm_argc, jvm_argv);
   if(env == NULL) {
      exit(1);
   }
   
   for(p= main_class_name; *p != '\0'; p++) {
      if(*p == '.') {
         *p = '/';
      }
   }
   
   	main_class = (*env)->FindClass(env, main_class_name);
   if (main_class == NULL) {
      fprintf(stderr,"class %s not found\n", main_class_name);
      exit(1);
   }
   
   main_class = (jclass)(*env)->NewGlobalRef(env, main_class);
   if (main_class == NULL) {
      fprintf(stderr,"Did not get a global ref on main class\n");
      exit(1);
   }
   
   if(load_libs(env, main_class)) {
      exit(1);
   }
   
   result = invoke_main( env, main_class, main_argc, main_argv );
   
   if(doexit) {
      exit(result);
   }
   return 0;
}