Exemplo n.º 1
0
std::shared_ptr<gd::Platform> PlatformLoader::LoadPlatformInManager(gd::String fullpath)
{
    std::cout << "Loading platform " << fullpath << "..." << std::endl;
    Handle platformHdl = OpenLibrary(fullpath.ToLocale().c_str()); //Use the system locale for filepath
    if (platformHdl == NULL)
    {
        gd::String error = DynamicLibraryLastError();

        cout << "Loading of "<< fullpath <<" failed." << endl;
        cout << "Error returned : \"" << error << "\"" << endl;
        #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
        wxString userMsg = _("Platform ") + fullpath +
            _(" could not be loaded.\nContact the developer for more information.\n\nDetailed log:\n") + error;
        wxMessageBox(userMsg, _("Platform not compatible"), wxOK | wxICON_EXCLAMATION);
        #endif
    }
    else
    {
        CreatePlatformFunPtr createFunPtr = (CreatePlatformFunPtr)GetSymbol(platformHdl, "CreateGDPlatform");
        DestroyPlatformFunPtr destroyFunPtr = (DestroyPlatformFunPtr)GetSymbol(platformHdl, "DestroyGDPlatform");

        if ( createFunPtr == NULL || destroyFunPtr == NULL )
        {
            cout << "Loading of "<< fullpath <<" failed (no valid create/destroy functions)." << endl;

            CloseLibrary(platformHdl);

            #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
            wxString userMsg = _("Platform ")+ fullpath +
                _(" could not be loaded.\nContact the developer for more information.\n\nDetailed log:\nNo valid create/destroy functions." );
            wxMessageBox(userMsg, _("Platform not compatible"), wxOK | wxICON_EXCLAMATION);
            #endif
        }
        else
        {
            #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
            gd::LocaleManager::Get()->AddCatalog(wxFileName(fullpath).GetName()); //In editor, load catalog associated with extension, if any.
            #endif

            std::shared_ptr<gd::Platform> platform(createFunPtr(), destroyFunPtr);
            std::cout << "Loading of " << fullpath << " done." << std::endl;

            gd::PlatformManager::Get()->AddPlatform(platform);
            std::cout << "Registration in platform manager of " << fullpath << " done." << std::endl;
            return platform;
        }
    }

    return std::shared_ptr<gd::Platform>();
}
Exemplo n.º 2
0
void ExtensionsLoader::LoadExtension(const gd::String & fullpath, gd::Platform & platform, bool forgiving)
{
    if ( platform.GetExtensionCreateFunctionName().empty() )
    {
        cout << "Unable to load extension " << fullpath << ":" << endl;
        cout << "The plaftorm does not support extensions creation." << endl;
        return;
    }

    Handle extensionHdl = OpenLibrary(fullpath.c_str());
    if (extensionHdl == NULL)
    {
        gd::String error = DynamicLibraryLastError();

        cout << "Unable to load extension " << fullpath << "." << endl;
        cout << "Error returned : \"" << error << "\"" << endl;
        #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
        wxString userMsg = _("Extension ")+ fullpath + _(" could not be loaded.\nContact the developer for more informations.\n\nDetailed log:\n") + error;
        wxMessageBox(userMsg, _("Extension not compatible"), wxOK | wxICON_EXCLAMATION);
        #endif

        return;
    }

    createExtension create_extension = (createExtension)GetSymbol(extensionHdl, platform.GetExtensionCreateFunctionName().c_str());

    if (create_extension == NULL)
    {
        if (!forgiving)
        {
            cout << "Unable to load extension " << fullpath << " (Creation function symbol not found)." << endl;
            #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
            wxString userMsg = _("Extension ")+ fullpath + _(" could not be loaded.\nContact the developer for more informations." );
            wxMessageBox(userMsg, _("Extension not compatible"), wxOK | wxICON_EXCLAMATION);
            #endif
        }

        CloseLibrary(extensionHdl);
        return;
    }

    #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
    gd::LocaleManager::Get()->AddCatalog(wxFileName(fullpath).GetName()); //In editor, load catalog associated with extension, if any.
    #endif

    gd::PlatformExtension * extensionPtr = create_extension();
    gd::String error;

    //Perform safety check about the compilation
    if ( !extensionPtr->compilationInfo.informationCompleted )
        error += "Compilation information not filled.\n";

    #if defined(GD_IDE_ONLY)
    else if ( extensionPtr->compilationInfo.runtimeOnly )
        error += "Extension compiled for runtime only.\n";

    #if !defined(GD_NO_WX_GUI)
    else if ( extensionPtr->compilationInfo.wxWidgetsMajorVersion != wxMAJOR_VERSION ||
              extensionPtr->compilationInfo.wxWidgetsMinorVersion != wxMINOR_VERSION ||
              extensionPtr->compilationInfo.wxWidgetsReleaseNumber != wxRELEASE_NUMBER ||
              extensionPtr->compilationInfo.wxWidgetsSubReleaseNumber != wxSUBRELEASE_NUMBER )
        error += "Not the same wxWidgets version.\n";
    #endif
    #endif
    #if defined(__GNUC__)
    else if ( extensionPtr->compilationInfo.gccMajorVersion != __GNUC__ ||
              extensionPtr->compilationInfo.gccMinorVersion != __GNUC_MINOR__ )
        error += "Not the same GNU Compiler version.\n";

    #endif
    else if ( extensionPtr->compilationInfo.sfmlMajorVersion != 2 ||
              extensionPtr->compilationInfo.sfmlMinorVersion != 0 )
        error += "Not the same SFML version.\n";

    else if ( extensionPtr->compilationInfo.gdCoreVersion != GDCore_RC_FILEVERSION_STRING)
        error += "Not the same GDevelop Core version.\n(Extension is using "+extensionPtr->compilationInfo.gdCoreVersion+", GDevelop is using "+GDCore_RC_FILEVERSION_STRING+")\n";

    else if ( extensionPtr->compilationInfo.sizeOfpInt != sizeof(int*))
        error += "Not the same architecture.\n(Extension sizeof(int*) is "+gd::String::From(extensionPtr->compilationInfo.sizeOfpInt)+", GDevelop sizeof(int*) is "+gd::String::From(sizeof(int*))+")\n";

    if ( !error.empty() )
    {
        char beep = 7;
        cout << "-- WARNING ! --" << beep << endl;
        cout << "Bad extension " + fullpath + " loaded :\n" + error;
        cout << "---------------" << endl;

        #if defined(RELEASE)//Load extension despite errors in non release build

        //Destroy the extension class THEN unload the library from memory
        delete extensionPtr;
        CloseLibrary(extensionHdl);
        #endif

        #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI) && defined(RELEASE) //Show errors in IDE only
        wxString userMsg = _("Extension ") + fullpath + _(" has errors :\n") +
            error + _("\nThe extension was not loaded. Contact the developer to get more information." );
        wxMessageBox(userMsg, _("Extension not compatible"), wxOK | wxICON_EXCLAMATION);
        #endif

        #if defined(RELEASE)//Load extension despite errors in non release build
        return;
        #endif
    }

    std::shared_ptr<gd::PlatformExtension> extension(extensionPtr);
    platform.AddExtension(extension);
    return;
}