示例#1
0
TEST(TestGameFileLoader, CanOpen)
{
  // Test CGameFileLoader::CanOpen() with useStrategies = false, because
  // strategies have already already been tested above

  GameClientConfig gc("gameclient.test");
  GameClientConfig gc_nes; gc_nes.extensions.insert(".nes");
  GameClientConfig gc_bin; gc_bin.extensions.insert(".bin");
  CFileItem file;

  EXPECT_TRUE(CGameFileLoader::CanOpen(file, gc));

  file.SetProperty("gameclient", "gameclient.badegg");
  EXPECT_FALSE(CGameFileLoader::CanOpen(file, gc));

  file.ClearProperty("gameclient");
  gc.platforms.push_back(PLATFORM_NINTENDO_64);
  EXPECT_TRUE(CGameFileLoader::CanOpen(file, gc));
  file.GetGameInfoTag()->SetPlatform("Playstation");
  EXPECT_FALSE(CGameFileLoader::CanOpen(file, gc));
  gc.platforms.clear();
  EXPECT_TRUE(CGameFileLoader::CanOpen(file, gc));

  file.SetPath(XBMC_REF_FILE_PATH("xbmc/games/test/LocalFile.nes"));
  EXPECT_TRUE(CGameFileLoader::CanOpen(file, gc));
  EXPECT_TRUE(CGameFileLoader::CanOpen(file, gc_nes));
  EXPECT_FALSE(CGameFileLoader::CanOpen(file, gc_bin));

  // Test entering .zip files
  CFileItem localZipFile(XBMC_REF_FILE_PATH("xbmc/games/test/LocalFile.zip"), false);
  EXPECT_TRUE(CGameFileLoader::CanOpen(localZipFile, gc)); // No extensions specified, will try to load zip directly
  EXPECT_TRUE(CGameFileLoader::CanOpen(localZipFile, gc_nes));
  EXPECT_FALSE(CGameFileLoader::CanOpen(localZipFile, gc_bin));
}
示例#2
0
CFileItem* CSavestateDatabase::CreateFileItem(const CVariant& object) const
{
  using namespace ADDON;

  CSavestate save;
  save.Deserialize(object);
  CFileItem* item = new CFileItem(save.Label());

  item->SetPath(save.Path());
  if (!save.Thumbnail().empty())
    item->SetArt("thumb", save.Thumbnail());
  else
  {
    AddonPtr addon;
    if (CAddonMgr::GetInstance().GetAddon(save.GameClient(), addon, ADDON_GAMEDLL))
      item->SetArt("thumb", addon->Icon());
  }

  // Use the slot number as the second label
  if (save.Type() == SAVETYPE::SLOT)
    item->SetLabel2(StringUtils::Format("%u", save.Slot()));

  item->m_dateTime = save.Timestamp();
  item->SetProperty(FILEITEM_PROPERTY_SAVESTATE_DURATION, static_cast<uint64_t>(save.PlaytimeWallClock()));
  item->GetGameInfoTag()->SetGameClient(save.GameClient());
  item->m_dwSize = save.Size();
  item->m_bIsFolder = false;

  return item;
}
示例#3
0
文件: GameUtils.cpp 项目: Arcko/xbmc
bool CGameUtils::FillInGameClient(CFileItem &item, bool bPrompt)
{
  using namespace ADDON;

  if (item.GetGameInfoTag()->GetGameClient().empty())
  {
    // If the fileitem is an add-on, fall back to that
    if (item.HasAddonInfo() && item.GetAddonInfo()->Type() == ADDON::ADDON_GAMEDLL)
    {
      item.GetGameInfoTag()->SetGameClient(item.GetAddonInfo()->ID());
    }
    else if (bPrompt)
    {
      // No game client specified, need to ask the user
      GameClientVector candidates;
      GameClientVector installable;
      bool bHasVfsGameClient;
      GetGameClients(item, candidates, installable, bHasVfsGameClient);

      if (candidates.empty() && installable.empty())
      {
        int errorTextId = bHasVfsGameClient ?
            35214 : // "This game can only be played directly from a hard drive or partition. Compressed files must be extracted."
            35212;  // "This game isn't compatible with any available emulators."

        // "Failed to play game"
        KODI::MESSAGING::HELPERS::ShowOKDialogText(CVariant{ 35210 }, CVariant{ errorTextId });
      }
      else if (candidates.size() == 1 && installable.empty())
      {
        // Only 1 option, avoid prompting the user
        item.GetGameInfoTag()->SetGameClient(candidates[0]->ID());
      }
      else
      {
        std::string gameClient = CGUIDialogSelectGameClient::ShowAndGetGameClient(item.GetPath(), candidates, installable);
        if (!gameClient.empty())
          item.GetGameInfoTag()->SetGameClient(gameClient);
      }
    }
  }

  return !item.GetGameInfoTag()->GetGameClient().empty();
}
示例#4
0
void CRetroPlayer::PrintGameInfo(const CFileItem &file) const
{
  const CGameInfoTag *tag = file.GetGameInfoTag();
  if (tag)
  {
    CLog::Log(LOGDEBUG, "RetroPlayer: ---------------------------------------");
    CLog::Log(LOGDEBUG, "RetroPlayer: Game tag loaded");
    CLog::Log(LOGDEBUG, "RetroPlayer: URL: %s", tag->GetURL().c_str());
    CLog::Log(LOGDEBUG, "RetroPlayer: Title: %s", tag->GetTitle().c_str());
    CLog::Log(LOGDEBUG, "RetroPlayer: Platform: %s", tag->GetPlatform().c_str());
    CLog::Log(LOGDEBUG, "RetroPlayer: Genres: %s", StringUtils::Join(tag->GetGenres(), ", ").c_str());
    CLog::Log(LOGDEBUG, "RetroPlayer: Developer: %s", tag->GetDeveloper().c_str());
    if (tag->GetYear() > 0)
      CLog::Log(LOGDEBUG, "RetroPlayer: Year: %u", tag->GetYear());
    CLog::Log(LOGDEBUG, "RetroPlayer: Game Code: %s", tag->GetID().c_str());
    CLog::Log(LOGDEBUG, "RetroPlayer: Region: %s", tag->GetRegion().c_str());
    CLog::Log(LOGDEBUG, "RetroPlayer: Publisher: %s", tag->GetPublisher().c_str());
    CLog::Log(LOGDEBUG, "RetroPlayer: Format: %s", tag->GetFormat().c_str());
    CLog::Log(LOGDEBUG, "RetroPlayer: Cartridge type: %s", tag->GetCartridgeType().c_str());
    CLog::Log(LOGDEBUG, "RetroPlayer: Game client: %s", tag->GetGameClient().c_str());
    CLog::Log(LOGDEBUG, "RetroPlayer: ---------------------------------------");
  }
}
示例#5
0
/*! \brief Run a script, plugin or game add-on.
 *  \param params The parameters.
 *  \details params[0] = add-on id.
 *           params[1] is blank for no add-on parameters
 *           or
 *           params[1] = add-on parameters in url format
 *           or
 *           params[1,...] = additional parameters in format param=value.
 */
static int RunAddon(const std::vector<std::string>& params)
{
  if (params.size())
  {
    const std::string& addonid = params[0];

    AddonPtr addon;
    if (CAddonMgr::GetInstance().GetAddon(addonid, addon, ADDON_PLUGIN))
    {
      PluginPtr plugin = std::dynamic_pointer_cast<CPluginSource>(addon);
      std::string urlParameters;
      std::vector<std::string> parameters;
      if (params.size() == 2 &&
          (StringUtils::StartsWith(params[1], "/") || StringUtils::StartsWith(params[1], "?")))
        urlParameters = params[1];
      else if (params.size() > 1)
      {
        parameters.insert(parameters.begin(), params.begin() + 1, params.end());
        urlParameters = "?" + StringUtils::Join(parameters, "&");
      }
      else
      {
        // Add '/' if addon is run without params (will be removed later so it's safe)
        // Otherwise there are 2 entries for the same plugin in ViewModesX.db
        urlParameters = "/";
      }

      std::string cmd;
      if (plugin->Provides(CPluginSource::VIDEO))
        cmd = StringUtils::Format("ActivateWindow(Videos,plugin://%s%s,return)", addonid.c_str(), urlParameters.c_str());
      else if (plugin->Provides(CPluginSource::AUDIO))
        cmd = StringUtils::Format("ActivateWindow(Music,plugin://%s%s,return)", addonid.c_str(), urlParameters.c_str());
      else if (plugin->Provides(CPluginSource::EXECUTABLE))
        cmd = StringUtils::Format("ActivateWindow(Programs,plugin://%s%s,return)", addonid.c_str(), urlParameters.c_str());
      else if (plugin->Provides(CPluginSource::IMAGE))
        cmd = StringUtils::Format("ActivateWindow(Pictures,plugin://%s%s,return)", addonid.c_str(), urlParameters.c_str());
      else if (plugin->Provides(CPluginSource::GAME))
        cmd = StringUtils::Format("ActivateWindow(Games,plugin://%s%s,return)", addonid.c_str(), urlParameters.c_str());
      else
        // Pass the script name (addonid) and all the parameters
        // (params[1] ... params[x]) separated by a comma to RunPlugin
        cmd = StringUtils::Format("RunPlugin(%s)", StringUtils::Join(params, ",").c_str());
      CBuiltins::GetInstance().Execute(cmd);
    }
    else if (CAddonMgr::GetInstance().GetAddon(addonid, addon, ADDON_SCRIPT) ||
        CAddonMgr::GetInstance().GetAddon(addonid, addon, ADDON_SCRIPT_WEATHER) ||
        CAddonMgr::GetInstance().GetAddon(addonid, addon, ADDON_SCRIPT_LYRICS) ||
        CAddonMgr::GetInstance().GetAddon(addonid, addon, ADDON_SCRIPT_LIBRARY))
    {
      // Pass the script name (addonid) and all the parameters
      // (params[1] ... params[x]) separated by a comma to RunScript
      CBuiltins::GetInstance().Execute(StringUtils::Format("RunScript(%s)", StringUtils::Join(params, ",").c_str()));
    }
    else if (CAddonMgr::GetInstance().GetAddon(addonid, addon, ADDON_GAMEDLL))
    {
      CFileItem item;

      if (params.size() >= 2)
      {
        item = CFileItem(params[1], false);
        item.GetGameInfoTag()->SetGameClient(addonid);
      }
      else
        item = CFileItem(addon);

      if (!g_application.PlayMedia(item, "", PLAYLIST_NONE))
      {
        CLog::Log(LOGERROR, "RunAddon could not start %s", addonid.c_str());
        return false;
      }
    }
    else
      CLog::Log(LOGERROR, "RunAddon: unknown add-on id '%s', or unexpected add-on type (not a script or plugin).", addonid.c_str());
  }
  else
  {
    CLog::Log(LOGERROR, "RunAddon called with no arguments.");
  }

  return 0;
}