예제 #1
0
파일: App.cs 프로젝트: agan112/nsh-kj
        /// <summary>
        /// Updates Keju dialog
        /// </summary>
        public static void UpdateKejuDialog(KejuQA kejuQA)
        {
            KejuDialog dialog = KejuDialog.GetInstance(kejuQA);

            if (!KejuDialog.IsOpen)
            {
                dialog.ShowDialog();
                return;
            }

            dialog.Invoke(new MethodInvoker(() => {
                dialog.WindowState = FormWindowState.Normal;
                dialog.Activate();
                dialog.UpdateDialog(kejuQA);
            }));
        }
예제 #2
0
파일: App.cs 프로젝트: agan112/nsh-kj
        public static void Main(string[] args)
        {
            Mutex mutex = new Mutex(false, Application.ProductName + Application.ProductVersion.ToString());

            try {
                if (!mutex.WaitOne(0, false))
                {
                    // another instance of the application may be running
                    return;
                }

                if (args.Contains("/verbose"))
                {
                    ConsoleManager.Show();
                }

                Logger = new Logger();
                Logger.WriteLine(LogLevel.Informational, "{0} version {1}", Application.ProductName, Application.ProductVersion);

                Directory.CreateDirectory(AppDirectory);
                FileStream stream = new FileStream(Path.Combine(AppDirectory, Application.ProductName + ".log"), args.Contains("/appendLog") ? FileMode.Append : FileMode.OpenOrCreate);
                Logger.Streams.Add(stream);

#if !DEBUG
                AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e) {
                    Logger.WriteLine(LogLevel.Error, "unhandled exception: {0}", e.ExceptionObject);

                    if (e.IsTerminating)
                    {
                        Logger.WriteLine(LogLevel.Warning, "CLR terminating");
                        Environment.Exit(1);
                    }
                };
#endif

                // Disable Windows XP-like text rendering
                Application.SetCompatibleTextRenderingDefault(false);

                // Initialize context menu
                mContextMenu = new ContextMenu(new MenuItem[] {
                    new MenuItem("科举截图", OnScreenshotClicked)
                    {
                        DefaultItem = true
                    },
                    new MenuItem("-"),
                    new MenuItem("设置", OnPreferencesClicked),
                    new MenuItem("关于", OnAboutClicked),
                    new MenuItem("-"),
                    new MenuItem("退出", OnQuitClicked)
                });

                // Initialize notify icon
                mNotifyIcon = new NotifyIcon()
                {
                    Icon = IconExtensions.ExtractFromAssembly("AppIcon", new Size(16, 16)),
                    Text = APP_NAME,

                    ContextMenu = mContextMenu
                };
                mNotifyIcon.MouseClick += delegate(object sender, MouseEventArgs mouseEventArgs) {
                    if (mouseEventArgs.Button == MouseButtons.Left)
                    {
                        OnScreenshotClicked(sender, mouseEventArgs);
                    }
                    else if (mouseEventArgs.Button == MouseButtons.Middle)
                    {
                        OnQuitClicked(sender, mouseEventArgs);
                    }
                };

                SetIconFrame(0, 16, GetNotifyIconVariant());
                mNotifyIcon.Visible = true;

                Preferences = Preferences.Load();
                RegisterHotKeys();

                InitializeAssetCache();
                CheckSettings();

                // start application event loop
                // 先出提示弹窗
                KejuQA kejuQA = new KejuQA();
                kejuQA.Topic = "Alt+Q截图题目即可,“拼诗句”需要截题目+9宫格候选字";
                List <string> tips = new List <string>();
                tips.Add("不要截取太多无用的东西,以免影响检索成功率");
                tips.Add(indexTip);
                kejuQA.Options = tips;
                Application.Run(KejuDialog.GetInstance(kejuQA));
            } finally {
                if (mutex != null)
                {
                    mutex.Close();
                    mutex = null;
                }
            }

            // UpdateKejuDialog(kejuQA);
        }