Ejemplo n.º 1
0
        String AbstractFileManager::makeRelative(const String& absolutePath, const String& referencePath) {
            if (!::wxIsAbsolutePath(absolutePath))
                return absolutePath;
            if (!::wxIsAbsolutePath(referencePath))
                return "";
            
            StringList absolutePathComponents = resolvePath(pathComponents(absolutePath));
            StringList referencePathComponents = resolvePath(pathComponents(referencePath));
            StringList relativePathComponents;

            if (!isDirectory(referencePath))
                referencePathComponents.pop_back();
            
            unsigned int i = 0;
            for (; i < (std::min)(absolutePathComponents.size(), referencePathComponents.size()); i++) {
                const String& absolutePathComponent = absolutePathComponents[i];
                const String& referencePathComponent = referencePathComponents[i];
                if (absolutePathComponent != referencePathComponent)
                    break;
            }
            
            for (unsigned int j = i; j < referencePathComponents.size(); j++)
                relativePathComponents.push_back("..");
            
            for (unsigned int j = i; j < absolutePathComponents.size(); j++)
                relativePathComponents.push_back(absolutePathComponents[j]);
            
            return joinComponents(relativePathComponents);
        }
Ejemplo n.º 2
0
 String AbstractFileManager::resolvePath(const String& path) {
     StringList components = resolvePath(pathComponents(path));
     String cleanPath = joinComponents(components);
     if (path[0] == '/')
         cleanPath = "/" + cleanPath;
     return cleanPath;
 }
Ejemplo n.º 3
0
void App::runNormal()
{
   bool componentsStarted = false;
   RunMode runMode;

   // init data objects
   initDataObjects(argc, argv);

   // check if mgmt host is defined if mode is not "help"
   runMode = this->cfg->determineRunMode();
   if ( (runMode != RunMode_INVALID) && !cfg->getSysMgmtdHost().length() )
      throw InvalidConfigException("Management host undefined");

   // tests
   if ( cfg->getDebugRunStartupTests() )
   {
      if ( !StartupTests::perform() )
      {
         this->log->log(1, "Startup Tests failed => shutting down...");
         appResult = APPCODE_RUNTIME_ERROR;
         return;
      }
   }

   // init components

   try
   {
      initComponents();

      // tests
      if(cfg->getDebugRunComponentTests() )
      {
         if(!ComponentTests::perform() )
         {
            this->log->log(1, "Component Tests failed => shutting down...");
            appResult = APPCODE_RUNTIME_ERROR;
            return;
         }
      }
   }
   catch(ComponentInitException& e)
   {
      log->logErr(e.what() );
      log->log(1, "A hard error occurred. Shutting down...");
      appResult = APPCODE_INITIALIZATION_ERROR;
      return;
   }


   // log system and configuration info

   logInfos();


   // detach process

   try
   {
      if(this->cfg->getRunDaemonized() )
         daemonize();
   }
   catch(InvalidConfigException& e)
   {
      log->logErr(e.what() );
      log->log(1, "A hard error occurred. Shutting down...");
      appResult = APPCODE_INVALID_CONFIG;
      return;
   }


   // start component threads

   if(this->cfg->getDebugRunComponentThreads() )
   {
      startComponents();

      componentsStarted = true;

      // tests
      if(cfg->getDebugRunIntegrationTests() )
      {
         if(!IntegrationTests::perform() )
         {
            this->log->log(1, "Integration Tests failed => shutting down...");
            appResult = APPCODE_RUNTIME_ERROR;

            stopComponents();
            goto err_joinAndExit;
         }
      }

      appResult = executeMode(runMode);

      // self-termination
      stopComponents();
   }


err_joinAndExit:
   if(componentsStarted)
   {
      joinComponents();
      log->log(3, "All components stopped. Exiting now!");
   }
}