
// ========================= START =========================
// ----------------------------------
// Strings "resourced" for translation.
// ----------------------------------
var topWindowTitle = updateObjectName+" SmartUpdate" ;
var defaultText = "Initializing SmartUpdate..." ;  // this is the first message that gets put in the status window.
var Msg1         = "SmartUpdate Successfully Completed" ;
var Msg2         = "The value of navigator.platform is: " ;
var Msg3         = "Filename in newSub is: " ;
var Msg4         = "SmartUpdate Aborted:  " ;
var Msg5         = "Starting script..." ;
var ErrorMsg1    = "Error: Wrong operating system: " ;
var ErrorMsg2    = "Error Adding SubComponent: " ;
var ErrorMsg3    = "Error passing su to setupFiles: " ;
var ErrorMsg4    = "Error at startInstall: " ;
var ErrorMsg5    = "Error getting folder: " ;
var ErrorMsg6    = "Error adding at least one subcomponent." ;
var ErrorMsg7    = "Error at FinalizeInstall: " ;
var ErrorMsg8    = "Error at setupFiles: " ;
var ErrorMsg9    = "Error at checkSystemEnvironment: " ;
var ErrorMsg10   = "Error: This SmartUpdate requires Communicator Beta 6 or later. " ;
var SuccessMsg1  = "new SoftwareUpdate succeeded." ;
var SuccessMsg2  = "checkSystemEnvirnoment succeeded." ;
var SuccessMsg3  = "setupFiles succeeded." ;
var WarningMsg1  = "Warning: No registry info product node" ;
var WarningMsg2  = "Warning: Version is no newer than previously installed version." ;
var WarningMsg3  = "Warning: Unable to create the VersionInfo object." ;
var WarningMsg4  = "Warning: Unable to create the SoftwareUpdate object." ;
var WarningMsg5  = "Warning: Communicator does not have a version number" ;
var WarningMsg6  = "Warning: SmartUpdate could not detect version of Communicator. Be sure you are running Communicator Beta 6 or later." ;

// ----------------------------
// GLOBAL VARIABLE DECLARATIONS
// ----------------------------
var abortCalled   = false ;
var newSubFailure = false ;
var debugOutput   = false ;  // Turns debugging output on/off
var silentValue = this.silent ;

//-------------------------------------------------
// Here is where the main body of execution begins.
//-------------------------------------------------

if (checkJava() && checkASD()) {
   java.lang.System.out.println(Msg5) ;
   
   var vi = new netscape.softupdate.VersionInfo(versionMaj, versionMin, versionRel, versionBld) ;
       dbgIfMsg( (vi == null), WarningMsg3) ;
   var su = new netscape.softupdate.SoftwareUpdate( this, updateObjectName ) ;
       dbgIfMsg( (su == null), WarningMsg4) ;

   var err = 0 ;
   if ( (su != null) ) {
      dbgMsg(SuccessMsg1) ;

      err = checkSystemEnvironment() ;
      if ( err == 0 ) {
         dbgMsg(SuccessMsg2) ;

         err = setupFiles(su) ;
         if (err == 0) {
            dbgMsg(SuccessMsg3) ;

            err = su.FinalizeInstall();   // This actually copies all the files.
            if (err == 0) {               // Install succeeded
               dbgMsg(Msg1) ;

               if(showPostReadme)
                  showReadme(postReadmeFile, "url" ) ;
               }
            else {                        // Install failed
               dbgMsg(ErrorMsg7 + err) ;
               abortMe(err) ;
            } //FinalizeInstall
         }
         else {
            dbgMsg(ErrorMsg8 + err) ;
            abortMe(err) ;
         } //setupFiles
      } 
      else {
         dbgMsg(ErrorMsg9 + err) ;
         abortMe(err) ;
      } //checkSystemEnvironment
   }
}
