示例#1
0
Kumu::PathList_t&
Kumu::FindInPath(const IPathMatch& Pattern, const std::string& SearchDir,
		  Kumu::PathList_t& FoundPaths, bool one_shot, char separator)
{
  char name_buf[MaxFilePath];
  DirScanner Dir;

  if ( KM_SUCCESS(Dir.Open(SearchDir.c_str())) )
    {
      while ( KM_SUCCESS(Dir.GetNext(name_buf)) )
	{
	  if ( name_buf[0] == '.' ) continue; // no hidden files
	  std::string tmp_path = SearchDir + separator + name_buf;

	  if ( PathIsDirectory(tmp_path.c_str()) )
	    FindInPath(Pattern, tmp_path, FoundPaths, one_shot, separator);
	  
	  else if ( Pattern.Match(name_buf) )
	    {
	      FoundPaths.push_back(SearchDir + separator + name_buf);
	      if ( one_shot )
		break;
	    }
	}
    }

  return FoundPaths;
}
示例#2
0
Result_t
h__DeletePath(const std::string& pathname)
{
  if ( pathname.empty() )
    return RESULT_NULL_STR;

  Result_t result = RESULT_OK;

  if ( ! PathIsDirectory(pathname) )
    {
      result = DeleteFile(pathname);
    }
  else
    {
      {
	DirScanner TestDir;
	char       next_file[Kumu::MaxFilePath];
	result = TestDir.Open(pathname.c_str());

	while ( KM_SUCCESS(result) && KM_SUCCESS(TestDir.GetNext(next_file)) )
	  {
	    if ( next_file[0] == '.' )
	      {
		if ( next_file[1] ==  0 )
		  continue; // don't delete 'this'
		
		if ( next_file[1] == '.' && next_file[2] ==  0 )
		  continue; // don't delete 'this' parent
	      }

	    result = h__DeletePath(pathname + std::string("/") + next_file);
	  }
      }

      if ( _rmdir(pathname.c_str()) != 0 )
	{
	  switch ( errno )
	    {
	    case ENOENT:
	    case ENOTDIR:
	      result = RESULT_NOTAFILE;
	      break;

	    case EROFS:
	    case EBUSY:
	    case EACCES:
	    case EPERM:
	      result = RESULT_NO_PERM;
	      break;

	    default:
	      DefaultLogSink().Error("DeletePath %s: %s\n", pathname.c_str(), strerror(errno));
	      result = RESULT_FAIL;
	    }
	}
    }

  return result;
}
示例#3
0
bool
CodeWindowHandler::handleKey(const InputEvent &e) { 
    CodeWindow * d = NULL;
    DisplayWindow * dd = NULL;
    //wm set the event before this was called. 
    InputState * wimp = _wm->wimp();

    bool ret = false;

    if (wimp->ctrlDown ) {

        ret = true;
        switch ( wimp->lastKey ) { 

        case KEY_CTRL_U:
            _wm->arrangeWindows();
            break;
        case KEY_CTRL_N:
            d = (CodeWindow*)new_window();
            d->current()->setBuffer( d->getTextContent()->getBuf() );
            d->moveto(wimp->lastPos[0], wimp->lastPos[1] );
            _wm->addWindow(d);
            _wm->setTopWindow(d);
            
            break;
        case KEY_CTRL_F:
        case KEY_CTRL_O:    //create new window and pass the call down...
            if ( !_wm->top()) { 
                DirScanner dr;
                fileData * f = dr.openFileDialog();
                fileData * nf = f;
                int c = 0;
                while ( nf ) { 
                    EM_log( CK_LOG_INFO, "(audicle) opening file %d : %s", c, nf->fileName.c_str() );

                    d = (CodeWindow*)new_window(); //new codewindow, new textwindow, empty buffer
                    d->getTextContent()->open( (char*)nf->fileName.c_str());
                    d->current()->setBuffer( d->getTextContent()->getBuf() );

                    Point2D np = wimp->lastPos + Point2D(0.03, -0.03 ) * (double)c;
                    d->moveto(np[0], np[1] );
                    d->resize( max ( 2.25, d->base()->w() ) , max ( 2.5, d->base()->h() )  );
                    _wm->addWindow(d);
                    _wm->setTopWindow(d);

                    c++;
                    nf = nf->next;
                }

            }
            else ret = false;
            break;
        default:
            ret = false;
        }
    }
    return ret;

}
示例#4
0
bool
TextWindowHandler::handleKey(const InputEvent &e) { 

    DisplayWindow * d;

    e.fprint( stderr );
    InputState * wimp = _wm->wimp();
    wimp->setEvent(e);

    bool ret = false; 
    if (wimp->ctrlDown ) {

        bool ret = true;
        switch ( wimp->lastKey ) {
        case KEY_CTRL_N:
            fprintf(stderr,"Make new window\n");
            d = new DisplayWindow();
            d->setContent(new TextContent());
            _wm->addWindow(d);
            d->moveto(wimp->lastPos[0], wimp->lastPos[1] );
            break;
        case KEY_CTRL_F:
        case KEY_CTRL_O:    //create new window and pass the call down...
            if ( !_wm->top()) { 
                DirScanner dr;
                fileData * f = dr.openFileDialog();
                fileData * nf = f;
                int c = 0;
                while ( nf ) { 
                    EM_log( CK_LOG_INFO, "(audicle) opening file %d : %s", c, nf->fileName.c_str());

                    d = new DisplayWindow();

                    TextContent * ntext = new TextContent();
                    ntext->open((char*)nf->fileName.c_str());
                    d->setContent(ntext);

                    Point2D np = wimp->lastPos + Point2D(0.03, -0.03 ) * (double)c; 
                    d->moveto(np[0], np[1] );
                    _wm->addWindow(d);
                    _wm->setTopWindow(d);

                    c++;
                    nf = nf->next;
                }

            }
            break;
        default:
            ret = false;
        }
    }

    return ret;

}
示例#5
0
void
TextBuffer::write( char * filepath) { 
    fprintf(stderr, "writing to file\n");
    char outfile[256];
    outfile[0] = '\0';
    if ( filepath ) strncpy ( (char*)outfile, filepath, 256 );
    else if ( _filepath.size() > 0 ) strncpy ( (char*)outfile, _filepath.c_str(), 256 );

    if ( strlen(outfile) == 0 ) { 
        char newname[512];
        newname[0]= '\0';

        DirScanner * dScan = new DirScanner();
        fileData * fD = dScan->saveFileDialog();
        if ( fD ) {
            fprintf(stderr, "textbuf - opening %s\n", fD->fileName.c_str() );
            write ( (char*) fD->fileName.c_str() );
        }
        else {  
            fprintf (stderr, "no filename specified\n");
        }
        return;
	      
//		_mesg = "waiting for file name..."; 
//        fprintf(stderr, "enter a filename!...\n>");
//        fscanf(stdin, "%s", newname );

    }
    FILE * f = fopen ( outfile ,"w" );
    if ( f ) { 
        print(f);
        fclose(f);
        _mesg = (std::string)"wrote to file " + outfile;
		_filepath = outfile;
		char * name = strrchr ( outfile, DM ); 
		_filename = ( name ) ? name+1 : _filepath ; 
        setVersion();
    }
    else { 
        _mesg = (std::string)"! error writing to file " + outfile;
        fprintf( stderr, "texteditor] TextBuffer::write() error- could not open %s\n", outfile );
    }
}
int main(int argc, char *args[]){
    if(argc < 3){
    	std::cout << "Program moves and renames file "
    			"from Graphical Herbalism installation" << std::endl;
    	std::cout << "Usage: prog_name path/to/morrowind/data "
    			"empty_nif_file_path.nif" << std::endl;
    	return 0;
    }

    std::string dataDir = args[1];
    std::string emptyNif = args[2];

    Logger log;

    DirScanner scanner;
    scanner.attachLogger(&log);
    scanner.scan(dataDir);

    DirAnalyzer analyzer;
    analyzer.attachLogger(&log);
    analyzer.setOriginals(scanner.getOriginalNifs());
    analyzer.setPicked(scanner.getPickedNifs());
    analyzer.setUnpicked(scanner.getUnpickedNifs());
    analyzer.setEmpty(emptyNif);
    analyzer.analyze();

    FileMover mover;
    mover.attachLogger(&log);
    mover.move(analyzer.getFilesToMove());
    mover.copy(analyzer.getFilesToCopy());

    log.returnLog();
    return 0;
}
示例#7
0
void
TextBuffer::open( char * filepath ) { 
    if ( !filepath ) { 
        
        DirScanner dScan;
        fileData * fD = dScan.openFileDialog();
        if ( fD ) {
            fprintf(stderr, "textbuf - opening %s\n", fD->fileName.c_str() );
            open ( (char*) fD->fileName.c_str() );
            if ( fD->next ) 
                fprintf(stderr, "textbuffer: opening first of multiple files...\n");
        }
        else {  
            fprintf (stderr, "no filename specified\n");
        }
        return;
    }
    else if ( !_source->readfile(filepath) ) { 
        _lines.clear();        
        std::string ln;
        while ( _source->getline(ln) != EOF ) { 
            addLine(ln);
        }
        setFilePath ( filepath );
        _mesg = (std::string)"read file: " + _filename ;

        _edits.clear();
	    _undoPos = -1;
	    _inUndo = false;
        _editDepth  =0;
        _modDepth = 0;
        setVersion();
    }
    
    else { 
        _filepath = "";
        _filename = "";
        _mesg = (std::string)"file: " + filepath + " not found";
    }
}
Result_t
ASDCP::AtmosSyncChannelMixer::OpenRead(const Kumu::PathList_t& argv, const Rational& PictureRate)
{
  Result_t result = RESULT_OK;
  PathList_t::iterator fi;
  Kumu::PathList_t file_list;
  PCM::AudioDescriptor tmpDesc;

  if ( argv.size() == 1 && PathIsDirectory(argv.front()) )
  {
    DirScanner Dir;
    char name_buf[MaxFilePath];
    result = Dir.Open(argv.front().c_str());

    if ( KM_SUCCESS(result) )
      result = Dir.GetNext(name_buf);

    while ( KM_SUCCESS(result) )
	{
	  if ( name_buf[0] != '.' ) // no hidden files
      {
        std::string tmp_path = argv.front() + "/" + name_buf;
        file_list.push_back(tmp_path);
      }

	  result = Dir.GetNext(name_buf);
	}

    if ( result == RESULT_ENDOFFILE )
	{
	  result = RESULT_OK;
	  file_list.sort();
	}
  }
  else
  {
    file_list = argv;
  }

  for ( fi = file_list.begin(); KM_SUCCESS(result) && fi != file_list.end(); ++fi )
  {
    result = OpenRead(*fi, PictureRate);
  }

  if ( ASDCP_SUCCESS(result) && (m_ChannelCount < ATMOS::SYNC_CHANNEL))
  {
    // atmos sync channel has not been added
    result = MixInSilenceChannels();
    if ( ASDCP_SUCCESS(result) )
      result = MixInAtmosSyncChannel();
  }

  if ( ASDCP_SUCCESS(result) )
  {
    m_ADesc.ChannelCount = m_ChannelCount;
    m_ADesc.AvgBps = (ui32_t)(ceil(m_ADesc.AudioSamplingRate.Quotient()) * m_ADesc.BlockAlign);
  }
  else
  {
    clear();
  }

  return result;
}
示例#9
0
//-----------------------------------------------------------------------------
// name: on_event()
// desc: ...
//-----------------------------------------------------------------------------
t_TAPUINT UITreesynth::on_event( const AudicleEvent & event )
{
    static t_TAPUINT m_mouse_down = FALSE;
    static t_TAPUINT which = 0;
    static Point2D last;
    t_TAPBOOL hit = FALSE;
    Point2D diff;
    t_TAPUINT i;

    if( event.type == ae_event_INPUT )
    {
        InputEvent * ie = (InputEvent *)event.data;
        if( ie->type == ae_input_MOUSE )
        {
            ie->popStack();

            for( i = 0; i < NUM_UI_ELEMENTS; i++ )
            {
                if( ie->checkID( ui_elements[i]->id ) )
                {
                    if( ie->state == ae_input_DOWN )
                    {
                        hit = TRUE;
                        ui_elements[i]->down = TRUE;
                        
                        if( i >= SL_PERCENTAGE && i <= SL_STOPLEVEL )
                            ui_elements[i]->slide_last = (ie->pos[1]/AudicleWindow::main()->m_vsize ) / g_slider_height;
                    
                        
                        if( i == FL_ANCFIRST )
                        {
                            ui_elements[i]->slide = 1.0f - ui_elements[i]->slide;
                            if( g_ts )
                            {
                                g_mutex.acquire();
                                g_ts->ancfirst = ui_elements[FL_ANCFIRST]->fvalue() > 0.5;
                                g_mutex.release();
                            }
                        }

                        if( i == FL_RANDFLIP )
                        {
                            ui_elements[i]->slide = 1.0f - ui_elements[i]->slide;
                            if( g_ts )
                            {
                                g_mutex.acquire();
                                g_ts->randflip = ui_elements[FL_RANDFLIP]->fvalue() > 0.5;
                                g_mutex.release();
                            }
                        }

                        if( i == FL_WRITE_FILE )
                        {
                            if( g_shutup )
                            {
                                ui_elements[i]->slide = 1.0f - ui_elements[i]->slide;
                            }
                            else
                            {
                                msg_box( "bad!", "wavelet-tree already synthesizing!" );
                            } 
                        }
                    }

                    if( ie->state == ae_input_UP && ui_elements[i]->down == TRUE )
                    {

                        // ~~~~~~~~~~~~~~~~~~~~~~~~ LOAD FROM FILE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        if( i == BT_LOAD_FILE )
                        {
                            m_audio->bus(1)->stop();
                            usleep( 100000 );
                            g_shutup = TRUE;
                            g_lib = FALSE;
                            DirScanner dScan;
                            fileData * fD = dScan.openFileDialog();
                            if ( fD )
                            {
                                fprintf(stderr, "residue file %s\n", fD->fileName.c_str() );
                                if ( fD->next ) 
                                    fprintf( stderr, "may not be opening first of multiple files...\n");
                                
                                strcpy( g_ifile, fD->fileName.c_str() );
                            }
                        }

                        
                        // ~~~~~~~~~~~~~~~~~~~~~~~~ LOAD FROM ANALYSIS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        if( i == BT_LOAD_ANALYSIS )
                        {
                            m_audio->bus(1)->stop();
                            usleep( 100000 );
                            g_shutup = TRUE;
                            g_lib = TRUE;
                        }


                        // ~~~~~~~~~~~~~~~~~~~~~~~~ SYNTHESIZE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        if( i == BT_SYNTHESIZE )
                        {
                            if( g_shutup )
                            {
                                ts_init( ui_elements );
                                ts_run();
                                AudioSrcEliot * ts = new AudioSrcEliot( g_tsio );
                                ts->on = &ui_elements[BT_SYNTHESIZE]->on;
                                m_audio->bus(1)->play( ts, FALSE );
                                ui_elements[BT_SYNTHESIZE]->on = TRUE;
                                ui_elements[BT_SYNTHESIZE]->on_where = 0.0;
                            }
                            else
                            {
                                msg_box( "bad!", "wavelet-tree already synthesizing!" );
                            }
                        }


                        // ~~~~~~~~~~~~~~~~~~~~~~~~ STOP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        if( i == BT_STOP )
                        {
                            m_audio->bus(1)->stop();
                            usleep( 100000 );
                            g_shutup = TRUE;
                        }

                    }
                }

                // button up
                if( ie->state == ae_input_UP && ui_elements[i]->down )
                    ui_elements[i]->down = FALSE;
            }   

            // background
            if( hit == FALSE )
            {
                if( ie->state == ae_input_DOWN )
                {
                    which = !!(ie->mods & ae_input_CTRL);
                    m_mouse_down = TRUE;
                    last = ie->pos;
                }
                else 
                {
                    m_mouse_down = FALSE;
                }
            }
        }
        else if( ie->type == ae_input_MOTION )
        {
            for( i = SL_PERCENTAGE; i <= SL_STOPLEVEL; i++ )
            {
                if( ui_elements[i]->down )
                {
                    ui_elements[i]->slide += (ie->pos[1]/AudicleWindow::main()->m_vsize ) 
                                            / g_slider_height - ui_elements[i]->slide_last;
                    ui_elements[i]->slide_last = (ie->pos[1]/AudicleWindow::main()->m_vsize ) / g_slider_height;
                    if( ui_elements[i]->slide > 1.0 ) ui_elements[i]->slide = ui_elements[i]->slide_last = 1.0;
                    if( ui_elements[i]->slide < 0.0 ) ui_elements[i]->slide = ui_elements[i]->slide_last = 0;
                }
            }

            if( ui_elements[SL_STARTLEVEL]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->startlevel = ui_elements[SL_STARTLEVEL]->ivalue();
                    g_mutex.release();
                }
            }

            if( ui_elements[SL_STOPLEVEL]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->stoplevel = ui_elements[SL_STOPLEVEL]->ivalue();
                    g_mutex.release();
                }
            }

            if( ui_elements[SL_PERCENTAGE]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->percentage = ui_elements[SL_PERCENTAGE]->fvalue();
                    g_mutex.release();
                }
            }

            if( ui_elements[SL_K]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->kfactor = ui_elements[SL_K]->fvalue();
                    g_mutex.release();
                }
            }

            if( ui_elements[FL_ANCFIRST]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->ancfirst = ui_elements[FL_ANCFIRST]->fvalue() > 0.5;
                    g_mutex.release();
                }
            }

            if( ui_elements[FL_RANDFLIP]->down )
            {
                if( g_ts )
                {
                    g_mutex.acquire();
                    g_ts->randflip = ui_elements[FL_RANDFLIP]->fvalue() > 0.5;
                    g_mutex.release();
                }
            }
        }
    }

    return AudicleFace::on_event( event );
}
示例#10
0
Result_t
ASDCP::PCMParserList::OpenRead(const Kumu::PathList_t& argv, const Rational& PictureRate)
{
  Result_t result = RESULT_OK;
  PathList_t::iterator fi;
  Kumu::PathList_t file_list;

  if ( argv.size() == 1 && PathIsDirectory(argv.front()) )
    {
      DirScanner Dir;
      char name_buf[MaxFilePath];
      result = Dir.Open(argv.front().c_str());

      if ( KM_SUCCESS(result) )
	result = Dir.GetNext(name_buf);

      while ( KM_SUCCESS(result) )
	{
	  if ( name_buf[0] != '.' ) // no hidden files
	    {
	      std::string tmp_path = argv.front() + "/" + name_buf;
	      file_list.push_back(tmp_path);
	    }

	  result = Dir.GetNext(name_buf);
	}

      if ( result == RESULT_ENDOFFILE )
	{
	  result = RESULT_OK;
	  file_list.sort();
	}
    }
  else
    {
      file_list = argv;
    }

  for ( fi = file_list.begin(); KM_SUCCESS(result) && fi != file_list.end(); ++fi )
    {
      mem_ptr<ParserInstance> I = new ParserInstance;
      result = I->OpenRead(fi->c_str(), PictureRate);

      if ( ASDCP_SUCCESS(result) )
	{
	  if ( fi == file_list.begin() )
	    {
	      m_ADesc = I->ADesc;
	    }
	  else
	    {
	      if ( I->ADesc.AudioSamplingRate != m_ADesc.AudioSamplingRate )
		{
		  DefaultLogSink().Error("AudioSamplingRate mismatch in PCM parser list.");
		  return RESULT_FORMAT;
		}

	      if ( I->ADesc.QuantizationBits  != m_ADesc.QuantizationBits )
		{
		  DefaultLogSink().Error("QuantizationBits mismatch in PCM parser list.");
		  return RESULT_FORMAT;
		}

	      if ( I->ADesc.ContainerDuration < m_ADesc.ContainerDuration )
		m_ADesc.ContainerDuration = I->ADesc.ContainerDuration;

	      m_ADesc.BlockAlign += I->ADesc.BlockAlign;
	    }

	  m_ChannelCount += I->ADesc.ChannelCount;
	}

      if ( ASDCP_SUCCESS(result) )
	result = I->FB.Capacity(PCM::CalcFrameBufferSize(m_ADesc));

      if ( ASDCP_SUCCESS(result) )
	{
	  push_back(I);
	  I.release();
	}
    }

  if ( ASDCP_SUCCESS(result) )
    {
      m_ADesc.ChannelCount = m_ChannelCount;
      m_ADesc.AvgBps = (ui32_t)(ceil(m_ADesc.AudioSamplingRate.Quotient()) * m_ADesc.BlockAlign);
    }
  else
    {
      clear();
    }

  return result;
}