Exemple #1
0
/*
 * PopDirectory
 */
void PopDirectory( void )
{
    if( oldPath[0] != '\0' ) {
        ChangeDirectory( oldPath );
    }
    ChangeDirectory( CurrentDirectory );

} /* PopDirectory */
Exemple #2
0
/*
 * PopDirectory - restore the last directory
 */
void PopDirectory( void )
{
    if( oldPath[0] != 0 ) {
        ChangeDirectory( oldPath );
    }
    DosSelectDisk( oldDisk );
    ChangeDirectory( CurrentDirectory );

} /* PopDirectory */
Exemple #3
0
/*
 * PopDirectory
 */
void PopDirectory( void )
{
    unsigned    total;

    if( oldPath[0] != 0 ) {
        ChangeDirectory( oldPath );
    }
    _dos_setdrive( oldDrive, &total );
    ChangeDirectory( CurrentDirectory );

} /* PopDirectory */
Exemple #4
0
/*
 * PushDirectory
 */
void PushDirectory( const char *orig )
{
    oldPath[0] = '\0';
    GetCWD2( oldPath, sizeof( oldPath ) );
    ChangeDirectory( orig );

} /* PushDirectory */
Exemple #5
0
util::Error ChangeMatch(const acl::User& user, const VirtualPath& path, VirtualPath& match)
{
  std::string lcBasename(util::ToLowerCopy(path.Basename().ToString()));

  util::Error e(PP::DirAllowed<PP::View>(user, path));
  if (!e) return e;

  try
  {
    for (auto& entry : DirContainer(user, path.Dirname()))
    {
      if (!util::StartsWith(util::ToLowerCopy(entry), lcBasename)) continue;
      // this hackishness forces creation of a fresh virtualpath,
      // therefore forcing resolution of symlinks
      match = MakeVirtual(fs::Path((path.Dirname() / entry).ToString()));
      e = ChangeDirectory(user, match);
      if (e || (e.Errno() != ENOENT && e.Errno() != ENOTDIR))
      {
        return e;
      }
    }
  }
  catch (const util::SystemError& e)
  {
    return util::Error::Failure(e.Errno());
  }

  return util::Error::Failure(ENOENT);
}
int CreateDirInPathAndBackToCurrentDir(char* dirName, char* path, char* currentDir)
{
    if(-1 == ChangeDirectory(path)) return -1;
    if (0 != access(dirName, F_OK))
    {
        if (ENOENT == errno) { // if file does not exist
            if(-1 == CreateDir(dirName)) return -1;
        }
        if (ENOTDIR == errno) {
            fprintf(stderr, "Not a directory!\n");
            return -1;
        }
    }
    if(-1 == ChangeDirectory(currentDir)) return -1;
    return 0;
}
void CMWEditApp::OnFileOpen (void) {
  COpenPluginDlg OpenDlg;
  int		 Result;

  ChangeDirectory(GetMWDataPath());
  m_Masters.RemoveAll();
  m_Plugins.RemoveAll();
  m_ActivePlugin.Empty();

  Result = OpenDlg.DoModal();
  if (Result != IDOK) return;

  m_Masters.AddHead(&OpenDlg.GetMasters());
  m_Plugins.AddHead(&OpenDlg.GetPlugins());
  m_ActivePlugin = OpenDlg.GetActivePlugin();

  if (m_ActivePlugin.IsEmpty() && m_Plugins.GetCount() == 0 && m_Masters.GetCount() == 0)
    return;
  else if (!m_ActivePlugin.IsEmpty())
    AfxGetApp()->OpenDocumentFile(m_ActivePlugin);
  else {
    CString Buffer;
    Buffer.Format(_T("noname%d.esp"), m_NonameCount);
    m_NonameCount++;
    AfxGetApp()->OpenDocumentFile(Buffer);
   }

 }
Exemple #8
0
//---------------------------------------------------------------------------
void __fastcall TUnixDirView::ExecuteParentDirectory()
{
  PathChanging(true);
#ifndef DESIGN_ONLY
  ChangeDirectory(PARENTDIRECTORY);
#endif
}
Exemple #9
0
//-------------------------------------------------------------
// Pre     : If bCreateIntermediates is TRUE, create all eventually
//           missing parent directories too
// Post    : Return TRUE on success
// Task    : Create new directory
//-------------------------------------------------------------
bool CPath::DirectoryCreate(bool bCreateIntermediates /*= TRUE*/)
{
    std::string	PathText;
    bool	bSuccess;

    GetDriveDirectory(PathText);
    StripTrailingBackslash(PathText);
    bSuccess =::CreateDirectory(PathText.c_str(),NULL) != 0;
    if(!bSuccess)
    {
        CPath CurrentDir(CPath::CURRENT_DIRECTORY);
        bSuccess = ChangeDirectory() != 0;
        CurrentDir.ChangeDirectory();
    }

    if(!bSuccess && bCreateIntermediates)
    {
        std::string::size_type nDelimiter =PathText.rfind(DIRECTORY_DELIMITER);
        if(nDelimiter == std::string::npos)
            return FALSE;

        PathText.resize(nDelimiter + 1);
        CPath SubPath(PathText);

        if (SubPath.DirectoryCreate())
            return DirectoryCreate(false);
        else
            return FALSE;
    }

    return bSuccess;
}
Exemple #10
0
/*
 * ScreenInit - get screen info
 */
void ScreenInit( void )
{
    struct _osinfo              info;
    int                         rows, cols;
    unsigned                    size;
    unsigned                    seg;
    vi_rc                       rc;


    QNXCon = console_open( QNXConHandle, O_WRONLY );
    if( QNXCon == NULL ) {
        // FatalError( ERR_WIND_NO_MORE_WINDOWS );
        ChangeDirectory( HomeDirectory );
        exit( 0 );
    }
    if( console_size( QNXCon, QNXConsole, 0, 0, &rows, &cols ) != 0 ) {
        console_close( QNXCon );
        FatalError( ERR_WIND_NO_MORE_WINDOWS );
    }
    rc = BIOSKeyboardInit();
    if( rc != ERR_NO_ERR ) {
        console_close( QNXCon );
        FatalError( rc );
    }
    EditVars.WindMaxWidth = cols;
    EditVars.WindMaxHeight = rows;

    qnx_osinfo( 0, &info );
    switch( info.primary_monitor ) {
    case _MONITOR_PGS:
    case _MONITOR_CGA:
    case _MONITOR_PS30_COLOR:
    case _MONITOR_EGA_COLOR:
    case _MONITOR_VGA_COLOR:
        EditFlags.Color = TRUE;
        break;
    case _MONITOR_EGA_MONO:
    case _MONITOR_VGA_MONO:
    case _MONITOR_PS30_MONO:
        EditFlags.BlackAndWhite = TRUE;
        break;
    default:
        EditFlags.Monocolor = TRUE;
        break;
    }
    size = cols * rows * sizeof( char_info );
    seg = qnx_segment_alloc( size );
    Scrn = MK_FP( seg, 0 );
    ScreenPage( 0 );

} /* ScreenInit */
Exemple #11
0
//---------------------------------------------------------------------------
void __fastcall TUnixDirView::ExecuteHomeDirectory()
{
#ifndef DESIGN_ONLY
  // don't select any directory
  PathChanging(false);
  UnicodeString APath = Terminal->SessionData->RemoteDirectory;
  if (WinConfiguration->DefaultDirIsHome && !APath.IsEmpty() &&
      !Terminal->SessionData->UpdateDirectories)
  {
    if (APath[1] != L'/')
    {
      Terminal->BeginTransaction();
      try
      {
        ChangeDirectory(HOMEDIRECTORY);
        ChangeDirectory(APath);
      }
      __finally
      {
        Terminal->EndTransaction();
      }
    }
    else
    {
Exemple #12
0
util::Error ChangeAlias(const acl::User& user, const Path& path, VirtualPath& match)
{
  if (path.Basename() != path) return util::Error::Failure(ENOENT);
  
  std::string name = util::ToLowerCopy(path.ToString());
  for (auto& alias : cfg::Get().Alias())
  {
    if (alias.Name() == name)
    {
      match = VirtualPath(alias.Path());
      return ChangeDirectory(user, match);
    }
  }
  
  return util::Error::Failure(ENOENT);
}
Exemple #13
0
/* EJECUTA */
int
EjecutarLineas(char* cadena, Comando* linea, int fd_ant, int fd_out, int is_primero){	
	int fp;
	linea=SepararTokens(cadena, linea);
	if(strcmp(linea->command, "cd")==0){
		if(is_primero==0){
			ChangeDirectory(linea);
		//}else{
		//	fprintf(stderr, "El comando cd debe estar al principio de fichero\n" );
		}
		return -2;
	}else{
		fp=forky(linea, fd_ant, fd_out);
		return fp;
	}
}
Exemple #14
0
void StartUtility()
{
	int iChoice ;
	byte errCode ;

	while(1)
	{
		printf("\n\n ******************************************* \n") ;
		printf("\n 1) List Contents.\n 2) Change Directory.\n 3) Create Directory.\n 4) Copy File To MOS FS.\n 5) Copy File From MOS FS.\n 6) Exit.\n 7) Dump FS Table.\n") ;
		printf("\n\tChoice: ") ;
		scanf("%d", &iChoice) ;

		switch(iChoice)
		{
			case 1:
					if((errCode = Directory_GetContent_SPIKE(&FSMountInfo_FD1)) != Directory_SUCCESS)
						fprintf(stderr, "\n Failed To Read Dir Entry: %u\n", errCode) ;
					break ;

			case 2:
					ChangeDirectory() ;
					break ;

			case 3:
					CreateDirectory() ;
					break ;

			case 4:
					CopyFileToMOSFS() ;
					break ;

			case 5:
					CopyFileFromMOSFS() ;
					break ;

			case 6:
					return ;	

			case 7:
					DumpFSTable() ;
					break ;

			default:
					fprintf(stderr, "\n Invalid Choice...\n") ;
		}
	}
}
Exemple #15
0
/*
 * FileSPVAR - build file special variables
 */
void FileSPVAR( void )
{
    char        path[FILENAME_MAX];
    char        drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
    int         i;

    /*
     * build path
     */
    if( CurrentFile == NULL ) {
        VarAddGlobalStr( "F", "" );
        VarAddGlobalStr( "H", "" );
        drive[0] = dir[0] = fname[0] = ext[0] = 0;
    } else {
        VarAddGlobalStr( "F", CurrentFile->name );
        VarAddGlobalStr( "H", CurrentFile->home );
        ConditionalChangeDirectory( CurrentFile->home );
        _splitpath( CurrentFile->name, drive, dir, fname, ext );
    }
    VarAddGlobalStr( "P1", dir );
    VarAddGlobalStr( "D1", drive );
    strcpy( path, drive );
    strcat( path, dir );
    i = strlen( path ) - 1;
    if( path[i] == FILE_SEP && i > 0 ) {
        path[i] = 0;
    }
    if( CurrentFile != NULL ) {
        PushDirectory( path );
        ChangeDirectory( path );
        GetCWD2( path, FILENAME_MAX );
        PopDirectory();
    } else {
        path[0] = 0;
    }
    if( path[strlen(path) - 1] == FILE_SEP ) {
        StrMerge( 2, path, fname, ext );
    } else {
        StrMerge( 3, path,FILE_SEP_STR, fname, ext );
    }
    _splitpath( path, drive, dir, fname, ext );
    VarAddGlobalStr( "D", drive );
    VarAddGlobalStr( "P", dir );
    VarAddGlobalStr( "N", fname );
    VarAddGlobalStr( "E", ext );

} /* FileSPVAR */
Exemple #16
0
/*
 * Quit - print usage messages
 */
void Quit( const char **usage_msg, const char *str, ... )
{
    va_list     al;

    usage_msg = usage_msg;
#ifdef __WIN__
    {
        char    buff[MAX_STR];

        if( str != NULL ) {
            va_start( al, str );
            MyVSprintf( buff, str, al );
            va_end( al );
        } else {
            buff[0] = 0;
        }
        CloseStartupDialog();
        UsageDialog( UsageMsg, buff,  sizeof( UsageMsg ) / sizeof( char *) );
    }
#else
    {
        int     i;
        int     cnt;

        if( str != NULL ) {
            va_start( al, str );
            MyVPrintf( str, al );
            va_end( al );
            cnt = 1;
        } else {
            cnt = sizeof( UsageMsg ) / sizeof( char *);
        }

        for( i = 0; i < cnt; i++ ) {
            MyPrintf( "%s\n", UsageMsg[i] );
        }
    }
#endif
    // can't do an ExitEditor because we will not have initialized anything
    // yet (this is always called from checkFlags)
    // ExitEditor( 0 );
    ChangeDirectory( HomeDirectory );
    FiniMem();
    exit( 0 );

} /* Usage */
Exemple #17
0
//---------------------------------------------------------------------------
void __fastcall TUnixDirView::ExecuteFile(TListItem * Item)
{
#ifndef DESIGN_ONLY
  ASSERT_VALID_ITEM;
  if (ITEMFILE->IsDirectory ||
      !Terminal->ResolvingSymlinks)
  {
    PathChanging(true);
    ChangeDirectory(ITEMFILE->FileName);
  }
  else
  {
    if (ItemFocused != Item) ItemFocused = Item;
    DisplayPropertiesMenu();
  }
#else
  USEDPARAM(Item);
#endif
}
bool LoadCtrl::OnCommand (int ctrlId, int notifyCode) throw (Win::Exception)
{
	if (ctrlId == IDOK || ctrlId == IDC_LIST && notifyCode == LBN_DBLCLK)
	{
		if (_listBox.GetSelectedPath (GetWindow (), GetBuffer (), GetBufLen ()))
		{
			// directory selected
			ChangeDirectory ();
		}
		else if (_listBox.IsSelection ())
			EndOk ();
		else
			EndCancel ();
		return true;
	}
	else if (ctrlId == IDCANCEL)
	{
		EndCancel ();
		return true;
	}
	return false;
}
Exemple #19
0
void CommandParser::start()
{

    Vector< String > args;
    help( args);
    char buf[2000];

    while (true)
    {
        printf("%s > ",FileSystem::path().data());
        String line(Terminal::readLine(buf));
        Vector< String > args = line.split(' ');
        if (args.isEmpty())
            continue;
        String command = args[0];

        if (command == String("time"))
            Ticks(args);
        else if (command == String("ram"))
            Ram(args);
        else if (command == String("cls"))
            ClearScreen(args);
        else if (command == String("ls"))
            ListOfFiles(args);
        else if (command == String("cd"))
            ChangeDirectory(args);
        else if (command == String("read"))
            ReadFile(args);
        else if (command == String("reboot"))
            reboot(args);
        else if (command == String("help"))
            help(args);
        else if (command == String("wait"))
            wait(args);
        else
            Unknown(args);
    }
}
Exemple #20
0
/*
 * SaveFile - save data from current file
 */
vi_rc SaveFile( char *name, linenum start, linenum end, int dammit )
{
    int         i;
    bool        existflag = FALSE, restpath = FALSE, makerw = FALSE;
    char        *fn;
    fcb         *cfcb, *sfcb, *efcb;
    linenum     s, e, lc;
    long        bc = 0;
    status_type lastst;
    vi_rc       rc;
    int         write_crlf;

    if( CurrentFile == NULL ) {
        return( ERR_NO_FILE );
    }

    /*
     * get file name
     */
    if( name == NULL ) {
        if( CurrentFile->viewonly ) {
            return( ERR_FILE_VIEW_ONLY );
        }
        if( CFileReadOnly() ) {
            rc = readOnlyCheck();
            if( rc != ERR_NO_ERR ) {
                return( ERR_READ_ONLY_FILE );
            }
            makerw = TRUE;
        }
        fn = CurrentFile->name;
        restpath = TRUE;
    } else {
        existflag = TRUE;
        fn = name;
    }
    if( fn[0] == 0 ) {
        return( ERR_NO_FILE_NAME );
    }
    if( SameFile( fn, CurrentFile->name ) ) {
        if( CurrentFile->viewonly ) {
            return( ERR_FILE_VIEW_ONLY );
        }
    }
    if( dammit ) {
        existflag = FALSE;
    }

    /*
     * get range and fcbs
     */
    if( start == -1L && end == -1L ) {
        s = 1L;
        rc = CFindLastLine( &e );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
    } else {
        s = start;
        e = end;
    }
    lc = e - s + 1;
    rc = FindFcbWithLine( s, CurrentFile, &sfcb );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    rc = FindFcbWithLine( e, CurrentFile, &efcb );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }

    if( restpath ) {
        rc = ChangeDirectory( CurrentFile->home );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
    }
    if( !CurrentFile->is_stdio ) {
        if( makerw ) {
            chmod( fn, PMODE_RW );
        }
        rc = FileOpen( fn, existflag, O_TRUNC | O_WRONLY | O_BINARY | O_CREAT, WRITEATTRS, &fileHandle);
        if( rc != ERR_NO_ERR ) {
            Message1( strerror( errno ) );
            return( rc );
        }
    } else {
        fileHandle = 0;
#ifdef __WATCOMC__
        setmode( fileno( stdout ), O_BINARY );
#endif
    }

    /*
     * start writing fcbs
     */
#ifdef __WIN__
    ToggleHourglass( TRUE );
#endif
    if( EditFlags.CRLFAutoDetect ) {
        write_crlf = CurrentFile->write_crlf;
    } else {
        write_crlf = EditFlags.WriteCRLF;
    }
    lastst = UpdateCurrentStatus( CSTATUS_WRITING );
    for( cfcb = sfcb; cfcb != efcb; cfcb = cfcb->next ) {
        rc = writeRange( s, cfcb->end_line, cfcb, &bc, write_crlf, TRUE );
        if( rc != ERR_NO_ERR ) {
#ifdef __WIN__
            ToggleHourglass( FALSE );
#endif
            UpdateCurrentStatus( lastst );
            return( rc );
        }
        s = cfcb->end_line + 1;
    }

    /*
     * last bit
     */
    rc = writeRange( s, e, efcb, &bc, write_crlf, EditFlags.LastEOL );
#ifdef __WIN__
    ToggleHourglass( FALSE );
#endif
    UpdateCurrentStatus( lastst );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    if( !CurrentFile->is_stdio ) {
        i = close( fileHandle );
        if( makerw ) {
            chmod( fn, PMODE_R );
        }
        if( i == -1 ) {
            Message1( strerror( errno ) );
            return( ERR_FILE_CLOSE );
        }
    }
    if( restpath ) {
        rc = ChangeDirectory( CurrentDirectory );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
    }

    FileIOMessage( fn, lc, bc );
    return( ERR_NO_ERR );

} /* SaveFile */
Exemple #21
0
void RunShell()
{
    int running = 1;
    char* str;
    char** argv;
    InitBackgroundProcessing();
    while (running)
    {
        CheckProcessQueue();
        PrintPrompt();
        str = ReadInput();
        argv = ParseInput(str);

        if (argv[0] == NULL)
        {
            // do nothing if empty arguments
        }
        else if (CheckForIOandPipeErrors(argv))
        {
            // do nothing if IO or pipe error
        }
        else if (CheckForBackgroundErrors(argv))
        {
            // do nothing if background processing format error
        }
        else if (strcmp(argv[0], "exit") == 0)
        {
            BigFree(argv);
            printf("Exiting Shell...\n");
            OnExitProcessQueueWait();
            exit(0);
        }
        else if (strcmp(argv[0], "cd") == 0)
        {
            if (ArraySize(argv) <= 2)
            {
                if (ArraySize(argv) == 2)
                    ChangeDirectory(argv[1]);
                else
                    ChangeDirectory(getenv("HOME"));
            }
            else
            {
                printf("Too many arguments...\n");
            }
        }
        else if (strcmp(argv[0], "limits") == 0)
        {
            if (ArraySize(argv) > 1)
            {
                argv = ArrayRemoveElement(argv, 0);
                Limits(argv);
            }
        }
        else if (strcmp(argv[0], "etime") == 0)
        {
            if (ArraySize(argv) > 1)
            {
                argv = ArrayRemoveElement(argv, 0);
                ETime(argv);
            }
        }
        else if (IsExecutable(argv[0]))
        {
            int background = VecContainsStr(argv, "&");
            int I_loc = VecContainsStr(argv, "<");
            int O_loc = VecContainsStr(argv, ">");
            int pipe_count = ArgvCountSymbol(argv, "|");
            if (I_loc != -1)
            {
                argv = ExecuteExternalWithInput(argv, I_loc, background);
            }
            else if (O_loc != -1)
            {
                argv = ExecuteExternalWithOutput(argv, O_loc, background);
            }
            else if (pipe_count > 0)
            {
                argv = ExecuteExternalWithPipe(argv, pipe_count, background);
            }
            else
            {
                char* cmd = ArgvToString(argv);
                if (background != -1)
                {
                    argv = ArrayRemoveElement(argv, background);
                }
                ExecuteExternal(argv, background, cmd);
                free(cmd);
            }
        }
        BigFree(argv);
    }
}
Exemple #22
0
void CFtpDialog::MessageReceived(BMessage *msg)
{
	switch (msg->what)
	{
		case 'cnct':
			Connect();
			break;

		case msg_ServerNameChanged:
			fServerName->MarkAsInvalid(false);
			break;

		case msg_SelectedDirectory:
		{
			BMenuItem *src;
			FailOSErr(msg->FindPointer("source", (void**)&src));

			strcpy(fPath, "/");
			if (src != fDirectoryField->Menu()->ItemAt(0))
			{
				int i = 1;

				while (true)
				{
					if (i >= fDirectoryField->Menu()->CountItems())
						break;

					BMenuItem *I = fDirectoryField->Menu()->ItemAt(i);

					strcat(fPath, I->Label());
					strcat(fPath, "/");

					if (src == I)
						break;

					++i;
				}
			}

			ChangeDirectory();
			break;
		}

		case msg_SelectedListItem:
		{
			CFtpListItem *i = dynamic_cast<CFtpListItem*>(
				fListView->ItemAt(fListView->CurrentSelection()));
			if (i == reinterpret_cast<CFtpListItem*>(NULL))
			{
				beep();
				return;
			}

			if (i->IsDirectory())
			{
				strcat(fPath, *i);
				strcat(fPath, "/");
				ChangeDirectory();
			}
			else if (OkClicked())
				Quit();
			break;
		}

		case msg_ToggleDot:
			ListDirectory();
			break;

		default:
			HDialog::MessageReceived(msg);
			break;
	}
} // CFtpDialog::MessageReceived
Exemple #23
0
bool CFtpDialog::OkClicked()
{
	CFtpListItem *i;

	if (fSave)
	{
		i = dynamic_cast<CFtpListItem*>(
			fListView->ItemAt(fListView->CurrentSelection()));
		if (i && i->IsDirectory())
		{
			ChangeDirectory();
			return false;
		}
		else
		{
			try
			{
				BMessage msg(msg_DoFtpSave);
				msg.AddPointer("url", new URLData(GetText("srvr"), GetText("user"),
					GetText("pass"), fPath, GetText("name")));
				if (fOwner)
					fOwner->PostMessage(&msg);
				else
					fCaller.SendMessage(&msg);
				return true;
			}
			catch (HErr& e)
			{
				e.DoError();
			}
		}
	}
	else
	{
		int32 dirCnt = 0;
		int32 filCnt = 0;
		int32 n = -1;
		while ((i = dynamic_cast<CFtpListItem*>(
			fListView->ItemAt(fListView->CurrentSelection(++n))))) {
			if (i && i->IsDirectory())
				dirCnt++;
			else
				filCnt++;
		}
		if (dirCnt == 1  && filCnt == 0)
		{
			ChangeDirectory();
			return false;
		}
		else if (dirCnt == 0 && filCnt > 0)
		{
			n = -1;
			Hide();
			while ((i = dynamic_cast<CFtpListItem*>(
				fListView->ItemAt(fListView->CurrentSelection(++n))))) {
				try
				{
					URLData url(GetText("srvr"), GetText("user"), GetText("pass"), fPath, *i);
					gApp->NewWindow(url);
				}
				catch (HErr& e)
				{
					e.DoError();
				}
			}

			return true;
		}
		else
		{
			beep();
		}
	}
	return false;
} // CFtpDialog::OkClicked
gboolean ChangeDirectory(const char* d) {
  
  Log(DEBUGGING, "ChangeDirectory \"%s\"", d);
  char data[LIBUSB_PATH_MAX];
  int c;
  char directory_p[LIBUSB_PATH_MAX], *directory;
  directory = directory_p;
  strncpy(directory, d, LIBUSB_PATH_MAX - 1);
  
  //the following breaks the CD into seperate directory paths...
  //I found the complex path support in the camcorder a bit flakey.
  if((strlen(directory) > 1) && (directory[0] == '/')) {
    if(ChangeDirectory("/")==FALSE)
      return FALSE;
    //directory=directory.Mid(1,LIBUSB_PATH_MAX); //strip off leading /
    directory++;
    rTrim(directory, '/');
    
    //    directory.TrimRight("/"); //strip off trailing /
  }
  

  while( strlen(directory)>1 && directory[0]=='/' ) { //FIXME
    char temp[LIBUSB_PATH_MAX];
    strncpy(temp, directory, LIBUSB_PATH_MAX - 1);
    if (directory[0]=='/')
      directory[0] = '\0';    
    
    if(ChangeDirectory(temp)==FALSE) {
      Log(ERROR, "failed to change directory to parent directory %s",temp);
      return FALSE;
    }

    strncpy(temp, directory, LIBUSB_PATH_MAX - 1);
    directory = temp + 1;
    //ptemp[strlen(ptemp) - 1] = '\0';
    rTrim(directory, '/');
    //    directory=directory.Mid(directory.Find('/')+1,LIBUSB_PATH_MAX);
    //    directory.TrimRight("/");
  }
  
  //We're at a single level directory at this point... lets validate it
  if(strlen(directory) == 0)
    return TRUE;
  c=directory[0];
  if(! ( ((c>='a')&&(c<='z')) ||  ((c>='A')&&(c<='Z'))  || 
	 ((c>='0')&&(c<='9')) || (c=='_') || c=='/') ) {
    Log(ERROR, "//not liking the first character of this directory!");
    //the camcorder's CD command created directories if they're not
    //there... best to be prudent and assume it's some kind of error.
    return FALSE;
  }
  
  //validation is done... we can procede with the actual command stuff.
  memset(&data,0x00,LIBUSB_PATH_MAX);
  strcpy(data,directory);
  
  if(ControlMessageWrite(0xb800,data, strlen(data)+1,TIMEOUT)==TRUE) {
    return TRUE;
  }
  Log(ERROR, "change directory to %s failed", directory);
  return FALSE;
}
static void RecursiveListing(const char* parentpath, file_info* parent, GtkTreeIter* parent_place, int partition, int level, GtkTreeStore* treestore) {
  gboolean firstitem;
  file_info tData, pData;
  int count;
  //  const char* parentpath = parentpath_cs.text;
  int t;
  GtkTreeIter child;
  // file_info hitems[999];
  char recursedir[STRINGSIZE];
  char tempstring[STRINGSIZE];
  file_info* f_i;
  int total_getfileinfo_calls = 0;
  firstitem = TRUE;
  
  Log(DEBUGGING, "RecursiveListing: %s", parentpath);
  if (level == 5) return; //recursive runaway!!! lookout!!!

  //for (t=0; t < 1000; ++t) {
    //    hItem[t].number_of_children = 0; //only parameter that would really get you in trouble
    
  // }
  //NOTE: We take 2 passes at the directory, due to the way the
  //camcorder directory listing works (doesn't lend itself to easy
  //recursion.
  
  for(t=0;t<1000;t++)  { //don't bitch. 1000 items in one directory is a lot.
    Log(DEBUGGING, "Getfileinfo?");
    if(GetFileInfo(&tData, firstitem)==FALSE)
      break; //we've passed the last item.
    ++total_getfileinfo_calls;
    Log(DEBUGGING, "Getfileinfo.");
    firstitem=FALSE;
    
    
    if( (strcmp(tData.filename,".") == 0) ||
	(strcmp(tData.filename,"..") == 0) ||
	(tData.filename[0]==0x20) ) { //0x20 == space bar?
      t--;
      continue;
    }
    
    strcpy(pData.filename,tData.filename);
    pData.filesize = tData.filesize;
    pData.filetype = tData.filetype;
    pData.number_of_children = 0;
    
    strcpy(pData.dirpath, parentpath);
    strcpy(pData.fullpath, parentpath);
    
    if (strlen(tData.filename) + strlen(pData.fullpath) < STRINGSIZE - 1)
      strcat(pData.fullpath, tData.filename);
    pData.partition=partition;
    Log(DEBUGGING, "pData.fullpath: %s", pData.fullpath);
      
      
    f_i = AddToTreeStore(GTK_TREE_STORE(treestore), parent_place, &child, &pData, parent);
    //from here on in f_i and pData should contain the same info (at different memory locations)
    //also, AddToTreeStore stores data elsewhere so don't delete f_i
    if(pData.filetype==FIDIR) {
      Log(DEBUGGING, "if (pData.filetype == FIDIR)");
      strncpy (recursedir, pData.fullpath, STRINGSIZE - 2);
      strcat (recursedir, "/");
      if (ChangeDirectory(pData.fullpath) == FALSE) {
	Log(ERROR, "Couldn't recurse into %s", pData.fullpath);
	return;
	
      }

      //      RecursiveListing(recursedir, f_i);
      //hItem[t] = m_directory_tree.InsertItem(pData->filename,0,0,parent);
      //Log("enter recursion");
      
      //RecursiveListing(NULL, NULL, NULL, 0, 0, NULL);
      Log(DEBUGGING, "RecursiveListing recursion.");
      RecursiveListing(recursedir, f_i, &child, partition, level + 1, GTK_TREE_STORE(treestore));
      //      strncpy(tempstring, f_i->dirpath, STRINGSIZE - 2); //really hoping dirpath is this dir
      //      strcat(tempstring, "/");
      if (ChangeDirectory(pData.dirpath) == FALSE) {
	Log(ERROR, "couldn't change back to current directory after recursion");
	return;
      }
      if (firstitem == TRUE) firstitem = FALSE;
      GetFileInfo(&pData, TRUE);
      for (count = 1; count < total_getfileinfo_calls; ++count) {
	GetFileInfo(&pData, FALSE);
      }
      //Log("end recursion");
    } else {
	//AddToTreeStore(treestore, parent_place, &child, &pData, parent);
      Log(DEBUGGING, "Not a directory: %s", pData.fullpath);
      
      //Log("that point");
      
      //hItem[t] = m_directory_tree.InsertItem(pData->filename,2,2,parent);
    }
    //SetItemData(hItem[t],(DWORD)pData);;
    
  }
  //end = t;

  //return; //debug... don't recurse

  /*for(t=0;t<end;t++) {
    //if(hItem[t]==0)
    //  return;
    rData=(FILE_INFO *)m_directory_tree.GetItemData(hItem[t]);
    if(rData->filetype==FIDIR)
      {
	CString recursedir=rData->fullpath + "/";
	if(m_camcorder.ChangeDirectory(rData->fullpath)==false)
	  {
	    Log("Couldn't recurse into "+rData->fullpath);
	    return;
	  }
	RecursiveListing(recursedir,hItem[t],partition, level+1);
		}
	}

  */
  
}
static GtkTreeModel* create_model(void) {
  GtkTreeStore* treestore = gtk_tree_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
  GtkTreeIter rootlevel, toplevel;
  int t;
  file_info root_file_data, current_file_data, *addeditem = NULL;
  
  char tempstring[STRINGSIZE];
  //  EnableControls(FALSE);

  strcpy(root_file_data.filename, "/");
  root_file_data.filesize = 0;
  root_file_data.filetype = FIROOT;
  strcpy(root_file_data.fullpath, "");
  root_file_data.partition = 255;
  root_file_data.number_of_children = 0;
  

  AddToTreeStore(treestore, NULL, &rootlevel, &root_file_data, NULL);
  /*  gtk_tree_store_append(treestore, &rootlevel, NULL); //create blank entry
  root_directory = AddFileDataToList(&root_file_data);
  addeditem = root_directory;
  gtk_tree_store_set(treestore, &rootlevel, COL_FILENAME, root_file_data.filename, COL_POINTER, addeditem, -1);*/


  for (t=0; t<5; ++t) {
    if (t == 1) continue; //skip the non-filesystem partition
    
    snprintf(tempstring, STRINGSIZE-1, "p%d",t);  //partition directory name
    strcpy(current_file_data.filename, tempstring);
    current_file_data.filesize = 0;
    strcpy(current_file_data.fullpath, "/");
    strcpy(current_file_data.dirpath, "/");
    current_file_data.partition = t;
    current_file_data.filetype = FIPART;
    current_file_data.number_of_children = 0;
    strcpy(tempstring, "add filename: ");
    if (strlen(tempstring) + strlen(current_file_data.filename) < STRINGSIZE)
      strcat(tempstring, current_file_data.filename);
    //    Log("add filename:");
    Log(DEBUGGING, "current_file_data.filename: %s", current_file_data.filename);

    AddToTreeStore(treestore, &rootlevel, &toplevel, &current_file_data, &root_file_data);

    if (ChangePartition(t) == FALSE) {
      EnableControls(TRUE);
      return NULL;
    }
    if(ChangeDirectory("/")==FALSE) {
      EnableControls(TRUE);
      return NULL;
    }
    //RecursiveListing("/",addeditem,t);
    //    strcpy(tempstring, "/");
    RecursiveListing("/", addeditem, &toplevel, t, 0, treestore);
    //m_directory_tree.Expand(hItem[t],TVE_EXPAND);//hmm?
    
    //TODO: map filename data to some data in memory
    
  }

  //m_directory_tree.Expand(rItem,TVE_EXPAND);
	
  ChangePartition(0); //make sure we're back at the media partition!!!
  ChangeDirectory("/DCIM");

  //Log();
  EnableControls(TRUE);
  return GTK_TREE_MODEL(treestore);
	
}
Exemple #27
0
__geta4 void main(void)
#endif
{
  DEBUG_FUNC_IN();

  uint32_t spiclk;
  fileTYPE sd_boot_file;

  HideSplash();
  SPI_fast();

  // boot message
  draw_boot_logo();
  BootPrintEx("**** MINIMIG-DE1 ****");
  BootPrintEx("Minimig by Dennis van Weeren");
  BootPrintEx("Updates by Jakub Bednarski, Tobias Gubener, Sascha Boing, A.M. Robinson & others");
  BootPrintEx("DE1 port by Rok Krajnc ([email protected])");
  BootPrintEx(" ");
  sprintf(s, "Build git commit: %s", __BUILD_REV);
  BootPrintEx(s);
  sprintf(s, "Build git tag: %s", __BUILD_TAG);
  BootPrintEx(s);
  BootPrintEx(" ");
  BootPrintEx("For updates & code see https://github.com/rkrajnc/minimig-de1");
  BootPrintEx("For support, see http://www.minimig.net");
  BootPrintEx(" ");

  printf("\r\r**** MINIMIG-DE1 ****\r\r");
  printf("Minimig by Dennis van Weeren\r");
  printf("Updates by Jakub Bednarski, Tobias Gubener, Sascha Boing, A.M. Robinson & others\r");
  printf("DE1 port by Rok Krajnc ([email protected])\r\r");
  printf("Build no. ");
  printf(__BUILD_NUM);
  //printf(" by ");
  //printf(__BUILD_USER);
  printf("\rgit commit ");
  printf(__BUILD_REV);
  printf("\rgit tag");
  printf(__BUILD_TAG);
  printf("\r\r");
  printf("For updates & code see https://github.com/rkrajnc/minimig-de1\r");
  printf("For support, see http://www.minimig.net/\r\r");

  spiclk = 100000 / (20*(read32(REG_SPI_DIV_ADR) + 2));
  printf("SPI divider: %u\r", read32(REG_SPI_DIV_ADR));
  sprintf(s, "SPI clock: %u.%uMHz", spiclk/100, spiclk%100);
  BootPrintEx(s);
  printf("%s\r", s);

  if (!MMC_Init()) FatalError(1);
  BootPrintEx("SD card found ...");
  printf("SD card found ...\r");

  if (!FindDrive()) FatalError(2);
  BootPrintEx("Drive found ...");
  printf("Drive found ...\r");

  ChangeDirectory(DIRECTORY_ROOT);

  //eject all disk
  df[0].status = 0;
  df[1].status = 0;
  df[2].status = 0;
  df[3].status = 0;
 
  BootPrintEx("Booting ...");
  printf("Booting ...\r");

  TIMER_wait(8000);
  config.kickstart.name[0]=0;
  SetConfigurationFilename(0); // Use default config
  LoadConfiguration(0);  // Use slot-based config filename

  // main loop
  while (1) {
    HandleFpga();
    HandleUI();
  }

  DEBUG_FUNC_OUT();
}
Exemple #28
0
/*
 * ExitEditor - do just that
 */
void ExitEditor( int rc )
{
#ifdef __WIN__
    WriteProfile();
#endif
#ifdef __IDE__
    IDEFini();
#endif
#ifdef __WIN__
    DDEFini();
#endif
    SaveHistory();
    RestoreInterrupts();
    SwapFileClose();
    WindowSwapFileClose();
    SwapBlockFini();
    ExtendedMemoryFini();
    SelRgnFini();
    LangFiniAll();
    FiniMouse();
    FiniMenu();
    FiniSavebufs();
    FindCmdFini();
    DirFini();
    CurrentWindow = NO_WINDOW;
    FinishWindows();
    ScreenFini();
#ifdef __WIN__
    FiniClrPick();
    FiniFtPick();
    CursorOp( COP_FINI );
    SubclassGenericFini();
    FiniProfile();
#endif
    FiniFileStack();
    DeleteResidentScripts();
    MatchFini();
    FiniKeyMaps();
    ErrorFini();
    FiniCommandLine();
    SSFini();
    HistFini();
    BoundDataFini();
    FTSFini();
    StaticFini();
    VarFini();
    AutoSaveFini();
    FiniConfigFileName();
    miscGlobalsFini();
    ChangeDirectory( HomeDirectory );
#if defined( __NT__ ) && !defined( __WIN__ )
    {
        SetConsoleActiveScreenBuffer( GetStdHandle( STD_OUTPUT_HANDLE ) );
    }
#endif
    MemFree( HomeDirectory );
    MemFree( CurrentDirectory );
#if defined( VI_RCS )
    ViRCSFini();
#endif
    FiniMem();
    exit( rc );

} /* ExitEditor */
gboolean delete_file(GtkWidget* widget,
		     GdkEvent* event,
		     gpointer data) {
  GtkTreeSelection* selection;
  GtkTreeModel* model;// = m_directory_model;
  GtkTreeIter iter;
  char tempstring[STRINGSIZE];
  
  if(CheckCameraOpen()==FALSE)
    return FALSE;
  
  //HTREEITEM hItem = m_directory_tree.GetSelectedItem();
  
  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_directory_tree));
  if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
    //    gpointer data = NULL;
    file_info* p = NULL;
    //    gchar* filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(file_selection_box));
    gchar* filename;
    //char [STRINGSIZE];
    //    char* storedir = dirpath;
    //string_combo s_c;
    gtk_tree_model_get (model, &iter, COL_FILENAME, &filename,
			COL_POINTER, &data, -1);
    p = data;
   
    if (p) {
      if(p->filetype!=FIFILE) {
	MessageBox("Sorry, delete is currently limited to files");
	return FALSE;
      }
      
      if(p->partition!=0) {
	if (MessageBoxConfirm("Do you really want delete a file from a non-movie partition?\r\nThis could easily kill your camera.") == FALSE)
	  return FALSE;
      } else {
	strcpy(tempstring, "Do you really want to delete ");
	if (strlen(tempstring) + strlen(p->filename) + 1 < STRINGSIZE) {
	  strcat(tempstring,p->filename);
	  strcat(tempstring,"?");
	}
	if (MessageBoxConfirm(tempstring) == FALSE) {
	  return FALSE;
	}
	
	if(ChangePartition(p->partition)==FALSE) {
	  return FALSE;
	}
	  
	if(ChangeDirectory(p->dirpath)==FALSE) {
	  return FALSE;
	}
	
	EnableControls(FALSE);
	  
	if(DelFile(p->filename)==FALSE) {
	  Log(ERROR, "Failed to delete %s", p->filename);
	  EnableControls(TRUE);
	  return FALSE;
	}
	Log(ERROR, "Deleted %s successfully", p->filename);
	EnableControls(TRUE);
      }
    }
  } 
  return TRUE;
}