Exemplo n.º 1
0
        public static void Initialize(AppendString appendString)
        {
            // Floder Check
            if (!Directory.Exists(BASE_PATH + @"\Config"))
            {
                // First start alterful
                ASettings.DisplayRightMenu  = true;
                ASettings.AutoRunWithSystem = true;
                CreateShortcut(APATH_PATH + @"\alterful" + AFile.LNK_EXTENTION, BASE_PATH + @"\Alterful.exe");
                CreateShortcut(APATH_PATH + @"\atemp" + AFile.LNK_EXTENTION, ATEMP_PATH);
                CreateShortcut(APATH_PATH + @"\desktop" + AFile.LNK_EXTENTION, Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                IS_FIRST_START = true;
            }

            // Old version auto startup alterful.exe but new version startup AlterfulPiple.exe,
            // so over execute to overwrite the old auto startup register configurate.
            if (ASettings.AutoRunWithSystem)
            {
                ASettings.AutoRunWithSystem = true;
            }

            Directory.CreateDirectory(BASE_PATH + @"\APath");
            Directory.CreateDirectory(BASE_PATH + @"\ATemp");
            Directory.CreateDirectory(BASE_PATH + @"\Config");
            Directory.CreateDirectory(CONST_INSTRUCTION_PATH);

            // File Check
            AConstQuote.CreateConstQuoteFile();
            ATheme.CreateThemeConfigFile();

            // Config Check
            AConstQuote.ReadAllConfig();
            ATheme.ReadAllConfig();

            // Enviroment Check
            SysEnviroment.SetPathAfter(APATH_PATH);

            // Regedit Check

            // Others
            System.IO.File.Delete(@".\restart.bat");
            ShowANew(appendString);
            ShowANotification("Alterful 正在后台运行", "Press Alt+A to active Alterful");
        }
Exemplo n.º 2
0
        /// <summary>
        /// 执行指令框中的指令
        /// </summary>
        private void ExecuteTextBoxInstrution()
        {
            UpdateMaxWidth(InstructionTextBox.Text);

            // Execute instruction.
            string retnInfo = ExecuteInstruction(InstructionTextBox.Text);

            InitializeGUI(ATheme.GetThemeConfig());
            if (AInstruction.ADD_CONST_INSTRUCTION == retnInfo)
            {
                constInstructionInputMode  = true;
                TestRichTextbox.IsReadOnly = false; InstructionTextBox.IsEnabled = false;
                //AppendRTBLine(TestRichTextbox, "确认编辑: Alt + S / 取消编辑: Alt + Esc", themeConfig.ForegroundOutputWarning, themeConfig.BackgroundOutputWarning);
                AppendRTBLine(TestRichTextbox, "Confirm: Alt + S / Cancel: Alt + Esc", themeConfig.ForegroundOutputWarning, themeConfig.BackgroundOutputWarning);
                TestRichTextbox.BorderThickness = new Thickness(1);

                // Content Start
                TestRichTextbox.CaretPosition                     = TestRichTextbox.Document.ContentEnd;
                constInstructionContentRange.ContentStart         = TestRichTextbox.CaretPosition.Paragraph.ContentStart;
                TestRichTextbox.CaretPosition.Paragraph.IsEnabled = false;

                // If ci already exist
                string constInstruction = AInstruction_Const.GetConstInstructionFromMacroInstruction(InstructionTextBox.Text);
                if (AConstInstruction.Exist(constInstruction))
                {
                    ConstInstruction ci = new ConstInstruction();
                    if (AConstInstruction.GetConstInstructionFrame(constInstruction, ref ci))
                    {
                        OldConstInstructionFileName = AConstInstruction.GetFileNameFromConstInstruction(ci);
                        foreach (string insLine in ci.instructionLines)
                        {
                            AppendRTBLine(TestRichTextbox, insLine, themeConfig.ForegroundOutput, themeConfig.BackgroundOutput);
                            UpdateMaxWidth(insLine);
                        }
                    }
                }

                // Set CaretPosition.
                TestRichTextbox.CaretPosition = TestRichTextbox.Document.ContentEnd;

                //UpdateMaxWidth("确认编辑: Alt + S / 取消编辑: Alt + Esc");
                UpdateMaxWidth("Confirm: Alt + S / Cancel: Alt + Esc");
                Resize(true, constInstructionInputWidthBias);
                TestRichTextbox.Focus(); showOutput = true;
                return;
            }
            else if (AInstruction.UPDATE_INSTRUCTION == retnInfo)
            {
                UpdateMaxWidth(InstructionTextBox.Text);
                AppendRTBLine(TestRichTextbox, InstructionTextBox.Text, themeConfig.ForegroundOutput, themeConfig.BackgroundOutput);
                showOutput = true;
                InstructionTextBox.Text = "";
                Resize();
                AHelper.AppendString appendString = delegate(string content, AInstruction.ReportType type)
                {
                    // InstructionTextBox 被主线程占用,利用 Dispatcher 进行操作
                    TestRichTextbox.Dispatcher.BeginInvoke((Action)(() => {
                        switch (type)
                        {
                        case AInstruction.ReportType.NONE: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutput, themeConfig.BackgroundOutput); break;

                        case AInstruction.ReportType.WARNING: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutputWarning, themeConfig.BackgroundOutputWarning); break;

                        case AInstruction.ReportType.OK: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutputOk, themeConfig.BackgroundOutputOk); break;

                        case AInstruction.ReportType.ERROR: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutputError, themeConfig.BackgroundOutputError); break;
                        }
                        InstructionTextBox.Text = "";
                        UpdateMaxWidth(content);
                        Resize();
                    }));
                };

                new Thread(AUpdate.UpdateAndRestart).Start(appendString);
                return;
            }

            // Append instruction line.
            AppendRTBLine(TestRichTextbox, InstructionTextBox.Text, themeConfig.ForegroundOutput, themeConfig.BackgroundOutput);

            // Print report.
            foreach (var reportInfo in AInstruction.ReportInfo)
            {
                AppendRTBLine(TestRichTextbox, reportInfo, themeConfig.ForegroundOutputWarning, themeConfig.BackgroundOutputWarning);
                UpdateMaxWidth(reportInfo);
                // If have reportInfo, then show outputBox.
                showOutput = true;
            }

            // Print return information.
            SolidColorBrush bgcolor;
            SolidColorBrush fgcolor;

            switch (AInstruction.reportType)
            {
            case AInstruction.ReportType.OK: bgcolor = themeConfig.BackgroundOutputOk; fgcolor = themeConfig.ForegroundOutputOk; if (AInstruction.ReportInfo.Count == 0)
                {
                    showOutput = false;
                }
                break;

            case AInstruction.ReportType.WARNING: bgcolor = themeConfig.BackgroundOutputWarning; fgcolor = themeConfig.ForegroundOutputWarning; showOutput = true; break;

            case AInstruction.ReportType.ERROR: bgcolor = themeConfig.BackgroundOutputError; fgcolor = themeConfig.ForegroundOutputError; showOutput = true; break;

            default: bgcolor = themeConfig.BackgroundOutputWarning; fgcolor = themeConfig.ForegroundOutputWarning; break;
            }
            if (retnInfo != "")
            {
                AppendRTBLine(TestRichTextbox, retnInfo.Trim(), fgcolor, bgcolor);
            }

            if (AInstruction.GetType(InstructionTextBox.Text) == InstructionType.CMD)
            {
                InstructionTextBox.Text = "> "; showOutput = true;
            }
            else
            {
                InstructionTextBox.Text = "";
                if (AInstruction.ReportType.OK == AInstruction.reportType && 0 == AInstruction.ReportInfo.Count)
                {
                    Visibility = Visibility.Hidden;
                }
            }
            InstructionTextBox.SelectionStart = InstructionTextBox.Text.Length;

            // Update width and resize.
            UpdateMaxWidth(retnInfo);
            Resize();
        }
Exemplo n.º 3
0
        public MainWindow()
        {
            /*
             * TODO: Automatically initialize default startup items for users who first use Alterful.
             * foreach (AHelper.SoftwareInstalled software in AHelper.GetInstalledSoftwareList())
             * {
             *  Console.WriteLine(software.DisplayName + " (" + software.InstallLocation + ")");
             * }
             */

            if (!GotMutex)
            {
                AHelper.ShowANotification("Alterful 已在运行中", "Alterful is already running");
                Environment.Exit(1);//退出程序
            }

            // Global Initialization.
            InitializeComponent();
            AHelper.Initialize(delegate(string content, AInstruction.ReportType type)
            {
                // InstructionTextBox 被主线程占用,利用 Dispatcher 进行操作
                TestRichTextbox.Dispatcher.BeginInvoke((Action)(() => {
                    switch (type)
                    {
                    case AInstruction.ReportType.NONE: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutput, themeConfig.BackgroundOutput); break;

                    case AInstruction.ReportType.WARNING: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutputWarning, themeConfig.BackgroundOutputWarning); break;

                    case AInstruction.ReportType.OK: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutputOk, themeConfig.BackgroundOutputOk); break;

                    case AInstruction.ReportType.ERROR: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutputError, themeConfig.BackgroundOutputError); break;
                    }
                    InstructionTextBox.Text = "";
                    UpdateMaxWidth(content);
                    Resize();
                }));
            });
            InitializeGUI(ATheme.GetThemeConfig(), !AHelper.IS_FIRST_START && !AHelper.HAS_ANEW);
            InitializePipe();
            CheckCommandLine();
            appendStringDelegate = AppendStringFunction;

            Thread thread = new Thread(new ThreadStart(CheckUpdate));

            thread.Start();

            // If is first startup, give user some tips.
            if (AHelper.IS_FIRST_START)
            {
                string outInfo = "欢迎来到 Alterful,以下是初次上手帮助!\n- 在[指令框输入框]按 Alt 来隐藏/显示回显框;\n- 使用组合键 [Alt+A] 来唤醒/隐藏指令框;\n- 右键任意文件/文件夹来将其添加为启动项;\n- 在指令输入框键入启动项名并回车来启动它;\n- 需要时键入波浪号(~)并回车来结束 Alterful;\n- 前往 help.alterful.com 了解详细功能和使用技巧。";
                TestRichTextbox.Dispatcher.BeginInvoke((Action)(() => {
                    UpdateMaxWidth(outInfo);
                    AppendRTBLine(TestRichTextbox, outInfo, themeConfig.ForegroundOutputWarning, themeConfig.BackgroundOutputWarning);
                    Visibility = Visibility.Visible;
                    showOutput = true;
                    Resize();
                }));
            }

            // Instruction Test.
            // MainTest();
            // Close();
        }