cadencii.ScriptServer.reload C# (CSharp) Method

reload() public static method

スクリプトを読み込み、コンパイルします。
public static reload ( ) : void
return void
        public static void reload() {
            // 拡張子がcs, txtのファイルを列挙
            String dir = Utility.getScriptPath();
            Vector<String> files = new Vector<String>();
            files.addAll( Arrays.asList( PortUtil.listFiles( dir, ".txt" ) ) );
            files.addAll( Arrays.asList( PortUtil.listFiles( dir, ".cs" ) ) );

            // 既存のスクリプトに無いまたは新しいやつはロード。
            Vector<String> added = new Vector<String>(); //追加または更新が行われたスクリプトのID
            foreach ( String file in files ) {
                String id = PortUtil.getFileName( file );
                double time = PortUtil.getFileLastModified( file );
                added.add( id );

                boolean loadthis = true;
                if ( scripts.containsKey( id ) ) {
                    double otime = scripts.get( id ).fileTimestamp;
                    if ( time <= otime ) {
                        // 前回コンパイルした時点でのスクリプトファイルよりも更新日が同じか古い。
                        loadthis = false;
                    }
                }

                // ロードする処理
                if ( !loadthis ) {
                    continue;
                }

                ScriptInvoker si = (new PluginLoader()).loadScript( file );
                scripts.put( id, si );
            }

            // 削除されたスクリプトがあれば登録を解除する
            boolean changed = true;
            while ( changed ) {
                changed = false;
                for ( Iterator<String> itr = scripts.keySet().iterator(); itr.hasNext(); ) {
                    String id = itr.next();
                    if ( !added.contains( id ) ) {
                        scripts.remove( id );
                        changed = true;
                        break;
                    }
                }
            }
        }

Same methods

ScriptServer::reload ( String id ) : void

Usage Example

Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            Thread.GetDomain().UnhandledException += new UnhandledExceptionEventHandler(Cadencii_UnhandledException);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // 引数を解釈
            parseArguments(args);
            if (mPrintVersion)
            {
                Console.Write(BAssemblyInfo.fileVersion);
                return;
            }
            string file = mPathVsq;

            Logger.setEnabled(false);
            string logfile = PortUtil.createTempFile() + ".txt";

            Logger.setPath(logfile);
#if DEBUG
            Logger.setEnabled(true);
#endif

#if !DEBUG
            try {
#endif

            // 言語設定を読み込み
            try {
                Messaging.loadMessages();
                // システムのデフォルトの言語を調べる.
                // EditorConfigのコンストラクタは,この判定を自動でやるのでそれを利用
                EditorConfig ec = new EditorConfig();
                Messaging.setLanguage(ec.Language);
            } catch (Exception ex) {
                Logger.write(typeof(FormMain) + ".ctor; ex=" + ex + "\n");
                serr.println("FormMain#.ctor; ex=" + ex);
            }

            // 開発版の場合の警告ダイアログ
            string str_minor = BAssemblyInfo.fileVersionMinor;
            int minor        = 0;
            try {
                minor = int.Parse(str_minor);
            } catch (Exception ex) {
            }

            /*if ((minor % 2) != 0) {
             *  AppManager.showMessageBox(
             *      PortUtil.formatMessage(
             *          _("Info: This is test version of Cadencii version {0}"),
             *          BAssemblyInfo.fileVersionMeasure + "." + (minor + 1)),
             *      "Cadencii_UTAU",
             *      cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION,
             *      cadencii.windows.forms.Utility.MSGBOX_INFORMATION_MESSAGE);
             * }*/

            // スプラッシュを表示するスレッドを開始
#if !MONO
            splashThread = new Thread(new ThreadStart(showSplash));
            splashThread.TrySetApartmentState(ApartmentState.STA);
            splashThread.Start();
#endif

            // AppManagerの初期化
            AppManager.init();

#if ENABLE_SCRIPT
            try {
                ScriptServer.reload();
                PaletteToolServer.init();
            } catch (Exception ex) {
                serr.println("Cadencii::Main; ex=" + ex);
                Logger.write(typeof(Cadencii) + ".Main; ex=" + ex + "\n");
            }
#endif
            AppManager.mMainWindowController = new FormMainController();
            AppManager.mMainWindow           = new FormMain(AppManager.mMainWindowController, file);
#if !MONO
            AppManager.mMainWindow.Load += mainWindow_Load;
#endif
            Application.Run(AppManager.mMainWindow);
#if !DEBUG
        }

        catch (Exception ex) {
            String            str_ex = getExceptionText(ex, 0);
            FormCompileResult dialog = new FormCompileResult(
                _("Failed to launch Cadencii. Please send the exception report to developer"),
                str_ex);
            dialog.Text = _("Error");
            dialog.ShowDialog();
            if (splash != null)
            {
                splash.Invoke(new Action(splash.Close));
            }
            Logger.write(typeof(Cadencii) + ".Main; ex=" + ex + "\n");
        }
#endif
        }