Ejemplo n.º 1
0
bool Account::updateSupportInfo()
{
    std::string apiEndpoint(API_ENDPOINT);
    CPLJSONObject root = http::fetchJson(apiEndpoint + "/support_info/");
    if(!root.IsValid()) {
        return false;
    }

    bool supported = root.GetBool("supported");

    Settings &settings = Settings::instance();
    settings.set("account/supported", supported);

    if(supported) {
        settings.set("account/sign", root.GetString("sign"));
        settings.set("account/start_date", root.GetString("start_date"));
        settings.set("account/end_date", root.GetString("end_date"));

        // Get key file
        const char *settingsPath = CPLGetConfigOption("NGS_SETTINGS_PATH", nullptr);
        std::string keyFilePath = File::formFileName(settingsPath, KEY_FILE, "");
        return http::getFile(apiEndpoint + "/rsa_public_key/", keyFilePath);
    }

    m_supported = checkSupported();

    return true;
}
Ejemplo n.º 2
0
// smell: yellow (the save functions may have additional options, not regarded)
// Save file
FXbool
MFXImageHelper::saveImage(const std::string& file,
                          int width, int height, FXColor* data) {
    FXString ext = FXPath::extension(file.c_str());
    checkSupported(ext);
    FXFileStream stream;
    if (!stream.open(file.c_str(), FXStreamSave)) {
        throw InvalidArgument("Could not open file for writing!");
    }
    if (comparecase(ext, "gif") == 0) {
        return fxsaveGIF(stream, data, width, height, false /* !!! "fast" */);
    } else if (comparecase(ext, "bmp") == 0) {
        return fxsaveBMP(stream, data, width, height);
    } else if (comparecase(ext, "xpm") == 0) {
        return fxsaveXPM(stream, data, width, height);
    } else if (comparecase(ext, "pcx") == 0) {
        return fxsavePCX(stream, data, width, height);
    } else if (comparecase(ext, "ico") == 0 || comparecase(ext, "cur") == 0) {
        return fxsaveICO(stream, data, width, height);
    } else if (comparecase(ext, "tga") == 0) {
        return fxsaveTGA(stream, data, width, height);
    } else if (comparecase(ext, "rgb") == 0) {
        return fxsaveRGB(stream, data, width, height);
    } else if (comparecase(ext, "xbm") == 0) {
        return fxsaveXBM(stream, data, width, height);
    } else if (comparecase(ext, "png") == 0) {
        return fxsavePNG(stream, data, width, height);
    } else if (comparecase(ext, "jpg") == 0 || comparecase(ext, "jpeg") == 0) {
        return fxsaveJPG(stream, data, width, height, 75);
    } else if (comparecase(ext, "tif") == 0 || comparecase(ext, "tiff") == 0) {
        return fxsaveTIF(stream, data, width, height, 0);
    }
    throw InvalidArgument("Unknown file extension for image!");
}
Ejemplo n.º 3
0
    osg::ref_ptr<osg::Image> ImageManager::getImage(const std::string &filename)
    {
        std::string normalized = filename;
        mVFS->normalizeFilename(normalized);

        osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
        if (obj)
            return osg::ref_ptr<osg::Image>(static_cast<osg::Image*>(obj.get()));
        else
        {
            Files::IStreamPtr stream;
            try
            {
                stream = mVFS->get(normalized.c_str());
            }
            catch (std::exception& e)
            {
                std::cerr << "Failed to open image: " << e.what() << std::endl;
                mCache->addEntryToObjectCache(normalized, mWarningImage);
                return mWarningImage;
            }

            size_t extPos = normalized.find_last_of('.');
            std::string ext;
            if (extPos != std::string::npos && extPos+1 < normalized.size())
                ext = normalized.substr(extPos+1);
            osgDB::ReaderWriter* reader = osgDB::Registry::instance()->getReaderWriterForExtension(ext);
            if (!reader)
            {
                std::cerr << "Error loading " << filename << ": no readerwriter for '" << ext << "' found" << std::endl;
                mCache->addEntryToObjectCache(normalized, mWarningImage);
                return mWarningImage;
            }

            osgDB::ReaderWriter::ReadResult result = reader->readImage(*stream, mOptions);
            if (!result.success())
            {
                std::cerr << "Error loading " << filename << ": " << result.message() << " code " << result.status() << std::endl;
                mCache->addEntryToObjectCache(normalized, mWarningImage);
                return mWarningImage;
            }

            osg::Image* image = result.getImage();
            image->setFileName(normalized);
            if (!checkSupported(image, filename))
            {
                mCache->addEntryToObjectCache(normalized, mWarningImage);
                return mWarningImage;
            }

            mCache->addEntryToObjectCache(normalized, image);
            return image;
        }
    }
Ejemplo n.º 4
0
Account::Account() : m_authorized(false), m_supported(false)
{
    const char *settingsPath = CPLGetConfigOption("NGS_SETTINGS_PATH", nullptr);
    Settings &settings = Settings::instance();
    m_firstName = settings.getString("account/first_name", "no name");
    m_lastName = settings.getString("account/last_name", "no name");
    m_email = settings.getString("account/email", "no email");

    m_avatarPath = File::formFileName(settingsPath, AVATAR_FILE, "");

    m_supported = checkSupported();
}
Ejemplo n.º 5
0
    osg::ref_ptr<osg::Image> TextureManager::getImage(const std::string &filename)
    {
        std::string normalized = filename;
        mVFS->normalizeFilename(normalized);
        std::map<std::string, osg::ref_ptr<osg::Image> >::iterator found = mImages.find(normalized);
        if (found != mImages.end())
            return found->second;
        else
        {
            Files::IStreamPtr stream;
            try
            {
                stream = mVFS->get(normalized.c_str());
            }
            catch (std::exception& e)
            {
                std::cerr << "Failed to open image: " << e.what() << std::endl;
                return NULL;
            }

            osg::ref_ptr<osgDB::Options> opts (new osgDB::Options);
            opts->setOptionString("dds_dxt1_detect_rgba"); // tx_creature_werewolf.dds isn't loading in the correct format without this option
            size_t extPos = normalized.find_last_of('.');
            std::string ext;
            if (extPos != std::string::npos && extPos+1 < normalized.size())
                ext = normalized.substr(extPos+1);
            osgDB::ReaderWriter* reader = osgDB::Registry::instance()->getReaderWriterForExtension(ext);
            if (!reader)
            {
                std::cerr << "Error loading " << filename << ": no readerwriter for '" << ext << "' found" << std::endl;
                return NULL;
            }

            osgDB::ReaderWriter::ReadResult result = reader->readImage(*stream, opts);
            if (!result.success())
            {
                std::cerr << "Error loading " << filename << ": " << result.message() << " code " << result.status() << std::endl;
                return NULL;
            }

            osg::Image* image = result.getImage();
            if (!checkSupported(image, filename))
            {
                return NULL;
            }

            mImages.insert(std::make_pair(normalized, image));
            return image;
        }
    }
Ejemplo n.º 6
0
void MainWindow::onDeviceSelected(int index)
{
    Q_D(MainWindow);
    d->device = d->pc->devices()[index];

    refreshPresets();

    if (d->state == MainWindowPrivate::FinishedPatching) {
        d->state = MainWindowPrivate::ChoseFile;
    }

    checkSupported();
    updateWidgetsVisibility();
}
Ejemplo n.º 7
0
FXImage*
MFXImageHelper::loadImage(FXApp* a, const std::string& file) {
    FXString ext = FXPath::extension(file.c_str());
    checkSupported(ext);
    FXImage* img = NULL;
    if (comparecase(ext, "gif") == 0) {
        img = new FXGIFImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "bmp") == 0) {
        img = new FXBMPImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "xpm") == 0) {
        img = new FXXPMImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "pcx") == 0) {
        img = new FXPCXImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "ico") == 0 || comparecase(ext, "cur") == 0) {
        img = new FXICOImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "tga") == 0) {
        img = new FXTGAImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "rgb") == 0) {
        img = new FXRGBImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "xbm") == 0) {
        img = new FXXBMImage(a, NULL, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "png") == 0) {
        img = new FXPNGImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "jpg") == 0 || comparecase(ext, "jpeg") == 0) {
        img = new FXJPGImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "tif") == 0 || comparecase(ext, "tiff") == 0) {
        img = new FXTIFImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else {
        throw InvalidArgument("Unknown file extension '" + toString(ext.text()) + "' for image '" + file + "'!");
    }

    FXFileStream stream;
    if (img != NULL && stream.open(file.c_str(), FXStreamLoad)) {
        a->beginWaitCursor();
        img->loadPixels(stream);
        stream.close();

        img->create();
        a->endWaitCursor();
    } else {
        delete img;
        throw InvalidArgument("Loading failed!");
    }
    return img;
}
Ejemplo n.º 8
0
void MainWindow::chooseFile()
{
    Q_D(MainWindow);

    QString fileName = QFileDialog::getOpenFileName(this, QString(),
            d->settings.value(QStringLiteral("last_dir")).toString(),
            tr("Zip files (*.zip)"));
    if (fileName.isNull()) {
        return;
    }

    d->settings.setValue(QStringLiteral("last_dir"),
                         QFileInfo(fileName).dir().absolutePath());

    d->state = MainWindowPrivate::ChoseFile;

    d->fileName = fileName;

    checkSupported();
    updateWidgetsVisibility();
}
Ejemplo n.º 9
0
CmCError CheckSyntax(char *filename, CmCParser *synParser)
{

  //*****************************************
  //parse the file
  //*****************************************

  int error;
  synParser->SetDelimiters("=(){},;'");
  synParser->StoreDelimiters(true);
  error = synParser->Parse(filename);
  if(error) return (CmCError((CmCToken *) NULL, SYN_INVALID_FILE));

  //*****************************************
  //check syntax
  //*****************************************

  int  curveId;
  int  parameterId;
  int  commandTypeId, commandId;
  CmCToken *token, *(tokenSet)[MAX_TOKEN_NUM];
  while(token = synParser->GetToken())
    {
      //identify the command...
      commandId     = Command(token->token_);
      commandTypeId = CommandType(commandId);

      //based on the command, identify the number of tokens
      //associated with it and obtain those tokens
      error = GetTokenSet(commandId, tokenSet, synParser);

      //if the specified number of tokens does not exist
      //then return an error
      if(error == SYN_ERROR) return CmCError((CmCToken *) NULL, error);

      //if the specified tokens exist, then check them for
      //their validity

      switch(commandTypeId)
	{
	case CMD_IO:
	  switch(commandId)
	    {
	    case CMD_SAVE:
	      //check structure
	      if(strcmp(tokenSet[0]->token_, "(")) return CmCError(tokenSet[0], SYN_MISSING_LEFT_PARENTHESIS);
	      if(strcmp(tokenSet[1]->token_, "'")) return CmCError(tokenSet[1],SYN_MISSING_QUOTATION);
	      if(strcmp(tokenSet[3]->token_, "'")) return CmCError(tokenSet[3],SYN_MISSING_QUOTATION);
	      if(strcmp(tokenSet[4]->token_, ",")) return CmCError(tokenSet[4],SYN_MISSING_COMMA);
	      if(strcmp(tokenSet[6]->token_, ",")) return CmCError(tokenSet[6],SYN_MISSING_COMMA);
	      if(strcmp(tokenSet[8]->token_, ")")) return CmCError(tokenSet[8],SYN_MISSING_RIGHT_PARENTHESIS);
	      if(strcmp(tokenSet[9]->token_, ";")) return CmCError(tokenSet[9],SYN_MISSING_SEMICOLON);

	      //check constants
	      if(!validFileType(tokenSet[5]->token_))  return CmCError(tokenSet[5],SYN_INVALID_FILETYPE);
	      if(!validOutputType(tokenSet[7]->token_))return CmCError(tokenSet[7],SYN_INVALID_OUTPUTTYPE);
	      if(checkSupported(FileType(tokenSet[5]->token_))) 
		 return CmCError(tokenSet[5],SYN_UNSUPPORTED_FILETYPE);
	      break;

	    case CMD_LOAD:
	      //check structure
	      if(strcmp(tokenSet[0]->token_, "(")) return CmCError(tokenSet[0],SYN_MISSING_LEFT_PARENTHESIS);
	      if(strcmp(tokenSet[1]->token_, "'")) return CmCError(tokenSet[1],SYN_MISSING_QUOTATION);
	      if(strcmp(tokenSet[3]->token_, "'")) return CmCError(tokenSet[3],SYN_MISSING_QUOTATION);
	      if(strcmp(tokenSet[4]->token_, ",")) return CmCError(tokenSet[4],SYN_MISSING_COMMA);
	      if(strcmp(tokenSet[6]->token_, ")")) return CmCError(tokenSet[6],SYN_MISSING_RIGHT_PARENTHESIS);
	      if(strcmp(tokenSet[7]->token_, ";")) return CmCError(tokenSet[7],SYN_MISSING_SEMICOLON);

	      //check constants
	      if(!validInputType(tokenSet[5]->token_)) return CmCError(tokenSet[5],SYN_INVALID_INPUTTYPE);
	      break;
	      
	    case CMD_USE_RESULT:
	      if(strcmp(tokenSet[0]->token_, "(")) return CmCError(tokenSet[0], SYN_MISSING_LEFT_PARENTHESIS);
	      if(strcmp(tokenSet[2]->token_, ")")) return CmCError(tokenSet[2], SYN_MISSING_RIGHT_PARENTHESIS);
	      if(strcmp(tokenSet[3]->token_, ";")) return CmCError(tokenSet[3], SYN_MISSING_SEMICOLON);
	      if((OutputType(tokenSet[1]->token_) != OUTPUT_SEGM_IMAGE) &&
		 (OutputType(tokenSet[1]->token_) != OUTPUT_FILT_IMAGE)) {
		if(OutputType(tokenSet[1]->token_) != OUTPUT_UNKNOWN) {
		  return CmCError(tokenSet[1], SYN_ASSIGN_INVALID_ARG);
		} else {
		  return CmCError(tokenSet[1], SYN_INVALID_OUTPUTTYPE);
		}
	      }
	      break;
	    }
	  break;
       
	case CMD_EXECUTION:
	  if(tokenSet[0]->token_[0] != ';') return CmCError(tokenSet[0],SYN_MISSING_SEMICOLON);
	  break;
	case CMD_FLAGS:
	  if(!validFlag(tokenSet[0]->token_)) return CmCError(tokenSet[0],SYN_INVALID_FLAG);
	  if(tokenSet[1]->token_[0] != ';')   return CmCError(tokenSet[1],SYN_MISSING_SEMICOLON);
	  break;
	//unknown command
	default:
	  break;
	}

      //if its not a command, then maybe its a parameter
      if(commandTypeId == UNKNOWN_COMMAND) {
	//get the parameter type
	parameterId = Parameter(token->token_);

	if(parameterId != UNKNOWN_PARAMETER) {
	  
	  //retreive tokens expected given a parameter
	  error = GetParamTokenSet(tokenSet, synParser);
	  if(error == SYN_ERROR) return CmCError(token, SYN_ERROR);
	  
	  //check those tokens for validity
	  if(strcmp(tokenSet[0]->token_, "=")) return CmCError(tokenSet[0],SYN_MISSING_EQUALS);
	  if(strcmp(tokenSet[2]->token_, ";")) return CmCError(tokenSet[2],SYN_MISSING_SEMICOLON);

	  //make sure parameter is of the right type
	  error = CheckParameter(parameterId, tokenSet[1]->token_);
	  if(error) return CmCError(token, error);

 	//if its an unknown parameter then maybe its a curve list
	} else {
	  //get custom curve
	  curveId = CustomCurve(token->token_);
	    
	  //if its not a custom curve list then flag an error
	  if(curveId == UNKNOWN_CURVE) return CmCError(token,SYN_INVALID_PARAMCMD);

	  //check for equals
	  token = synParser->GetToken();
	  if(token->token_[0] != '=') return CmCError(token,SYN_MISSING_EQUALS);

	  //if its a curve list, then check that a proper point list
	  //is provided
	  error = CheckList(synParser, &token);
	  if(error) return CmCError(token, error);

	  //check for semicolon
	  token = synParser->GetToken();
	  if(token->token_[0] != ';') return CmCError(token,SYN_MISSING_SEMICOLON);
	}
      }
      
      //command/parameter identified and verified for
      //its validity, next command/parameter
    }

  //reset parser
  synParser->StartOver();
  
  //file is syntaxically correct
  return CmCError((CmCToken *) NULL, NO_ERRORS);
  
}
Ejemplo n.º 10
0
    osg::ref_ptr<osg::Texture2D> TextureManager::getTexture2D(const std::string &filename, osg::Texture::WrapMode wrapS, osg::Texture::WrapMode wrapT)
    {
        std::string normalized = filename;
        mVFS->normalizeFilename(normalized);
        MapKey key = std::make_pair(std::make_pair(wrapS, wrapT), normalized);
        std::map<MapKey, osg::ref_ptr<osg::Texture2D> >::iterator found = mTextures.find(key);
        if (found != mTextures.end())
        {
            return found->second;
        }
        else
        {
            Files::IStreamPtr stream;
            try
            {
                stream = mVFS->get(normalized.c_str());
            }
            catch (std::exception& e)
            {
                std::cerr << "Failed to open texture: " << e.what() << std::endl;
                return mWarningTexture;
            }

            osg::ref_ptr<osgDB::Options> opts (new osgDB::Options);
            opts->setOptionString("dds_dxt1_detect_rgba"); // tx_creature_werewolf.dds isn't loading in the correct format without this option
            size_t extPos = normalized.find_last_of('.');
            std::string ext;
            if (extPos != std::string::npos && extPos+1 < normalized.size())
                ext = normalized.substr(extPos+1);
            osgDB::ReaderWriter* reader = osgDB::Registry::instance()->getReaderWriterForExtension(ext);
            if (!reader)
            {
                std::cerr << "Error loading " << filename << ": no readerwriter for '" << ext << "' found" << std::endl;
                return mWarningTexture;
            }

            osgDB::ReaderWriter::ReadResult result = reader->readImage(*stream, opts);
            if (!result.success())
            {
                std::cerr << "Error loading " << filename << ": " << result.message() << " code " << result.status() << std::endl;
                return mWarningTexture;
            }

            osg::Image* image = result.getImage();
            if (!checkSupported(image, filename))
            {
                return mWarningTexture;
            }

            // We need to flip images, because the Morrowind texture coordinates use the DirectX convention (top-left image origin),
            // but OpenGL uses bottom left as the image origin.
            // For some reason this doesn't concern DDS textures, which are already flipped when loaded.
            if (ext != "dds")
            {
                image->flipVertical();
            }

            osg::ref_ptr<osg::Texture2D> texture(new osg::Texture2D);
            texture->setImage(image);
            texture->setWrap(osg::Texture::WRAP_S, wrapS);
            texture->setWrap(osg::Texture::WRAP_T, wrapT);
            texture->setFilter(osg::Texture::MIN_FILTER, mMinFilter);
            texture->setFilter(osg::Texture::MAG_FILTER, mMagFilter);
            texture->setMaxAnisotropy(mMaxAnisotropy);

            texture->setUnRefImageDataAfterApply(mUnRefImageDataAfterApply);

            mTextures.insert(std::make_pair(key, texture));
            return texture;
        }
    }