Esempio n. 1
0
bool DirectoryIsWritable(wxString const & DirectoryName)
{
	bool result = false;
	wxString TempFilename = GetTempFilename(DirectoryName, "tstperm");
	wxFileOutputStream fileStream(TempFilename);
	if (fileStream.IsOk() == false)
		return false;
	if (fileStream.Write("Test", 4).IsOk() == false)
		result = false;
	else
		result = true;
	DeleteFile(TempFilename);
	return result;
}
Esempio n. 2
0
bool GameManager::DownloadAndInstall(std::string storeZipUrl) {
	if (curDownload_.get() != 0) {
		ERROR_LOG(HLE, "Can only process one download at a time");
		return false;
	}
	if (installInProgress_) {
		ERROR_LOG(HLE, "Can't download when an install is in progress (yet)");
		return false;
	}

	std::string filename = GetTempFilename();
	curDownload_ = g_DownloadManager.StartDownload(storeZipUrl, filename);
	return true;
}
Esempio n. 3
0
QString RDFeed::GetExportCommand(RDStation *station,const QString &srcfile,
				 QString *destfile,RDFeed::Error *err) const
{
  int format_in=0;
  int len;
  RDSettings settings;
  QString custom_cmd;

  *destfile=GetTempFilename();
  QFile file(srcfile);
  if(!file.exists()) {
    *err=RDFeed::ErrorCannotOpenFile;
    return QString();
  }
  RDWaveFile *wave=new RDWaveFile(srcfile);
  if(!wave->openWave()) {
    *err=RDFeed::ErrorUnsupportedType;
    delete wave;
    return QString();
  }
  int samplerate=wave->getSamplesPerSec();
  switch(wave->getFormatTag()) {
      case WAVE_FORMAT_PCM:
	format_in=0;
	len=wave->getSampleLength()*wave->getChannels()*
	  (wave->getBitsPerSample()/8);
	break;

      case WAVE_FORMAT_MPEG:
	format_in=wave->getHeadLayer();
	len=wave->getSampleLength()*wave->getChannels()*2;
	break;
  }
  wave->closeWave();
  delete wave;

  QString cmd;
  float normal=0.0;
  RDLibraryConf *rdlibrary=new RDLibraryConf(station->name(),0);
  if(normalizeLevel()<=0) {
    normal=pow(10.0,(double)(normalizeLevel()/20000.0));
    cmd=QString().
      sprintf("rd_export_file %6.4f %d %d %s %d %d %d %d %d %s %s.dat %s.%s %d",
	      normal,
	      format_in,
	      samplerate,
	      (const char *)srcfile,
	      uploadFormat(),
	      uploadChannels(),
	      uploadSampleRate(),
	      uploadBitRate()/1000,
	      uploadQuality(),
	      (const char *)RDEscapeString(*destfile),
	      (const char *)(*destfile),
	      (const char *)(*destfile),
	      RDConfiguration()->audioExtension().ascii(),
	      rdlibrary->srcConverter());
  }
  else {
    cmd=QString().
      sprintf("rd_export_file 0 %d %d %s %d %d %d %d %d %s %s.dat %s.%s %d",
	      format_in,
	      samplerate,
	      (const char *)srcfile,
	      uploadFormat(),
	      uploadChannels(),
	      uploadSampleRate(),
	      uploadBitRate()/1000,
	      uploadQuality(),
	      (const char *)RDEscapeString(*destfile),
	      (const char *)(*destfile),
	      (const char *)(*destfile),
	      RDConfiguration()->audioExtension().ascii(),
	      rdlibrary->srcConverter());
  }
  delete rdlibrary;

  switch(uploadFormat()) {  // Custom format?
    case RDSettings::Pcm16:
    case RDSettings::MpegL1:
    case RDSettings::MpegL2:
    case RDSettings::MpegL3:
    case RDSettings::Flac:
    case RDSettings::OggVorbis:
      break;

    default:
      settings.setFormat(uploadFormat());
      settings.setChannels(uploadChannels());
      settings.setSampleRate(uploadSampleRate());
      settings.setBitRate(uploadBitRate());
      custom_cmd=settings.resolvedCustomCommandLine(*destfile);
      if(custom_cmd.isEmpty()) {
	return QString();
      }
      cmd+=" \""+custom_cmd+"\"";
      break;
  }

  // printf("CMD: %s",(const char *)cmd);
  *err=RDFeed::ErrorOk;

  return cmd;
}
Esempio n. 4
0
QString RDFeed::GetImportCommand(RDStation *station,const QString &srcfile,
				 QString *destfile,Error *err) const
{
  int format_in=0;
  int temp_length;
  int finished_length;
  QString cmd;

  if(!QFile::exists(srcfile)) {
    *err=RDFeed::ErrorNoFile;
    return QString();
  }
  RDWaveFile *wave=new RDWaveFile(srcfile);
  if(!wave->openWave()) {
    *err=RDFeed::ErrorCannotOpenFile;
    delete wave;
    return QString();
  }
  if(wave->type()==RDWaveFile::Unknown) {
    *err=RDFeed::ErrorUnsupportedType;
    wave->closeWave();
    delete wave;
    return QString();
  }
  int samplerate=wave->getSamplesPerSec();
  switch(wave->getFormatTag()) {
      case WAVE_FORMAT_PCM:
	format_in=0;
	temp_length=wave->getSampleLength()*
	  wave->getChannels()*(wave->getBitsPerSample()/8);
	break;

      case WAVE_FORMAT_MPEG:
	format_in=wave->getHeadLayer();
	temp_length=wave->getSampleLength()*wave->getChannels()*2;
	break;

      case WAVE_FORMAT_FLAC:
	format_in=0;
	temp_length=wave->getSampleLength()*wave->getChannels()*2;
	break;
  }
  delete wave;

  int lib_fmt=0;
  finished_length=
    (int)(((double)temp_length/2.0)*(double)uploadChannels()*
	  ((double)uploadSampleRate())/44100.0);
  lib_fmt=0;
  *destfile=GetTempFilename();
  QString tempwav_name=*destfile+".wav";
  QString tempdat_name=*destfile+".dat";

  float normal=0.0;
  normal=pow(10.0,(double)(-1.0/20.0));
  RDLibraryConf *rdlibrary=new RDLibraryConf(station->name(),0);
  cmd=QString().
    sprintf("rd_import_file %6.4f %d %d %s %d %d %d %d %s %s %s %d",
	    normal,
	    format_in,
	    samplerate,
	    (const char *)RDEscapeString(srcfile.utf8()),  
	    lib_fmt,
	    uploadChannels(),
	    uploadSampleRate(),
	    (uploadChannels())*uploadBitRate()/1000,
	    (const char *)(*destfile),
	    (const char *)tempdat_name,
	    (const char *)tempwav_name,
	    rdlibrary->srcConverter());
  // printf("CMD: %s\n",(const char *)cmd);
  *err=RDFeed::ErrorOk;
  delete rdlibrary;

  return cmd;
}
Esempio n. 5
0
void ArticleDownloader::LogDebugInfo()
{
	char szTime[50];
#ifdef HAVE_CTIME_R_3
		ctime_r(&m_tLastUpdateTime, szTime, 50);
#else
		ctime_r(&m_tLastUpdateTime, szTime);
#endif

	debug("      Download: status=%i, LastUpdateTime=%s, filename=%s", m_eStatus, szTime, Util::BaseFileName(GetTempFilename()));
}
Esempio n. 6
0
int AstralImageImport( LPSTR lpInFile, LPSTR lpProfile, int nFileType )
//////////////////////////////////////////////////////////////////////////
{
    OFSTRUCT ofstruct;

    HINSTANCE hDLL              = NULL;
    HINSTANCE hSrcLibrary       = NULL;
    HINSTANCE hDstLibrary       = NULL;
    HINSTANCE hImportSetupData  = NULL;
    HINSTANCE hExportSetupData  = NULL;

    CREATESETUP  lpfnCreateSetup    = NULL;
    DESTROYSETUP lpfnDestroySetup   = NULL;
    IMPORTPROC   lpfnImportProc     = NULL;

    IMPORT_OPTIONS   Options;
    EXPORT_OPTIONS   Export;

    int error = IMPORT_NOERROR;

    FNAME szFilterPath;
    FNAME szOutFile; 
    FNAME szTempFile;
    FNAME szINIPath;
    char szFilter[13]; 
    char szINI[13]; 

    ProgressBegin( 1, PROGRESS_ID( IDS_UNDOIMPORTIMAGE ));

    szFilterPath[0] = szOutFile[0] = szTempFile[0] = szINIPath[0] = 0;
    szFilter[0] = szINI[0] = 0; 

    if( !nFileType || 
         nFileType < IDN_FIRSTIMPORTFILETYPE || 
         nFileType > IDN_LASTIMPORTFILETYPE )
    {
        error = IMPORT_INVALIDFILE_ERROR;
        goto ImportAbort;
    }

    // load ISGDI9.DLL explicitly
    GetModuleFileName( PictPubApp.Get_hInstAstral(), szFilterPath, sizeof( szFilterPath ));
    *strrchr( szFilterPath, '\\' ) = '\0';        
    lstrcat( szFilterPath, "\\" );
    lstrcat( szFilterPath, FILTER_DRIVER );

    hDLL = LoadLibrary( szFilterPath );

#ifdef WIN32
    if( hDLL == NULL )
#else
    if( hDLL < HINSTANCE_ERROR )
#endif
    {
        error = IMPORT_DLLLOAD_ERROR;
        goto ImportAbort;
    }

    // get filter and profile names
    GetImportFilter( nFileType, szFilter, szINI );

    // get location of filters
    GetExtNamePath( szFilterPath, IDN_IMPORTFILTERS );

    // set import filter path
    lstrcat( szFilterPath, szFilter );  

    if( OpenFile( szFilterPath, &ofstruct, OF_EXIST ) == HFILE_ERROR ) 
    {
        error = IMPORT_SRCLIBLOAD_ERROR;
        goto ImportAbort;
    }

    // set import filter profile path
    if( Control.bNetworkInstall )       // use pouch path
    {
        GetIniPath( szINIPath );
    }
    else                               // use filters directory
    {
        GetExtNamePath( szINIPath, IDN_IMPORTFILTERS );
    }
    lstrcat( szINIPath, szINI );  

#ifdef WIN32
    if(( hSrcLibrary = LoadLibrary( szFilterPath )) != NULL )
#else
    if(( hSrcLibrary = LoadLibrary( szFilterPath )) >= HINSTANCE_ERROR )
#endif
    {
        lpfnCreateSetup     = 
                ( CREATESETUP )GetProcAddress( hSrcLibrary, "CreateSetup" );
        hImportSetupData    = 
                ( HINSTANCE )( *lpfnCreateSetup )( hSrcLibrary, szINIPath, NULL, NULL );
    }
    else
    {
        error = IMPORT_SRCLIBLOAD_ERROR;
        goto ImportAbort;
    }

    // set export filter path 
    *strrchr( szFilterPath, '\\' ) = '\0';        
    lstrcat( szFilterPath, "\\" );
    lstrcat( szFilterPath, EXPORT_FILTER );

    if( OpenFile( szFilterPath, &ofstruct, OF_EXIST ) == HFILE_ERROR ) 
    {
        error = IMPORT_DSTLIBLOAD_ERROR;
        goto ImportAbort;
    }

#ifdef WIN32
    if(( hDstLibrary = LoadLibrary( szFilterPath )) != NULL )
#else
    if(( hDstLibrary = LoadLibrary( szFilterPath )) >= HINSTANCE_ERROR )
#endif
    {
        lpfnCreateSetup     = 
                ( CREATESETUP )GetProcAddress( hDstLibrary, "CreateSetup" );
        hExportSetupData    = 
                ( HINSTANCE )( *lpfnCreateSetup )( hDstLibrary, lpProfile, NULL, NULL );
    }
	else
    {
        error = IMPORT_DSTLIBLOAD_ERROR;
        goto ImportAbort;
    }

    memset( &Export, 0, sizeof( EXPORT_OPTIONS ));

    Export.GetSet_Status   = 
        ( GETSET_STATUS )MakeProcInstance(( FARPROC )GetSet_DialogStatus, PictPubApp.Get_hInstAstral());

    if( Export.GetSet_Status == NULL )
    {
        error = IMPORT_IMPORTFILE_ERROR;
        goto ImportAbort;
    }

    *strrchr( szFilterPath, '\\' ) = '\0';        
    *strrchr( szINIPath, '\\' ) = '\0';        

    memset( &Options, 0, sizeof( IMPORT_OPTIONS ));

    Options.hInputData     = hImportSetupData;      // Handle to import data
    Options.hOutputData    = hExportSetupData;      // Handle to export data
    Options.lpszDriverPath = szFilterPath;          // Driver DLL directory
    Options.lpszFontPath   = szFilterPath;          // Font file directory
    Options.lpExport       = &Export;

    // set temp file directory
    if( Control.bNetworkInstall )
        Options.lpszWorkPath   = szINIPath;         
    else
        Options.lpszWorkPath   = szFilterPath;         

    lstrcpy( szOutFile, Options.lpszWorkPath );     
    lstrcat( szOutFile, "\\" ); 

    // create temp file name
    lstrcpy( szTempFile, "PP" );
    GetTempFilename( szTempFile, ".TIF" );
    lstrcat( szOutFile, szTempFile );    

    lpfnImportProc = ( IMPORTPROC )GetProcAddress( hSrcLibrary, "ImportFile" );

    if( !( error = (( *lpfnImportProc )( NULL, EXPORT_FILTER, szOutFile, lpInFile, ( LPSTR )&Options ))))    
        lstrcpy( lpInFile, szOutFile );
    else
        FileDelete( szOutFile );        // get rid of temp file in case of error

    if( Export.GetSet_Status != NULL )
        FreeProcInstance(( FARPROC )Export.GetSet_Status );
    
ImportAbort:

#ifdef WIN32
    if( hDstLibrary != NULL )
#else
    if( hDstLibrary >= HINSTANCE_ERROR )
#endif
    {
        lpfnDestroySetup = ( DESTROYSETUP )GetProcAddress( hDstLibrary, "DestroySetup" );
        ( *lpfnDestroySetup )( hExportSetupData );

        FreeLibrary( hDstLibrary );
    }

#ifdef WIN32
    if( hSrcLibrary != NULL )
#else
    if( hSrcLibrary >= HINSTANCE_ERROR )
#endif
    {
        lpfnDestroySetup = ( DESTROYSETUP )GetProcAddress( hSrcLibrary, "DestroySetup" );
        ( *lpfnDestroySetup )( hImportSetupData );

        FreeLibrary( hSrcLibrary );
    }

#ifdef WIN32
    if( hDLL != NULL )
#else
    if( hDLL >= HINSTANCE_ERROR )
#endif
    {
        FreeLibrary( hDLL );
    }

    ProgressEnd();

    switch( error )
    {
        case IMPORT_NOERROR:
            break;

        case IMPORT_INVALIDFILE_ERROR:              // type not supported
            Message( IDS_INVALIDIMPORTFILE_ERROR );
            break;

        case IMPORT_SRCLIBLOAD_ERROR:               // error loading import filter
            Message( IDS_IMPORTLIBLOAD_ERROR );
            break;

        case IMPORT_DSTLIBLOAD_ERROR:               // error loading export filter
            Message( IDS_EXPORTLIBLOAD_ERROR );
            break;

        case IME_INVALID_FILE_TYPE:                 // incorrect file format
            Message( IDS_INVALIDIMPORTFILE_TYPE );
            break;

        case IME_INVALID_FILE_VERSION:              // unsupported file version
            Message( IDS_INVALIDIMPORTFILE_VERSION );
            break;

        case IME_MEMORY:                            // insufficient memory
            Message( IDS_EMEMALLOC );
            break;

        case IMPORT_DLLLOAD_ERROR:
        case IMPORT_IMPORTFILE_ERROR:               // non-specific error from app
        default:                                    // non-specific error from filter
            Message( IDS_IMPORTFILE_ERROR );    
            break;
    }
    return error;
}
Esempio n. 7
0
unsigned RDFeed::postFile(RDStation *station,const QString &srcfile,Error *err,
			  bool log_debug,RDConfig *config)
{
  QString sql;
  RDSqlQuery *q;
  QString cmd;
  QString tmpfile;
  QString tmpfile2;
  QString destfile;
  int time_length=0;
  RDUpload *upload=NULL;
  RDUpload::ErrorCode upload_err;
  RDWaveFile *wave=NULL;
  unsigned audio_time=0;

  emit postProgressChanged(0);
  emit postProgressChanged(1);
  qApp->processEvents();

  //
  // Convert Cut
  //
  tmpfile=GetTempFilename();
  RDAudioConvert *conv=new RDAudioConvert(station->name(),this);
  conv->setSourceFile(srcfile);
  conv->setDestinationFile(tmpfile);
  RDSettings *settings=new RDSettings();
  settings->setFormat(uploadFormat());
  settings->setChannels(uploadChannels());
  settings->setSampleRate(uploadSampleRate());
  settings->setBitRate(uploadBitRate());
  settings->setNormalizationLevel(normalizeLevel()/100);
  conv->setDestinationSettings(settings);
  switch(conv->convert()) {
  case RDAudioConvert::ErrorOk:
    wave=new RDWaveFile(tmpfile);
    if(wave->openWave()) {
      audio_time=wave->getExtTimeLength();
    }
    delete wave;
    break;

  case RDAudioConvert::ErrorInvalidSettings:
  case RDAudioConvert::ErrorFormatNotSupported:
    emit postProgressChanged(totalPostSteps());
    delete settings;
    delete conv;
    *err=RDFeed::ErrorUnsupportedType;
    unlink(tmpfile);
    return 0;

  case RDAudioConvert::ErrorNoSource:
  case RDAudioConvert::ErrorNoDestination:
  case RDAudioConvert::ErrorInternal:
  case RDAudioConvert::ErrorInvalidSource:
  case RDAudioConvert::ErrorNoDisc:
  case RDAudioConvert::ErrorNoTrack:
  case RDAudioConvert::ErrorInvalidSpeed:
  case RDAudioConvert::ErrorFormatError:
  case RDAudioConvert::ErrorNoSpace:
    emit postProgressChanged(totalPostSteps());
    delete settings;
    delete conv;
    *err=RDFeed::ErrorGeneral;
    unlink(tmpfile);
    return 0;
  }
  delete settings;
  delete conv;

  //
  // Upload
  //
  emit postProgressChanged(2);
  emit postProgressChanged(3);
  qApp->processEvents();
  QFile file(tmpfile);
  int length=file.size();

  unsigned cast_id=CreateCast(&destfile,length,time_length);
  RDPodcast *cast=new RDPodcast(cast_id);
  upload=new RDUpload(station->name(),this);
  upload->setSourceFile(tmpfile);
  upload->setDestinationUrl(purgeUrl()+"/"+cast->audioFilename());
  switch((upload_err=upload->runUpload(purgeUsername(),purgePassword(),
				       log_debug))) {
  case RDUpload::ErrorOk:
    sql=QString().sprintf("update PODCASTS set AUDIO_TIME=%u where ID=%u",
			  audio_time,cast_id);
    q=new RDSqlQuery(sql);
    delete q;
    break;

  default:
    emit postProgressChanged(totalPostSteps());
    *err=RDFeed::ErrorUploadFailed;
    printf("Upload Error: %s\n",(const char *)RDUpload::errorText(upload_err));
    sql=QString().sprintf("delete from PODCASTS where ID=%u",cast_id);
    q=new RDSqlQuery(sql);
    delete q;
    delete upload;
    delete cast;
    *err=RDFeed::ErrorUploadFailed;
    unlink(tmpfile);
    return 0;
  }
  delete upload;
  delete cast;
  unlink(QString().sprintf("%s.wav",(const char *)tmpfile));
  unlink(tmpfile);
  emit postProgressChanged(totalPostSteps());

  *err=RDFeed::ErrorOk;
  return cast_id;
}
Esempio n. 8
0
unsigned RDFeed::postCut(RDUser *user,RDStation *station,
			 const QString &cutname,Error *err,bool log_debug,
			 RDConfig *config)
{
  QString tmpfile;
  QString destfile;
  QString sql;
  RDSqlQuery *q;
  RDPodcast *cast=NULL;
  RDUpload *upload=NULL;
  RDUpload::ErrorCode upload_err;
  RDAudioConvert::ErrorCode audio_conv_err;

  emit postProgressChanged(0);
  emit postProgressChanged(1);

  //
  // Export Cut
  //
  tmpfile=GetTempFilename();
  RDCut *cut=new RDCut(cutname);
  if(!cut->exists()) {
    delete cut;
    *err=RDFeed::ErrorCannotOpenFile;
    return 0;
  }
  RDAudioExport *conv=new RDAudioExport(station,config,this);
  conv->setCartNumber(cut->cartNumber());
  conv->setCutNumber(cut->cutNumber());
  conv->setDestinationFile(tmpfile);
  conv->setRange(cut->startPoint(),cut->endPoint());
  RDSettings *settings=new RDSettings();
  settings->setFormat(uploadFormat());
  settings->setChannels(uploadChannels());
  settings->setSampleRate(uploadSampleRate());
  settings->setBitRate(uploadBitRate());
  settings->setNormalizationLevel(normalizeLevel()/100);
  conv->setDestinationSettings(settings);
  switch(conv->runExport(user->name(),user->password(),&audio_conv_err)) {
  case RDAudioExport::ErrorOk:
    break;

  case RDAudioExport::ErrorInvalidSettings:
    delete settings;
    delete conv;
    *err=RDFeed::ErrorUnsupportedType;
    unlink(tmpfile);
    return 0;

  case RDAudioExport::ErrorNoSource:
  case RDAudioExport::ErrorNoDestination:
  case RDAudioExport::ErrorInternal:
  case RDAudioExport::ErrorUrlInvalid:
  case RDAudioExport::ErrorService:
  case RDAudioExport::ErrorInvalidUser:
  case RDAudioExport::ErrorAborted:
  case RDAudioExport::ErrorConverter:
    delete settings;
    delete conv;
    *err=RDFeed::ErrorGeneral;
    unlink(tmpfile);
    return 0;
  }
  delete settings;
  delete conv;

  //
  // Upload
  //
  emit postProgressChanged(2);
  QFile file(tmpfile);
  int length=file.size();
  unsigned cast_id=CreateCast(&destfile,length,cut->length());
  delete cut;
  cast=new RDPodcast(cast_id);
  upload=new RDUpload(station->name(),this);
  upload->setSourceFile(tmpfile);
  upload->setDestinationUrl(purgeUrl()+"/"+cast->audioFilename());
  switch((upload_err=upload->runUpload(purgeUsername(),purgePassword(),
				       log_debug))) {
  case RDUpload::ErrorOk:
    *err=RDFeed::ErrorOk;
    break;

  default:
    emit postProgressChanged(totalPostSteps());
    *err=RDFeed::ErrorUploadFailed;
    sql=QString().sprintf("delete from PODCASTS where ID=%u",cast_id);
    q=new RDSqlQuery(sql);
    delete q;
    delete upload;
    delete cast;
    *err=RDFeed::ErrorUploadFailed;
    unlink(tmpfile);
    return 0;
  }
  emit postProgressChanged(3);
  unlink(tmpfile);
  delete upload;
  delete cast;

  emit postProgressChanged(totalPostSteps());

  return cast_id;
}