Beispiel #1
0
bool FilterLibrary::IsWritable() const
{
   /*
    * If wheter this is a new library, or the current library file does not
    * exist, or it is a read-only file, then this library is not writable.
    */
   if ( filePath.IsEmpty() )
      return false;
   if ( !File::Exists( filePath ) )
      return false;
   if ( File::IsReadOnly( filePath ) )
      return false;

   /*
    * Do not allow rewriting the default filter collection.
    */
#ifdef __PCL_WINDOWS
   // Windows filesystem is case-insensitive
   if ( filePath.CompareIC( DefaultLibraryPath() ) == 0 )
#else
   if ( filePath == DefaultLibraryPath() )
#endif
      return false;

   /*
    * Attempt to create a file on the same directory where we have the current
    * filter collection file. If we can create a file, then the current filter
    * library is (should be) writable.
    */
   try
   {
      String dirPath = File::ExtractDrive( filePath ) + File::ExtractDirectory( filePath );
      if ( !File::DirectoryExists( dirPath ) ) // ?? cannot happen
         return false;

      if ( !dirPath.EndsWith( '/' ) )
         dirPath += '/';
      String testFileName = dirPath + "test_file";
      if ( File::Exists( testFileName ) )
      {
         String baseName = testFileName;
         unsigned i = 0;
         do
            testFileName = baseName + String( ++i );
         while ( File::Exists( testFileName ) );
      }
      File f;
      f.CreateForWriting( testFileName );
      f.Close();
      File::Remove( testFileName );
      return true;
   }
   catch ( ... )
   {
      return false;
   }
}
Beispiel #2
0
void FilterLibrary::SaveAs( const String& _filePath )
{
   File f;
   f.CreateForWriting( _filePath );
   if ( !filters.IsEmpty() )
      for ( filter_list::const_iterator i = filters.Begin(); ; )
      {
         f.OutText( i->ToSource() );
         if ( ++i == filters.End() )
            break;
         f.OutTextLn( IsoString() );
      }
   f.Close();

   filePath = _filePath;
}
Beispiel #3
0
bool PixInsightX11Installer::DoInstall()
{
   ShowLogo();
   RootRequired();

   if ( !File::DirectoryExists( m_sourceDir ) )
      throw Error( "The source installation directory does not exist: " + m_sourceDir );
   if ( !File::DirectoryExists( m_installDesktopDir ) )
      throw Error( "The desktop entry installation directory does not exist: " + m_installDesktopDir );
   if ( !File::DirectoryExists( m_installIconsDir ) )
      throw Error( "The application icons installation directory does not exist: " + m_installIconsDir );

   if ( !File::Exists( m_sourceIcon16x16File ) ||
        !File::Exists( m_sourceIcon24x24File ) ||
        !File::Exists( m_sourceIcon32x32File ) ||
        !File::Exists( m_sourceIcon48x48File ) ||
        !File::Exists( m_sourceIcon64x64File ) ||
        !File::Exists( m_sourceIcon128x128File ) ||
        !File::Exists( m_sourceIcon256x256File ) )
   {
      throw Error( "One or more application icons are missing in the source installation directory. "
                   "Unpack a valid installation archive and try again." );
   }

   std::cout <<
   "\nPixInsight will be installed with the following parameters:"
   "\n"
   "\nSource installation directory ... " << m_sourceDir <<
   "\nPixInsight Core application ..... " << m_installDir <<
   "\nApplication desktop entry ....... " << m_desktopEntryFile <<
   "\nApplication icons directory ..... " << m_installIconsDir <<
   "\nCreate /bin launcher script ..... " << (m_createBinLauncher ? "yes" : "no") <<
   "\nRemove previous installation .... " << (m_removePrevious ? "yes" : "no") <<
   "\n";

   if ( !AskForConfirmation() )
      return false;

   std::cout << "\nPlease wait while PixInsight is being installed...\n" << std::flush;

   // Backup an existing previous installation
   String oldDir = RenameOldInstallationDirectory( m_installDir );

   // Copy the PixInsight Core application
   File::CreateDirectory( m_installDir );
   CopyFiles( m_installDir, m_sourceDir );

   // Application launcher script on /bin
   if ( m_createBinLauncher )
   {
      File f;
      f.CreateForWriting( m_binLauncherFile );
#ifdef __PCL_FREEBSD
      f.OutTextLn( "#!/usr/local/bin/bash" );
#else
      f.OutTextLn( "#!/bin/bash" );
#endif
      f.OutTextLn( m_installDir.ToUTF8() + "/bin/PixInsight.sh $*" );
      f.Close();

      // Make it executable
      IsoString binLauncherFile8 = m_binLauncherFile.ToUTF8();
      if ( chmod( binLauncherFile8.c_str(), S_IRUSR|S_IWUSR|S_IXUSR |
                                            S_IRGRP        |S_IXGRP |
                                            S_IROTH        |S_IXOTH ) != 0 )  // rwxr-xr-x
      throw Error( "Failed to chmod the /bin launcher script: " + m_binLauncherFile );
   }

   // Write the desktop entry file
   {
      File f;
      f.CreateForWriting( m_desktopEntryFile );
      f.OutTextLn( "[Desktop Entry]" );
      f.OutTextLn( "Encoding=UTF-8" );
      f.OutTextLn( "Name=PixInsight" );
      f.OutTextLn( "GenericName=Image Processing Software" );
      f.OutTextLn( "Comment=Advanced image processing platform" );
      f.OutTextLn( "Exec=" + m_installDir.ToUTF8() + "/bin/PixInsight.sh %F" );
      f.OutTextLn( "Terminal=false" );
      f.OutTextLn( "MultipleArgs=true" );
      f.OutTextLn( "Type=Application" );
      f.OutTextLn( "Icon=" + m_installDir.ToUTF8() + "/bin/pixinsight-icon.256.png" );
      f.OutTextLn( "Categories=Application;Graphics;ImageProcessing;RasterGraphics;Photography;Astronomy;" );
      f.OutTextLn( "MimeType=image/fits;application/fits;"
                            "image/tiff;application/tiff;image/tif;application/tif;"
                            "image/png;application/png;application/x-png;"
                            "image/jpeg;application/jpeg;image/jpg;application/jpg;" );
      f.Close();
   }

   // Copy application icons
   if ( File::DirectoryExists( m_installIconsDir + "/16x16/apps" ) )
      CopyFile( m_installIconsDir + "/16x16/apps/PixInsight.png", m_sourceIcon16x16File );
   if ( File::DirectoryExists( m_installIconsDir + "/24x24/apps" ) )
      CopyFile( m_installIconsDir + "/24x24/apps/PixInsight.png", m_sourceIcon24x24File );
   if ( File::DirectoryExists( m_installIconsDir + "/32x32/apps" ) )
      CopyFile( m_installIconsDir + "/32x32/apps/PixInsight.png", m_sourceIcon32x32File );
   if ( File::DirectoryExists( m_installIconsDir + "/48x48/apps" ) )
      CopyFile( m_installIconsDir + "/48x48/apps/PixInsight.png", m_sourceIcon48x48File );
   if ( File::DirectoryExists( m_installIconsDir + "/64x64/apps" ) )
      CopyFile( m_installIconsDir + "/64x64/apps/PixInsight.png", m_sourceIcon64x64File );
   if ( File::DirectoryExists( m_installIconsDir + "/128x128/apps" ) )
      CopyFile( m_installIconsDir + "/128x128/apps/PixInsight.png", m_sourceIcon128x128File );
   if ( File::DirectoryExists( m_installIconsDir + "/256x256/apps" ) )
      CopyFile( m_installIconsDir + "/256x256/apps/PixInsight.png", m_sourceIcon256x256File );

   // If requested, remove a previous installation.
   if ( !oldDir.IsEmpty() )
      if ( m_removePrevious )
      {
         RemoveDirectory( oldDir );
         std::cout << "\n* Previous PixInsight installation removed.\n";
      }
      else
      {
         std::cout <<
         "\n* A previous PixInsight installation has been left on the following directory:"
         "\n" << oldDir << "\n";
      }

   // Set the setuid and setgid bits of the main updater program. The updater
   // requires elevated privileges.
   String updaterFilePath = m_installDir + "/bin/PixInsightUpdater";
   IsoString updaterFilePath8 = updaterFilePath.ToUTF8();
   if ( chmod( updaterFilePath8.c_str(), S_IRUSR|S_IWUSR|S_IXUSR |
                                         S_IRGRP        |S_IXGRP |
                                         S_IROTH        |S_IXOTH |
                                         S_ISUID|S_ISGID ) != 0 )  // rwsr-xr-x
      throw Error( "Failed to set the setuid/setgid bits of the updater program: " + updaterFilePath );

   std::cout << "\n* PixInsight installation completed.\n\n";
   return true;
}