Esempio n. 1
0
    Addon::Addon(const char* cid, bool installed) throw (AddonException)
    {
      String id(cid ? cid : emptyString);

      // if the id wasn't passed then get the id from
      //   the global dictionary
      if (id.empty())
        id = getDefaultId();

      // if we still don't have an id then bail
      if (id.empty())
        throw AddonException("No valid addon id could be obtained. None was passed and the script wasn't executed in a normal xbmc manner.");

      bool success = ADDON::CAddonMgr::Get().GetAddon(id.c_str(), pAddon);
      if (!success && !installed)
      {
        CAddonDatabase addondb;
        addondb.Open();
        success = addondb.GetAddon(id, pAddon);
      }

      // if we still fail we MAY be able to recover.
      if (!success)
      {
        // we need to check the version prior to trying a bw compatibility trick
        ADDON::AddonVersion version(getAddonVersion());
        ADDON::AddonVersion allowable("1.0");

        if (version <= allowable)
        {
          // try the default ...
          id = getDefaultId();

          if (id.empty() || !ADDON::CAddonMgr::Get().GetAddon(id.c_str(), pAddon))
            throw AddonException("Could not get AddonPtr!");
          else
            CLog::Log(LOGERROR,"Use of deprecated functionality. Please to not assume that \"os.getcwd\" will return the script directory.");
        }
        else
        {
          throw AddonException("Could not get AddonPtr given a script id of %s."
                               "If you are trying to use 'os.getcwd' to set the path, you cannot do that in a version %s plugin.",
                               id.c_str(), version.asString().c_str());
        }
      }

      CAddonMgr::Get().AddToUpdateableAddons(pAddon);
    }
Esempio n. 2
0
  PyObject* Addon_New(PyTypeObject *type, PyObject *args, PyObject *kwds)
  {
    Addon *self;

    self = (Addon*)type->tp_alloc(type, 0);
    if (!self) return NULL;

    static const char *keywords[] = { "id", NULL };
    const char *id = NULL;

    // parse arguments
    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      (char*)"|s",
      (char**)keywords,
      (char**)&id
      ))
    {
      Py_DECREF(self);
      return NULL;
    };

    // if the id wasn't passed then get the id from
    //   the global dictionary
    if (!id)
      id = getDefaultId();

    // if we still don't have an id then bail
    if (!id)
    {
        PyErr_SetString(PyExc_Exception, "No valid addon id could be obtained. None was passed and the script wasn't executed in a normal xbmc manner.");
        Py_DECREF(self);
        return NULL;
    }

    // if we still fail we MAY be able to recover.
    if (!CAddonMgr::Get().GetAddon(id, self->pAddon))
    {
      // we need to check the version prior to trying a bw compatibility trick
      ADDON::AddonVersion version(getAddonVersion());
      ADDON::AddonVersion allowable("1.0");

      if (version <= allowable)
      {
        // try the default ...
        id = getDefaultId();

        if (!CAddonMgr::Get().GetAddon(id, self->pAddon))
        {
          PyErr_SetString(PyExc_Exception, "Could not get AddonPtr!");
          Py_DECREF(self);
          return NULL;
        }
        else
          CLog::Log(LOGERROR,"Use of deprecated functionality. Please to not assume that \"os.getcwd\" will return the script directory.");
      }
      else
      {
        CStdString errorMessage ("Could not get AddonPtr given a script id of ");
        errorMessage += id;
        errorMessage += ". If you are trying to use 'os.getcwd' to set the path, you cannot do that in a ";
        errorMessage += version.Print();
        errorMessage += " plugin.";
        PyErr_SetString(PyExc_Exception, errorMessage.c_str());
        Py_DECREF(self);
        return NULL;
      }
    }

    return (PyObject*)self;
  }