Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8276 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Jun 8, 2006, 5:21:29 PM (18 years ago)
Author:
bensch
Message:

merged new GUI

Location:
trunk/src/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/gui/gl/glgui_style.h

    r8145 r8276  
    3434    virtual ~GLGuiStyle();
    3535
    36 
    3736  private:
    3837    float             _borderLeft;           //!< The Distance to the left Border of the widget, before any internal Element starts.
  • trunk/src/lib/shell/shell_completion_plugin.cc

    r7661 r8276  
    100100      dir.setFileName(ResourceManager::getInstance()->getDataDir() + this->_subDir);
    101101      dir.open();
    102       while(dir)
     102      for(unsigned int i = 0; i < dir.fileCount(); i++ )
    103103      {
    104         completionList.push_back(this->_subDir + "/" + dir.next());
     104        completionList.push_back(this->_subDir + "/" + dir[i]);
    105105      }
    106106    }
     
    118118      std::string fileName;
    119119      std::string currFile;
    120       while(dir)
     120      for(unsigned int i = 0; i < dir.fileCount(); i++)
    121121      {
    122         currFile = dir.next();
     122        currFile = dir[i];
    123123        if (currFile[0] == '.')
    124124         continue;
  • trunk/src/lib/util/directory.cc

    r7661 r8276  
    3838
    3939#if not defined (__WIN32__)
    40  #include <sys/stat.h>
    41  #include <sys/types.h>
     40#include <sys/types.h>
     41#include <sys/stat.h>
     42#include <dirent.h>
     43#else
     44#include <windows.h>
     45#include <winbase.h>
    4246#endif
     47
     48#include <iostream>
     49
     50/**
     51 * @brief Constructs a Directory handler.
     52 * @param directoryName the name of the Directory to access.
     53 */
    4354Directory::Directory(const std::string& directoryName)
    44   : File(directoryName), willfail(false)
     55    : File(directoryName)
    4556{
    46   this->handle = 0;
    47   this->willfail = true;
     57  this->_opened = false;
    4858}
    4959
     60/**
     61 * @brief destructs the Directory.
     62 */
    5063Directory::~Directory()
    5164{
     65  this->close();
    5266}
    5367
     68
     69/**
     70 * @brief openes the Directory
     71 * @returns true on success, false on error. (does not exist, no rights -> test with functions of File)
     72 *
     73 * Fills the List of Files, and sets the Directory to open state
     74 */
    5475bool Directory::open()
    5576{
     77  if (this->_opened)
     78    this->close();
     79
     80  // Openes the Directory for reading:
    5681#if not defined(__WIN32__)
    57   if (this->handle != NULL)
    58     this->close();
    59   this->handle = opendir(this->name().c_str());
     82  DIR* handle;
     83  handle = opendir(this->name().c_str());
    6084  if (!handle)
    61     willfail = true;
     85  {
     86    std::cerr << "could not open directory " << this->name() << " for reading" << std::endl;
     87    return false;
     88  }
     89#else
     90  HANDLE handle;
     91
     92  // First check the attributes trying to access a non-Directory with
     93  // FindFirstFile takes ages
     94  DWORD attrs = GetFileAttributes(this->name().c_str());
     95  if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) )
     96  {
     97    return false;
     98  }
     99  std::string Full(this->name());
     100  // Circumvent a problem in FindFirstFile with c:\\* as parameter
     101  if ( (Full.length() > 0) && (Full[Full.length()-1] != '\\') )
     102    Full += "\\";
     103  WIN32_FIND_DATA entry;
     104  handle = FindFirstFile( (Full+"*").c_str(), &entry);
     105  if (handle == INVALID_HANDLE_VALUE)
     106  {
     107    std::cerr << "could not open directory " << this->name() << " for reading" << std::endl;
     108    return false;
     109  }
    62110  else
    63111  {
    64     willfail = false;
    65     dirent* entry = readdir(handle);
    66     if (entry)
    67       current = entry->d_name;
    68     else
    69       willfail = true;
     112    this->_fileNames.push_back(entry.cFileName);
    70113  }
    71 #else
    72     if (handle != INVALID_HANDLE_VALUE)
    73       this->close();
    74 
    75     // First check the attributes trying to access a non-Directory with
    76     // FindFirstFile takes ages
    77     DWORD attrs = GetFileAttributes(this->name().c_str());
    78     if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) )
    79     {
    80       willfail = true;
    81       return false;
    82     }
    83     std::string Full(this->name());
    84     // Circumvent a problem in FindFirstFile with c:\\* as parameter
    85     if ( (Full.length() > 0) && (Full[Full.length()-1] != '\\') )
    86       Full += "\\";
    87     WIN32_FIND_DATA entry;
    88     handle = FindFirstFile( (Full+"*").c_str(), &entry);
    89     if (handle == INVALID_HANDLE_VALUE)
    90     {
    91       willfail = true;
    92       return false;
    93     }
    94     else
    95     {
    96       willfail = false;
    97       current = entry.cFileName;
    98       return true;
    99     }
    100114#endif
    101115
     116  // BUILDING the list of contained Files. (only the names)
     117#if not defined(__WIN32__)
     118  dirent* entry;
     119  while ((entry = readdir(handle)) != NULL)
     120    this->_fileNames.push_back(entry->d_name);
     121  closedir(handle);
     122#else
     123  WIN32_FIND_DATA entry;
     124  while ((int ok = FindNextFile(handle, &entry)) != 0)
     125    this->_fileNames.push_back(entry.cFileName);
     126  FindClose(handle);
     127#endif
     128  this->_opened = true;
     129  return true;
    102130}
    103131
     132/**
     133 * @brief closes the directory
     134 * @returns true.
     135 *
     136 * Clears the List of Files in the Directory.
     137 */
    104138bool Directory::close()
    105139{
    106 #if not defined(__WIN32__)
    107   if (this->handle != NULL)
    108     closedir(handle);
    109   this->handle = NULL;
    110 #else
    111   if (handle != INVALID_HANDLE_VALUE)
    112     FindClose(handle);
    113     handle = 0;
    114 #endif
    115   this->willfail = true;
    116   this->current = "";
     140  this->_opened = false;
     141  this->_fileNames.clear();
    117142  return true;
    118143}
    119144
    120145
    121 
    122 std::string Directory::next()
    123 {
    124 #if not defined(__WIN32__)
    125   std::string prev(current);
    126   dirent* entry = readdir(handle);
    127   if (entry)
    128     current = entry->d_name;
    129   else
    130     willfail = true;
    131   return prev;
    132 
    133 #else
    134   std::string prev = current;
    135   WIN32_FIND_DATA entry;
    136   int ok = FindNextFile(handle, &entry);
    137   if (!ok)
    138     willfail = true;
    139   else
    140     current = entry.cFileName;
    141   return current;
    142 #endif
    143 }
    144 
    145 
     146/**
     147 * @brief creates the directory
     148 * @returns true on success, false on error
     149 */
    146150bool Directory::create()
    147151{
  • trunk/src/lib/util/directory.h

    r7661 r8276  
    2727
    2828#include "file.h"
    29 
    30 #if not defined (__WIN32__)
    31  #include <sys/types.h>
    32  #include <dirent.h>
    33 #else
    34  #include <windows.h>
    35  #include <winbase.h>
    36 #endif
     29#include <vector>
    3730
    3831class Directory : public File
     
    4437  virtual bool open();
    4538  virtual bool close();
    46   operator void*() const { return willfail ? (void*)0:(void*)(-1); }
    47 
    48   std::string next();
    4939
    5040  bool create();
    5141
     42  /** @returns if the Directory was opened */
     43  bool isOpen() const { return this->_opened; }
     44  /** @returns the FileCount (count of files contained in this directory) */
     45  unsigned int fileCount() const { return _fileNames.size(); };
     46  /** @returns the FileNames contained inside of the Directory */
     47  const std::vector<std::string>& fileNames() const { return this->_fileNames; };
     48  /** @returns the i'th FileName @param fileNumber the fileNumber (must not bigger than fileCount()) */
     49  const std::string& operator[](unsigned int fileNumber) const { return this->_fileNames[fileNumber]; };
     50  /** @returns a formated string containing the FileName, prepended with the directory-Name */
     51  std::string fileNameInDir(unsigned int fileNumber) const { return this->name() + "/" + _fileNames[fileNumber]; };
     52  /** @returns a File pointing to the File @param fileNumber the fileNumber (must not bigger than fileCount()) */
     53  File getFile(unsigned int fileNumber) const { return File(fileNameInDir(fileNumber)); };
     54
    5255private:
    53 #if not defined(__WIN32__)
    54   DIR* handle;
    55 #else
    56   HANDLE    handle;
    57 #endif
    58   bool willfail;
    59   std::string current;
     56  bool                        _opened;          //!< If the directory was opened.
     57  std::vector<std::string>    _fileNames;       //!< The List of Files contained in the directory. (will be filled when open was called.)
    6058};
    6159
  • trunk/src/lib/util/file.cc

    r7674 r8276  
    160160{
    161161#warning implement
     162  return false;
    162163}
    163164
     
    165166{
    166167#warning implement
     168  return false;
    167169}
    168170
     
    249251    oFile.put(ch);
    250252  }
     253  return true;
    251254}
    252255
     
    298301bool File::remove()
    299302{
     303  if (!this->exists())
     304    return false;
     305
    300306  this->close();
    301307  unlink(this->_name.c_str());
    302308  delete this->_status;
    303309  this->_status = NULL;
     310
     311  return true;
    304312}
    305313
Note: See TracChangeset for help on using the changeset viewer.