Пример #1
0
dmz::Boolean
dmz::set_qwidget_stylesheet (const String &Name, const Config &Source, QWidget *widget) {

   Boolean result (False);

   if (widget) {

      Config cd;

      if (Name) { Source.lookup_config (Name, cd); }
      else { cd = Source; }

      String qss (config_to_string ("file", cd));

      if (qss) {

         QFile file (qss.get_buffer ());
         if (file.open (QFile::ReadOnly)) {

            QString styleSheet (QLatin1String (file.readAll ()));
            widget->setStyleSheet (styleSheet);

            qDebug () << widget->objectName () << "Style Sheet:" << qss.get_buffer ();
            result = True;
         }
      }
   }

   return result;
}
Пример #2
0
// QtPluginIconPalletTool Interface
void
dmz::QtPluginIconPalletTool::_add_type (const ObjectType &Type) {

   const String IconResource = config_to_string (
      get_plugin_name () + ".resource",
      Type.get_config());

   const String IconName = _rc.find_file (IconResource);

   if (IconName) {

      const String Name = Type.get_name ();

      if (Name) {

         QImage back (
            (int)_iconExtent,
            (int)_iconExtent,
            QImage::Format_ARGB32_Premultiplied);
         QPainter painter (&back);
         painter.setCompositionMode (QPainter::CompositionMode_Source);
         painter.fillRect (back.rect (), Qt::transparent);
         painter.setCompositionMode (QPainter::CompositionMode_SourceOver);
         QSvgRenderer qsr (QString (IconName.get_buffer ()));
         QRectF size = qsr.viewBoxF ();
         qreal width = size.width ();
         qreal height = size.height ();
         qreal scale = (width > height) ? width : height;
         if (scale <= 0.0f) { scale = 1.0f; }
         scale = _iconExtent / scale;
         width *= scale;
         height *= scale;
         size.setWidth (width);
         size.setHeight (height);
         if (height < _iconExtent) { size.moveTop ((_iconExtent - height) * 0.5f); }
         if (width < _iconExtent) { size.moveLeft ((_iconExtent - width) * 0.5f); }
         qsr.render (&painter, size);
         painter.end ();
         QIcon icon;
         icon.addPixmap (QPixmap::fromImage (back));
         QStandardItem *item = new QStandardItem (icon, Name.get_buffer ());
         item->setEditable (false);
         _model.appendRow (item);
      }
   }
   else if (IconResource) {

      _log.error << "Unable to find icon resource: " << IconResource
          << " for object type: " << Type.get_name () << endl;
   }

   RuntimeIterator it;
   ObjectType next;

   while (Type.get_next_child (it, next)) { _add_type (next); }
}
Пример #3
0
void
dmz::RenderModuleCoreOgreBasic::_init_root (Config &local) {

   String logName ("ogre.log");
   Boolean suppressLogFileOutput (True);

   Config logData;
   if (local.lookup_config ("log", logData)) {

      suppressLogFileOutput = False;
      logName = config_to_string ("name", logData, logName);
   }

   Ogre::LogManager *logManager = new Ogre::LogManager;

   Ogre::Log *log =
      Ogre::LogManager::getSingleton ().createLog (
         logName.get_buffer (), True, False, suppressLogFileOutput);

   if (suppressLogFileOutput) {

      //Ogre::LogManager::getSingleton ().setLogDetail(Ogre::LL_LOW);
      log->addListener (&_ogreLogger);
   }

   _root = new Ogre::Root("", "");

   ConfigIterator it;
   Config cd;

   Config pluginList;
   if (local.lookup_all_config ("plugins.plugin", pluginList)) {

      Boolean done (!pluginList.get_first_config (it, cd));
      while (!done)  {

         String name;
         if (cd.lookup_attribute ("name", name)) {

            try {

               _root->loadPlugin (name.get_buffer ());
            }
            catch (Ogre::Exception e) {

               String msg (e.getFullDescription ().c_str ());
               _log.error << msg << endl;
            }
         }

         done = !pluginList.get_next_config (it, cd);
      }
   }
}
Пример #4
0
dmz::QtVersion::QtVersion (Config &local, const String &Prefix) :
      QWidget (0, Qt::Dialog),
      _state (*(new State (local, Prefix))) {

   _state.ui.setupUi (this);

   const String Name (_state.version.get_name ());
   const String Major (_state.version.get_major ());
   const String Minor (_state.version.get_minor ());
   const String Bug (_state.version.get_bug ());
   const String Build (_state.version.get_build ());
   const String Release (_state.version.get_release ());
   const String Image (_state.version.get_image_name ());

   if (Image) {

      _state.pix.load (Image.get_buffer ());

      if (!_state.pix.isNull ()) {

         _state.ui.imageLabel->setPixmap (_state.pix);
      }
      else { out << "**** Unable to load about image: " << Image << endl; }
   }

   if (Name) { _state.ui.nameLabel->setText (Name.get_buffer ()); }

   if (Major) {

      String value (Major);
      if (Minor) {

         value << "." << Minor;

         if (Bug) { value << "." << Bug; }
      }

      if (Release) { value << " " << Release; }

      _state.ui.versionLabel->setText (value.get_buffer ());
   }

   if (Build) { _state.ui.buildLabel->setText (Build.get_buffer ()); }

   // hit Ctrl+V to display a aboutQt message box
   QAction *action = new QAction (this);
   action->setShortcut (Qt::CTRL + Qt::Key_V);
   addAction (action);
   connect (action, SIGNAL (triggered ()), qApp, SLOT (aboutQt ()));
}
Пример #5
0
dmz::V8Value
dmz::JsModuleUiV8QtBasic::_form_layout_insert_row (const v8::Arguments &Args) {

   v8::HandleScope scope;
   V8Value result = v8::Undefined ();

   JsModuleUiV8QtBasic *self = _to_self (Args);
   if (self) {

      QFormLayout *form = self->v8_to_qobject<QFormLayout> (Args.This ());
      if (form) {

         QLayout *layout = 0;
         QWidget *widget = 0;

         int row = v8_to_int32 (Args[0]);
         if (Args.Length () == 2) {

            layout = self->v8_to_qobject<QLayout> (Args[1]);
            widget = self->_to_qwidget (Args[1]);

            if (layout) { form->addRow (layout); }
            else if (widget) { form->addRow (widget); }
         }
         else if (Args.Length () == 3) {

            String text = v8_to_string (Args[1]);
            widget = self->_to_qwidget (Args[1]);
            QWidget *field = self->_to_qwidget (Args[2]);
            layout = self->v8_to_qobject<QLayout> (Args[2]);

            if (widget) {

               if (field) { form->insertRow (row, widget, field); }
               else if (layout) { form->insertRow (row, widget, layout); }
            }
            else if (text) {

               if (field) { form->insertRow (row, text.get_buffer (), field); }
               else if (layout) {

                  form->insertRow (row, text.get_buffer (), layout);
               }
            }
         }
      }
   }

   return scope.Close (result);
}
Пример #6
0
/*!

\brief Creates a directory.
\details Defined in dmzSystemFile.h. Function will create a path as deep as is
requested in \a Path. Function returns dmz::True if path already exists.
\param[in] Path String containing directory to create.
\return Returns dmz::True if directory was successfully created.

*/
dmz::Boolean
dmz::create_directory (const String &Path) {

   Boolean result (False);

   if (Path) {

      result = True;
      const String FormattedPath (format_path (Path));
      StringTokenizer st (FormattedPath, '/');
      String dir;
      if (FormattedPath.get_char (0) == '/') { dir << "/"; }
      String part (st.get_next ());

      while (part) {

         if (dir) { dir << "/" << part; }
         else { dir = part; }

         if (!is_valid_path (dir)) {

            if (mkdir (dir.get_buffer (), S_IRUSR | S_IWUSR | S_IXUSR) != 0) {

               result = False;
            }
         }

         if (result) { part = st.get_next (); }
         else { part.flush (); }
      }
   }

   return result;
}
QGraphicsItem *
dmz::QtPluginCanvasObjectBasic::_create_image_item (
      ObjectStruct &os,
      QGraphicsItem *parent,
      const Config &Data,
      HashTableStringTemplate<String> &table) {

   QGraphicsItem *item (0);

   String fileName = config_to_string ("resource", Data);
   String *repName = table.lookup (fileName);

   const String File = _rc.find_file (repName ? *repName : fileName).to_lower ();
   QFileInfo fi (File.get_buffer ());

   if (fi.suffix () == QLatin1String ("svg")) {

      item = _create_svg_item (os, parent, Data, table);
   }
   else {

      item = _create_pixmap_item (os, parent, Data, table);
   }

   return item;
}
void
dmz::QtPluginCanvasObjectBasic::update_object_text (
      const UUID &Identity,
      const Handle ObjectHandle,
      const Handle AttributeHandle,
      const String &Value,
      const String *PreviousValue) {

   ObjectStruct *os (_objectTable.lookup (ObjectHandle));
   if (os) {

      QtCanvasObjectTextTable *textTable (os->textTable.lookup (AttributeHandle));

      if (textTable) {

         HashTableStringIterator it;
         QtCanvasObjectText *item (textTable->get_first (it));

         while (item) {

            item->set_text (Value.get_buffer ());
            item = textTable->get_next (it);
         }
      }
   }
}
Пример #9
0
void
dmz::LuaExtObjectObserver::update_object_text (
      const UUID &Identity,
      const Handle ObjectHandle,
      const Handle AttributeHandle,
      const String &Value,
      const String *PreviousValue) {

   LUA_START_VALIDATE (L);

   const int Handler (obs_setup_cb (L, *this, AttributeHandle, ObjectTextFunc));

   if (Handler) {

      lua_create_handle (L, ObjectHandle);
      lua_create_handle (L, AttributeHandle);
      lua_pushstring (L, Value.get_buffer ());
      if (PreviousValue) { lua_pushstring (L, PreviousValue->get_buffer ()); }
      else { lua_pushnil (L); }

      obs_do_cb (L, *this, 4, Handler, AttributeHandle, ObjectTextMask);
   }

   LUA_END_VALIDATE (L, 0);
}
Пример #10
0
/*!

\brief Gets a list of files found at the specified path.
\details Defined in dmzSystemFile.h.
\param[in] Path String containing path used to find the file list.
\param[out] container dmz::StringContainer used to store files found at the specified
\a Path
\return Returns dmz::True if the specified \a Path is valid.
\sa dmz::get_directory_list

*/
dmz::Boolean
dmz::get_file_list (
      const String &Path,
      StringContainer &container) {

   Boolean result (False);

   container.clear ();

   if (is_valid_path (Path)) {

      DIR *dir = opendir (Path.get_buffer ());

      if (dir) {

         result = True;

         struct dirent *current = readdir (dir);

         while (current) {

            if (current->d_type != DT_DIR) {

               container.add (current->d_name);
            }

            current = readdir (dir);
         }

         closedir (dir); dir = 0;
      }
   }

   return result;
}
dmz::Boolean
dmz::ReaderZip::open_file (const String &FileName) {

   Boolean result (False);

   if (_state.zf) {

      close_file ();

      result = _state.zip_error (unzLocateFile (
         _state.zf,
         FileName.get_buffer (),
         1)); // Case sensitive

      if (result) {

         result = _state.zip_error (unzOpenCurrentFile (_state.zf));

         if (result) { _state.fileName = FileName; }
      }
   }
   else { _state.error.flush () << "Zip archive not open."; }

   return result;
}
Пример #12
0
/*!

\brief Removes an attribute from the Config.
\details
The \a Name parameter may be scoped.
\param[in] Name String containing name of attribute to remove.
\param[out] value String used to return value of attribute if removed.
\return Returns dmz::True if an attribute with \a Name is removed.

*/
dmz::Boolean
dmz::Config::remove_attribute (const String &Name, String &value) {

   Boolean result (False);

   if (_state.context) {

      String dataName;
      String attrName;

      if (!pop_last_config_scope_element (Name, dataName, attrName)) { attrName = Name; }

      Config cd;

      if (dataName) { lookup_config (dataName, cd); }
      else { cd = *this; }

      if (cd) {

         ConfigAttributeContext *ac = cd._state.context->attrTable.lookup (attrName);

         if (ac) {

            ac->lock.lock ();
               value = ac->value;
               ac->value.empty ();
            ac->lock.unlock ();

            if (value.get_buffer ()) { result = True; }
         }
      }
   }

   return result;
}
void
dmz::RenderModuleCoreOSGBasic::_init (Config &local, Config &global) {

   const String UpStr = config_to_string ("osg-up.value", local, "y").to_lower ();
   if (UpStr == "y") { set_osg_y_up (); _log.info << "OSG render Y is up." << endl; }
   else if (UpStr == "z") { set_osg_z_up (); _log.info << "OSG render Z is up" << endl; }
   else {

      _log.warn << "Unknown osg up type: " << UpStr << ". Defaulting to Y up." << endl;
   }

   Config pluginList;

   if (local.lookup_all_config ("plugin-list.plugin", pluginList)) {

      RuntimeContext *context (get_plugin_runtime_context ());

      if (dmz::load_plugins (context, pluginList, local, global, _extensions, &_log)) {

         _extensions.discover_plugins ();
         _extensions.discover_external_plugin (this);
      }
   }

   osgDB::Registry *reg = osgDB::Registry::instance ();
   Config pathList;

   if (reg && local.lookup_all_config ("loader.path", pathList)) {

      osgDB::FilePathList &fpl = reg->getLibraryFilePathList ();

      ConfigIterator it;
      Config path;

      while (pathList.get_next_config (it, path)) {

         String pathStr = config_to_string ("value", path);

         if (get_absolute_path (pathStr, pathStr)) {

            fpl.push_back (pathStr.get_buffer ());
         }
      }

   }

   if(reg) {

      reg->setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES);
   }

   _defaultHandle = activate_default_object_attribute (
      ObjectDestroyMask | ObjectPositionMask | ObjectScaleMask | ObjectOrientationMask);

   _bvrHandle = config_to_named_handle (
      "bounding-volume-radius-attribute.name",
      local,
      ObjectAttributeBoundingVolumeRaidusName,
      get_plugin_runtime_context ());
}
Пример #14
0
/*!

\brief Get next attribute stored in the config context.
\param[in] it ConfigIterator used to iterate over the attributes.
\param[out] name String to store the name of the next attribute.
\param[out] value String to store the value of the next attribute.
\return Returns dmz::True if the next name and value were stored in \a name and
\a value. Returns dmz::False when there are no more name-value pairs to return.

*/
dmz::Boolean
dmz::Config::get_next_attribute (
      ConfigIterator &it,
      String &name,
      String &value) const {

   Boolean result (False);

   if (_state.context) {

      ConfigAttributeContext *ac = _state.context->attrTable.get_next (it.state.it);

      if (ac) {

         ac->lock.lock ();
            value = ac->value;
         ac->lock.unlock ();

         name = it.state.it.get_hash_key ();

         if ((name == "") || (!value.get_buffer ())) {

            result = get_next_attribute (it, name, value);
         }
         else { result = True; }
      }
   }

   return result;
}
Пример #15
0
// AudioModule Interface
dmz::Handle
dmz::AudioModuleFMOD::create_sound (const String &FileName) {

   Handle result (0);
   String absPath;

   if (_system) {

      // Convert to absolute file path
      Boolean validPath = get_absolute_path (FileName, absPath);

      if (validPath) {

         SoundStruct *soundData = _soundNameTable.lookup (absPath);

         if (soundData) {

            result = soundData->get_handle ();
         }
         else {

            FMOD::Sound *newSound (0);

            FMOD_RESULT fmodResult = _system->createSound (
               absPath.get_buffer (),
               FMOD_3D,
               0,
               &newSound);

            String loadingErrorHeader ("Loading Sound '");
            loadingErrorHeader << absPath << "'";

            if (_error_check (loadingErrorHeader, fmodResult)) {

               SoundStruct *newSoundData = new SoundStruct (
                  absPath,
                  newSound,
                  _soundHandleTable,
                  _soundNameTable,
                  get_plugin_runtime_context ());

               if (newSoundData && _soundNameTable.store (absPath, newSoundData)) {

                  Handle newHandle = newSoundData->get_handle ();

                  if (newHandle && _soundHandleTable.store (newHandle, newSoundData)) {

                     _log.info << "Sound file '" << absPath << "' Loaded" << endl;
                     result = newHandle;
                  }
               }
               else if (newSoundData) { newSoundData->unref (); }
            }
         }
      }
   }

   return result;
}
Пример #16
0
void
dmz::LogObserverFile::store_log_message (
      const String &LogName,
      const LogLevelEnum Level,
      const String &Message) {

   if (_state.file && (Level >= 0)) {

      if (Level <= LocalMaxLevels) { _state.out << LocalLevelStr[Level]; }

      if (LogName) { _state.out << LogName.get_buffer () << ":"; }

      if (Message) { _state.out << Message.get_buffer (); }

      _state.out << endl;
   }
}
Пример #17
0
void
dmz::RenderPluginStaticTerrainOSG::_init (Config &local) {

   Config list;

   if (local.lookup_all_config ("model", list)) {

      ConfigIterator it;
      Config model;

      while (list.get_next_config (it, model)) {

         const String ResourceName = config_to_string ("resource", model);

         if (ResourceName) {

            const String FileName = _rc.find_file (ResourceName);
            const Boolean Isect = config_to_boolean ("isect", model, True);

            if (FileName) {

               ModelStruct *ms = new ModelStruct (Isect);

               if (ms) {

                  ms->model = osgDB::readNodeFile (FileName.get_buffer ());

                  if (ms->model.valid ()) { 

                  osg::BoundingSphere bound = ms->model->computeBound ();
                  _log.info << FileName << " center: ["
                     << bound.center ().x () << ", "
                     << bound.center ().y () << ", "
                     << bound.center ().z () << "]" << endl;

                     ms->next = _modelList;
                     _modelList = ms;

                     _log.info << "Loaded model: " << FileName
                       << " (" << ResourceName << ")" << endl;
                  }
                  else {

                     delete ms; ms = 0;
                     _log.error << "Failed loading model: " << FileName
                        << " (" << ResourceName << ")" << endl;
                  }
               }
            }
         }
         else {

            _log.error << "No resource name specified for static terrain." << endl;
         }
      }
   }
}
Пример #18
0
   void init () {

      // size will be different than length if a Header and/or Footer is defined.
      size_t size  = get_file_size (FileName);
      length = size;

      if (Header) { length += Header.get_length (); size = length; }
      if (Footer) { length += Footer.get_length (); }

      if (length > 0) {

         buffer = new char[length + 1];

         if (buffer) {

            buffer[length] = '\0';

            Int32 place (0);

            if (Header) {

               strncpy (buffer, Header.get_buffer (), Header.get_length ());
               place += Header.get_length ();
            }

            FILE *file = open_file (FileName, "rb");

            if (file) {

               while (place < size) {

                  place += read_file (file, length - place, &(buffer[place]));
               }

               close_file (file);
            }

            if (Footer) {

               strncpy (&(buffer[place]), Footer.get_buffer (), Footer.get_length ());
            }
         }
      }
   }
Пример #19
0
void
dmz::ArchivePluginAutoSave::update_plugin_state (
      const PluginStateEnum State,
      const UInt32 Level) {

   if (State == PluginStateStart) {

      if (_firstStart && _saveFile && is_valid_path (_saveFile) && _archiveMod) {

         _log.info << "Restoring from auto save archive: " << _saveFile << endl;

         Config global ("global");
         XMLParser parser;
         XMLInterpreterConfig interpreter (global);
         parser.set_interpreter (&interpreter);

         FILE *file = open_file (_saveFile, "rb");

         if (file) {

            Boolean error (False);
            String buffer;

            while (read_file (file, 1024, buffer) && !error) {

               const Int32 Length = buffer.get_length ();
               const char *cbuf = buffer.get_buffer ();

               if (!parser.parse_buffer (cbuf, Length, Length < 1024)) {

                  error = True;
                  _log.error << "Unable to restore from auto save archive: " << _saveFile
                     << " : " << parser.get_error ();
               }
            }

            close_file (file);

            Config data;

            if (!error && global.lookup_all_config_merged ("dmz", data)) {

               _archiveMod->process_archive (_archiveHandle, data);
            }
         }
      }

      _firstStart = False;
   }
   else if (State == PluginStateShutdown) {

      if (is_valid_path (_saveFile)) { remove_file (_saveFile); }
   }
}
Пример #20
0
dmz::RenderPluginObjectOSG::ModelStruct *
dmz::RenderPluginObjectOSG::_load_model (const String &ResourceName) {

   ModelStruct *result (0);
   String foundFile (_rc.find_file (ResourceName));

   if (foundFile) {

      result = _modelTable.lookup (foundFile);

      if (!result) {

         result = new ModelStruct;
         result->model = osgDB::readNodeFile (foundFile.get_buffer ());

         if (result->model.valid ()) {

            osgUtil::Optimizer optimizer;
            optimizer.optimize(result->model.get());

            osg::Node::DescriptionList &list = result->model->getDescriptions ();

            String str ("<dmz><render><resource name=\"");
            str << ResourceName << "\"/></render></dmz>";
            list.push_back (str.get_buffer ());

            _log.info << "Loaded file: " << foundFile << " (" << ResourceName << ")"
               << endl;
            _modelTable.store (foundFile, result);
         }
         else {

            delete result; result = 0;
            _log.error << "Failed loading file: " << foundFile << " (" << ResourceName
               << ")" << endl;
         }
      }
   }

   return result;
}
Пример #21
0
   State (
         const char *Buffer,
         const size_t Length,
         const String Header,
         const String &Footer) :
         buffer (0),
         length (Length),
         count (1) {

      if (Header) { length += Header.get_length (); }
      if (Footer) { length += Footer.get_length (); }

      if (length > 0) {

         size_t place (0);

         buffer = new char[length + 1];

         if (buffer) {

            buffer[length] = '\0';

            if (Header) {

               strncpy (buffer, Header.get_buffer (), Header.get_length ());
               place += Header.get_length ();
            }

            if (Length) {

               strncpy (&(buffer[place]), Buffer, Length);
               place += Length;
            }

            if (Footer) {

               strncpy (&(buffer[place]), Footer.get_buffer (), Footer.get_length ());
            }
         }
      }
   }
Пример #22
0
/*!

\brief Determines the size of a file.
\details Defined in dmzSystemFile.h.
\param[in] Path String containing path to the file.
\return Returns the size of the file in bytes.

*/
dmz::UInt64
dmz::get_file_size (const String &Path) {

   UInt64 result (0);

   struct stat s;

   if (!stat (Path.get_buffer (), &s)) {

      result = UInt64 (s.st_size > 0 ? s.st_size : 0);
   }

   return result;
}
Пример #23
0
/*!

\brief Determines if a path is a directory.
\details Defined in dmzSystemFile.h. Works with both files and directories.
\param[in] Path String containing path to validate.
\return Returns dmz::True if \a Path is a valid directory.

*/
dmz::Boolean
dmz::is_directory (const String &Path) {

   Boolean result (False);

   struct stat s;

   if (!stat (Path.get_buffer (), &s)) {

      if (S_ISDIR (s.st_mode)) { result = True; }
   }

   return result;
}
Пример #24
0
// Object Observer Interface
void
dmz::QtPluginCanvasLink::link_objects (
      const Handle LinkHandle,
      const Handle AttributeHandle,
      const UUID &SuperIdentity,
      const Handle SuperHandle,
      const UUID &SubIdentity,
      const Handle SubHandle) {

   if (_canvasModule) {

      if (_linkAttrTable.lookup (AttributeHandle)) {

         QGraphicsItem *superItem (_canvasModule->lookup_item (SuperHandle));
         QGraphicsItem *subItem (_canvasModule->lookup_item (SubHandle));

         if (superItem && subItem) {

            LinkStruct *os (new LinkStruct (
               LinkHandle,
               AttributeHandle,
               SuperHandle,
               SubHandle,
               _penWidth,
               _arrowMultiplier));

            if (_linkTable.store (LinkHandle, os)) {

               Float32 minZ (qMin (superItem->zValue (), subItem->zValue ()));

               os->item->setZValue (minZ - 1.0f);

               String name ("Link");
               name << "." << AttributeHandle << "." << LinkHandle;

               os->item->setData (QtCanvasObjectNameIndex, name.get_buffer ());

               _store_edge (SuperHandle, os->item);
               _store_edge (SubHandle, os->item);

               _canvasModule->add_item (LinkHandle, os->item);

               QGraphicsItem *superParent = superItem->parentItem ();
               if (superParent) { os->item->setParentItem (superParent); }
            }
            else { delete os; os = 0; }
         }
      }
   }
}
Пример #25
0
void
dmz::RenderModuleCoreOgreBasic::_init_resources (Config &local) {

   Config resourceList;
   if (local.lookup_all_config ("resources.resource", resourceList)) {

      ConfigIterator it;
      Config cd;

      Boolean done (!resourceList.get_first_config (it, cd));
      while (!done)  {

         String name;
         if (cd.lookup_attribute ("name", name)) {

            String type = config_to_string ("type", cd, "FileSystem");
            String group = config_to_string ("group", cd, "General");
            Boolean recursive = config_to_boolean ("recursive", cd, False);

            try {

               Ogre::ResourceGroupManager::getSingleton ().addResourceLocation (
                  name.get_buffer (),
                  type.get_buffer (),
                  group.get_buffer (),
                  recursive);
            }
            catch (Ogre::Exception e) {

               _log.error << e.getFullDescription ().c_str () << endl;
            }
         }

         done = !resourceList.get_next_config (it, cd);
      }
   }
}
Пример #26
0
/*!

\ingroup Foundation
\brief Converts an XML file to a config context tree.
\details Defined in dmzFoundationXMLUtil.h.
\param[in] FileName String containing name of XML file to parse.
\param[out] data Config object to store parsed XML data.
\param[in] log Pointer to Log for streaming log messages.
\return Returns dmz::True if the XML file was successfully parsed.
\sa dmz::Config \n dmz::ConfigContext

*/
dmz::Boolean
dmz::xml_to_config (const String &FileName, Config &data, Log *log) {

   if (!data) { Config tmp ("global"); data = tmp; }

   ParserXML parser;
   InterpreterXMLConfig interpreter (data);
   parser.set_interpreter (&interpreter);
   Boolean error (False);

   FILE *file = open_file (FileName, "rb");

   if (file) {

      String buffer;

      while (read_file (file, 1024, buffer) && !error) {

         const Int32 Length = buffer.get_length ();
         const char *cbuf = buffer.get_buffer ();

         if (!parser.parse_buffer (cbuf, Length, Length < 1024)) {

            error = True;

            if (log) {

               log->error << "In file: " << FileName << " : " << parser.get_error ()
                  << endl;
            }
         }
      }

      close_file (file);
   }
   else {

      error = True;

      if (log) {

         log->error << "Unable to open file: " << FileName << endl;
      }
   }

   return !error;
}
Пример #27
0
/*!

\brief Gets a list of directories found at the specified path.
\details Defined in dmzSystemFile.h.
\param[in] Path String containing path used to find the directory list.
\param[out] container dmz::StringContainer used to store directories found at the specified
\a Path
\return Returns dmz::True if the specified \a Path is valid.
\sa dmz::get_file_list

*/
dmz::Boolean
dmz::get_directory_list (
      const String &Path,
      StringContainer &container) {

   Boolean result (False);

   container.clear ();

   if (is_valid_path (Path)) {

      DIR *dir = opendir (Path.get_buffer ());

      if (dir) {

         result = True;

         struct dirent *current = readdir (dir);

         while (current) {

            if (current->d_type == DT_DIR) {

               Boolean store (True);

               // Filter out . and .. directories
               if (current->d_name[0] == '.') {

                  if ((current->d_name[1] == '\0') ||
                     ((current->d_name[1] == '.') && (current->d_name[2] == '\0'))) {

                     store = False;
                  }
               }

               if (store) { container.add (current->d_name); }
            }

            current = readdir (dir);
         }

         closedir (dir); dir = 0;
      }
   }

   return result;
}
/*!

\brief Creates zip archive for writing.
\details Will close any open zip archive before opening a new archive. If a zip archive
already exists with the same name, it will be overwritten.
\param[in] FileName String containing the name of the new zip archive.
\param[in] Mode Parameter for future functionality.
\return Returns dmz::True if the archive was successfully created.

*/
dmz::Boolean
dmz::WriterZip::open_zip_file (const String &FileName, const UInt32 Mode) {

   Boolean result (False);

   close_zip_file ();

   _state.zf = zipOpen (FileName.get_buffer (), APPEND_STATUS_CREATE);

   if (_state.zf) {

      _state.zipFileName = FileName;
      result = True;
   }

   return result;
}
Пример #29
0
dmz::V8Value
dmz::JsExtV8Input::_input_key_to_string (const v8::Arguments &Args) {

   v8::HandleScope scope;
   V8Value result = v8::Undefined ();

   const UInt32 Key = v8_to_uint32 (Args[0]);

   if (Key) {

      const String KeyStr = key_value_to_string (Key);

      if (KeyStr) { result = v8::String::New (KeyStr.get_buffer ()); }
   }

   return scope.Close (result);
}
/*!

\brief Opens zip archive for reading.
\param[in] FileName String containing name of zip archive to open.
\param[in] Mode Parameter for future functionality.
\return Returns dmz::True if the zip archive was successfully opened.

*/
dmz::Boolean
dmz::ReaderZip::open_zip_file (const String &FileName, const UInt32 Mode) {

   Boolean result (False);

   close_zip_file ();

   _state.zf = unzOpen (FileName.get_buffer ());

   if (_state.zf) {

      _state.zipFileName = FileName;
      result = True;
   }

   return result;
}