Exemple #1
0
void PixInsightX11Installer::CopyFiles( const String& targetDir, const String& sourceDir )
{
   if ( !targetDir.BeginsWith( '/' ) )
      throw Error( "CopyFiles(): Relative target directory." );
   if ( !sourceDir.BeginsWith( '/' ) )
      throw Error( "CopyFiles(): Relative source directory." );
   if ( targetDir.EndsWith( '/' ) || sourceDir.EndsWith( '/' ) )
      throw Error( "CopyFiles(): Incorrectly terminated directories." );
   if ( !File::DirectoryExists( targetDir ) )
      throw Error( "CopyFiles(): Nonexistent target directory." );
   if ( !File::DirectoryExists( sourceDir ) )
      throw Error( "CopyFiles(): Nonexistent source directory." );

   StringList sourceItems = SearchDirectory( sourceDir );

   size_type sourceDirLen = sourceDir.Length();
   for ( StringList::const_iterator i = sourceItems.Begin(); i != sourceItems.End(); ++i )
   {
      String relSourcePath = *i;
      relSourcePath.DeleteLeft( sourceDirLen );

      String targetPath = targetDir + relSourcePath;
      if ( targetPath.EndsWith( '/' ) )
      {
         /*
          * Create a subdirectory
          */
         targetPath.Delete( targetPath.UpperBound() );
         if ( !File::DirectoryExists( targetPath ) )
         {
            File::CreateDirectory( targetPath );
            String sourcePath = *i;
            sourcePath.Delete( sourcePath.UpperBound() );
            File::CopyTimesAndPermissions( targetPath, sourcePath );
         }
      }
      else
      {
         /*
          * Copy a file
          */
         /*
          * ### N.B. We don't have to create subdirectories here becase they
          * have been reported by SearchDirectory(), and we are creating them
          * before copying files. SearchDirectory() promises that all
          * subdirectories are reported before their contained files.
          */
         /*
         String targetSubdir = File::ExtractDirectory( targetPath );
         if ( targetSubdir.EndsWith( '/' ) )
            targetSubdir.Delete( targetSubdir.UpperBound() );
         if ( !File::DirectoryExists( targetSubdir ) )
            File::CreateDirectory( targetSubdir );
         */
         File::CopyFile( targetPath, *i );
      }
   }
}
Exemple #2
0
void PixInsightX11Installer::RemoveDirectory_Recursive( const String& dirPath, const String& baseDir )
{
   if ( dirPath.Has( ".." ) )
      throw Error( "RemoveDirectory(): Attempt to climb up the filesystem." );
   if ( !dirPath.BeginsWith( baseDir ) )
      throw Error( "RemoveDirectory(): Attempt to redirect outside the base directory." );
   if ( !File::DirectoryExists( dirPath ) )
      throw Error( "RemoveDirectory(): Attempt to remove a nonexistent directory." );

   String currentDir = dirPath;
   if ( !currentDir.EndsWith( '/' ) )
      currentDir += '/';

   FindFileInfo info;
   for ( File::Find f( currentDir + "*" ); f.NextItem( info ); )
   {
      String itemPath = currentDir + info.name;
      if ( info.IsDirectory() )
      {
         if ( info.name != "." && info.name != ".." )
         {
            RemoveDirectory_Recursive( itemPath, baseDir );
            File::RemoveDirectory( itemPath );
         }
      }
      else
      {
         File::Remove( itemPath );
      }
   }
}
Exemple #3
0
void PixInsightX11Installer::DirectorySearch_Recursive( StringList& foundItems, const String& dirPath, const String& baseDir )
{
   if ( dirPath.Has( ".." ) )
      throw Error( "SearchDirectory(): Attempt to redirect outside the base directory." );
   if ( !dirPath.BeginsWith( baseDir ) )
      throw Error( "SearchDirectory(): Attempt to redirect outside the base directory." );
   if ( !File::DirectoryExists( dirPath ) )
      throw Error( "SearchDirectory(): Attempt to search a nonexistent directory." );

   String currentDir = dirPath;
   if ( !currentDir.EndsWith( '/' ) )
      currentDir += '/';

   StringList directories;
   FindFileInfo info;
   for ( File::Find f( currentDir + "*" ); f.NextItem( info ); )
      if ( info.IsDirectory() )
      {
         if ( info.name != "." && info.name != ".." )
         {
            directories.Add( info.name );
            foundItems.Add( currentDir + info.name + '/' );
         }
      }
      else
         foundItems.Add( currentDir + info.name );

   for ( StringList::const_iterator i = directories.Begin(); i != directories.End(); ++i )
      DirectorySearch_Recursive( foundItems, currentDir + *i, baseDir );
}
Exemple #4
0
//-----------------------------------------------------------------------------------------------------------------------------------------------------
VOID Configuration::LoadConfigFile(LPCTSTR Filename)
{
  TextStream T(File::Open(Filename, FileMode::OPEN));

  while(!T.EndOfStream())
  {
    String L = T.ReadLine();
    if (L.BeginsWith("#"))
      continue;

    String::Iterator i = L.Find('=');
    if (i != L.End())
    {
      String Name = L.Substr(L.Begin(), i);
      String Value = L.Substr(i+1, L.End());

      if (m_Schema.Contains(Name))
      {
        Item I = m_Schema.Get(Name);
        if ((I.m_Source & ConfigurationSource::FILE) == 0)
          continue;
        I.m_Present = TRUE;
      }

      m_ConfigValues.Add(Name,Value);
    }
  }
}
Exemple #5
0
String PixInsightX11Installer::Unquoted( const String& s )
{
   String r = s;
   if ( s.BeginsWith( '\"' ) )
      if ( s.EndsWith( '\"' ) )
      {
         r.DeleteRight( r.UpperBound() );
         r.DeleteLeft( 1 );
      }
   if ( s.BeginsWith( '\'' ) )
      if ( s.EndsWith( '\'' ) )
      {
         r.DeleteRight( r.UpperBound() );
         r.DeleteLeft( 1 );
      }
   return r;
}
Exemple #6
0
StringList PixInsightX11Installer::SearchDirectory( const String& dirPath )
{
   if ( !dirPath.BeginsWith( '/' ) )
      throw Error( "SearchDirectory(): Relative search directory." );
   if ( dirPath.EndsWith( '/' ) )
      throw Error( "SearchDirectory(): Incorrectly terminated directory." );

   StringList foundItems;
   DirectorySearch_Recursive( foundItems, dirPath, dirPath );
   return foundItems;
}
Exemple #7
0
void PixInsightX11Installer::RemoveDirectory( const String& dirPath )
{
   if ( !dirPath.BeginsWith( '/' ) )
      throw Error( "RemoveDirectory(): Relative directory." );
   if ( !File::DirectoryExists( dirPath ) )
      throw Error( "RemoveDirectory(): Nonexistent directory." );

   // Remove all files and subdirectories recursively
   RemoveDirectory_Recursive( dirPath, dirPath );

   File::RemoveDirectory( dirPath );
}
void PropertyWindow::SetProperty()
{
	if(property->GetOption().second!=-1 && textField->GetText().length() > 0)
	{
		String value = textField->GetText();
		try {
			switch(properties[property->GetOption().second].Type)
			{
				case StructProperty::Integer:
				case StructProperty::ParticleType:
				{
					int v;
					if(value.length() > 2 && value.BeginsWith("0x"))
					{
						//0xC0FFEE
						v = value.Substr(2).ToNumber<unsigned int>(Format::Hex());
					}
					else if(value.length() > 1 && value.BeginsWith("#"))
					{
						//#C0FFEE
						v = value.Substr(1).ToNumber<unsigned int>(Format::Hex());
					}
					else
					{
						int type;
						if ((type = sim->GetParticleType(value.ToUtf8())) != -1)
						{
							v = type;

#ifdef DEBUG
							std::cout << "Got type from particle name" << std::endl;
#endif
						}
						else
						{
							v = value.ToNumber<int>();
						}
					}

					if (properties[property->GetOption().second].Name == "type" && (v < 0 || v >= PT_NUM || !sim->elements[v].Enabled))
					{
						new ErrorMessage("Could not set property", "Invalid particle type");
						return;
					}

#ifdef DEBUG
					std::cout << "Got int value " << v << std::endl;
#endif

					tool->propValue.Integer = v;
					break;
				}
				case StructProperty::UInteger:
				{
					unsigned int v;
					if(value.length() > 2 && value.BeginsWith("0x"))
					{
						//0xC0FFEE
						v = value.Substr(2).ToNumber<unsigned int>(Format::Hex());
					}
					else if(value.length() > 1 && value.BeginsWith("#"))
					{
						//#C0FFEE
						v = value.Substr(1).ToNumber<unsigned int>(Format::Hex());
					}
					else
					{
						v = value.ToNumber<unsigned int>();
					}
#ifdef DEBUG
					std::cout << "Got uint value " << v << std::endl;
#endif
					tool->propValue.UInteger = v;
					break;
				}
				case StructProperty::Float:
				{
					if (value.EndsWith("C"))
					{
						float v = value.SubstrFromEnd(1).ToNumber<float>();
						tool->propValue.Float = v + 273.15;
					}
					else if(value.EndsWith("F"))
					{
						float v = value.SubstrFromEnd(1).ToNumber<float>();
						tool->propValue.Float = (v-32.0f)*5/9+273.15f;
					}
					else
					{
						tool->propValue.Float = value.ToNumber<float>();
					}
#ifdef DEBUG
					std::cout << "Got float value " << tool->propValue.Float << std::endl;
#endif
				}
					break;
				default:
					new ErrorMessage("Could not set property", "Invalid property");
					return;
			}
			tool->propOffset = properties[property->GetOption().second].Offset;
			tool->propType = properties[property->GetOption().second].Type;
		} catch (const std::exception& ex) {
			new ErrorMessage("Could not set property", "Invalid value provided");
			return;
		}
		Client::Ref().SetPref("Prop.Type", property->GetOption().second);
		Client::Ref().SetPrefUnicode("Prop.Value", textField->GetText());
	}
}