internal static void Main(string[] args) { #if !DEBUG // Only allows starting from launcher, because otherwise: // * if the current one is not the latest version, data loss might occur because of // the updater. // * the launcher start this program with admin permission. Without this // some issues may occur. try { var latest = UsingLatestVersion(); if (!latest || !Windows.IsAdministrator()) { MsgBoxHelper.ShowError(null, "Please start QSimPlanner via Launcher.exe."); return; } } catch (Exception e) { MsgBoxHelper.ShowError(null, "An error occurred.\n" + e.Message); return; } #endif CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; using (var mutex = new Mutex(false, $"Global\\{GetGuid()}")) { if (!mutex.WaitOne(0, false)) { MsgBoxHelper.ShowError(null, "QSimPlanner is already running."); return; } config = XDocument.Load("./config.xml").Root; #if !DEBUG // We want the debugger to break when having an unhandled exception. SetExceptionHandler(); #endif Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); #if !DEBUG UpdateOnFirstRun(); MoveNavData(); #endif ShowLicenseIfNeeded(); WebRequests.SetSecuityProtocol(); var mainFrm = new QspForm(); mainFrm.Init(); Application.Run(mainFrm); } }
private void btnGotoPage_Click(object sender, EventArgs e) { try { int pageNum = Convert.ToInt32(txtGotoPageNum.Text); GotoPage(pageNum); } catch { MsgBoxHelper.ShowError("頁號必需輸入整數!"); } }
/// <summary> /// 顯示無法轉換的字元。 /// </summary> private void ShowInvlaidCharForm(int errorCount) { MsgBoxHelper.ShowError("共有 " + errorCount.ToString() + " 個字元無法轉換!\r\n" + "請逐一修正後再執行轉換程序。"); m_InvalidCharForm.Show(); m_InvalidCharForm.Left = this.Left + this.Width - m_InvalidCharForm.Width - 4; m_InvalidCharForm.Top = rtbOrg.PointToScreen(new Point(0, 0)).Y; m_InvalidCharForm.Height = 400; if (m_InvalidCharForm.Bottom > (this.Bottom - 30)) { m_InvalidCharForm.Height = this.Bottom - 30 - m_InvalidCharForm.Top; } }
internal static void Main(string[] args) { #if !DEBUG // Only allows starting from launcher. Otherwise data loss might occur because of // the updater. try { var latest = UsingLatestVersion(); if (!latest) { MsgBoxHelper.ShowError(null, "Please start QSimPlanner via Launcher.exe."); return; } } catch (Exception e) { MsgBoxHelper.ShowError(null, "An error occurred.\n" + e.Message); return; } #endif CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; using (var mutex = new Mutex(false, $"Global\\{GetGuid()}")) { if (!mutex.WaitOne(0, false)) { MsgBoxHelper.ShowError(null, "QSimPlanner is already running."); return; } SetExceptionHandler(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); #if !DEBUG UpdateOnFirstRun(); #endif var mainFrm = new QspForm(); mainFrm.Init(); Application.Run(mainFrm); } }
/// <summary> /// 更新指定的點字方格。 /// </summary> /// <param name="row"></param> /// <param name="col"></param> /// <param name="brWord"></param> private void UpdateCell(int row, int col, BrailleWord brWord) { // 處理點字 string brFontText = null; try { if (brWord.IsContextTag) { brFontText = " "; } else { brFontText = BrailleFontConverter.ToString(brWord); } } catch (Exception e) { MsgBoxHelper.ShowError(e.Message + "\r\n" + "列:" + row.ToString() + ", 行: " + col.ToString()); brFontText = ""; } row = GetBrailleRowIndex(row); // 確保列索引為點字列。 //若每個 cell 一方點字,就用以下迴圈填入點字 //for (int i = 0; i < brFontText.Length; i++) //{ // brGrid[row, col+i].Value = brFontText[i]; //} brGrid[row, col].Value = brFontText; brGrid[row, col].Tag = brWord; brGrid[row + 1, col].Value = brWord.Text; brGrid[row + 1, col].Tag = brWord; brGrid[row + 2, col].Value = brWord.PhoneticCode; brGrid[row + 2, col].Tag = brWord; }
private static void ReportError(string message) { try { var url = config.GetString("ErrorReportUrl"); var assemblyLocation = Assembly.GetExecutingAssembly().Location; var info = new ProcessStartInfo() { WorkingDirectory = Path.GetDirectoryName(assemblyLocation), FileName = "ErrorReport.exe", Arguments = Strings.EscapeCommandLineArg(url) + " " + Strings.EscapeCommandLineArg(message), WindowStyle = ProcessWindowStyle.Hidden }; Process.Start(info); } catch (Exception e) { MsgBoxHelper.ShowError(null, "Failed to report the error."); LoggerInstance.Log(e); } }
/// <summary> /// 把一列點字填入指定的 grid 列(影響三列)。 /// </summary> /// <param name="brLine">點字串列。</param> /// <param name="row">欲填入 grid 中的哪一列。</param> /// <param name="autoSize">填完之後,是否要自動重新調整儲存格大小。</param> private void FillRow(BrailleLine brLine, int row, bool autoSize) { string brFontText; int col = brGrid.FixedColumns; // 確保列索引是點字所在的列。 row = GetBrailleRowIndex(row); brGrid.SuspendLayout(); try { foreach (BrailleWord brWord in brLine.Words) { // 處理點字 try { if (brWord.IsContextTag) { brFontText = " "; } else { brFontText = BrailleFontConverter.ToString(brWord); } } catch (Exception e) { MsgBoxHelper.ShowError(e.Message + "\r\n" + "列:" + row.ToString() + ", 行: " + col.ToString()); brFontText = ""; } brGrid[row, col] = new SourceGrid.Cells.Cell(brFontText); brGrid[row, col].ColumnSpan = brFontText.Length; brGrid[row, col].View = m_BrView; brGrid[row, col].Tag = brWord; brGrid[row, col].AddController(m_MenuController); brGrid[row, col].AddController(m_ClickController); // 處理明眼字 brGrid[row + 1, col] = new SourceGrid.Cells.Cell(brWord.Text); brGrid[row + 1, col].ColumnSpan = brFontText.Length; brGrid[row + 1, col].View = m_MingViewCJK; // TODO: 確認音標字形可以正確顯示. 否則要分開判斷,音標符號改用 m_MingView brGrid[row + 1, col].Tag = brWord; brGrid[row + 1, col].AddController(m_MenuController); brGrid[row + 1, col].AddController(m_ClickController); // 處理注音碼 brGrid[row + 2, col] = new SourceGrid.Cells.Cell(brWord.PhoneticCode); brGrid[row + 2, col].ColumnSpan = brFontText.Length; if (brWord.IsPolyphonic) { if (AppGlobals.Config.Braille.ErrorProneWords.IndexOf(brWord.Text) >= 0) { // 容易判斷錯誤的破音字用顯眼的紅色標示。 brGrid[row + 2, col].View = m_PhonView3; } else { // 一般破音字用黃色標示。 brGrid[row + 2, col].View = m_PhonView2; } } else { brGrid[row + 2, col].View = m_PhonView; } brGrid[row + 2, col].Tag = brWord; col += brFontText.Length; } } finally { brGrid.Rows.AutoSizeRow(row); brGrid.Rows.AutoSizeRow(row + 1); brGrid.Rows.AutoSizeRow(row + 2); brGrid.ResumeLayout(); } }
private async Task <bool> DoUpdateAsync(bool autoMode) { HttpUpdater updater = new HttpUpdater() { ClientPath = Application.StartupPath, ServerUri = AppGlobals.Config.AutoUpdateFilesUrl, ChangeLogFileName = "ChangeLog.txt" }; // debug using local update feed. //updater.ServerUri = "http://localhost/ebeupdate/"; try { await updater.GetUpdateListAsync(); } catch (Exception ex) { // 無法取得檔案更新清單(可能是網際網路無法連線) string msg = "無法取得檔案更新清單: " + ex.Message; if (autoMode) { StatusText = msg; } else { MsgBoxHelper.ShowError(msg); } return(false); } if (updater.HasUpdates()) { if (MsgBoxHelper.ShowYesNo("「易點雙視」有新版本,是否立即更新?") == DialogResult.Yes) { UpdateProgressForm updForm = new UpdateProgressForm(); updForm.Show(); try { updater.FileUpdating += updForm.updator_FileUpdating; updater.FileUpdated += updForm.updator_FileUpdated; updater.DownloadProgressChanged += updForm.updator_DownloadProgressChanged; if (await updater.UpdateAsync() > 0) { updForm.TopMost = false; var fvi = FileVersionInfo.GetVersionInfo(Application.ExecutablePath); MsgBoxHelper.ShowInfo("「易點雙視」更新完成!"); return(true); } } catch (Exception ex) { updForm.TopMost = false; MsgBoxHelper.ShowError("更新失敗!\r\n" + ex.Message); } finally { updForm.Close(); updForm.Dispose(); } } } else { if (!autoMode) { MsgBoxHelper.ShowInfo("您使用的已經是最新版,無須更新。"); } } return(false); }