#version Smart_Script 1.21
#timeout 1800
#linewait 0
#error_continue

// dialexec.ssc (MCHK Version) for Smart Script
// Copyright 1999,2000,2001 Sony Corp.
// VASVersion=1.3.01.11010
function  main( $argc , @argv )
{
    // Define error messages ( Modify it if you think that it is necessary.
    // It doesn't influence a movement even if the inside of "" is changed.)
    :$errInvalidArg = "Invalid argument.";
    // Define section end

    // Notice:To execute this script, you must set the working folder to PPK Setup.
    // log file name
    $LogFileName = "SeSetup.LOG";
    if ( $argc == 4 || $argc == 5 ) {
        // open log file
        $_result = IsFileExisting( $LogFileName );
        if ( $_result ) {
            &LogFile = OpenFile( $LogFileName , "a" );
        }
        // First argument is the name of connected place.
        // If dialup connection is unnecessary, set first argument to "".
        $dialup = @argv[ 0 ];
        // Second argument is the script file name to be executed.
        $script = @argv[ 1 ];
        // Third argument is the script file name that is executed after disconnecting.
        $afterprocessing = @argv[ 2 ];
        //Fourth argument is the mail check mode.
        $check = @argv[ 3 ];
        if ( $argc == 5 ) {
            $reg = @argv[ 4 ];
            if ( $reg eq "reg" ) {
                $limit = LoadRegistry( "HKEY_CURRENT_USER\\Software\\Sony Corporation\\VAIO Action Setup\\TimerApp\\" , "LimitTime" );
            } else {
                $limit = 15;
            }
        } else {
            $limit = 15;
        }
        if ( $dialup ne "" ) {
            :$title = $dialup & ":" & $script;
            WriteLog( &LogFile , "dialup connection to " & $dialup & " start." );
            // Connect dialup
            @dialargv[ 0 ] = $dialup;
            $_result = ExecuteScript( "lib\\connect.ssc" , 1 , @dialargv );
            if ( ! $_result ) {
                WriteLog( &LogFile , "Connection to " & $dialup & " succeeded." );
            } else {
                WriteLog( &LogFile , "Connection to " & $dialup & "failed." );
                $_result = CloseFile( &LogFile );
                exit 1;
            }
        } else {
            :$title = "NoDialup:" & $script;
        }
        // Call script file
        @scriptarg[ 0 ] = $check;
        @scriptarg[ 1 ] = $limit;
        $result = ExecuteScript( $script , 2 , @scriptarg );
        if ( $result != 1 ) {
            WriteLog( &LogFile , $script & " finished successfully." );
        } else {
            WriteLog( &LogFile , $script & " failed." );
        }
        // Disconnect dialup
        $var = DisconnectDialUp(  );
        WriteLog( &LogFile , $dialup & " disconnected." );
        $_result = CloseFile( &LogFile );
        //Information LED
        if ( $result == -1 || $check == 4 && $result != 1 ) {
            $_result = ExecuteFile( "bin\\SeILED.exe /ON" );
        } else {
            if ( $check == 4 && $result == 1 ) {
                $_result = ExecuteFile( "bin\\SeILED.exe /OFF" );
            }
        }
        if ( $afterprocessing ne "" ) {
            //
            $_result = WaitTime( 10 );
            $_result = ExecuteFile( $afterprocessing );
        }
    } else {
        $_result = TimerMessage( $errInvalidArg, 3 );
        exit 1;
    }
}
function  WriteLog( &LogFile , $action )
{
    $_result = IsFileValid( &LogFile );
    if ( $_result ) {
        @time = GetLocalTime( );
        $LogString = ToDateString( @time ) & " " & ToTimeString( @time );
        $LogString &= " [" & :$title & "] " & $action & "\n";
        $_result = WriteFile( &LogFile , $LogString );
    }
}
