Ejemplo n.º 1
0
 public OutputStreamWriter( FileOutputStream stream, String charsetName ) {
     Encoding enc = Encoding.GetEncoding( charsetName );
     if ( charsetName.ToLower().Equals( "utf-8" ) ) {
         enc = new System.Text.UTF8Encoding( false );
     }
     m_writer = new StreamWriter( stream, enc );
 }
Ejemplo n.º 2
0
 /// <summary>
 /// スクリプトを実行します。
 /// </summary>
 /// <param name="evsd"></param>
 public static boolean invokeScript( String id, VsqFileEx vsq ) {
     ScriptInvoker script_invoker = null;
     if ( scripts.containsKey( id ) ) {
         script_invoker = scripts.get( id );
     } else {
         return false;
     }
     if ( script_invoker != null && script_invoker.scriptDelegate != null ) {
         try {
             VsqFileEx work = (VsqFileEx)vsq.clone();
             ScriptReturnStatus ret = ScriptReturnStatus.ERROR;
             if ( script_invoker.scriptDelegate is EditVsqScriptDelegate ) {
                 boolean b_ret = ((EditVsqScriptDelegate)script_invoker.scriptDelegate).Invoke( work );
                 if ( b_ret ) {
                     ret = ScriptReturnStatus.EDITED;
                 } else {
                     ret = ScriptReturnStatus.ERROR;
                 }
             } else if ( script_invoker.scriptDelegate is EditVsqScriptDelegateEx ) {
                 boolean b_ret = ((EditVsqScriptDelegateEx)script_invoker.scriptDelegate).Invoke( work );
                 if ( b_ret ) {
                     ret = ScriptReturnStatus.EDITED;
                 } else {
                     ret = ScriptReturnStatus.ERROR;
                 }
             } else if ( script_invoker.scriptDelegate is EditVsqScriptDelegateWithStatus ) {
                 ret = ((EditVsqScriptDelegateWithStatus)script_invoker.scriptDelegate).Invoke( work );
             } else if ( script_invoker.scriptDelegate is EditVsqScriptDelegateExWithStatus ) {
                 ret = ((EditVsqScriptDelegateExWithStatus)script_invoker.scriptDelegate).Invoke( work );
             } else {
                 ret = ScriptReturnStatus.ERROR;
             }
             if ( ret == ScriptReturnStatus.ERROR ) {
                 AppManager.showMessageBox( _( "Script aborted" ), "Cadencii", com.github.cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION, com.github.cadencii.windows.forms.Utility.MSGBOX_INFORMATION_MESSAGE );
             } else if ( ret == ScriptReturnStatus.EDITED ) {
                 CadenciiCommand run = VsqFileEx.generateCommandReplace( work );
                 AppManager.editHistory.register( vsq.executeCommand( run ) );
             }
             String config_file = configFileNameFromScriptFileName( script_invoker.ScriptFile );
             FileOutputStream fs = null;
             boolean delete_xml_when_exit = false; // xmlを消すときtrue
             try {
                 fs = new FileOutputStream( config_file );
                 script_invoker.Serializer.serialize( fs, null );
             } catch ( Exception ex ) {
                 serr.println( "AppManager#invokeScript; ex=" + ex );
                 delete_xml_when_exit = true;
             } finally {
                 if ( fs != null ) {
                     try {
                         fs.close();
                         if ( delete_xml_when_exit ) {
                             PortUtil.deleteFile( config_file );
                         }
                     } catch ( Exception ex2 ) {
                         serr.println( "AppManager#invokeScript; ex2=" + ex2 );
                     }
                 }
             }
             return (ret == ScriptReturnStatus.EDITED);
         } catch ( Exception ex ) {
             AppManager.showMessageBox( _( "Script runtime error:" ) + " " + ex, _( "Error" ), com.github.cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION, com.github.cadencii.windows.forms.Utility.MSGBOX_INFORMATION_MESSAGE );
             serr.println( "AppManager#invokeScript; ex=" + ex );
         }
     } else {
         AppManager.showMessageBox( _( "Script compilation failed." ), _( "Error" ), com.github.cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION, com.github.cadencii.windows.forms.Utility.MSGBOX_WARNING_MESSAGE );
     }
     return false;
 }