Ejemplo n.º 1
0
 private void OnOptionChanged()
 {
     OptionChangedEvent?.Invoke(blueprints);
 }
Ejemplo n.º 2
0
        static void Main()
        {
            //------------------------
            // 多重起動を防止する
            //------------------------
            // 同じ場所から複数インスタンスが起動された場合は弾くよう修正
            // 異なる場所から起動された場合は多重起動を認める。
            try
            {
                Process		myProcess;

                Process	[]procs = Process.GetProcesses();
                myProcess = Process.GetCurrentProcess();

                foreach( Process proc in procs  )
                {
                    try
                    {
                        if( (proc.Id != myProcess.Id)									&&
                            (proc.MainModule.FileName == myProcess.MainModule.FileName)	)
                        {
                            MessageBox.Show(
                                "mAgicAnimeは既に起動しています。\n" +
                                "(別々のパスから起動すれば複数起動できます)",
                                null										,
                                MessageBoxButtons.OK						,
                                MessageBoxIcon.Warning						);
                            return;
                        }
                    }
                    catch( Exception ex )
                    {
                        // プロセスによっては弾かれるため
                    }
                }
            }
            catch( Exception ex )
            {
            }

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

            try
            {
                //-----------------------------
                // アプリデータフォルダ作成
                //-----------------------------
                try
                {
                    if( !Directory.Exists(AppDataPath) )
                    {
                        Directory.CreateDirectory(AppDataPath);
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show("データフォルダの準備中にエラーが発生しました。",
                                    null,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Stop);
                    return;
                }
                //--------------------------
                // バージョンアップ時処理
                //--------------------------
                List<string>    upgradedLog = new List<string>();
                CheckUpgraded( ref upgradedLog );

                //------------------------------------
                // 初回起動時のコンフィギュレーション
                //------------------------------------
                AppConfiguration( ref upgradedLog );

                //--------------------------
                // ロガーの初期化
                //--------------------------
                mTextLogger		= new TextLogger(LogPath);
                mMemoryLogger	= new MemoryLogger();
                var teeLogger	= new TeeLogger( new List<Logger>{ mTextLogger, mMemoryLogger } );
                teeLogger.SetDefault();

                Logger.Output("------------------------------------------------");
                Logger.Output("起動(Ver " + Application.ProductVersion + ")");

                for( int i = 0 ; i < upgradedLog.Count ; ++i )
                    Logger.Output( upgradedLog[i] );

                //--------------------------
                // プラグインの初期化
                //--------------------------
                ReserveManager.InitPlugins();
                EncodeManager.InitPlugins();

                //--------------------------
                // メインフォームの初期化
                //--------------------------

                mMainForm = new MainForm();

                SystemEvents.SessionEnding += new SessionEndingEventHandler( OnSessionClosing );

                //------------------------
                // トレイアイコン準備
                //------------------------
                mTrayIcon				= new UserInterface.TrayIcon();
                mTrayIcon.Initialize();

                //------------------------
                // その他の初期化
                //------------------------
                OptionChanged += ApplyIconOption;
                // オプション変更時にデータ更新
                OptionChanged += delegate (object sender, EventArgs args)
                {
                    AnimeServer.GetInstance().BeginUpdate( 0 );

                    PathHelper.SetFileNameRule( Settings.Default.fileTitleMode );
                };

                PathHelper.SetFileNameRule( Settings.Default.fileTitleMode );

                //------------------------------------
                // 起動時に情報更新(オプション指定時)
                //------------------------------------
                if( Settings.Default.bootRefresh )
                {
                    AnimeServer server = AnimeServer.GetInstance();
                    server.BeginUpdate( 0 );
                }

                if( !Settings.Default.inTaskTray )
                    mMainForm.Show();

                // 未読機能をOFFの場合は表示しない
                if(	!Settings.Default.disableUnread
                &&	Settings.Default.notifyUnreadBalloon )
                {
                    mTrayIcon.PopupUnreadBalloon(); // 未読を表示(オプション設定時)
                }

                mAppContext = new ApplicationContext();
                mAppContext.MainForm = new UserInterface.DummyForm();

                Application.Run( mAppContext );

                mTrayIcon.mNotifyIcon.Visible = false; // 残骸が残るため
                mTrayIcon.Cleanup();

            //				Application.Run( mainForm );
            }
            catch (Exception ex)
            {
                ShowException(ex, MessageBoxIcon.Exclamation);
            }
            finally
            {
                Cleanup();
            }

            // メッセージループの外側でシャットダウンをかける
            if( mShutDown )
            {
                ComputerPowerDown();
            }
        }