global env

set revn 140
set config 1
set unconfig 0
set runFromWithInInstaller 0
set nohelp 0

set i 0
foreach arg $argv {
   switch -glob -- $arg {
      -install        { set runFromWithInInstaller 1 }
      -nohelp         { set nohelp 1 }
      -noconfig       { set config 0; set unconfig 0 }
      -unconfig       { set unconfig 1; set config 0 }
      -installdir     { set installDir       [lindex $argv [expr $i + 1]] }
      -rev            { set revn             [lindex $argv [expr $i + 1]] }
      -scripttosource { set scripttosource   [lindex $argv [expr $i + 1]] }
   }
   incr i
}

catch {source $scripttosource}

if { $config == 1 || $unconfig == 1 } {
   puts "Configuring Help ..."
   set cmdPath ""
   if { [ string compare -nocase "$env(ANSYS_SYSDIR)" "intel" ] == 0 || [ string compare -nocase "$env(ANSYS_SYSDIR)" "winx64" ] == 0 } {
      set config_dir "$installDir\\v$revn\\commonfiles\\configs"
      if { [ string compare -nocase "$env(ANSYS_SYSDIR)" "intel" ] == 0 } {
         set config_dir "$config_dir\\win32"
      } else {
         set config_dir "$config_dir\\$env(ANSYS_SYSDIR)"
      }

      if { $config == 1 } {
         set config_dir "$config_dir\\config"
         set cmdPath "$config_dir\\AnsConfigHelp.exe"
      } else {
         #$unconfig
         set config_dir "$config_dir\\unconfig"
         set cmdPath "$config_dir\\AnsUnconfigHelp.exe"
      }

      puts "\nRunning $cmdPath"
      exec $cmdPath
   }

   #---------------------------------------------
   set cmdPath ""
   if { $runFromWithInInstaller == 1 && $config == 1 && $nohelp == 0 } {
      if { [ string compare -nocase "$env(ANSYS_SYSDIR)" "linx64" ] == 0 } {
         set cmdPath "\"$installDir/v$revn/Tools/mono/Linux64/bin/mono\" \"$installDir/v$revn/commonfiles/help/HelpViewer/Indexer/ANSYSHelpIndexer.exe\" -removePreviousIndex -operation MERGE_FORMAT -inputDir \"$installDir/v$revn/commonfiles/help/en-us\" -outputDir \"$installDir/v$revn/commonfiles/help/en-us/LuceneIndex\" -format \"LuceneIndex_*\""
         #set cmdPath "\"$installDir\\v$revn\\commonfiles\\help\\HelpViewer\\Indexer\\HelpViewer.Indexer.exe\" -operation MERGE_FORMAT -inputDir \"$installDir\\v$revn\\commonfiles\\help\\en-us\" -outputDir \"$installDir\\v$revn\\commonfiles\\help\\en-us\\LuceneIndex\" -format \"$installDir\\v$revn\\LuceneIndex_*\""
      } else {
         set cmdPath "\"$installDir\\v$revn\\commonfiles\\help\\HelpViewer\\Indexer\\ANSYSHelpIndexer.exe\" -removePreviousIndex -operation MERGE_FORMAT -inputDir \"$installDir\\v$revn\\commonfiles\\help\\en-us\" -outputDir \"$installDir\\v$revn\\commonfiles\\help\\en-us\\LuceneIndex\" -format \"LuceneIndex_*\""
      }

      puts "\nRunning $cmdPath"
      ReplaceAllOccurences cmdPath "\\" "\\\\"
      #catch { exec $cmdPath }
      ConfigIOLoop $cmdPath 1 $installDir

      #---------------------------------------------
      if { [ string compare -nocase "$env(ANSYS_SYSDIR)" "linx64" ] == 0 } {
         set cmdPath "\"$installDir/v$revn/Tools/mono/Linux64/bin/mono\" \"$installDir/v$revn/commonfiles/help/HelpViewer/Indexer/ANSYSHelpIndexer.exe\" -removePreviousIndex -operation AUTO -inputDir \"$installDir/v$revn/commonfiles/help/en-us/LuceneIndex\" -outputDir \"$installDir/v$revn/commonfiles/help/en-us/AutoCompleteIndex\""
      } else {
         set cmdPath "\"$installDir\\v$revn\\commonfiles\\help\\HelpViewer\\Indexer\\ANSYSHelpIndexer.exe\" -removePreviousIndex -operation AUTO -inputDir \"$installDir\\v$revn\\commonfiles\\help\\en-us\\LuceneIndex\" -outputDir \"$installDir\\v$revn\\commonfiles\\help\\en-us\\AutoCompleteIndex\""
      }

      puts "\nRunning $cmdPath"
      ReplaceAllOccurences cmdPath "\\" "\\\\"
      #catch { exec $cmdPath }
      ConfigIOLoop $cmdPath 1 $installDir

      #---------------------------------------------
      if { [ string compare -nocase "$env(ANSYS_SYSDIR)" "linx64" ] == 0 } {
         set cmdPath "\"$installDir/v$revn/Tools/mono/Linux64/bin/mono\" \"$installDir/v$revn/commonfiles/help/HelpViewer/Indexer/ANSYSHelpIndexer.exe\" -removePreviousIndex -operation SPELL -inputDir \"$installDir/v$revn/commonfiles/help/en-us/LuceneIndex\" -outputDir \"$installDir/v$revn/commonfiles/help/en-us/SpellCheckerIndex\""
      } else {
         set cmdPath "\"$installDir\\v$revn\\commonfiles\\help\\HelpViewer\\Indexer\\ANSYSHelpIndexer.exe\" -removePreviousIndex -operation SPELL -inputDir \"$installDir\\v$revn\\commonfiles\\help\\en-us\\LuceneIndex\" -outputDir \"$installDir\\v$revn\\commonfiles\\help\\en-us\\SpellCheckerIndex\""
      }

      puts "\nRunning $cmdPath"
      ReplaceAllOccurences cmdPath "\\" "\\\\"
      #catch { exec $cmdPath }
      ConfigIOLoop $cmdPath 1 $installDir
   }
}
